Quantcast
Channel: Tweetable hash function challenge - Code Golf Stack Exchange
Browsing all 25 articles
Browse latest View live

Answer by NikoNyrh for Tweetable hash function challenge

Here are a few similar constructs, which are quite "seedable" and makes incremental parameter optimization possible. Damn it is difficult to get lower than 6k! Assuming the score has the mean of 6829...

View Article



Answer by Magenta for Tweetable hash function challenge

Python 3, 89 bytes, 6534 hash collisions def H(x): v=846811 for y in x: v=(972023*v+330032^ord(y))%2**24 return v%2**24 All the large magic numbers you see here are fudge constants.

View Article

Answer by Shieru Asakoto for Tweetable hash function challenge

JavaScript, 121 bytes, 3268 3250 3244 6354(3185) collisions s=>{v=i=0;[...s].map(z=>{v=((((v*13)+(s.length-i)*7809064+i*380886)/2)^(z.charCodeAt(0)*266324))&16777215;i++});return v}...

View Article

Answer by Kevin Kenny for Tweetable hash function challenge

tcl 88 bytes, 6448 / 3233 collisions I see people have been counting either the number of colliding words, or else the number of words placed in nonempty buckets. I give both counts - the first is...

View Article

Answer by sergiol for Tweetable hash function challenge

tcl #91 bytes, 6508 collisions 91 bytes, 6502 collisions proc H s {lmap c [split $s ""] {incr h [expr [scan $c %c]*875**[incr i]]};expr $h&0xFFFFFF} Computer is still performing a search to...

View Article


Image may be NSFW.
Clik here to view.

Answer by Anders Kaseorg for Tweetable hash function challenge

Alright fine I’ll go learn a golfing language. CJam, 140 bytes, 3314 colliding words 00000000: 7b5f 3162 225e d466 4a55 a05e 9f47 fc51 {_1b"^.fJU.^.G.Q 00000010: c45b 4965 3073 72dd e1b4 d887 a4ac bcbd...

View Article

Answer by Dennis for Tweetable hash function challenge

CJam, 4125 3937 3791 3677 0000000: 7b 5f 39 62 31 31 30 25 5f 22 7d 13 25 77 {_9b110%_"}.%w 000000e: 77 5c 22 0c e1 f5 7b 83 45 85 c0 ed 08 10 w\"...{.E..... 000001c: d3 46 0c 5c 22 59 f8 da 7b f8 18...

View Article

Answer by fluffy for Tweetable hash function challenge

C++: 7112 6694 6483 6479 6412 6339 collisions, 90 bytes I implemented a naïve genetic algorithm for my coefficient array. I'll update this code as it finds better ones. :) int h(const char*s){uint32_t...

View Article


Answer by Blue for Tweetable hash function challenge

Python, 6995 6862 6732 Just a simple RSA function. Pretty lame, but beats some answers. M=0x5437b3a3b1 P=0x65204c34d def H(s): n=0 for i in range(len(s)): n+=pow(ord(s[i]),P,M)<<i return n%(8**8)

View Article


Answer by Anders Kaseorg for Tweetable hash function challenge

Python 2, 140 bytes, 4266 colliding words I didn’t really want to start with the non-printable bytes thing given their unclear tweetability, but well, I didn’t start it. :-P 00000000: efbb bf64 6566...

View Article

Answer by jose_castro_arnaud for Tweetable hash function challenge

Ruby, 9309 collisions, 107 bytes def hash(s);require'prime';p=Prime.first(70);(0...s.size).reduce(0){|a,i|a+=p[i]**(s[i].ord)}%(2**24-1);end Not a good contender, but I wanted to explore a different...

View Article

Answer by Paul Chernoch for Tweetable hash function challenge

Ruby, 6473 collisions, 129 bytes h=->(w){@p=@p||(2..999).select{|i|(2..i**0.5).select{|j|i%j==0}==[]};c=w.chars.reduce(1){|a,s|(a*@p[s.ord%92]+179)%((1<<24)-3)}} The @p variable is filled with...

View Article

Answer by bmm6o for Tweetable hash function challenge

C#, 6251 6335 int H(String s){int h = 733;foreach (char c in s){h = (h * 533 + c);}return h & 0xFFFFFF;} The constants 533 and 733 889 and 155 give the best score out of all of the ones I've...

View Article


Answer by kasperd for Tweetable hash function challenge

Python, 5333 4991 I believe this is the first contender to score significantly better than a random oracle. def H(s):n=int(s.encode('hex'),16);return...

View Article

Answer by binarymax for Tweetable hash function challenge

Javascript (ES5), 6765 This is CRC24 shaved down to 140 Bytes. Could golf more but wanted to get my answer in :)...

View Article


Answer by Dennis for Tweetable hash function challenge

CJam, 6273 {49f^245b16777213%} XOR each character with 49, reduce the resulting string via x, y &mapsto; 245x + y, and take the residue modulo 16,777,213 (the largest 24-bit prime). Scoring $ cat...

View Article

Answer by Godric Seer for Tweetable hash function challenge

Matlab, 30828 8620 6848 It builds the hash by assigning a prime number to each ascii character/position combo and calculating their product for each word modulo the largest prime smaller than 2^24....

View Article


Answer by Bewusstsein for Tweetable hash function challenge

Java 8, 7054 6467 This is inspired by (but not copied from) the builtin java.lang.String.hashCode function, so feel free to disallow according to rule #2. w -> { return w.chars().reduce(53, (acc, c)...

View Article

Answer by Mwr247 for Tweetable hash function challenge

JavaScript (ES6), 6389 The hash function (105 bytes): s=>[...s.replace(/[A-Z]/g,a=>(b=a.toLowerCase())+b+b)].reduce((a,b)=>(a<<3)*28-a^b.charCodeAt(),0)<<8>>>8 The scoring...

View Article

Answer by ASCII-only for Tweetable hash function challenge

Python, 6390 6376 6359 H=lambda s:reduce(lambda a,x:a*178+ord(x),s,0)%(2**24-48) May be considered a trivial modification to Martin Büttner's answer.

View Article
Browsing all 25 articles
Browse latest View live




Latest Images