Thread Rating:
• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Challenge: Algorithms having only one line of code. Moneo Posting Freak Posts: 1,956 Threads: 65 Joined: Jun 2003 06-26-2003, 09:06 PM Quote:HEY! NO FAIR! IT's THREE LINES OF CODE! Technically, you're right, but Antoni's approach still merits recognition within the constraints of this challange. Your approach also deserves merit for its simplicity, even though it needs the extra GOTO instruction to work. I recommend making it a little shorter as follows: Code:```REM 1 IF fact& = 2 THEN fact2& = fact2& * 2 ELSE fact2& = fact2& * fact&: fact& = fact& - 1: GOTO 1 1 IF fact& > 1 THEN fact2& = fact2& * fact&: fact& = fact& - 1: GOTO 1```***** Moneo Posting Freak Posts: 1,956 Threads: 65 Joined: Jun 2003 06-26-2003, 11:57 PM Quote:Well, in the line of Antoni's, here's my very own fibonnaci series callculator: Code:```FUNCTION fibonacci& (n&)    IF n& < 2 THEN fibonacci& = 1 ELSE fibonacci& = fibonacci&(n& - 1) + fibonacci&(n& - 2) END FUNCTION``` Excellent na-th-an! Here again we have a brilliant recursive function. How many of you know what a Fibonacci series is? It's a series where any number in the series is the sum of the two preceding numbers., i.e., 1,1,2,3,5,8,13 ..... What would you use a Fibonacci series for? What is a practical use? ***** na_th_an Posting Freak Posts: 6,419 Threads: 74 Joined: Mar 2002 06-27-2003, 12:53 AM Well, it is very used to teach recursion and algorithmics, but it came from a simple problem: Fibonacci wanted to determine the rate at which pairs of rabbits would reproduce. Info here : http://www.mcs.surrey.ac.uk/Personal/R.K...ml#Rabbits SCUMM (the band) on Myspace! ComputerEmuzone Games Studio underBASIC, homegrown musicians [img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i Moneo Posting Freak Posts: 1,956 Threads: 65 Joined: Jun 2003 06-27-2003, 03:15 AM I agree that Fibonacci first developed his famous series to see the reproduction rate of rabbits. But, what would I use this series for today in computer programming applications? I personally have only seen one practical use of the series, and that was for a polyphase merge sort used on an IBM mainframe with only 3 tape drives available. The Fibonacci series determined how many internally sorted "runs" were distributed onto each of the tapes, so that only one of the 3 tapes (the one with the least number of runs) had to be rewound at the end of a given sort pass. Polyphase merge sorts have become a popular academic topic. Many implementations using more than 3 tapes still continue to use the Fibonacci series. It works, although studies have shown that this series is not the most efficient for over 3 tapes. ***** oracle Posting Freak Posts: 3,343 Threads: 83 Joined: Mar 2003 06-27-2003, 12:57 PM I use the fibonacci series to test StatLib. Though that may not be useful in real life... StatLib nearly has negative and decimal support! (sorry, spamming...) The factorial method came up in my other challenge, the statistical one that started statlib off, that's why so many people have been repoducing it. I think only na_th_an should get the recognition for it, because he won. size=9]Oracle QBNZ | GeSHi - Generic Syntax Highlighter for PHP | PHPClasses[/size] LooseCaboose Senior Member Posts: 691 Threads: 5 Joined: Apr 2002 06-27-2003, 01:55 PM Basic is kinda hopeless for this task for all but the very simplest algorithms because even a loop construct requires more than one line: Code:`while condition : wend`Futhermore you cant make assignments within the condition part of a loop because Basic interprets this as a test for equality. So, seeing as your rules didn't actually specify that I have to write Basic code, heres a pseudo bubble sort in one line of Java or C++ code (Wont work in C because you arent allow to declare variables within the expression list of a for loop: Code:`for(int a[5]={2,4,3,5,1},int t,int i=0;i<4;i++){if(a[i]

Forum Jump:

Users browsing this thread: 1 Guest(s)