/* Find the temperature closest to 0 (code golf) in Picat. https://codegolf.stackexchange.com/questions/112021/find-the-temperature-closest-to-0 """ In this exercise, you have to analyze records of temperature to find the closest to zero. Write a program that prints the temperature closest to 0 among input data. Input N, the number of temperatures to analyse (optional). This will be nonzero. The N temperatures expressed as integers ranging from -273 to 5526. Output Output the temperature closest to 0. If two temperatures are equally close, take the positive one. For instance, if the temperatures are -5 and 5, output 5. Example Input 5 1 -2 -8 4 5 Output 1 This challenge is similar to this one [https://github.com/GlenDC/Codingame/blob/master/descriptions/temperatures.md] on CodinGame, you can view the problem statement source here. Some modifications have been made to the text. """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. main => go. go ?=> % 96 chars including filename,reading the file and printing read_file_lines("find_the_temperature_closest_to_0.txt").second.split(" ").map(to_int).t.println, nl. go => true. go2 => [1,-2,-8,4,5].t.println, [-5,-3].t.println, % -> -3 [1,-2,-8,4,5].t2.println, [-5,-3].t2.println, % -> -3 nl. % From a Python solution % 29 chars t(L)=max([(-I*I,I):I in L]).second. % 30 chars % t(L)=T[2]=>T=max([(-I*I,I):I in L]). % 20 chars + 45 chars (argmin) = 65 chars t2(L)=L[L.map(abs).a.head]. % arg min a(L)=M=>V=min(L), M=[I:I in 1..L.len,L[I]==V]. /* % Ungolfed argmin(L) = MinIxs => Min = min(L), MinIxs = [I : I in 1..L.length, L[I] == Min]. */