![]() |
|
|
#11 |
|
CEO
Join Date: Dec 2007
Age: 15
Posts: 962
|
I've known about this for a while, and currently have 24 problems completed. I just coded a solution for #220 in Java and it's computing right now.
http://projecteuler.net/index.php?se...roblems&id=220 Code:
public class Heighway_Dragon {
static int a,b,x,y;
public static void main(String[] args) {
position(1000000000000l,construct(50));
}
public static String construct(int i){
String current = "Fa";
String next;
for(int generation=1;generation<=i;generation++){
next = "";
for(int x=0;x<current.length();x++){
switch(current.charAt(x)){
case 'a': next+="aRbFR"; break;
case 'b': next+="LFaLb"; break;
case 'F': next+="F"; break;
case 'R': next+="R"; break;
case 'L': next+="L"; break;
}
}
current=next;
}
return current;
}
public static void position(long pos, String dragon){
dragon=dragon.replaceAll("a","");
dragon=dragon.replaceAll("b","");
int direction=1;
while(b<pos){
a++;
if(dragon.charAt(a)=='F'){
if(direction==1)
y++;
if(direction==2)
x++;
if(direction==3)
y-=1;
if(direction==4)
x-=1;
b++;
} else if(dragon.charAt(a)=='L') {
direction-=1;
if(direction==0)
direction=4;
} else if(dragon.charAt(a)=='R') {
direction+=1;
if(direction==5)
direction=1;
}
}
System.out.println(x);
System.out.println(y);
}
}
__________________
|
|
|
|
|
|
#12 |
|
Freddy
Join Date: Jul 2003
Location: Florida
Age: 21
Posts: 12,635
|
This is pretty cool. If I wasn't supposed to be doing a test right now and not being online, I'd try some of these today.
For now I'll just bookmark it and start tomorrow.
__________________
|
|
|
|
|
|
#13 |
|
♥♥♥
Join Date: Oct 2004
Location: Texas
Posts: 11,587
|
Found out that the site isn't blocked on my school's websense. That means I'll actually have something to do in my compsci class, after I finish the entire week's worth of work in 15 minutes...
__________________
12.01.09 |
|
|
|
|
|
#14 |
|
Future Schizophrenic
Join Date: Oct 2004
Location: Quel'Dorei
Age: 18
Posts: 12,329
|
I have 70 problems solved.
Bam.
__________________
|
|
|
|
![]() |
| Thread Tools | |
|
|