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

Commonmark migration
Source Link

JavaScript (Node.js), 78 bytes

This is a port of xnor's great answer.

s=>(t=118,u=10340,g=k=>Buffer(s).map(x=>(u+=t-=k&x-96)-531*t?x:x+t))(g(~0))+''

Try it online!


JavaScript (Node.js), (削除) 121 118 (削除ここまで) 116 bytes

s=>[...s+'jEIM'].some(c=>[...s].some(C=>Buffer(o=p+c+s.slice(++i)).map(c=>k=k*99^c,k=p+=C)|k==0x6B9400B8,i=p=''))&&o

Try 10 random test cases online!

##How?

How?

###Replacement letters

Replacement letters

All letters in the original paragraph appear at least twice, except j, E, I and M that appear only once and may disappear in the modified paragraph.

That's why we do:

[...s + 'jEIM'].some(c => ...)

This way, it is guaranteed that each possible replacement letter is tried.

###Hash

Hash

Using a built-in hash would be rather lengthy in Node:

require('crypto').createHash('md5').update(string).digest('hex')

Instead of that, we use the following custom 32-bit hash:

Buffer(string).map(c => k = k * 99 ^ c, k = 0)

This was (rather painfully) tested against all possible inputs.

JavaScript (Node.js), 78 bytes

This is a port of xnor's great answer.

s=>(t=118,u=10340,g=k=>Buffer(s).map(x=>(u+=t-=k&x-96)-531*t?x:x+t))(g(~0))+''

Try it online!


JavaScript (Node.js), (削除) 121 118 (削除ここまで) 116 bytes

s=>[...s+'jEIM'].some(c=>[...s].some(C=>Buffer(o=p+c+s.slice(++i)).map(c=>k=k*99^c,k=p+=C)|k==0x6B9400B8,i=p=''))&&o

Try 10 random test cases online!

##How?

###Replacement letters

All letters in the original paragraph appear at least twice, except j, E, I and M that appear only once and may disappear in the modified paragraph.

That's why we do:

[...s + 'jEIM'].some(c => ...)

This way, it is guaranteed that each possible replacement letter is tried.

###Hash

Using a built-in hash would be rather lengthy in Node:

require('crypto').createHash('md5').update(string).digest('hex')

Instead of that, we use the following custom 32-bit hash:

Buffer(string).map(c => k = k * 99 ^ c, k = 0)

This was (rather painfully) tested against all possible inputs.

JavaScript (Node.js), 78 bytes

This is a port of xnor's great answer.

s=>(t=118,u=10340,g=k=>Buffer(s).map(x=>(u+=t-=k&x-96)-531*t?x:x+t))(g(~0))+''

Try it online!


JavaScript (Node.js), (削除) 121 118 (削除ここまで) 116 bytes

s=>[...s+'jEIM'].some(c=>[...s].some(C=>Buffer(o=p+c+s.slice(++i)).map(c=>k=k*99^c,k=p+=C)|k==0x6B9400B8,i=p=''))&&o

Try 10 random test cases online!

How?

Replacement letters

All letters in the original paragraph appear at least twice, except j, E, I and M that appear only once and may disappear in the modified paragraph.

That's why we do:

[...s + 'jEIM'].some(c => ...)

This way, it is guaranteed that each possible replacement letter is tried.

Hash

Using a built-in hash would be rather lengthy in Node:

require('crypto').createHash('md5').update(string).digest('hex')

Instead of that, we use the following custom 32-bit hash:

Buffer(string).map(c => k = k * 99 ^ c, k = 0)

This was (rather painfully) tested against all possible inputs.

added a port of xnor's answer
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (Node.js), 78 bytes

This is a port of xnor's great answer .

s=>(t=118,u=10340,g=k=>Buffer(s).map(x=>(u+=t-=k&x-96)-531*t?x:x+t))(g(~0))+''

Try it online!


JavaScript (Node.js) , (削除) 121 118 (削除ここまで) 116 bytes

s=>[...s+'jEIM'].some(c=>[...s].some(C=>Buffer(o=p+c+s.slice(++i)).map(c=>k=k*99^c,k=p+=C)|k==0x6B9400B8,i=p=''))&&o

Try 10 random test cases online!

##How?

###Replacement letters

All letters in the original paragraph appear at least twice, except j, E, I and M that appear only once and may disappear in the modified paragraph.

That's why we do:

[...s + 'jEIM'].some(c => ...)

This way, it is guaranteed that each possible replacement letter is tried.

###Hash

Using a built-in hash would be rather lengthy in Node:

require('crypto').createHash('md5').update(string).digest('hex')

Instead of that, we use the following custom 32-bit hash:

Buffer(string).map(c => k = k * 99 ^ c, k = 0)

This was (rather painfully) tested against all possible inputs.

JavaScript (Node.js), (削除) 121 118 (削除ここまで) 116 bytes

s=>[...s+'jEIM'].some(c=>[...s].some(C=>Buffer(o=p+c+s.slice(++i)).map(c=>k=k*99^c,k=p+=C)|k==0x6B9400B8,i=p=''))&&o

