Cops' thread
In this thread, your task is to make a recursion-based program/function to generate any integer series. Robbers will try and find a shorter non-recursive solution over in the Robbers' thread.
Challenge synopsis
In many languages, recursive functions can significantly simplify a programming task. However, the syntax overhead for a proper recursion may limits its usability in code-golf.
The cops will create a program or function taking a single integer n
, which will generate the first n
entries of an integer series, using only recursion1. They should also make sure there is a shorter nonrecursive way to generate the sequence in order to mark their entry as safe.
The robbers will try to find a shorter program or function in the same language, generating the same integer series, using no recursion2.
If the cops' submission is not cracked within ten days (240 hours), the cop will prove it was in fact possible to have a shorter non-recursive approach by revealing their own solution. They may then mark their submission as safe.
The winner of the cops challenge will be the shortest (according to code-golf) recursion-based submission marked safe.
The winner of the robbers challenge will be the robber who cracked the most solutions.
1: It only needs to be recursive in syntax; you don't need to worry about for example tail call optimization.
2: Again, non-recursive in syntax; so you can't post a recursive solution and claim its compiled to a loop thanks to tail call optimization.
Submission requirements
Each submission will take a single integer n
(zero- or one-based). The submission will then output or return the first n
entries of an integer series of choice. (note that this integer series must not depend on n
). The input and output method may differ between the recursive and non-recursive approach. The integer series may be any deterministic series with a length of at least 5. The series should be explained properly.
Your submission does not have to work for arbitrary large n
, but should work for at least n=5
. The non-recursive approach must be able to work up to at least the same n
as the recursive approach, or up to n=2^15-1
, whichever is smaller.
Recursion
For the sake of this challenge, recursion is defined as creating the desired sequence using a function (or function-like construct) that calls itself (or calls a sequence of functions that ends up calling itself; this includes constructs like the Y combinator). The recursion depth should go to infinity as n
goes to infinity. The non-recursive approach is anything that is not recursive.
for
is done by recursive behind, isfor
recursive or loop? \$\endgroup\$n
if it's theoretically correct, but it cannot be run due to time or memory constraints? \$\endgroup\$n=5
must be computed \$\endgroup\$xfor
is available through some kind of import?) so perhaps this language cannot compete. \$\endgroup\$