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

replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

JavaScript (ES6), (削除) 237 (削除ここまで) (削除) 210 (削除ここまで) (削除) 204 (削除ここまで) (削除) 188 (削除ここまで) (削除) 182 (削除ここまで) 178 bytes

Credit to @Downgoat @Downgoat for saving 16 bytes in the 188-byte revision

Update: I had a brainwave and reduced the first operation on s to a single map call instead of two separate ones

s=>(r=" .':",a=[],s=[...s].map(c=>(t=('00'+r.indexOf(c).toString(2)).slice(-2),a.push(t[0]),t[1])),a.splice(0,0,s.shift()),s.push(a.pop()),a.map((v,i)=>r[+('0b'+v+s[i])]).join``)

###Pretty Print & Explanation

s => (
 r = " .':", // Map of characters to their (numerical) binary representations (e.g. r[0b10] = "'")
 a = [], // extra array needed
 // Spread `s` into an array
 s = [...s].map(c => (
 // Map each character to a `0`-padded string representation of a binary number, storing in `t`
 t = ('00' + r.indexOf(c).toString(2)).slice(-2)),
 // Put the first character of `t` into `a`
 a.push(t[0]),
 // Keep the second character for `s`
 t[1]
 )),
 // Put the first character of `s` in the first index of `a`
 a.splice(0,0,s.shift()),
 // Append the last character of `a` to `s`
 s.push(a.pop(),
 // Rejoin the characters, alternating from `a` to `s`, representing the rotated matrix, and map them back to their string representation
 // Use implicit conversion of a binary number string using +'0b<num>'
 a.map((v,i) => r[+('0b' + v + s[i])]).join``
)

JavaScript (ES6), (削除) 237 (削除ここまで) (削除) 210 (削除ここまで) (削除) 204 (削除ここまで) (削除) 188 (削除ここまで) (削除) 182 (削除ここまで) 178 bytes

Credit to @Downgoat for saving 16 bytes in the 188-byte revision

Update: I had a brainwave and reduced the first operation on s to a single map call instead of two separate ones

s=>(r=" .':",a=[],s=[...s].map(c=>(t=('00'+r.indexOf(c).toString(2)).slice(-2),a.push(t[0]),t[1])),a.splice(0,0,s.shift()),s.push(a.pop()),a.map((v,i)=>r[+('0b'+v+s[i])]).join``)

###Pretty Print & Explanation

s => (
 r = " .':", // Map of characters to their (numerical) binary representations (e.g. r[0b10] = "'")
 a = [], // extra array needed
 // Spread `s` into an array
 s = [...s].map(c => (
 // Map each character to a `0`-padded string representation of a binary number, storing in `t`
 t = ('00' + r.indexOf(c).toString(2)).slice(-2)),
 // Put the first character of `t` into `a`
 a.push(t[0]),
 // Keep the second character for `s`
 t[1]
 )),
 // Put the first character of `s` in the first index of `a`
 a.splice(0,0,s.shift()),
 // Append the last character of `a` to `s`
 s.push(a.pop(),
 // Rejoin the characters, alternating from `a` to `s`, representing the rotated matrix, and map them back to their string representation
 // Use implicit conversion of a binary number string using +'0b<num>'
 a.map((v,i) => r[+('0b' + v + s[i])]).join``
)

JavaScript (ES6), (削除) 237 (削除ここまで) (削除) 210 (削除ここまで) (削除) 204 (削除ここまで) (削除) 188 (削除ここまで) (削除) 182 (削除ここまで) 178 bytes

Credit to @Downgoat for saving 16 bytes in the 188-byte revision

Update: I had a brainwave and reduced the first operation on s to a single map call instead of two separate ones

s=>(r=" .':",a=[],s=[...s].map(c=>(t=('00'+r.indexOf(c).toString(2)).slice(-2),a.push(t[0]),t[1])),a.splice(0,0,s.shift()),s.push(a.pop()),a.map((v,i)=>r[+('0b'+v+s[i])]).join``)

###Pretty Print & Explanation

s => (
 r = " .':", // Map of characters to their (numerical) binary representations (e.g. r[0b10] = "'")
 a = [], // extra array needed
 // Spread `s` into an array
 s = [...s].map(c => (
 // Map each character to a `0`-padded string representation of a binary number, storing in `t`
 t = ('00' + r.indexOf(c).toString(2)).slice(-2)),
 // Put the first character of `t` into `a`
 a.push(t[0]),
 // Keep the second character for `s`
 t[1]
 )),
 // Put the first character of `s` in the first index of `a`
 a.splice(0,0,s.shift()),
 // Append the last character of `a` to `s`
 s.push(a.pop(),
 // Rejoin the characters, alternating from `a` to `s`, representing the rotated matrix, and map them back to their string representation
 // Use implicit conversion of a binary number string using +'0b<num>'
 a.map((v,i) => r[+('0b' + v + s[i])]).join``
)
added 92 characters in body
Source Link