Try 10 random test cases online!

##How?

###Replacement letters

All letters in the original paragraph appear at least twice, except j, E, I and M that appear only once and may disappear in the modified paragraph.

That's why we do:

[...s + 'jEIM'].some(c => ...)

This way, it is guaranteed that each possible replacement letter is tried.

###Hash

Using a built-in hash would be rather lengthy in Node:

require('crypto').createHash('md5').update(string).digest('hex')

Instead of that, we use the following custom 32-bit hash:

Buffer(string).map(c => k = k * 99 ^ c, k = 0)

This was (rather painfully) tested against all possible inputs.

JavaScript (Node.js), 78 bytes

This is a port of xnor's great answer .

s=>(t=118,u=10340,g=k=>Buffer(s).map(x=>(u+=t-=k&x-96)-531*t?x:x+t))(g(~0))+''

Try it online!


JavaScript (Node.js) , (削除) 121 118 (削除ここまで) 116 bytes

s=>[...s+'jEIM'].some(c=>[...s].some(C=>Buffer(o=p+c+s.slice(++i)).map(c=>k=k*99^c,k=p+=C)|k==0x6B9400B8,i=p=''))&&o

Try 10 random test cases online!

##How?

###Replacement letters

All letters in the original paragraph appear at least twice, except j, E, I and M that appear only once and may disappear in the modified paragraph.

That's why we do:

[...s + 'jEIM'].some(c => ...)

This way, it is guaranteed that each possible replacement letter is tried.

###Hash

Using a built-in hash would be rather lengthy in Node:

require('crypto').createHash('md5').update(string).digest('hex')

Instead of that, we use the following custom 32-bit hash:

Buffer(string).map(c => k = k * 99 ^ c, k = 0)

This was (rather painfully) tested against all possible inputs.

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

JavaScript (Node.js), (削除) 121 118 (削除ここまで) 118116 bytes

s=>[...s+'jEIM'].some(c=>[...s].some(C=>Buffer(o=p+c+s.slice(++i)).map(c=>k=~k*97+cc=>k=k*99^c,k=p+=C)|k==0x8B9C2B0C2|k==0x6B9400B8,i=p=''))&&o

Try 10 random test cases online! Try 10 random test cases online!

##How?

###Replacement letters

All letters in the original paragraph appear at least twice, except j, E, I and M that appear only once and may disappear in the modified paragraph.

That's why we do:

[...s + 'jEIM'].some(c => ...)

This way, it is guaranteed that each possible replacement letter is tried.

###Hash

Using a built-in hash would be rather lengthy in Node:

require('crypto').createHash('md5').update(string).digest('hex')

Instead of that, we use the following custom 32-bit hash:

Buffer(string).map(c => k = ~kk * 9799 +^ c, k = 0)

The bitwise ~ ensures that the value from the previous iteration is turned into a 32-bit quantity to prevent an arithmetic overflow.

This was (rather painfully) tested against all possible inputs.

JavaScript (Node.js), (削除) 121 (削除ここまで) 118 bytes

s=>[...s+'jEIM'].some(c=>[...s].some(C=>Buffer(o=p+c+s.slice(++i)).map(c=>k=~k*97+c,k=p+=C)|k==0x8B9C2B0C2,i=p=''))&&o

Try 10 random test cases online!

##How?

###Replacement letters

All letters in the original paragraph appear at least twice, except j, E, I and M that appear only once and may disappear in the modified paragraph.

That's why we do:

[...s + 'jEIM'].some(c => ...)

This way, it is guaranteed that each possible replacement letter is tried.

###Hash

Using a built-in hash would be rather lengthy in Node:

require('crypto').createHash('md5').update(string).digest('hex')

Instead of that, we use the following custom hash:

Buffer(string).map(c => k = ~k * 97 + c, k = 0)

The bitwise ~ ensures that the value from the previous iteration is turned into a 32-bit quantity to prevent an arithmetic overflow.

This was (rather painfully) tested against all possible inputs.

JavaScript (Node.js), (削除) 121 118 (削除ここまで) 116 bytes

s=>[...s+'jEIM'].some(c=>[...s].some(C=>Buffer(o=p+c+s.slice(++i)).map(c=>k=k*99^c,k=p+=C)|k==0x6B9400B8,i=p=''))&&o

Try 10 random test cases online!

##How?

###Replacement letters

All letters in the original paragraph appear at least twice, except j, E, I and M that appear only once and may disappear in the modified paragraph.

That's why we do:

[...s + 'jEIM'].some(c => ...)

This way, it is guaranteed that each possible replacement letter is tried.

###Hash

Using a built-in hash would be rather lengthy in Node:

require('crypto').createHash('md5').update(string).digest('hex')

Instead of that, we use the following custom 32-bit hash:

Buffer(string).map(c => k = k * 99 ^ c, k = 0)

This was (rather painfully) tested against all possible inputs.

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

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