Skip to content

Commit 829e9c1

Browse files
authored
Add files via upload
1 parent a263717 commit 829e9c1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

4 thought/4 thought.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'''https://open.kattis.com/problems/4thought'''
2+
3+
def fours(n):
4+
5+
if n>256 or n<-256:
6+
return None
7+
8+
9+
10+
usage = ['+', '-','//','*']
11+
12+
for i in usage:
13+
for j in usage:
14+
for k in usage:
15+
combination = '4 '+i+' 4 '+j+' 4 '+k+' 4'
16+
#print(i,j,k,' ==> ',combination,' ==> ',eval(combination))
17+
if eval(combination) == n:
18+
if '//' in combination:
19+
combination = combination.replace('//','/')
20+
21+
return combination + ' = {}'.format(n)
22+
23+
24+
25+
times = int(input())
26+
27+
for i in range(times):
28+
result = fours(int(input()))
29+
if result == None:
30+
print('no solution')
31+
32+
else:
33+
print(result)

0 commit comments

Comments
 (0)