WC -Sx- Jones wrote:

> WC -Sx- Jones wrote:
> > What is happening here -
> > while(1) {
> >   (++$count) ? $count += $count-- : $count += $count++;
> >
>
> :) May I ask a different way?
>
> #! /usr/bin/perl
> use strict;
> use warnings;
>
> my $count;
> my $str;
>
> while(1) {
>    (++$count) ? $count += $count--
>               : $count += $count++;
>
>    $str = unpack("B32", pack("N", $count));
>    print "$count \tis binary $str\n";
>    exit if $count > 60_000;
>    sleep 1;
> }
>
> __END__
> -Sx-
>
> PS - I am admit that I am likely in the middle of
> a nervous break-down  LOL :)
>
> BTW - Joseph was correct about the side-effects issue. :)
> No one seemed to address the other data formats...

That is pretty much how I got there.  Not that I would have to unpcak those
numbers--they're pretty much engreained onmy memory ever since an instructor
gave us the prefect number problem as an assignment.  Definitely increased my
admiration for Euclid, who did not have the binary p[aradigm to work with.

To elaborate a little:

Greetings! E:\d_drive\perlStuff>perl -w
#!perl -w
use strict;
use warnings;

my $count;

while(1) {
   if (++$count) {              # on second round: $count ==  ($oringinal * 4 -
1) + 1 == $oringinal * 4
                          # $oringinal = $count == 1
      $count += $count;   # $count == $oringinal * 2
      $count--;           # $count == ($oringinal * 2) - 1
      my $alternative_yes = $count;  #dead code
      $count += $count;   # $count == (($oringinal * 2) - 1) * 2 == (($oringinal
* 2) * 2) - (1 * 2) == ($oringinal * 4) - 2
      $count++;           # $count ==  (($oringinal * 4) - 2) + 1 == $oringinal
* 4 - 1
      my $alternative_no = $count;   #dead code
   } else {
      die "The impossible has happened! $!";
   }
      print "$count\n"; exit if $count > 60_000;
   sleep 1;
}

^Z
3
15
63

So the upshot is that the function essentially quadruples the base value for the
loop on each iteration, but prints a value one less than the base value.

The values above could be clearly exzpressed as
4 -1
16 -1
64 -1
256 -1

or

4 ** 1 - 1
4 ** 2 - 1
4 ** 3 -1

..with a bit of sleight of hand thrown in for spice.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to