Code-golf is a competition to solve a particular problem in the fewest bytes of source code. If you want to score by characters instead of bytes, state this explicitly in the challenge. If source code length is not the primary scoring criterion, consider using another tag instead.

learn more… | top users | synonyms

14
votes
19answers
732 views

At least h with at least h

Input A list of nonnegative integers. Output The largest nonnegative integer h such that at least h of the numbers in the list are greater than or equal to h. Test Cases [0,0,0,0] -> 0 ...
16
votes
13answers
889 views

Draw a bowling formation

Your goal is to display ASCII art of a formation in ten-pin bowling where only some of the pins remain. Fewest bytes wins. The tens pins are in a triangular formation: O O O O O O O O ...
-6
votes
1answer
67 views

Area under a curve

Write a program that when given five integers as input, outputs the value given by the following integral: Input is five integers (in any reasonable format) in the order a b c d e where each ...
9
votes
2answers
169 views

Magic box problem

You have an input array of size m*n. Each cell in the array is populated with either P or T. The only operation you can do on the array is flip columns. When you flip a column, the letters in all the ...
-2
votes
0answers
71 views

Sudoku compression code golf

This question is heavily influenced by this question Sudoku Compression but is not the same - it's code golf. Like the original, your job is to write two separate programs in any language that: Can ...
8
votes
3answers
232 views

3x3 Connected Components

The Challenge Consider the 3x3 king grid, as shown in the following ASCII graphic: A--B--C |\/|\/| |/\|/\| D--E--F |\/|\/| |/\|/\| G--H--I You are given as input a length-9 list of integers that ...
12
votes
19answers
1k views

Shorter than a Split Second!

Challenge You task for this question is to split an input array of integers on the second occurrence of every integer in that array. Not clear enough ? Here is an example to help Input array: [2 1 ...
15
votes
33answers
1k views

Create an array with repeated numbers

Challenge Your task in this question is to write a program or a named function which takes a positive integer n (greater than 0) as input via STDIN, ARGV or function arguments and outputs an array ...
14
votes
17answers
2k views

Most common number

Calculate the most common number in a list. You should use an expression that fits on one line (the record is just 18 characters). d = [4,3,1,0,6,1,6,4,4,0,3,1,7,7,3,4,1,1,2,8] winner = ... # TODO: ...
11
votes
1answer
454 views

Sharing pizza fairly

The difficulty with sharing pizza with friends is that it is hard to make sure that everyone gets the same amount of pepperoni on their slice. So, your task is to decide how to fairly slice a pizza so ...
10
votes
3answers
438 views

Write a Magic Spellchecker

The game Waving Hands is somewhere between a pen-and-paper Magic: the Gathering and a very elaborate Rock Paper Scissors. Each turn you write down one of eight gestures for each hand: wiggled ...
33
votes
8answers
1k views

Reverse indentation

I've heard that your code can run faster if you indent it in reverse, so that the compiler can process it like a tree design pattern from the very top of the "branches" down. This helps because ...
5
votes
5answers
405 views

Create a T9 keyboard [on hold]

This question asks for a T9 dictionary matching functionality which is a very interesting problem. But T9 has another way of typing and that is typing character-by-character. You would NOT need a ...
31
votes
41answers
10k views

yes is 91 lines long

yes, from coreutils, is 91 lines long. Many of them are comments, but that is still WAY too long. Write a program that imitates yes: outputting to stdout an infinite stream of "y\n"'s there must be ...
17
votes
5answers
963 views

Caesar-Cypher-Mania

The Caesar Cypher is a very simple substitution cypher where each letter is shifted by a fixed offset (looping around Z to A). Similarly, we can also a Caesar cypher for the set of printable ASCII ...
7
votes
2answers
820 views

Draw Sri Yantra

Challenge: Draw Sri Yantra. How to: There are different ways to draw it. All include many steps. If you think you can draw it without following the linked steps scroll below for the elements you ...
14
votes
10answers
1k views

Find the last Sunday in every month of a given year

F# solutions known inside 140 chars, and this is a Rosetta Code problem. Required result on stdout or in a string variable for input year 2014: 2014-01-26 2014-02-23 2014-03-30 2014-04-27 ...
18
votes
3answers
413 views

Squarefinder – Locating regular tetragons

Imagine a bunch of rectangles drawn in the plane, each rectangle with its vertices at integer coordinates and its sides parallel to the axes: The rectangles partition the plane into a number of ...
47
votes
9answers
3k views

Draw the Warm Welcome Secret Hat

Winter Bash 2014 is on its prime and don't we all love the hats ? Especially the secret hats! So why not draw one of secret hats ? The challenge Your task is to draw the Warm Welcome Hat in ...
-7
votes
21answers
322 views

Produce the word 'codegolf' without using any of its characters in code

You need to produce the word codegolf Rules: None of the characters of the word codegolf (i.e. 'c', 'o', 'd', 'e', 'g', 'o', 'l' and 'f') in either case can exist anywhere in the code. Case of ...
22
votes
2answers
341 views

Implement a PCG

What better problem for PCG.SE than to implement PCG, A Better Random Number Generator? This new paper claims to present a fast, hard-to-predict, small, statistically optimal random number generator. ...
29
votes
10answers
1k views

Verify a Minesweeper board

Your goal is to check whether a completed Minesweeper board is valid. This means that each number is a correct count of mines in cells adjacent to it, including diagonals. The board does not wrap ...
8
votes
7answers
446 views

Find pairs of numbers with a particular LCM and GCD

I was working on a math question with a friend of mine, and we decided to write a script that finds the answer. The original question is as follows: The difference of two natural numbers is 2010 ...
18
votes
9answers
815 views

Sum the time durations

Challenge Write the shortest code that can sum all the time durations that appear in the stdin. The program must only consider the strings that match with one of the following patterns and ignore the ...
13
votes
5answers
683 views

Return the clock emoji closest to the current time when run

I can have a large if/else condition for each 30 minutes but I'm looking for more math and Unicode based solution. Here are clock emojis: πŸ•πŸ•‘πŸ•’πŸ•“πŸ•”πŸ••πŸ•–πŸ•—πŸ•˜πŸ•™πŸ•šπŸ•›πŸ•œπŸ•πŸ•žπŸ•ŸπŸ• πŸ•‘πŸ•’πŸ•£πŸ•€πŸ•₯πŸ•¦πŸ•§. If you lack ...
5
votes
6answers
456 views

Tic Tac Toe encoder/decoder

James Bond is about to start a new mission and you are his computer scientist friend. As Tic Tac Toe is becoming more and more popular you decide that nothing would be more underhanded than a Tic Tac ...
2
votes
1answer
155 views

Make a working digital clock with ascii numbers [duplicate]

The challenge is make a digital clock that exhibits ascii numbers in a 24-hour format like: _ _ _ _ |_| |_| . |_| |_| |_| |_| . |_| |_| or _ _ _ _| _| . |_| |_ |_ _| . ...
43
votes
20answers
5k views

Significant Whitespace

We define whitespace to be any of the three characters, tab (0x09), newline (0x0A) or space (0x20). For this challenge, you're to write two programs or functions in the same programming language, ...
7
votes
2answers
201 views

Find a point's position on the integral Hilbert curve

The Hilbert curves are a class of space-filling fractal curves where every bend in the path is at a right angle and the curve as a whole fills up a square, with the property that sequences of ...
59
votes
5answers
4k views

Recognise Stack Exchange Sites by Their Icon

After spending a while on Stack Exchange, I can recognise most sites in the Hot Network Questions by their little icon (which is also their favicon), but certainly not all of them. Let's write a ...
6
votes
5answers
568 views

Implement t9-like functionality

Your challenge today is to implement a t9-like functionality. You will implement a function that will only have 2 parameters. You will receive 1 phone number in a string and the content of a text ...
22
votes
2answers
366 views

Partial Ordering of Regex Patterns

For the purpose of this challenge, we say that a regex pattern matches a string if the entire string is matched by the pattern, not just a substring. Given two regex patternsβ€€Aβ€€andβ€€B, we say thatβ€€Aβ€€...
11
votes
7answers
1k views

Longest reverse palindromic DNA substring

As you may know, in DNA there are four bases β€” adenine (A), cytosine (C), guanine (G) and thymine (T). Typically A bonds with T and C bonds with G, forming the "rungs" of the DNA double helix ...
2
votes
4answers
401 views

Use threes to count the threes!

Write a program or function that takes two numbers - x>3 and n>0 - as input, and finds all possible bases b where the digit 3 appears at least n times in (x in base b). Input and output may be ...
6
votes
4answers
327 views

Algorithm - Costliest Possible Route in Grid Puzzle

Objective Find the most expensive path from the top-left of a square grid to the bottom-right such that its total cost is below a given threshold. Scenario You are given a square NxN grid. You are ...
18
votes
4answers
2k views

Convert numbers to binary… but you're allowed to use twos as well

Based on the "binary, but with twos" notation mentioned in this numberphile video, write a function that takes a single number as input and outputs all variations of that number in a "binary" system ...
23
votes
5answers
740 views

Create icy avatar images for the winter season

It's winter, and the time of year has come for it to start getting cold (and for strange colorful headcloths to start appearing... soon). Let's write some code to make avatar pictures and other ...
4
votes
2answers
237 views

Compute the shortest decimal representation of a IEEE 754 double-precision binary floating-point number

Format The format is a 64 bit value x representing a IEEE-754 double-precision binary floating-point number (a.k.a "a double"). x is assumed to represent a real number (not a NaN or Infinity). Goal ...
-4
votes
0answers
44 views

Shortest Java Prime Numbers programme [duplicate]

Your job is to write a Prime Numbers programme, which prints out a certain amount of prime numbers in Java. Rules: You may not look online Have fun! Smallest programme in Java(bytes, determined ...
20
votes
6answers
1k views

Mutual Negative Quines

This was inspired by Print a Negative of your Code and Golf a mutual quine. Consider a rectangle of characters, that meet the following restrictions: Consists solely of printable ASCII characters ...
14
votes
13answers
2k views

Find the Semordnilaps

Semordnilaps (also known as heteropalindromes, semi-palindromes, half-palindromes, reversgrams, mynoretehs, reversible anagrams, word reversals, or anadromes) are words which are also words when ...
20
votes
21answers
2k views

Shortest Minmod Function

The minmod function is a variant of the familiar min, which appears in slope-limiting high-resolution schemes for partial differential equations. Given a number of slopes, it picks out the flattest ...
8
votes
9answers
1k views

Build a rot32 encryptor

Building a golfed rot13 encryptor is too easy because the letters are all the same order in the ASCII character space. Let's try a rot32 engine instead. Your task is to build a function that takes a ...
10
votes
2answers
355 views

Concatenate Strings with Context

Strings with Context For the purposes of this challenge, a string with context is a triple of strings, called the left context, the data part, and the right context. It represents a substring of a ...
5
votes
4answers
499 views

Decode MD5, Brute Force

The Challenge Create a program that brute-force* decodes the MD5-hashed string, given here: 92a7c9116fa52eb83cf4c2919599c24a which translates to code-golf The Rules You may not use any built-in ...
14
votes
8answers
976 views

RNA to Protein Translation

RNA, like DNA, is a molecule found in cells encoding genetic information. It consists of nucleotides, which are represented by the bases adenine (A), cytosine (C), guanine (G) and uracil (U).* A codon ...
59
votes
11answers
11k views

Print a Negative of your Code

Consider a square of printable ASCII characters (code points 0x20 to 0x7E) for side length N, like the following (here, N = 6): =\ g \ 7 m+y "g L ~ e> PHq We also require each row ...
5
votes
6answers
307 views

Mobius inversion

Your goal is to implement MΓΆbius inversion, a linear operation on a sequence of numbers that is used in combinatorics and number theory. Fewest bytes wins. What is MΓΆbius inversion? Given a (finite) ...
13
votes
5answers
913 views

Play Wythoff's Nim perfectly

Your goal is to write a perfect player for the game of Wythoff's Nim. Rules of Wythoff's Nim Wythoff's Nim is a deterministic two-player game played with two piles of identical counters. Players ...
15
votes
14answers
1k views

Look-and-say: Conway revisited

You should all be familiar with the Conway sequence (a.k.a. 'look-and-say'-sequence) by now: 1 11 21 1211 111221 312211 etc You can also start by any arbitrary number as starting ...