determining if a int is a power
Brandon Michael Moore
brandon at its.caltech.edu
Sat Nov 8 01:59:06 EST 2003
Are you looking for numbers that are squares, or any
power (probably any power at least two)? If it's the latter
you need something more interesting that sqrt.
An alternative to squaring the number agagin is to
use properFraction.
Brandon
On Fri, 7 Nov 2003, Hamilton Richards wrote:
> Also note that
>
> if x then True else False
>
> is just a verbose way of writing
>
> x
>
> At 2:51 PM -0800 11/7/03, Hal Daume III wrote:
> >try "floor (sqrt (fromIntegral n))"
> >
> >On Fri, 7 Nov 2003 ddekker6 at chello.nl wrote:
> >
> >> hello all,
> >>
> >> im new to haskell and have to do some excersises. Well i ran into
> >>this problem. I have to determin if a list of int's contains a int
> >>that is a power. So i have been trying using "any" with a helper
> >>function which return a Bool if the int is a power and applying
> >>that to the list. I think that this aproach should work.
> >> Anyway the problem im having is in the helper function. I have
> >>been trying this:
> >> isPower n =
> >> let powerF = floor(sqrt(n)) in
> >> if (powerF*PowerF == n)
> >> then True
> > > else False
>
> [...]
> --
> ------------------------------------------------------------------
> Hamilton Richards, PhD Department of Computer Sciences
> Senior Lecturer The University of Texas at Austin
> 512-471-9525 1 University Station C0500
> Taylor Hall 5.138 Austin, Texas 78712-1188
> ham at cs.utexas.edu hrichrds at swbell.net
> ------------------------------------------------------------------
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
More information about the Haskell-Cafe
mailing list