Javaを生成します


14

あなたの上司は、次のようなコードを書くことを望んでいます。

public static boolean isPowerOfTen(long input) {
  return
    input == 1L
  || input == 10L
  || input == 100L
  || input == 1000L
  || input == 10000L
  || input == 100000L
  || input == 1000000L
  || input == 10000000L
  || input == 100000000L
  || input == 1000000000L
  || input == 10000000000L
  || input == 100000000000L
  || input == 1000000000000L
  || input == 10000000000000L
  || input == 100000000000000L
  || input == 1000000000000000L
  || input == 10000000000000000L
  || input == 100000000000000000L
  || input == 1000000000000000000L;
}

(Martin Smith、https://codereview.stackexchange.com/a/117294/61929

これは効率的ですが、入力するのは面白くありません。キーを押す回数を最小限に抑えるため、この関数を出力する(または出力に文字列を返す)短いプログラムまたは関数(またはメソッド)を作成します。また、Unicode 8.0のすべてに必要な120,737個のキーをすべて備えた独自のカスタムフルレンジUnicodeキーボードを使用しているため、キー押下ではなくUnicode文字をカウントします。または、あなたの言語がユニコードソースコードを使用していない場合、バイト。

プログラムや関数の入力はすべてスコアにカウントされます。明らかに入力する必要があるためです。

明確化と編集:

  • 最後の3つの末尾のスペースを削除しました }
  • 後に単一の末尾スペースを削除しました return
  • 関数/メソッドから出力の文字列を返すことは問題ありません

12
0==Math.log10(input)%1
SuperJedi224

7
ユニコード文字を数えます」と言いますが、すぐに「またはバイト」と言います。どちらですか?
ドアノブ

2
どちらを選んでも、つまり最低のスコアを与えます。テキストソースを使用しない言語を許可するためにバイトを追加しました。
フィリップハグランド

1
while(input%10==0) input/=10; return input == 1;
PSkocik

4
05AB1Eは、UnicodeではなくバイトであるWindows CP1252を使用します。私は標準的なルールを目指していますが、いつも間違っていると言われます。
フィリップハグランド

回答:


15

PostgreSQL、158文字

select'public static boolean isPowerOfTen(long input) {
  return
   '||string_agg(' input == 1'||repeat('0',x)||'L','
  ||')||';
}'from generate_series(0,18)x

私は、RDBMSがコードゴルフの答えとして使用されるのを見たことがありません...甘い!+1
クリスクレフィス16

このサイトでは、@ ChrisCirefice SQLが実際に一般的です。(または、少なくとも予想以上に一般的です。)
アレックスA.

@AlexA。うーん、よくPCGはあまり頻繁ではないSEサイトの1つなので、SQLの回答は見たことがありません:)
クリスサイレフィス

7

Vim 97のキーストローク

ipublic static boolean isPowerOfTen(long input) {
  return
  || input == 1L<esc>qyYpfLi0<esc>q16@yo}<esc>3Gxx

さて、私は今日、vimを生成するJavaを使用しています。


に置き換えるfL$、キーストロークを節約できます
Leaky Nun

また、第3ラインは、input == 1L1バイト...によってずれている
漏れ修道女

そのため、最後のキーをx変更しr<sp>、キーストロークの数を変更する必要があります
Leaky Nun


7

CJam、52文字

YA#_("𐀑򀺸󆚜񸎟񜏓񞍁򛟯󩥰󾐚򉴍􍼯𹾚򶗜򳙯󭧐񹷜񊽅𸏘򴂃򦗩󧥮𤠐𰑈򶂤𘏧󔆧򇃫󡀽򊠑񊩭򯐙񛌲񊚩𤱶𻺢"f&bY7#b:c~

オンラインでお試しください!

ステージ1

Unicode文字U + 10000からU + 10FFFFを使用して、1文字で20ビットをエンコードできます。CJamは内部で16ビット文字を使用するため、それぞれがU + D800からU + DBFFの範囲のサロゲートのペアとしてエンコードされ、その後にU + DC00からU + DFFFの範囲の1つが続きます。

各サロゲートのビットごとのANDを1023と取得することにより、エンコードされた10ビットの情報を取得します。結果の配列をベース1024からベース128に変換して、BMP以外のUnicode文字の任意の文字列をASCII文字列にデコードできます。

コードは次のことを行います。

