Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge: Algorithms having only one line of code.
#32
Quote:Sorry, LooseCaboose, but this challenge is for Basic programs exclusively.

Oh well, I was just being pedantic because your rules don't state what langauge I have to write in. I have tested the code an it does work.

Like I said, its really hard to write one line algorithms in basic because all of the constructs (if, while, select, etc) require more than one line. Na_th_an's modulo counter was cool and Oracle's bit flip thing was neat, but as I said before the following works almost as well for flipping between an on and off state:
Code:
x = NOT x
The advantage of Oracle's approach is that any non-zero value will be flipped to zero, whereas my example flips between x and -x only.

Antoni's and Na_th_an's recursive functions are very clever, but don't actually obey your rules because they both use either the colon line separator or three lines with a proper function body, however seeing as you are accepting them heres one which calculates the sum of the values 1 to n:
Code:
function sum%(n as integer)
  if n = 1 then sum% = 1 else sum% = n + sum%(n - 1)
end function
esus saves.... Passes to Moses, shoots, he scores!
Reply


Messages In This Thread
To Oracle: 2nd look at your code. - by Moneo - 06-24-2003, 09:07 PM
To Seph and Agamemnus: - by Moneo - 06-24-2003, 09:17 PM
factorial. - by Agamemnus - 06-24-2003, 09:51 PM
To Agamemnus - by Moneo - 06-24-2003, 10:21 PM
To na_th_an: - by Moneo - 06-27-2003, 03:15 AM
ok, - by Agamemnus - 06-27-2003, 05:17 PM
To Oracle re Statlib - by Moneo - 06-27-2003, 10:39 PM
Re: To na_th_an: - by na_th_an - 06-28-2003, 01:14 AM
To LooseCaboose: - by Moneo - 06-28-2003, 03:08 AM
Challenge: Algorithms having only one line of code. - by LooseCaboose - 06-28-2003, 05:45 AM
Re: To Oracle re Statlib - by oracle - 06-28-2003, 05:50 AM
To Oracle: - by Moneo - 06-29-2003, 03:10 AM
To Ak00ma: - by Moneo - 06-30-2003, 03:39 AM
Power of 2 - by Moneo - 07-02-2003, 02:42 AM
To Antoni: - by Moneo - 07-02-2003, 03:03 AM
197 - by whitetiger0990 - 07-02-2003, 06:29 PM
To na_th_an re "replacement" logic: - by Moneo - 07-02-2003, 08:29 PM
Re ROUNDING using .5: - by Moneo - 07-02-2003, 08:47 PM
Re: Re ROUNDING using .5: - by Moneo - 03-20-2006, 06:19 AM
Challenge: Algorithms having only one line of code. - by Anonymous - 03-29-2006, 10:09 PM
Challenge: Algorithms having only one line of code. - by Anonymous - 03-29-2006, 10:24 PM
Challenge: Algorithms having only one line of code. - by Anonymous - 03-29-2006, 10:52 PM
my one-liner - by neuro - 03-30-2006, 12:08 AM

Forum Jump:


Users browsing this thread: 3 Guest(s)