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

6.629 ms

+/- 0.501 ms

JS

18.094 ms

+/- 1.207 ms

Native

2.128 ms

+/- 0.099 ms

Part 2

Mean

Error

JVM

10.288 ms

+/- 2.129 ms

JS

32.922 ms

+/- 0.428 ms

Native

9.184 ms

+/- 0.116 ms

Run it in the browser!