[Haskell-beginners] How can I view a digit on the N-th position of 9^(9^9) in Haskell?

Sergej KAREL KSergej at seznam.cz
Fri Jun 7 04:06:27 UTC 2019


Hello Francesco,
Im total beginner. I read some books and online pages.

I do not know, how to apply your rows if Im looking eg. digit on position 
177486336 of the number string

Sorry for asking so straightforward

Sergej





---------- Původní e-mail ----------
Od: Francesco Ariis <fa-ml at ariis.it>
Komu: beginners at haskell.org
Datum: 6. 6. 2019 22:13:36
Předmět: Re: [Haskell-beginners] How can I view a digit on the N-th position
of 9^(9^9) in Haskell? 
"Hello Sergej,

On Thu, Jun 06, 2019 at 09:06:00PM +0200, Sergej KAREL wrote:
> Hello,
> Im looking for setting up a solver for the determination of digit on N-th 
> position of the high value number

The trick is to only take the appropriate reminder instead of the whole
multiplication result. Something like:

λ> myMult x y = rem (x * y) 100
λ> :t +d foldr1
foldr1 :: (a -> a -> a) -> [a] -> a
λ> myPower x y = foldr1 myMult (replicate y x)
λ> myPower 9 9
89
λ> 9^9
387420489
λ> myPower 9 (myPower 9 9)
89

Does this help?
-F
_______________________________________________
Beginners mailing list
Beginners at haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20190607/17bdd3ce/attachment.html>


More information about the Beginners mailing list