Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Vampire Numbers Revisited

by Roy Johnson (Monsignor)
on Mar 23, 2005 at 23:55 UTC ( [id://441920]=note: print w/replies, xml ) Need Help??


in reply to Re: Vampire Numbers Revisited
in thread Vampire Numbers Revisited

I went from the other direction: Look at only the squares in the range:
use strict; use warnings; use POSIX 'ceil'; my $digits = 6; my $fd = $digits/2; my ($lo, $hi) = ((9 x ($digits-1))+1, 9 x $digits); for my $sqrt (ceil(sqrt $lo) .. int(sqrt $hi)) { my $prod = $sqrt * $sqrt; next if substr($prod, $fd, 1) eq '0'; my ($f1, $f2) = (substr($prod, 0, $fd), substr($prod, $fd)); print "$f1 + $f2 = $sqrt, the root of $prod\n" if $f1 + $f2 == $sqrt +; }

Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-23 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found