Skip to main content

Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

Filter by
Sorted by
Tagged with
2 votes
2 answers
216 views

Background This video goes into ways you can humanize binary, including creating a more compact writing notation using . and | ...
user119818's user avatar
  • 1,631
4 votes
2 answers
177 views

Say there are three multisets A, B, C. An infix condition has form <ON|FACING|NEAR> <a multiset> where ON requires ...
l4m2's user avatar
  • 32.6k
11 votes
4 answers
542 views

Given two sorted lists of same length \$\{a_i\}\$ and \$\{b_i\}\$, find the smallest \$w\$ such that it's possible to connect each pair of points \$(0,a_i)\$ and \$(w,b_i)\$ with paths such that x-...
l4m2's user avatar
  • 32.6k
0 votes
1 answer
112 views

You have to code in python, and the number generated by your code must be bigger than all other current submissions. You need to make your code as small as possible, it has to terminate but you can ...
IAmNotLarry's user avatar
-1 votes
1 answer
135 views

Given a String of opening brackets and the letter G, such that it makes a applicative tree of the leaf node G and ( representing ...
malediscord kitten's user avatar
8 votes
4 answers
605 views

Objective Given a prime number \$p\$ and an integer \$n \geq 2\$, find a degree-\$n\$ primitive polynomial modulo \$p\$. Mathematical explanation When we perform "modular arithmetic" over ...
Dannyu NDos's user avatar
  • 7,381
14 votes
10 answers
1k views

The most common way to represent a polynomial is writing it as a linear combination of monomials, i.e., powers of the variable. For example, the polynomial \$p(x) = x^3 + 2x^2 + x + 1\$ is a linear ...
alephalpha's user avatar
  • 51.9k
18 votes
18 answers
2k views

Task Given an unsorted list of integers, order it in such a way that the absolute difference of every two adjacent elements will always be equal to 1: \$|dx| = 1\$ There will be guaranteed one or more ...
Glory2Ukraine's user avatar
11 votes
7 answers
612 views

This was originally a question from interviewstreet.com over a decade ago You are given an array (or whatever - your choice of input) of positive integers \$y_1,\ldots,y_n\$ that represents \$n\$ line ...
Henry's user avatar
  • 219
18 votes
8 answers
1k views

Introduction: When saying numbers out loud, the order is slightly different in Dutch than in English. For a number like \$1234\$: in English you'd say: one thousand, two hundred and thirty-four in ...
Kevin Cruijssen's user avatar
11 votes
17 answers
924 views

A redundant regular expression (regex) is defined here as a regex which has some amount of characters which can be removed while not affecting its functionality -- i.e. it matches the exact same set ...
97.100.97.109's user avatar
8 votes
8 answers
971 views

This is inspired by this homework assignment. Telomeres are regions of repetitive DNA sequences that occur at the ends of linear chromosomes in eukaryotes (such as humans and other mammals). In ...
M--'s user avatar
  • 986
8 votes
6 answers
949 views

I was thinking when SQL can be less verbose than traditional programming languages and came up with this challenge. Input Natural number N Generating data We ...
Dr Y Wit's user avatar
  • 519
-7 votes
8 answers
314 views

Write the shortest program or function that accepts a sequence of three or more letters and returns its I18n-style numeronym, preserving the original letter case. The I18n-style numeronym is formed by ...
Steve Bennett's user avatar
1 vote
2 answers
230 views

Bands and Bonds is a browser clicker game about delving in a dungeon. It has the particularity that only one of the actions you may take can be auto-repeated at the same time: You may start several ...
Themoonisacheese's user avatar
9 votes
3 answers
322 views

Divide 1 by a sum/difference of square roots Input: An expression that is a sum/difference of square roots of positive integers. You can assme it will not equal 0. The general form is \$\pm\sqrt{a_1}\...
Lucenaposition's user avatar
5 votes
4 answers
357 views

DNA is read in groups of three nucleotides (the letters you see in a sequence), called codons, for determining what protein sequence the portion of DNA will yield. I already used this in a previous ...
Whitehot's user avatar
  • 633
6 votes
9 answers
698 views

Parse rpip7 musical notation rpip7 is a minimalist music notation derived from ip7, designed for simple playback (for example, on an Arduino with a buzzer). It supports only these symbols: ...
islptng's user avatar
  • 435
21 votes
17 answers
1k views

I was looking for a simple sequence that's not yet referenced on the OEIS and came up with this one(*): \$a_1=2\$ \$a_2=3\$ For \$n>2\$, \$a_n\$ is the smallest number of the form \$a_i\times a_j+...
Arnauld's user avatar
  • 206k
14 votes
17 answers
1k views

Each quarterback in the NFL is given a passer rating at the end of the game, which measures how good their forward passes were. It is not strictly a basic arithmetic formula, and is calculated as ...
Parcly Taxel's user avatar
  • 4,749
10 votes
8 answers
752 views

An extension of Find the closest palindromic number mixed with Numbers Interpreted in Smallest Valid Base. A number is a palindrome if its sequence of digits is the same when reading them from left to ...
Value Ink's user avatar
  • 13.6k
15 votes
18 answers
1k views

This is a sequel to Numbers Interpreted in Smallest Valid Base. Let us define the operation of rebasing a number as writing out its digits in decimal form, then interpreting them in the smallest base <...
SquareFinder's user avatar
19 votes
13 answers
2k views

G-code is a set of instructions used to manipulate machines in CNC, 3d printing, or other similar applications. It controlls the position of a tool, manuvering it to create a path. Your goal is to ...
Ted's user avatar
  • 2,417
20 votes
31 answers
2k views

Let us define the operation of rebasing a number as writing out its digits in decimal form, then interpreting them in the smallest base N possible (...
SquareFinder's user avatar
-5 votes
14 answers
445 views

Input: A string, can be multi-line. The newlines must to be real newline (e.g., you cannot request that each newline be (n)). There is another input, a number (not ...
QOO-OOKALAN's user avatar
15 votes
10 answers
2k views

Verify a Chinese ID Number The Resident Identity Card (居民身份证) is a document issued to most Chinese citizens. It contains information about its holder, including their name, address, and ID number, an ...
CanonNi's user avatar
  • 259
11 votes
7 answers
739 views

This challenge is from a video game, Keep Talking And Nobody Explodes. A yes or no choice isn’t too bad. Unfortunately you have to make five of them and any of them could be your last. — from the ...
Dannyu NDos's user avatar
  • 7,381
12 votes
12 answers
748 views

Challenge: Given inputs \$i\$ and \$n\$, calculate \$R_i(n)\$ where: $$R_0(n)=n \\ R_i(n)=\sum_{j=0}^nR_{i-1}(j)$$ Note that \$R_1\$ is triangular function, and \$R_2\$ is tetrahedral function. This ...
Fmbalbuena's user avatar
  • 5,085
10 votes
2 answers
370 views

Task: Your task is make a program to check if there exists integers \$a \ge 2, b \ge 2\$ such that \$a^b=i\$ where \$i\$ is the input integer at least 2. The catch is that your program must return a ...
Fmbalbuena's user avatar
  • 5,085
8 votes
12 answers
2k views

Introduction In my CS4 class I worked with another student to golf this lab as much as possible. I learned a lot about Ruby with it, and I am curious what optimizations could be done. :D Challenge A ...
packjack's user avatar
11 votes
11 answers
795 views

Challenge: Find integers \$a\$ and \$b\$ defining linear function \$f(x) = ax + b\$ with \$a > 0, b \ge 0\$ such that the sum of the elements of the input list \$l\$ located at the values of the ...
Fmbalbuena's user avatar
  • 5,085
5 votes
13 answers
857 views

Given a printable ASCII string, return any letter which is not present (ignoring case), if possible, else return the empty string. Test Cases: ...
Steve Bennett's user avatar
13 votes
4 answers
708 views

Write a program or function which, given a clockwise spiral as input, extends that spiral by one character. When given no input, your function returns the start of the spiral: ...
Steve Bennett's user avatar
18 votes
18 answers
1k views

Write a program/function to output a peg solitaire board in its starting position: ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ○ ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ...
Steve Bennett's user avatar
17 votes
22 answers
2k views

I had this problem come up for me recently and I thought it would make a fun code-golf. You will receive as input a list of positive integers. e.g. ...
Wheat Wizard's user avatar
  • 103k
8 votes
6 answers
839 views

Challenge: NSDT is like a calculus model invented by me that contains only 4 commands and grouping. Your task is to check in which way the program ends. The program is read from left to right. There ...
Fmbalbuena's user avatar
  • 5,085
3 votes
4 answers
778 views

Write a program or function to output an N x N sunburst image made of red, orange and yellow emoji icons. For N=40, it should look roughly like this: ...
Steve Bennett's user avatar
17 votes
10 answers
1k views

Should be relatively easy to do, given an input of a resistance (in ohms) and a tolerance (%), output the colour codes for a 4 band resistor, left to right. Input will always be a valid ohm value and %...
Natelolzzz's user avatar
12 votes
2 answers
232 views

You will be given a block of text and a cursor position at the end of a possibly incomplete word. You must output a suggestion for what this word (let's call it w) ...
Ted's user avatar
  • 2,417
14 votes
20 answers
2k views

This is the 2D version of Sum of neighbours: Given a 2D grid of integers, output a grid of the same size where each cell contains the sum of the values of its orthogonal and diagonal neighbors (up to ...
turalson's user avatar
  • 581
12 votes
9 answers
1k views

You will be given a pinball board with a ball on it. Determine where the ball will exit the board. The ball will fall straight down, unless obstructed by a left or right bumper, in which case it will ...
Ted's user avatar
  • 2,417
-4 votes
3 answers
345 views

Given the anti-clockwise points of a properly formed, non-self-intersecting, not-necessarily-convex polygon, render it as a filled ASCII art polygon. Input A series of at least 3 (x,y) pairs ...
Steve Bennett's user avatar
2 votes
1 answer
346 views

I'm pretty new to code golfing, but I recently came across a guy on Kattis that consistently has exactly 5 character Bash solutions for some problems. For example, here is a leaderboard showing his 5 ...
Donald Trump's user avatar
12 votes
15 answers
2k views

A loop is a rectangle of text like this: hgf ile jkd abc To unroll it, you start at the bottom left, and proceed to the right, spiralling anti-clockwise in towards ...
Steve Bennett's user avatar
21 votes
10 answers
2k views

Overview I have a sample of 10 quotes. You will receive as input to your program one of these quotes, however all the vowels (aeiou) will be replaced with the ...
Ted's user avatar
  • 2,417
17 votes
6 answers
884 views

A palindromic polynomial is a polynomial whose list of coefficients is a palindrome. For example, the polynomial \$p(x) = x^4 + 2x^3 + 3x^2 + 2x + 1\$ is palindromic because its coefficients are \$[1, ...
alephalpha's user avatar
  • 51.9k
2 votes
4 answers
621 views

Objective Your challenge is to write a program that, given a paragraph from a book, will output another program that prints out that paragraph. (See my example program in an answer) Scoring The link ...
ACertainArchangel's user avatar
18 votes
30 answers
2k views

Given X>0, return the smallest Y>=0 such that X+Y is a palindrome. Code golf. Tests: 5 => 0 14 => 8 200 => 2 819 => 9 1100 => 11 1122 => 99
Steve Bennett's user avatar
5 votes
3 answers
431 views

Overview You will be given a list of strings. If any two elements are equal, you can delete both of them. If one element a is a substring of element ...
Ted's user avatar
  • 2,417
13 votes
8 answers
1k views

You will be given a decimal number n in the form of a string. You must determine if that number, when stored in standard number type ...
Ted's user avatar
  • 2,417

1
2 3 4 5
248