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

You are not logged in.

## #26 2013-07-06 06:16:27

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Help with M

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #27 2013-07-06 06:24:27

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

### Re: Help with M

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
The knowledge of some things as a function of age is a delta function.

Offline

## #28 2013-07-06 06:29:17

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Help with M

What would you use it for?

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #29 2013-07-06 06:36:46

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

### Re: Help with M

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
The knowledge of some things as a function of age is a delta function.

Offline

## #30 2013-07-06 06:42:44

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Help with M

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.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #31 2013-07-06 06:45:04

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

### Re: Help with M

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
The knowledge of some things as a function of age is a delta function.

Offline

## #32 2013-07-06 06:49:33

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Help with M

Post #16 looks like a beauty to me.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #33 2013-07-06 06:50:53

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

### Re: Help with M

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.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #34 2013-07-06 06:56:37

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Help with M

By doing what M does.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #35 2013-07-06 07:00:40

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

### Re: Help with M

Hm?

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
The knowledge of some things as a function of age is a delta function.

Offline

## #36 2013-07-06 07:02:39

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Help with M

Sort of like using NextPrime.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #37 2013-07-06 07:39:53

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

### Re: Help with M

I still do not get it.

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
The knowledge of some things as a function of age is a delta function.

Offline

## #38 2013-07-06 07:42:52

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Help with M

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.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #39 2013-07-06 08:02:56

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

### Re: Help with M

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.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #40 2013-07-06 13:01:07

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Help with M

Actually you do not keep the entire list.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #41 2013-07-06 15:12:05

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

### Re: Help with M

No?

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
The knowledge of some things as a function of age is a delta function.

Offline

## #42 2013-07-06 16:49:50

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,838
Website

### Re: Help with M

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'
I'm not crazy, my mother had me tested.

Offline

## #43 2013-07-06 17:23:20

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

### Re: Help with M

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

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
The knowledge of some things as a function of age is a delta function.

Offline

## #44 2013-07-06 19:16:36

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Help with M

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.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #45 2013-07-06 19:49:44

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,838
Website

### Re: Help with M

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'
I'm not crazy, my mother had me tested.

Offline

## #46 2013-07-06 19:54:24

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Help with M

I remember that problem.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #47 2013-07-06 21:10:29

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,037

### Re: Help with M

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.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #48 2013-07-07 00:16:35

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Help with M

Hi;

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

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline