We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 54f8386 commit 15b7755Copy full SHA for 15b7755
ProblemSolving/evenDigits/even.py
@@ -0,0 +1,26 @@
1
+# Naive add/sub with 2 pointers
2
+
3
+def isEven(num):
4
+ for i in list(str(num).strip()):
5
+ if int(i)%2 != 0:
6
+ return False
7
+ return True
8
9
+def uniqCalc(N):
10
+ left = right = 0
11
12
+ while not isEven(N-left) and not isEven(N+right):
13
+ #print N+left, N+right, isEven(N+left), isEven(N+right)
14
+ left += 1
15
+ right += 1
16
17
+ if isEven(N-left):
18
+ return left
19
+ else:
20
+ return right
21
22
+testcases = input()
23
+for i in range(testcases):
24
+ num = input()
25
+ print "Case #"+str(i+1)+": "+str(uniqCalc(num))
26
0 commit comments