-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
68 lines (48 loc) · 1.31 KB
/
main.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import sys
def filled(value):
return f"\033[30;47m {value} \033[0m"
def dimmed(value):
return f"\033[2m{value}\033[0m"
def blue(value):
return f"\033[34m{value}\033[0m"
def red(value):
return f"\033[91m{value}\033[0m"
print("Picross Helper")
print(blue("https://github.com/jakubito/picross-helper"))
while True:
try:
line_length = int(input("\nEnter line length: "))
except ValueError:
print(red("Invalid input"))
else:
break
while True:
user_input = input("\n> ")
if not user_input:
continue
if user_input in ("exit", "quit", "stop"):
sys.exit(0)
try:
hints = list(map(int, user_input.split()))
except ValueError:
print(red("Invalid input"))
continue
hints_total = sum(hints) + len(hints) - 1
delta = line_length - hints_total
if delta < 0:
print(red("Line length exceeded"))
continue
output = list()
empty = 0
for hint in hints:
if hint > delta:
if empty + delta > 0:
output.append(empty + delta)
output.append(filled(hint - delta))
empty = 1
else:
empty += hint + 1
if output:
print(dimmed(" ⟶ ").join(map(str, output)))
else:
print(blue("No squares to fill"))