All Questions

Filter by
Sorted by
Tagged with
15 votes
11 answers
1k views

Flood fill by distance

Say I have a grid with some obstacles: ---- | X | | | |XX | | | ---- I can fill this with numbers, as distance from the top left corner. But, because ...
user avatar
  • 31.5k
19 votes
16 answers
2k views

Check a mushroom forest

In this challenge you will receive a list of pairs of non-negative integers representing a mushroom forest. Each pair represents a mushroom whose center is at that horizontal coordinate. The only ...
user avatar
  • 89.4k
14 votes
2 answers
2k views

Can `a?b<c:b>c` be shortened in Javascript?

So I have the situation where I have one boolean value a and, if that one is true and b<c ...
user avatar
19 votes
23 answers
2k views

The Unaverageables

Related. Given a list of 3 or more positive integers, remove every number X for which there is another number Y in the list and the average of X and Y is also in the list. In other words, if X, Y, and ...
user avatar
16 votes
22 answers
975 views

Iterative Smallest Complement

For this challenge, we will define the "complement" of a list of integers A as being any list B such that the union of ...
user avatar
21 votes
9 answers
2k views

How tall are the mushrooms?

In this challenge you will receive a list of non-negative integers. Each one represents a mushroom with a cap of that radius centered at that location. So a 0 ...
user avatar
  • 89.4k
23 votes
25 answers
3k views

How far from binary?

Given a decimal integer n as input, output the smallest (in terms of absolute value) decimal integer m such that the absolute ...
user avatar
  • 36.6k
16 votes
12 answers
2k views

Find the walls!

This is a simpler variant of my previous challenge Don't touch the walls!, as suggested by Jonah. Given a multi-dimensional rectangular array of integers between 0 and 9, output all the elements ...
user avatar
  • 22.2k
1 vote
10 answers
355 views

Divide by an odd number, 2-adically

Given \$a\$ and \$b\$, both odd \$n+1\$-bit integers, compute \$a/b\$ to a precision of \$n+1\$ bits in the 2-adic integers. That is, compute \$c\$ such that \$a = bc\, (\mathop{\rm mod} 2^{n+1})\$. \$...
user avatar
1 vote
1 answer
209 views

Implement the slowest possible sorting algorithm that retains a fast best case [closed]

I have recently been on a quest to create really really slow sorting algorithms that make Bogosort seem like it is the best. The task is simple: Sort an array of integers in as long average time as ...
user avatar
  • 27
25 votes
24 answers
3k views

backwardS_hybriD-snakE_kebaB-cameL_case

There are a bunch of different casing conventions, like camelCase, PascalCase, snake_case ...
user avatar
  • 31.5k
22 votes
16 answers
2k views

Create Bernard from Desmos

Background In the online graphing calculator Desmos, there is a certain shape that appears in the lower left portion of the graph in many high detail graphs, which the Desmos community has dubbed &...
user avatar
  • 5,712
20 votes
4 answers
1k views

Gray coded Gray code convertor

To increase data safety at our company, we are planning to start using Gray code numbers (where successive values differ by only one bit) instead of classical binary ones. Please help us to make a ...
user avatar
  • 1,335
17 votes
11 answers
1k views

Extend a matrix in all directions

Given a multidimensional, rectangular array and a list of dimensions, such as: [ [1, 2], [3, 4] ] [3, 4] Your challenge is to extend the matrix to the ...
user avatar
  • 31.5k
20 votes
25 answers
1k views

Truncate words in a sentence

Inspired by wezl. Your challenge is to take words (sequences of [a-zA-Z]) and truncate them to length 3. For example, ...
user avatar
  • 31.5k
13 votes
4 answers
262 views

Is it a heapable sequence?

A binary max heap is a rooted tree with integer labeled nodes such that: No node has more than 2 children. The label of every node is greater than all of its children. We say a sequence of integers ...
user avatar
  • 1,231
6 votes
2 answers
387 views

Generate Fibonacci Primes Quickly

Unsurprisingly, fibonacci primes are primes that are also Fibonacci numbers. There are currently 34 known Fibonacci primes and an additional 15 probable Fibonacci primes. For the purpose of this ...
user avatar
  • 2,175
17 votes
13 answers
1k views

Enumerate all pure sets

