XGenStudios Forums

Go Back   XGenStudios Forums > XGen Studios > Flash and Coding Forum

Reply
 
Thread Tools
Old 11-01-2009, 05:50 PM   #11
Serisium
CEO
 
Join Date: Dec 2007
Age: 15
Posts: 962
Default

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);
    }
}
__________________

Serisium is offline   Reply With Quote
Old 11-01-2009, 07:56 PM   #12
Freddy
Freddy
 
Freddy's Avatar
 
Join Date: Jul 2003
Location: Florida
Age: 21
Posts: 12,635
Default

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.
__________________
Freddy is offline   Reply With Quote
Old 11-03-2009, 07:22 PM   #13
game-bot
♥♥♥
 
game-bot's Avatar
 
Join Date: Oct 2004
Location: Texas
Posts: 11,587
Default

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
game-bot is offline   Reply With Quote
Old 11-04-2009, 04:12 PM   #14
Blixinator
Future Schizophrenic
 
Blixinator's Avatar
 
Join Date: Oct 2004
Location: Quel'Dorei
Age: 18
Posts: 12,329
Default

I have 70 problems solved.
Bam.

__________________
Blixinator is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 06:13 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All Material Copyright Xgenstudios Forums and Its Respective Posters