Day 6: Turing Trouble

Puzzle Description

Advent of Code 2022, Day 6

Scala Center Advent of Code 2022, Day 6

This one seems like it was easy to make short, even dumb stupid 2022 me got a short answer:

def process(input: String, size: Int): Int =
  input.sliding(size).indexWhere: it =>
    it.combinations(2).forall(i => i.charAt(0) != i.charAt(1))
  + size

Benchmark

Part 1

Mean

Error

JVM

1.713 ms

+/- 0.010 ms

JS

3.707 ms

+/- 0.002 ms

Native

2.266 ms

+/- 0.002 ms

Part 2

Mean

Error

JVM

7.578 ms

+/- 0.281 ms

JS

15.881 ms

+/- 0.036 ms

Native

10.261 ms

+/- 0.016 ms

Run it in the browser!