/* Brain Twister #80: Iccanobif numbers in Picat. From https://enigmaticcode.wordpress.com/2025/07/03/braintwister-80-iccanobif-numbers/ """ From New Scientist #3550, 5th July 2025 [link] [link] Iccanobif numbers are formed by following this procedure: reverse the digits of the two previous terms and add the resulting numbers together. The first two terms are 1, 1. These numbers match the Fibonacci sequence for the first few terms. After how many terms do the sequences first differ? There are two terms with four digits. What are they? Unlike Fibonacci, each Iccanobif number isn’t necessarily bigger than the previous one. When do they first decrease? """ Here's the output: 1 = 1 = 1 2 = 1 = 1 3 = 2 = 2 4 = 3 = 3 5 = 5 = 5 6 = 8 = 8 7 = 13 = 13 8 = 39 = 21 First diff 9 = 124 = 34 10 = 514 = 55 11 = 836 = 89 12 = 1053 = 144 Four digits 13 = 4139 = 233 Four digits 14 = 12815 = 377 15 = 61135 = 610 16 = 104937 = 987 17 = 792517 = 1597 18 = 1454698 = 2584 19 = 9679838 = 4181 20 = 17354310 = 6765 21 = 9735140 = 10946 First less 22 = 1760750 = 17711 23 = 986050 = 28657 24 = 621360 = 46368 25 = 113815 = 75025 26 = 581437 = 121393 27 = 1252496 = 196418 28 = 7676706 = 317811 29 = 13019288 = 514229 30 = 94367798 = 832040 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 ?=> CheckEqual = true, CheckLess = true, Prev = 1, foreach(N in 1..30) I = fi(N,iccanobif), F = fi(N,fibonacci), println(N=I=F), if CheckEqual == true,I != F then println("First diff"), CheckEqual := false, end, if I.to_string.len == 4 then println("Four digits"), end, if CheckLess, I < Prev then println("First less"), CheckLess := false end, Prev := I end, nl. go => true. rev(A) = A.to_string.reverse.to_int. table fi(1,_) = 1. fi(2,_) = 1. fi(N,Type) = P1+P2 => N > 2, P1 = fi(N-1,Type), P2 = fi(N-2,Type), if (Type == iccanobif) P1 := P1.rev, P2 := P2.rev end.