/* Advent of Code 2023 Day 6 in Picat. https://adventofcode.com/2023/day/6 This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. import sat. main => go. /* $ hyperfine 'picat 6.pi' Benchmark 1: picat 6.pi Time (mean ± σ): 2.124 s ± 0.019 s [User: 2.102 s, System: 0.021 s] Range (min … max): 2.102 s … 2.168 s 10 runs */ go => Lines = read_file_lines("6.txt"), % Part 1 [Times,Distances] = [Line.split(": ").tail.map(to_int) : Line in Lines], println([counts(T,D) : {T,D} in zip(Times,Distances)].prod), % Part 2 [Time2,Distance2] = [Line.split(": ").tail.join('') : Line in Lines].map(to_int), println(counts(Time2,Distance2)), nl. counts(Time,Distance) = [1 : T in 0..Time, (Time - T)*T > Distance].len.