IP Validation Challenge 2⃣5⃣5⃣.2⃣5⃣5⃣.2⃣5⃣5⃣.0⃣ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 29

IP Validation Challenge 2⃣5⃣5⃣.2⃣5⃣5⃣.2⃣5⃣5⃣.0⃣

Write an algorithm that will identify valid IPv4 addresses in dot-decimal format. IPs should be considered valid if they consist of four octets, with values between 0..255 (included). valid input: 1.2.3.4 123.45.0.86 0.0.0.0 255.255.255.255 invalid input: hello >> not a possible ip 1.2.3 >> 3 octets 1.2.3.4.5 >> 5 octets 123.456.78.90 >> 456 is greater than 255 123.023.01.102 >> 023 and 01 are not valid abc.def.sae.jei >> seriously? 222.-34.224.123 >> no negative numbers Every language is welcome!

3rd Oct 2017, 4:44 PM
Andrea Simone Costa
Andrea Simone Costa - avatar
41 Answers
3rd Oct 2017, 4:52 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 16
Marking thread. Will come back to this later.
4th Oct 2017, 12:06 AM
Hatsy Rei
Hatsy Rei - avatar
4th Oct 2017, 4:09 AM
Hatsy Rei
Hatsy Rei - avatar
+ 14
@Andrea : Edited the code accordingly!
3rd Oct 2017, 5:03 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
3rd Oct 2017, 7:26 PM
m abrate
m abrate - avatar
+ 8
https://code.sololearn.com/ci0L14KWyu3d/?ref=app
3rd Oct 2017, 5:17 PM
Ekansh
3rd Oct 2017, 5:40 PM
David Akhihiero
David Akhihiero - avatar
+ 7
I'm a bit busy today, so this one is kind of crude. https://code.sololearn.com/cIU09T5S33Cp/?ref=app
4th Oct 2017, 9:59 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
@Teja 012 is not valid so 4 example 123.123.012.123 is not a valid ip Edit: good work!
3rd Oct 2017, 4:53 PM
Andrea Simone Costa
Andrea Simone Costa - avatar
+ 4
https://code.sololearn.com/cPpz06Q8S3B0/?ref=app
3rd Oct 2017, 5:03 PM
Amr Ibrahim Khudair
Amr Ibrahim Khudair - avatar
3rd Oct 2017, 11:23 PM
Matt Wall
Matt Wall - avatar
+ 4
4th Oct 2017, 1:45 AM
Nikhil Patel
Nikhil Patel - avatar
4th Oct 2017, 2:14 PM
LunarCoffee
LunarCoffee - avatar
+ 4
@Stoyan There are some issues with your otherwise good code: - negative octets are possible - leading zeroes are allowed in your implementation Also, you could just output the method parameter instead of interpolating the octets together because the input obviously is valid at that stage.
4th Oct 2017, 3:57 PM
Armin Linzbauer
Armin Linzbauer - avatar
+ 4
Special approach: Filter using language features and behaviors, not by values Primarily by: exception, -mod behavior, recast length https://code.sololearn.com/cd03CF9McF30/?ref=app
5th Oct 2017, 10:22 PM
Kirk Schafer
Kirk Schafer - avatar
+ 3
@calvin this is cheating! ahahah!
3rd Oct 2017, 5:04 PM
Andrea Simone Costa
Andrea Simone Costa - avatar
+ 3
@amr 123.012.123.123 is not valid because 012 is not valid Edit: nice!
3rd Oct 2017, 5:05 PM
Andrea Simone Costa
Andrea Simone Costa - avatar
+ 3
fixed
3rd Oct 2017, 5:13 PM
Amr Ibrahim Khudair
Amr Ibrahim Khudair - avatar
+ 3
did I? which one?
3rd Oct 2017, 6:41 PM
David Akhihiero
David Akhihiero - avatar