Skip to content
This repository was archived by the owner on Sep 1, 2021. It is now read-only.

Latest commit

 

History

History
107 lines (76 loc) · 1.41 KB

File metadata and controls

107 lines (76 loc) · 1.41 KB

L1: Preparing the input

Read input:

0:"5.in"
    ("BFFFBFFRLR"
     "FBBBFFBRRL"
     ...)

Partially applied = (=[...]) applied to "R", same as "R"=...

=["FFBBBBBLRL"]"R" 
    0 0 0 0 0 0 0 0 1 0

Map (') partially applied = to every character in "RB"

=["FFBBBBBLRL"]'"RB"
    (0 0 0 0 0 0 0 0 1 0
     0 0 1 1 1 1 1 0 0 0)

Reduce (/) the result with max (|), which is equivalent to OR for binary vectors

|/=["FFBBBBBLRL"]'"RB"
    0 0 1 1 1 1 1 0 1 0

Make scalar from base-2 vector

2 _sv |/=["FFBBBBBLRL"]'"RB"
    250

For each (') line in input apply previous expression as anonymous function, {...} automatically makes available first three arguments as x,y and z

{2 _sv |/=[x]'"RB"}'0:"5.in"
    549 462 167 ...

Assign result to S

S:{2 _sv |/=[x]'"RB"}'0:"5.in"
    549 462 167 ...

L2: Answer to part 1

Reduce ('/') S with max ('|')

|/S
    955

L3: Answer to part 2

"Grade down" S, gives array of indices to S which sort it

<S
    100 748 752 ...

S indexed by (@) its grade down, i.e is sorted S

S@<S
    71 72 73 74 ...

Map - to each pair (':) in sorted S

 {-':x}S@<S
    1 1 1 ... 1 2 1 1 ...

Find index of 2 (?2) in the result

{(-':x)?2}S@<S
    497

Index by it...

{x@(-':x)?2}S@<S
    568

And add one

1+{x@(-':x)?2}S@<S
    569