YA#    e# Push 1024 as 2 ** 10.
_(     e# Copy and decrement to push 1023.

"𑅰󻢶񹱨񉽌񍍎񄆋򎿙򧃮񑩹󠷽􂼩􉪦񭲣񶿝򭁩󭰺􄔨񍢤𘎖񮧗򦹀𹀠񐢑񜅈𠟏򘍎󾇗򲁺􅀢򅌛񎠲򦙤򃅒𹣬񧵀򑀢"

f&     e# Apply bitwise AND with 1023 to each surrogate character.
b      e# Convert the string from base 1024 to integer.
Y7#    e# Push 128 as 2 ** 7.
b      e# Convert the integer to base 128.
:c     e# Cast each base-128 to an ASCII character.
~      e# Evaluate the resulting string.

ステージ2

上記のデコードプロセスにより、次のソースコード(98バイト)が生成されます。

"public static boolean isPowerOfTen(long input) {
  return
   ""L
  || input == ":S6>AJ,f#S*"L;
}"

オンラインでお試しください!

コードは次のことを行います。

e# Push the following string.

"public static boolean isPowerOfTen(long input) {
  return
   "

e# Push the following string and save it in S.

"L
  || input == ":S

e# Discard the first 6 characters of S. The new string begins with " input".

6>

e# Elevate 10 (A) to each exponent below 19 (J).

AJ,f#

e# Join the resulting array, using the string L as separator.

S*

e# Push the following string.

"L;
}"

あなたは、ユダヤ教のようなSEのサイトは、サイトのUnicodeサポートをストレステストのものであることを期待するかもしれないが、これはクレイジーです:D
フィリップハグランド

引用符の間の文字を正確に2つ見ることができます。hexdumpを投稿できますか?
パベル

実際に2つ見ることができますか?そのような運はありません...文字をUTF-8としてエンコードすると、hexdumpは次のようになります。tio.run/nexus/bash#AagAV///eHhkIC1nIDH//…–
デニス

6

Java(登録商標)、217の 215 220 219 192バイト

ゴルフ済み:

public static String b(){String s="public static boolean isPowerOfTen(long input) {\n  return\n    input == 1L",z="";for(int i=0;i++<18;){z+="0";s+="\n  || input == 1"+z+"L";}return s+";\n}";}

ゴルフをしていない:

  public static String a(){
    String s = "public static boolean isPowerOfTen(long input) {\n  return\n    input == 1L", z="";
    for (int i=0; i++ < 18;) {
        z += "0";
        s += "\n  || input == 1"+z+"L";
    }
    return s + ";\n}";
  }

(最初の答え、湖)

ありがとう!
-2バイト:user902383
-1バイト:Denham Coote

変更点:

  • スペースの代わりにタブを使用
  • 出力の最後の行を逃した:18-> 19
  • 内側のループを削除
  • 印刷から文字列を返すように変更

4
内側のforループには括弧は必要ありません
-user902383

Java 8構文を使用し、他の要素も短縮しました:()->{String s="public static boolean isPowerOfTen(long input) {\n\treturn input == 1L";for(int i=0,k;i++<18;){s+="\n\t|| input == 1";for(k=0;k++<i;)s+="0";s+="L";}return s+";\n}";}(180バイト)印刷する代わりに文字列を返すようになりましたが、それは短くなっています。
アディソンクランプ

1
より詳細なJavaプログラムを生成するための詳細なJavaプログラムを作成するための+1。
チョイス

代わりに、バイトを節約するfor(int i=1;i<19;i++)ように書くことができfor(int i=1;i++<19;)ます
デンハムクート

また、宣言し int i=1,k;た後、あなたが書くことができますfor(;i++<19;)し、for(k=0;k++<i;)
デンハムクート

4

Pyth、118の 106 103バイト

