Files
advent_of_code/2016/1/main.ua

25 lines
756 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# aoc 2016/1
&fras $ input.txt
°/$"_, _" ⍜⇌↘₁
∧◇(⍥\+⋕ ⍣(
⍩⊙⍜⊢(×i) °(⊂@L)
| ⍩⊙⍜⊢(ׯi) °(⊂@R))
)⊙i_0
⌵+°ℂ⊣
$Part₁
# the idea is to represent our position
# as a complex number (2d vector). rotate by
# 90 or -90 degrees when you encounter L or R
# by multiplying by i or -i on the direction
# vector.
# this can be done by folding with the initial
# values i (direction) and 0 (position), pattern-
# matching the next token on L or R and recognizing
# them by ⍩.
# once the direction vector has been rotated
# accordingly, ⍥\+⋕ to add the direction unit vector
# to the position vector n times for token Ln or Rn.
#
# we can see many awesome pieces of functional and
# array oriented code!