Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
23
Task/Flatten-a-list/8th/flatten-a-list.8th
Normal file
23
Task/Flatten-a-list/8th/flatten-a-list.8th
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
\ take a list (array) and flatten it:
|
||||
|
||||
: (flatten) \ a -- a
|
||||
(
|
||||
\ is it a number?
|
||||
dup >kind ns:n n:= if
|
||||
\ yes. so add to the list
|
||||
r> swap a:push >r
|
||||
else
|
||||
\ it is not, so flatten it
|
||||
(flatten)
|
||||
then
|
||||
drop
|
||||
) a:each drop ;
|
||||
|
||||
: flatten \ a -- a
|
||||
[] >r (flatten) r> ;
|
||||
|
||||
[[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
|
||||
dup . cr
|
||||
flatten
|
||||
. cr
|
||||
bye
|
||||
Loading…
Add table
Add a link
Reference in a new issue