Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [recursion]

For challenges involving recursive functions, or functions or programs calling itself, directly or indirectly.

-4
votes
0answers
147 views

Recursive Multiplication [on hold]

Two kids stand over a board of 100 sweets, each with a number from 1-100 drawn on it. They try to eat as many of them as they can and keeping a track of the running total. For example if a kid eats ...
3
votes
2answers
206 views

Algorithm to print the Minimum number of adjacent character swaps necessary to remove all instances of “VK” in a given string?

For example, how many adjacent swaps are at least needed to convert some string such as BVVKCV to one without any instances of VK...
9
votes
12answers
1k views

Different combinations possible

Problem Given a value n, imagine a mountain landscape inscribed in a reference (0, 0) to (2n, 0). There musn't be white spaces between slopes and also the mountain musn't descend below the x axis. ...
6
votes
12answers
607 views

Recursively count lines of code, excluding empty lines and comments

Requirement: Write a program (in any language) that counts the number of lines of code in files matching *.sh in the directory tree starting from the directory that ...
17
votes
12answers
514 views

Generalized Cantor set segment lengths

Problem Let's define a generalized Cantor set by iteratively deleting some rational length segments from the middle of all intervals that haven't yet been deleted, starting from a single continuous ...
21
votes
16answers
5k views

One More Program and I'm Out!

Given a positive integer nesting level n and string s of printable ascii characters( to <...
26
votes
15answers
3k views

Многочлены Чебышёва (Chebyshev Polynomials)

Chebyshev Polynomials are a family of orthogonal polynomials that pop up in all kinds of places in math, and they have a lot of quite interesting properties. One characterization of them is that they ...
12
votes
14answers
505 views

Repeated reciprocal

What you need to do is create a function/program that takes a decimal as input, and outputs the result of repeatedly taking the reciprocal of the fractional part of the number, until the number ...
39
votes
22answers
6k views

The best base is 10… Let's reach it!

Input: A positive integer n consisting of digits in the range 0-9. Challenge: If d is the highest digit in the integer, assume the base of the number is d+1. E.g. if the integer is 1256 then you ...
20
votes
2answers
757 views

Are these lists equal?

As you may very well know python has lists. As you might not know these lists can contain themselves. a = [] a.append(a) Python 2 Python 3 These are cool and ...
52
votes
38answers
4k views

Arbitrary-length currying

Write a function, f, that takes in a positive integer and returns a function. The new function returned should be identical to f...
12
votes
4answers
2k views

Output subdivisions of international standard paper sizes

ISO Paper Sizes Defined: The A series paper sizes are defined by the following requirements: ...
58
votes
25answers
5k views

Cantor's unspeakable numbers

An unspeakable number is a number which is divisible by seven or has seven as one of its digits. A children game is to count skipping unspeakable numbers ...
20
votes
3answers
405 views

Peel the potato

This is a potato: @@ @@@@ @@@@@@ @@@@@@ @@@@ @@ More generally, a size N potato is defined as the following shape: If N is even, it is 2 centered ...
106
votes
7answers
4k views

Exponentially Slimy Programming: Stacking Minecraft Slimes

Slimes are cube shaped enemies in Minecraft that break into multiple smaller versions of themselves when killed. For the purposes of this challenge we'll depict them as an 8×8 pixel image with 3 ...
15
votes
2answers
1k views

Is there a way of shortening fat-arrow functions?

From what I've seen throughout my time here on PPCG, most JavaScript entries involving fat arrow functions tend to be one of two camps: The simple ones that are capable of running as a single ...
15
votes
35answers
3k views

Hofstadter H-sequence

Definition a(0) = 0 a(n) = n-a(a(a(n-1))) for integer n > 0 Task Given non-negative ...
10
votes
6answers
302 views

Binary Recurrence Sequences

A binary recurrence sequence is a recursively-defined sequence of the following form: This is a generalization of the Fibonacci (...
11
votes
1answer
557 views

Recursive Steiner Chains

Steiner Chains are a set of N circles where each circle is tangent to 2 other non-intersecting circles as well as the the previous and next circles of the chain, as seen in the below images: In ...
54
votes
40answers
4k views

Alex-style Addition

Inspired by Alex's glorious Learn you an R for great good, we are going to humbly recreate Alex's "one true R program" -- but with a twist. Alex-style Addition works like this -- it has a 90% chance ...
30
votes
3answers
2k views

Tiny Lisp, tiny interpreter

Lisp programmers boast that Lisp is a powerful language which can be built up from a very small set of primitive operations. Let's put that idea into practice by golfing an interpreter for a dialect ...
13
votes
7answers
445 views

Prefix Tree Traversal

Write a program that takes in (via stdin or command line) a string with the recursive form PREFIX[SUFFIXES] where PREFIX may ...
30
votes
11answers
1k views

Print, Increment, Decrement, Alias - Interpret Prindeal

Prindeal (pronounced prin-dee-al) is a new esoteric programming language that only has four commands: print, increment, decrement, and alias. Despite its minimalism, complex mathematical operations ...
20
votes
12answers
1k views

Evaluating Parentheses and Brackets as Integers

Write a program that takes in a string of the four characters ()[] that satisfies these points: Every left parenthesis ( has a ...
7
votes
8answers
3k views

Ways to arrange the integers 1 to 9 with operators so that the result is 100

Prelude: This task is taken from Five Problems Every Software Engineer Should Be Able to Solve in Less Than an Hour, which I really recommend. The task: Write a program that outputs all ...
5
votes
2answers
801 views

Coding a recursive function for highest possible input

Challenge You are given the following function:- which is the same as:- with the base cases q(r, b, L) = 1 whenever r ≤ L, q(r, 0, L) = 0, if r > L and q(r, 0, L) = 1, if r ≤ L. Your task is to ...
32
votes
30answers
6k views

The Ackermann function

The Ackermann function is notable for being the one of the simplest examples of a total, computable function that isn't primitive recursive. We will use the definition of ...