# Posts tagged code-golf

Challenge A simple challenge: Given a two-dimensional matrix (an array of arrays) of real numbers, compute the determinant. The determinant of a matrix is a mathematical construct used in many ap...

This is a fixed output challenge. Output a textual representation of a chessboard hosting 8 queens, none of which are attacking each other. There are 92 ways of arranging them, 12 if rotations and...

Many programming languages have the concept of keywords, special syntax items that are not just identifiers reserved by some library, but words reserved by the language itself. The challenge is to...

Given a sequence of letters, omit those with the highest or lowest pop count. Terminology The pop count or population count of a binary string is the number of 1s in it. For this challenge, the ...

Given a string of printable ASCII characters, convert them all to lowercase, except not just the letters. ASCII characters that are letters have a bit in their binary representation that is 0 for ...

Given a string, convert all of its letters using ROT13, and all of its digits using ROT5. This is sometimes referred to as ROT13.5. Input A sequence of printable ASCII characters (character cod...

Convert a matrix or grid of digits to its antitranspose. For a square matrix , this is its reflection in its antidiagonal. More generally, for a rectangular matrix, this is its reflection in its sk...

Challenge Given an array of numbers return the cumulative count of each item. This is the number of times an item has occurred so far. Examples [1,1,2,2,2,1,1,1,3,3] -> [1,2,1,2,3,3,4,5,1,2]...

Given a sequence of lower case letters, sort them into order of height. Heights The heights of letters are dependent on font, so for this challenge the height order to be used is as defined below...

Given a chess board with some knights on it, say how many squares are neither attacked by a knight nor containing a knight. Input An 8 by 8 grid where each square is either a knight or empty T...

Given a sequence of letters, output only the vowels. Input A sequence of letters This may be a string or any ordered data structure of characters (provided it is consistent between inputs) Th...

Connect opposite corners of a rectangle of characters without putting 4 characters in a row. Input Two numbers, W and H, representing the width and height of the rectangle Each number will be ...

Given a radius R, output a text representation of a circle. Input A positive integer R (strictly greater than zero) You do not need to handle values of R greater than 32 Output A square ...

Given a word that can be rotated by 180 degrees (a half turn) about at least one of its 3 axes and continue to be composed of English alphabet letters, output one of its rotated forms. The 3 rotat...

Given an integer $N$ in balanced quinary, output the first $N$ characters of your source code if $N$ is positive, or the last $-N$ characters of your source code if $N$ is negative. Terminology ...

Background While we do have a "Hello, World!" challenge, we still don't have one regarding input. So let's do one! Challenge Create a program that takes an input (not as a function argument) the...

Challenge Given a string, e.g. Hello, do the following: Mirror it: Hello -> HelloolleH and create a right triangle using it as the sides: H ee l l l l o...

This is a fixed output challenge. It is similar to a standard Kolmogorov complexity challenge, except you get to choose your own fixed output. Given no input, output 55 fruits. You may choose any 5...

Given a positive integer as input, indicate which base from 2 to 16 gives the most holes in the representation of the input in that base. The digits used are 0123456789ABCDEF. Note that these incl...

Looping counter Create an infinite loop that outputs lines of asterisks, with each line containing one more asterisk. Instead of the asterisk, any printable, non-whitespace character can be used. ...

Introduction The classic "Hello, World" challenge. What more can I say? Rules Program takes no input. Program outputs Hello, World! with an optional trailing newline. No other output is accep...

Given a grid of numbers, mark the concentric areas around nonzero elements (beacons) decreasing from the value of the beacon till 1. For example, here are some grids with a single beacon: Size 1:...

An integer is called square-free if it is not a multiple of a perfect square other than 1. For example, 42 is square-free, but 44 is not because it is a multiple of the perfect square 4 = 2². Your...

A chequer board (also spelt "checker board" in some places) is an 8 by 8 grid of squares alternating between 2 colours. Check whether a provided pattern could be a region of a chequer board. The c...

Challenge Given an array in any suitable format, create a frequency table for it. i.e: Pair each unique element with the number of times it appears in the array. You can return the frequency tabl...

This challenge is based on the i. verb from J. A range grid is basically a range of m × n numbers fit into a rectangular grid with m rows and n columns. A 2×3 range grid would be: 0 1 2 3 4 5 ...

Challenge A Niven number is a positive integer which is divisible by the sum of its digits. For example, 81 -> 8+1=9 -> 81%9=0. Your task is to find the first n Niven numbers, given n. Te...

Multiply complex numbers. 2 space-seperated ones will be input, as follows: (update: you can replace i with j or some other symbol if needed) a+bi -a+bi a-bi -a-bi where a and b are integers ...

Given an positive integer $n$, return the least positive integer $k$ such that the $k$th partial sum of the harmonic series is greater than or equal to $n$. For example, if $n = 2$, then $k = 4$, b...

Task I often need to find the factorial of a number or the sum of all numbers up to a number when cheating on math tests. To help me with this, your task is to write $F$, a generalized version of ...

Get ready for a comparatively dry question - this is intended to be one of the "the"s of the code-golfing dictionary. Create a program which inputs a base 10 non-negative whole number (without lea...

Task Given an IP address as a string, find its IP address class. For reference, here is a table: Class Leadingbits Numberof networks Addressesper network Total addressesin class Start...

Description From the Esolangs wiki, In Fractran, a program consists of a finite list of positive, rational numbers. The input to a program is a positive integer n. The list is then searched ...

Create a program P1 which takes as input a base 10 number N1 (the numbers for the variables are important). Given N1, P1 will print a program P2. P2 will take as input a base 10 number N2 and outpu...

Challenge This is a simple randomness challenge: Given a non-negative integer $n$, and positive integer $m$, simulate rolling and summing the results of $n$ fair dice, each of which have $m$ sides...

In this challenge, add 2 integers, but if both the integers are 2, output 5. Shortest code in each language wins! Example ungolfed program in Python 3.x def add(x, y): if x == 2 and y == 2: ...

Challenge Given a list of integers >= 0 , check if all of them are equal. Tests [1,1,1,1,1] -> true [0,1,1,6,7] -> false [1] -> true [] -> undefined(you do n...

Goldbach's Conjecture states that every even whole number greater than 2 is the sum of 2 prime numbers. Your task is to return those 2 prime numbers, given an even whole number as input. There are ...

Introduction The Pell(no, not Bell) Numbers are a simple, Fibonacci-like sequence, defined by the following relation: $P_n=\begin{cases}0&\mbox{if }n=0;\\1&\mbox{if }n=1;\\2P_{n-1}+P_{n-2...

Challenge It's a bootstrapping challenge this time! Write a full program that, once run, writes the source code of another program that in turn, once run, writes the source code for another progra...

In Google Docs, the word count tool looks like this: Pages would not make sense, but your goal is to implement every other count. Definitions Words are strings of text separated by any amount ...

Background Check out this video on the Collatz conjecture, also known as A006577. If you don't know what this is, we're given an equation of $3x + 1$, and it is applied this way: If $x$ is odd...

A rewrite of this SE question with a simpler input format and guidelines. Challenge Deadfish uses a single accumulator, on which all commands are to be performed. It has the following commands: ...

Challenge A catalogue type challenge that simply asks: Given an integer n (where n>=0) as input return a truthy value if n is a perfect square or a falsey value if not. Rules You may take...

Your goal is to reverse an ascii string. Given a (optionally newline or null terminated) input, output your input in reverse order, optionally followed by a newline. Terminate afterward. Function...

In this simple challenge, create a short program that takes 2 ints as input, output them, swap their places, then output them again. Those 2 integers can't be the same number. The program with the ...

Challenge What do computers understand? That's right, binary. All files are turned into binary digits when you run them, but what if I suggest giving you an int then turn it into it's binary value...

Given a non-ragged array (an array where all sub-arrays at a particular level have the same length) of non-negative integers, answer its shape, that is, the length along every dimension. You may as...