Coding Challenge #1

Anything and Everything about Uplink

Moderators: jelco, bert_the_turtle, Chris, Icepick, Rkiver

einstein
level5
level5
Posts: 1463
Joined: Mon Mar 04, 2002 5:23 pm
Location: Scotland

Postby einstein » Wed Oct 20, 2004 3:22 am

http://www.hostultra.com/~andrew1572/number.html is my php attempt...

not everything i want implemented yet tho... still to implement a happy/sad face output screen, a check that it is a number you enter in the box, and many other must have features...

this is v.0.8... which took about 5 minutes!
Darksun
level5
level5
Posts: 6461
Joined: Sat Dec 07, 2002 7:08 pm
Location: 127.0.0.1

Postby Darksun » Wed Oct 20, 2004 9:53 am

3213252154754547453644567845678765456789 is a happy number!

Yay :P
User avatar
Iris
level5
level5
Posts: 2423
Joined: Wed Apr 09, 2003 6:15 am
Location: Land of the Morning Calm

Postby Iris » Wed Oct 20, 2004 11:37 am

Hi Darksun,

I've sent you my solution to your challenge, written in HotBasic. Won't hog your system, it's only 7kb (without my pixie icon ^^). Check it out, and tell me what you think. (took 7 minutes of my working time to figure that, there goes my coffee break....)

Iris
Image
elDiablo
level5
level5
Posts: 3111
Joined: Thu Mar 14, 2002 12:23 pm
Location: London, UK

Postby elDiablo » Wed Oct 20, 2004 11:56 am

Well, just saw this. And as LlamaBoy got Java this time, I wont bother :P Damn you Llama!

Shotgun Java for #2! ;)
We dont stop playing cos we get old... We get old cos we stop playing.
Darksun
level5
level5
Posts: 6461
Joined: Sat Dec 07, 2002 7:08 pm
Location: 127.0.0.1

Postby Darksun » Wed Oct 20, 2004 12:05 pm

Well, I have 3 PHP implementations, so there's no reason I can't have 2 java implementations, just do it better than LLamaboy :P
User avatar
LLamaBoy
level5
level5
Posts: 1627
Joined: Sun Aug 18, 2002 12:18 pm
Location: Cyprus
Contact:

Postby LLamaBoy » Wed Oct 20, 2004 12:49 pm

But, but... That'd be impossible for him!

Also, do I get bonus points for doing 2 implementations?
Darksun
level5
level5
Posts: 6461
Joined: Sat Dec 07, 2002 7:08 pm
Location: 127.0.0.1

Postby Darksun » Wed Oct 20, 2004 12:52 pm

Yes, yes you do
coolsi
level5
level5
Posts: 3990
Joined: Wed Apr 10, 2002 6:46 pm

Postby coolsi » Wed Oct 20, 2004 4:53 pm

I'd do it in Eggdrop TCL (a happy number bot!) but I have no time at all this week...
Nakatomi is coming
einstein
level5
level5
Posts: 1463
Joined: Mon Mar 04, 2002 5:23 pm
Location: Scotland

Postby einstein » Wed Oct 20, 2004 7:45 pm

v0.9 is up...

New Features:
* properly deals with "0"
* checks that the user entered a number only

http://www.hostultra.com/~andrew1572/happy.php

edit - changed into only one file rather than the two file system before! Oh, and Darksun... do you want the new code or are you happy with having my simple implementation script (without frills...)

yet another edit - i've noticed an error in my implementation... it's also present in Blasted Heath's php implementation... i won't say what it is... cause well i wanna win! (even tho there is no prize.... :()

and again - my implementation has now been fixed to deal with the problem... which i may as well tell you is if a decimal number (e.g. 3.5) is entered it is treated as the number without the decimal there (e.g. 35)... my new implementation restricts the passing of anything other than an integer
camman977
level2
level2
Posts: 85
Joined: Wed Sep 29, 2004 10:45 pm
Location: Michigan, U.S.A.
Contact:

Postby camman977 » Thu Oct 21, 2004 12:00 am

ummm.....i havn't used vb in awhile and i was wondering if somebody could help me a little....how do i take a text box and make every character a different cariable or something like that?
Image
User avatar
LLamaBoy
level5
level5
Posts: 1627
Joined: Sun Aug 18, 2002 12:18 pm
Location: Cyprus
Contact:

Postby LLamaBoy » Thu Oct 21, 2004 12:10 am

textfield.Text.toCharArray() works, then you just access each character as a single element! :)
camman977
level2
level2
Posts: 85
Joined: Wed Sep 29, 2004 10:45 pm
Location: Michigan, U.S.A.
Contact:

Postby camman977 » Thu Oct 21, 2004 12:14 am

LLamaBoy wrote:textfield.Text.toCharArray() works, then you just access each character as a single element! :)

thanks but, is the array name in the parenthesis? and then how would i take and array and square each element? don't worry if you help me, you can even send source code for yours, i am not entering this one because i forgot everything! lol
Image
User avatar
LLamaBoy
level5
level5
Posts: 1627
Joined: Sun Aug 18, 2002 12:18 pm
Location: Cyprus
Contact:

Postby LLamaBoy » Thu Oct 21, 2004 12:19 am

Well, that function would return an array of Chars, so you just have an array to accept the return value, as so:

Code: Select all

Dim chars As Char() = textfield.Text.toCharArray()


Then, chars would be an array of Chars containing the characters found in the text field.
camman977
level2
level2
Posts: 85
Joined: Wed Sep 29, 2004 10:45 pm
Location: Michigan, U.S.A.
Contact:

Postby camman977 » Thu Oct 21, 2004 12:22 am

ok, thanks, ut i still dunno how to take that array and square every element and then do it again.... i am a total n00b programmer, sort of, i am just not usd to math related things, i always have made pranks to freak people out. lol. i had one that was called two choices, it would ask you if you wanted or c drive deleted or a virus loaded onto your system, and there was no way of exiting without restarting. when you chose one, it would act like it is doing it the shutdown your computer for effect. lol
Image
User avatar
Iris
level5
level5
Posts: 2423
Joined: Wed Apr 09, 2003 6:15 am
Location: Land of the Morning Calm

Postby Iris » Thu Oct 21, 2004 1:18 am

camman977 wrote:ok, thanks, ut i still dunno how to take that array and square every element and then do it again.... i am a total n00b programmer, sort of, i am just not usd to math related things, i always have made pranks to freak people out. lol. i had one that was called two choices, it would ask you if you wanted or c drive deleted or a virus loaded onto your system, and there was no way of exiting without restarting. when you chose one, it would act like it is doing it the shutdown your computer for effect. lol


camman977, it would be easier for you to treat each number as a string value and use mid$ to extract each number one by one, square it in the power of two, then add that value to increment a numeric variable. This numeric variable will hold the sum of all digits in the last number squared in the power of 2. No need to use arrays, you can just append the final value (in string form) to a string variable that holds the history of all values arrived at (You may use a separator character like '.' or '!' to segregate each value in the string). Then, a simple INSTR will let you know if that value has been arrived at before and tell you that the number is not a happy one.

Since you're a 'n00b' programmer (as you claim yourself to be), you might be happy to know that you can solve this without using recursions (ie. function calling itself over and over until it reaches the desired value), a simple DO..LOOP routine will do. Hope this helps.
Last edited by Iris on Thu Oct 21, 2004 1:23 am, edited 1 time in total.
Image

Return to “General”

Who is online

Users browsing this forum: No registered users and 19 guests