Comparing two numbers
Python 2, 95 94 76 bytes
Input must be comma separated.
A,B=input();print A,'is',['equal to','greater than','less than'][cmp(A,B)],B
CJam, 47
q~_~-g"is
equal greater less
to than"N/Sf/f=*S*
Try it online
Explanation:
q~ read and evaluate the input (array of 2 numbers)
_ duplicate the array
~- dump one array on the stack and subtract the numbers
g get signum (-1 for <, 0 for ==, 1 for >)
"…" push that string
N/ split into lines
Sf/ split each line by space
f= get the corresponding word (for the signum) from each line
* join the array of 2 numbers by the array of words
it effectively inserts the words between the numbers
S* join everything with spaces
Labyrinth, 180 152 149 bytes
<
?01.23.511.501.23};,!:?
:
= ;3.114.101.97.116.101.114.32.116.104.97.110.32.{!@
-""
; ;8.101.115:..""""""""""""^
1
.113.117.97.108.32.116.111.32.{!@
Edit: Managed to shave off 3 bytes by reusing 10
between 101
, 103
and 108
(the character codes of e
, g
and l
). The explanation below does not reflect this, but it's not a substantial change.
Explanation
There isn't much we can do in the way of saving bytes for printing the strings, that's just going to be long linear sections. So the main challenge in golfing is to avoid large amounts of unnecessary whitespace. That means we want the linear parts to "radiate out" from the left-most column. We can also gain some more savings by reusing the code that prints than B
. So let's look at the control flow here:
The program starts on a grid rotation command <
. This shifts the current row cyclically to the left with the IP on it, so we get this:
<
?.23.511.501.23};,!:?
:
= ;103.114.101.97.116.101.114.32.116.104.97.110.32.{!@
-""
1 ;108.101.115:..""""""""""""^
0
1.113.117.97.108.32.116.111.32.{!@
Now the IP is on an isolated cell, so it executes the same command again and again while the <
travels further to the left until...
<
?.23.511.501.23};,!:?
:
= ;103.114.101.97.116.101.114.32.116.104.97.110.32.{!@
-""
1 ;108.101.115:..""""""""""""^
0
1.113.117.97.108.32.116.111.32.{!@
At this point, the IP has somewhere to go and executes the first linear section (the second row) from right to left. What it does is read A
, copy, print. Consume the delimiting character between the numbers, print is
(and spaces). Then read B
, copy it and subtract A
from it at the -
.
At this point we hit first "fork in the road". If the difference yielded 0
, the IP keeps moving straight ahead towards the bottom branch. That branch simply prints equal to
and then B
.
Otherwise, the IP takes a left towards the two no-ops ""
. Then there's another fork. If the difference was negative, the IP takes another left towards the long upper branch. That branch simply prints greater than
and then B
.
If the difference was positive, the IP takes a right onto the lower branch, which prints less
. Now we want to reuse the than
from the other branch. But at the same time we don't want to connect the two branches later on, because we'd need a whole bunch of unnecessary spaces. Instead we use a few no-ops to align the lower branch with where the than
begins on the upper branch and then start manipulating the source again with ^
:
<
?.23.511.501.23};,!:?
: .
= ;103.114.101.97.116.101.114 32.116.104.97.110.32.{!@
-"" ^
1 ;108.101.115:..""""""""""""
0 2
1.113.117.97.108.32.116.111.3 .{!@
Again, this is isolates the IP, so ^
is executed again and we get
<
?.23.511.501.23};,!:? .
:
= ;103.114.101.97.116.101.114^32.116.104.97.110.32.{!@
-""
1 ;108.101.115:..""""""""""""2
0
1.113.117.97.108.32.116.111.3 .{!@
Now the IP can continue moving to the right and print than
and B
as required.