Coding Challenge #1

Anything and Everything about Uplink

Moderators: jelco, bert_the_turtle, Chris, Icepick, Rkiver

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

Postby Blasted heath » Sun Oct 17, 2004 9:42 pm

Whee! I now thoughly despise happy numbers, but it's done now, yay!
Blasted heath
ODDin
level5
level5
Posts: 2521
Joined: Fri Jul 04, 2003 10:44 pm
Location: Haifa, Israel
Contact:

Postby ODDin » Sun Oct 17, 2004 9:51 pm

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)?
Long Shoota
level4
level4
Posts: 896
Joined: Wed Feb 27, 2002 3:47 pm
Location: In CybarSpace
Contact:

Postby Long Shoota » Sun Oct 17, 2004 10:16 pm

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).
Blasted heath
level5
level5
Posts: 1292
Joined: Sat Jul 12, 2003 2:29 pm
Location: Scotland ©
Contact:

Postby Blasted heath » Sun Oct 17, 2004 10:55 pm

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
Blasted heath
User avatar
NeoThermic
Introversion Staff
Introversion Staff
Posts: 6256
Joined: Sat Mar 02, 2002 10:55 am
Location: ::1
Contact:

Postby NeoThermic » Sun Oct 17, 2004 10:59 pm

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
ODDin
level5
level5
Posts: 2521
Joined: Fri Jul 04, 2003 10:44 pm
Location: Haifa, Israel
Contact:

Postby ODDin » Sun Oct 17, 2004 11:18 pm

Oh. Then it was just the page I tried that put it in a way too complicated way...
Ok.
But I don't know whether I'll have time to code that in the near future...
Hmm, maybe I'll just pass the 1st challenge then.
Disco Stuie_uplink
level3
level3
Posts: 343
Joined: Wed Nov 19, 2003 8:40 pm
Location: Sheffield, England
Contact:

Postby Disco Stuie_uplink » Sun Oct 17, 2004 11:26 pm

Forgive me for being dumb (and I really think I am being so) but if you are following the procedure above, of

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
level4
Posts: 896
Joined: Wed Feb 27, 2002 3:47 pm
Location: In CybarSpace
Contact:

Postby Long Shoota » Sun Oct 17, 2004 11:31 pm

Square 9 then 7, then add them.

So what about if a number becomes 10? Does that also add to go higher than 2?
Blasted heath
level5
level5
Posts: 1292
Joined: Sat Jul 12, 2003 2:29 pm
Location: Scotland ©
Contact:

Postby Blasted heath » Sun Oct 17, 2004 11:33 pm

Disco Stuie wrote:Forgive me for being dumb (and I really think I am being so) but if you are following the procedure above, of

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?


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
level3
Posts: 343
Joined: Wed Nov 19, 2003 8:40 pm
Location: Sheffield, England
Contact:

Postby Disco Stuie_uplink » Sun Oct 17, 2004 11:33 pm

*me blushes*
Long Shoota
level4
level4
Posts: 896
Joined: Wed Feb 27, 2002 3:47 pm
Location: In CybarSpace
Contact:

Postby Long Shoota » Sun Oct 17, 2004 11:36 pm

*me mocks*
Disco Stuie_uplink
level3
level3
Posts: 343
Joined: Wed Nov 19, 2003 8:40 pm
Location: Sheffield, England
Contact:

Postby Disco Stuie_uplink » Sun Oct 17, 2004 11:38 pm

*me decides that now is not the time to mention that he is doing A-Level Further Maths...*

*me goes and hides in a corner, slowly counting 1 to 10, over and over and over*
Darksun
level5
level5
Posts: 6461
Joined: Sat Dec 07, 2002 7:08 pm
Location: 127.0.0.1

Postby Darksun » Mon Oct 18, 2004 9:03 am

My maths teacher wrote a program to do this, that's why I decided to make this challenge :P

And Blasted heath, could you email me the source code for your script?
Blasted heath
level5
level5
Posts: 1292
Joined: Sat Jul 12, 2003 2:29 pm
Location: Scotland ©
Contact:

Postby Blasted heath » Mon Oct 18, 2004 2:36 pm

I did yesterday...
Blasted heath
Stewsburntmonkey
level5
level5
Posts: 11553
Joined: Wed Jul 10, 2002 7:44 pm
Location: Nashville, TN
Contact:

Postby Stewsburntmonkey » Tue Oct 19, 2004 5:12 am

The solution is actually rather trivial in Perl (yay hashes). :)

Return to “General”

Who is online

Users browsing this forum: No registered users and 19 guests