All Legal combinations of digits For the 24 Game

The rules of our 24 game are based on the original card game, and quite simple:

Take 4 integers between 0 and 9, and by joining them with parentheses () and the 4 arithmetic symbols (+,-,×,÷) only, formulate an equation that gives 24.

My mother and I used to compete and see who could work out 24 using passing cars’ license plates the fastest. But then we came to a country where the majority of cars have only 3 digits in their license, so this game is no longer playable, and I am happy to ruin the fun for good (for myself).

This page lists all legal combinations of numbers (sorted) using which you can work out 24. It is sometimes still a nontrivial challenge to find the actual solution, though. In Year 7 my math teacher asked me how to get 24 using 3, 3, 7, and 7, to which I confidently answered “there’s no solution!”.

I was wrong. 24 = (3 + 3÷7) × 7.

(Also my Python code is in no way optimized… so you can write your own in minutes. Also this version does not account for powers or roots.)

33321
3322
3331
3332
3333
44221
4222
4311
4320
4321
4322
4330
4331
4333
4411
4420
4421
4422
4430
4431
4432
4433
4441
4442
4443
4444
55221
5222
5311
5321
5322
5330
5331
5332
5333
5410
5411
5421
5422
5431
5432
5433
5440
5441
5442
5443
5444
5510
5511
5521
5522
5532
5533
5541
5542
5543
5544
5551
5554
5555
66211
6220
6221
6310
6311
6320
6321
6322
6331
6332
6333
6400
6410
6411
6420
6421
6422
6430
6432
6433
6440
6441
6442
6443
6444
6510
6511
6521
6522
6531
6532
6533
6540
6542
6543
6544
6551
6553
6554
6555
6611
6620
6621
6622
6630
6631
6632
6633
6640
6641
6642
6643
6650
6651
6652
6653
6654
6655
6661
6662
6663
6664
6665
6666
77211
7221
7222
7310
7311
7321
7322
7330
7331
7332
7333
7410
7411
7421
7422
7431
7432
7433
7440
7441
7442
7443
7444
7511
7520
7521
7522
7531
7532
7533
7541
7542
7543
7544
7552
7553
7554
7621
7622
7630
7631
7632
7633
7640
7641
7642
7651
7652
7653
7654
7655
7662
7663
7664
7665
7721
7722
7731
7732
7733
7741
7742
7743
7744
7752
7754
7755
7763
7764
7765
7773
7774
88111
8210
8211
8221
8222
8300
8310
8311
8320
8321
8322
8330
8331
8332
8333
8410
8411
8420
8421
8422
8430
8431
8432
8433
8440
8441
8442
8443
8444
8511
8520
8521
8522
8530
8531
8532
8541
8542
8543
8544
8552
8553
8554
8611
8620
8621
8622
8630
8631
8632
8633
8640
8641
8642
8643
8644
8651
8652
8653
8654
8655
8662
8663
8664
8665
8666
8721
8722
8730
8731
8732
8733
8740
8741
8742
8743
8744
8751
8752
8753
8754
8755
8762
8763
8764
8765
8772
8773
8774
8811
8820
8821
8822
8830
8831
8832
8840
8841
8842
8844
8850
8851
8852
8853
8854
8855
8861
8862
8863
8864
8865
8866
8871
8872
8873
8874
8875
8880
8881
8882
8883
8884
8885
8886
99211
9221
9222
9310
9311
9320
9321
9322
9330
9331
9332
9333
9411
9421
9422
9430
9431
9432
9433
9441
9442
9443
9444
9521
9522
9530
9531
9532
9533
9541
9542
9543
9551
9552
9553
9554
9555
9611
9620
9621
9622
9631
9632
9633
9640
9641
9642
9643
9644
9650
9651
9652
9653
9654
9661
9662
9663
9664
9665
9666
9721
9731
9732
9733
9741
9742
9743
9744
9751
9752
9753
9754
9761
9762
9763
9764
9765
9766
9771
9773
9775
9821
9822
9830
9831
9832
9833
9841
9842
9843
9844
9851
9852
9853
9854
9855
9860
9861
9862
9863
9864
9865
9866
9870
9871
9872
9873
9874
9875
9876
9881
9882
9883
9884
9885
9886
9887
9931
9932
9933
9942
9943
9951
9953
9954
9955
9960
9961
9962
9963
9964
9965
9971
9973
9974
9976
9982
9983
9984
9986
9993