Skip to content

Instantly share code, notes, and snippets.

@LdBeth
Last active December 9, 2022 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LdBeth/b8efabc2e976e524b3519dec08195063 to your computer and use it in GitHub Desktop.
Save LdBeth/b8efabc2e976e524b3519dec08195063 to your computer and use it in GitHub Desktop.
⎕VR 'foo'
∇ hist←foo ins;head;end;m
[1] hist←⊂0 0
[2] head←0 0
[3] end←0 0
[4] :For m :In ins
[5] head+←m
[6] :If ∨/2≤|head-end
[7] end+←×head-end
[8] hist,←⊂end
[9] :EndIf
[10] :EndFor
[11] hist←∪hist
⎕VR 'foo2'
∇ hist←foo2 ins;ends;m;i;d
[1] hist←⊂0 0
[2] ends←10/(⊂0 0)
[3] :For m :In ins
[4] (1⊃ends)+←m
[5] :For i :In ⍳9
[6] :If ∨/2≤|d←(i⊃ends)-((1+i)⊃ends)
[7] ((1+i)⊃ends)+←×d
[8] :EndIf
[9] :EndFor
[10] hist,←⊂10⊃ends
[11] :EndFor
[12] hist←∪hist
⎕VR 'ins'
∇ ins←{
[1] n←⊃(//)⎕VFI ⍵
[2] 'R'=⊃⍵:n/(⊂0 1)
[3] 'L'=⊃⍵:n/(⊂0 ¯1)
[4] 'U'=⊃⍵:n/(⊂1 0)
[5] 'D'=⊃⍵:n/(⊂¯1 0)
[6] }
data←⊃,/ins¨⊃⎕NGET'input.txt'1
⊢part1←⍴foo data
⊢part2←⍴foo2 data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment