Skip to main content

Questions tagged [function]

For challenges that ask for a function or involve functions in some way. (Also known as methods or subroutines.)

Filter by
Sorted by
Tagged with
13 votes
16 answers
893 views

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 ...
Jack's user avatar
  • 231
5 votes
3 answers
529 views

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 ...
Mardoxx's user avatar
  • 181
27 votes
12 answers
1k views

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 ...
Jordan's user avatar
  • 11.9k
19 votes
62 answers
5k views

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 ...
moltarze's user avatar
  • 2,578
12 votes
22 answers
2k views

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 ...
moltarze's user avatar
  • 2,578
16 votes
14 answers
2k views

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 ...
Laikoni's user avatar
  • 26.4k
-1 votes
1 answer
200 views

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
AndiChin's user avatar
  • 335
33 votes
15 answers
4k views

Write a program or function that can distinguish the following 12 trigonometric functions: sin, cos, ...
Laikoni's user avatar
  • 26.4k
-3 votes
2 answers
1k views

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....
Lance Pollard's user avatar
19 votes
10 answers
2k views

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 ...
Mr. Xcoder's user avatar
  • 42.9k
21 votes
7 answers
2k views

A half-exponential function is one which when composed with itself gives an exponential function. For instance, if f(f(x)) = 2^x, then ...
izzyg's user avatar
  • 42.3k
13 votes
3 answers
537 views

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 ...
izzyg's user avatar
  • 42.3k
10 votes
2 answers
604 views

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 ...
BlackCap's user avatar
  • 3,958
15 votes
5 answers
283 views

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 ...
izzyg's user avatar
  • 42.3k
2 votes
4 answers
852 views

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 ...
Glen O's user avatar
  • 2,976
2 votes
2 answers
3k views

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() ...
MicFin's user avatar
  • 123
12 votes
6 answers
3k views

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 ...
Ismael Miguel's user avatar
8 votes
12 answers
3k views

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: ...
user avatar
23 votes
18 answers
5k views

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 ...
Orhym's user avatar
  • 333
12 votes
13 answers
4k views

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. ...
Harry Beadle's user avatar
-2 votes
4 answers
622 views

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 ...
zoplonix's user avatar
  • 1,013
18 votes
24 answers
8k views

Create a function in your chosen language that prints out the following: ...
rybo111's user avatar
  • 4,565
19 votes
25 answers
3k views

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 ...
TheSoftwareJedi's user avatar
80 votes
78 answers
17k views

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 ...
user avatar
29 votes
13 answers
5k views

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 ...
r.e.s.'s user avatar
  • 3,162
19 votes
15 answers
2k views

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 ...
jawns317's user avatar
  • 1,182
29 votes
13 answers
2k views

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 ...
jawns317's user avatar
  • 1,182
3 votes
2 answers
416 views

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 ...
beary605's user avatar
  • 4,368