s[."
{Z-L¡JxÙÿ
LæÝ<­í?¢µb'¥ÜA«Ç}h¹äÚÏß"\nb*4dj"\n  || "ms[." uøs|ÀiÝ"*d\0\L)U19\;b\}

オンラインでお試しください!

このすべての文字列のハードコーディングは、実際には多くのバイトを消費しますが、それについては何もできません

更新:パックされた文字列を使用して3バイトを保存しました。ヒントをありがとう@ user81655!


パックされた文字列を使用できます
...-user81655

私はPythを知らず、完全な文字列をパックする方法があるかどうかはわかりません(パッキングプログラムは常にそれを変更します)が、これに結果をパックしてr連結しnます(98バイト)。
-user81655

@ user81655ありがとう、Pythがこれを知っていませんでした。:)最初の大きな文字列をパックするのは理にかなっていますが、フォームをアンパックするオーバーヘッドは、小さな文字列には価値がありません。
デンカー

@ user81655私はそれを知っていますが、103文字を数えます。どのようにして97に到達しましたか?
デンカー

おっと、私の間違い、私はそれらを間違って数えていました。
user81655

4

C#の(CSI)181 180 179バイト

string i=" input == 1",e="public static bool";Console.Write(e+@"ean isPowerOfTen(long input) {
  return
   "+i+string.Join(@"L
  ||"+i,e.Select((_,x)=>new string('0',x)))+@"L;
}")

関与する小さなトリックは1つだけです。これを書く簡単な方法は次のとおりです。

string.Join("L\n  || input == 1",Enumerable.Range(0,18).Select(x=>new string('0',x)))

とにかく必要なテキストの最初の18文字の文字列を使用することで、長いEnumerable.Rangeを取り除くことができます。これは、文字列がIEnumerableを実装し、アイテム(不要)とラムダ関数に必要なインデックスを渡すSelectのバージョンがあるために機能します。


1
@WashingtonGuedesありがとう
-raggy

1
いくつかの説明を追加してください
ユーメル

1
CSIは式本体をサポートしていますか?その場合、{ return ... }はに置き換えることができます=>...
mınxomaτ

現在コンピューター上にないので、これをテストすることはできません。最後の逐語的文字列はその中の括弧をエスケープしますか?それとも、私が知らなかった素晴らしいトリックですか?:)
Yytsi

4

PowerShell、120バイト

'public static boolean isPowerOfTen(long input) {'
'  return'
"   $((0..18|%{" input == 1"+"0"*$_})-join"L`n  ||")L;`n}"

最初の2行は単なる文字列リテラルであり、そのまま出力されます。

3行目は3つのスペースで始まりL;`n}"、最後の数バイトで終わるまでで終わります。スクリプトブロック内の中間ビット$(...)%0to からforループすることで構築され18、各反復input == 1は、対応するゼロの数で連結された文字列を構築します。これにより、文字列の配列が吐き出されます。次に-join、配列の各要素L`n ||を使用して、改行パイプを作成します。その大きな文字列はスクリプトブロックの出力であり、中央に自動的に挿入されて出力されます。

PS C:\Tools\Scripts\golfing> .\go-generate-some-java.ps1
public static boolean isPowerOfTen(long input) {
  return
    input == 1L
  || input == 10L
  || input == 100L
  || input == 1000L
  || input == 10000L
  || input == 100000L
  || input == 1000000L
  || input == 10000000L
  || input == 100000000L
  || input == 1000000000L
  || input == 10000000000L
  || input == 100000000000L
  || input == 1000000000000L
  || input == 10000000000000L
  || input == 100000000000000L
  || input == 1000000000000000L
  || input == 10000000000000000L
  || input == 100000000000000000L
  || input == 1000000000000000000L;
}

3

ジャバスクリプト、172の 157 152 150 148バイト

p=>`public static boolean isPowerOfTen(long input) {
  return${[...Array(19)].map((x,i)=>`
  ${i?'||':' '} input == 1${'0'.repeat(i)}L`).join``};
}`


2
ES7 ${10**i}では、の代わりにを使用して9バイトを節約できます1${'0'.repeat(i)}
ニール

3

C、158155バイト

i;main(){for(puts("public static boolean isPowerOfTen(long input) {\n  return");i<19;)printf("  %s input == 1%0.*dL%s\n",i++?"||":" ",i,0,i<18?"":";\n}");}

こちらからオンラインでお試しください。


:あなたはprintf関数の戻り値を使用する場合は、バイトをオフに剃ることができますi;main(){for(puts("public static boolean isPowerOfTen(long input) {\n return");printf(" %s input == 1%0.*dL%s\n",i++?"||":" ",i,0,i<18?"":";\n}")-37);}
algmyr

3

ゼリー、75バイト

(これらはJellyのカスタムコードページのバイトです。)

0r18⁵*;@€⁶j“¢œḤḅg^NrÞḢ⁷ẉ»“⁵®UẆƓḃÐL⁴ṖịṛFþẈ¹9}¶ ƁḋȮ¦sẒẆd€Ḟɼ¿ỌṀP^µ\f@»;;“L;¶}”

ここで試してみてください。

説明

0r18      Range [0..18]
⁵*        Take the 10^ of each number
;@€⁶      Prepend a space to each number
j“...»    Join by compressed string "L\n  || input =="
“...»;    Prepend compressed string "public static ... =="
;“L;¶}”   Append "L;\n}"

