You can simplify F22 as follows:
F23=: [: {."1 (+/ , {.)^:(([: < ])`(1 0"_))
F23 8
1 1 2 3 5 8 13 21
This is using the gerund form of Power u^:n to create this statement:
([: {."1 (+/ , {.)^:(<8)) 1 0
1 1 2 3 5 8 13 21
On Tue, Feb 18, 2014 at 10:17 PM, Linda Alvord <[email protected]>wrote:
> I've been trying to understand and simplify a function for the Fibonacci
> series.
>
> F22=:E=:[:{."1 D=: (C=:+/,{.)^:B=:(A=:[:<])`(1 0"_)
>
> F22 8
> 1 1 2 3 5 8 13 21
>
> A 8
> --┐
> │8│
> L--
> C 8
> 8 8
> D 8
> 1 0
> 1 1
> 2 1
> 3 2
> 5 3
> 8 5
> 13 8
> 21 13
> E 8
> 1 1 2 3 5 8 13 21
>
> This has worked. But:.
>
> B 8
> |syntax error
> | B 8
>
> B
> -------------T-------------------┐
> │--T--------┐│--T---------------┐│
> ││3│---T-T-┐│││"│--------T-----┐││
> ││ ││[:│<│]││││ ││--T---┐│--T-┐│││
> ││ │L--+-+--│││ │││0│1 0│││0│_││││
> │L-+---------││ ││L-+----│L-+--│││
> │ ││ │L-------+------││
> │ │L-+----------------│
> L------------+--------------------
>
>
> F22=:E=:[:{."1 D=: (C=:+/,{.)^:B=:(A=:[:<])`(1 0"_)
>
> F22 8
> 1 1 2 3 5 8 13 21
>
> A 8
> --┐
> │8│
> L--
> C 8
> 8 8
> D 8
> 1 0
> 1 1
> 2 1
> 3 2
> 5 3
> 8 5
> 13 8
> 21 13
> E 8
> 1 1 2 3 5 8 13 21
>
> B 8
> |syntax error
> | B 8
>
> B
> -------------T-------------------┐
> │--T--------┐│--T---------------┐│
> ││3│---T-T-┐│││"│--------T-----┐││
> ││ ││[:│<│]││││ ││--T---┐│--T-┐│││
> ││ │L--+-+--│││ │││0│1 0│││0│_││││
> │L-+---------││ ││L-+----│L-+--│││
> │ ││ │L-------+------││
> │ │L-+----------------│
> L------------+--------------------
>
> 5!:2 <'B'
> -------------T-------------------┐
> │--T--------┐│--T---------------┐│
> ││3│---T-T-┐│││"│--------T-----┐││
> ││ ││[:│<│]││││ ││--T---┐│--T-┐│││
> ││ │L--+-+--│││ │││0│1 0│││0│_││││
> │L-+---------││ ││L-+----│L-+--│││
> │ ││ │L-------+------││
> │ │L-+----------------│
> L------------+--------------------
>
>
> 5!:4 <'B'
> -- (<(<,'3'),<;:'[:<]'),<(<,'"'),<(<(,'0');1 0),<(,'0');_
>
> However it looks like I expect here. Something seems wrong.
>
> 5!:4 <'F22'
> -- [:
> │ -- {.
> +- " --+- 1
> │ -- / --- +
> --+ -----+- ,
> │ │ L- {.
> │ │ -- [:
> L- ^: -+ ------+- <
> │ │ L- ]
> L----+
> │ -- 1 0
> L- " -+- _
>
> Linda
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm