You are not logged in.

- Topics: Active | Unanswered

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

M is Mathematica.

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

Why not Maxima?

By the way, you also asked whether you can call bobbym as 'M'

'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

Offline

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

Let me introduce you to the nomenclature:

M-Mathematica

m-bobbym and his two male predecessors.

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

Ok

Why not Maxima?

'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

Offline

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

Because it is the currently used nomenclature.

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: 90,886

In order to design an algorithm I still need an answer to the question of what numbers are permitted.

**In mathematics, you don't understand things. You just get used to them.**

Offline

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

He answered that on the previous page...

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,886

It might be there and then again it might not.

**In mathematics, you don't understand things. You just get used to them.**

Offline

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

Agnishom wrote:

Any thing .... Just liike bobbym does in Add 99 and post forever

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,886

Then I might suggest a greedy algorithm.

**In mathematics, you don't understand things. You just get used to them.**

Offline

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

anonimnystefy wrote:

See this: http://www.alpertron.com.ar/4SQUARES.HTM

Have you checked this link? It can be done by recursion.

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,886

Recursion: anything done by it can always be done better in another way.

**In mathematics, you don't understand things. You just get used to them.**

Offline

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

Maybe, but it's a start. And it is definitely better than brute force.

Speaking of recursion, does M do memoization while running a recursion?

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,886

Yes, see the examples on Fibonacci numbers I think.

I am going offline for a while.

**In mathematics, you don't understand things. You just get used to them.**

Offline

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

Okay, see you later.

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

Offline

Hm, A greedy algorithm is like what?

'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

Offline

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

Hi bobbym

If we are working in a language which does memoization in recursions, recursion will suffice.

If not, a DP type solution will do.

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,886

Hi anonimnystefy;

If not, a DP type solution will do

DP?

Hi Agnishom;

Basically, take the biggest square you can out each time.

**In mathematics, you don't understand things. You just get used to them.**

Offline

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

Dynamic programming. Basically, we will do all values from 1 to n, and it will be O(n) because we can calculate a value in O(1) when we have the previous values.

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,886

Because he is allowing multiplicities and zero he is guaranteeing that every number is the sum of 4 squares.

17 = 4^2 + 1^2 + 0^2 + 0^2

17 = 3^2 + 2^2 + 2^2 + 0^2

**In mathematics, you don't understand things. You just get used to them.**

Offline

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

I was suggesting an algorithm in post #45. I do not know how you got anything else from that post...

Your greedy algorithm doesn't work for 1022 (and probably many more numbers).

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,886

Not so!

Done by hand!

**In mathematics, you don't understand things. You just get used to them.**

Offline

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

Yes, but that is not what your algorithm gets. The largest square below 1022 is 961=31^2.

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

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,886

You do not have to stop there. When 31 does not work you try 30 which does. Algorithm is very fast.

**In mathematics, you don't understand things. You just get used to them.**

Offline

I see, can you explain the structure of your greedy algorithm more clearly?

'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

Offline