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

Francesco Ariis fa-ml at ariis.it
Thu Jun 6 20:12:56 UTC 2019


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


More information about the Beginners mailing list