-
Description Builds a stack of
depth
generators, each incrementing a value starting at 0 by 1 before yielding.vals
number of items are then generated. Expected time complexity should beO(depth * vals)
, however we find thatdepth = 10, vals = 1000
is very fast,depth = 100, vals = 100
is somewhat slow, anddepth = 1000, vals = 10
is extremely slow (times out).Code USING: kernel math generators combinators.extras ; IN: example GEN: foo ( n -- gen ) [ [ 0 yield ] forever ] [ 1 - foo [ [ next 1 + yield ] keep ] forever drop ] if-zero ;
Test Cases USING: example tools.testest generators arrays ; IN: example.tests CONSTANT: depth 100 CONSTANT: vals 300 : run-tests ( -- ) "Example" describe#{ "test case" it#{ <{ depth foo vals take -> vals depth <array> }> }# }# ; MAIN: run-tests
Output:
-
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}