IP address or not?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
An IP address is a 32-bit numeric address written as four numbers separated by periods. Each number can be zero to 255.
Input: An IP address,
Valid format: a.b.c.d
where a, b, c or d can be 0
or a number not having 0
at first position.
Output: 0
or 1
Test Cases:
1.160.10.240
- valid192.001.32.47
- invalid1.2.3.
- invalid1.2.3
- invalid0.00.10.255
- invalid192.168.1.1
- valid1.2.$.4
- invalid255.160.0.34
- valid
This is code-golf, so fewest bytes will win!
code-golf string number decision-problem
New contributor
rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
 |Â
show 2 more comments
up vote
1
down vote
favorite
An IP address is a 32-bit numeric address written as four numbers separated by periods. Each number can be zero to 255.
Input: An IP address,
Valid format: a.b.c.d
where a, b, c or d can be 0
or a number not having 0
at first position.
Output: 0
or 1
Test Cases:
1.160.10.240
- valid192.001.32.47
- invalid1.2.3.
- invalid1.2.3
- invalid0.00.10.255
- invalid192.168.1.1
- valid1.2.$.4
- invalid255.160.0.34
- valid
This is code-golf, so fewest bytes will win!
code-golf string number decision-problem
New contributor
rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
I'd recommend a truthy/falsey value rather than 1/0. Or even two distinct sets of outputted values
– Jo King
1 hour ago
1
Also, some more test cases would be nice. Will the input conform to an IP address-like format or can it be stuff likeHello World!
or123.-34.0.1*2
?
– Jo King
1 hour ago
I will add some test cases soon!
– rv7
1 hour ago
You didn't really answer any questions about the format. For example, the python answer fails a case likea.b.c.d
– Jo King
1 hour ago
Why1.1.1.999
is lost
– l4m2
1 hour ago
 |Â
show 2 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
An IP address is a 32-bit numeric address written as four numbers separated by periods. Each number can be zero to 255.
Input: An IP address,
Valid format: a.b.c.d
where a, b, c or d can be 0
or a number not having 0
at first position.
Output: 0
or 1
Test Cases:
1.160.10.240
- valid192.001.32.47
- invalid1.2.3.
- invalid1.2.3
- invalid0.00.10.255
- invalid192.168.1.1
- valid1.2.$.4
- invalid255.160.0.34
- valid
This is code-golf, so fewest bytes will win!
code-golf string number decision-problem
New contributor
rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
An IP address is a 32-bit numeric address written as four numbers separated by periods. Each number can be zero to 255.
Input: An IP address,
Valid format: a.b.c.d
where a, b, c or d can be 0
or a number not having 0
at first position.
Output: 0
or 1
Test Cases:
1.160.10.240
- valid192.001.32.47
- invalid1.2.3.
- invalid1.2.3
- invalid0.00.10.255
- invalid192.168.1.1
- valid1.2.$.4
- invalid255.160.0.34
- valid
This is code-golf, so fewest bytes will win!
code-golf string number decision-problem
code-golf string number decision-problem
New contributor
rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 6 mins ago
New contributor
rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 1 hour ago
rv7
1063
1063
New contributor
rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
I'd recommend a truthy/falsey value rather than 1/0. Or even two distinct sets of outputted values
– Jo King
1 hour ago
1
Also, some more test cases would be nice. Will the input conform to an IP address-like format or can it be stuff likeHello World!
or123.-34.0.1*2
?
– Jo King
1 hour ago
I will add some test cases soon!
– rv7
1 hour ago
You didn't really answer any questions about the format. For example, the python answer fails a case likea.b.c.d
– Jo King
1 hour ago
Why1.1.1.999
is lost
– l4m2
1 hour ago
 |Â
show 2 more comments
1
I'd recommend a truthy/falsey value rather than 1/0. Or even two distinct sets of outputted values
– Jo King
1 hour ago
1
Also, some more test cases would be nice. Will the input conform to an IP address-like format or can it be stuff likeHello World!
or123.-34.0.1*2
?
– Jo King
1 hour ago
I will add some test cases soon!
– rv7
1 hour ago
You didn't really answer any questions about the format. For example, the python answer fails a case likea.b.c.d
– Jo King
1 hour ago
Why1.1.1.999
is lost
– l4m2
1 hour ago
1
1
I'd recommend a truthy/falsey value rather than 1/0. Or even two distinct sets of outputted values
– Jo King
1 hour ago
I'd recommend a truthy/falsey value rather than 1/0. Or even two distinct sets of outputted values
– Jo King
1 hour ago
1
1
Also, some more test cases would be nice. Will the input conform to an IP address-like format or can it be stuff like
Hello World!
or 123.-34.0.1*2
?– Jo King
1 hour ago
Also, some more test cases would be nice. Will the input conform to an IP address-like format or can it be stuff like
Hello World!
or 123.-34.0.1*2
?– Jo King
1 hour ago
I will add some test cases soon!
– rv7
1 hour ago
I will add some test cases soon!
– rv7
1 hour ago
You didn't really answer any questions about the format. For example, the python answer fails a case like
a.b.c.d
– Jo King
1 hour ago
You didn't really answer any questions about the format. For example, the python answer fails a case like
a.b.c.d
– Jo King
1 hour ago
Why
1.1.1.999
is lost– l4m2
1 hour ago
Why
1.1.1.999
is lost– l4m2
1 hour ago
 |Â
show 2 more comments
3 Answers
3
active
oldest
votes
up vote
2
down vote
JavaScript (Node.js), 54 bytes
x=>x.split`.`.every(t=>!k--<=t&t<256&+t+x==t+x,k=4)*!k
Try it online!
I have added some test cases!
– rv7
1 hour ago
@rv7 Still problem?
– l4m2
1 hour ago
add a comment |Â
up vote
1
down vote
05AB1E, 19 bytes
'.¡©g4Q®0Å?_*®žz‹«P
Try it online or verify all test cases.
Explanation:
'.¡ '# Split the input by "."
© # Save it in the register (without popping)
g4Q # Check if the size is 4
®0Å?_ # Check for each that they do NOT start with a "0"
®žz‹ # Check if each is smaller than 256
* « # Merge all results together
P # Check if all are truthy (and output implicitly)
add a comment |Â
up vote
0
down vote
Retina 0.8.2, 24 bytes
.0
a
d+.d+.d+.d+
Try it online!
255.160.0.34
is a valid IP address
– rv7
6 mins ago
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
JavaScript (Node.js), 54 bytes
x=>x.split`.`.every(t=>!k--<=t&t<256&+t+x==t+x,k=4)*!k
Try it online!
I have added some test cases!
– rv7
1 hour ago
@rv7 Still problem?
– l4m2
1 hour ago
add a comment |Â
up vote
2
down vote
JavaScript (Node.js), 54 bytes
x=>x.split`.`.every(t=>!k--<=t&t<256&+t+x==t+x,k=4)*!k
Try it online!
I have added some test cases!
– rv7
1 hour ago
@rv7 Still problem?
– l4m2
1 hour ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
JavaScript (Node.js), 54 bytes
x=>x.split`.`.every(t=>!k--<=t&t<256&+t+x==t+x,k=4)*!k
Try it online!
JavaScript (Node.js), 54 bytes
x=>x.split`.`.every(t=>!k--<=t&t<256&+t+x==t+x,k=4)*!k
Try it online!
edited 1 hour ago
answered 1 hour ago
l4m2
3,7781430
3,7781430
I have added some test cases!
– rv7
1 hour ago
@rv7 Still problem?
– l4m2
1 hour ago
add a comment |Â
I have added some test cases!
– rv7
1 hour ago
@rv7 Still problem?
– l4m2
1 hour ago
I have added some test cases!
– rv7
1 hour ago
I have added some test cases!
– rv7
1 hour ago
@rv7 Still problem?
– l4m2
1 hour ago
@rv7 Still problem?
– l4m2
1 hour ago
add a comment |Â
up vote
1
down vote
05AB1E, 19 bytes
'.¡©g4Q®0Å?_*®žz‹«P
Try it online or verify all test cases.
Explanation:
'.¡ '# Split the input by "."
© # Save it in the register (without popping)
g4Q # Check if the size is 4
®0Å?_ # Check for each that they do NOT start with a "0"
®žz‹ # Check if each is smaller than 256
* « # Merge all results together
P # Check if all are truthy (and output implicitly)
add a comment |Â
up vote
1
down vote
05AB1E, 19 bytes
'.¡©g4Q®0Å?_*®žz‹«P
Try it online or verify all test cases.
Explanation:
'.¡ '# Split the input by "."
© # Save it in the register (without popping)
g4Q # Check if the size is 4
®0Å?_ # Check for each that they do NOT start with a "0"
®žz‹ # Check if each is smaller than 256
* « # Merge all results together
P # Check if all are truthy (and output implicitly)
add a comment |Â
up vote
1
down vote
up vote
1
down vote
05AB1E, 19 bytes
'.¡©g4Q®0Å?_*®žz‹«P
Try it online or verify all test cases.
Explanation:
'.¡ '# Split the input by "."
© # Save it in the register (without popping)
g4Q # Check if the size is 4
®0Å?_ # Check for each that they do NOT start with a "0"
®žz‹ # Check if each is smaller than 256
* « # Merge all results together
P # Check if all are truthy (and output implicitly)
05AB1E, 19 bytes
'.¡©g4Q®0Å?_*®žz‹«P
Try it online or verify all test cases.
Explanation:
'.¡ '# Split the input by "."
© # Save it in the register (without popping)
g4Q # Check if the size is 4
®0Å?_ # Check for each that they do NOT start with a "0"
®žz‹ # Check if each is smaller than 256
* « # Merge all results together
P # Check if all are truthy (and output implicitly)
answered 13 mins ago


Kevin Cruijssen
32k554173
32k554173
add a comment |Â
add a comment |Â
up vote
0
down vote
Retina 0.8.2, 24 bytes
.0
a
d+.d+.d+.d+
Try it online!
255.160.0.34
is a valid IP address
– rv7
6 mins ago
add a comment |Â
up vote
0
down vote
Retina 0.8.2, 24 bytes
.0
a
d+.d+.d+.d+
Try it online!
255.160.0.34
is a valid IP address
– rv7
6 mins ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Retina 0.8.2, 24 bytes
.0
a
d+.d+.d+.d+
Try it online!
Retina 0.8.2, 24 bytes
.0
a
d+.d+.d+.d+
Try it online!
answered 13 mins ago
Okx
12.2k27100
12.2k27100
255.160.0.34
is a valid IP address
– rv7
6 mins ago
add a comment |Â
255.160.0.34
is a valid IP address
– rv7
6 mins ago
255.160.0.34
is a valid IP address– rv7
6 mins ago
255.160.0.34
is a valid IP address– rv7
6 mins ago
add a comment |Â
rv7 is a new contributor. Be nice, and check out our Code of Conduct.
rv7 is a new contributor. Be nice, and check out our Code of Conduct.
rv7 is a new contributor. Be nice, and check out our Code of Conduct.
rv7 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174455%2fip-address-or-not%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
I'd recommend a truthy/falsey value rather than 1/0. Or even two distinct sets of outputted values
– Jo King
1 hour ago
1
Also, some more test cases would be nice. Will the input conform to an IP address-like format or can it be stuff like
Hello World!
or123.-34.0.1*2
?– Jo King
1 hour ago
I will add some test cases soon!
– rv7
1 hour ago
You didn't really answer any questions about the format. For example, the python answer fails a case like
a.b.c.d
– Jo King
1 hour ago
Why
1.1.1.999
is lost– l4m2
1 hour ago