2つの数値を比較する


25

チャレンジ

二つの整数を考えるAB、入力として、あなたは、次の場合に出力するプログラムを作成する必要がありA>BA==BまたはA<B

整数は、少なくとも256個の値を含む、言語でサポートされる任意の妥当な範囲になります。

プログラムは、STDINまたは関数の引数を介して入力を受け取る完全なプログラムまたは関数のいずれかです。

出力

もし A>B出力する

A is greater than B

もし A==B出力する

A is equal to B

もし A<B出力する

A is less than B

置換する場所ABその整数値。

勝ち

バイト単位の最短プログラムが優先されます。

リーダーボード

var QUESTION_ID=55693,OVERRIDE_USER=8478;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>


今日のプログラミングパズルとコードゴルフ:三項の声明!
トレブシェット

関数は、ソリューションを出力するのではなく、単にソリューションを返すことができますか?
TheNumberOne

@TheNumberOneいいえ、彼らはソリューションを印刷する必要があります
ベータ崩壊

回答:


11

CJam、47

q~_~-g"is
equal greater less
to than"N/Sf/f=*S*

オンラインで試す

説明:

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

CJamは今日のPythより1バイト短いように見えます:(
orlp

入力のいくつかの部分を読み取るためのデフォルトに従って、入力を読み取り、コードから[A B]削除することができ]ます。
デニス

@Dennisありがとう、私はそれについて考えていましたが、確かではありませんでした。
-aditsu

@orlp 2バイトになりました。それが眉をひそめるのではなく、笑う理由です:)
aditsu

あなたのコードが実際に~_~... の形でスマイリーを含むことは適切です
ダレルホフマン

19

Python 2、95 94 76バイト

入力はコンマで区切る必要があります。

A,B=input();print A,'is',['equal to','greater than','less than'][cmp(A,B)],B

私は興味をそそられています、何cmp(A,B)が何をするのか説明できますか?:)
ベータ崩壊

2
@BetaDecay、docs.python.org/2/library/functions.html#cmp。「2つのオブジェクトxとyを比較し、結果に応じて整数を返します。戻り値は、x <yの場合は負、x == yの場合はゼロ、x> yの場合は厳密に正です。」cPython 2.7.6では、これらの整数の値はそれぞれ-1、0、1です。関数の定義はこれを指示しないので、教科書は、「Python 2」ではなく、Pythonの正確な実装とバージョンがここに与えられたと主張するかもしれませんが、ほとんどの実装はここでも同じように動作するでしょう。
ymbirtt

私はちょうどあなたが私が思い付くためにあなたの答えをコピーしなかったことを知ってほしい鉱山。私はちょうど彼らがどれほど近いか見ました。私が書いたとき、スニペットを実行するのに問題があり、まだPythonの回答がなかったと誓うことができました(2ページ目を見逃したに違いありません)。奇妙なことに、私は完全に独立してそれを書きました。
mbomb007

SP3000私はそれをチェックし、それは、Python 2.7.6に完全に正常に動作します@
ML

1
@ML私のコメントは過去の改訂を参照していましたが、現在は古くなっているため、コメントを削除しました
-Sp3000

10

ラビリンス180の 152 149バイト

