Well, here is a quick hack comparing two hashing algorithms. The first keys on the sum of the digits (1234 -> 10), The second uses the last two chars (1234 -> 34). Since we started with a random set, the results aren't too surprising.....
#!/usr/bin/perl -wT use strict; my $count = shift || 10000; my $verbose = shift || 0; my %hash; for (1..$count) { my $value = int(rand(899_999_999)+100_000_000); # uncomment one of the next two lines to toggle algorithms #my $hv = digitsum($value); my $hv = lastchars($value); print "$value => $hv\n" if $verbose; $hash{$hv}++; } my $keycount = keys %hash; my @orderedvalues = (sort {$a <=> $b} values %hash); my ($min,$max) = (@orderedvalues)[0,-1]; print "$keycount keys\n"; print "Min:$min\n"; print "Max:$max\n"; for (@orderedvalues) { printf "%4d:",$_; print '*' x int($_/$max*70),"\n"; } sub digitsum { my $key = shift; my $hv; $hv += $_ for (split//,$key); return $hv; } sub lastchars { my $key = shift; my ($hv) = ($key =~ /(..)$/); return $hv; } =OUTPUT using lastchars 100 keys Min:77 Max:119 77:********************************************* 79:********************************************** 80:*********************************************** 80:*********************************************** 81:*********************************************** 82:************************************************ 85:************************************************** 86:************************************************** 86:************************************************** 86:************************************************** 87:*************************************************** 87:*************************************************** 88:*************************************************** 88:*************************************************** 88:*************************************************** 88:*************************************************** 88:*************************************************** 88:*************************************************** 88:*************************************************** 89:**************************************************** 89:**************************************************** 89:**************************************************** 90:**************************************************** 90:**************************************************** 91:***************************************************** 91:***************************************************** 92:****************************************************** 93:****************************************************** 93:****************************************************** 93:****************************************************** 93:****************************************************** 94:******************************************************* 94:******************************************************* 95:******************************************************* 95:******************************************************* 95:******************************************************* 96:******************************************************** 96:******************************************************** 97:********************************************************* 97:********************************************************* 97:********************************************************* 97:********************************************************* 98:********************************************************* 98:********************************************************* 98:********************************************************* 99:********************************************************** 99:********************************************************** 99:********************************************************** 100:********************************************************** 100:********************************************************** 100:********************************************************** 100:********************************************************** 101:*********************************************************** 102:************************************************************ 102:************************************************************ 102:************************************************************ 103:************************************************************ 103:************************************************************ 103:************************************************************ 104:************************************************************* 105:************************************************************* 105:************************************************************* 106:************************************************************** 106:************************************************************** 106:************************************************************** 106:************************************************************** 106:************************************************************** 106:************************************************************** 107:************************************************************** 107:************************************************************** 107:************************************************************** 107:************************************************************** 108:*************************************************************** 109:**************************************************************** 109:**************************************************************** 109:**************************************************************** 109:**************************************************************** 109:**************************************************************** 110:**************************************************************** 110:**************************************************************** 110:**************************************************************** 110:**************************************************************** 111:***************************************************************** 111:***************************************************************** 112:***************************************************************** 112:***************************************************************** 113:***************************************************************** +* 113:***************************************************************** +* 114:***************************************************************** +** 114:***************************************************************** +** 114:***************************************************************** +** 115:***************************************************************** +** 116:***************************************************************** +*** 116:***************************************************************** +*** 116:***************************************************************** +*** 116:***************************************************************** +*** 116:***************************************************************** +*** 118:***************************************************************** +**** 118:***************************************************************** +**** 119:***************************************************************** +***** =OUTPUT using digitsum 59 keys Min:1 Max:477 1: 1: 1: 2: 2: 2: 4: 4: 5: 5: 6: 10:* 12:* 12:* 16:** 19:** 21:*** 22:*** 25:*** 29:**** 35:***** 45:****** 51:******* 51:******* 63:********* 68:********* 74:********** 88:************ 96:************** 113:**************** 127:****************** 138:******************** 145:********************* 152:********************** 172:************************* 184:*************************** 209:****************************** 225:********************************* 226:********************************* 242:*********************************** 249:************************************ 266:*************************************** 283:***************************************** 294:******************************************* 309:********************************************* 341:************************************************** 364:***************************************************** 380:******************************************************* 381:******************************************************* 383:******************************************************** 422:************************************************************* 424:************************************************************** 439:**************************************************************** 441:**************************************************************** 446:***************************************************************** 458:***************************************************************** +** 464:***************************************************************** +*** 476:***************************************************************** +**** 477:***************************************************************** +*****

-Blake


In reply to Re5: brainteaser: splitting up a namespace evenly by blakem
in thread brainteaser: splitting up a namespace evenly by perrin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.