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
18
votes
2answers
2k views

Can you spot the liar?

It's the end of the year, you and your friends have just received your grades and ranks for the GOLF101 class. On a chat group, everyone sends their grade and rank to see who's got the best one. ...
17
votes
58answers
5k views

Print 0 to 100 without 1-9 characters

Print 0 to 100 without using characters 1,2,3,4,5,6,7,8,9 in your code. Seperator of numbers can be comma, whitespace or newline. Shortest code wins.
23
votes
22answers
2k views

Pad a jagged array to be square

Given a 2-dimensional jagged array and a fill value, pad the array in both dimensions with the fill value to ensure that it is square and not jagged (i.e., all rows are the same length, and that ...
75
votes
184answers
14k views

Count up forever

Write a program that counts up forever, starting from one. Rules: Your program must log to STDOUT or an acceptable alternative, if ...
15
votes
35answers
4k views

1, 2, miss a few, 99, 100

When I was a kid, there was a "really cool" shortcut to count to 100: 1, 2, miss a few, 99, 100 Output the exact string above, in the fewest characters ...
55
votes
34answers
11k views

Print the phrase “And she said, 'But that's his.'” using only the alphabet

Print the phrase And she said, 'But that's his.' using only the following characters: ...
15
votes
13answers
700 views

Balance The uppercase

Oh, No! the sentences are out of balance. Quick! balance them. Given a sentence with words, balance each word by capitalizing a letter on the right hand-sight for each uppercase letter on the left ...
21
votes
32answers
1k views

Remove excessive occurrences

Given an array \$A\$ of positive integers between \$1\$ and \$9\$ inclusive and a positive integer \$n\$, remove all integers in \$A\$ which appear more than \$n\$ times. For example: ...
25
votes
14answers
2k views

Langton's ant ASCII art.

Draw the path of Langton's ant. Description Squares on a plane are colored variously either black or white. We arbitrarily identify one square as the "ant". The ant can travel in any of the four ...
13
votes
17answers
916 views

Determine the degree of a polynomial

Background: For this challenge, a polynomial looks like this: $$P(x)=a_nx^n+a_{n-1}x^{n-1}+\dots+a_2x^2+a_1x+a_0$$ The degree, \$n\$, is the highest power \$x\$ is raised to. An example of a degree 7 ...
19
votes
5answers
873 views

Remove the mininum sum seam from an array

The seam carving algorithm, or a more complex version of it, is used for content-aware image resizing in various graphics programs and libraries. Let's golf it! Your input will be a rectangular two ...
82
votes
69answers
14k views

Print your code backwards - reverse quine

Write a program that prints its own source code out backwards, in other words an eniuq. Scoring: +50 if you use pull data from the Internet. +25 if you read your own source code. +1 point per ...
-4
votes
0answers
44 views

Reverse error quine

Based on this Write a quine that prints it own source code in reverse, but to STDERR. Penalties +200 using other files I.E. reverse.txt +150 internet usage +100 ...
12
votes
4answers
2k views

Interpret Befunge-93

The program will be provided as the first argument, stdin should be used for all read requests by the program and stdout for all write requests. It can be assumed that the program is less than 80 ...
18
votes
10answers
2k views

What's next, Achilles?

Powerful numbers are positive integers such that, when expressed as a prime factorisation: $$a = p_1^{e_1} \times p_2^{e_2} \times p_3^{e_3} \cdots \times p_k^{e_k}$$ all exponents \$e_1, e_2, ...\$ ...
17
votes
43answers
2k views

Divisible strings

Task Given a string s, output a truthy value if the ASCII code of each letter is divisible by the length of s, and a falsey ...
22
votes
17answers
5k views

“Hello world” that creates a different “Hello world” program

Create a program, that outputs a hello world string ("Hello world", "Hello, World" etc.), and source code. Output is written to stdout or equivalent. Hello world string is embedded in the source code. ...
5
votes
15answers
659 views

Prime Challenge

CODE GOLF & Coding Challenges: In today's challenge, you'll be asked to print the following very special AND tricky AND satisfying Prime Number...! Are you golfers ready? ...
27
votes
16answers
3k views

Многочлены Чебышёва (Chebyshev Polynomials)

Chebyshev Polynomials are a family of orthogonal polynomials that pop up in all kinds of places in math, and they have a lot of quite interesting properties. One characterization of them is that they ...
64
votes
42answers
5k views

Write the shortest self-identifying program (a quine variant)

Write a program that will generate a "true" output iff the input matches the source code of the program, and which generates a "false" output iff the input does not match the source code of the ...
60
votes
111answers
9k views

Reverse stdin and place on stdout

Requirements: Take an input on stdin including new lines / carriage returns of unlimited length (only bounded by system memory; that is, there is no inherent limit in the program.) Output the reverse ...
28
votes
53answers
8k views

Find the Missing Letter

Guidelines Task Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array (lists in some languages). Rules This is code golf so ...
23
votes
14answers
4k views
+50

Is this an L-shape?

Background An L-shape is defined as a polyomino which can be made by extending two rectangular legs in orthogonal directions from a full square (called a pivot). The size of the square should be at ...
59
votes
56answers
4k views

Count trailing truths

Inspired by, and in memory of, my dear friend and colleague, Dan Baronet, 1956 – 2016. R.I.P. He found the shortest possible APL solution to this task: Task Given a Boolean list, count the number of ...
463
votes
815answers
149k views

“Hello, World!”

So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the most ...
37
votes
11answers
5k views

Shortest terminating program whose output size exceeds Graham's number

Write the shortest possible program (length measured in bytes) satisfying the following requirements: no input output is to stdout execution eventually terminates total number of output bytes exceeds ...
18
votes
29answers
4k views

bfcat - encode a file as a brainf*** program

Challenge Write a program or function that given a string, returns a valid Brainfuck program that when compiled and executed as Brainfuck, returns that string.. Assume all inputs are encoded as ...
20
votes
21answers
4k views
+100

Get the closest value to number

In this code golf, you need to get the closest number from another one in a list. The output may be the closest number to the input. Example: ...
23
votes
17answers
3k views

Bake me a slice of cake

My birthday is in a month, and this is a slice of tasty cake. ...
21
votes
34answers
2k views

Interleaving reversing

Given a string, reverse it interleavingly. Here's how to do it for abcdefghi and abcdefghij, 0-indexed: Separate the chars at ...
18
votes
34answers
2k views
+100

Recover the power from the prime power

It seems that many people would like to have this, so it's now a sequel to this challenge! Definition: a prime power is a natural number that can be expressed in the form pn where p is a prime and n ...
49
votes
71answers
7k views

Output Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo

Challenge The goal is to output Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo. Context. (Maybe another interesting challenge could be printing all ...
51
votes
68answers
10k views
+100

How even is a number?

The ancient Greeks had these things called singly and doubly even numbers. An example of a singly even number is 14. It can be divided by 2 once, and has at that point become an odd number (7), after ...
7
votes
5answers
174 views

Find the number of ways to choose `n` objects from `r` objects with repetition so that every object has a matching neighbour

For example, if n is 5 and r is 2, it would mean the number of lists below: ...
29
votes
27answers
5k views

Code Golf: Your own horizontal pet ASCII snake

Very heavily inspired by this challenge Code Golf: Your own pet ASCII snake - I thought making it horizontal would add an extra layer of complexity. An example horizontal snake: ...
29
votes
83answers
3k views

Numbers by Position

Numbers by Position Challenge Print the numbers: 1 22 333 4444 55555 666666 7777777 88888888 999999999 In that order. I/O Takes no input. The numbers can ...
32
votes
28answers
3k views

Print a tongue twister!

The goal of this challenge is to print the following tongue twister: ...
43
votes
20answers
10k views

Duck, duck, gone!

Here is the (quite scary) Five little ducks song(it is not long): ...
28
votes
52answers
3k views

Backwards Alphabet Triangle

Without taking any input, output this exact text: ...
23
votes
25answers
4k views

Even and Odd Numbers

Sandbox Adapted from exercise 4 of 100 little Keg exercises The ability to repeat chunks of code within a program is an important part of any programming language. Also just as important is the ...
31
votes
20answers
4k views

Print this maximally long URL

Task This one is simple. We want to compress a URL, but don't trust URL shorteners. Write a program that prints to stdout (or a 0-argument function that returns) the following, working URL: http://...
21
votes
23answers
5k views

Print a list of iPhones

Write the shortest program that prints, in order, a complete list of iPhone iterations, according to this site: ...
-1
votes
12answers
299 views

Let's start with a brainy quote

The challenge today is to write a program that outputs a known proverb, Where there is a will, there is a way., that means if someone is determined to do something, ...
30
votes
35answers
5k views

Help, I've mixed my week up!

My dog ate my calendar, and now my days are all mixed up. I tried putting it back together, but I keep mixing up the days of the week! I need some help putting my calendar back together, with the days ...
15
votes
14answers
2k views

Rod of Asclepius

With this challenge we pay homage to everyone around the whole world fighting against the coronavirus crisis; particularly represented are the people tied to medicine, as the Rod of Asclepius is a ...
17
votes
14answers
2k views

Fibonacci trees

Background Fibonacci trees \$T_n\$ are a sequence of rooted binary trees of height \$n-1\$. They are defined as follows: \$T_0\$ has no nodes. \$T_1\$ has a single node (the root). The root node of \$...
37
votes
12answers
2k views

lc's dvntrs n Wndrlnd

The task Today's special offer: consonants and punctuation for FREE! Your program or function will be given as input the first 6 paragraphs of Lewis Carroll's famous novel Alice's Adventures in ...
9
votes
8answers
1k views
19
votes
30answers
3k views

Does this month start on a Monday?

June 2020 is a month in which June 1st corresponds to Monday, June 2nd corresponds to Tuesday, ... June 7th corresponds to Sunday. For reference, here's the cal of ...
-3
votes
7answers
362 views

Print om sign with pi

This time I will give you an easy challenge: Print the Om sign with \$\pi\$!(Sorry for many challenges with \$\pi\$) Here is the om sign drawn using pi numbers: ...

1
2 3 4 5
204