Stewsburntmonkey wrote:It is funny since you can do the whole sum of squares in one line of Perl.
You can do anything in one line of Perl.
Though I assume you mean 80 characters and not one instruction
Moderators: jelco, bert_the_turtle, Chris, Icepick, Rkiver
Stewsburntmonkey wrote:It is funny since you can do the whole sum of squares in one line of Perl.

ODDin wrote:Oh boy, you did it in VB.net...
What makes it a little bit hard for me to get, from the depths of my VB6. But I think I got the general idea.
Only few things I totally can't get:
1) You can condition a definition of a variable? Neat.
2) What do the "New String" and "New Ineger" things do, exactly? I know that in VB.net even strings and integers are considered objects, but how does that work?
3) WHY, oh WHY did you use recursion?
Code: Select all
$apptype console
app.icon = "iris.ico"
defint tempval, ctr, itercnt
defstr number, tempnum, history
cls
input "Enter a number: "; number
tempnum = number
history = number + "."
do
inc(itercnt)
tempval = 0
for ctr = 1 to tempnum.length
if val(mid$(tempnum, ctr, 1) > 0 then
tempval = tempval + val(mid$(tempnum, ctr, 1)^2
end if
next
tempnum = str$(tempval)
number = tempnum + "."
if instr(history, number) then
print left$(history, instr(history, ".", 0)); " is not a happy number."
pause
application.terminate
else
history = history + number
end if
print "Iteration "; str$(itercnt); " = "; tempnum
loop until tempval = 1
print left$(history, instr(history, ".", 0)); " is a happy number!"
pause
end

Darksun wrote:.
I'm going to give a week for entries, but if you don't think that is long enough, tell me and I may extend it.
Good luck.

Darksun wrote:OK, I have the results.
Neothermic, Blasted Heath, Iris, coolsi, Stewsburntmonkey and Fartan and einstein all produced a solution, and get 1 point. Llamaboy was busy, and entered two different solutions (one in VB and the other in Java) so he gets 2 points.
Now, bonus points -
I liked coolsi for his unique approach - an IRC bot. That earns 1 bonus points.
I thought Stewsburntmonkey's solution (written in perl) was very neat, so that earns 3 bonus points
But the solution that impressed me most was one by Fartan (an old forumer who never posted much, but is apparantly still around), written in PureBasic ASM, for which he earns the grand prize of 5 bonus points.
Everyone, give yourself a pat on the back. I'll be posting another (harder!) challenge soon. I'm not posting the solutions - I'll leave that up to entrants. If you really want to see how someone solved the challenge, email them and ask them nicely, I'm sure they'll send you a copy of their code.

Iris wrote:' quick & dirty solution in HotBasic console mode...
'[/code]Code: Select all
$apptype console
app.icon = "iris.ico"
defint tempval, ctr, itercnt
defstr number, tempnum, history
cls
input "Enter a number: "; number
tempnum = number
history = number + "."
do
inc(itercnt)
tempval = 0
for ctr = 1 to tempnum.length
if val(mid$(tempnum, ctr, 1) > 0 then
tempval = tempval + val(mid$(tempnum, ctr, 1)^2
end if
next
tempnum = str$(tempval)
number = tempnum + "."
if instr(history, number) then
print left$(history, instr(history, ".", 0)); " is not a happy number."
pause
application.terminate
else
history = history + number
end if
print "Iteration "; str$(itercnt); " = "; tempnum
loop until tempval = 1
print left$(history, instr(history, ".", 0)); " is a happy number!"
pause
end
Iris wrote:' quick & dirty solution in HotBasic console mode...
'[/code]Code: Select all
$apptype console
app.icon = "iris.ico"
defint tempval, ctr, itercnt
defstr number, tempnum, history
cls
input "Enter a number: "; number
tempnum = number
history = number + "."
do
inc(itercnt)
tempval = 0
for ctr = 1 to tempnum.length
if val(mid$(tempnum, ctr, 1) > 0 then
tempval = tempval + val(mid$(tempnum, ctr, 1)^2
end if
next
tempnum = str$(tempval)
number = tempnum + "."
if instr(history, number) then
print left$(history, instr(history, ".", 0)); " is not a happy number."
pause
application.terminate
else
history = history + number
end if
print "Iteration "; str$(itercnt); " = "; tempnum
loop until tempval = 1
print left$(history, instr(history, ".", 0)); " is a happy number!"
pause
end
Iris wrote:' quick & dirty solution in HotBasic console mode...
'[/code]Code: Select all
$apptype console
app.icon = "iris.ico"
defint tempval, ctr, itercnt
defstr number, tempnum, history
cls
input "Enter a number: "; number
tempnum = number
history = number + "."
do
inc(itercnt)
tempval = 0
for ctr = 1 to tempnum.length
if val(mid$(tempnum, ctr, 1) > 0 then
tempval = tempval + val(mid$(tempnum, ctr, 1)^2
end if
next
tempnum = str$(tempval)
number = tempnum + "."
if instr(history, number) then
print left$(history, instr(history, ".", 0)); " is not a happy number."
pause
application.terminate
else
history = history + number
end if
print "Iteration "; str$(itercnt); " = "; tempnum
loop until tempval = 1
print left$(history, instr(history, ".", 0)); " is a happy number!"
pause
end
Users browsing this forum: No registered users and 15 guests