Coding Challenge #1
Moderators: jelco, bert_the_turtle, Chris, Icepick, Rkiver
-
Blasted heath
- level5

- Posts: 1292
- Joined: Sat Jul 12, 2003 2:29 pm
- Location: Scotland ©
- Contact:
I must admit - I didn't code this, since I didn't get the math about the happy numbers.
We aren't even close to this here, in 10th class (we started studying parabulas (sp?) only a month and a half ago, so what do you want?).
And another question - after the challenge is over, will you show the source codes of the winners (if they won't mind, of course)?
We aren't even close to this here, in 10th class (we started studying parabulas (sp?) only a month and a half ago, so what do you want?).
And another question - after the challenge is over, will you show the source codes of the winners (if they won't mind, of course)?
-
Long Shoota
- level4

- Posts: 896
- Joined: Wed Feb 27, 2002 3:47 pm
- Location: In CybarSpace
- Contact:
-
Blasted heath
- level5

- Posts: 1292
- Joined: Sat Jul 12, 2003 2:29 pm
- Location: Scotland ©
- Contact:
I didn't know what happy numbers were either... there's nothing hard about them.
I'll post a link to this script what I wrote here, 'cos there's no way of stealing the code, you filthy theives. (Not that you'd want to anyway...)
http://www.ecowonline.co.uk/misc/happynumbers.php
I'll post a link to this script what I wrote here, 'cos there's no way of stealing the code, you filthy theives. (Not that you'd want to anyway...)
http://www.ecowonline.co.uk/misc/happynumbers.php
Blasted heath
- NeoThermic
- Introversion Staff

- Posts: 6256
- Joined: Sat Mar 02, 2002 10:55 am
- Location: ::1
- Contact:
Long Shoota wrote:What's hard to get about the maths?
You take a number, say 7
You square 7
7^2 = 49
You square each digit of the number
4^2 = 16
9^2 = 81
You add the numbers
16 + 81 = 97
You repeat the proceedure until the number reaches 1 (if it ever does).
Er... you're missing something. I think quite a few of you might of. If it never reaches 1, it repeats a number in the series periodically. So you will need to store all the calculations you've done, and check against that as well as against 1. If it repeats without hitting 1, its not a Happy Number.
NeoThermic
-
Disco Stuie_uplink
- level3

- Posts: 343
- Joined: Wed Nov 19, 2003 8:40 pm
- Location: Sheffield, England
- Contact:
Forgive me for being dumb (and I really think I am being so) but if you are following the procedure above, of
are you then squaring 9 and squaring 7, then adding 81 to 49; or, are you squaring 97, then squaring the digits of that answer?
And, in any case, I don't quite see how you can end up with 1 at any time - if you are always adding integer squares to each other, you are always going to have to have >2 as an answer (no two integers add to make 1, is what I mean). Explanation?
Long Shoota wrote:What's hard to get about the maths?
You take a number, say 7
You square 7
7^2 = 49
You square each digit of the number
4^2 = 16
9^2 = 81
You add the numbers
16 + 81 = 97
You repeat the proceedure until the number reaches 1 (if it ever does).
are you then squaring 9 and squaring 7, then adding 81 to 49; or, are you squaring 97, then squaring the digits of that answer?
And, in any case, I don't quite see how you can end up with 1 at any time - if you are always adding integer squares to each other, you are always going to have to have >2 as an answer (no two integers add to make 1, is what I mean). Explanation?
-
Long Shoota
- level4

- Posts: 896
- Joined: Wed Feb 27, 2002 3:47 pm
- Location: In CybarSpace
- Contact:
-
Blasted heath
- level5

- Posts: 1292
- Joined: Sat Jul 12, 2003 2:29 pm
- Location: Scotland ©
- Contact:
Disco Stuie wrote:Forgive me for being dumb (and I really think I am being so) but if you are following the procedure above, ofLong Shoota wrote:What's hard to get about the maths?
You take a number, say 7
You square 7
7^2 = 49
You square each digit of the number
4^2 = 16
9^2 = 81
You add the numbers
16 + 81 = 97
You repeat the proceedure until the number reaches 1 (if it ever does).
are you then squaring 9 and squaring 7, then adding 81 to 49; or, are you squaring 97, then squaring the digits of that answer?
And, in any case, I don't quite see how you can end up with 1 at any time - if you are always adding integer squares to each other, you are always going to have to have >2 as an answer (no two integers add to make 1, is what I mean). Explanation?
Example: 68 is a happy number, its digits squares add up to 100, 1^2 + 0^2 + 0^2 = 1
You are doing the same as you did to the first number to the number it produced.
Blasted heath
-
Disco Stuie_uplink
- level3

- Posts: 343
- Joined: Wed Nov 19, 2003 8:40 pm
- Location: Sheffield, England
- Contact:
-
Long Shoota
- level4

- Posts: 896
- Joined: Wed Feb 27, 2002 3:47 pm
- Location: In CybarSpace
- Contact:
-
Disco Stuie_uplink
- level3

- Posts: 343
- Joined: Wed Nov 19, 2003 8:40 pm
- Location: Sheffield, England
- Contact:
-
Blasted heath
- level5

- Posts: 1292
- Joined: Sat Jul 12, 2003 2:29 pm
- Location: Scotland ©
- Contact:
-
Stewsburntmonkey
- level5

- Posts: 11553
- Joined: Wed Jul 10, 2002 7:44 pm
- Location: Nashville, TN
- Contact:
Who is online
Users browsing this forum: No registered users and 19 guests

