Coding Challenge #1
Moderators: jelco, bert_the_turtle, Chris, Icepick, Rkiver
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
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
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
Well, that function would return an array of Chars, so you just have an array to accept the return value, as so:
Then, chars would be an array of Chars containing the characters found in the text field.
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.
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 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.
Who is online
Users browsing this forum: No registered users and 19 guests




