~pmikkelsen/apl2048

9fedf63591319236eaa82c1519cc99307021416b — Peter Mikkelsen 7 months ago 4747f70
Move newnumber to seperate function, and simplify shift
2 files changed, 14 insertions(+), 15 deletions(-)

A newnumber.aplf
M swipeup.aplf
A newnumber.aplf => newnumber.aplf +8 -0
@@ 0,0 1,8 @@
 newnumber←{
     elements←,⍵
     shape←⍴⍵
     indexes←(elements∊0)/⍳×/shape
     index←indexes[?⍴indexes]
     elements[index]←(2 2 4)[?3]
     shape⍴elements
 }

M swipeup.aplf => swipeup.aplf +6 -15
@@ 1,22 1,13 @@
 swipeup←{
     swiperowup←{
         p←1
         shift←{
             i←0⌈⍺
             (i↑⍵),((i+1)↓⍵)
         }
     swiperow←{
         (⍴⍵)↑1{
             shift←{(⍺≠⍳⍴⍵)/⍵}
             (⍺+1)>⍴⍵:⍵
             ⍵[⍺]=0:⍺ ∇(⍺-1)shift ⍵
             ⍵[⍺+1]=0:⍺ ∇ ⍺ shift ⍵
             ⍵[⍺]=0:⍺ ∇ ⍺ shift ⍵
             ⍵[⍺+1]=0:⍺ ∇ (⍺+1) shift ⍵
             ⍵[⍺]≠⍵[⍺+1]:(⍺+1)∇ ⍵
             ⍵[⍺]=⍵[⍺+1]:(⍺+1)∇ ⍺ shift ((⍵[⍺]×2)@⍺)⍵
             ⍵[⍺]=⍵[⍺+1]:(⍺+1)∇ (⍺+1) shift((⍵[⍺]×2)@⍺)⍵
         }⍵
     }
     shape←⍴⍵
     elements←,⍉shape⍴∊swiperowup¨⊂[1]⍵
     indexes←(elements∊0)/⍳×/shape
     index←indexes[?⍴indexes]
     elements[index]←(2 2 4)[?2]
     shape⍴elements
     newnumber⍉(⍴⍵)⍴∊swiperow¨⊂[1]⍵
 }