Menu
  • HOME
  • TAGS

How can I write a Collatz sequence with List::Gen?

perl,collatz,list-gen

Here is a workaround that tests the element for defined-ness to decide when to end the list. It requires modifying the iterator definition to populate an undef element immediately after it encounters a 1 in the chain: iterate{ $_ == 1 ? undef : $_%2 ? 3*$_+1 : $_/2 }->from(...