Skip to main content
shaved another 2 bytes off
Source Link
mkst
  • 5.2k
  • 12
  • 19

K (oK), 37 2929 27 bytes

Solution:

+/2!.#:'=+\1 '=+\-199 -0 99 99"^v<>"?-1 1@5!

Try it online!Try it online!

Explanation:

Create list of steps, create path, group, count each repeat, if mod 2 is 0 then off, else on. Felt very AdventOfCode-ish.

+/2!.#:'=+\1 '=+\-199 -0 99 99"^v<>"?-1 1@5! / the solution
                           5! ? / lookup right in left
                   input mod 5, "^v<>"  /yields up,4 down,3 left,0 right2
           1 -1 -99 99 0 99 -1 1    / upleft, downnull, leftright, rightdown, up
         +\                   / sum along
        =                     / group into key=>value
     #:'                      / count each value
    .                         / take the value 
  2!                          / modulo 2
+/                            / sum up

Notes:

  • -8 bytes by stealing David Horák's method of squashing x-y into x (I know it has limitations, but it works for the examples)
  • -2 bytes thanks to ngn

K (oK), 37 29 bytes

Solution:

+/2!.#:'=+\1 -1 -99 99"^v<>"?

Try it online!

Explanation:

Create list of steps, create path, group, count each repeat, if mod 2 is 0 then off, else on. Felt very AdventOfCode-ish.

+/2!.#:'=+\1 -1 -99 99"^v<>"? / the solution
                            ? / lookup right in left
                      "^v<>"  / up, down, left, right
           1 -1 -99 99        / up, down, left, right
         +\                   / sum along
        =                     / group into key=>value
     #:'                      / count each value
    .                         / take the value 
  2!                          / modulo 2
+/                            / sum up

Notes:

  • -8 bytes by stealing David Horák's method of squashing x-y into x (I know it has limitations, but it works for the examples)

K (oK), 37 29 27 bytes

Solution:

+/2!.#:'=+\-99 0 99 -1 1@5!

Try it online!

Explanation:

Create list of steps, create path, group, count each repeat, if mod 2 is 0 then off, else on. Felt very AdventOfCode-ish.

+/2!.#:'=+\-99 0 99 -1 1@5! / the solution
                        5!  / input mod 5, "^v<>" yields 4 3 0 2
           -99 0 99 -1 1    / left, null, right, down, up
         +\                 / sum along
        =                   / group into key=>value
     #:'                    / count each value
    .                       / take the value 
  2!                        / modulo 2
+/                          / sum up

Notes:

  • -8 bytes by stealing David Horák's method of squashing x-y into x (I know it has limitations, but it works for the examples)
  • -2 bytes thanks to ngn
shaved off 8 bytes
Source Link
mkst
  • 5.2k
  • 12
  • 19

K (oK), 3737 29 bytes

Solution:

+/2!.#:'=+\(1'=+\1 0;-1 0;0 -1;099 1)"^v<>"99"^v<>"?

Try it online!Try it online!

Explanation:

Create list of steps, create path, group, count each repeat, if mod 2 is 0 then off, else on. Felt very AdventOfCode-ish.

+/2!.#:'=+\(1'=+\1 0;-1 0;0 -1;099 1)"^v<>"99"^v<>"? / the solution
                                    ? / lookup right in left
                              "^v<>"  / up, down, left, right
           (1 0;-1 0;0 -1;099 1)99        / up, down, left, right
         +\                           / sum along
        =                             / group into key=>value
     #:'                              / count each value
    .                                 / take the value 
  2!                                  / modulo 2
+/                                    / sum up

Notes:

  • -8 bytes by stealing David Horák's method of squashing x-y into x (I know it has limitations, but it works for the examples)

K (oK), 37 bytes

Solution:

+/2!.#:'=+\(1 0;-1 0;0 -1;0 1)"^v<>"?

Try it online!

Explanation:

Create list of steps, create path, group, count each repeat, if mod 2 is 0 then off, else on. Felt very AdventOfCode-ish.

+/2!.#:'=+\(1 0;-1 0;0 -1;0 1)"^v<>"? / the solution
                                    ? / lookup right in left
                              "^v<>"  / up, down, left, right
           (1 0;-1 0;0 -1;0 1)        / up, down, left, right
         +\                           / sum along
        =                             / group into key=>value
     #:'                              / count each value
    .                                 / take the value 
  2!                                  / modulo 2
+/                                    / sum up

K (oK), 37 29 bytes

Solution:

+/2!.#:'=+\1 -1 -99 99"^v<>"?

Try it online!

Explanation:

Create list of steps, create path, group, count each repeat, if mod 2 is 0 then off, else on. Felt very AdventOfCode-ish.

+/2!.#:'=+\1 -1 -99 99"^v<>"? / the solution
                            ? / lookup right in left
                      "^v<>"  / up, down, left, right
           1 -1 -99 99        / up, down, left, right
         +\                   / sum along
        =                     / group into key=>value
     #:'                      / count each value
    .                         / take the value 
  2!                          / modulo 2
+/                            / sum up

Notes:

  • -8 bytes by stealing David Horák's method of squashing x-y into x (I know it has limitations, but it works for the examples)
Source Link
mkst
  • 5.2k
  • 12
  • 19

K (oK), 37 bytes

Solution:

+/2!.#:'=+\(1 0;-1 0;0 -1;0 1)"^v<>"?

Try it online!

Explanation:

Create list of steps, create path, group, count each repeat, if mod 2 is 0 then off, else on. Felt very AdventOfCode-ish.

+/2!.#:'=+\(1 0;-1 0;0 -1;0 1)"^v<>"? / the solution
                                    ? / lookup right in left
                              "^v<>"  / up, down, left, right
           (1 0;-1 0;0 -1;0 1)        / up, down, left, right
         +\                           / sum along
        =                             / group into key=>value
     #:'                              / count each value
    .                                 / take the value 
  2!                                  / modulo 2
+/                                    / sum up