Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added a commented version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

Commented

a => a.map(c => // for each character c in the input array a[]:
 ~a ? // if a is not -1:
 1 / c ? // if c is a digit:
 m[y][x] = // update m[y][x]:
 " ░▒▓█"[c] // with either a 'grayscale' character
 || a // or a (if c = 5)
 : // else:
 c < {} ? // if c is not a letter:
 a = // update a:
 c > "!" ? // if c = "?":
 -1 // use -1
 : // else (c = "!"):
 m[y][x] // use the character at the current position
 : // else (c is a letter):
 c > "s" ? // if c = "w":
 y -= !!y // decrement y if it's not 0
 : // else:
 c > "d" ? // if c = "s":
 y += y < 24 // increment y if it's less than 24
 : // else:
 x += // update x:
 c > "a" ? // if c = "d":
 x < 79 // increment x if it's less than 79
 : // else (c = "a"):
 -!!x // decrement x if it's not 0
 : // else (a = -1):
 a = c, // copy c in a
 m = [...1e9 + {}] // start with a matrix m[] made of 25 rows ...
 .map(_ => //
 [..."".padEnd(80)] // ... of 80 columns, filled with spaces
 ), //
 x = y = 0 // start with x = 0 and y = 0
) && m // end of map() -> return m[]

Commented

a => a.map(c => // for each character c in the input array a[]:
 ~a ? // if a is not -1:
 1 / c ? // if c is a digit:
 m[y][x] = // update m[y][x]:
 " ░▒▓█"[c] // with either a 'grayscale' character
 || a // or a (if c = 5)
 : // else:
 c < {} ? // if c is not a letter:
 a = // update a:
 c > "!" ? // if c = "?":
 -1 // use -1
 : // else (c = "!"):
 m[y][x] // use the character at the current position
 : // else (c is a letter):
 c > "s" ? // if c = "w":
 y -= !!y // decrement y if it's not 0
 : // else:
 c > "d" ? // if c = "s":
 y += y < 24 // increment y if it's less than 24
 : // else:
 x += // update x:
 c > "a" ? // if c = "d":
 x < 79 // increment x if it's less than 79
 : // else (c = "a"):
 -!!x // decrement x if it's not 0
 : // else (a = -1):
 a = c, // copy c in a
 m = [...1e9 + {}] // start with a matrix m[] made of 25 rows ...
 .map(_ => //
 [..."".padEnd(80)] // ... of 80 columns, filled with spaces
 ), //
 x = y = 0 // start with x = 0 and y = 0
) && m // end of map() -> return m[]
minor update
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES8), 173 bytes

Expects an array of characters and returns a matrix of characters.

a=>a.map(c=>~a?1/c?m[y][x]=" ░▒▓█"[c]||a:c<{}?a=c>"!"?-1:m[y][x]:c>"s"?y-=!!y:c>"d"?y+=y<24:x+=c>"a"?x<79:-!!x:a=c,m=[...1e9+{}].map(_=>[..."".padEnd(80)]),x=y=0)&&m

Try it online! Try it online!

JavaScript (ES8), 173 bytes

Expects an array of characters and returns a matrix of characters.

a=>a.map(c=>~a?1/c?m[y][x]=" ░▒▓█"[c]||a:c<{}?a=c>"!"?-1:m[y][x]:c>"s"?y-=!!y:c>"d"?y+=y<24:x+=c>"a"?x<79:-!!x:a=c,m=[...1e9+{}].map(_=>[..."".padEnd(80)]),x=y=0)&&m

Try it online!

JavaScript (ES8), 173 bytes

Expects an array of characters and returns a matrix of characters.

a=>a.map(c=>~a?1/c?m[y][x]=" ░▒▓█"[c]||a:c<{}?a=c>"!"?-1:m[y][x]:c>"s"?y-=!!y:c>"d"?y+=y<24:x+=c>"a"?x<79:-!!x:a=c,m=[...1e9+{}].map(_=>[..."".padEnd(80)]),x=y=0)&&m

Try it online!

saved 2 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES8), 175173 bytes

Expects an array of characters and returns a matrix of characters.

a=>a.map(c=>~a?1/c?m[y][x]=" ░▒▓█"[c]||a:c<{}?a=c>"!"?-1:m[y][x]:c>"s"?y-=!!y:c>"d"?y+=y<24:c>"a"x+=c>"a"?x+=x<79x<79:c>{}?x-=!!x:a=c>"!"?-1:m[y][x]:a=c,m=[...1e9+{}].map(_=>[..."".padEnd(80)]),x=y=0)&&m

Try it online! Try it online!

JavaScript (ES8), 175 bytes

Expects an array of characters and returns a matrix of characters.

a=>a.map(c=>~a?1/c?m[y][x]=" ░▒▓█"[c]||a:c>"s"?y-=!!y:c>"d"?y+=y<24:c>"a"?x+=x<79:c>{}?x-=!!x:a=c>"!"?-1:m[y][x]:a=c,m=[...1e9+{}].map(_=>[..."".padEnd(80)]),x=y=0)&&m

Try it online!

JavaScript (ES8), 173 bytes

Expects an array of characters and returns a matrix of characters.

a=>a.map(c=>~a?1/c?m[y][x]=" ░▒▓█"[c]||a:c<{}?a=c>"!"?-1:m[y][x]:c>"s"?y-=!!y:c>"d"?y+=y<24:x+=c>"a"?x<79:-!!x:a=c,m=[...1e9+{}].map(_=>[..."".padEnd(80)]),x=y=0)&&m

Try it online!

saved 3 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
saved 2 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading

AltStyle によって変換されたページ (->オリジナル) /