Skip to content

Commit c7185e8

Browse files
committed
Countdown - Numbers Round.
Countdown - Numbers Round. And README inclusion.
1 parent 0879d79 commit c7185e8

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed

Countdown/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Countdown
2+
3+
## Description
4+
5+
Countdown is a 1982 British game show involving word and number tasks. There are
6+
two contestants in each episode that compete in three game types: letters
7+
rounds, in which the contestants attempt to make the longest word possible from
8+
nine randomly chosen letters; numbers rounds, in which the contestants must
9+
use arithmetic to reach a random target number from six other numbers; and the
10+
conundrum, a buzzer round in which the contestants compete to solve a
11+
nine-letter anagram.
12+
13+
### Letters Round
14+
The contestant in control chooses between two stacks of letter tiles, one
15+
containing vowels (A-E-I-O-U only) and the other consonants, and the assistant
16+
reveals the top tile from that stack and places it on the board. This is done
17+
nine times, and the final grouping must contain at least three vowels and four
18+
consonants. The contestants then have 30 seconds to form the longest single
19+
word they can, using the nine revealed letters; no letter may be used more often
20+
than it appears in the selection.
21+
22+
#### Example
23+
Contestant One chooses five consonants, then three vowels, then another
24+
consonant.
25+
26+
Selection is: `G Y H D N O E U R`
27+
28+
Contestant One declares 7, while Contestant Two declares 8.
29+
30+
Contestant One reveals `younger`, but Contestant Two reveals `hydrogen` and
31+
scores 8 points. Contestant One does not score.
32+
33+
### Numbers Round
34+
The contestant in control chooses six of 24 shuffled face-down number tiles,
35+
arranged into two groups: 20 "small numbers" (two each of 1 to 10), and four
36+
"large numbers" of 25, 50, 75, and 100. Some special episodes replace the large
37+
numbers with 12, 37, 62, and 87. The contestant decides how many large numbers
38+
are to be used, from none to all four, after which the six tiles are randomly
39+
drawn and placed on the board. Then, a random three-digit target number is then
40+
generated by an electronic machine. The contestants have 30 seconds to work out
41+
a sequence of calculations with the numbers whose final result is as close to
42+
the target number as possible. They may use only the four basic operations of
43+
addition, subtraction, multiplication and division, and do not have to use all
44+
six numbers. A number may not be used more times than it appears on the board.
45+
Division can only be performed if the result has no remainder. Fractions are not
46+
allowed, and only positive integers may be obtained as a result at any stage of
47+
the calculation.
48+
49+
#### Example
50+
Contestant One requests two large numbers and four small numbers.
51+
52+
Selection is: 75 50 2 3 8 7
53+
54+
Randomly generated target is: 812
55+
56+
Contestant One declares 813, while Contestant Two declares 815.
57+
58+
Contestant One is closer and so reveals: 75 + 50 – 8 = 117, and 117 × 7 – (3 ×
59+
2) = 813, which scores 7 points for being 1 away. Contestant Two does not score.
60+
61+
# Solvers
62+
- `numbers-round.py` is a solver for the Numbers Round.

Countdown/numbers-round.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/python
2+
3+
import sys
4+
import copy
5+
import argparse
6+
import itertools
7+
8+
9+
def parse_arguments():
10+
parser = argparse.ArgumentParser(description = 'Countdown - Numbers Game',
11+
add_help = False)
12+
13+
parser._optionals.title = 'Target and List Numbers'
14+
15+
parser.add_argument('-h', '--help', action = 'help',
16+
default = argparse.SUPPRESS,
17+
help = 'Countdown Numbers Game. Inform a list of six numbers (-l) and a target (-t).')
18+
19+
parser.add_argument('-t', '--target', type = int, action = 'store',
20+
dest = 'target', default = 100, help = 'The target of the game.')
21+
22+
parser.add_argument('-l', '--list', type = int, nargs = '+',
23+
default = [1, 2, 4, 8, 10, 25], help = 'List with six integers.')
24+
25+
arguments = parser.parse_args()
26+
27+
return arguments
28+
29+
30+
pd = {}
31+
def nubmers_game(L, t, s, ol):
32+
global pd
33+
ops = ['+', '-', '*', '/']
34+
ss = copy.deepcopy(s)
35+
key = str((ss, L))
36+
if key in pd:
37+
return pd[key]
38+
39+
if len(L) == 1:
40+
if L[0] == t:
41+
print(f'Target: {t}\nNumbers: {ol}\nSolution: {ss}')
42+
return True
43+
else:
44+
pd[key] = False
45+
return False
46+
else:
47+
for c in itertools.combinations(L, 2):
48+
if not c[0] or not c[1]:
49+
continue
50+
tmp = L[:]
51+
tmp.remove(c[0])
52+
tmp.remove(c[1])
53+
exp1 = f'{c[0]} %s {c[1]}'
54+
exp2 = f'{c[1]} %s {c[0]}'
55+
if nubmers_game(tmp + [c[0] + c[1]], t, ss + [exp1 % ('+')], ol):
56+
return True
57+
elif nubmers_game(tmp + [c[0] - c[1]], t, ss + [exp1 % ('-')], ol):
58+
return True
59+
elif nubmers_game(tmp + [c[1] - c[0]], t, ss + [exp2 % ('-')], ol):
60+
return True
61+
elif nubmers_game(tmp + [c[0] * c[1]], t, ss + [exp1 % ('*')], ol):
62+
return True
63+
elif c[0] % c[1] == 0 and nubmers_game(tmp + [c[0] // c[1]], t, ss + [exp1 % ('/')], ol):
64+
return True
65+
elif c[1] % c[0] == 0 and nubmers_game(tmp + [c[1] // c[0]], t, ss + [exp2 % ('/')], ol):
66+
return True
67+
elif nubmers_game(tmp + [c[0]], t, ss, ol):
68+
return True
69+
elif nubmers_game(tmp + [c[1]], t, ss, ol):
70+
return True
71+
pd[key] = False
72+
return False
73+
74+
75+
if __name__ == '__main__':
76+
77+
args = parse_arguments()
78+
79+
if len(args.list) != 6:
80+
print(f'The set of numbers in Countdown is 6.')
81+
sys.exit(-1)
82+
83+
if args.target < 0 or args.target > 999:
84+
print(f'The target number in Countdown is between 0 and 999.')
85+
sys.exit(-1)
86+
87+
if not nubmers_game(args.list, args.target, [], args.list):
88+
print(f'Target: {args.target}')
89+
print(f'Numbers: {args.list}')
90+
print(f'Solution: Not found.')
91+
92+

Countdown/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ So far, the following projects have been integrated to this repo:
196196
|[Pressure_Converter](https://github.com/E-wave112/Awesome-Python-Scripts/tree/master/Pressure_Converter)|[E-Wave](https://github.com/E-wave112)|
197197
| [File Carving](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/File_Carving) | [Yeryeong Kim](https://github.com/icarusicarus/) |
198198
|[Google Meet Joiner](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/google_meet_joiner)|[JohanSanSebastian](https://github.com/JohanSanSebastian)|
199+
|[Countdown](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Countdown)|[Jeremias Gomes](https://github.com/j3r3mias)|
199200

200201
## How to use :
201202

0 commit comments

Comments
 (0)