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

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

Below is a summary table sorted by final lookup index:

Below is summary table sorted by final lookup index:

Below is a summary table sorted by final lookup index:

added an explanation
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

Try it online!

How?

The hash function was found by brute force:

parseInt(s, 36) * 53 % 437 % 44 % 15

It's a bit long but almost perfect:

  • all slots from 0 to 14 are used
  • black, white and purple (all scoring 11) gracefully collide on the same slot
  • however, two distinct slots are used for lead and zebra (both scoring 23)

Below is summary table sorted by final lookup index:

 string | parseInt() | * 53 | mod 437 | mod 44 | mod 15 | value
-----------+-------------+---------------+---------+--------+--------+-------
 "lead" | 998293 | 52909529 | 191 | 15 | 0 | 23
 "green" | 28152239 | 1492068667 | 339 | 31 | 1 | 3
 "ceramic" | 27013759860 | 1431729272580 | 134 | 2 | 2 | 104
 "moab" | 1057907 | 56069071 | 223 | 3 | 3 | 616
 "bfb" | 14807 | 784771 | 356 | 4 | 4 | 3164
 "red" | 35509 | 1881977 | 255 | 35 | 5 | 1
 "zomg" | 1664872 | 88238216 | 50 | 6 | 6 | 16656
 "yellow" | 2080372496 | 110259742288 | 37 | 37 | 7 | 4
 "rainbow" | 59409106160 | 3148682626480 | 243 | 23 | 8 | 47
 "zebra" | 59454982 | 3151114046 | 127 | 39 | 9 | 23
 "ddt" | 17345 | 919285 | 274 | 10 | 10 | 816
 "bad" | 14629 | 775337 | 99 | 11 | 11 | 55760
 "pink" | 1190576 | 63100528 | 350 | 42 | 12 | 5
 "black" | 19468964 | 1031855092 | 204 | 28 | 13 | 11
 "white" | 54565250 | 2891958250 | 189 | 13 | 13 | 11
 "purple" | 1563335762 | 82856795386 | 336 | 28 | 13 | 11
 "blue" | 541526 | 28700878 | 29 | 29 | 14 | 2

Try it online!

How?

The hash function was found by brute force:

parseInt(s, 36) * 53 % 437 % 44 % 15

It's a bit long but almost perfect:

  • all slots from 0 to 14 are used
  • black, white and purple (all scoring 11) gracefully collide on the same slot
  • however, two distinct slots are used for lead and zebra (both scoring 23)

Below is summary table sorted by final lookup index:

 string | parseInt() | * 53 | mod 437 | mod 44 | mod 15 | value
-----------+-------------+---------------+---------+--------+--------+-------
 "lead" | 998293 | 52909529 | 191 | 15 | 0 | 23
 "green" | 28152239 | 1492068667 | 339 | 31 | 1 | 3
 "ceramic" | 27013759860 | 1431729272580 | 134 | 2 | 2 | 104
 "moab" | 1057907 | 56069071 | 223 | 3 | 3 | 616
 "bfb" | 14807 | 784771 | 356 | 4 | 4 | 3164
 "red" | 35509 | 1881977 | 255 | 35 | 5 | 1
 "zomg" | 1664872 | 88238216 | 50 | 6 | 6 | 16656
 "yellow" | 2080372496 | 110259742288 | 37 | 37 | 7 | 4
 "rainbow" | 59409106160 | 3148682626480 | 243 | 23 | 8 | 47
 "zebra" | 59454982 | 3151114046 | 127 | 39 | 9 | 23
 "ddt" | 17345 | 919285 | 274 | 10 | 10 | 816
 "bad" | 14629 | 775337 | 99 | 11 | 11 | 55760
 "pink" | 1190576 | 63100528 | 350 | 42 | 12 | 5
 "black" | 19468964 | 1031855092 | 204 | 28 | 13 | 11
 "white" | 54565250 | 2891958250 | 189 | 13 | 13 | 11
 "purple" | 1563335762 | 82856795386 | 336 | 28 | 13 | 11
 "blue" | 541526 | 28700878 | 29 | 29 | 14 | 2
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES6), 111 bytes

Expects a list of [count, bloon] pairs.

a=>a.reduce((t,[k,s])=>t+k*[23,3,104,616,3164,1,16656,4,47,23,816,55760,5,11,2][parseInt(s,36)*53%437%44%15],0)

Try it online!

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