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

5 messages
Open this post in threaded view
|

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

 Hello,Im looking for setting up a solver for the determination of digit on N-th position of the high value numberBest regardsSergej_______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|

## Re: 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 [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|

## Re: How can I view a digit on the N-th position of 9^(9^9) in Haskell?

 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 stringSorry for asking so straightforwardSergej ---------- Původní e-mail ---------- Od: Francesco Ariis <[hidden email]> Komu: [hidden email] 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 numberThe trick is to only take the appropriate reminder instead of the wholemultiplication 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) 89Does this help?-F_______________________________________________Beginners mailing list[hidden email]http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners_______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|

## Re: How can I view a digit on the N-th position of 9^(9^9) in Haskell?

 On 6/7/19 12:06 AM, Sergej KAREL wrote: > 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 This is a math problem. Read the first few chapters of a book on number theory -- you'll usually find something like this in the exercises. For example, exercise 2.30 in the freely-available "Elementary Number Theory: Primes, Congruences, and Secrets" by William Stein:   https://wstein.org/ent/_______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Open this post in threaded view
|

## Re: How can I view a digit on the N-th position of 9^(9^9) in Haskell?

Hello Sergej,

if you need to know the  Nth digit of a number (i.e. 10987654321), assuming that we say that the rightmost digit is the digit 1, (so in my example 1st digit is 1), you can use:
> x=10987654321
> div (mod x (10^N)) (10^(N-1))

So, if you don't need a fast program and you want to compute the digit in position 177486336 of 9^(9^9):
> x=9^(9^9)
> div (mod x (10^177486336)) (10^177486335)
(it takes about 1 minute to compute it)

or in general if you want to know the N-th digit :
> x=9^(9^9)
> div (mod x (10^N)) (10^(N-1))

 Mail priva di virus. www.avg.com

Il giorno ven 7 giu 2019 alle ore 16:53 Michael Orlitzky <[hidden email]> ha scritto:
On 6/7/19 12:06 AM, Sergej KAREL wrote:
> 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

This is a math problem. Read the first few chapters of a book on number
theory -- you'll usually find something like this in the exercises.

For example, exercise 2.30 in the freely-available "Elementary Number
Theory: Primes, Congruences, and Secrets" by William Stein:

https://wstein.org/ent/

_______________________________________________
Beginners mailing list
[hidden email]