Questions tagged [recursion]
For challenges involving recursive functions, or functions or programs calling itself, directly or indirectly.
41 questions
21
votes
12
answers
1k
views
What's left after repeatedly removing palindromes
Sometimes a string has buried palindromes in it:
hallolilah contains lol.
And if we took out ...
7
votes
2
answers
596
views
Situations when recursion helps [closed]
Recursion is actually quite powerful, sometimes its doesn't look like that child problem of itself exist, but recursion is just helpful.
One case per answer.
-3
votes
8
answers
1k
views
Number of cigarettes that can be made from a given number of butts
Assumption
A cigarette can be made by combining four cigarette butts. Cigarette butts last infinitely until smoked.
Explanation
Say you have 31 butts. That means, you can make 7 cigarettes from 28 ...
18
votes
7
answers
2k
views
The TAK function
The TAK function is defined as follows for integers \$x\$, \$y\$, \$z\$:
$$
t(x, y, z) = \begin{cases}
y, & \text{if $x \le y$} \\
t(t(x-1,y,z), t(y-1,z,x), t(z-1,x,y)), & \text{otherwise}
\...
1
vote
0
answers
229
views
DP approach gives TLE [closed]
There is a question to basically find the largest sum in an array, such that no two elements are chosen adjacent to each other. The concept is to recursively calculate the sum, while considering and ...
13
votes
25
answers
2k
views
Output the length of (the length plus a message) [duplicate]
The task is simple. You're given an arbitrary string message. Return that message prefixed with a number, such that the length of that number plus the message equals the number. In other words, the ...
5
votes
6
answers
394
views
AoCG2021 Leftover: Recursive Combat
This challenge is one of the two challenges which were planned for Advent of Code Golf 2021, but didn't fit into the 25-day schedule.
Related to AoC2020 Day 22, Part 2.
Combat is a simple two-player ...
17
votes
31
answers
2k
views
Nesting list with a value repeated `n` amount of times
Given the input of n and value. The code is supposed to nest the single element list with ...
22
votes
9
answers
1k
views
Unicode T-square
Challenge
Create a function or program that, when given an integer size, behaves the following way:
If size is equal to 1, ...
-8
votes
3
answers
363
views
Generate a RecursionError [closed]
Write the shortest possible code cause an error due to recursion too deep
Example error in python
RecursionError: maximum recursion depth exceeded
Example error in ...
9
votes
1
answer
305
views
Branch Out - Monkey Edition
The Monkey has swung home to find his tree all in pieces.
He likes order and scoops up all his 'tree-parts' and sets them out in 3 groups.
The Monkey's ...
18
votes
14
answers
3k
views
Visualize a Recursive Acronym
Background
Famously, the acronym GNU stands for GNU's Not Unix. 1
It's recursive because, after expanding it once, it still ...
47
votes
76
answers
8k
views
Pointlessly make your way down the alphabet
Disclaimer: This challenge inspired by me spending the morning debugging recursive functions, which have been frying my brain a little.
Here's an example of recursion, from a letter, we keep going to ...
32
votes
31
answers
9k
views
1, 2, 4, 8, 16, ... 33?
Challenge
Write a function/program that outputs either the n'th element, or the first n elements, in the well known number ...
5
votes
2
answers
463
views
Golf my iteration function
Here is my ungolfed Ruby code for a function I want to try and golf:
...