blob: 5afbbce15fc019a46eb8e4dcea680cf75052b467 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#!/usr/bin/env python3
# Challenge 044
#
# TASK #2
# Make it $200
# You have only $1 left at the start of the week. You have been given an
# opportunity to make it $200. The rule is simple with every move you can either
# double what you have or add another $1. Write a script to help you get $200
# with the smallest number of moves.
min_moves = "+".join(["1" for x in range(200)])
def find_min_moves(moves, num):
global min_moves
if num > 200:
pass
elif num == 200:
if len(moves) < len(min_moves):
min_moves = moves
else:
find_min_moves(moves+"*2", num*2)
find_min_moves(moves+"+1", num+1)
find_min_moves("1", 1)
print(min_moves)
|