Permalink
Browse files

Solved problem 17

  • Loading branch information...
krmaxwell committed May 9, 2012
1 parent f22995c commit 5bf3053af8358d349b126082adb4609032876530
Showing with 29 additions and 9 deletions.
  1. +1 −1 README.md
  2. +28 −8 prob17.py
View
@@ -16,4 +16,4 @@ My code for working through [Project Euler](https://projecteuler.net/).
* **Problem 14:** COMPLETE
* **Problem 15:** COMPLETE
* **Problem 16:** COMPLETE
-* **Problem 17:** In progress
+* **Problem 17:** COMPLETE
View
@@ -6,7 +6,9 @@
tens = ['ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
flag = False
numstr = ''
+i = 0
+'''
if len(sys.argv) == 1:
print "Give me a number"
flag = True
@@ -18,15 +20,33 @@
if n <= 0:
print "Number should be positive"
flag = True
+'''
-if not flag:
+for n in range(1,1001):
+ #numstr = ''
hundred = n/100
n = n % 100
ten = n/10
- n = n % 10
- print hundred,' ',ten,' ',n
- if hundred > 1:
- print ones[hundred-1],"hundred and"
- if ten > 2:
- print tens[ten-1]
- print ones[n-1]
+ if n >= 20:
+ n = n % 10
+
+ #print hundred,' ',ten,' ',n # debug code, to be removed
+ if hundred == 10:
+ numstr += 'onethousand'
+ elif hundred > 0:
+ numstr += ones[hundred-1]
+ if ten == 0 and n == 0:
+ numstr += 'hundred'
+ else:
+ numstr += 'hundredand'
+
+ if ten > 1:
+ numstr += tens[ten-1]
+ if n != 0:
+ numstr += ones[n-1]
+ #numstr = ''.join(hundredstr, tens[ten-1], ones[n-1])
+ #numstr = ''.join(['i' for i in xrange(numstr)])
+ #print numstr
+
+print len(numstr),'chars'
+

0 comments on commit 5bf3053

Please sign in to comment.