一部でコードゴルフが流行っていたので、便乗してみた。
ずいぶん昔に、某巨大掲示板にて、ゴルフゲームをコードゴルフする遊びが流行っていたので、そこからアイデアを得ました。
まずこれ。
できるだけゴルフっぽくしたやつ
(217文字)
次に、いろいろと制限を加えてコードをスリムにしたやつ
(141文字)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//クリックで操作 | |
//タイトルバーに表示 | |
//初期化にワンクリック必要 | |
//結果はゴールまでのマス数 | |
c=n=0,onclick=function r(){n-->0?(g=[],g[6]="_",g[++c]="*",document.title=g.join("-"),setTimeout(r,300)):(n=Math.random()*6,c>5&&alert(c-6))} |
最後に、consoleで動かすようにして、140文字以下にしたもの
(134文字)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//consoleで動かすgolf | |
//r() でgolf実行 | |
c=n=0;function r(){if(n>0){g=[];g[++c]=".";g[6]="_";console.log(g.join("-"));r(n--)}else{c>=6&&console.log(c-6);n=Math.random()*6}}r() |
もっと短くならないかなぁ。