/* Apocalyptic numbers in Picat. From http://www.f1compiler.com/samples/Apocalyptic%20Numbers.f1.html """ According to Clifford A. Pickover "Apocalyptic Number" is a number such that the number is 2 to the power of i, where i > 1 and the number contains "666". The following number is the first power of 2 to exhibit this feature (i = 157, i.e. 2**157): 182687704666362864775460604089535377456991567872 ^^^ Clifford also asked the following questions: Q1: are there any other apocalyptic powers for higher powers than 157. Q2: are there any "double apocalyptic powers", i.e. numbers which contains six 6's in a row. """ The first apocalyptic numbers are: [157,192,218,220,222,224,226,243,245,247,251] The first double apocalyptic numbers are: [2269,2271,2868,2870,2954,2956,5485,5651,6323,7244,7389] This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. main => go. go => garbage_collect(200_000_000), Map = get_global_map(), Map.put(count,0), Map.put(numbers,[]), Target = "666", % Target = "666666", member(N,2..20000), S = (2**N).to_string(), once(find(S,Target,From,To)), println(n=N), println(s=S), println([from=From,to=To]), Map.put(count,Map.get(count)+1), Map.put(numbers,Map.get(numbers)++[N]), if Map.get(count) <= 10 then fail else println(Map.get(numbers)) end, nl. apocalyptic(N,Target, From,To) => find((2**N).to_string(),Target,From,To). % When N is an integer: Radix = [N,N,N,...,N] base(N,List) = base([N : _I in 1..List.length],List), integer(N) => true. % Radix is a list base(Radix,List) = S, list(Radix) => S = sum([E*R :{R,E} in zip(Radix.cumprod_base().reverse(),List)]). % cumulative product (special for base) cumprod_base(List) = C => One = 1, C = [One], Len = List.length, foreach(I in Len..-1..2) One := One * List[I], C := C ++ [One] end.