def gcd(a,b) { if (b == 0) { return a } else { return gcd(b, a%b) } } def numFracs(int d) { int low = d / 3 + 1 int high = d / 2 ret = 0 for (i in low..high) { if (gcd(i,d) == 1) { ++ret } } return ret } ans = 0 for (i in 4..12000) { ans += numFracs(i) } println ans
Friday, December 20, 2013
Problem 73 - Groovy
I haven't solved a problem in a while because of finals and break and such...and another reason is because I am playing with some very frustrating esolangs that have yet to bear any fruit. I decided to take a break from that and solve problem 73 in Groovy, a language which, like so many others, runs on the JVM and is very java-like.
Friday, December 13, 2013
Problem 71 - Processing
I decided to solve problem 71 in Processing. Now, Processing is, like ChucK, not a language that was designed for Project Euler, it is a language designed for drawing things and other things that involve graphics. Nonetheless, it worked fairly well for the purposes of this problem. The main trick was counting down from 1000000 to circumvent precision problems.
int gcd(int a, int b) { if (b == 0) { return a; } else { return gcd(b, a%b); } } void draw() { int closest = 0; double smallestDiff = 10; for (int d = 1000000; d > 8; --d) { int num = floor(3.0 / 7.0 * d); double diff = (3.0/7.0) - (num*1.0) / d; if (diff < smallestDiff && num / gcd(num, d) != 3) { smallestDiff = diff; closest = num / gcd(num, d); } } println(closest); noLoop(); }
Monday, December 9, 2013
Progress
Below is the table of my progress. It includes all of the languages that I have solved problems in, as well as which problem I solved in that language. Statements of the problems can be found at projecteuler.net, and all of the solutions are linked to from the table, in addition to being directly in posts on this blog.
BrainFuck | 1* |
Haskell | 2*,37 |
J | 3*,24*,35* |
J | 69*,72 |
Ruby | 4*,40*,56 |
Whenever | 2,5* |
Ook! | 6* |
Racket | 7*,26*,57 |
K | 8*,30 |
Javascript | 9*,31*,60 |
sML | 10*,42 |
PHP | 11 |
Go | 12*,32 |
cLisp | 13*,62 |
C | 48*,50 |
Fortran95 | 3,15* |
Python | 16*,24*,39* |
Python | 65*,66 |
ELM | 17*,48 |
Scala | 18*,44 |
Perl | 19*,70 |
Java | 20 |
FALSE | 4 |
Squirrel | 21*,52*,55 |
D | 22 |
Ceylon | 23 |
Problem 72 - more J
I haven't gotten around to solving too many problems recently because of finals, but I decided to take a couple of minutes and look at the problems that were coming up. As I still had J free, I managed to find a problem which took me under a minute to solve in J. Below is my solution to problem 72 in J, solution runs in about 8 seconds.
+/5 p:}.}.i.1000001
Subscribe to:
Posts (Atom)