Project Euler #220: Heighway Dragon

Sort by

recency

|

8 Discussions

|

  • + 0 comments

    i have this lengthy solution, if anybody can suggest better

    a = 'arbfr'
    b = 'lfalb'
    
    def moves(d0, m):
        x,y = 0,0
        directions = ["north","east","south","west"]
        current = "north"
        count = 0
        for i in range(len(d0)):
            if d0[i]=="l":
                current = directions[(directions.index(current)+3)%4]
            elif d0[i]=="r":
                current = directions[(directions.index(current)+1)%4]
            elif d0[i]=="f":
                count = count +1
                if current=="north":
                    y = y+1
                elif current=="east":
                    x = x+1
                elif current=="south":
                    y = y-1
                elif current=="west":
                    x = x-1  
            if count == m:
                return (x,y)
            else:
                continue
    
    for _ in range(int(input())):
        d0 = 'fa'
        n = int(input())
        m = int(input(),16)
        
        for i in range(n):
            d0 = list(d0)
            for j in range(len(d0)):
                if d0[j]=="a":
                    d0[j] = a
                    j = j+5
                elif d0[j]=="b":
                    d0[j] = b
                    j = j+5
            d0 = "".join(d0)
            
        final_pos = moves(d0,m)
        print('{:X}'.format(final_pos[0]))
        print('{:X}'.format(final_pos[1]))
    
  • + 1 comment

    Hi Bayleef. It appears that no matter how i optimize the solution, it never passes exactly 11-15 test cases. Can you please confirm, just to be sure, that these test cases are still correct? I run 100 queries with whatever m and n (within the constraints), and execution time never exceed second (usually it's less than 0.01 sec for 100 queries with any crazy ms i can think off). I tried looking for insight and solutions from discussion thread from original project euler site, and best of the posted solutions don't pass these tests cases too. Exactly these five (11-15) tests cases. Approaches in solutions used are either the same, or not that much superior.

    It would be really helpfull to have confidence that these tests at this moment are definitely correct. Thank you in advance!

  • + 1 comment

    From to , : do we first apply the rule, then the rule every time?

  • + 0 comments

    kcrhur hvighuiyrotuqr;gh nrgjjhhu rijiouhiu8rkjgt98ufe9i59086tvx 89wegth g te 4utg gtybig thuuit5 totrgfjffmnjkfhlkhduitilt8496 5896 86y8ut tjkigbjv g

  • + 0 comments

    Strong Text