81 - 99 of 99 Posts

Joined

·
5,282 Posts

Joined

·
1,198 Posts

Originally Posted by rabidgnome229 No primitive datatype can hold that value. You need to create/use a third party BigInteger type class |

Quote:

Originally Posted by error10 Why would you multiply two numbers if you didn't intend to use the result? |

My question was more deeply nested. I wanted to know if he intend to do power modulo operation, which won't need more than 32bits type (depending on the arguments).

I even tried this:

m ^ e === c (mod n)

like that:

Code:

Code:

```
int c = 1;
for (int i=0;i<e;i++){
c = (c*m)%n;
}
```

Joined

·
5,282 Posts

Joined

·
5,282 Posts

Code:

Code:

```
#!/usr/bin/env python
import sys
def fib_even():
sum = 0
last = (0, 1)
curr = 0
while sum < 4000000 :
curr = last[0] + last[1]
if not (curr % 2) :
sum += curr
last = (last[1], curr)
else:
return sum-curr
def get_fact(fact, num):
if not num in fact :
fact[num] = num * get_fact(fact, num-1)
return fact[num]
def factorial_sum(limit):
fact = {0 : 1, 1 : 1, 2 : 2}
r = xrange(3, limit+1)
for n in r:
num = n
sum = get_fact(fact, n % 10)
while n / 10 != 0 :
n /= 10;
f = get_fact(fact, n % 10)
sum += f
else:
if sum == num :
print " ", num, " is a solution"
sum = fib_even()
print "The sum of all even fibonacci number such that the sum is less than 4,000,000 is", sum
if len(sys.argv) < 2 :
factorial_sum(1000000)
else :
factorial_sum(int(sys.argv[1]))
```

Joined

·
2,724 Posts

could i use whitespace for these

Im learning java in school but really only know the basics

Im learning java in school but really only know the basics

Joined

·
5,282 Posts

Code:

Code:

```
#!/usr/bin/env python
import sys
##### function definitions #####
def is_prime(p, n) :
for d in p :
if (n/d)*d == n :
return False
else :
return True
##### begin main #####
# parse command line arguments
if len(sys.argv) < 2 :
limit = 1000000
else :
limit = int(sys.argv[1])
# seed list of primes
p = [2]
r = xrange(3, limit+1)
solution = []
# generate all primes in range
for n in r :
if is_prime(p, n) :
p = p + [n]
# iterate through all primes
for n in p :
# convert to a list of digits
s = str(n)
r = xrange(1, len(s))
valid = True
# check all rotations of the prime
for i in r :
rs = s[i:len(l)] + s[0:i]
if not int(rs) in p :
valid = False
else :
if valid == True :
solution = solution + [n]
for s in solution :
print s
```

Joined

·
13,477 Posts

Though I'm not sure how much faster you can get it, a good backtracking algorithm can do it in under 1s. I'd still like to see what you come up with though

Joined

·
13,477 Posts

Joined

·
1,125 Posts

Code:

Code:

```
[CODE]
<?php
$handle = fopen("roman.txt", "r");
$numbers_file = fread($handle, filesize("roman.txt"));
fclose($handle);
$numbers_array = explode("\
", $numbers_file);
foreach($numbers_array as $number) {
$number = preg_replace("/[\
\
]/", "", $number);
print($number . ": " . strlen($number) . " characters beforehand.\
");
$old = strlen($number);
$number = str_replace("IIIII", "V", $number);
$number = str_replace("IIII", "IV", $number);
$number = str_replace("VIV", "IX", $number);
$number = str_replace("VV", "X", $number);
$number = str_replace("XXXXX", "L", $number);
$number = str_replace("XXXX", "XL", $number);
$number = str_replace("LXL", "XC", $number);
$number = str_replace("LL", "C", $number);
$number = str_replace("CCCCC", "D", $number);
$number = str_replace("CCCC", "CD", $number);
$number = str_replace("DCD", "CM", $number);
$number = str_replace("DD", "M", $number);
print($number . ": ". strlen($number) . " characters afterward.\
");
print("There were " . ($old - strlen($number)) . " characters saved.\
\
");
}
?>
```

It's verified working with the txt you provided. I think there are a couple of small cases where it won't, but none in your example file.

Joined

·
51 Posts

i'm need a new challenge. anyone got something for me?

Joined

·
51 Posts

Joined

·
1,198 Posts

I have something for you.

"Elliptic curve cryptography"

* Generate keys

* Encode

* Decode

PS. I'm interested in it, but don't have the time to try. AFAIK this is one of the most secure asymmetric encryptions.

PS2. 112bit ECC has the security level of 2048bit RSA.

Joined

·
1,758 Posts

Anyone looking for a good challenge may want to google for ACM programming competition questions.

Joined

·
2 Posts

=( Sad face at modifying other people's code, I like it when their work can just be a big black box.

Joined

·
2 Posts

Quote:

Originally Posted by ToastedZergling I have given the #10 Crackless Wall Puzzle using javascript, but I'm having a problem calculating the larger values. I can get up to W (18, 5) = 7958, but if I go much further up on the first parameter I get array out of bounds errors and other ugly messages. Does anyone think they could lend a spare set of eyes to see how I can improve this? I'm thinking I will have to modify the permute function, which I didn't write to begin with =( Sad face at modifying other people's code, I like it when their work can just be a big black box. |

81 - 99 of 99 Posts

- This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.

Overclock.net

A forum community dedicated to overclocking enthusiasts and testing the limits of computing. Come join the discussion about computing, builds, collections, displays, models, styles, scales, specifications, reviews, accessories, classifieds, and more!

Full Forum Listing
Explore Our Forums

Recommended Communities

Join now to ask and comment!