user
Task

Given six numbers randomly selected from the list [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 25, 50, 75, 100], calculate using only positive integers and four operations [+, -, \*, /] a random number between 101 and 999.

Example:

Using: [3, 6, 25, 50, 75, 100]  
Target: 952

Solution:

* 100 + 6 = 106
* 75 \* 3 = 225
* 106 \* 225 = 23850
* 23850 - 50 = 23800
* 23800 / 25 = 952

Origins

This is originally a 1972 French television game show. The game consists of randomly selecting six of the twenty-four numbers, from a list of: twenty "small numbers" (two each from 1 to 10), and four "large numbers" of 25, 50, 75 and 100. A random target number between 101 and 999 is generated. The players have 30 seconds to work out a sequence of calculations with the numbers whose final result is as close as possible to the target number. Only the four basic operations: addition, subtraction, multiplication and division can be used to create new numbers and not all six numbers are required. A number can only be used once. Division can only be done if the result has no remainder (fractions are not allowed) and only positive integers can be obtained at any stage of the calculation. (More info on the original game).

Extra challenge

The brute force algorithm is quite obvious. What is more interesting is to find some optimisation heuristics to reduce the number of calculations. For example, a rather interesting computational challenge is to calculate, as fast as possible, all existing solutions (that means 2'764'800 operations) for all possible games (with all the 13'243 combinations of six numbers out of twenty-four for all 898 possible targets between 101 and 999).
assistant
**Translation of**: Wren

```
# 20221021 Raku programming solution

sub countdown ($target, @numbers) {
   return False if @numbers.elems == 1;
   for @numbers.kv -> \n0k,\n0v {
      (my @nums1 = @numbers).splice(n0k,1);
      for @nums1.kv -> \n1k,\n1v {
         (my @nums2 = @nums1).splice(n1k,1);
         if n1v >= n0v {
            (my @numsNew = @nums2).append: my $res = n1v + n0v; 
            if ($res == $target or countdown($target, @numsNew)) {
               say "$res = ",n1v,' + ',n0v andthen return True
            }
	        if n0v != 1 {
               (my @numsNew = @nums2).append: my $res = n1v * n0v;	
	           if ($res == $target or countdown($target, @numsNew)) {
                  say "$res = ",n1v,' * ',n0v andthen return True
	           }
            }
            if n1v != n0v {
	           (my @numsNew = @nums2).append: my $res = n1v - n0v;
	           if ($res == $target or countdown($target, @numsNew)) {
                  say "$res = ",n1v,' - ',n0v andthen return True
               }
            }
            if n0v != 1 and n1v %% n0v {
               (my @numsNew = @nums2).append: my $res = n1v div n0v;
               if ($res == $target or countdown($target, @numsNew)) {
                  say "$res = ",n1v,' / ',n0v andthen return True
               }
            }
         }
      }
   }
   return False
}

my @allNumbers  = < 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 25 50 75 100 >;
my @numbersList = <3 6 25 50 75 100>  ,   <100 75 50 25 6 3>, 
                  <8 4 4 6 8 9>       ,   @allNumbers.pick(6);
my @targetList  = 952, 952, 594, (101..1000).pick;

for (0..^+@numbersList) -> \i {
   say "Using : ", my @numbers = |@numbersList[i];
   say "Target: ", my $target  = @targetList[i];
   say "No exact solution found" unless countdown $target, @numbers;
   say() 
}

```

Output:

```
Using : [3 6 25 50 75 100]
Target: 952
952 = 23800 / 25
23800 = 23850 - 50
23850 = 225 * 106
106 = 100 + 6
225 = 75 * 3

Using : [100 75 50 25 6 3]
Target: 952
952 = 23800 / 25
23800 = 23850 - 50
23850 = 7950 * 3
7950 = 106 * 75
106 = 100 + 6

Using : [8 4 4 6 8 9]
Target: 594
594 = 66 * 9
66 = 64 + 2
64 = 16 * 4
2 = 6 - 4
16 = 8 + 8

Using : [100 9 50 2 9 8]
Target: 599
599 = 590 + 9
590 = 59 * 10
10 = 8 + 2
59 = 109 - 50
109 = 100 + 9
```