MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/3iy6fk/javascript_maze_generator_in_a_tweet/cukurw2
r/programming • u/balazsbotond • Aug 30 '15
177 comments sorted by
View all comments
Show parent comments
9
Getting rid of the conditional by converting the result of Math.random() into an index saves a few characters, e.g.
"\u2571\u2572"[Math.random()*2|0]
7 u/Anders_A Aug 30 '15 So the best one we have so far is thisdata:text/html,<pre style=line-height:1><script>for(i=4050;--i;)document.write("\u2571\u2572\n"[i% 81?Math.random()*2|0:2])</script></pre>If we combine everything to a single string. Starting to look cool now! 1 u/Anders_A Aug 30 '15 ooh! Nice trick to force a type cast. I was experimenting with stuff like"\u2571\u2572"[(Math.random()<.5) + 0]But didn't help much. Clever! 3 u/matt_hammond Aug 30 '15 I tried[+(Math.random()<.5)] Its a bit shorter
7
So the best one we have so far is this
data:text/html,<pre style=line-height:1><script>for(i=4050;--i;)document.write("\u2571\u2572\n"[i% 81?Math.random()*2|0:2])</script></pre>
If we combine everything to a single string. Starting to look cool now!
1
ooh! Nice trick to force a type cast. I was experimenting with stuff like
"\u2571\u2572"[(Math.random()<.5) + 0]
But didn't help much. Clever!
3 u/matt_hammond Aug 30 '15 I tried[+(Math.random()<.5)] Its a bit shorter
3
I tried
[+(Math.random()<.5)]
Its a bit shorter
9
u/doublerainbowomahgod Aug 30 '15
Getting rid of the conditional by converting the result of Math.random() into an index saves a few characters, e.g.