Questions tagged [code-golf]
Code-golf is a competition to solve a particular problem in the fewest bytes of source code.
12,031
questions
0
votes
0
answers
126
views
Shortest way to cause a seg fault at 0x9c?
In honour of CrowdStrike's exception at 0x9c, what's the shortest way (character-wise) to cause a segfault by dereferencing address 0x9c?
The best I can come up with is:
...
1
vote
1
answer
130
views
Compute Dickman
Input
A floating point number \$x\$ between 1 and 8 inclusive.
Output
The Dickman function of \$x\$.
The Dickman–de Bruijn function \$\rho(u)\$ is a continuous function that satisfies the delay ...
3
votes
18
answers
305
views
Check if two lists are permutations of each other [duplicate]
Challenge
Given two lists of equal length, find if one of them is a permutation of the other. Output truthy or falsy values, or 1 or 0.
Test case Examples
...
13
votes
15
answers
883
views
Reorder for smallest largest prefix sum
Given a multiset of integers, order them such that the largest absolute prefix sum $$\max_i \left| \sum_{k<i} a_k \right|$$ is smallest. Output any solution if multiple exist.
You can assume input ...
18
votes
19
answers
4k
views
Wait, ASCII was 128 characters all along?
Challenge
In this challenge, you have to take a nonnegative integer as input, convert it into base-128 bytes (0 → 0x00, 127 → ...
20
votes
15
answers
2k
views
Sorting with a deque
You're given an array of positive integers. Your job is to sort them using an initially empty deque (double-ended queue) by the following procedure:
Take a number from the front of the array, and ...
7
votes
39
answers
1k
views
Calculate sum of self-exponentation
Given an array of positive integers, calculate the sum of each number raised to its own power. For example, given 4,6,7, the code needs to return \$4^4+6^6+7^7=...
14
votes
9
answers
956
views
Draw a Regular Reuleaux Polygon
Related: Draw A Reuleaux Triangle!, Draw a regular polygon
A Reuleaux polygon is a curve of constant width made up of circular arcs of constant radius. The most well-known Reuleaux polygon is the ...
16
votes
16
answers
2k
views
o y u (or and or)
In Spanish, the word 'or' is represented as 'o', with the exception of cases where the following letter starts with 'o' or 'ho' (including accented forms like 'ó' or 'hó'). Numbers also follow this ...
17
votes
9
answers
2k
views
A Ring of Cubes
Given an integer greater than or equal to 2, output ASCII-art resembling an isometric-perspective cube ring with that side length.
Expected outputs given below for 2, 3. You can imagine the rest. You ...
9
votes
12
answers
3k
views
Keyboard Ping Pong
Keyboard Ping Pong
(This question was inspired by this post.)
Challenge
Given a string of letters, determine if the word "ping-pongs" across the keyboard. (Letters alternating between sides ...
9
votes
13
answers
1k
views
Is it an option for the ls utility specified in POSIX.1-2017?
The ls utility lists specified directory content. It is infamous for stupidly lots of options which is known for anti-pattern design of implementing software.(...
11
votes
15
answers
2k
views
Is this a Hadamard matrix?
Hadamard matrices is a square matrix whose entries are either +1 or −1 and whose rows are mutually orthogonal.
In other words, it means that each pair of rows has matching entries in exactly half of ...
14
votes
19
answers
895
views
Rolling median of all K-length ranges
Given an array of integers of length N and an odd integer K, return N - K + 1 integers, where the ith integer represents the median of a K-length subarray starting from i.
You may write a full program ...
3
votes
1
answer
125
views
Detect revokes in Jass
Jass is a trick-taking game for four players and the national card game of Switzerland. It is played with a 36-card deck, four suits each with ranks 6, 7, 8, 9, 10, J, Q, K, A. We will be using French ...
12
votes
1
answer
321
views
Plot the ground path of a satellite
If you model a satellite as a free point orbiting a body, you can pretty easily see it has 6 degrees of freedom: three for the X, Y, and Z position, and three for the X, Y, and Z velocity. However, ...
9
votes
12
answers
691
views
Minimum number of select-all/copy/paste steps for a string containing n copies of the original
This challenge is based on this Mathematics answer.
Write the shortest program or function that, when given some natural number \$n\$, outputs \$S(n)\$, which is the minimum number of steps for ...
26
votes
39
answers
2k
views
Segments of a string, doubling in length
Simple task today. Given a string whose length is one less than a whole power of 2, divide it into segments with doubling length.
For example for the string ...
9
votes
8
answers
1k
views
Sort Number Array
Given array \$A\$ \$(a_0, a_1,... , a_n) \$ as a permutation of \$(0, 1,...,n)\$ where \$n ≥ 2\$. Sort array \$A\$ into array \$(0, 1,...,n\$) with \$2\$ caveats:
\$1\$ swap is counted when swapping ...
7
votes
7
answers
816
views
Parity of a number with missing digits
It turns out that you need every digit of a number to determine its parity, if it is written in an odd base.
Your programs should take input as a number between 2 and 36 inclusive, and a nonempty ...
23
votes
7
answers
1k
views
Output the Steiner system S(5,8,24)
Output 759 "rows", each of which consists of 8 distinct integers in the range 0,1,...,23, with the property that every set of 5 integers in the range 0,1,...,23 is contained in exactly one ...
23
votes
11
answers
2k
views
Binary Slashes Display
(easy mode of Seven Slash Display)
Given a positive integer (or alternatively, a string/list of bits of its binary representation) output it with this diagonal ASCII-art formation:
(output for 53 / <...
16
votes
15
answers
2k
views
Transpose these notes!
In this challenge, you should take input as a number between 0 and 11 inclusive and a (possibly empty) list of the following strings/notes:
...
13
votes
14
answers
4k
views
NaN is not equal to NaN
In many programming languages, the floating-point value NaN, or "not a number", in some programming languages generated by the expression ...
1
vote
2
answers
239
views
Write a function that takes an input string and encodes it using a modified Fibonacci sequence in reverse [closed]
Given an input string, first convert each character to its ASCII value.
Generate a reversed Fibonacci sequence of the same length as the input string.
Encode each character by adding its ASCII value ...
14
votes
5
answers
366
views
Generate a subgroup of a free group
In group theory, the free group with \$n\$ generators can be obtained by taking \$n\$ distinct symbols (let's call them \$a, b, c ...\$ etc), along with their inverses \$ a^{-1},b^{-1},c^{-1} ...\$ . ...
16
votes
23
answers
2k
views
Smallest Harmonic number greater than N
The sequence of Harmonic numbers are the sums of the reciprocals of the first k natural numbers (not including zero):
\${\displaystyle H_{k}=1+{\frac {1}{2}}+{\frac {1}{3}}+\cdots +{\frac {1}{k}}=\sum ...
13
votes
9
answers
1k
views
Sum of square roots (as an algebraic number)
An algebraic number is a number that is a root of a non-zero polynomial with integer coefficients. It is well-known that the sum of two algebraic numbers is algebraic. In particular, the sum of a list ...
19
votes
22
answers
1k
views
Find characters common among all strings
Find characters common among all strings
You are given multiple Strings as an input. Your task is to find the characters that are present in every string, and ...
7
votes
7
answers
590
views
Build the first 6 letters of an Italian codice fiscale (tax identification number)
Given a single string with a person's name and surname, output the first 6 characters of their codice fiscale.
Codice fiscale
Codice fiscale is a 16-character long alphanumeric string that identifies (...