MSM, 31 bytes
'?ddF',',',.....T',',':'?....':
MSM is stack based, so the two input numbers are expected to be on top of the stack, i.e. on the right of the string. MSM has neither numbers nor booleans so we are free to choose a (reasonable) representation:
T True
F False
123 numbers are just sequences of ascii digits. There's no literal
representation in MSM source code, so you have to construct them
digit by digit: 321.. -> 123 (remember: . is concatenation)
TIO doesn't support MSM out of the box, so I've included the JS interpreter from the esolang page.
Try it online!
How it works: (I use a
and b
for the two numbers on the stack).
Excerpt from the MSM command reference:
' quote, push next char on the stack, even if it is a command
? skip next command if the two top elements of the stack are equal
, drop
: expand string at top of the stack and push each char of it on the stack
. concatenate two top elements
everything else is pushed
Stack trace:
' ? d d F ' , ' , ' , . . . . . T ' , ' , ' : ' ? . . . . ' : a b
d d F ' , ' , ' , . . . . . T ' , ' , ' : ' ? . . . . ' : a b ?
The next 6 chars are pushed on the stack and concatenated with 5 dots
T ' , ' , ' : ' ? . . . . ' : a b ? ,,,Fdd
The next 5 chars are pushed on the stack and concatenated with 4 dots
' : a b ? ,,,Fdd ?:,,T
:
and the two numbers are pushed
? ,,,Fdd ?:,,T : a b
Now it gets interesting. If the two numbers are equal, ,,,Fdd
is skipped
?:,,T : a b -- ?:,,T as a whole is not a command, so it's pushed
: a b ?:,,T -- expand
a b ? : , , T -- push a b
? : , , T a b -- a b are still equal, so skip :
, , T a b -- drop a b
T -- MSM stops, output is True
If the two numbers are not equal, don't skip ,,,Fdd
, but push it:
,,,Fdd ?:,,T : a b
: a b ,,,Fdd ?:,,T -- expand
a b ,,,Fdd ? : , , T -- push up to ?
? : , , T a b ,,,Fdd -- number b is never equal to ,,,Fdd so expand
, , T a b , , , F d d -- drop two dummy values
T a b , , , F -- push T a b
, , , F T a b -- drop b a T
F -- stop
int f(int a, int b){ return a==b;}
? Becauseint
in C represents numbers with base-2 bit-patterns, not decimal. (The details are implementation-defined, but there are enough requirements in the C standard that I don't think an implementation could legally choose a BCD (binary-coded-decimal) representation. At least not forunsigned char
.) I think you're getting mixed up by source code that looks likeint a = 1234;
. That uses a decimal representation in the source, but not in the program.int a=0x4d2;
is identical to1234
. \$\endgroup\$ – Peter Cordes Jan 10 '18 at 4:20