I searched for (but didn't find) a way to get the human "how many?" function, so I wrote:

#!/usr/bin/perl # fuzzy-size.pl # = Copyright 2010 Xiong Changnian <xiong@sf-id.com> = # = Free Software = Artistic License 2.0 = NO WARRANTY = use strict; use warnings; use feature qw( say ); # "How many apples are in the box?" # This is an ordinary question asked by ordinary people every day. # It's not the same as "Count the apples in the box." # A rough estimate will be fine. # # fuzz() returns 0 for 0 and the exact number for 1, 2, or 3. # It returns 3 ("a few") for 4 also and 6 ("half dozen") for 5..7; # and so forth for increasing magnitudes. # fuzz() returns "the same" (negated) values for negative integers; # we sometimes ask "How many do we need" as well. # But fractions are ignored; you don't count broken apples. # my @raw = ( -768, -9, -3, -2, -1, -0.5, 0, 0.005, 0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 100, 768, 18433, 633999, ); my $in ; my $out ; foreach $in ( @raw ) { $out = fuzz( $in ); say $in, qq{\t}, $out; }; sub fuzz { my $in = int shift; # no floats here, move + along my $out ; return 0 if ( $in == 0 ); my $negative = ( $in < 0 ); # store algebraic sign $in = abs $in; $out = int sqrt exp ( (int log $in**2) + 0.7 ); if ( $negative ) { $out = 0 - $out; }; # restore sign return $out; }; __DATA__ Output: -768 -943 -9 -10 -3 -3 -2 -2 -1 -1 -0.5 0 0 0 0.005 0 0.5 0 1 1 2 2 3 3 4 3 5 6 6 6 7 6 8 10 9 10 10 10 11 10 12 10 13 17 14 17 15 17 16 17 17 17 18 17 19 17 20 17 21 28 23 28 100 127 768 943 18433 18958 633999 627814 __END__

In reply to Fuzzy How-Many by Xiong

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.