Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: TMTOWTDI Puzzle: Generating a range of numbers

by wog (Curate)
on Dec 19, 2001 at 04:38 UTC ( [id://132987]=note: print w/replies, xml ) Need Help??


in reply to TMTOWTDI Puzzle: Generating a range of numbers

(update: the first one has been edited to fix problems/bad style since I first pressed submit. Oopsie.)

use strict; my @result; my $one = "a" =~ /./; sub add { my($vA,$vB) = @_; ($vA,$vB) = ($vA^$vB,($vA&$vB)<<$one) while $vB; return $vA; } my $val = $one; do { push @result, $val; $val = add($val,$one); } until $one.$one eq $val;

... or, without any lines preceeding it in the file it's in ...

sub f { die if $::f_A; die if $::f_B; die if $::f_C; die if $::f_D; die if $::f_E; die if $::f_F; die if $::f_G; die if $::f_H; die if $::f_I; die if $::f_J; } my @vars = map { "::f_$_" } qw(A B C D E F G H I J); my @result; foreach (@vars) { $$_ = "true"; eval { f() }; push @result, $@ =~ /line ([^.]+)\./; $$_ = undef; }

update: A very, very cheap solution: (doesn't work on EBCDIC systems, sorry)

my @result = split " ", "pasarauatawavayaxapq"^"AAAAAAAAAAAAAAAAAAAA";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://132987]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found