in reply to mapping 10 -> 4 equally.

That's not possible for your example string, is it? (there's 10 x 10 characters)

Maybe I'm overthinking... bin packing?

use Algorithm::Bucketizer; while (my $in = <>) { chomp($in); my %counts; $counts{$_}++ for split //, $in; my $b = Algorithm::Bucketizer->new(bucketsize=>length($in)/4); $b->add_item($_, $counts{$_}) for keys %counts; $b->optimize(maxrounds=>100); print $_->serial, " => ", join(", ", map {"$_ ($counts{$_})"} $_->items ), "\n" for $b->buckets; }

e.g.

chhbfbjjjcgaiiaachbaefeabcbjffdgaggbgccaihgjddedfheejdigcdeiacebdehfig +egifibdabhfdihbdhifcgjfjhcaejj 1 => f (10), g (10) 2 => b (10), h (10) 3 => i (10), j (10) 4 => e (10), d (10) 5 => c (10), a (10) abbbbbbbccddddddeeefffffgggghhhh 1 => e (3), f (5) 2 => b (7), a (1) 3 => c (2), d (6) 4 => g (4), h (4)

Replies are listed 'Best First'.
Re^2: mapping 10 -> 4 equally.
by BrowserUk (Patriarch) on Jun 20, 2015 at 21:19 UTC
    That's not possible for your example string, is it?

    I don't see why not?

    If a->1, b->2, c->3, d->4, e->1, f->2, g->3, h->4, every other i->1|2, every other j->3|4; that'd would 25 each of 1, 2, 3 & 4.

    Which I guess indicates a laborious way to do it:

    chhbfbjjjcgaiiaachbaefeabcbjffdgaggbgccaihgjddedfheejdigcdeiacebdehfig +egifibdabhfdihbdhifcgjfjhcaejj 3442223433311211342112112324224313323331143344142411442334111312414223 +131222412424142442233324431134 11 11 11 11 1 11 1 11 111 1 1 +1 1 1 1 11 25 222 2 2 2 2 2 22 2 2 2 2 22 + 222 2 2 2 22 2 25 3 3 333 3 3 3 33 333 33 33 3 3 + 3 333 3 3 25 44 4 4 4 4 4 44 4 4 44 4 4 4 + 4 4 4 4 44 44 4 25

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
    I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

      Ah I see, I thought each letter could only be mapped to one number.