JavaScript (ES6), (削除) 237 (削除ここまで) (削除) 210 (削除ここまで) (削除) 204 (削除ここまで) (削除) 188 (削除ここまで) 182(削除) 182 (削除ここまで) 178 bytes

Credit to @Downgoat for saving 16 bytes in the 188-byte revision

Update: I had a brainwave and reduced the first operation on s to a single map call instead of two separate ones

s=>(r=" .':",a=[],s=[...s].map(c=>(t=('00'+r.indexOf(c).toString(2)).slice(-2),a.push(t[0]),t[1])),a.splice(0,0,s.shift()),s.push(a.pop()),a.map((v,i)=>r[parseInt=>r[+(v+s[i],2'0b'+v+s[i])]).join``)

###Pretty Print & Explanation

s => (
 r = " .':", // Map of characters to their (numerical) binary representations (e.g. r[0b10] = "'")
 a = [], // extra array needed
 // Spread `s` into an array
 s = [...s].map(c => (
 // Map each character to a `0`-padded string representation of a binary number, storing in `t`
 t = ('00' + r.indexOf(c).toString(2)).slice(-2)),
 // Put the first character of `t` into `a`
 a.push(t[0]),
 // Keep the second character for `s`
 t[1]
 )),
 // Put the first character of `s` in the first index of `a`
 a.splice(0,0,s.shift()),
 // Append the last character of `a` to `s`
 s.push(a.pop(),
 // Rejoin the characters, alternating from `a` to `s`, representing the rotated matrix, and map them back to their string representation
 // Use implicit conversion of a binary number string using +'0b<num>'
 a.map((v,i) => r[parseIntr[+('0b' + v + s[i],2)]).join``
)

JavaScript (ES6), (削除) 237 (削除ここまで) (削除) 210 (削除ここまで) (削除) 204 (削除ここまで) (削除) 188 (削除ここまで) 182 bytes

Credit to @Downgoat for saving 16 bytes in the 188-byte revision

Update: I had a brainwave and reduced the first operation on s to a single map call instead of two separate ones

s=>(r=" .':",a=[],s=[...s].map(c=>(t=('00'+r.indexOf(c).toString(2)).slice(-2),a.push(t[0]),t[1])),a.splice(0,0,s.shift()),s.push(a.pop()),a.map((v,i)=>r[parseInt(v+s[i],2)]).join``)

###Pretty Print & Explanation

s => (
 r = " .':", // Map of characters to their (numerical) binary representations (e.g. r[0b10] = "'")
 a = [], // extra array needed
 // Spread `s` into an array
 s = [...s].map(c => (
 // Map each character to a `0`-padded string representation of a binary number, storing in `t`
 t = ('00' + r.indexOf(c).toString(2)).slice(-2)),
 // Put the first character of `t` into `a`
 a.push(t[0]),
 // Keep the second character for `s`
 t[1]
 )),
 // Put the first character of `s` in the first index of `a`
 a.splice(0,0,s.shift()),
 // Append the last character of `a` to `s`
 s.push(a.pop(),
 // Rejoin the characters, alternating from `a` to `s`, representing the rotated matrix, and map them back to their string representation
 a.map((v,i) => r[parseInt(v + s[i],2)]).join``
)

JavaScript (ES6), (削除) 237 (削除ここまで) (削除) 210 (削除ここまで) (削除) 204 (削除ここまで) (削除) 188 (削除ここまで) (削除) 182 (削除ここまで) 178 bytes

Credit to @Downgoat for saving 16 bytes in the 188-byte revision

Update: I had a brainwave and reduced the first operation on s to a single map call instead of two separate ones

s=>(r=" .':",a=[],s=[...s].map(c=>(t=('00'+r.indexOf(c).toString(2)).slice(-2),a.push(t[0]),t[1])),a.splice(0,0,s.shift()),s.push(a.pop()),a.map((v,i)=>r[+('0b'+v+s[i])]).join``)

###Pretty Print & Explanation

s => (
 r = " .':", // Map of characters to their (numerical) binary representations (e.g. r[0b10] = "'")
 a = [], // extra array needed
 // Spread `s` into an array
 s = [...s].map(c => (
 // Map each character to a `0`-padded string representation of a binary number, storing in `t`
 t = ('00' + r.indexOf(c).toString(2)).slice(-2)),
 // Put the first character of `t` into `a`
 a.push(t[0]),
 // Keep the second character for `s`
 t[1]
 )),
 // Put the first character of `s` in the first index of `a`
 a.splice(0,0,s.shift()),
 // Append the last character of `a` to `s`
 s.push(a.pop(),
 // Rejoin the characters, alternating from `a` to `s`, representing the rotated matrix, and map them back to their string representation
 // Use implicit conversion of a binary number string using +'0b<num>'
 a.map((v,i) => r[+('0b' + v + s[i])]).join``
)
added 194 characters in body
Source Link

JavaScript (ES6), (削除) 237 (削除ここまで) (削除) 210 (削除ここまで) (削除) 204 (削除ここまで) 188(削除) 188 (削除ここまで) 182 bytes

Credit to @Downgoat for saving 16 bytes in the latest188-byte revision

Update: I had a brainwave and reduced the first operation on s to a single map call instead of two separate ones

s=>(r=" .':",a=[],s=[...s].map(c=>(t=('00'+r.indexOf(c).toString(2)).slice(-2)).map(n=>(,a.push(n[0]t[0]),n[1]t[1])),a.splice(0,0,s.shift()),s.push(a.pop()),a.map((v,i)=>r[parseInt(v+s[i],2)]).join``)

###Pretty Print & Explanation

s => (
 r = " .':", // Map of characters to their (numerical) binary representations (e.g. r[0b10] = "'")
 a = [], // extra array needed
 // Spread `s` into an array, mapping s = [...s].map(c => (
  // Map each character to a `0`-padded string representation of a binary number, storing in `t`
 s = [...s].map(ct =>= ('00' + r.indexOf(c).toString(2)).slice(-2)),
 // Put the first character of `t` into `a` and keep the second charactera.push(t[0]),
 for `s`
 // Keep the second character for `s`
 .map(nt[1]
 => (a.push(n[0]),n[1])),
 // Put the first character of `s` in the first index of `a`
 a.splice(0,0,s.shift()),
 // Append the last character of `a` to `s`
 s.push(a.pop(),
 // Rejoin the characters, alternating from `a` to `s`, representing the rotated matrix, and map them back to their string representation
 a.map((v,i) => r[parseInt(v + s[i],2)]).join``
)

JavaScript (ES6), (削除) 237 (削除ここまで) (削除) 210 (削除ここまで) (削除) 204 (削除ここまで) 188 bytes

Credit to @Downgoat for saving 16 bytes in the latest revision

s=>(r=" .':",a=[],s=[...s].map(c=>('00'+r.indexOf(c).toString(2)).slice(-2)).map(n=>(a.push(n[0]),n[1])),a.splice(0,0,s.shift()),s.push(a.pop()),a.map((v,i)=>r[parseInt(v+s[i],2)]).join``)

###Pretty Print & Explanation

s => (
 r = " .':", // Map of characters to their (numerical) binary representations (e.g. r[0b10] = "'")
 a = [], // extra array needed
 // Spread `s` into an array, mapping each character to a `0`-padded string representation of a binary number
 s = [...s].map(c => ('00' + r.indexOf(c).toString(2)).slice(-2))
 // Put the first character into `a` and keep the second character for `s`
 .map(n => (a.push(n[0]),n[1])),
 // Put the first character of `s` in the first index of `a`
 a.splice(0,0,s.shift()),
 // Append the last character of `a` to `s`
 s.push(a.pop(),
 // Rejoin the characters, alternating from `a` to `s`, representing the rotated matrix, and map them back to their string representation
 a.map((v,i) => r[parseInt(v + s[i],2)]).join``
)

JavaScript (ES6), (削除) 237 (削除ここまで) (削除) 210 (削除ここまで) (削除) 204 (削除ここまで) (削除) 188 (削除ここまで) 182 bytes

Credit to @Downgoat for saving 16 bytes in the 188-byte revision

Update: I had a brainwave and reduced the first operation on s to a single map call instead of two separate ones

s=>(r=" .':",a=[],s=[...s].map(c=>(t=('00'+r.indexOf(c).toString(2)).slice(-2),a.push(t[0]),t[1])),a.splice(0,0,s.shift()),s.push(a.pop()),a.map((v,i)=>r[parseInt(v+s[i],2)]).join``)

###Pretty Print & Explanation

s => (
 r = " .':", // Map of characters to their (numerical) binary representations (e.g. r[0b10] = "'")
 a = [], // extra array needed
 // Spread `s` into an array  s = [...s].map(c => (
  // Map each character to a `0`-padded string representation of a binary number, storing in `t`
 t = ('00' + r.indexOf(c).toString(2)).slice(-2)),
 // Put the first character of `t` into `a` a.push(t[0]),
 // Keep the second character for `s`
 t[1]
 )),
 // Put the first character of `s` in the first index of `a`
 a.splice(0,0,s.shift()),
 // Append the last character of `a` to `s`
 s.push(a.pop(),
 // Rejoin the characters, alternating from `a` to `s`, representing the rotated matrix, and map them back to their string representation
 a.map((v,i) => r[parseInt(v + s[i],2)]).join``
)
added 110 characters in body
Source Link
Loading
added 3 characters in body
Source Link
Downgoat
  • 29.2k
  • 6
  • 85
  • 157
Loading
still attempting syntax highlighting, not sure I'm going to get it to work.
Source Link
Loading
deleted 235 characters in body
Source Link
Loading
attempted (and failed) to add language syntax highlighting - doesn't work here?
Source Link
Loading
Source Link
Loading

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