% https://open.kattis.com/problems/ghostleg % 1s 2048Mb % 1.4 Easy % % This works but is a little messy .. import util. main :- [N,M|Ns] = read_file_lines().map(split).flatten.map(to_int), writeln([n=N,m=M,ns=Ns]), Ps = [], foreach(P in Ns) Ps := Ps ++ [[P,P+1]] end, println(ps=Ps), Res = [], foreach(I in 1..N) R = I, foreach([P1,P2] in Ps) if P1 == R then R := P2 elseif P2 == R then R := P1 end end, Res := Res ++ [R] end, println(Res), L = new_list(N), foreach({R,I} in zip(Res,1..N)) nth(R,L,I) end, println(L), nl.