Countdown - Numbers Round.

Countdown - Numbers Round. And README inclusion.
This commit is contained in:
Jeremias Moreira Gomes 2022-10-07 21:13:04 -03:00
parent 0879d79bfb
commit c7185e870e
4 changed files with 156 additions and 0 deletions

62
Countdown/README.md Normal file
View File

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

View File

@ -0,0 +1,92 @@
#!/usr/bin/python
import sys
import copy
import argparse
import itertools
def parse_arguments():
parser = argparse.ArgumentParser(description = 'Countdown - Numbers Game',
add_help = False)
parser._optionals.title = 'Target and List Numbers'
parser.add_argument('-h', '--help', action = 'help',
default = argparse.SUPPRESS,
help = 'Countdown Numbers Game. Inform a list of six numbers (-l) and a target (-t).')
parser.add_argument('-t', '--target', type = int, action = 'store',
dest = 'target', default = 100, help = 'The target of the game.')
parser.add_argument('-l', '--list', type = int, nargs = '+',
default = [1, 2, 4, 8, 10, 25], help = 'List with six integers.')
arguments = parser.parse_args()
return arguments
pd = {}
def nubmers_game(L, t, s, ol):
global pd
ops = ['+', '-', '*', '/']
ss = copy.deepcopy(s)
key = str((ss, L))
if key in pd:
return pd[key]
if len(L) == 1:
if L[0] == t:
print(f'Target: {t}\nNumbers: {ol}\nSolution: {ss}')
return True
else:
pd[key] = False
return False
else:
for c in itertools.combinations(L, 2):
if not c[0] or not c[1]:
continue
tmp = L[:]
tmp.remove(c[0])
tmp.remove(c[1])
exp1 = f'{c[0]} %s {c[1]}'
exp2 = f'{c[1]} %s {c[0]}'
if nubmers_game(tmp + [c[0] + c[1]], t, ss + [exp1 % ('+')], ol):
return True
elif nubmers_game(tmp + [c[0] - c[1]], t, ss + [exp1 % ('-')], ol):
return True
elif nubmers_game(tmp + [c[1] - c[0]], t, ss + [exp2 % ('-')], ol):
return True
elif nubmers_game(tmp + [c[0] * c[1]], t, ss + [exp1 % ('*')], ol):
return True
elif c[0] % c[1] == 0 and nubmers_game(tmp + [c[0] // c[1]], t, ss + [exp1 % ('/')], ol):
return True
elif c[1] % c[0] == 0 and nubmers_game(tmp + [c[1] // c[0]], t, ss + [exp2 % ('/')], ol):
return True
elif nubmers_game(tmp + [c[0]], t, ss, ol):
return True
elif nubmers_game(tmp + [c[1]], t, ss, ol):
return True
pd[key] = False
return False
if __name__ == '__main__':
args = parse_arguments()
if len(args.list) != 6:
print(f'The set of numbers in Countdown is 6.')
sys.exit(-1)
if args.target < 0 or args.target > 999:
print(f'The target number in Countdown is between 0 and 999.')
sys.exit(-1)
if not nubmers_game(args.list, args.target, [], args.list):
print(f'Target: {args.target}')
print(f'Numbers: {args.list}')
print(f'Solution: Not found.')

View File

@ -0,0 +1 @@

View File

@ -196,6 +196,7 @@ So far, the following projects have been integrated to this repo:
|[Pressure_Converter](https://github.com/E-wave112/Awesome-Python-Scripts/tree/master/Pressure_Converter)|[E-Wave](https://github.com/E-wave112)| |[Pressure_Converter](https://github.com/E-wave112/Awesome-Python-Scripts/tree/master/Pressure_Converter)|[E-Wave](https://github.com/E-wave112)|
| [File Carving](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/File_Carving) | [Yeryeong Kim](https://github.com/icarusicarus/) | | [File Carving](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/File_Carving) | [Yeryeong Kim](https://github.com/icarusicarus/) |
|[Google Meet Joiner](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/google_meet_joiner)|[JohanSanSebastian](https://github.com/JohanSanSebastian)| |[Google Meet Joiner](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/google_meet_joiner)|[JohanSanSebastian](https://github.com/JohanSanSebastian)|
|[Countdown](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Countdown)|[Jeremias Gomes](https://github.com/j3r3mias)|
## How to use : ## How to use :