Skip to content

Instantly share code, notes, and snippets.

@andersk
Last active August 29, 2015 14:21

Revisions

  1. andersk revised this gist May 27, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion flowsnake.hs
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ import Control.Applicative -- not needed in GHC 7.10
    t[a,b]=[3*a+b,2*b-a]
    _#[0,0]=0
    0#_=3
    n#p=3-3735978229407?(4^(7*(n-1)#t[(s+3)?7|s<-p]+p!!0%7))%4
    n#p=[352,6497,2466,-1]!!((n-1)#t[(s+3)?7|s<-p])?(4^p!!0%7)%4
    0&_=0
    n&p=(n-1)&t p+maximum(abs<$>sum p:p)
    n!b=n&[1,-b]
  2. andersk revised this gist May 27, 2015. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions flowsnake.hs
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,15 @@

    import Control.Applicative -- not needed in GHC 7.10

    (?)=div
    (%)=mod
    t[a,b]=[3*a+b,2*b-a]
    _#[0,0]=0
    0#_=3
    n#p=3-mod(div 3735978229407$4^(7*(n-1)#t[div(s+3)7|s<-p]+mod(p!!0)7))4
    0%_=0
    n%p=(n-1)%t p+maximum(abs<$>sum p:p)
    n!b=n%[1,-b]
    f n=putStr$unlines[["__ \\/ "!!(2*n#t[div a 2,-b]+mod a 2)|a<-[b-n!2+1..b+n!2+0^div n 3]]|b<-[-n!0..n!0]]
    n#p=3-3735978229407?(4^(7*(n-1)#t[(s+3)?7|s<-p]+p!!0%7))%4
    0&_=0
    n&p=(n-1)&t p+maximum(abs<$>sum p:p)
    n!b=n&[1,-b]
    f n=putStr$unlines[["__ \\/ "!!(2*n#t[a?2,-b]+a%2)|a<-[b-n!2+1..b+n!2+0^n?3]]|b<-[-n!0..n!0]]

    main=f 3
  3. andersk revised this gist May 27, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion flowsnake.hs
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,6 @@ n#p=3-mod(div 3735978229407$4^(7*(n-1)#t[div(s+3)7|s<-p]+mod(p!!0)7))4
    0%_=0
    n%p=(n-1)%t p+maximum(abs<$>sum p:p)
    n!b=n%[1,-b]
    f n=putStr$unlines[["__ \\/ "!!(2*n#t[div a 2,-b]+mod a 2)|a<-[b-n!2+1..b+n!2+fromEnum(n<3)]]|b<-[-n!0..n!0]]
    f n=putStr$unlines[["__ \\/ "!!(2*n#t[div a 2,-b]+mod a 2)|a<-[b-n!2+1..b+n!2+0^div n 3]]|b<-[-n!0..n!0]]

    main=f 3
  4. andersk revised this gist May 27, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions flowsnake.hs
    Original file line number Diff line number Diff line change
    @@ -3,12 +3,12 @@
    import Control.Applicative -- not needed in GHC 7.10

    t[a,b]=[3*a+b,2*b-a]
    _#[0,0]=3
    0#_=0
    n#p=mod(div 0xf5bf9ae65b4000$4^(7*(n-1)#t[div(s+3)7|s<-p]+mod(p!!0)7))4
    _#[0,0]=0
    0#_=3
    n#p=3-mod(div 3735978229407$4^(7*(n-1)#t[div(s+3)7|s<-p]+mod(p!!0)7))4
    0%_=0
    n%p=(n-1)%t p+maximum(abs<$>sum p:p)
    n!b=n%[1,-b]
    f n=putStr$unlines[[" \\/ __"!!(2*n#t[div a 2,-b]+mod a 2)|a<-[b-n!2+1..b+n!2+fromEnum(n<3)]]|b<-[-n!0..n!0]]
    f n=putStr$unlines[["__ \\/ "!!(2*n#t[div a 2,-b]+mod a 2)|a<-[b-n!2+1..b+n!2+fromEnum(n<3)]]|b<-[-n!0..n!0]]

    main=f 3
  5. andersk revised this gist May 27, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions flowsnake.hs
    Original file line number Diff line number Diff line change
    @@ -5,9 +5,9 @@ import Control.Applicative -- not needed in GHC 7.10
    t[a,b]=[3*a+b,2*b-a]
    _#[0,0]=3
    0#_=0
    n#l=mod(div 0xf5bf9ae65b4000$4^(7*(n-1)#t[div(s+3)7|s<-l]+mod(l!!0)7))4
    n#p=mod(div 0xf5bf9ae65b4000$4^(7*(n-1)#t[div(s+3)7|s<-p]+mod(p!!0)7))4
    0%_=0
    n%l=(n-1)%t l+maximum(abs<$>sum l:l)
    n%p=(n-1)%t p+maximum(abs<$>sum p:p)
    n!b=n%[1,-b]
    f n=putStr$unlines[[" \\/ __"!!(2*n#t[div a 2,-b]+mod a 2)|a<-[b-n!2+1..b+n!2+fromEnum(n<3)]]|b<-[-n!0..n!0]]

  6. andersk revised this gist May 27, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion flowsnake.hs
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ import Control.Applicative -- not needed in GHC 7.10
    t[a,b]=[3*a+b,2*b-a]
    _#[0,0]=3
    0#_=0
    n#l=mod(div 0xf5bf9ae65b4000$4^(7*(n-1)#t[div(s+3)7|s<-l]+mod(head l)7))4
    n#l=mod(div 0xf5bf9ae65b4000$4^(7*(n-1)#t[div(s+3)7|s<-l]+mod(l!!0)7))4
    0%_=0
    n%l=(n-1)%t l+maximum(abs<$>sum l:l)
    n!b=n%[1,-b]
  7. andersk revised this gist May 27, 2015. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions flowsnake.hs
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,13 @@

    import Control.Applicative -- not needed in GHC 7.10

    t[a,b]=[3*a+b,2*b-a]
    _#[0,0]=3
    0#_=0
    n#[a,b]=mod(div 0xf5bf9ae65b4000$4^(7*(n-1)#[div(s+3)7|s<-[3*a-b,a+2*b]]+mod(3*a-b)7))4
    n#l=mod(div 0xf5bf9ae65b4000$4^(7*(n-1)#t[div(s+3)7|s<-l]+mod(head l)7))4
    0%_=0
    n%(c,d)=(n-1)%(2*c-d,c+3*d)+maximum(abs<$>[c,d,c+d])
    f n=putStr$unlines[[" \\/ __"!!(2*n#[div a 2,b]+mod a 2)|a<-[b-n%(2,-1)+1..b+n%(2,-1)+fromEnum(n<3)]]|b<-[-n%(0,1)..n%(0,1)]]
    n%l=(n-1)%t l+maximum(abs<$>sum l:l)
    n!b=n%[1,-b]
    f n=putStr$unlines[[" \\/ __"!!(2*n#t[div a 2,-b]+mod a 2)|a<-[b-n!2+1..b+n!2+fromEnum(n<3)]]|b<-[-n!0..n!0]]

    main=f 3
  8. andersk revised this gist May 27, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion flowsnake.hs
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,6 @@ _#[0,0]=3
    n#[a,b]=mod(div 0xf5bf9ae65b4000$4^(7*(n-1)#[div(s+3)7|s<-[3*a-b,a+2*b]]+mod(3*a-b)7))4
    0%_=0
    n%(c,d)=(n-1)%(2*c-d,c+3*d)+maximum(abs<$>[c,d,c+d])
    f n=putStr$unlines[[" \\/ __"!!(2*n#[div a 2,b]+mod a 2)|a<-[b-max(n%(2,-1)-1)0..b+n%(2,-1)+fromEnum(n<3)]]|b<-[-n%(0,1)..n%(0,1)]]
    f n=putStr$unlines[[" \\/ __"!!(2*n#[div a 2,b]+mod a 2)|a<-[b-n%(2,-1)+1..b+n%(2,-1)+fromEnum(n<3)]]|b<-[-n%(0,1)..n%(0,1)]]

    main=f 3
  9. andersk created this gist May 23, 2015.
    12 changes: 12 additions & 0 deletions flowsnake.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    -- http://codegolf.stackexchange.com/questions/50521/ascii-art-of-the-day-2-flow-snakes

    import Control.Applicative -- not needed in GHC 7.10

    _#[0,0]=3
    0#_=0
    n#[a,b]=mod(div 0xf5bf9ae65b4000$4^(7*(n-1)#[div(s+3)7|s<-[3*a-b,a+2*b]]+mod(3*a-b)7))4
    0%_=0
    n%(c,d)=(n-1)%(2*c-d,c+3*d)+maximum(abs<$>[c,d,c+d])
    f n=putStr$unlines[[" \\/ __"!!(2*n#[div a 2,b]+mod a 2)|a<-[b-max(n%(2,-1)-1)0..b+n%(2,-1)+fromEnum(n<3)]]|b<-[-n%(0,1)..n%(0,1)]]

    main=f 3