Type-check an expressionFixing a logic systemSolve an algebraic expressionExpand the variadic expressionJimmy these arrays downConvert a logical expression to conjunctive normal formRegular expression parserIs it a valid number theory expression?Ordinal string checkPrimality testing formulaLet's play Peg Solitaire
How is CoreiX like Corei5, i7 is related to Haswell, Ivy Bridge?
Is it bad writing or bad story telling if first person narrative contains more information than the narrator knows?
Is it a good idea to copy a trader when investing?
Would encrypting a database protect against a compromised admin account?
Does the 500 feet falling cap apply per fall, or per turn?
What's the difference between const array and static const array in C/C++
Why are parallelograms defined as quadrilaterals? What term would encompass polygons with greater than two parallel pairs?
What can cause an unfrozen indoor copper drain pipe to crack?
Peculiarities in low dimensions or low order or etc
Was the Highlands Ranch shooting the 115th mass shooting in the US in 2019
Is there an application which does HTTP PUT?
Is every story set in the future "science fiction"?
Program for finding longest run of zeros from a list of 100 random integers which are either 0 or 1
Why did Captain America age?
Was Mohammed the most popular first name for boys born in Berlin in 2018?
Why is the Sun made of light elements only?
When quoting someone, is it proper to change "gotta" to "got to" without modifying the rest of the quote?
How to evaluate sum with one million summands?
What is wrong with my code? RGB potentiometer
Why is it wrong to *implement* myself a known, published, widely believed to be secure crypto algorithm?
Why are low spin tetrahedral complexes so rare?
What does this quote in Small Gods refer to?
What does formal training in a field mean?
Why was wildfire not used during the Battle of Winterfell?
Type-check an expression
Fixing a logic systemSolve an algebraic expressionExpand the variadic expressionJimmy these arrays downConvert a logical expression to conjunctive normal formRegular expression parserIs it a valid number theory expression?Ordinal string checkPrimality testing formulaLet's play Peg Solitaire
$begingroup$
Given an infix expression, determine whether all constants are of the same type.
Operators will consist only of these dyadic operators: +-/*
Your program or function should take a valid expression string as input, and output a truthy value if the constants in the expression are of the same time, and a falsey value otherwise.
The expression will consist solely of constants, and may contain any of the following types:
- String, of the form
"String"
(Always double quotes, can be empty, no escape characters, may contain any ASCII text) - Integer, of the form
14
(Always positive or zero) - Float, of the form
7.3f
(Always positive or zero, always has a decimal component, eg14.0f
) - Byte, of the form
0x42
(0-255
, Always 2 hexadecimal characters) - Boolean, of the form
true
(true
orfalse
, case insensitive)
The expression will not contain parentheses, as order of operation doesn't affect type when no type coercion is present.
A lone constant with no operators is a valid expression.
An empty expression is not a valid expression.
You may assume that the expression string contains no whitespace outside of string literals.
Note: Alternatively you may assume that there will always be spaces between constants and operators, as seen in the testcases. If you make this assumption, please specify as such in your answer
You do not have to handle invalid expressions such as 1 +
.
Scoring
This is code-golf, so fewest bytes wins!
Test cases
(Whitespace added for readability)
2 + 3
True
"Hello" / "World"
True
true * false
True
"Hello" + 4
False
"Hello" + "4"
True
3 + 2.4f / 8
False
0xff * 0xff
True
0xff + 2
False
6
True
" " + ""
True
"4 + false" + "word"
True
code-golf string decision-problem parsing
$endgroup$
add a comment |
$begingroup$
Given an infix expression, determine whether all constants are of the same type.
Operators will consist only of these dyadic operators: +-/*
Your program or function should take a valid expression string as input, and output a truthy value if the constants in the expression are of the same time, and a falsey value otherwise.
The expression will consist solely of constants, and may contain any of the following types:
- String, of the form
"String"
(Always double quotes, can be empty, no escape characters, may contain any ASCII text) - Integer, of the form
14
(Always positive or zero) - Float, of the form
7.3f
(Always positive or zero, always has a decimal component, eg14.0f
) - Byte, of the form
0x42
(0-255
, Always 2 hexadecimal characters) - Boolean, of the form
true
(true
orfalse
, case insensitive)
The expression will not contain parentheses, as order of operation doesn't affect type when no type coercion is present.
A lone constant with no operators is a valid expression.
An empty expression is not a valid expression.
You may assume that the expression string contains no whitespace outside of string literals.
Note: Alternatively you may assume that there will always be spaces between constants and operators, as seen in the testcases. If you make this assumption, please specify as such in your answer
You do not have to handle invalid expressions such as 1 +
.
Scoring
This is code-golf, so fewest bytes wins!
Test cases
(Whitespace added for readability)
2 + 3
True
"Hello" / "World"
True
true * false
True
"Hello" + 4
False
"Hello" + "4"
True
3 + 2.4f / 8
False
0xff * 0xff
True
0xff + 2
False
6
True
" " + ""
True
"4 + false" + "word"
True
code-golf string decision-problem parsing
$endgroup$
4
$begingroup$
Does "case insensitive" for Boolean values mean that we have to support all cases? Or that we can decide which case to use?
$endgroup$
– Arnauld
Apr 30 at 16:09
$begingroup$
@Arnauld must support all cases
$endgroup$
– Skidsdev
Apr 30 at 16:31
$begingroup$
@JonathanAllan my interpretation was that we had to handle any mixture of cases (e.g.truE+fALSe
). If not I can save two bytes in my solution.
$endgroup$
– Nick Kennedy
Apr 30 at 19:50
add a comment |
$begingroup$
Given an infix expression, determine whether all constants are of the same type.
Operators will consist only of these dyadic operators: +-/*
Your program or function should take a valid expression string as input, and output a truthy value if the constants in the expression are of the same time, and a falsey value otherwise.
The expression will consist solely of constants, and may contain any of the following types:
- String, of the form
"String"
(Always double quotes, can be empty, no escape characters, may contain any ASCII text) - Integer, of the form
14
(Always positive or zero) - Float, of the form
7.3f
(Always positive or zero, always has a decimal component, eg14.0f
) - Byte, of the form
0x42
(0-255
, Always 2 hexadecimal characters) - Boolean, of the form
true
(true
orfalse
, case insensitive)
The expression will not contain parentheses, as order of operation doesn't affect type when no type coercion is present.
A lone constant with no operators is a valid expression.
An empty expression is not a valid expression.
You may assume that the expression string contains no whitespace outside of string literals.
Note: Alternatively you may assume that there will always be spaces between constants and operators, as seen in the testcases. If you make this assumption, please specify as such in your answer
You do not have to handle invalid expressions such as 1 +
.
Scoring
This is code-golf, so fewest bytes wins!
Test cases
(Whitespace added for readability)
2 + 3
True
"Hello" / "World"
True
true * false
True
"Hello" + 4
False
"Hello" + "4"
True
3 + 2.4f / 8
False
0xff * 0xff
True
0xff + 2
False
6
True
" " + ""
True
"4 + false" + "word"
True
code-golf string decision-problem parsing
$endgroup$
Given an infix expression, determine whether all constants are of the same type.
Operators will consist only of these dyadic operators: +-/*
Your program or function should take a valid expression string as input, and output a truthy value if the constants in the expression are of the same time, and a falsey value otherwise.
The expression will consist solely of constants, and may contain any of the following types:
- String, of the form
"String"
(Always double quotes, can be empty, no escape characters, may contain any ASCII text) - Integer, of the form
14
(Always positive or zero) - Float, of the form
7.3f
(Always positive or zero, always has a decimal component, eg14.0f
) - Byte, of the form
0x42
(0-255
, Always 2 hexadecimal characters) - Boolean, of the form
true
(true
orfalse
, case insensitive)
The expression will not contain parentheses, as order of operation doesn't affect type when no type coercion is present.
A lone constant with no operators is a valid expression.
An empty expression is not a valid expression.
You may assume that the expression string contains no whitespace outside of string literals.
Note: Alternatively you may assume that there will always be spaces between constants and operators, as seen in the testcases. If you make this assumption, please specify as such in your answer
You do not have to handle invalid expressions such as 1 +
.
Scoring
This is code-golf, so fewest bytes wins!
Test cases
(Whitespace added for readability)
2 + 3
True
"Hello" / "World"
True
true * false
True
"Hello" + 4
False
"Hello" + "4"
True
3 + 2.4f / 8
False
0xff * 0xff
True
0xff + 2
False
6
True
" " + ""
True
"4 + false" + "word"
True
code-golf string decision-problem parsing
code-golf string decision-problem parsing
edited May 1 at 14:26
DJMcMayhem♦
40.7k12150316
40.7k12150316
asked Apr 30 at 14:47
SkidsdevSkidsdev
6,7952977
6,7952977
4
$begingroup$
Does "case insensitive" for Boolean values mean that we have to support all cases? Or that we can decide which case to use?
$endgroup$
– Arnauld
Apr 30 at 16:09
$begingroup$
@Arnauld must support all cases
$endgroup$
– Skidsdev
Apr 30 at 16:31
$begingroup$
@JonathanAllan my interpretation was that we had to handle any mixture of cases (e.g.truE+fALSe
). If not I can save two bytes in my solution.
$endgroup$
– Nick Kennedy
Apr 30 at 19:50
add a comment |
4
$begingroup$
Does "case insensitive" for Boolean values mean that we have to support all cases? Or that we can decide which case to use?
$endgroup$
– Arnauld
Apr 30 at 16:09
$begingroup$
@Arnauld must support all cases
$endgroup$
– Skidsdev
Apr 30 at 16:31
$begingroup$
@JonathanAllan my interpretation was that we had to handle any mixture of cases (e.g.truE+fALSe
). If not I can save two bytes in my solution.
$endgroup$
– Nick Kennedy
Apr 30 at 19:50
4
4
$begingroup$
Does "case insensitive" for Boolean values mean that we have to support all cases? Or that we can decide which case to use?
$endgroup$
– Arnauld
Apr 30 at 16:09
$begingroup$
Does "case insensitive" for Boolean values mean that we have to support all cases? Or that we can decide which case to use?
$endgroup$
– Arnauld
Apr 30 at 16:09
$begingroup$
@Arnauld must support all cases
$endgroup$
– Skidsdev
Apr 30 at 16:31
$begingroup$
@Arnauld must support all cases
$endgroup$
– Skidsdev
Apr 30 at 16:31
$begingroup$
@JonathanAllan my interpretation was that we had to handle any mixture of cases (e.g.
truE+fALSe
). If not I can save two bytes in my solution.$endgroup$
– Nick Kennedy
Apr 30 at 19:50
$begingroup$
@JonathanAllan my interpretation was that we had to handle any mixture of cases (e.g.
truE+fALSe
). If not I can save two bytes in my solution.$endgroup$
– Nick Kennedy
Apr 30 at 19:50
add a comment |
8 Answers
8
active
oldest
votes
$begingroup$
JavaScript (ES6), 79 77 75 bytes
Saved 2 bytes thanks to @ExpiredData
Expects whitespace around operators. Returns a Boolean value.
s=>![/".*?"/g,/0x../g,/S+f/g,/d/,/e/i].filter(e=>s!=(s=s.split(e)+''))[1]
Try it online!
How?
- We remove all strings, using
/".*?"/g
- We remove all bytes, using
/0x../g
- We remove all floats, using
/S+f/g
- We look for a remaining digit with
/d/
; if we do find one, there must be at least one integer - We look for a remaining
"e"
or"E"
with/e/i
; if we do find one, there must be at least one Boolean value
All removed expressions are actually replaced with a comma, which is harmless.
We filter out the regular expressions causing no change to the input string and test whether less than two of them remain at the end of the process.
$endgroup$
$begingroup$
true
andfalse
are marked as being case insensitive, I think that means you need to make your regex ignore case when searching for theset
ands
(I could be wrong though).
$endgroup$
– Jonathan Allan
Apr 30 at 16:03
1
$begingroup$
@JonathanAllan I've put a temporary fix and asked the OP.
$endgroup$
– Arnauld
Apr 30 at 16:09
$begingroup$
75 bytes
$endgroup$
– Expired Data
May 1 at 7:57
$begingroup$
@ExpiredData Nice. :) Thanks!
$endgroup$
– Arnauld
May 1 at 8:08
add a comment |
$begingroup$
Perl 5 -p
, 73 bytes
for$f(qw/".*?" d+.d+f 0x.. ....?e d+/)s/$f//gi&&last$_=/^[+/* -]*$/
Try it online!
How?
Attempt to remove strings, floats, hex, boolean, and integers, in that order. Stop as soon as something is removed. After stopping, check to see if the remaining string consists only of operators and whitespace. It if does, the trype check is true; if not, it's false.
First attempt: Perl 5 -MList::Util=all
-p
, 99 bytes
s/".*?"/!/g;for$f(qw/! d+ d+.d+f 0x[0-9a-f]2 (true|false)/)$}improve this answer
$endgroup$
$begingroup$
108 bytes
$endgroup$
– Expired Data
May 1 at 7:42
add a comment Ë
-26 bytes by making a port of @NickKennedy's Jelly answer, so make sure to upvote him!!
Expects input with spaces at the operands.
Try it online or verify all (plus some more) test cases.
Explanation:
'"¡ '# Split the (implicit) input-string by '"'
āÉÏ # Only keep all values at 0-based even indices
» # Join them by newlines
l # Converted to lowercase (for `true`/`false`)
ð¡ # Split by spaces (NOTE: `#` cannot be used here, since inputs without
# operands wouldn't be wrapped inside a list)
āÉÏ # Keep all values at 0-based even indices again
ε".e
x"Så} # Check for each item for each of [".","e","n","x"] if it's in the item
Ë # Check if all inner lists are the same
# (which is output implicitly as result)
$endgroup$
add a comment |
$begingroup$
Python 2, 102 bytes
import re
def f(s):
m=map(eval,re.split('[*+-/]',s))
return all(map(lambda t:type(t)==type(m[0]),m))
Try it online!
Not entirely sure how to represent some of these types in Python. For example, 0xff and 2 are both treated as integers. And 2.4f isn't a valid type in Python, I think. Capitalized True and False for testing Booleans.
Edit: Grammar
$endgroup$
3
$begingroup$
Will fail the last test case
$endgroup$
– Embodiment of Ignorance
Apr 30 at 16:08
$begingroup$
...and (as it stands) thetrue * false
one.
$endgroup$
– Jonathan Allan
Apr 30 at 18:46
$begingroup$
It passes for "True * False". I can try to make it work with lower case, but I figured since bools are always capitalized in python it would be sufficient.
$endgroup$
– GotCubes
Apr 30 at 19:12
2
$begingroup$
Currently this does not fulfill the challenge criteria. Namely: It does not handle booleans case insensitively, it errors on floats, and it incorrectly returns true when given an expression consisting of bytes and integers
$endgroup$
– Skidsdev
May 1 at 13:38
add a comment |
$begingroup$
Stax, 26 bytes
ïd"┬Z¡►L!8$lm╗╕╤☻ú≡╝ò6Å>^
Run and debug it
This program expects spaces around the operators. In general, it works by applying a few transformations to the input such that the maximum character for each expression type is distinct.
Unpacked, ungolfed, and commented, it looks like this.
i suppress automatic evaluation of input
'"/2::'s* replace quoted strings with 's'
.d'9R replace all digits with '9'
.ez|t replace 'e' with 'z'
j2:: split on spaces, and discard alternating groups (operators)
$begingroup$
Japt -!
, 36 bytes
`".*?" 0x.. %S+f %d eimprove this answer
$endgroup$
$begingroup$
$_=/^[+/* -]*$/
may be changed by$_=!y#-+/* ##c
, and....?e
by.*e
$endgroup$
– Nahuel Fouilleul
May 2 at 9:11
$begingroup$
otherwise in one regex, 63 bytes
$endgroup$
– Nahuel Fouilleul
May 2 at 9:22
$begingroup$
58 bytes assuming there will always be spaces between constants and operators
$endgroup$
– Nahuel Fouilleul
May 2 at 9:37
add a comment improve this answer
$endgroup$
$begingroup$
$_=/^[+/* -]*$/
may be changed by$_=!y#-+/* ##c
, and....?e
by.*e
$endgroup$
– Nahuel Fouilleul
May 2 at 9:11
$begingroup$
otherwise in one regex, 63 bytes
$endgroup$
– Nahuel Fouilleul
May 2 at 9:22
$begingroup$
58 bytes assuming there will always be spaces between constants and operators
$endgroup$
– Nahuel Fouilleul
May 2 at 9:37
add a comment false)/)$ Check each section is equal (will return true for single section)
$endgroup$
add a comment |
$begingroup$
05AB1E, 50 24 bytes
'"¡āÉÏ»lð¡āÉÏε".e
x"Så}Ë
-26 bytes by making a port of @NickKennedy's Jelly answer, so make sure to upvote him!!
Expects input with spaces at the operands.
Try it online or verify all (plus some more) test cases.
Explanation:
'"¡ '# Split the (implicit) input-string by '"'
āÉÏ # Only keep all values at 0-based even indices
» # Join them by newlines
l # Converted to lowercase (for `true`/`false`)
ð¡ # Split by spaces (NOTE: `#` cannot be used here, since inputs without
# operands wouldn't be wrapped inside a list)
āÉÏ # Keep all values at 0-based even indices again
ε".e
x"Så} # Check for each item for each of [".","e","n","x"] if it's in the item
Ë # Check if all inner lists are the same
# (which is output implicitly as result)
$endgroup$
add a comment |
$begingroup$
05AB1E, 50 24 bytes
'"¡āÉÏ»lð¡āÉÏε".e
x"Så}Ë
-26 bytes by making a port of @NickKennedy's Jelly answer, so make sure to upvote him!!
Expects input with spaces at the operands.
Try it online or verify all (plus some more) test cases.
Explanation:
'"¡ '# Split the (implicit) input-string by '"'
āÉÏ # Only keep all values at 0-based even indices
» # Join them by newlines
l # Converted to lowercase (for `true`/`false`)
ð¡ # Split by spaces (NOTE: `#` cannot be used here, since inputs without
# operands wouldn't be wrapped inside a list)
āÉÏ # Keep all values at 0-based even indices again
ε".e
x"Så} # Check for each item for each of [".","e","n","x"] if it's in the item
Ë # Check if all inner lists are the same
# (which is output implicitly as result)
$endgroup$
05AB1E, 50 24 bytes
'"¡āÉÏ»lð¡āÉÏε".e
x"Så}Ë
-26 bytes by making a port of @NickKennedy's Jelly answer, so make sure to upvote him!!
Expects input with spaces at the operands.
Try it online or verify all (plus some more) test cases.
Explanation:
'"¡ '# Split the (implicit) input-string by '"'
āÉÏ # Only keep all values at 0-based even indices
» # Join them by newlines
l # Converted to lowercase (for `true`/`false`)
ð¡ # Split by spaces (NOTE: `#` cannot be used here, since inputs without
# operands wouldn't be wrapped inside a list)
āÉÏ # Keep all values at 0-based even indices again
ε".e
x"Så} # Check for each item for each of [".","e","n","x"] if it's in the item
Ë # Check if all inner lists are the same
# (which is output implicitly as result)
edited May 1 at 7:25
answered Apr 30 at 17:15
Kevin CruijssenKevin Cruijssen
44.4k575224
44.4k575224
add a comment |
add a comment |
$begingroup$
Python 2, 102 bytes
import re
def f(s):
m=map(eval,re.split('[*+-/]',s))
return all(map(lambda t:type(t)==type(m[0]),m))
Try it online!
Not entirely sure how to represent some of these types in Python. For example, 0xff and 2 are both treated as integers. And 2.4f isn't a valid type in Python, I think. Capitalized True and False for testing Booleans.
Edit: Grammar
$endgroup$
3
$begingroup$
Will fail the last test case
$endgroup$
– Embodiment of Ignorance
Apr 30 at 16:08
$begingroup$
...and (as it stands) thetrue * false
one.
$endgroup$
– Jonathan Allan
Apr 30 at 18:46
$begingroup$
It passes for "True * False". I can try to make it work with lower case, but I figured since bools are always capitalized in python it would be sufficient.
$endgroup$
– GotCubes
Apr 30 at 19:12
2
$begingroup$
Currently this does not fulfill the challenge criteria. Namely: It does not handle booleans case insensitively, it errors on floats, and it incorrectly returns true when given an expression consisting of bytes and integers
$endgroup$
– Skidsdev
May 1 at 13:38
add a comment |
$begingroup$
Python 2, 102 bytes
import re
def f(s):
m=map(eval,re.split('[*+-/]',s))
return all(map(lambda t:type(t)==type(m[0]),m))
Try it online!
Not entirely sure how to represent some of these types in Python. For example, 0xff and 2 are both treated as integers. And 2.4f isn't a valid type in Python, I think. Capitalized True and False for testing Booleans.
Edit: Grammar
$endgroup$
3
$begingroup$
Will fail the last test case
$endgroup$
– Embodiment of Ignorance
Apr 30 at 16:08
$begingroup$
...and (as it stands) thetrue * false
one.
$endgroup$
– Jonathan Allan
Apr 30 at 18:46
$begingroup$
It passes for "True * False". I can try to make it work with lower case, but I figured since bools are always capitalized in python it would be sufficient.
$endgroup$
– GotCubes
Apr 30 at 19:12
2
$begingroup$
Currently this does not fulfill the challenge criteria. Namely: It does not handle booleans case insensitively, it errors on floats, and it incorrectly returns true when given an expression consisting of bytes and integers
$endgroup$
– Skidsdev
May 1 at 13:38
add a comment |
$begingroup$
Python 2, 102 bytes
import re
def f(s):
m=map(eval,re.split('[*+-/]',s))
return all(map(lambda t:type(t)==type(m[0]),m))
Try it online!
Not entirely sure how to represent some of these types in Python. For example, 0xff and 2 are both treated as integers. And 2.4f isn't a valid type in Python, I think. Capitalized True and False for testing Booleans.
Edit: Grammar
$endgroup$
Python 2, 102 bytes
import re
def f(s):
m=map(eval,re.split('[*+-/]',s))
return all(map(lambda t:type(t)==type(m[0]),m))
Try it online!
Not entirely sure how to represent some of these types in Python. For example, 0xff and 2 are both treated as integers. And 2.4f isn't a valid type in Python, I think. Capitalized True and False for testing Booleans.
Edit: Grammar
answered Apr 30 at 16:06
GotCubesGotCubes
593
593
3
$begingroup$
Will fail the last test case
$endgroup$
– Embodiment of Ignorance
Apr 30 at 16:08
$begingroup$
...and (as it stands) thetrue * false
one.
$endgroup$
– Jonathan Allan
Apr 30 at 18:46
$begingroup$
It passes for "True * False". I can try to make it work with lower case, but I figured since bools are always capitalized in python it would be sufficient.
$endgroup$
– GotCubes
Apr 30 at 19:12
2
$begingroup$
Currently this does not fulfill the challenge criteria. Namely: It does not handle booleans case insensitively, it errors on floats, and it incorrectly returns true when given an expression consisting of bytes and integers
$endgroup$
– Skidsdev
May 1 at 13:38
add a comment |
3
$begingroup$
Will fail the last test case
$endgroup$
– Embodiment of Ignorance
Apr 30 at 16:08
$begingroup$
...and (as it stands) thetrue * false
one.
$endgroup$
– Jonathan Allan
Apr 30 at 18:46
$begingroup$
It passes for "True * False". I can try to make it work with lower case, but I figured since bools are always capitalized in python it would be sufficient.
$endgroup$
– GotCubes
Apr 30 at 19:12
2
$begingroup$
Currently this does not fulfill the challenge criteria. Namely: It does not handle booleans case insensitively, it errors on floats, and it incorrectly returns true when given an expression consisting of bytes and integers
$endgroup$
– Skidsdev
May 1 at 13:38
3
3
$begingroup$
Will fail the last test case
$endgroup$
– Embodiment of Ignorance
Apr 30 at 16:08
$begingroup$
Will fail the last test case
$endgroup$
– Embodiment of Ignorance
Apr 30 at 16:08
$begingroup$
...and (as it stands) the
true * false
one.$endgroup$
– Jonathan Allan
Apr 30 at 18:46
$begingroup$
...and (as it stands) the
true * false
one.$endgroup$
– Jonathan Allan
Apr 30 at 18:46
$begingroup$
It passes for "True * False". I can try to make it work with lower case, but I figured since bools are always capitalized in python it would be sufficient.
$endgroup$
– GotCubes
Apr 30 at 19:12
$begingroup$
It passes for "True * False". I can try to make it work with lower case, but I figured since bools are always capitalized in python it would be sufficient.
$endgroup$
– GotCubes
Apr 30 at 19:12
2
2
$begingroup$
Currently this does not fulfill the challenge criteria. Namely: It does not handle booleans case insensitively, it errors on floats, and it incorrectly returns true when given an expression consisting of bytes and integers
$endgroup$
– Skidsdev
May 1 at 13:38
$begingroup$
Currently this does not fulfill the challenge criteria. Namely: It does not handle booleans case insensitively, it errors on floats, and it incorrectly returns true when given an expression consisting of bytes and integers
$endgroup$
– Skidsdev
May 1 at 13:38
add a comment |
$begingroup$
Stax, 26 bytes
ïd"┬Z¡►L!8$lm╗╕╤☻ú≡╝ò6Å>^
Run and debug it
This program expects spaces around the operators. In general, it works by applying a few transformations to the input such that the maximum character for each expression type is distinct.
Unpacked, ungolfed, and commented, it looks like this.
i suppress automatic evaluation of input
'"/2::'s* replace quoted strings with 's'
.d'9R replace all digits with '9'
.ez|t replace 'e' with 'z'
j2:: split on spaces, and discard alternating groups (operators)
{|Mm calculate the maximum character in each remaining group
:u resulting array contains exactly one distinct value
Run this one
$endgroup$
add a comment |
$begingroup$
Stax, 26 bytes
ïd"┬Z¡►L!8$lm╗╕╤☻ú≡╝ò6Å>^
Run and debug it
This program expects spaces around the operators. In general, it works by applying a few transformations to the input such that the maximum character for each expression type is distinct.
Unpacked, ungolfed, and commented, it looks like this.
i suppress automatic evaluation of input
'"/2::'s* replace quoted strings with 's'
.d'9R replace all digits with '9'
.ez|t replace 'e' with 'z'
j2:: split on spaces, and discard alternating groups (operators)
{|Mm calculate the maximum character in each remaining group
:u resulting array contains exactly one distinct value
Run this one
$endgroup$
add a comment |
$begingroup$
Stax, 26 bytes
ïd"┬Z¡►L!8$lm╗╕╤☻ú≡╝ò6Å>^
Run and debug it
This program expects spaces around the operators. In general, it works by applying a few transformations to the input such that the maximum character for each expression type is distinct.
Unpacked, ungolfed, and commented, it looks like this.
i suppress automatic evaluation of input
'"/2::'s* replace quoted strings with 's'
.d'9R replace all digits with '9'
.ez|t replace 'e' with 'z'
j2:: split on spaces, and discard alternating groups (operators)
{|Mm calculate the maximum character in each remaining group
:u resulting array contains exactly one distinct value
Run this one
$endgroup$
Stax, 26 bytes
ïd"┬Z¡►L!8$lm╗╕╤☻ú≡╝ò6Å>^
Run and debug it
This program expects spaces around the operators. In general, it works by applying a few transformations to the input such that the maximum character for each expression type is distinct.
Unpacked, ungolfed, and commented, it looks like this.
i suppress automatic evaluation of input
'"/2::'s* replace quoted strings with 's'
.d'9R replace all digits with '9'
.ez|t replace 'e' with 'z'
j2:: split on spaces, and discard alternating groups (operators)
{|Mm calculate the maximum character in each remaining group
:u resulting array contains exactly one distinct value
Run this one
edited Apr 30 at 20:50
answered Apr 30 at 20:45
recursiverecursive
5,7741322
5,7741322
add a comment |
add a comment |
$begingroup$
Japt -!
, 36 bytes
`".*?" 0x.. %S+f %d e|E`¸è@UÀ(U=rXÃÉ
Try it
$endgroup$
$begingroup$
33 bytes?
$endgroup$
– Shaggy
May 1 at 22:31
add a comment |
$begingroup$
Japt -!
, 36 bytes
`".*?" 0x.. %S+f %d e|E`¸è@UÀ(U=rXÃÉ
Try it
$endgroup$
$begingroup$
33 bytes?
$endgroup$
– Shaggy
May 1 at 22:31
add a comment |
$begingroup$
Japt -!
, 36 bytes
`".*?" 0x.. %S+f %d e|E`¸è@UÀ(U=rXÃÉ
Try it
$endgroup$
Japt -!
, 36 bytes
`".*?" 0x.. %S+f %d e|E`¸è@UÀ(U=rXÃÉ
Try it
answered May 1 at 5:18
Embodiment of IgnoranceEmbodiment of Ignorance
3,459128
3,459128
$begingroup$
33 bytes?
$endgroup$
– Shaggy
May 1 at 22:31
add a comment |
$begingroup$
33 bytes?
$endgroup$
– Shaggy
May 1 at 22:31
$begingroup$
33 bytes?
$endgroup$
– Shaggy
May 1 at 22:31
$begingroup$
33 bytes?
$endgroup$
– Shaggy
May 1 at 22:31
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f184961%2ftype-check-an-expression%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
$begingroup$
Does "case insensitive" for Boolean values mean that we have to support all cases? Or that we can decide which case to use?
$endgroup$
– Arnauld
Apr 30 at 16:09
$begingroup$
@Arnauld must support all cases
$endgroup$
– Skidsdev
Apr 30 at 16:31
$begingroup$
@JonathanAllan my interpretation was that we had to handle any mixture of cases (e.g.
truE+fALSe
). If not I can save two bytes in my solution.$endgroup$
– Nick Kennedy
Apr 30 at 19:50