/* Facorial dot problem in Picat. From Chris Smith: https://twitter.com/aap03102/status/1054411350577999872 """ Color one blue dot, or erase one blue dot, to make a valid equation: (71+1)(71-1)=71 [Using dot matrix font.] """ The solution is to remove the second to last dot in the last '1', making it a '!', i.e. (71+1)(71-1)=7! Some comments indicate that this pattern is not very uncommon. How general is it, i.e. (N+1)*(N-1) = Y! or more general (N+M)*(N-M) = Y! Here are the possible solutions if we limit M to 0..10 and Y to 1..10. (1+0)(1-0) = 1! (1) (5+1)(5-1) = 4! (24) (7+5)(7-5) = 4! (24) (11+1)(11-1) = 5! (120) (13+7)(13-7) = 5! (120) (27+3)(27-3) = 6! (720) (28+8)(28-8) = 6! (720) (71+1)(71-1) = 7! (5040) (201+9)(201-9) = 8! (40320) This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import cp. main => go. % % M :: 0..10 % go ?=> N :: 1..1000, M :: 0..10, X :: 1..10, Fact :: 1..1_000_000, (N+M)*(N-M) #= Fact, factorial_cp(X,Fact), solve([N,M,X,Fact]), printf("(%d+%d)(%d-%d) = %d! (%d)\n",N,M,N,M,X,Fact), fail, nl. go => true. % % Larger domains. % go2 ?=> N :: 0..1000, M :: 0..1000, X :: 1..9, Fact :: 1..1_000_000, (N+M)*(N-M) #= Fact, factorial_cp(X,Fact), solve($[], [N,M,X,Fact]), printf("(%d+%d)(%d-%d) = %d! (%d)\n",N,M,N,M,X,Fact), fail, nl. go2 => true. n_factorial(0, F) ?=> F#=1. n_factorial(1, F) ?=> F#=1. n_factorial(N, F) => println($n_factorial(N, F)), N #> 0, N1 #= N - 1, F #> 0, F #= N * F1, solve([N,F]), n_factorial(N1,F1). % CP version factorial_cp(N,F) ?=> N #= 0, F #= 1. factorial_cp(N,F) => N #> 0, N #<= F, N1 #= N-1, factorial_cp(N1,F1), F #= N*F1.