Questions tagged [function]
For challenges that ask for a function or involve functions in some way. (Also known as methods or subroutines.)
28 questions
13
votes
16
answers
893
views
Make a zigzag array of length n with a defect at position d
In the fewest bytes, in any language, write a function, zigzagdefect(n, d) that takes as input integers n and d < n. The function should return a list of length ...
5
votes
3
answers
529
views
Valid python function invocation signatures
Background
In Python, function arguments are defined within the parentheses following the function name in the function definition. There are different ways to present function arguments, and they can ...
27
votes
12
answers
1k
views
Increment, decrement, undo, peek
Write a program or function (hereafter "function") that returns or prints the source code of four new functions: Increment, decrement, undo, and peek.
The initial function contains an ...
19
votes
62
answers
5k
views
Write a function [closed]
I honestly can't believe this challenge does not already exist.
The challenge
Write a function.
The specifics
Your program must define some sort of callable function. This includes anything ...
12
votes
22
answers
2k
views
Find the C-factor of a vote
In this challenge you will be determining how controversial a vote is, given an array of other votes, by figuring out a number called the C-factor. What is the C-factor, you ask?
Well, imagine you've ...
16
votes
14
answers
2k
views
Arbitrary Length Hashing
Consider you have a hash function \$\mathcal{H}\$ which takes strings of length \$2n\$ and returns strings of length \$n\$ and has the nice property that it is collision resistant, i.e. it is hard to ...
-1
votes
1
answer
200
views
Symmetric Numbers [duplicate]
write a function to tell if a number is symmetric or not.
for example:
input:
151
output:
True
input:
142
output:
False
and so on:
1111 True,
2390 False,
1226221 True
33
votes
15
answers
4k
views
Black Box Trigonometry
Write a program or function that can distinguish the following 12 trigonometric functions: sin,
cos,
...
-3
votes
2
answers
1k
views
Fastest way to perform the equivalent of an if-statement in x86 assembly
The task is simple: Create an if-statement from scratch in x86 assembly that runs in as few clock-cycles as possible.
Must be x86 assembly.
Can't use any of the conditional jump/branch instructions (e....
19
votes
10
answers
2k
views
Approximate definite integrals using Riemann sums
Left and right Riemann sums are approximations to definite integrals. Of course, in mathematics we need to be very accurate, so we aim to calculate them with a number of subdivisions that approaches ...
21
votes
7
answers
2k
views
Half-Exponential Function
A half-exponential function is one which when composed with itself gives an exponential function. For instance, if f(f(x)) = 2^x, then ...
13
votes
3
answers
537
views
Compute the most efficient binary function
Today, we'll be computing the most efficient binary function. More specifically, we'll be computing the function which, when an expression is created from applying the function to the constant input 0 ...
10
votes
2
answers
604
views
Convert pointfree to pointful
Being a Haskell hacker, I prefer pointfree notation over pointful. Unfortunately some people find pointfree notation hard to read, and I find it hard to get the correct number of parentheses when I ...
15
votes
5
answers
283
views
Properties of Binary Functions
Many important topics in abstract algebra involve a binary function acting on a set. A number of properties of such functions have been defined in the investigation of such topics.
Your challenge will ...
2
votes
4
answers
852
views
Pi Bowling to 10 in 10 [closed]
Your Goal: Estimate pi to at least 10 decimal places. The format is your choice - it can output as a number, as a string, as an output to STDOUT, etc.
Seems easy, right? But wait, it's not as simple ...
2
votes
2
answers
3k
views
Javascript function challenge add(1,2) and add(1)(2) both should return 3 [closed]
A friend of mine challenged me to write a function that works with both of these scenarios
add(1,2) // 3
add(1)(2) // 3
My instinct was the write an add() ...
12
votes
6
answers
3k
views
Implement t9-like functionality
Your challenge today is to implement a t9-like functionality.
You will implement a function that will only have 2 parameters.
You will receive 1 phone number in a string and the content of a text ...
8
votes
12
answers
3k
views
Function/macro that returns true if one of its arguments contains a call to itself
Write a function (or macro) that returns true if and only if at least one of its arguments contains a call to the function itself and false otherwise.
For example:
...
23
votes
18
answers
5k
views
Find nearest number in a given array
This is inspired by a real world problem I had. I'm curious to see if there is any clever way to go about this.
You are given two unsorted arrays, A and B, each containing an arbitrary number of ...
12
votes
13
answers
4k
views
Theatre Seating
Task
A theatre has 10 rows, labelled A to J from front to back, and 15 seats in each row,
numbered 1 to 15 from left to right.
...
-2
votes
4
answers
622
views
Riffle Shuffle Golf Time
Anyone who has spent any time around a deck of playing cards will recognize the riffle shuffle. The deck is cut in half and the two stacks are riffled simultaneously into the same pile before being ...
18
votes
24
answers
8k
views
Old MacDonald function
Create a function in your chosen language that prints out the following:
...
19
votes
25
answers
3k
views
Incremental Betting
Several months ago I had this question as a pre-screening puzzle for an interview. Recently when thinking about blog material, it popped in my head as a good example to use for solving a problem ...
80
votes
78
answers
17k
views
Call a method without calling it [closed]
Inspired by a now deleted StackOverflow question. Can you come up with a way to get a particular method executed, without explicitly calling it? The more indirect it is, the better.
Here's what I ...
29
votes
13
answers
5k
views
Lifetime of a Worm
Terms
A worm is any list of nonnegative integers, and its rightmost (i.e., last) element is called the head. If the head is not 0, the worm has an active segment consisting of the longest contiguous ...
19
votes
15
answers
2k
views
Write a function that tells you which TWO of its lines has been removed
In my previous code challenge, I asked you to write a function that tells you which of its lines has been removed.
The instructions were:
Write a function that contains five lines.
If you run ...
29
votes
13
answers
2k
views
Write a function that tells you which of its lines has been removed
Write a function that contains five lines.
If you run the function as-is, it should return 0.
If you remove any one of the five lines and run the function, it should tell you which of the lines has ...
3
votes
2
answers
416
views
Finding limits of functions
A limit in math determines the value that a function f(x) approaches as x gets closer and closer to a certain value.
Let me use ...