/* Advent of Code 2024 in Picat. Problem 11 https://adventofcode.com/2024/day/11 Part 1 This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. main => go. /* Hyperfine Benchmark 1: picat -g go 11_part1.pi Time (mean ± σ): 104.6 ms ± 10.2 ms [User: 77.5 ms, System: 27.0 ms] Range (min … max): 81.5 ms … 118.7 ms 25 runs */ go => File = "11.txt", L = read_file_lines(File).first.split().map(to_int).to_array, foreach(_ in 1..25) L := p1(L).to_list.flatten.to_array end, println(L.len). table n1(N) = Res => if N == 0 then Res = 1 elseif N.to_string.len mod 2 == 0 then Res = half1(N) else Res = N*2024 end. table half1(N) = [S1,S2] => S = N.to_string, Len = S.len, Half = Len // 2, S1 = S[1..Half].to_int, S2 = S[Half+1..Len].to_int. % Do a separate loop for each input number p1(L) = {n1(E) : E in L}.