Here's my week assignment: you have the number 237612231. Make how many IPs combination you can in any language. IP format #.#.#.# (each # hold up 1 to 3 digits)
Here's what I going to deliver in pythonv = '237612231'
print "{}.{}{}.{}{}{}.{}{}{}".format(*v) # 1 2 3 3
print "{}.{}{}{}.{}{}.{}{}{}".format(*v) # 1 3 2 3
print "{}.{}{}{}.{}{}{}.{}{}".format(*v) # 1 3 3 2
print "{}{}.{}.{}{}{}.{}{}{}".format(*v) # 2 1 3 3
print "{}{}.{}{}{}.{}.{}{}{}".format(*v) # 2 3 1 3
print "{}{}.{}{}{}.{}{}{}.{}".format(*v) # 2 3 3 1
print "{}{}.{}{}.{}{}.{}{}{}".format(*v) # 2 2 2 3
print "{}{}.{}{}.{}{}{}.{}{}".format(*v) # 2 2 3 2
print "{}{}.{}{}{}.{}{}.{}{}".format(*v) # 2 3 2 2
print "{}{}{}.{}{}.{}{}{}.{}".format(*v) # 3 2 3 1
print "{}{}{}.{}{}{}.{}{}.{}".format(*v) # 3 3 2 1
print "{}{}{}.{}.{}{}.{}{}{}".format(*v) # 3 1 2 3
print "{}{}{}.{}{}.{}.{}{}{}".format(*v) # 3 2 1 3
print "{}{}{}.{}.{}{}{}.{}{}".format(*v) # 3 1 3 2
print "{}{}{}.{}{}{}.{}.{}{}".format(*v) # 3 3 1 2
print "{}{}{}.{}{}.{}{}.{}{}".format(*v) # 3 2 2 2
I'm feeling very dumb to come up with that arbitrary solution. =(
>>57090583
999.999.999.999 isn't an IP address.
>>57090583
i dont understand the question
you have to make as many ip addresses as you can using those digits right? do they have to be in that order always?
>>57090621
Read the question. You ware given an arbitrary number
>>57090659
Yes, you have to make as many ips combination with that number in that order
>>57090680
well then in that case your solution wont work as it would output some numbers higher than 255
>>57090720
Yes, I'm aware of that
You have to focus on the format of the ip, not in if it's valid
>>57090752
its actually quite easy to fix since the numbers are in a predetermined order
hence all # 13 XX are invalid etc etc
so just delete those lines
>>57090778
code?
You should really be starting with calculating the number of permutations rather than going straight to code.
it was a shitty exercise that was supposed to be done in 1:30 hour. that was my shitty solution.
>>57094020
asking for help? I posted my solution asshole. the question was just to format the given number in the ip formart, not verify if it's a valid ip.
>>57090607
I don't know programming but:
Return every single combination with 3 dots in it
filter out any number that's longer than 3 digits without a dot point to break it
filter out any number above 255
Get a fucking brain, nerd.
>>57090583
>can't even solve this
>being this retarded
>even a pajeet like me can solve thisdef solve(s, i, lim):
if i > 3:
return
elif i == 3:
if len(s) == 3:
lim[i] = int(s)
print(lim)
return
for k in range(3):
if k + 1 < len(s):
lim[i] = int(s[:k+1])
solve(s[k+1:], i+1, lim)
if __name__ == "__main__":
s = "237612231"
solve(s, 0, [0, 0, 0, 0])
>>57094478
and if you want each part to be less than 255, just add the condition before printing
>>57094478
and this was the output[2, 37, 612, 231]
[2, 376, 12, 231]
[23, 7, 612, 231]
[23, 76, 12, 231]
[23, 761, 2, 231]
[237, 6, 12, 231]
[237, 61, 2, 231]
with the condition that no number should be greater than 255[23, 76, 12, 231]
[237, 6, 12, 231]
[237, 61, 2, 231]
>>57094510
Well, here's my output:2.37.612.231
2.376.12.231
2.376.122.31
23.7.612.231
23.761.2.231
23.761.223.1
23.76.12.231
23.76.122.31
23.761.22.31
237.61.223.1
237.612.23.1
237.6.12.231
237.61.2.231
237.6.122.31
237.612.2.31
237.61.22.31
>>57094510
23.76.122.31
Dumbass, kill yourself
>>57094712
Get rid of the numbers above 255 and you got it, champ.
>>57094729
I told you not to validate the IP, just make as much combinations IP LIKE as you can
Actual solution[23, 76, 12, 231]
[23, 76, 122, 31]
[237, 6, 12, 231]
[237, 6, 122, 31]
[237, 61, 2, 231]
[237, 61, 22, 31]
[237, 61, 223, 1]
Code:def solve(s, i, lim):
if i > 3:
return
elif i == 3:
if len(s) <= 3 and max(lim) <= 255:
lim[i] = int(s)
print(lim)
return
for k in range(3):
if k + 1 < len(s):
lim[i] = int(s[:k+1])
solve(s[k+1:], i+1, lim)
if __name__ == "__main__":
s = "237612231"
solve(s, 0, [0, 0, 0, 0])
>>57094712
well mine isn't hardcoded, idiot
>>57094729
I just forgot to put <= in line 5
>>57094769
well, that's fair.
>>57094802
how long did it took you?
>>57090583s = '237612231'
for i in range(1,4):
for j in range(1,4):
for k in range(1,4):
for l in range(1,4):
if i+j+k+l == 9:
print ('.'.join([s[0:i],s[i:i+j],s[i+j:i+j+k],s[i+j+k:i+j+k+l]]))
>>57095095
Yes, a had a similar one, but was bugged.
>>57090669
And there are no limits set on how you can use that arbitary number. For example if you times it by 9000 and use the result as the max for a range of numbers to generate IPs from -> all the possible IP's
>>57090607
>print "{}{}{}.{}{}{}.{}.{}{}".format(*v) # 3 3 1 2
>237.612.2.31