Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Converting a Number into a Radical

by hdb (Prior)
on Dec 20, 2013 at 10:25 UTC ( #1067941=note: print w/replies, xml ) Need Help??


in reply to Re: Converting a Number into a Radical
in thread Converting a Number into a Radical

I could not resist to write it out:

use strict; use warnings; use Math::Factor::XS 'prime_factors'; my $n = shift; ( $n and $n > 0 and $n == int $n ) or die "Need positive integer as in +put!\n"; my %p; $p{$_}++ for prime_factors( $n ); my $radical = 1; $radical *= $_ for grep { $p{$_}%2 } keys %p; print "sqrt( $n ) = ", sqrt( $n/$radical ), " * sqrt( $radical )\n";

What I was missing is a product function, like sum from List::Util. There is one in the replacement List::Util that comes with Scalar::Util but that means overwriting the standard module which makes me feel uncomfortable.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067941]
help
Chatterbox?
[LanX]: interpolation! like in a "string"
[Lady_Aleena]: LanX, I just never thought I would be explaining perl regex to others. It is usually others explaining why a regex isn't working to me.
[Discipulus]: congratulations shmem! (was my last upvote? ;=)

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2017-04-28 09:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (520 votes). Check out past polls.