Skip to content

Instantly share code, notes, and snippets.

@Steven24K
Created January 14, 2026 13:46
Show Gist options
  • Select an option

  • Save Steven24K/fa28d8da224f49ad86ec4c3022b96086 to your computer and use it in GitHub Desktop.

Select an option

Save Steven24K/fa28d8da224f49ad86ec4c3022b96086 to your computer and use it in GitHub Desktop.
# Higher order function and recursive combined.
count = lambda x, counter, func: counter == x if counter else count(x, func(counter), func)
# some variations using the above function
increment = lambda x: x + 1
increment_by_two = lambda x: x + 2
double = lambda x: x * 2
decrement_by_x = lambda x: lambda y: x - y
decrement = lambda x: decrement_by_x(x)(1)
decrement_by_two = lambda x: decrement_by_x(x)(2)
count_to = lambda to, counter: count(to, counter, increment)
count_double = lambda to, counter: count(to, counter, increment_by_two)
multiply = lambda to, counter: count(to, counter, double)
count_down = lambda min, counter: count(min, counter, decrement)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment