diff options
author | Leah Neukirchen <leah@vuxu.org> | 2020-12-13 16:34:55 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2020-12-13 16:34:55 +0100 |
commit | 6f632d4daff51d874e049bcdd168366fd1b4c71c (patch) | |
tree | 690190640f7b064938c898d8ec6a94d3b907d413 /day12.ijs | |
parent | cc9dc71b287c001b1dc5f61a59a770d805d65659 (diff) | |
download | adventofcode2020-6f632d4daff51d874e049bcdd168366fd1b4c71c.tar.gz adventofcode2020-6f632d4daff51d874e049bcdd168366fd1b4c71c.tar.xz adventofcode2020-6f632d4daff51d874e049bcdd168366fd1b4c71c.zip |
day12
Diffstat (limited to 'day12.ijs')
-rw-r--r-- | day12.ijs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/day12.ijs b/day12.ijs new file mode 100644 index 0000000..e5301ed --- /dev/null +++ b/day12.ijs @@ -0,0 +1,35 @@ +load 'aoc.ijs' +d =: ({.;".@}.) every lines 'day12' + +rotl =: ] ({. ,~ [: - {:)@[&0~ 90 %~ [ + +step1 =: 4 : 0 +'xx yy dx dy' =. y +'ins n' =. x +select. ins +case. 'N' do. y + 0,n,0,0 +case. 'S' do. y - 0,n,0,0 +case. 'E' do. y + n,0,0,0 +case. 'W' do. y - n,0,0,0 +case. 'L' do. xx,yy,n rotl dx,dy +case. 'R' do. xx,yy,(360 - n) rotl dx,dy +case. 'F' do. y + n*dx,dy,0,0 +end. +) + ++/|2 {. 0 0 1 0 (step1 F.. ]) d NB. 1294 + +step2 =: 4 : 0 +'ins n' =. x +select. {. ins +case. 'N' do. y + 0,0,0,n +case. 'S' do. y - 0,0,0,n +case. 'E' do. y + 0,0,n,0 +case. 'W' do. y - 0,0,n,0 +case. 'L' do. (2{.y),n rotl 2}.y +case. 'R' do. (2{.y),(360-n) rotl 2}.y +case. 'F' do. y + n*(2}.y),0,0 +end. +) + ++/|2 {. 0 0 10 1 (step2 F.. ]) d NB. 20592 |