Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,266

Since there is no known formula for the nth prime use the loop and memoization.

**In mathematics, you don't understand things. You just get used to them.Of course that result can be rigorously obtained, but who cares?Combinatorics is Algebra and Algebra is Combinatorics.**

**Online**

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,544

Yes. Here is the function that finds the nth number to satisfy the condition Test:

```
Nth[n_Integer, Test_] := Module[{res, num},
res = 1;
num = 1;
While[num < n, If[Test@res, num++]; If[num < n, res++]];
res
]
```

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,266

What would you use it for?

**In mathematics, you don't understand things. You just get used to them.Of course that result can be rigorously obtained, but who cares?Combinatorics is Algebra and Algebra is Combinatorics.**

**Online**

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,544

Well, to get Harshad from HarshadQ, for example.

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,266

Isn't the one I suggested capable of that and it is less procedural?

**In mathematics, you don't understand things. You just get used to them.Of course that result can be rigorously obtained, but who cares?Combinatorics is Algebra and Algebra is Combinatorics.**

**Online**

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,544

Which one?

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,266

Post #16 looks like a beauty to me.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

**Online**

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,544

But, with that you only test which of those are Harshad. How do you plan on finding the nth one for a given n?

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,266

By doing what M does.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

**Online**

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,544

Hm?

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,266

Sort of like using NextPrime.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

**Online**

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,544

I still do not get it.

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,266

You keep a list and expand upon it each time you need a higher number. M keeps a very big list of primes in memory. But although it would be faster it is harder to program so stick with what you have there.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

**Online**

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,544

Oh, I get it. But, I do not think I am going to use the Harshad function so often that I need a list such as a prime list.

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,266

Actually you do not keep the entire list.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

**Online**

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,544

No?

Here lies the reader who will never open this book. He is forever dead.

Offline

anonimnystefy wrote:

I want to find the 1000th Harshad number in base 5.

Sounds like a Brilliant problem!

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

**Online**

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,544

I agree. It most certainly seems like a Brilliant problem.

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,266

It is not a brilliant problem for L5.

You do not need the whole list to speed everything up but you do not require it for a program that run infrequently. CSBFC.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

**Online**

I solved that problem.

BTW, I have a 17 MB list of primes, so I did not have to compute the primes again

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

**Online**

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,266

I remember that problem.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

**Online**

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,544

By the way, I was looking over at Rosetta Code. There is a problem that attracts my attention. It's this one. How can it be done in M?

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 87,266

Hi;

I can provide the core commands but you must tell how you want the game to be played.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

**Online**