You start with a zero and try to reach exactly 100 in 4 stages, each stage consisting of either increasing or decreasing your current number by a factorial n!( number like 1,2,6,24,120,720 etc) .
How many sequences exist to accomplish this task?
5 dim H(4)
10 gosub *AddOn
20 end
1010 *AddOn
1020 local I,Ch
1030 inc Lvl
1040 for I=1 to 40
1045 Ch=!(I)
1050 Tot=Tot+Ch:H(Lvl)=Ch
1060 if Lvl=4 and Tot=100 then Ways=Ways+1:print Ways,H(1);H(2);H(3);H(4)
1070 if Lvl<4 then gosub *AddOn
1080 Tot=Tot-2*Ch:H(Lvl)=-Ch
1090 if Lvl=4 and Tot=100 then Ways=Ways+1:print Ways,H(1);H(2);H(3);H(4)
1100 if Lvl<4 then gosub *AddOn
1110 Tot=Tot+Ch
1200 next
1210 dec Lvl
1250 return
finds
1 2 2 -24 120
2 2 2 120 -24
3 2 -24 2 120
4 2 -24 120 2
5 2 120 2 -24
6 2 120 -24 2
7 -2 6 -24 120
8 -2 6 120 -24
9 -2 -24 6 120
10 -2 -24 120 6
11 -2 120 6 -24
12 -2 120 -24 6
13 6 -2 -24 120
14 6 -2 120 -24
15 6 -24 -2 120
16 6 -24 120 -2
17 6 120 -2 -24
18 6 120 -24 -2
19 -24 2 2 120
20 -24 2 120 2
21 -24 -2 6 120
22 -24 -2 120 6
23 -24 6 -2 120
24 -24 6 120 -2
25 -24 120 2 2
26 -24 120 -2 6
27 -24 120 6 -2
28 120 2 2 -24
29 120 2 -24 2
30 120 -2 6 -24
31 120 -2 -24 6
32 120 6 -2 -24
33 120 6 -24 -2
34 120 -24 2 2
35 120 -24 -2 6
36 120 -24 6 -2
That's 36 ways, but really only two fundamentally different sets of numbers: -24, 2, 2 and 120; and -24, -2, 6 and 120, with 12 permutations of the former and 24 of the latter.
|
Posted by Charlie
on 2010-03-24 12:49:05 |