Skip to main content
added 176 characters in body; deleted 30 characters in body
Source Link
mellamokb
  • 6.1k
  • 3
  • 27
  • 34

JavaScript (169 168 141141 137)

r=1+Mathr=Math.random()*6|0;s='-----\n|'+(r>1r>0?'o ':'  ')+(r>3r>2?'o':' ')+'|\n|'+(r-65?' ':'o');alert(s+(r%2-1?' ':'o')+s.split('').reverse().join(''))

Doesn't look quite right in alert because it's not fixed-width font, but rest assured it is correct, or test by emitting a <pre> tag and doing writeln :-)

Proof: http://jsfiddle.net/d4YTn/2/ (only works in JS 1.7-compliant browsers, such as FF2+)

jsfiddle appears to be down currently, so I can't update itProof: http://jsfiddle.net/d4YTn/3/ (only works in JS 1.7-compliant browsers, such as FF2+)

Credits: Hacked Math trick from @minitech and die print logic from @Keith.

Edit: Remove Math trick from @minitech because it actually made it longer :-)

Edit 2: Save 17 chars. Borrow trick from @Keith for taking advantage of dice symmetry. Use trick for simplifying converting random numbenumber to int.

Edit 3: Remove 1+ to shift random number from 1-6 to 0-5 and save 2 chars. As a result, I can also change r%2-1 to r%2 and save another 2 chars.

Edit 4: jsfiddle is working again. Updated :-)

JavaScript (169 168 141)

r=1+Math.random()*6|0;s='-----\n|'+(r>1?'o ':'  ')+(r>3?'o':' ')+'|\n|'+(r-6?' ':'o');alert(s+(r%2-1?' ':'o')+s.split('').reverse().join(''))

Doesn't look quite right in alert because it's not fixed-width font, but rest assured it is correct, or test by emitting a <pre> tag and doing writeln :-)

Proof: http://jsfiddle.net/d4YTn/2/ (only works in JS 1.7-compliant browsers, such as FF2+)

jsfiddle appears to be down currently, so I can't update it.

Credits: Hacked Math trick from @minitech and die print logic from @Keith.

Edit: Remove Math trick from @minitech because it actually made it longer :-)

Edit 2: Save 17 chars. Borrow trick from @Keith for taking advantage of dice symmetry. Use trick for simplifying converting random numbe to int.

JavaScript (169 168 141 137)

r=Math.random()*6|0;s='-----\n|'+(r>0?'o ':'  ')+(r>2?'o':' ')+'|\n|'+(r-5?' ':'o');alert(s+(r%2?' ':'o')+s.split('').reverse().join(''))

Doesn't look quite right in alert because it's not fixed-width font, but rest assured it is correct, or test by emitting a <pre> tag and doing writeln :-)

Proof: http://jsfiddle.net/d4YTn/3/ (only works in JS 1.7-compliant browsers, such as FF2+)

Credits: Hacked Math trick from @minitech and die print logic from @Keith.

Edit: Remove Math trick from @minitech because it actually made it longer :-)

Edit 2: Save 17 chars. Borrow trick from @Keith for taking advantage of dice symmetry. Use trick for simplifying converting random number to int.

Edit 3: Remove 1+ to shift random number from 1-6 to 0-5 and save 2 chars. As a result, I can also change r%2-1 to r%2 and save another 2 chars.

Edit 4: jsfiddle is working again. Updated :-)

added 232 characters in body
Source Link
mellamokb
  • 6.1k
  • 3
  • 27
  • 34

JavaScript (169 168168 141)