<
?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.{!@

編集:、および(文字コード、および)を再利用すること10により101、3バイトを削ることができました。以下の説明はこれを反映していませんが、実質的な変更ではありません。103108egl

説明

文字列を印刷するためにバイトを節約する方法でできることはあまりありません。それは単に長い直線セクションになります。したがって、ゴルフの主な課題は、大量の不要な空白を避けることです。つまり、一番左の列から線形部分を「放射」させたいということです。また、印刷するコードを再利用することで、さらに節約できます。than B。ここで、制御フローを見てみましょう。

プログラムは、グリッド回転コマンドで開始し<ます。これにより、現在の行がIPのある左に循環的にシフトするため、次のようになります。

                                                     <
?.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.{!@

IPは孤立したセル上にあるため、同じコマンドを何度も繰り返し実行しながら、<さらに左に移動して...

                    <
?.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.{!@

この時点で、IPはどこかに行くことができ、最初の線形セクション(2行目)を右から左に実行します。読み取りA、コピー、印刷です。数字、印刷is(およびスペース)の間の区切り文字を使用します。次に、読み取りB、それをコピーAし、-ます。

この時点で、最初に「道路の分岐点」に当たります。差が生じた0場合、IPは一番下のブランチに向かってまっすぐ進み続けます。そのブランチは単に印刷equal toしてからB

それ以外の場合、IPは2つのno-opsに向かって左に移動し""ます。その後、別の分岐点があります。差が負の場合、IPはさらに長い上部分岐に向かって左を取ります。そのブランチは単に印刷greater thanしてからB

差が正の場合、IPは下のブランチに権利を取得し、印刷しlessます。ここでthan、もう一方のブランチから再利用したいと思います。しかし、同時に2つのブランチを接続する必要はありません。不要なスペースがたくさん必要になるからです。代わりに、いくつかのノーオペレーションを使用して、下のブランチをthan上のブランチの開始位置に合わせてから、ソースをもう一度操作します^

                    <
?.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 .{!@

繰り返しますが、これはIPを分離するため、^再度実行され、

                    <
?.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 .{!@

今IPは右と印刷に移動し続けることができるthanB必要に応じて。


8

JavaScript(ES6)、66バイト

(a,b)=>a+` is ${a<b?"less than":a>b?"greater than":"equal to"} `+b

無名関数を定義します。そのf=前に追加してテストし、次のように呼び出しますalert(f(4, 5))


残念ながら、繰り返しの「より」から節約されるものはありません。


本気ですか?Javaの回答は、;)を回避するようです;
ベータ崩壊

3
@BetaDecayまあ、いや。Javaの答えでさえ、thanpublic void c(int a,int b){System.out.print(a+" is "+(a==b?"equal to ":a>b?"greater than ":"smaller than ")+b);}
edc65

@BetaDecay実際にテキストを出力しない場合、これは有効な回答ですか?またはalert()、スコアに7を追加する必要があります。
curiousdannii

@curiousdanniiああ、そうですねalert()、コードとバイトカウントの一部としてカウントしない場合、これは無効です
ベータディケイ

@BetaDecayああ、答えが返されるだけでなく印刷されると期待されていることに気づきませんでした。REPL環境が問題ない場合、これはFireFoxコンソールで無料で実行できます。それ以外の場合は最大73です。
jrich15年

8

Java、114 113バイトまたはラムダ表記を使用した場合は74 72 67

カリーリングベースのソリューションを提供してくれたKevin Cruijssenに感謝します。

a->b->a+" is "+(a==b?"equal to ":(a>b?"greater":"less")+" than ")+b

古いプレラムダソリューション

public void c(int a,int b){System.out.print(a+" is "+(a==b?"equal to ":(a>b?"greater":"less")+" than ")+b);}

コメントのユーザーhjkの意味として、lambdaを使用した場合、74バイトまで大幅に削減できます。

(a,b)->a+" is "+(a==b?"equal to ":(a>b?"greater":"less")+" than ")+b;

1
巧妙な圧縮方法than:)
TheNumberOne

4
public必要に応じて削除できます。これをラムダにすることをお勧めします。の前の1つのスペースを削除でき{ます。
TheNumberOne

1
また、#Javaの後にカンマを追加して、リーダーボードに参加できるようにします。;)
TNT

2
公式の質問仕様は、「小さく」ではなく「小さく」と言うことです。あなたもそれをして3バイトを失うかもしれません!私はJavaを知りませんが、ラムダコードはテキストを印刷するのですか、それとも単に返すのですか?印刷されない場合、おそらく有効な答えではありません。
curiousdannii

2
@hjkカリー化を使用したラムダの短縮:a->b->a+" is "+(a==b?"equal to ":(a>b?"greater":"smaller" )+" than ")+bはい、ほぼ2年が経過しています。;)そして、上記の2つのコメントで述べたように、チャレンジの説明lesssmaller基づく代わりに実際に使用できます。ここで試して、カレーがどのように行われるかを確認してください。
ケビンCruijssen

7

R、80バイト

function(A,B)cat(A,"is",c("less than","equal to","greater than")[2+sign(A-B)],B)

1
上記の仕様に従うために「より小さい」を「より小さい」に変更すると、3バイト節約できます。三項演算子を使用しない場合は+1。
bmarks

ああ、ありがとう、私はそれをキャッチしませんでした!一定!
flodel

@bmarks Rには三項演算子がありません。:P
アレックスA.

@AlexA。知っている。リストと符号関数を使用することは、これまでの他の回答(ほとんどが三項演算子などを使用)とは非常に異なっていたことを意味しました。
bmarks

右。比較のために、if / elseを使用した最初の試行は83 function(A,B)cat(A,"is",if(A==B)"equal to"else c(if(A>B)"greater"else"less","than"),B)でした。
flodel

7

Pyth、52 49バイト

jdm@cd)._-FQcj"
is
equal greater less
to than
"Qb

7

ジュリア、69 66バイト

f(A,B)="$A is $(A>B?"greater than":A<B?"less than":"equal to") $B"

これは、文字列補間を使用して埋め込みAB単一の文字列内で、三元。

グレンOのおかげで3バイト節約


6

Perl、64 63バイト

#!/usr/bin/perl -p
s/ /" is ".("equal to ",greaterx,lessx)[$`<=>$']/e;s/x/ than /

62バイト+ 1バイト-p。単一のスペースで区切られた2つの数値を使用して、STDINから入力を取得します。

$ echo 1 2 | ./cmp
1 is less than 2
$ echo 42 -17 | ./cmp
42 is greater than -17
$ echo 123456789 123456789 | ./cmp
123456789 is equal to 123456789

使い方:

<=>オペレータ復帰-1、最初のオペランドが等しい、未満であるか、または第二よりも大きいかどうかに応じて0または1です。便利なことに、Perlでは、最後の要素が位置-1に、最後から2番目の要素が位置-2に、というように、配列とスライスを含む負の添え字を使用できます。

コード内

("equal to ",greaterx,lessx)[$`<=>$']

我々は、の戻り値を使用して<=>対応する文字列、取得するには、リストのスライスに添字として$`最初の数ですし、$'、2番目のです。

の繰り返しを避けるためthanxはプレースホルダーとして使用され、最後の2番目の置換で置き換えられます。


代替ソリューション、63バイト

#!/usr/bin/perl -p
@a=(equal,greater,than,to,less);s/ / is @a[$i=$`<=>$',!$i+2] /

62バイト+ 1バイト -p。最初のソリューションと同様に、STDINからスペースで区切られた入力を取得します。

使い方:

このソリューションもスライスを使用しますが、リストスライスとは異なり、配列スライスを文字列(および置換のRHS)に補間できるという事実を利用しています。これにより、/e、置換演算子に修飾子と引用符を。

実際のトリックは、スライスの添え字にあります。

@a[$i=$`<=>$',!$i+2]

の異なる値に対して<=>、これは以下を与えます:

$i  !$i+2  $a[$i]  $a[!$i+2]
----------------------------
-1    2     less      than
 0    3     equal     to
 1    2     greater   than

配列または配列スライスが文字列に補間されると、要素は自動的に結合さ$"れます(デフォルトでは、単一のスペース)。


5

マウス、79バイト

?A:?B:A.!" is "A.B.<["less than"]A.B.>["greater than"]A.B.=["equal to"]" "B.!$

文字列が見つかると、スタックに置かれるのではなく、すぐにSTDOUTに書き込まれます。スタックには整数のみを含めることができます。

ゴルフをしていない:

? A:                            ~ Read an integer A from STDIN
? B:                            ~ Read an integer B from STDIN
A. !                            ~ Write A to STDOUT
" is "
A. B. < [ "less than" ]         ~ If A < B
A. B. > [ "greater than" ]      ~ If A > B
A. B. = [ "equal to" ]          ~ If A == B
" "
B. !                            ~ Write B to STDOUT
$                               ~ End of program

4

GolfScript、61バイト

\.@.@="equal to "{.@.@>"greater""less"if" than "+}if" is "\+@

スタックに2つの整数が必要です。オンラインでお試しください

使い方:

  • \.@.@-AとBはすでにスタック上にあり、このコードにより、スタックは次のようになりますABBA\スタック上の2つの最上位アイテムを交換し、最上位アイテムを.複製し@、3つの最上位アイテムをローテーションします(1 2 3-> 2 3 1)。

  • 次に、3つの項目がスタックにプッシュされます:=記号、、"equal to "およびの間のブロック{}ifステートメントはこれを行う:最初の引数が真と評価された場合、それは最初のコードブロック(第2引数)を実行し、そうでない場合は、2番目のコードブロック(第3の引数)。したがって、AとBが等しい場合、スタックで「等しい」をプッシュします。それらが等しくない場合、ブロック間でコードを実行します。=スタックから上位2つのアイテムをポップすることに注意してくださいAB。スタックはのようになります。

  • ブロック内には、最初に表示され.@.@ます。これらのコマンドの前のスタックはのようABに見え、その後のスタックはのようになりBAABます。コマンドは上記のものと似ています。

  • 次に、別のifステートメントがあります。今回は、A> Bかどうかをチェックし、trueの場合は、スタックで「より大きい」をプッシュします。それ以外の場合、スタックに「少なく」プッシュします。これら2つのいずれかをプッシュした後、スタック上で「より」をプッシュし、前にプッシュした文字列と連結します。>スタックの上位2つのアイテムもポップするため、スタックはのようになりBA"string"ます。

  • 次の3つのコマンドは次のとおり" is "\+です。" is "その文字列をスタックにプッシュし(スタックはのように見えますBA"string"" is ")、\上位2つの項目をスワップします(スタックはのように見えますBA" is ""string")。+ 2つのトップアイテム連結します(スタックはのように見えますBA" is string")。

  • 最後のコマンド、@3つのスタックアイテムを回転させるので、スタックは次のようになりますA" is string"B。GolfScriptは、プログラムが終了するとスタック値をSTDOUTに自動的に出力するため、目的の出力が得られます。


4

MATLAB、105バイト

x=input('');y=input('');t={'less than','greater than','equal to'};
sprintf('%i is %s %i',x,t{(x>=y)+(x==y)+1},y)

読みやすくするために、sprintfの前に改行を追加しました。この改行を使用しても使用しなくても機能するため、バイトカウントには含まれません。2つの入力番号の間でEnterキーを押す必要があります。


2
の非常に巧妙な使用sprintf
ルイスメンドー


4

Fortran、129

Fortran 算術演算ifこの課題に最適な

テスト:イデオン

read(*,*)i,j
if(i-j)1,2,3
1 print*,i," is less than",j
stop
2 print*,j," is equal to",j
stop
3 print*,i," is greater than",j
end

3

Bash、94 86バイト(Digital Traumaのおかげで8バイトを節約)

p=equal;q=than;(($1>$2))&&p=greater&&[ ]||(($1<$2))&&p=less||q=to;echo $1 is $p $q $2

テスト(Linuxの場合):

echo 'p=equal;q=than;(($1>$2))&&p=greater&&[ ]||(($1<$2))&&p=less||q=to;echo $1 is $p $q $2' > cmp.sh
chmod +x cmp.sh
./cmp.sh 10 12
10 is less than 12

[ ]after の使用は、式で演算子が前に評価さp=greaterれないようにすることです||=...&&p=greater||(($1<$2))... の中で演算子がです(演算子の優先順位!)。

(($1>$2))&&p=greaterまたは(($1<$2))&&p=less、の周りに角かっこを使用することもできますが、角かっこは変数の内部スコープを作成するため、p変更されません。


1
p=equal;q=than;(($1>$2))&&p=greater&&[ ]||(($1<$2))&&p=less||q=to;echo $1 is $p $q $2
デジタル外傷

3

IA-32マシンコード+ Linux、107バイト

コードのHexdump:

60 89 e5 89 d0 e8 51 00 00 00 4c c6 04 24 20 38
d1 74 20 68 74 68 61 6e 4c c6 04 24 20 72 0d 68
61 74 65 72 68 20 67 72 65 44 eb 11 68 6c 65 73
73 eb 0a 68 6c 20 74 6f 68 65 71 75 61 68 20 69
73 20 88 c8 e8 12 00 00 00 89 ea 29 e2 89 e1 31
db 43 8d 43 03 cd 80 89 ec 61 c3 5b d4 0a 4c 04
30 88 04 24 c1 e8 08 75 f3 ff e3

ハードウェアの制限のため、コードは0〜255の範囲の数値で動作します。

ソースコード(gccでアセンブル可能):

    .globl print_it
    .text
    .align 16
print_it:
    pushal;
    mov %esp, %ebp; // save esp (stack pointer)
    mov %edx, %eax; // put second number in al
    call prepend;   // convert al to string

    dec %esp;       // write ...
    movb $' ', (%esp); // ... a space
    cmp %dl, %cl;   // compare the numbers
    je equal;       // if equal, goto there

    push $0x6e616874; // write "than"
    dec %esp;       // write ...
    movb $' ', (%esp); // ... a space
    jb less;        // if below, goto there

greater:
    push $0x72657461; // write "ater"
    push $0x65726720; // write " gre"
    inc %esp;         // remove a space
    jmp finish;     // bypass the code for "less than"

less:
    push $0x7373656c; // write "less"
    jmp finish;     // bypass the code for "equal"

equal:
    push $0x6f74206c; // write "l to"
    push $0x61757165; // write "equa"

finish:
    push $0x20736920; // write " is "

    mov %cl, %al;   // put first number in al
    call prepend;   // convert al to string

    mov %ebp, %edx; // calculate the length ...
    sub %esp, %edx; // ... of the output message
    mov %esp, %ecx; // address of the message
    xor %ebx, %ebx; // set ebx to ...
    inc %ebx;       // ... 1 (i.e. stdout)
    lea 3(%ebx), %eax; // set eax=4 (syscall "write")
    int $0x80;      // do the system call
    mov %ebp, %esp; // restore the stack pointer
    popal;          // restore other registers
    ret;            // return

prepend:            // writes al converted to string
    pop %ebx;       // remove return address from the stack
appendloop:
    aam;            // calculate a digit in al, rest in ah
    dec %esp;
    add $'0', %al;  // convert the digit to ASCII
    mov %al, (%esp);// write the digit
    shr $8, %eax;   // replace al by ah; check if zero
    jnz appendloop; // nonzero? repeat
    jmp *%ebx;      // return

これはスタックの深刻な乱用です!コードは、最後から最初まで、スタック上に出力メッセージを構築します。4バイトを書き込むには、単一のpush命令を使用します。1バイトを書き込むには、2つの命令を使用します。

dec %esp
mov %al, (%esp);

運がよければ、書き込むフラグメントのほとんどは4バイトです。それらの1つ(「より大きい」の「gre」)は3バイトです。4バイトをプッシュし、その後1バイトを削除することで処理されます。

inc %esp

10進数形式で数値を書き込むルーチンは、aam命令を使用axして10繰り返し除算します。右から左に数字を計算することは有利です!


記述する数値は2つあるため、コードはサブルーチンを使用します。サブルーチンは2回呼び出されます。ただし、サブルーチンは結果をスタックに書き込むため、レジスタを使用して戻りアドレスを保持します。


上記のマシンコードを呼び出すCコード:

include <stdio.h>

void print_it(int, int) __attribute__((fastcall));

int main()
{
    print_it(90, 102);
    puts("");
    print_it(78, 0);
    puts("");
    print_it(222, 222);
    puts("");
    return 0;
}

出力:

90 is less than 102
78 is greater than 0
222 is equal to 222

3

ShortScript、98バイト

←Α
←Β
↑Γαis
↔α>β→γgreater thanβ
↔α<β→γless thanβ
↔α|β→γequal toβ

Shortチャレンジはこのチャレンジの後に公開されたため、この答えは競合しません。


3

フーリエ147 74バイト

文字列印刷はこの課題よりも新しいため、競合しない

I~AoI~B` is `<A{1}{`greater than`}A<B{1}{`less than`}A{B}{`equal to`}` `Bo

FourIDEでお試しください!

ダンノ、なぜ以前は印刷を許可しなかったのか...コードが読みやすく、ゴルフに最適


変数101やなどの一般的な文字116を変数に割り当てることで保存できるはずですよね?変数スコープがどのように/どのように処理されるかわかりません。
ジオビット

@Geobitsフーリエにはローカルスコープがありません。そのため、私はそれに取り組みます
ベータ崩壊

@Geobitsは変数を使用してもう少しゴルフしました
ベータ崩壊

2

C、155の 136 127 83バイト

f(a,b){printf("%d is %s %d\n",a,a>b?"greater than":a<b?"less than":"equal to",b);}

5
You can make this much shorter - rename argc and argv, define both a and b in one line, skip the argc check, and more.
ugoren

1
Note that the requirement is either a complete program or a function. A function would be much shorter.
ugoren

@ugoren I was not sure whether it could be a function, so I decided to write a complete program. I'm gonna refactor it. Thank you again!
Mauren

2

Haskell, 87 bytes

One byte shorter than Otomo's approach.

a?b=show a++" is "++["less than ","equal to ","greater than "]!!(1+signum(a-b))++show b

Nice solution. :)
Otomo

2

Lua, 118 bytes

I don't see enough Lua answers here so...

function f(a,b)print(a>b and a.." is greater than "..b or a==b and a.." is equal to "..b or a.." is less than "..b)end

Ungolfed:

function f(a,b)
    print(a>b and a.." is greater than "..b or a==b and a.." is equal to "..b or a.." is less than "..b)
end

Welcome to PPCG!
Dennis

2

Python 2, 78 bytes

I love how cmp() is really useful, but it was removed in Python 3.

Using an anonymous function:

lambda a,b:`a`+' is '+['equal to ','greater than ','less than '][cmp(a,b)]+`b`

Not using a function (79 bytes):

a,b=input();print a,'is %s'%['equal to','greater than','less than'][cmp(a,b)],b

Isn't this a dupe of @TheNumberOne's answer?
Beta Decay

@BetaDecay Nope. They are different. Read my comment on that answer.
mbomb007

2

JavaScript, 151 104 100 95 92 bytes

a+=prompt()
b+=prompt()
alert(a+" is "+(a>b?"greater than ":a<b?"lesser than ":"equal to ")+b)

I managed to shorten with help of edc65


I am a JavaScript newbie...
Kritixi Lithos

May I ask what you are using to find your score?
Beta Decay

Not it's broken (syntax error). Just try before posting
edc65

Is there an error now?
Kritixi Lithos

1
a = expression. That is an initialisation. var a is declaring the variable a. You have to use it in real code for a lot of good reasons. But it's optional in javascript and avoiding var you save 4 charactes
edc65

2

C# 6, 113 103 100 95 bytes

void C(int a,int b){System.Console.Write($"{a} is {a-b:greater than;less than;equal to} {b}");}

Thanks to edc65 for saving 13 bytes and to cell001uk for saving 5 bytes using C# 6's interpolated strings!


Save 10 bytes void C(int a,int b){System.Console.Write("A is {0} B",a==b?"equal to":a>b?"greater than":"less than");}
edc65

@edc65 Nice, thanks!
ProgramFOX

I love C# formatting: Write("{0} is {1:greater than;less than;equal to} {2}",a,a-b,b)
edc65

@edc65 Woah, that's awesome! Thanks! Also thanks for reminding me that A and B have to be replaced by their values, I totally overlooked that >_>
ProgramFOX



1

Pyth, 57 55 53 bytes

AQjd[G"is"@c"equal to
greater than
less than"b._-GHH)

This basically does:

["less than", "greater than", "equal to"][sign_of(A-B)]

Saved 2 bytes thanks to @AlexA.'s suggestion of using A instead of J and K and another 2 bytes by replacing the whole addition mess with a simpler subtraction.

Live demo and test cases.

55-byte version

AQjd[G"is"@c"less than
greater than
equal to"b+gGHqGHH)

Live demo and test cases.

57-byte version:

jd[JhQ"is"@c"less than
greater than
equal to"b+gJKeQqJKK)

Live demo and test cases.


One byte shorter: AQs[Gd"is"d?<GH"less than"?>GH"greater than""equal to"dH
Alex A.

@AlexA. I just used the suggestion of A instead of J and K, which saved 2 bytes.
kirbyfan64sos


1

SWI-Prolog, 94 bytes

a(A,B):-(((A>B,C=greater;A<B,C=less),D=than);C=equal,D=to),writef("%t is %t %t %t",[A,C,D,B]).

1

Swift, 105 92 byte

func c(a:Int, b:Int){println("A is",(a==b ?"equal to":(a<b ?"less":"greater")," than"),"B")}

even shorter with Swift 2.0 (103 90 byte)

func c(a:Int, b:Int){print("A is",(a==b ?"equal to":(a<b ?"less":"greater")," than"),"B")}

1

Processing, 92 bytes

void c(int a,int b){print(a+" is "+(a>b?"greater than ":a<b?"lesser than ":"equal to ")+b);}
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.