Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I made a quick and dirty script to see if some combination of + and -'s between all the digits of that string would return 42.

my $str = '7c9695cb23a71d851688cc0d7f8b1072'; my @nums = map {hex} split '', $str; my @ops = qw(+ -); my @iter = (0) x (length($str) - 1); MAIN: while (1) { my @set = (@ops[@iter], ''); my $newstr = join '', map {$nums[$_] . $set[$_]} (0..$#nums); print "$newstr\n" if 42 == eval $newstr; # Increment my $i = $#iter; while (++$iter[$i] == @ops) { $iter[$i--] = 0; last MAIN if $i < 0; } }

After running for an hour though, I decided that I needed to test this by hand:

use List::Util qw(sum); my $str = '7c9695cb23a71d851688cc0d7f8b1072'; print sum map {hex} split '', $str; =prints 231 =cut

Unfortunately, as you can see, the string contains an odd number of odd digits. This means that no combination of + and -'s between all the digits can return an even number. So there is no simple solution that equals 42


In reply to Re^2: what is for key pls by wind
in thread what is for key pls by Kadir

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (10)
    As of 2014-09-21 15:58 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (172 votes), past polls