)
}
}
)
(
}
{
)
)
(
)
(
(
{
}
)
(
)
}
)
)
{
(
(
)
)
}
)
(
}

Golfed Codepen – 3D Spiral Thing

  1. // sort of golfed version of https://www.instagram.com/p/C1uv6Kqv19T/
  2. // by @mewtru
  3. b = document.body
  4. a = Object.assign
  5. a(b.style, { background:'#000', color:'#fff'})
  6. w = 'snippet.zone snippet.zone'.toUpperCase().split``
  7. F = (n, O = 0, C, S, o, t) => { 
  8.   b.innerHTML += `<div id=${n} style='position:absolute;left:50%;top:50%;translate:-50% -50%;width:100% text-align:center;white-space:nowrap'></div>`
  9.   w.map(l => this[n].innerHTML += `<span style='display:inline-block;margin-right:5px;font-size:28px'>${l}</span>`)
  10.   t = O
  11.   setInterval(_ => {
  12.     t += .005
  13.     ;[...this[n].children].map((e, i) => { 
  14.       T = t + i / 2.7
  15.       a(e.style, {
  16.         translate: `0 ${Math.sin(T) * 100}px`,
  17.         scale: Math.cos(T) * .5 + .5})
  18.     }, 16)
  19.   })
  20. }
  21. F('Z') 
  22. F('X', 3)

“Very cool” pen by Lucas Fernando that comes from @mewtru
I decided to do a speed-coded semi-golfed version… can definitely be way more golfed 😀

Other Gates from NAND

  1. const nand = ([a, b]) => +!(a & b)
  2.  
  3. const not = ([a]) => nand([a, a])
  4.  
  5. const and = ([a, b]) => nand([nand([a, b]), nand([a, b])])
  6.  
  7. const or = ([a, b]) => nand([nand([a, a]), nand([b, b])])
  8.  
  9. const nor = ([a, b]) => 
  10.   nand([ 
  11.     nand([nand([a, a]), nand([b, b])]), 
  12.     nand([nand([a, a]), nand([b, b])])
  13.   ])
  14.  
  15. const xor = ([a, b]) =>
  16.   nand([
  17.     nand([a, nand([a, b])]),
  18.     nand([b, nand([a, b])])
  19.   ])
  20.  
  21. const xnor = ([a, b]) => 
  22.   nand([ 
  23.     nand([nand([a, a]), nand([b, b])]),
  24.     nand([a, b])
  25.   ])
  26.  
  27.  
  28. const inputs = [
  29.   [0, 0],
  30.   [0, 1],
  31.   [1, 0],
  32.   [1, 1]
  33. ]
  34.  
  35. const testGate = ({ gate, truth, result }) => console.log(
  36.   gate + ' matches truth? ', 
  37.   truth+'' === result+'' ? 
  38.     'yes :D' : `nope :( ${truth} ${result}`
  39. )
  40.  
  41. testGate({
  42.   gate: 'NAND',
  43.   truth: [1, 1, 1, 0],
  44.   result: inputs.map(nand)
  45. })
  46.  
  47. testGate({
  48.   gate: 'NOT',
  49.   truth: [0, 1],
  50.   result: [[1], [0]].map(not)
  51. })
  52.  
  53. testGate({
  54.   gate: 'AND',
  55.   truth: [0, 0, 0, 1],
  56.   result: inputs.map(and)
  57. })
  58.  
  59. testGate({
  60.   gate: 'OR',
  61.   truth: [0, 1, 1, 1],
  62.   result: inputs.map(or)
  63. })
  64.  
  65. testGate({
  66.   gate: 'NOR',
  67.   truth: [1, 0, 0, 0],
  68.   result: inputs.map(nor)
  69. })
  70.  
  71. testGate({
  72.   gate: 'XOR',
  73.   truth: [0, 1, 1, 0],
  74.   result: inputs.map(xor)
  75. })
  76.  
  77. testGate({
  78.   gate: 'XNOR',
  79.   truth: [1, 0, 0, 1],
  80.   result: inputs.map(xnor)
  81. })

Use NAND to create a bunch of other gates 😀 – I used this wikipedia article for reference

Multiplicative Persistence

  1. const multp = (val, count = 1, res) => 
  2.   (res = (val + '').split``
  3.     .reduce((a, b) => a * b, 1) + '').length > 1 ?
  4.       multp(res, count + 1) : count
  5.  
  6.  
  7. console.log('test:', multp(2678789))

Started watching this youtube video from numberphile and instantly made this half-golfed thing

Found this:

f=n=>[n,...n>9?f(eval([...n+''].join`*`)):[]]

By Arnauld over at codegolf.stackexchange

will definitely remember: [...n+'']

// golfed // hacks // humor // javascript // math

Building Spikes Codegolf

  1. f = 
  2.  
  3. n=>`   ^ 
  4.   /|\\
  5.  /.|.\\
  6. /..|..\\
  7. ___`.replace(/.[_|^]./g,'$&'.repeat(n))+'____'
  8.  
  9. // test it out
  10. document.body.innerHTML += 
  11. `<pre>${f(1)}
  12. ${f(3)}
  13. ${f(4)}`

Great codegolf stackexchange answer from user tsh

Odd Gradient Notation

  1. // "Being clever is not clever"
  2. // -- Bjarne Stroustrup
  3. D = document
  4. ang = {
  5.   '|': 180,
  6.   '-': 90,
  7.   '\\': 135,
  8.   '/': 225
  9. }
  10.  
  11. box = def => {
  12.   def = def.split(/\s+/)
  13.   form = def.length
  14.   I = i => parseInt(def[i], 16)
  15.  
  16.   ;[,,, _=>{x = y = I(0); w = h = I(1); c = def[2]},
  17.     _=>{x = I(0), y = I(1); w = h = I(2);c = def[3]},
  18.     _=>{x = I(0); y = I(1); w = I(2); h = I(3); c = def[4]}
  19.   ][form]()
  20.  
  21.   c = c.split``
  22.  
  23.   ca = c[0]
  24.   ca = ca+ca+ca
  25.   cD = ang[c[1]]
  26.   cb = c[2]
  27.   cb = cb+cb+cb 
  28.  
  29.   D.body.appendChild(
  30.     D.createElement`div`
  31.   ).style = `
  32.     position: absolute; left: ${x}px; top: ${y}px;
  33.     width: ${w}px; height: ${h}px;
  34.     background: linear-gradient(${cD}deg, #${ca}, #${cb})
  35.   `
  36. }
  37.  
  38. const parse = prog => prog.trim()
  39.   .split(/\n+/m)
  40.   .map(line => box(line.trim()))
  41.  
  42. parse(`
  43.   0 64 0/f
  44.   64 64 0\\f
  45.   a0 f0 30 54 f\\0
  46.   0 6f 20 60 0-c
  47.   f 7f 20 60 0|c
  48.   1f 8f 30 30 c/0
  49. `)

Just playing around… odd micro-gradient notation:

  1. '0 64 0/f'
  2. // x=0 y=0 width=0x64 height=0x64
  3. // 0/f = gradient black to white top right to bottom left
  4.  
  5. '64 64 0\\f'
  6. // x=0 y=0 width=0x64 height=0x64
  7. // 0\\f = black to to white gradient top left to bottom right
  8.  
  9. '0 6f 20 60 0-c'
  10. // x=0 y=0x6f width=0x20 height=0x60
  11. // 0-c = gradient black to grey (#ccc) left to right
  12.  
  13. // etc... ( | ) is top to bottom grad
// css // dom // golfed // graphics // hacks // humor // regex // speed-coded
snippet.zone ~ 2021-24 /// {s/z}