r=Math.floor(Mathr=1+Math.random()*6+1);alert('*6|0;s='-----\n|'+[[e\n|'+(r>1?'o''o ':' ' for')+(r>3?'o':' each')+'|\n|'+(er-6?' in':'o');alert(s+(r%2-1?' t':'o')]+s.joinsplit('') for each.reverse(t in [[r>1,0,r>3],[r>5,r&1,r>5],[r>3,0,r>1]])].join('|\n|''')+'|\n-----')

Doesn't look quite right in alert because it's not fixed-width font, but rest assured it is correct, or test by emitting a <pre> tag and doing writeln :-)

Proof: http://jsfiddle.net/d4YTn/2/ (only works in JS 1.7-compliant browsers, such as FF2+)

Proof: http://jsfiddle.net/d4YTn/2/ (only works in JS 1.7-compliant browsersjsfiddle appears to be down currently, such as FF2+)so I can't update it.

Credits: Hacked Math trick from @minitech and die print logic from @Keith.

Edit: Remove Math trick from @minitech because it actually made it longer :-)

Edit 2: Save 17 chars. Borrow trick from @Keith for taking advantage of dice symmetry. Use trick for simplifying converting random numbe to int.

JavaScript (169 168)

r=Math.floor(Math.random()*6+1);alert('-----\n|'+[[e?'o':' ' for each(e in t)].join('') for each(t in [[r>1,0,r>3],[r>5,r&1,r>5],[r>3,0,r>1]])].join('|\n|')+'|\n-----')

Doesn't look quite right in alert because it's not fixed-width font, but rest assured it is correct, or test by emitting a <pre> tag and doing writeln :-)

Proof: http://jsfiddle.net/d4YTn/2/ (only works in JS 1.7-compliant browsers, such as FF2+)

Credits: Hacked Math trick from @minitech and die print logic from @Keith.

Edit: Remove Math trick from @minitech because it actually made it longer :-)

JavaScript (169 168 141)

r=1+Math.random()*6|0;s='-----\n|'+(r>1?'o ':'  ')+(r>3?'o':' ')+'|\n|'+(r-6?' ':'o');alert(s+(r%2-1?' ':'o')+s.split('').reverse().join(''))

Doesn't look quite right in alert because it's not fixed-width font, but rest assured it is correct, or test by emitting a <pre> tag and doing writeln :-)

Proof: http://jsfiddle.net/d4YTn/2/ (only works in JS 1.7-compliant browsers, such as FF2+)

jsfiddle appears to be down currently, so I can't update it.

Credits: Hacked Math trick from @minitech and die print logic from @Keith.

Edit: Remove Math trick from @minitech because it actually made it longer :-)

Edit 2: Save 17 chars. Borrow trick from @Keith for taking advantage of dice symmetry. Use trick for simplifying converting random numbe to int.

added 109 characters in body
Source Link
mellamokb
  • 6.1k
  • 3
  • 27
  • 34

JavaScript (169169 168)

r=(M=Math)r=Math.floor(MMath.random()*6+1);alert('-----\n|'+[[e?'o':' ' for each(e in t)].join('') for each(t in [[r>1,0,r>3],[r>5,r&1,r>5],[r>3,0,r>1]])].join('|\n|')+'|\n-----')

Doesn't look quite right in alert because it's not fixed-width font, but rest assured it is correct, or test by emitting a <pre> tag and doing writeln :-)

Proof: http://jsfiddle.net/d4YTn/2/ (only works in JS 1.7-compliant browsers, such as FF2+)

Credits: Hacked Math trick from @minitech and die print logic from @Keith.

Edit: Remove Math trick from @minitech because it actually made it longer :-)

JavaScript (169)

r=(M=Math).floor(M.random()*6+1);alert('-----\n|'+[[e?'o':' ' for each(e in t)].join('') for each(t in [[r>1,0,r>3],[r>5,r&1,r>5],[r>3,0,r>1]])].join('|\n|')+'|\n-----')

Doesn't look quite right in alert because it's not fixed-width font, but rest assured it is correct, or test by emitting a <pre> tag and doing writeln :-)

Proof: http://jsfiddle.net/d4YTn/2/ (only works in JS 1.7-compliant browsers, such as FF2+)

Credits: Hacked Math trick from @minitech and die print logic from @Keith.

JavaScript (169 168)

r=Math.floor(Math.random()*6+1);alert('-----\n|'+[[e?'o':' ' for each(e in t)].join('') for each(t in [[r>1,0,r>3],[r>5,r&1,r>5],[r>3,0,r>1]])].join('|\n|')+'|\n-----')

Doesn't look quite right in alert because it's not fixed-width font, but rest assured it is correct, or test by emitting a <pre> tag and doing writeln :-)

Proof: http://jsfiddle.net/d4YTn/2/ (only works in JS 1.7-compliant browsers, such as FF2+)

Credits: Hacked Math trick from @minitech and die print logic from @Keith.

Edit: Remove Math trick from @minitech because it actually made it longer :-)

Source Link
mellamokb
  • 6.1k
  • 3
  • 27
  • 34
Loading