Skip to main content
Commonmark migration
Source Link

JavaScript (Node.js),  121  119 bytes

Saved 2 bytes thanks to @tsh

c=>`2XYZABC 0VW5DE U9F T9G S9H 0RQ5JI 2PONMLK`.replace(/./g,x=>''.padEnd(+x+1)||(B=Buffer)([65+([a,b]=B(c+x),a+b)%26])) 

Try it online!

##How?

How?

This code abuses Buffer to extract the ASCII codes of the template letter \$x\$ and input letter \$c\$ and convert them back into the target letter.

###Example with \$c=\$"H" and \$x=\$"B"

Example with \$c=\$"H" and \$x=\$"B"

// extracting the ASCII codes Buffer(c + x) → Buffer("HB") → <Buffer 48 42> // assigning them to variables [a, b] = Buffer(c + x) → a = 0x48 (72) and b = 0x42 (66) // computing the ASCII code of the target letter 65 + ((a + b) % 26) → 65 + (138 % 26) → 65 + 8 → 73 // turning it back into a character Buffer([73]) → <Buffer 49> → implicitly coerced to "I" by replace() 

JavaScript (Node.js),  121  119 bytes

Saved 2 bytes thanks to @tsh

c=>`2XYZABC 0VW5DE U9F T9G S9H 0RQ5JI 2PONMLK`.replace(/./g,x=>''.padEnd(+x+1)||(B=Buffer)([65+([a,b]=B(c+x),a+b)%26])) 

Try it online!

##How?

This code abuses Buffer to extract the ASCII codes of the template letter \$x\$ and input letter \$c\$ and convert them back into the target letter.

###Example with \$c=\$"H" and \$x=\$"B"

// extracting the ASCII codes Buffer(c + x) → Buffer("HB") → <Buffer 48 42> // assigning them to variables [a, b] = Buffer(c + x) → a = 0x48 (72) and b = 0x42 (66) // computing the ASCII code of the target letter 65 + ((a + b) % 26) → 65 + (138 % 26) → 65 + 8 → 73 // turning it back into a character Buffer([73]) → <Buffer 49> → implicitly coerced to "I" by replace() 

JavaScript (Node.js),  121  119 bytes

Saved 2 bytes thanks to @tsh

c=>`2XYZABC 0VW5DE U9F T9G S9H 0RQ5JI 2PONMLK`.replace(/./g,x=>''.padEnd(+x+1)||(B=Buffer)([65+([a,b]=B(c+x),a+b)%26])) 

Try it online!

How?

This code abuses Buffer to extract the ASCII codes of the template letter \$x\$ and input letter \$c\$ and convert them back into the target letter.

Example with \$c=\$"H" and \$x=\$"B"

// extracting the ASCII codes Buffer(c + x) → Buffer("HB") → <Buffer 48 42> // assigning them to variables [a, b] = Buffer(c + x) → a = 0x48 (72) and b = 0x42 (66) // computing the ASCII code of the target letter 65 + ((a + b) % 26) → 65 + (138 % 26) → 65 + 8 → 73 // turning it back into a character Buffer([73]) → <Buffer 49> → implicitly coerced to "I" by replace() 
added an explanation
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (Node.js),  121  119 bytes

Saved 2 bytes thanks to @tsh

c=>`2XYZABC 0VW5DE U9F T9G S9H 0RQ5JI 2PONMLK`.replace(/./g,x=>''.padEnd(+x+1)||(B=Buffer)([65+([a,b]=B(c+x),a+b)%26])) 

Try it online!

##How?

This code abuses Buffer to extract the ASCII codes of the template letter \$x\$ and input letter \$c\$ and convert them back into the target letter.

###Example with \$c=\$"H" and \$x=\$"B"

// extracting the ASCII codes Buffer(c + x) → Buffer("HB") → <Buffer 48 42> // assigning them to variables [a, b] = Buffer(c + x) → a = 0x48 (72) and b = 0x42 (66) // computing the ASCII code of the target letter 65 + ((a + b) % 26) → 65 + (138 % 26) → 65 + 8 → 73 // turning it back into a character Buffer([73]) → <Buffer 49> → implicitly coerced to "I" by replace() 

JavaScript (Node.js),  121  119 bytes

Saved 2 bytes thanks to @tsh

c=>`2XYZABC 0VW5DE U9F T9G S9H 0RQ5JI 2PONMLK`.replace(/./g,x=>''.padEnd(+x+1)||(B=Buffer)([65+([a,b]=B(c+x),a+b)%26])) 

Try it online!

JavaScript (Node.js),  121  119 bytes

Saved 2 bytes thanks to @tsh

c=>`2XYZABC 0VW5DE U9F T9G S9H 0RQ5JI 2PONMLK`.replace(/./g,x=>''.padEnd(+x+1)||(B=Buffer)([65+([a,b]=B(c+x),a+b)%26])) 

Try it online!

##How?

This code abuses Buffer to extract the ASCII codes of the template letter \$x\$ and input letter \$c\$ and convert them back into the target letter.

###Example with \$c=\$"H" and \$x=\$"B"

// extracting the ASCII codes Buffer(c + x) → Buffer("HB") → <Buffer 48 42> // assigning them to variables [a, b] = Buffer(c + x) → a = 0x48 (72) and b = 0x42 (66) // computing the ASCII code of the target letter 65 + ((a + b) % 26) → 65 + (138 % 26) → 65 + 8 → 73 // turning it back into a character Buffer([73]) → <Buffer 49> → implicitly coerced to "I" by replace() 
saved 2 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (Node.js), 121 121  119 bytes

Saved 2 bytes thanks to @tsh

c=>`2XYZABC 0VW5DE U9F T9G S9H 0RQ5JI 2PONMLK`.replace(/./g,x=>1/x?''x=>''.padEnd(-~x+x+1):||(B=Buffer)([65+([a,b]=B(c+x),a+b)%26])) 

Try it online!Try it online!

JavaScript (Node.js), 121 bytes

c=>`2XYZABC 0VW5DE U9F T9G S9H 0RQ5JI 2PONMLK`.replace(/./g,x=>1/x?''.padEnd(-~x):(B=Buffer)([65+([a,b]=B(c+x),a+b)%26])) 

Try it online!

JavaScript (Node.js),  121  119 bytes

Saved 2 bytes thanks to @tsh

c=>`2XYZABC 0VW5DE U9F T9G S9H 0RQ5JI 2PONMLK`.replace(/./g,x=>''.padEnd(+x+1)||(B=Buffer)([65+([a,b]=B(c+x),a+b)%26])) 

Try it online!

Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading