/* Enigma 1021: All at threes and sevens in Picat. From https://enigmaticcode.wordpress.com/2019/03/01/enigma-1021-all-at-threes-and-sevens/#comments """ For his work in detention, Johnny was set to multiply two large numbers together. One number consisted entirely of threes, the other entirely of sevens: 3333… × 7777… = ??? Surprisingly, he managed to get the correct answer. When he examined his answer he noticed that it contained exactly 7 sevens and 3 threes. How many digits were there altogether in Johnny’s answer? """ 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 => Found = false, foreach(Len3 in 10..100, Len7 in 10..100, Found = false) Three = [3.to_string() : _ in 1..Len3].join('').to_int, Seven = [7.to_string() : _ in 1..Len7].join('').to_int, Result = (Three * Seven).to_string(), if [1 : D in Result, D = '3'].len == 3, [1 : D in Result, D = '7'].len == 7 then println(len=Result.len), Found := true end end, nl. %% %% Misusing CP count/2. %% Slower. %% % go2 => % Found = false, % foreach(Len3 in 10..100, Len7 in 10..100, Found = false) % Three = [3.to_string() : _ in 1..Len3].join('').to_int, % Seven = [7.to_string() : _ in 1..Len7].join('').to_int, % Result = (Three * Seven), % ResultIntList = [I.to_int() : I in Result.to_string()], % C3 #= count(3,ResultIntList), % C7 #= count(7,ResultIntList), % if C3 #= 3, C7 #= 7 then % println([Three,Seven,Result]), % println(len=ResultIntList.len), % Found := true % end % end, % nl.