Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-18 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found