In set theory, a set is an unordered group of unique elements. A pure set is either the empty set \$\{\}\$ or a set containing only pure sets, like \$\{\{\},\{\{\}\}\}\$. Your challenge is to write a ...
user avatar
  • 31.5k
18 votes
25 answers
2k views

Is it a valid list?

Given a string like [[[],[[]]],[]], made of only commas and square brackets, your challenge is to determine whether it represents a list. A list is either: ...
user avatar
  • 31.5k
18 votes
10 answers
1k views

Position from atomic number in the periodic table

Let us consider the following representation of the periodic table. ...
user avatar
  • 321
-11 votes
5 answers
248 views

12 with no 1234567890, but polyglot

This is my 12th question, so I thought of this idea. Goal: Output 12, with any preceding or trailing whitespace permitted In as many languages as possible (where different versions or flags count as ...
user avatar
15 votes
3 answers
620 views

Universal Unicode Clock

Plot contrivance You wake up to find that something has gone horribly wrong! Your time machine has malfunctioned and you are lost sometime between June 2022 and October 1991. You check the computer ...
user avatar
  • 89.4k
20 votes
20 answers
2k views

Iteratively delete a list

Say I have a ragged list, like: [ [1, 2], [3, [4, 5] ] ] And I want to iterate over each item and delete it one-by-one. However, I don't know the ...
user avatar
  • 31.5k
6 votes
1 answer
208 views

Find the Circle-Tangent Polynomials

Introduction A circle-tangent polynomial is a polynomial of degree \$N\ge3\$ or above that is tangent to the unit circle from inside at all of its N-1 intersection points. The two tails that exits the ...
user avatar
30 votes
5 answers
5k views

Can the 🐸 visit all the 🪷?

In this challenge you will be simulating a frog jumping from lily-pad to lily-pad in a pond. A frog's jump distance is uniquely determined by the size of the lily pad it jumps from. So for example ...
user avatar
  • 89.4k
15 votes
5 answers
2k views

Don't touch the walls!

Given a multi-dimensional rectangular array of non-negative integers, pad it with the minimal number of zeroes so that only zeroes are "touching the edges" of the array, in every dimension. ...
user avatar
  • 22.2k
20 votes
25 answers
3k views

Give f and g that sometimes commute

Let \$Z\$ be either the integers, the positive integers, or the non-zero integers; pick whatever's convenient. Give two functions \$f\$ and \$g\$, each \$Z \to Z\$, such that: \$f(g(a)) = g(f(a))\$, ...
user avatar
  • 1,231
12 votes
15 answers
2k views

Speed up, slowpoke!

In this king-of-the-hill challenge, you will program a bot, consisting of a python function of the form def BOTNAME(info, me, round): pass # ... main body ...
user avatar
  • 1,443
21 votes
24 answers
3k views

Consecutive coin flips

This is a cross-post of a problem I posted to anarchy golf: http://golf.shinh.org/p.rb?tails Given two integers \$ n \$ and \$ k \$ \$ (0 \le k \le n) \$, count the number of combinations of \$ n \$ ...
user avatar
20 votes
16 answers
2k views

Print the power set of the power set ... of an empty set

Given a non-negative integer n, print the result of P(P(...P({}))), where the number of P's ...
user avatar
10 votes
6 answers
410 views

Parenthetical Names

Parenthetical names Your challenge is to build a program that puts parentheses around the 'title' part of names. For example, Sonic the Hedgehog is converted to <...
user avatar
22 votes
10 answers
3k views

Tell me how many there are, in Polish

Today, you're going to be writing Polish. No, not Polish notation—Polish, the actual language spoken in Poland. Given a number and a noun, output a Polish sentence telling me that there are that many ...
user avatar
23 votes
37 answers
2k views

Count /[^a-z]/ig with /[a-z]/ig

Write a program or function which takes a string of text as input and outputs the number of non-alphabetical characters in it (standard I/O rules apply). A non-alphabetical character is any character ...
user avatar
5 votes
0 answers
244 views

Sort my Cups︎︎︎︎︎︎︎︎︎︎ [closed]

I have a set of colored plastic cups. They come in four colors: green, yellow, pink, and blue. When I put them on my shelf, I like to stack them in a certain pattern. Your job is, given a list of any ...
user avatar
  • 3,410
17 votes
15 answers
2k views

Concatenatable numbers

Given a list of positive integers such as [69, 420], your challenge is to generate the sequence of numbers that can be formed by concatenating numbers from the ...
user avatar
  • 31.5k
14 votes
11 answers
1k views

Make the list Fibonacci-like

Related, but not dupe. Challenge A list of integers \$a_1, a_2, a_3, \dots, a_n\$ (\$ n ≥ 1 \$) is Fibonacci-like if \$a_i = a_{i-1} + a_{i-2}\$ for every \$i > 2\$. Note that every list that ...
user avatar
  • 1,017
19 votes
12 answers
2k views

Detect Mongolian vowel harmony

The Mongolian language has "vowel harmony". In short the vowel harmony means that certain vowels are not allowed to be placed next to each other in a word. This means that suffixes of ...
user avatar
  • 89.4k
11 votes
12 answers
777 views

Permutations summing to permutations

Given an integer \$N\$ consider a permutation \$p=p_1,p_2,p_3,\ldots\$ of \$1,\ldots,N-1\$. Let \$P = p_1 , p_1+p_2 \bmod N, p_1+p_2+p_3 \bmod N, \ldots\$ be its prefix sums modulo \$N\$. Sometimes \$...
user avatar
20 votes
19 answers
2k views

Make a list flat

Lists can contain lists and we have nested lists. But we don't like nested lists and want to flatten them. By flattening I mean create a list which does not contain any list, but elements of lists it ...
user avatar
16 votes
8 answers
2k views

Scribble Pad for Nerds

aka. implement an easier version of 05ab1e's canvas element. Description The canvas element is used to draw ASCII lines on the screen. The (easier version of the) canvas element takes a list of ...
user avatar
  • 4,621
0 votes
0 answers
69 views

How much more to a repdigit? [duplicate]

Challenge By Wikipedia, a repdigit is a natural number composed of repeated instances of the same digit. For example, \$0\$, \$1\$, \$33\$, \$555\$, \$9999\$ are repdigits, while \$10\$, \$121\$, \$...
user avatar
  • 1,017
12 votes
14 answers
644 views

Increasing permutation trees

For this challenge a "binary tree" is a rooted tree where each node has 0 children (leaf) or 2. The children of a node are unordered, meaning that while you might draw the tree with left ...
user avatar
  • 89.4k
9 votes
10 answers
548 views

Two In One: Guess That Language - Robbers

Cops' challenge This cops-and-robbers challenge challenges the Cop to write a non-empty program that, when run, produces some non-empty output in language A, and, when reversed, produces some non-...
user avatar
19 votes
15 answers
1k views

Two In One: Guess That Language - Cops

Robber's challenge This cops-and-robbers challenge challenges the Cop to write a non-empty program that, when run, produces some non-empty output in language A, and, when reversed, produces some non-...
user avatar
14 votes
4 answers
413 views

Fill the rectangle

Challenge In this challenge, you have to fill an \$M\$ x \$N\$ rectangle grid with the most \$A\$ x \$B\$ rectangle pieces possible. Requirements: The sizes of the \$M\$ x \$N\$ rectangle grid is ...
user avatar
  • 1,017
9 votes
8 answers
416 views

Durable Durations

Introduction Time is a really simple concept. Seconds pass, one after the other, all the same. But humans love making it hard. This Stackoverflow question has gathered many answers and even though ...
user avatar
  • 199
13 votes
12 answers
724 views

Count alternating permutations

An alternating permutation is a permutation of the first \$ n \$ integers \$ \{ 1 ... n \} \$, such that adjacent pairs of values in the permutation alternate between increasing and decreasing (or ...
user avatar
  • 22.2k
5 votes
0 answers
69 views

Tips for golfing in J-uby

J-uby is the Language of the Month for June 2022, so I'm looking for tips for golfing in it. As usual, please post one tip per answer, and avoid general tips such as "remove whitespace" or &...
user avatar
  • 8,986
11 votes
17 answers
1k views

Extract the contained powers of two!

Take as input an integer in any reasonable format. Then, output all the proper sub-strings of the base-10 digits of that integer that are powers of two, in any reasonable format. Test cases ...
user avatar
  • 1,443
17 votes
9 answers
2k views

How many light changes will a 7-segment display need?

Problem Assume you have a single 7-segment display without a decimal point, so 7 "lines" that can be labelled A through G as seen here. This display will only show the numbers from 0 to 9 ...
user avatar
  • 287

15 30 50 per page