| Bytes | Lang | Time | Link |
|---|---|---|---|
| 010 | Uiua | 240728T042946Z | ErikDaPa |
| 098 | Pascal | 240728T000000Z | Kai Burg |
| 008 | Excel / Google Sheets | 240728T105137Z | z.. |
| 002 | Thunno 2 | 230616T171551Z | The Thon |
| 009 | Juby | 221014T153231Z | Jordan |
| 030 | Julia 1.0 | 221024T085657Z | amelies |
| 026 | Julia 1.0 | 221020T154529Z | Ashlin H |
| 029 | Factor | 221020T083402Z | chunes |
| 051 | nroff | 221019T133511Z | 鳴神裁四点一号 |
| 021 | Ruby | 221014T152251Z | Jordan |
| 003 | Vyxal | 221014T115101Z | DialFros |
| 027 | R | 180204T121713Z | Robert H |
| 055 | R | 180404T051441Z | KamRa |
| 032 | C# | 180404T021852Z | lee |
| 005 | Implicit | 180404T013621Z | MD XF |
| 016 | Excel VBA | 180109T130517Z | danielta |
| 078 | Swift | 180109T152006Z | user3151 |
| 036 | FALSE | 180201T153951Z | 12Me21 |
| 001 | Pyt | 180131T030052Z | mudkip20 |
| nan | 180124T181241Z | Brad Gil | |
| 003 | Stratos | 180116T135910Z | Okx |
| 005 | K oK | 180113T111701Z | mkst |
| 022 | BrainFlak | 180109T104022Z | Mr. Xcod |
| 045 | Tcl | 180111T142539Z | sergiol |
| 1642 | PHP 5.6+ | 180110T163604Z | Xano |
| 012 | AWK | 180109T171642Z | Noskcaj |
| 035 | TSQL | 180109T185931Z | BradC |
| 013 | Q Kdb+ | 180110T182450Z | Sidney |
| 023 | Ruby | 180111T045559Z | NTCG |
| 007 | Mumps | 180110T203956Z | zmerch |
| 019 | PowerShell | 180110T194020Z | briantis |
| 051 | Java 8 | 180109T183643Z | Developi |
| 006 | Javascript | 180110T120607Z | General |
| 089 | Batch | 180110T094846Z | Neil |
| 008 | Excel | 180110T093225Z | Wernisch |
| 011 | Javascript | 180109T110321Z | elementb |
| 009 | dc | 180110T082825Z | seshouma |
| 065 | C++ gcc | 180110T063519Z | Ken Y-N |
| 027 | C gcc | 180109T102627Z | Steadybo |
| 235 | ><> | 180110T011029Z | Jo King |
| 035 | R | 180109T214633Z | rturnbul |
| 008 | Jelly | 180109T204154Z | caird co |
| 052 | Clean | 180109T195733Z | Οurous |
| 007 | APL NARS2000 | 180109T191818Z | Erik the |
| 020 | PowerShell | 180109T184932Z | AdmBorkB |
| 029 | Sinclair ZX81/Timex TS1000/1500 BASIC | 180109T111432Z | Shaun Be |
| 042 | SNOBOL4 CSNOBOL4 | 180109T183105Z | Giuseppe |
| 003 | Husk | 180109T163823Z | ბიმო |
| 488 | Taxi | 180109T155504Z | Engineer |
| 011 | Attache | 180109T153603Z | Conor O& |
| 033 | Operation Flashpoint scripting language | 180109T111608Z | Steadybo |
| 008 | Stacked | 180109T145744Z | Conor O& |
| 027 | Wolfram Language | 180109T144750Z | ktm |
| 004 | Pyth | 180109T123424Z | Dave |
| 9110 | Perl 5 | 180109T123345Z | Nahuel F |
| 024 | jq | 180109T120418Z | manatwor |
| 021 | Gema | 180109T113924Z | manatwor |
| 025 | Python 3 | 180109T113444Z | Mr. Xcod |
| 004 | APL Dyalog | 180109T104319Z | Uriel |
| 003 | Japt | 180109T105531Z | Shaggy |
| 007 | Alice | 180109T110121Z | Martin E |
| 020 | Haskell | 180109T103939Z | totallyh |
| 011 | Retina | 180109T105812Z | Martin E |
| 020 | Lua | 180109T104424Z | Jonathan |
| 017 | Triangularity | 180109T102753Z | Mr. Xcod |
| 004 | J | 180109T103455Z | FrownyFr |
| 001 | 05AB1E | 180109T102836Z | Emigna |
Uiua, 10 bytes
=∩(⋕▽⊸≠@ )
Explanation:
=∩(⋕▽⊸≠@ )
▽⊸≠@ => remove spaces
⋕ => parse
∩( ) => do for both strings
= => check if both match
Pascal, 98 B
The string capabilities and the procedure readStr require a processor supporting features of Extended Pascal as laid out in ISO standard 10206.
type T=string(80);function f(A,B:T):Boolean;var x,y:integer;begin
readStr(A+' '+B,x,y);f:=x=y end;
Nogolf’d:
program compareTwoNumbersGivenAsStrings(output);
type
line = string(80);
{ Returns `true` if two strings denote the same `integer`. }
function equal(protected imageX, imageY: line): Boolean;
var
x, y: integer;
begin
readStr(imageX + ' ' + imageY, x, y);
equal ≔ x = y
end;
{ ═══ MAIN ═══════════════════════════════════════════════ }
begin
writeLn(equal('0001', '1 ' ), true);
writeLn(equal('1450', '1450 ' ), true);
writeLn(equal('0010001 ', ' 10001 '), true);
writeLn(equal('0010000', ' 10 ' ), false);
writeLn(equal('101023', '101024' ), false)
end.
Excel / Google Sheets, 8 bytes
=-A1=-A2
or
=--A1=A2
Thunno 2, 2 bytes
Nạ
The "cast to integer" built-in (N) handles leading/trailing spaces and leading zeros. Then, we can just check equality with ạ.
J-uby, 9 bytes
:*&Z|+:==
Explanation
:* & Z | # Map with to_i (Z), then
+:== # Compare
I think this would be 7 bytes with J-uby’s ** operator:
Z**+:==
…but it’s broken or removed in the current version.
Julia 1.0, 30 bytes
a%b=eval(Meta.parse("$a==$b"))
Some meta programming fun, not the shortest solution though
Factor, 29 bytes
[ [ " "without dec> ] same? ]
Factor's number parser can't handle spaces so I have to remove them first.
nroff, 51 bytes
1 and 0 for truthy and falsey.
Wish type convertion were available.
.nr X \\$1=\\$2 did not work for some input.
.de F
.nr X \\$1
.nr Y \\$2
.nr X \\nX=\\nY
\\nX
..
R, 28 27 bytes
!diff(as.double(scan(,'')))
Reads numbers as strings, converts them to doubles and checks if their difference is not zero.
−1 byte thanks to Giuseppe
R, 55 bytes
V<-strtoi(gsub(" ","",c(A,B),fixed=T),base=9)
V[1]==V[2]
This is my first attempt at codegolf; gave it my best try. Suggestions welcome!
Assumptions:
The inputs are given as strings A and B
The integers contained are less than 1888888888. Larger values will cause strtoi() to return NA.
C# (32 bytes)
a=>b=>int.Parse(a)==int.Parse(b)
as already mentioned in the comments, you can do it shorter than the C# provided in the question. I wrote this thinking I was clever before reading the reply to the comments by the OP. :)
Implicit, 5 bytes
'ì'ì=
'ì'ì=
' «read string, push to stack »;
ì «swap type (integer/string) of top of stack »;
'ì «do it again for the second integer string »;
= «compare for equality »;
Excel VBA, 27 16 Bytes
-9 Thanks to @Nayrb and @TaylorScott
[C1]=[A1]-[B1]=0
Where you input the values on the Cells with 'string.
Where x and y are the input Strings and z is a Boolean output.
If CInt(x)=CInt(y) Then z=1
Using CInt
Swift, 80 79 78 bytes
import Foundation;func r(g:[NSString])->Bool{return g[0].intValue==g[1].intValue}
FALSE, 36 bytes
[0[^$9>][$32>[48-+10*]?]#%10/]$!\!=.
Numbers are received from the console, separated by a tab character.
True=-1, False=0.
Pyt, 1 byte
=
Explanation
Implicitly takes two inputs, and casts them to integers/floats if possible.
= Checks if the two are equal
Perl 6, 4 bytes
*==*
The == operator converts to Numeric which ignores leading and trailing whitespace, and leading 0's get ignored just the same. (0o127 is how you write an octal)
The two * are just there to turn it into a lambda that takes two arguments.
Stratos, 3 bytes
_=_
Both of the _ take an input as a string and convert it to a number, then negate it.
Java converts the input to a number by removing 0s and spaces.
The = takes the results of this and checks for equality
K (oK), 5 bytes
Solution:
=/.:'
Examples:
=/.:'("0001";"1 ")
1
=/.:'("1450";"1450 ")
1
=/.:'("0010001";" 10001 ")
1
=/.:'("0010000";" 10 ")
0
=/.:'("101023";"101024")
0
Explanation:
Convert each input to an integer, and then check for equality.
=/.:' / the solution
.:' / value (.:) each ('), converts char list to integer
=/ / equality (=) over (/)
PHP 5.6+, 16 (42 when callable) bytes
The minimum code that meets the puzzle's requirements (16 bytes):
(int)$a==(int)$b
In callable form (42 bytes):
function f($a,$b){return(int)$a==(int)$b;}
Explanation
Declare a regular function with a single-character name f with two, otherwise undetermined parameters. It returns the result of comparing both arguments after casting each to integers, which safely removed the padding and whitespace.
The code could have been made 2 bytes shorter by converting the function to a closure, but then the closure would not be assigned (which takes another 3 bytes), and therefore not callable.
AWK, 12 bytes
{$0=$1==$2}1
AWK, 9 bytes
$0=$1==$2
Alternate version: outputs 1 on match, otherwise outputs nothing
T-SQL, 35 bytes
Per our standards, data is input via pre-existing table t with varchar fields a and b.
SELECT IIF(ABS(a)=ABS(b),1,0)FROM t
Returns 1 if they match, 0 if they don't.
A few of SQL's mathematical functions (including ABS, FLOOR and CEILING) will do an implicit conversion to numeric if given string parameters, this is shorter than an explicit CAST(a AS INT) or CONVERT(INT,b), and works in this case since we know the input values are always positive.
IIF is specific to MS SQL 2012 and above, so no guarantee about other implementations.
Q (Kdb+), 13 bytes
=/["J"$(x;y)]
Explanation
(x;y) : a list of the two inputs.
"J"$ : casting each input to a long (7j) type from string (10c), which can correctly interpret
white space and leading 0s.
=/ : checks equality over elements in a list (each subsequent pair).
As there is only one pair, returns single boolian 0b/1b.
Ruby, 23 bytes
s=->x,y{x.to_i==y.to_i}
Mumps, 7 bytes
W +X=+Y
In Mumps, all data are strings, the '+' operator evaluates the string to a numeric value. There is no implicit output function, so the 'W' (Write) function provides the output.
PowerShell, 19 bytes
$args-join'-eq'|iex
-join the argument array ($args) with the string representation of the comparison operator (-eq) then evaluate the expression with Invoke-Expression (iex).
Java 8, 58 51 bytes
7 bytes thanks to Kevin
b->c->new Long(b.trim()).equals(new Long(c.trim()))
Explanation
Trims off spaces, casting to Long removes leading zeros, and then returns boolean value if they are equal or not.
Javascript, 6 bytes
Pretty standard stuff, but using Javascript's auto type casting
!(a-b)
Or if we don't need it as a function (19 bytes)
let f=(a,b)=>!(a-b)
Try it online! https://jsfiddle.net/pgz4ctLy/2/
Batch, 89 bytes
@call:c %1
@set e=%errorlevel%
@call:c %2
@if %e%==%errorlevel% echo 1
:c
@exit/b%~1
Prints 1 if the two numbers are the same. Explanation: Batch's numeric processing usually uses leading zeros to indicate an octal number, however exit/b always takes a decimal number. The ~ removes any quotes that would be needed to pass leading or trailing spaces in the parameter.
Excel, 8 bytes
=A1-B1=0
Excel does the string to num conversion for us.
(To input as string, prefix values with '.)
Javascript, 11 bytes
a=>b=>+a==b
Abusing Javascript's casting rules a bit; +a coerces a into a numeric type.
-6 bytes thanks to Shaggy and Martin Ender♦
Also a cool take by LiefdeWen:
a=>b=>~~a==~~b
dc, 9 bytes
[1p]sQ?=Q
Outputs 1 if the numbers are equal, or nothing if unequal. The input numbers are separated by ',', and this gives a warning since data is code in dc. I wasn't sure if space was allowed as delimiter, so I chose one that doesn't stop the program.
C++ (gcc), 65 bytes
#include<cstdlib>
auto a(auto b,auto c){return atoi(b)==atoi(c);}
I initially tried used a lambda expression, but auto a=[] is three more characters, and less one more for no trailing semicolon. On the other hand, since atoi is not referenced until the lambda is instantiated, could I delete the #include and put that in the test harness footer instead?
C (gcc), 27 bytes
f(s,t){s=atoi(s)==atoi(t);}
With -O0 (which is the default setting).
C, 32 bytes
f(s,t){return atoi(s)==atoi(t);}
><>, 2 + 3 = 5 bytes
=n
Uses the -v flag to pass the values into the program. This automatically converts them to numbers, removing the spaces and leading 0s. It then outputs if the two are equal, and exits with an error as it tries to compare an empty stack.
R, 37 35 bytes
pryr::f(as.double(x)==as.double(y))
There's probably some cleverer way to coerce strings to numerics but I haven't figured it out yet.
Jelly, 8 bytes
t€⁶V€€ḌE
Try it online! or see the test suite
35 answers, and no Jelly submission? Takes the argument as a list (["0001", "1 "] for the first example)
How it works
t€⁶V€€ḌE - Main link. Argument: list e.g. ["0001", "1 "]
€ - For €ach element... ["0001", "1"]
t - trim from both sides...
⁶ - spaces
€ - For €ach element...
V€ - evaluate €ach character [[0, 0, 0, 1], [1]]
Ḍ - Convert from digits [1, 1]
E - Are they equal? 1
APL (NARS2000), 7 bytes
=⍥⍎
Well, yes, I do know NARS2000 can't compete over Dyalog here since it uses Unicode, but I thought I'd rather show off ⍥ (called Composition in NARS2000, even though it's actually unrelated to function composition), something Dyalog doesn't have as a built-in and I haven't ever seen used here. In Dyalog, it has to be implemented as {(⍵⍵⍺)⍺⍺⍵⍵ ⍵}. What it does is call the right operand monadic function on both the left and right argument, and then call the left operand dyadic function on the results.
Here, the right operand is ⍎ (Execute, i.e. eval) and the left operand is = (Equal To, i.e. check if its arguments are equal).
PowerShell, 20 bytes
param($a,$b)+$a-eq$b
Similar to the JavaScript answer, just longer because PowerShell doesn't have currying. Uses + to cast the first string to integer, and then the -equals automatically casts the second string to integer. Output is True/False.
Sinclair ZX81/Timex TS1000/1500 BASIC, ~29 tokenized BASIC bytes
New solution thanks to Neil (thanks for the tip).
1 INPUT A$
2 INPUT B$
3 PRINT VAL A$=VAL B$
This solution requires user input, so enter in two strings with white spaces and/or leading zeros, or enter two strings of non-equal numeric value; 0 is false and 1 is true once line three has compared the value of each string entered.
Old solution: Sinclair ZX81/Timex TS1000/1500 BASIC, ~46 tokenized BASIC bytes
1 LET A$=" 001 "
2 LET B$="1"
3 PRINT (VAL A$=VAL B$)
The actual check is done in line three, which is only ~16 tokenized BASIC bytes; so entering each test case pair using direct mode will save ~30 bytes from the listing. Note that this byte count does not include the var stack.
SNOBOL4 (CSNOBOL4), 42 bytes
OUTPUT =EQ(EVAL(INPUT),EVAL(INPUT)) 1
END
Outputs 1 for truthy, nothing for falsey. Since (space) is the concatenation operator in SNOBOL, EVALing a number with leading/trailing spaces yields the number itself, and it also neatly takes care of any leading zeroes. EQ tests for numerical equality, conditionally setting OUTPUT to 1 on Success.
Husk, 3 bytes
¤=r
Explanation
¤ -- combine both arguments of ..
= -- .. equality ..
r -- .. with read
Taxi, 488 bytes
Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to The Babelfishery.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s 1 l 1 r.Pickup a passenger going to Equal's Corner.Pickup a passenger going to Equal's Corner.Go to Equal's Corner:n 1 l 1 l 1 l.Switch to plan "b" if no one is waiting.'1' is waiting at Writer's Depot.[b]'0' is waiting at Writer's Depot.Go to Writer's Depot:n 1 l 1 r.Pickup a passenger going to Post Office.Go to Post Office:n 1 r 2 r 1 l.
Ungolfed:
Go to Post Office: west 1st left 1st right 1st left.
Pickup a passenger going to The Babelfishery.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: south 1st left 1st right.
Pickup a passenger going to Equal's Corner.
Pickup a passenger going to Equal's Corner.
Go to Equal's Corner: north 1st left 1st left 1st left.
Switch to plan "b" if no one is waiting.
'1' is waiting at Writer's Depot.
[b]
'0' is waiting at Writer's Depot.
Go to Writer's Depot: north 1st left 1st right.
Pickup a passenger going to Post Office.
Go to Post Office: north 1st right 2nd right 1st left.
Taxi is (relatively) well-suited to this challenge because strings are the only input or output type allowed. The Babelfishery is what converts strings to number (and vice versa) and it handles stripping all the spaces and leading zeroes. It will also handle negative numbers if the - is immediately before the first digit. After that, Equal's Corner checks the two values against each other and Writer's Depot provides the output in string format. Output is 1 for truthy and 0 for falsey.
Attache, 11 bytes
Same@Map&:N
This takes an array of strings, such as V["0001", "1 "]. Simply stated, Map&:N is a function that maps N over its argument, and Same checks that the array contains only equal members. (Fun fact: this function works for more than 2 string arguments.)
Operation Flashpoint scripting language, 33 bytes
f={call format(["%1==%2"]+_this)}
Call with:
hint format["%1\n%2\n%3\n%4\n%5",
["0001", "1 "] call f,
["1450", "1450 "] call f,
["0010001 ", " 10001 "] call f,
["0010000", " 10 "] call f,
["101023", "101024"] call f]
Output:
Alternative version (41 bytes):
f={{t=call _x;r=t==s;s=t}forEach _this;r}
Still 5 bytes shorter than the more straightforward f={t=_this;call(t select 0)==call(t select 1)}
39 bytes:
f={{t=call _x;r=t==s;s=t}count _this;r}
count (which returns the size of an array) works instead of forEach, because you can give it a "lambda" that is used as a condition to count only the array elements that meet that condition. The "condition" used in this case is not a valid condition, but it doesn't matter here because it doesn't cause an error and the return value of the count is not needed.
Stacked, 8 bytes
[#~\#~=]
Explanation
[#~\#~=] anonymous function
#~ eval TOS
\ swap top two
#~ eval TOS
= push equality of top two
Wolfram Language, 27 bytes
ToExpression[#1<>"=="<>#2]&
Test cases:
In[1]:= ToExpression[#1 <> "==" <> #2] &["0001", "1"]
Out[1]= True
In[2]:= ToExpression[#1 <> "==" <> #2] &["1450", "1450 "]
Out[2]= True
In[3]:= ToExpression[#1 <> "==" <> #2] &["0010001", " 10001"]
Out[3]= True
In[4]:= ToExpression[#1 <> "==" <> #2] &["0010000", " 10 "]
Out[4]= False
In[5]:= ToExpression[#1 <> "==" <> #2] &["101023", "101024"]
Out[5]= False
Pyth, 4 bytes
qFsM
Int-parse each element of the input list with sM(Q), then Fold over equality.
jq, 24 characters
map(tonumber)|.[0]==.[1]
The 2 strings are passed as items of an array.
Sample run:
bash-4.4$ jq 'map(tonumber)|.[0]==.[1]' <<< '["0010001 ", " 10001 "]'
true
bash-4.4$ jq 'map(tonumber)|.[0]==.[1]' <<< '["0010000", " 10 "]'
false
Gema, 21 characters
*\n*=@cmpn{*;*;0;1;0}
No boolean in Gema. As the @get-switch{}/@set-switch{} functions use 0 and 1 to represent switch statuses, also used 0 and 1.
The 2 strings are passed on separate input lines.
Sample run:
bash-4.4$ gema '*\n*=@cmpn{*;*;0;1;0}' <<< $'0010001\n10001 '
1
bash-4.4$ gema '*\n*=@cmpn{*;*;0;1;0}' <<< $'0010000\n 10 '
0
Alice, 7 bytes
X/n
o@i
Any non-digit separator works. Prints 1 for equality and 0 otherwise.
Explanation
X XOR, does nothing.
/ Switch to Ordinal mode.
i Read all input as a string.
/ Switch to Cardinal mode.
X XOR. Implicitly finds all integers in the string and pushes them separately
onto the stack. The XOR gives 0 if the values are identical.
n Logical NOT. Gives 1 for equal inputs and 9 otherwise.
/ Switch to Ordinal.
o Print the 0 or 1 as a string.
/ Switch to Cardinal.
@ Terminate the program.
Retina, 11 bytes
.+
$*
D`
¶$
Input is linefeed separated, but the test suite uses comma separation for convenience. Prints 1 for equality and 0 for inequality.
Explanation
.+
$*
Convert each line to unary. This ignores leading zeros and spaces.
D`
Deduplicate: clear the second line if both are the same.
¶$
Check that the string now ends in a linefeed.
Triangularity, 17 bytes
..)..
.Ii).
@Ii=.
Triangularity is, for once, competitive!
How it works
Triangularity requires the code to have a triangular distribution of the dots. That is, the length of each row must be equal the number of rows multiplied by 2 and decremented, and each row must have (on each side) a number of dots equal to its position in the program (the bottom row is row 0, the one above it is row 1 and so forth). Keeping this in mind, let's analyse how the code works:
..).. || Push a 0 onto the stack.
.Ii || Get the 0th input and cast it to an integer.
). || Push another 0 onto the stack.
@I || Increment the ToS => 1. Get the first input.
i=. || Then cast it to an integer and compare their equality.
05AB1E, 1 byte
Q
Explanation
Comparison for equality Q will automatically try to evaluate strings as ints before comparing.