3

Vimscript、120バイト

仕事に適したツールを使用することもできます。

これは、自動インデントなどが設定されていないことを前提としています。 ^[そして、^Mのエスケープ文字があるESCCRそれぞれ。

aマクロは、現在の行を複製し、コピーに0を追加します。この:norm行は、すべてのボイラープレートとindent == 1Laを生成し、他を作成するために使用します。

:let @a='yyp$i0^['
:norm ipublic static boolean isPowerOfTen(long input) {^M  return^M  || input == 1L^[18@a$a;^M}
:3s/||/ /

サンプル出力の2行にある末尾のスペースがタイプミスではなかった場合、それらを含む126バイトのバージョンがあります。

:let @a='yyp/L^Mi0^['
:norm ipublic static boolean isPowerOfTen(long input) {^M  return ^M  || input == 1L^[18@a$a;^M}   
:3s/||/ /

2

Oracle SQL 9.2、311バイト

SELECT REPLACE(REPLACE('public static boolean isPowerOfTen(long input) {'||CHR(10)||'  return'||c||';'||'}', 'n  ||', 'n'||CHR(10)||'   '),CHR(10)||';', ';'||CHR(10)) FROM(SELECT LEVEL l,SYS_CONNECT_BY_PATH('input == '||TO_CHAR(POWER(10,LEVEL-1))||'L'||CHR(10),'  || ')c FROM DUAL CONNECT BY LEVEL<20)WHERE l=19

2

Perl 5の- 130 141

@s=map{'input == 1'.0 x$_."L\n  ||"}0..18;$s[$#s]=~s/\n  \|\|/;\n}/g;print"public static boolean isPowerOfTen(long input){\n  return\n    @s"

編集:正確なインデントを持つように修正


範囲の周りに括弧を使用する必要はありません。変更では、正確なインデントを再現するとよいでしょう。
マナトワーク

忘れてしまった括弧をありがとう。正確なインデントを持つように修正しました。
ChatterOne

g代替のフラグは必要ありません。また\n、その文字列にシングルがあるので、それとそれ以降のすべてを単純に一致させることができます$s[$#s]=~s/\n.+/;\n}/。しかしjoin:ベース1はまだ短くなりpastebin.com/hQ61Adt8
manatwork

ありがとうございますが、ソリューションをコピーして貼り付けるだけではいいとは思わないので、それをそのまま最善の努力として残します。やがて、ゴルフが上手になります:-)
ChatterOne

2

ES6、139バイト

_=>"0".repeat(19).replace(/./g,`
 || input == 1$\`L`).replace(`
 ||`,`public static boolean isPowerOfTen(long input) {
  return\n  `)+`;
}`

これらの三角形生成の質問が大好きです。


2

コトリン、194 193文字

fun main(u:Array<String>){var o="public static boolean isPowerOfTen(long input) {\n\treturn"
var p:Long=1
for(k in 0..18){
o+="\n\t"
if(k>0)o+="||"
o+=" input == ${p}L"
p*=10
}
print("$o;\n}")}

http://try.kotlinlang.org/でテストしてください


プログラミングパズルとコードゴルフへようこそ。最初の回答はいいですが、他の人が確認できるように、オンライン通訳へのリンクを追加するか、このプログラムの実行方法の例を追加してください。しかし、ここで素晴らしい時間を過ごしてください!:)
デンカー

2

ルビー、125 119バイト

$><<'public static boolean isPowerOfTen(long input) {
  return
   '+(0..19).map{|i|" input == #{10**i}L"}*'
  ||'+';
}'

-6バイトのmanatworkに感謝します!


多くのオリジナルではないソリューションのほとんどはこの方法を行っているとして、まだ短い:pastebin.com/1ZGF0QTs
manatwork

2

jq、123文字

(121文字のコード+ 2文字のコマンドラインオプション。)

"public static boolean isPowerOfTen(long input) {
  return
   \([range(19)|" input == 1\("0"*.//"")L"]|join("
  ||"));
}"

サンプル実行:

bash-4.3$ jq -nr '"public static boolean isPowerOfTen(long input) {
>   return
>    \([range(19)|" input == 1\("0"*.//"")L"]|join("
>   ||"));
> }"'
public static boolean isPowerOfTen(long input) {
  return
    input == 1L
  || input == 10L
  || input == 100L
  || input == 1000L
  || input == 10000L
  || input == 100000L
  || input == 1000000L
  || input == 10000000L
  || input == 100000000L
  || input == 1000000000L
  || input == 10000000000L
  || input == 100000000000L
  || input == 1000000000000L
  || input == 10000000000000L
  || input == 100000000000000L
  || input == 1000000000000000L
  || input == 10000000000000000L
  || input == 100000000000000000L
  || input == 1000000000000000000L;
}

オンラインテスト-rURLの受け渡しはサポートされていません-自分でRaw出力を確認してください。)


1

Javascript 175バイト

これを定期的にやろう

var s = "public static boolean isPowerOfTen(long input) {\n\treturn\n\t\tinput == 1";
for (var i = 1; i < 20; i++) {
    s += "\n\t|| input == 1";
    for (var j = 0; j < i; j++) {
        s += "0";
    }
    s += "L" ;
}
s += ";\n}";
alert(s);

かなり小さい。さて、セミコロンが不要であるか、varがないなどのJavaScriptマジック:

k="input == 1"
s="public static boolean isPowerOfTen(long input) {\n\treturn\n\t\t"+k+"L"
for(i=1;i<20;i++){s+="\n\t|| "+k
for(j=0;j<i;j++)s+="0";s+="L"}s+=";\n}"
alert(s)

その魔法の仕組みを説明できますか?:)
Marv

3
少なくともキーワード(for、while、varなど)が他のものに「触れない」まで、Javascriptはセミコロンを気にしません。また、varキーワードを使用しない場合、グローバル変数を取得します。これは、これまでプログラミング言語で見た中で最悪の機能です。
バリント

@Bálint。なぜこれが最悪の機能になるのでしょうか?
削除

@WashingtonGuedesご存知のように、ほとんどの言語は、関数内で何かをタイプミスした場合に通知します。javascriptは、まったく新しい変数を作成したかのようにそれを受け取るため、それについては何も言いません。
バリント

また、同じものがtrueを返す=に適用されます。
バリント

1

Python(3.5)137136バイト

print("public static boolean isPowerOfTen(long input) {\n  return\n   ",'\n  || '.join("input == %rL"%10**i for i in range(19))+";\n}")

前のバージョン

print("public static boolean isPowerOfTen(long input) {\n  return\n   ",'\n  || '.join("input == 1"+"0"*i+"L"for i in range(19))+";\n}")

Python 2.7で135:print "public static boolean isPowerOfTen(long input) {\n return\n %s;\n}"%"\n || ".join("input == %r"%10L**i for i in range(19))
moooeeeep

あなた@moooeeeepしている権利、%の使用R勝利1バイトとPython 2 print(括弧なし)は別のものを勝ち取る
エルワン

0

ANSI-SQL、252文字

WITH t as(SELECT '   'x,1 c,1 l UNION SELECT'  ||',c*10,l+1 FROM t WHERE l<19)SELECT 'public static boolean isPowerOfTen(long input) {'UNION ALL SELECT'  return 'UNION ALL SELECT x||' input == '||c||'L'||SUBSTR(';',1,l/19)FROM t UNION ALL SELECT'}   ';

ゴルフをしていない:

WITH t as (SELECT '   ' x,1 c,1 l UNION
           SELECT '  ||',c*10,l+1 FROM t WHERE l<19)
SELECT 'public static boolean isPowerOfTen(long input) {' UNION ALL
SELECT '  return ' UNION ALL
SELECT x||' input == '||c||'L'||SUBSTR(';',1,l/19) FROM t UNION ALL
SELECT '}   ';

深刻な試みではなく、単にOracle SQL / T-SQLエントリを突っ込むだけです。


For 40 additional chars I can add "from dual " and make it an "Oracle SQL" entry.
user1361991

0

JavaScript (Node.js), 156 bytes

s="public static boolean isPowerOfTen(long input) {\n  return "
for(i=1;i<1e19;i*=10)s+="\n  "+(i-1?"||":" ")+" input == "+i+"L"
console.log(s+";\n}   \n")

The i-1 will only be 0 (and thus falsey) on the very first round (it's just slightly shorter than i!=1.

Suggestions welcome!


0

Perl 5, 137 bytes

Not based on the previous Perl answer, but it is somehow shorter. I believe it can be shortened down again by taking care of the first "input" inside the loop, but I didn't try anything yet (at work atm)

$i="input";for(1..18){$b.="  || $i == 1"."0"x$_."L;\n"}print"public static boolean isPowerOfTen(long $i) {\n  return\n    $i == 1L;\n$b}"

0

CJam, 112 chars

"public static boolean isPowerOfTen(long input) {
  return
    input == 1"19,"0"a19*.*"L
  || input == 1"*"L;
}"

0

AWK+shell, 157 bytes

echo 18|awk '{s="input == 1";printf"public static boolean isPowerOfTen(long input) {\n return\n    "s"L";for(;I<$1;I++)printf"\n  ||%sL",s=s"0";print";\n}"}'

The question did say to count everything you would have to type. This does have the added bonus of being able to select how many lines would be placed in the isPowersOfTen method when the boss inevitably changes his mind.


Passing a here-string is shorter than piping from echo: awk '…'<<<18
manatwork

I knew about here-file but not here-string. Thanks for the info.
Robert Benson

0

T-SQL 289, 277, 250, 249 bytes

SELECT'public static boolean isPowerOfTen(long input){return '+STUFF((SELECT'||input=='+N+'L 'FROM(SELECT TOP 19 FORMAT(POWER(10.0,ROW_NUMBER()OVER(ORDER BY id)),'F0')N FROM syscolumns)A FOR XML PATH(''),TYPE).value('.','VARCHAR(MAX)'),1,2,'')+';}'

Update: Thanks @Bridge, I found a few more spaces too :)

Update2: Changed CTE to subquery -27 chars :) Update3: Another space bites the dust @bridge :)


1
I was able to trim off 7 more spaces (282 bytes) without changing the rest of the code: WITH A AS(SELECT CAST('1'AS VARCHAR(20))N UNION ALL SELECT CAST(CONCAT(N,'0')AS VARCHAR(20))FROM A WHERE LEN(N)<20)SELECT'public static boolean isPowerOfTen(long input){return '+STUFF((SELECT'|| input=='+N+'L 'FROM A FOR XML PATH(''),TYPE).value('.', 'VARCHAR(MAX)'), 1, 3, '')+';}'
Bridge

1
Now I look back I can see all the extra spaces in my original comment! I've found one more space you can get rid of - the one immediately after ROW_NUMBER()
Bridge

0

R, 185 bytes

Golfed

options(scipen=999);p=paste;cat(p("public static boolean isPowerOfTen(long input) {"," return",p(sapply(0:19,function(x)p(" input == ",10^x,"L",sep="")),collapse="\n ||"),"}",sep="\n"))

Ungolfed

options(scipen=999)
p=paste
cat(
  p("public static boolean isPowerOfTen(long input) {",
        " return",
        p(sapply(0:19,function(x)p(" input == ",10^x,"L",sep="")),collapse="\n ||"),
        "}",
        sep="\n")
)

0

Perl 6 (115 bytes)

say "public static boolean isPowerOfTen(long input) \{
  return
   {join "L
  ||",(" input == "X~(10 X**^19))}L;
}"

X operator does list cartesian product operation, for example 10 X** ^19 gives powers of ten (from 10 to the power of 0 to 19, as ^ is a range operator that counts from 0). Strings can have code blocks with { (which is why I escape the first instance of it).


0

Java, 210 / 166

Score is depending on whether returning the input from a function meets the definition of 'output'.

Console output (210):

class A{public static void main(String[]z){String a=" input == 1",t="L\n  ||"+a,s="public static boolean isPowerOfTen(long input) {\n  return\n   "+a;for(int i=0;++i<19;)s+=t+="0";System.out.print(s+"L;\n}");}}

String return (166):

String a(){String a=" input == 1",t="L\n  ||"+a,s="public static boolean isPowerOfTen(long input) {\n  return\n   "+a;for(int i=0;++i<19;)s+=t+="0";return s+"L;\n}";}

Legible version:

String a() {
    String a=" input == 1", t = "L\n  ||"+a,
        s = "public static boolean isPowerOfTen(long input) {\n  return\n   "+a;
    for (int i = 0; ++i < 19;)
        s += t += "0";
    return s + "L;\n}";
}

0

Batch, 230 208 206 205 bytes

@echo off
echo public static boolean isPowerOfTen(long input) {
echo   return
set m=input == 1
echo    %m%L
for /l %%a in (1,1,17)do call:a
call:a ;
echo }
exit/b
:a
set m=%m%0
echo  ^|^| %m%L%1

Edit: Saved 22 bytes by avoiding repeating input == and reusing the subroutine for the line with the extra semicolon. Saved 2 3 bytes by removing unnecessary spaces.


Do you need spaces around ==?
Pavel

@Pavel That's not code; it's part of the output.
Dennis
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.