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

You are not logged in.

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

bobbym

Offline

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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#27 2013-07-07 04:24:27

anonimnystefy
Real Member

Online

Re: Help with M

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

Code:

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

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

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

bobbym

Offline

Re: Help with M

What would you use it for?

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

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

anonimnystefy
Real Member

Online

Re: Help with M

Well, to get Harshad from HarshadQ, for example.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

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

bobbym

Offline

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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

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

anonimnystefy
Real Member

Online

Re: Help with M

Which one?

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

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

bobbym

Offline

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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

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

anonimnystefy
Real Member

Online

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?

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

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

bobbym

Offline

Re: Help with M

By doing what M does.

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

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

anonimnystefy
Real Member

Online

Re: Help with M

Hm?

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

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

bobbym

Offline

Re: Help with M

Sort of like using NextPrime.

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

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

anonimnystefy
Real Member

Online

Re: Help with M

I still do not get it.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

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

bobbym

Offline

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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

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

anonimnystefy
Real Member

Online

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.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#40 2013-07-07 11:01:07

bobbym

Offline

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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#41 2013-07-07 13:12:05

anonimnystefy
Real Member

Online

Re: Help with M

No?

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#42 2013-07-07 14:49:50

Agnishom
Real Member

Offline

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'
'The whole person changes, why can't a habit?' -Alokananda

#43 2013-07-07 15:23:20

anonimnystefy
Real Member

Online

Re: Help with M

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

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#44 2013-07-07 17:16:36

bobbym

Offline

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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#45 2013-07-07 17:49:44

Agnishom
Real Member

Offline

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'
'The whole person changes, why can't a habit?' -Alokananda

#46 2013-07-07 17:54:24

bobbym

Offline

Re: Help with M

I remember that problem.

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#47 2013-07-07 19:10:29

anonimnystefy
Real Member

Online

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?

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

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

bobbym

Offline

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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.