/* Which answer is closest to zero? in Picat. From https://www.reddit.com/r/askmath/comments/1hqjtej/what_answer_is_closest_to_zero/ """ [ an image of the problem ] The goal of this challenge is to rearrange the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, and 0 so the math problem's result is as close to zero as possible. In the image, you see 741*98=72618 -350*62=21700 = 50918 You have to use all the numbers 0-9 and each can only be used once. The record that day was 42. My best attempt was: 864*25 -739*10 =14210 I'm curious to know what the lowest possible answer could be. Is it possible to get 0 as final answer? """ The representation used below: AAA*BB - CCC*DD -------- = 0 Here are the 128 different solutions (with no leading digit) 130*97 - 485*26 = 0 135*96 - 270*48 = 0 135*96 - 480*27 = 0 138*90 - 276*45 = 0 145*76 - 290*38 = 0 145*76 - 380*29 = 0 148*70 - 296*35 = 0 160*97 - 485*32 = 0 165*78 - 429*30 = 0 170*94 - 235*68 = 0 184*95 - 230*76 = 0 184*95 - 760*23 = 0 185*92 - 370*46 = 0 185*92 - 460*37 = 0 186*45 - 279*30 = 0 186*90 - 372*45 = 0 187*92 - 506*34 = 0 195*72 - 468*30 = 0 195*84 - 273*60 = 0 217*80 - 496*35 = 0 230*76 - 184*95 = 0 235*68 - 170*94 = 0 235*68 - 940*17 = 0 237*60 - 948*15 = 0 248*95 - 310*76 = 0 248*95 - 760*31 = 0 259*86 - 301*74 = 0 270*48 - 135*96 = 0 270*63 - 945*18 = 0 273*60 - 195*84 = 0 276*45 - 138*90 = 0 279*30 - 186*45 = 0 279*30 - 465*18 = 0 290*38 - 145*76 = 0 296*35 - 148*70 = 0 296*51 - 408*37 = 0 301*74 - 259*86 = 0 306*27 - 459*18 = 0 307*58 - 614*29 = 0 309*54 - 618*27 = 0 310*76 - 248*95 = 0 310*97 - 485*62 = 0 318*60 - 795*24 = 0 328*95 - 410*76 = 0 328*95 - 760*41 = 0 345*26 - 897*10 = 0 351*96 - 702*48 = 0 360*89 - 712*45 = 0 360*91 - 728*45 = 0 370*46 - 185*92 = 0 372*45 - 186*90 = 0 380*29 - 145*76 = 0 381*90 - 762*45 = 0 406*37 - 518*29 = 0 408*37 - 296*51 = 0 408*79 - 632*51 = 0 408*92 - 736*51 = 0 410*76 - 328*95 = 0 429*30 - 165*78 = 0 451*76 - 902*38 = 0 459*18 - 306*27 = 0 460*37 - 185*92 = 0 465*18 - 279*30 = 0 468*30 - 195*72 = 0 476*53 - 901*28 = 0 480*27 - 135*96 = 0 481*70 - 962*35 = 0 485*26 - 130*97 = 0 485*26 - 970*13 = 0 485*32 - 160*97 = 0 485*32 - 970*16 = 0 485*62 - 310*97 = 0 485*62 - 970*31 = 0 486*30 - 972*15 = 0 496*35 - 217*80 = 0 504*89 - 712*63 = 0 504*91 - 728*63 = 0 506*34 - 187*92 = 0 518*29 - 406*37 = 0 614*29 - 307*58 = 0 618*27 - 309*54 = 0 618*45 - 927*30 = 0 630*27 - 945*18 = 0 632*51 - 408*79 = 0 702*48 - 351*96 = 0 702*63 - 819*54 = 0 712*45 - 360*89 = 0 712*45 - 890*36 = 0 712*63 - 504*89 = 0 716*30 - 895*24 = 0 716*40 - 895*32 = 0 728*45 - 360*91 = 0 728*45 - 910*36 = 0 728*63 - 504*91 = 0 732*60 - 915*48 = 0 732*80 - 915*64 = 0 736*51 - 408*92 = 0 748*20 - 935*16 = 0 754*31 - 806*29 = 0 760*23 - 184*95 = 0 760*31 - 248*95 = 0 760*41 - 328*95 = 0 762*45 - 381*90 = 0 782*53 - 901*46 = 0 795*24 - 318*60 = 0 806*29 - 754*31 = 0 819*54 - 702*63 = 0 890*36 - 712*45 = 0 895*24 - 716*30 = 0 895*32 - 716*40 = 0 897*10 - 345*26 = 0 901*28 - 476*53 = 0 901*46 - 782*53 = 0 902*38 - 451*76 = 0 910*36 - 728*45 = 0 915*48 - 732*60 = 0 915*64 - 732*80 = 0 927*30 - 618*45 = 0 935*16 - 748*20 = 0 940*17 - 235*68 = 0 945*18 - 270*63 = 0 945*18 - 630*27 = 0 948*15 - 237*60 = 0 962*35 - 481*70 = 0 970*13 - 485*26 = 0 970*16 - 485*32 = 0 970*31 - 485*62 = 0 972*15 - 486*30 = 0 This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. import cp. main => go. % Using permutation/1: 0.795s go ?=> permutation([A1,A2,A3, B1,B2, C1,C2,C3, D1,D2], 0..9), A1 > 0, B1 > 0, C1 > 0, D1 > 0, ((100*A1+10*A2+A3)*(10*B1+B2)) - (100*C1+10*C2+C3)*(10*D1+D2) == 0, printf("%d%d%d*%d%d - %d%d%d*%d%d = 0\n",A1,A2,A3,B1,B2,C1,C2,C3,D1,D2), fail, nl. go => true. % CP: 0.177s go2 ?=> X = new_list(10), X :: 0..9, all_different(X), [A1,A2,A3, B1,B2, C1,C2,C3, D1,D2] = X, A1 #> 0, B1 #> 0, C1 #> 0, D1 #> 0, ((100*A1+10*A2+A3)*(10*B1+B2)) - (100*C1+10*C2+C3)*(10*D1+D2) #= 0, solve($[ff,degree,updown],X), printf("%d%d%d*%d%d - %d%d%d*%d%d = 0\n",A1,A2,A3,B1,B2,C1,C2,C3,D1,D2), fail, nl. go2 => true.