/* Advent of Code 2023 Day 6 in Picat. https://adventofcode.com/2023/day/5 Here's a proof of concept using CP, though it's quite slower than using list comprehensions as in 6.pi. Even though SAT might be faster for larger instances, CP is much faster to generate all solutions (using solve_all/2). This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. import cp. main => go. go => nolog, garbage_collect(200_000_000), Lines = read_file_lines("6.txt"), [Times,Distances] = [Line.split(": ").tail.map(to_int) : Line in Lines], println(day6_cp(Times,Distances)), [Time2,Distance2] = [Line.split(": ").tail.join('') : Line in Lines].map(to_int), println(day6_cp([Time2],[Distance2])), nl. day6_cp(Times,Distances) = Prod => Prod = 1, foreach({Time,Distance} in zip(Times,Distances)) T :: 0..Time, (Time - T)*T #> Distance, Prod := Prod * solve_all($[],T).len end.