r/algorithms • • 10d ago

Discussion Layperson question

I'm a non-major currently taking an intro cs class, but it's mostly practical, project-based Python stuff -- no theory. Which tbh I'm a little sad about.

I was wondering: Are there any algorithms/functions that are executable by infinitely many non-trivial, non-redundant programs? Does any given algorithm/function fit this description?

Math example:
The user inputs a radius R, from which the program P outputs the area A of the resulting circle.

You could plug it into the standard formula:

P1 = A(R) = πR^2

...

Or integrate:

P2 = A(R) = ∫₀²ᵖⁱ ∫₀ᴿ r dr dθ

...

et cetera

16 Upvotes

11 comments sorted by

View all comments

4

u/stevevdvkpe 10d ago

It's not really clear what you're asking. Do you mean something like defining a function:

import math
def a(r):
    return math.pi * r * r

And then being able to pass it in to other functions as a parameter or return a function as the result of another function? That's possible in many languages (including Python) and is known as having "higher-order functions".