bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] Fibonacci sequence


From: David Lamkins
Subject: Re: [Bug-apl] Fibonacci sequence
Date: Thu, 3 Jul 2014 10:11:43 -0700

Here's a formulation using GNU APL. I was thinking in terms of d-fns when I wrote this. It uses simulated tail recursion. (I alter the args just before jumping to the function entry point.) If you actually wrote this using a d-fn, fibgen would be a local function of fibupto.

⍝!

∇z←seq fibgen limit
 loop:
  z←seq
  →(limit<+/¯2↑seq)/0
  seq←seq,+/¯2↑seq
  →loop


∇z←fibupto limit
  seq←1 1
  z←seq fibgen limit





On Thu, Jul 3, 2014 at 9:50 AM, Juergen Sauermann <address@hidden> wrote:
Hi,

how about this:

      F←{ ⍎ ↑(↑⍵>¯1↑⍵) ↓(1≠⍴,⍵) ↓'F ⍵,1 1' '¯1↓1↓⍵' 'F ⍵, +/¯2↑⍵' }

      F 44
1 1 2 3 5 8 13 21 34

/// Jürgen




On 07/03/2014 06:39 PM, Elias Mårtenson wrote:

I am actually trying to do it with GNU APL. I just got the challenges from Dyalog. :-)

I'll send you a link to it when I'm in front of a computer.

Regards,
Elias

On 4 Jul 2014 00:32, "David Lamkins" <address@hidden> wrote:
I assume you're trying to do this with Dyalog d-fns.

You need a generator that can produce the next number in the sequence, and a test to check whether you're done.You can run the generator and test in a tail-recursive loop while accumulating the results.

I don't know that you'd need to use local functions, but don't forget that's available.

From: "Elias Mårtenson" <address@hidden>
To: "address@hidden" <address@hidden>
Cc: 
Date: Thu, 3 Jul 2014 22:12:50 +0800
Subject: [Bug-apl] Fibonacci sequence
I was playing around with solving the Dyalog challenge, and I found them pretty easy with the exception of one.

The goal was to write a lambda function that given a single integer, returns a list of the Fibonacci series up to that number.

The only way I can think of solving it is by using a full function and a loop. That can't possibly be the easiest way.

Any suggestions?



--




--
"The secret to creativity is knowing how to hide your sources."
   Albert Einstein


http://soundcloud.com/davidlamkins
http://reverbnation.com/lamkins
http://reverbnation.com/lcw
http://lamkins-guitar.com/
http://lamkins.net/
http://successful-lisp.com/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]