Skip to content

Instantly share code, notes, and snippets.

@ncalm
Created August 31, 2024 19:58
Show Gist options
  • Save ncalm/48b96ac45685a7897fdf0a7336b2e96b to your computer and use it in GitHub Desktop.
Save ncalm/48b96ac45685a7897fdf0a7336b2e96b to your computer and use it in GitHub Desktop.
LAMBDA for generating an arbitrary skipped list of integers
/*
Return every 'x' integers no larger than n, optionally skipping the first 'skip'
integers in such a sequence
e.g.
EveryXtoN(10, 2) = {1; 3; 5; 7; 9}
EveryXtoN(10, 2, 1) = {3; 5; 7; 9}
EveryXtoN(10, 2, 2) = {5; 7; 9}
EveryXtoN(10, 3) = {1; 4; 7; 10}
EveryXtoN(10, 3, 1) = {4; 7; 10}
EveryXtoN(10, 3, 2) = {7; 10}
*/
EveryXtoN = LAMBDA(n, x, [skip],
SEQUENCE(CEILING.MATH((n - (x*skip)) / x), , (x*skip)+1, x)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment