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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Sergej KAREL
Hello,
Im looking for setting up a solver for the determination of digit on N-th position of the high value number
Best regards
Sergej

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

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

Francesco Ariis
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
Reply | Threaded
Open this post in threaded view
|

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

Sergej KAREL
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



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

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

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

Michael Orlitzky
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
Reply | Threaded
Open this post in threaded view
|

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

Ut Primum
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]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners