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
9
votes
16answers
648 views

Mirror and reverse text

Inspired by I reverse the source code, ... Your task, if you wish to accept it, is to reverse text and mirror select characters. Yes, yes, I know. Very surprising. Input A string, ...
1
vote
6answers
137 views

Does base n have any Rotate-Left-Double numbers?

Task A Rotate-Left-Double number in base \$n\$ is a number \$m\$, when its base-\$n\$ digits are rotated left once, equals \$2m\$. The base-\$n\$ representation of \$m\$ cannot have leading zeros. ...
3
votes
2answers
121 views

Code golf edit distance 2

The edit distance between two strings is the minimum number of single character insertions, deletions and substitutions needed to transform one string into the other. This task is simply to write ...
16
votes
2answers
482 views

Counting Cunningham chains

Prime numbers have always fascinated people. 2300 years ago Euclid wrote in his "Elements" A prime number is that which is measured by a unit alone. which means that a prime is only divisible by <...
18
votes
9answers
2k views

Is this a legal date? - April Fools' edition

Task A date can be compactly represented in a 6-character string in the format ddmmyy where the first two characters (dd) ...
17
votes
11answers
1k views

Let's decompress a bit

Given a compressed string \$s\$ made of printable ASCII characters (32 to 126), your task is to print or return the original text by applying this simple decompression algorithm: Start with \$k=0\$ ...
10
votes
3answers
553 views

Boil eggs using hourglasses

These are the classical puzzles: You need to boil eggs for exactly 9 minutes, or else the visiting Duchess will complain, and you will lose your job as head chef. But you have only 2 ...
9
votes
3answers
286 views

Multiplayer Rock-Paper-Scissors

Objective Given a nonempty multiset of Rock, Paper, and Scissors, output the winning figure ...
5
votes
5answers
352 views

Filesystem-sort my directory please

Sometimes lexicographical sorting of strings may cut it, but when browsing the filesystem, you really need better sorting criteria than just ASCII indices all the time. For this challenge, given a ...
20
votes
28answers
2k views

Alternating Triangles

Given a strictly positive integer n (therefore 0 isn't a valid test case), produce an approximate triangle of height ...
14
votes
49answers
4k views

Create a Parrot Program

Given an input, output that input followed by a newline endlessly. Input will be a string consisting only of printable ASCII characters (0x20-0x7E) and newlines (<...
19
votes
27answers
3k views

How happy is this emoticon?

In this challenge, submissions will be programs or function which, when given an emoticon such as :-), :(, or ...
26
votes
6answers
4k views

Draw an ASCII oak tree (or a woman with curly hair?)

Task Your task is to draw these beautiful oak trees: ...
19
votes
13answers
1k views

Convert Planck unit to SI metric

Objective Given a dimension of an SI unit, convert the Lorentz-Heaviside version of a Planck unit \$1\$ into SI metric. What is a Planck unit? Planck units are a set of units of measurement. It ...
72
votes
153answers
7k views

Output the sign

Given a number N, output the sign of N: If N is positive, output 1 If N is negative, output -1 If N is 0, output 0 N will be an integer within the representable range of integers in your chosen ...
116
votes
246answers
28k views

Fibonacci function or sequence

The Fibonacci sequence is a sequence of numbers, where every number in the sequence is the sum of the two numbers preceding it. The first two numbers in the sequence are both 1. Here are the first ...
29
votes
41answers
6k views

Is it really time?

A time in the format hhMMss is represented by six numbers in the range 0..9 (e.g.100203 for 3 seconds after 2 minutes after 10am (10:02.03), or ...
144
votes
53answers
26k views

Tips for golfing in C

What general tips do you have for golfing in C? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C (e.g. "remove comments" is not an ...
34
votes
38answers
4k views

Determinant of an Integer Matrix

Given a square integer matrix as input, output the determinant of the matrix. Rules You may assume that all elements in the matrix, the determinant of the matrix, and the total number of elements in ...
3
votes
26answers
552 views

Add N numbers without using + or -

Given N integers, output the sum of those integers. Input You may take the integers in any reasonable format, including: stdin arguments an array or list Rules ...
40
votes
22answers
6k views

Print the Periodic Table

Your challenge is to print/output/return this text: ...
27
votes
78answers
12k views

Print a Christmas Tree

The Challenge Print a nice Christmas tree with it's own star at the top using the shortest code possible. The tree star is an asterisk (*) and the tree body is ...
12
votes
14answers
1k views

Pseudo-deterministic number generator

Task Write a function/full program that will be able to produce two different sequences of integers in [0, ..., 9]. You will take an input ...
86
votes
268answers
17k views

Simple cat program

One of the most common standard tasks (especially when showcasing esoteric programming languages) is to implement a "cat program": read all of STDIN and print it to STDOUT. While this is named after ...
157
votes
17answers
27k views

Is My Swipe Pattern Legal?

Most Android smartphones allow the user to use a swipe pattern to open their phone: Certain patterns are legitimate, and others are impossible. Given an input swipe pattern, return a truthy or falsy ...
35
votes
13answers
6k views

God is real . . . unless declared integer

This challenge is inspired by Fortran's idiosyncratic implicit typing rules. Your task will be to determine the data type of the object GOD according to the ...
20
votes
33answers
2k views

Vowels up, consonants down

Challenge You will be given a string that can contain lowercase letters, uppercase letters, or spaces. You have to turn the vowels (a, e, i, o, u) in the string to upper case and consonants to lower ...
15
votes
14answers
1k views

Generating generating expressions for sequences

(yes, "generating generating" in the title is correct :) ) Context In middle (?) school we are taught about sequences and, in particular, we are taught about linear sequences where the ...
23
votes
16answers
3k views

Triangular domino tiling of an almost regular hexagon

Background An almost regular hexagon is a hexagon where all of its internal angles are 120 degrees, and pairs of the opposite sides are parallel and have equal lengths (i.e. a zonogon). The ...
68
votes
24answers
8k views

Crack the bank account's password!

Introduction In order to prevent keyloggers from stealing a user's password, a certain bank account system has implemented the following security measure: only certain digits are prompted to be ...
12
votes
26answers
2k views

Filter an array so that duplicate items are removed

In the shortest amount of code in any programming language, filter out the duplicate items in an array of which the order is irrelevant. Here are some test cases: ...
23
votes
18answers
2k views

Cook me a character meal

Chef Avillez is about to cook us some really nice meal. He is just waiting for us to give him some ingredients and to request a meal. Task Given a list of ingredients (strings matching ...
15
votes
9answers
811 views

What is the score of my Scopa hand?

I like card game challenges so I made this one for the Italian card game Scopa. My family has been playing this game since time immemorial. It has a very interesting scoring system that should be fun ...
30
votes
57answers
5k views

ASCII Triangles

Your task is to write a program or a function that prints an ASCII triangle. They look like this: |\ | \ | \ ---- Your program will take a single numeric input <...
44
votes
43answers
8k views

Reverse Polish notation

You must evaluate a string written in Reverse Polish notation and output the result. The program must accept an input and return the output. For programming languages that do not have functions to ...
30
votes
29answers
5k views

How far should I sum?

How far should I sum? The harmonic series is the "infinite sum" of all the fractions of the form \$\frac1n\$ for \$n\$ positive integer. I.e. the harmonic series is $$\frac11 + \frac12 + \frac13 + \...
37
votes
15answers
4k views

Golf a mutual quine

Using two languages of your choice, write the smallest “mutual quine” you can. That is, write a program P in language A that outputs the source code for a program Q in language B, such ...
42
votes
91answers
7k views

Halloween Golf: The 2spooky4me Challenge!

A current internet meme is to type 2spooky4me, with a second person typing 3spooky5me, following the (n)spooky(n+2)me pattern. Your mission is to implement this ...
54
votes
43answers
7k views

Compute the Kolakoski sequence

This is a repost of an old challenge, in order to adjust the I/O requirements to our recent standards. This is done in an effort to allow more languages to participate in a challenge about this ...
12
votes
5answers
283 views

Composition of permutations – the group product

Given two permutations in disjoint cycle form, output their product/composition in disjoint cycle form. To find the composition, convert the disjoint cycles to permutations in two-line notation. Each ...
40
votes
110answers
8k views

Print invisible text

Given a string as input, output a number of whitespace characters (0x0A and 0x20) equal to the length of the string. For example, given the string Hello, World! ...
50
votes
28answers
7k views

Check if computer is connected to the internet

Write a program which, according to whether the script has access to the internet, produces an output which is "Truthy/Falsey". You may try and connect to any existing site, at your own discretion (...
23
votes
56answers
2k 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 ...
55
votes
71answers
7k views

How to randomize letters in a word

According to some controversial story, the odrer of ltteres in a wrod deos not mttaer much for raednig, as lnog as the frist and lsat lteter macth with the orignial wrod. So, for fun, what would be ...
17
votes
18answers
2k views

Print Real Invisible Text

My previous challenge, Print invisible text was quite popular, likely due to how trivial it is. However those more observant of you may have noticed that you're not really printing invisible text, ...
80
votes
53answers
27k views

Shortest code that raises a SIGSEGV

Write the shortest code that raises a Segmentation Fault (SIGSEGV) in any programming language.
432
votes
774answers
134k 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 ...
25
votes
48answers
2k views

Encode the alphabet cipher

Given a string that contains only lowercase letters, encode that string with the alphabet cipher. To encode with the alphabet cipher (I will be using the example ...
51
votes
38answers
6k views

Spoonerise words

Given two words, spoonerise them by switching their initial consonant clusters. Fewest bytes wins. ...
373
votes
38answers
53k views

Covfefify a string

In this challenge, you must take a string matching the regex ^[a-zA-Z]+$ or whatever is reasonable (you don't have to consider uppercase or lowercase letters if you ...

1
2 3 4 5
191