Move History

Fork Selected
  • 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 be O(depth * vals), however we find that depth = 10, vals = 1000 is very fast, depth = 100, vals = 100 is somewhat slow, and depth = 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