Created
May 11, 2017 13:58
-
-
Save TApicella/16b20ab796779e60e1a4c9ae8f5946bc to your computer and use it in GitHub Desktop.
Daily Programmer 5-11-2017: Shorthand Range created by tapicella - https://repl.it/HsuW/15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Take the following inputs in shorthand range, and translate them to longhand range. | |
1,6,4,9,1,6 => [1, 6, 14, 19, 21, 26] | |
2,9..9,9 => [2, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 29] | |
5,7,0,1,9,4 => [5, 7, 10, 11, 19, 24] | |
''' | |
def parseInput(inputs): | |
tens = 0 | |
previous = -1 | |
dotmode = False | |
startval = True | |
results = [] | |
for i in inputs: | |
if startval: | |
num = int(i) | |
tens = num//10 | |
num = num+(tens*10) | |
results.append(num) | |
previous = int(i) | |
startval=False | |
elif i==',': | |
continue | |
elif i!='.': | |
num = int(i) | |
if dotmode: | |
start = (previous+1)%10 | |
larger = start > num | |
end = num+10 if larger else num | |
print("%d, %d" % (start, end)) | |
print(list(range(start, end))) | |
for j in range(((previous)+1)%10, end): | |
if j==0: | |
tens+=1 | |
jnum = j+(tens*10) | |
results.append(jnum) | |
previous=j | |
dotmode = False | |
if num <= (previous%10): | |
tens += 1 | |
num = num+(tens*10) | |
results.append(num) | |
previous = int(i) | |
elif i=='.' and not dotmode: | |
dotmode = True | |
elif i=='.': | |
continue | |
return results | |
print(parseInput('1,6,4,9,1,6')) | |
print(parseInput('2,9..9,9')) | |
print(parseInput('5,7,0,1,9,4')) | |
print(parseInput('2,9..8,9')) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment