也许你们中的一些人已经知道这个游戏了:你们有一组不同颜色的果冻豆。对于每一种颜色,豆可能有不同的口味,一些是好的,有些是坏的,你无法区分它们。你必须选择一个特定颜色的豆子,并祈祷你已经选择了一个好的。
因此,编写一个最短的程序,接收您选择的颜色(从给定的列表),并随机返回选择的味道。味道必须从内置的清单中挑选出来。可能的投入和产出清单如下:
Input Output choices [only one from the list]
--------------------------------------------------
green lawn clippings, lime, mucus, pear
yellow rotten eggs, buttered popcorn
blue toothpaste, blue berry
orange vomit, peach
brown canned dog food, chocolate
white stinky socks, tutti-frutti, baby diapers, coconut规则:
这是密码-高尔夫,愿最短的节目获胜!
发布于 2017-06-09 12:01:23
我需要弄清楚如何压缩JS中的字符串!
c=>(a="lawn clippings,lime,mucus,pear|rotten eggs,buttered popcorn|toothpaste,blue berry|vomit,peach|canned dog food,chocolate|stinky socks,tutti-frutti,baby diapers,coconut".split`|`["eluaoi".search(c[2])].split`,`)[new Date%a.length]如果这对你的口味来说还不够“随机”,那么添加7个字节,用new Date代替Math.random()。
c=>(a="lawn clippings,lime,mucus,pear|rotten eggs,buttered popcorn|toothpaste,blue berry|vomit,peach|canned dog food,chocolate|stinky socks,tutti-frutti,baby diapers,coconut".split`|`["eluaoi".search(c[2])].split`,`)[Math.random()*a.length|0]f=
c=>(a="lawn clippings,lime,mucus,pear|rotten eggs,buttered popcorn|toothpaste,blue berry|vomit,peach|canned dog food,chocolate|stinky socks,tutti-frutti,baby diapers,coconut".split`|`["eluaoi".search(c[2])].split`,`)[Math.random()*a.length|0]
r=(d=document).createElement("input");r.name="i";r.type="radio";l=d.createElement("label");j="Kiwi,sour_lemon,berryBlue,OrangeSherbet,rootBeer,Coconut".split`,`;for(s in e="green,yellow,blue,orange,brown,white".split`,`){r=r.cloneNode();l=l.cloneNode();l.setAttribute("for",r.id=r.value=e[s]);l.style.backgroundImage=`url(https://cdn-tp1.mozu.com/9046-11441/cms//files/${j[s]}.jpg)`;g.prepend(r,l);}onchange=_=>o.innerText=(v=(i=d.querySelector(":checked")).value)+": "+f(v,i.checked=0)body{align-items:center;background:#eee;display:flex;flex-wrap:wrap;height:100vh;justify-content:center;margin:0;text-align:center;}#g{background:#fff;box-shadow:5px 5px 5px #ccc;padding:10px;}input{display:none;}label{background-repeat:no-repeat;background-size:contain;cursor:pointer;display:inline-block;height:64px;margin:10px;width:75px;}#o{font-family:monospace;font-size:18px;margin:10px auto;text-align:center;width:100%;}<div id=g><pre id=o>click a jelly bean</pre></div>发布于 2017-06-09 12:20:19
¨¤.•4Õ!Õ•.•QCQΓ^ïTÁÕ#HвΘÊÓΘñ…~çÌùY$J*shÉÉk‹Ú&žвZÍζö<^'¢βŽÚq¡eζd`Ãó¨₅γ!i"v_Ym¤ÓδVË5¥vżQЉøΣγ9∞\L‰,ǝ¦8VÜUт:x+sм•'x'-:'q¡'j¡€.R‡解释:
¨¤ Get the second to last character of the string
.•4Õ!Õ• Compressed string: "eougwt"
.• .. • Compressed base-27 string
'x'-: Replace "x" with "-" (for tutti-frutti)
'q¡ Split on 'q'
'j¡ Split each on 'j'
€ For each...
.R Select a random element
‡ Transliterate如果有人想知道,下面是未压缩的字符串:
lawn clippingsjlimejmucusjpearqrotten eggsjbuttered popcornqtoothpastejblue berryqvomitjpeachqcanned dog foodjchocolateqstinky socksjtuttixfruttijbaby diapersjcoconut不过,我可能可以用一些巧妙的技巧和字典来压缩它。
发布于 2017-06-09 12:39:03
s->{String[]a="lawn clippings,lime,mucus,pear#rotten eggs,buttered popcorn#toothpaste,blue berry#vomit,peach#canned dog food,chocolate#stinky socks,tutti-frutti,baby diapers,coconut".split("#")["eluaoi".indexOf(s.charAt(2))].split(",");return a[new java.util.Random().nextInt(a.length)];}可以用char[]来打高尔夫球。
然而,如果没有Random.nextInt(int)的显式使用,随机部分就不可能“均匀分布”。甚至(int)(Math.random()*a.length)也不是均匀分布的。
https://codegolf.stackexchange.com/questions/125582
复制相似问题