XGenStudios Forums

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

Reply
 
Thread Tools
Old 11-01-2009, 04:50 PM   #11
Serisium
CEO
 
Serisium's Avatar
 
Join Date: Dec 2007
Age: 15
Posts: 1,017
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, 06:56 PM   #12
Freddy
Brotroid
 
Freddy's Avatar
 
Join Date: Jul 2003
Location: Chillin' with the Brozo
Age: 22
Posts: 13,097
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, 06:22 PM   #13
game-bot
you % me = you, bro
 
game-bot's Avatar
 
Join Date: Oct 2004
Location: Texas
Posts: 11,918
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...
__________________
game-bot is offline   Reply With Quote
Old 11-04-2009, 03:12 PM   #14
Blixinator
Person
 
Join Date: Oct 2004
Location: Quel'Dorei
Age: 19
Posts: 12,443
Default

I have 70 problems solved.
Bam.

__________________
Need to contact me?
Reddit | WoW | Steam | Facebook
Blixinator is offline   Reply With Quote
Old 12-16-2009, 08:28 PM   #15
game-bot
you % me = you, bro
 
game-bot's Avatar
 
Join Date: Oct 2004
Location: Texas
Posts: 11,918
Default

http://projecteuler.net/index.php?se...roblems&id=209

What does τ mean?
__________________
game-bot is offline   Reply With Quote
Old 12-16-2009, 08:33 PM   #16
Serisium
CEO
 
Serisium's Avatar
 
Join Date: Dec 2007
Age: 15
Posts: 1,017
Default

Quote:
Originally Posted by game-bot View Post
How many 6-input binary truth tables, τ, satisfy the formula

I assume it means a 6-input binary truth table.
__________________


Serisium is offline   Reply With Quote
Old 12-16-2009, 08:37 PM   #17
game-bot
you % me = you, bro
 
game-bot's Avatar
 
Join Date: Oct 2004
Location: Texas
Posts: 11,918
Default

Er, didn't see that part ,τ, part. Thanks.

On a side note, I just did problem 11 with nothing but ctrl+F and 2 minutes =P
__________________

Last edited by game-bot; 12-16-2009 at 10:12 PM.
game-bot is offline   Reply With Quote
Old 12-18-2009, 05:40 PM   #18
game-bot
you % me = you, bro
 
game-bot's Avatar
 
Join Date: Oct 2004
Location: Texas
Posts: 11,918
Default

Am I the only one doing these?

Just finished problem 54. Not too much programming insight required, but it was worth it in the fact that I now have an efficient playing card algorithm. Although if I were to make a poker game (of course, it'd be Texas Holdem), it'd need a number of tweaks, mostly for the case of ties, which this problem did not make you confront.

The whole program takes an average of ~55 ms to get the answer.

That #220 one looks interesting Serisium. You ever get it? I'm gonna do that next.

Yeah, this is a tough one. I'm down to the optimization point now. Determining D(50) takes too long with an unoptimized method. So far I've only been able to speed it up a small bit by noticing that 'b' always has at least 4 characters after it, so instead of moving the index up 5 (the length of both of the strings we're adding), it can be moved up 9. 'a' is stuck at 5. That's all I've got. Although I've noticed the following patterns:
  • The number of steps D(X) takes is equal to 2^X
  • The ending direction seems to always be South.
  • The ending x and y always have the same absolute value when X is odd. when X is even, either x or y will be zero, the one it is alternates every other even.
Not sure yet how these will allow for optimization.

EDIT

Found the pattern. I'll put it up in a bit =P

Here. Would spoiler tag it, but it'd make it hard to read.

To determine the ending posistion of D(X) without simulating the draw method or making the string, follow the pseudocode.

If X is odd,

n=floor(sqrt( ( 2^X ) / 2))
If X % 8 is 1,
x=n
y=n
If X % 8 is 3,
x=n
y=-n
If X % 8 is 5,
x=-n
y=-n
If X % 8 is 7,
x=-n
y=n
If X is even,

n=sqrt( (2^( X+1 ) ) / 2)
If X/2 is even,
If X % 8 is 4,
x=0
y=-n
Else
x=0
y=n
If X/2 is odd,
If X % 8 is 6,
x=-n
y=0
Else
x=n
y=0
Now we can easily get the x,y position of D(X). We'd use this to speed up the calculation of D(50)'s x,y after 10^12 steps by finding the biggest X with < 10^12 steps (which is 2^X), and using that as our starting position. Now to calculate the rest...

I have no idea. Is it possible? gah.

By the way, the above approach is 230x faster than the brute force.
__________________

Last edited by game-bot; 12-18-2009 at 09:14 PM.
game-bot is offline   Reply With Quote
Old 12-19-2009, 01:37 AM   #19
Blixinator
Person
 
Join Date: Oct 2004
Location: Quel'Dorei
Age: 19
Posts: 12,443
Default

Just started problem 98
http://projecteuler.net/index.php?se...problems&id=98

I'll finish it later. Already know what to do.
But I'm going to bed now
__________________
Need to contact me?
Reddit | WoW | Steam | Facebook
Blixinator is offline   Reply With Quote
Old 12-19-2009, 02:44 PM   #20
game-bot
you % me = you, bro
 
game-bot's Avatar
 
Join Date: Oct 2004
Location: Texas
Posts: 11,918
Default

I don't like the word ones ='(

I'm on solving 209 now. I don't know if it's that I'm not understanding the problem, or what, but I'm not getting the correct answer.

Code:
package projecteuler;

public class p209 {

    public static int solve() {
        return findHowManySatisfy();
    }

    private static int findHowManySatisfy() {
        int count = 0;
        boolean[] bool = new boolean[6];
        for (int b1 = 0; b1 < 2; b1++) {
            bool[0] = !bool[0];
            for (int b2 = 0; b2 < 2; b2++) {
                bool[1] = !bool[1];
                for (int b3 = 0; b3 < 2; b3++) {
                    bool[2] = !bool[2];
                    for (int b4 = 0; b4 < 2; b4++) {
                        bool[3] = !bool[3];
                        for (int b5 = 0; b5 < 2; b5++) {
                            bool[4] = !bool[4];
                            for (int b6 = 0; b6 < 2; b6++) {
                                bool[5] = !bool[5];
                                if (satisfiesTT(bool)) {
                                    count++;
                                }
                            }
                        }
                    }
                }
            }
        }
        return count;
    }

    private static boolean satisfiesTT(boolean[] b) {
        //τ(a, b, c, d, e, f) AND τ(b, c, d, e, f, a XOR (b AND c)) = 0
        boolean p2[] = new boolean[6];
        p2[0] = b[1];
        p2[1] = b[2];
        p2[2] = b[3];
        p2[3] = b[4];
        p2[4] = b[5];
        p2[5] = b[0] ^ (b[1] & b[2]);
        for (int i = 0; i < 6; i++) {
            if (p2[i] & b[i]) {
                return false;
            }
        }
        return true;
    }
}
The above outputs 18, which is wrong. Any tips?
__________________
game-bot 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 12:58 PM.


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