All Questions

Filter by
Sorted by
Tagged with
11 votes
19 answers
936 views

Restricted Integer Partitions

Pk(n) means the amount of partitions of n into exactly k parts. Given n and ...
20 votes
13 answers
2k views

smallest number of steps for a knight in chess

If you place a knight on any square of a chessboard, what is the smallest amount of steps to reach every position? Rules It is an 8 by 8 board. The knight starts at an arbitrary position, taken as ...
390 votes
46 answers
57k 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 ...
0 votes
0 answers
51 views

Program a compiler compiler

Program a compiler compiler Write a program, function, or likewise that takes in a BNF-like grammar specification(see below) and outputs a program or function in a language of your choice that takes ...
46 votes
118 answers
7k views

The vanilla factorial challenge

Task Given a non-negative integer \$n\$, evaluate the factorial \$n!\$. The factorial is defined as follows: $$ n!=\begin{cases}1 & n=0\\n\times(n-1)!&n>0\end{cases} $$ Rules All default I/...
23 votes
22 answers
2k views

A challenge for rookies

Print or return the following string: ...
27 votes
62 answers
7k views

Is string X a subsequence of string Y?

Given strings X and Y, determine whether X is a subsequence of Y. The empty string is regarded as a subsequence of every string. (E.g., '' and ...
7 votes
4 answers
439 views

Train Route Planning

We can model a rail network as a directed graph, where each node is a train station and each edge is a train connecting two train stations. We'll assume that each train travels between its ...
33 votes
34 answers
7k views

Numbers with Rotational Symmetry

Given an integer, output a truthy value if it is the same upside-down (rotated 180°) or a falsy value otherwise. 0, 1, and ...
46 votes
41 answers
18k views

Draw A Sierpinski Triangle

The Sierpinsky Triangle is a fractal created by taking a triangle, decreasing the height and width by 1/2, creating 3 copies of the resulting triangle, and place them such each triangle touches the ...
4 votes
5 answers
190 views

Rotatable numbers (Upside down) [duplicate]

Searching for rotatable numbers, like: 68089 If you consider numbers upside-down, 6 looks like ...
6 votes
17 answers
842 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? ...
28 votes
61 answers
3k 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 ...
9 votes
9 answers
444 views

CGCC Rocket Biking

Something I found while looking through some old files. It seemed like a neat idea for a code golf challenge. The intro One of the most popular events at the annual Cyclist's Grand Competition for ...
2 votes
0 answers
139 views

Solve the Greek Computer Puzzle Toy [closed]

Solve the Greek Computer Puzzle Toy There is a small toy of a series of stacked dials -- loosely inspired by the Antikythera Device. The puzzle, made by Project Genius, has a series of dials that must ...
8 votes
4 answers
243 views

Change the quotations as if in Microsoft Word

I noticed that in Microsoft Word, single quotations are either or , but not in Notepad. Your task today is: given a string <...
89 votes
154 answers
13k views

Determine whether strings are anagrams

Challenge Given two strings, work out if they both have exactly the same characters in them. Example Input word, wrdo This returns true because they are the ...
50 votes
7 answers
7k views

Build a Turing *incomplete* language

The world is full of Turing-complete programming languages. Just about every useful language (and most useless ones) are Turing-complete. Some even became Turing-complete by accident. Often this is ...
28 votes
56 answers
7k views

Write a Program that Writes a function BUT in a different language!

Write the shortest program that takes one input (n) from STDIN (or equivalent) and outputs a simple incrementing function with one argument (x) that returns x + n but the function must be in a ...
15 votes
31 answers
3k views

The inverse Collatz Conjecture

I think the Collatz Conjecture is already well-known. But what if we invert the rules? Start with an integer n >= 1. Repeat the following steps: If n is even, multiply it by 3 and add 1. If n is ...
127 votes
21 answers
123k views

Generate the longest error message in C++

Write a short program, that would generate the longest possible error message, in a standard C++ compiler (gcc, cl.exe, ...
23 votes
8 answers
2k views

Seeing the queen's lasers

In chess, the queen piece can move arbitrarily far in each cardinal and intercardinal direction. What does this mean? Well, I'll show you with an ASCII drawing: ...
19 votes
21 answers
2k views

How many partitions do I have?

The partition number of a positive integer is defined as the number of ways it can be expressed as a sum of positive integers. In other words, the number of integer partitions it has. For example, the ...
25 votes
34 answers
5k views

Negative of an ASCII photo

Task Given an \$m\times n\$ binary ascii "photo", return the negative of the photo Example: ...
9 votes
7 answers
732 views

Tips for golfing in Knight

Knight is the Language of the Month for August 2022, and I noticed that it didn't have a tips page, so here it is! I'm looking for ideas which can be applied to code-golf problems and which are also ...
15 votes
38 answers
2k views

Implement String Projection

Given two strings: a string s and an alphabet a, implement string projection in the shortest code possible. String projection ...
18 votes
30 answers
2k views

Divisor of a string

Challenge Given a positive-length string \$S\$, a divisor of \$S\$ is another (not necessarily distinct) string for which there exists a number \$a\$ such that when we repeat the divisor \$a\$ times, ...
89 votes
207 answers
20k views

Find the Factorial!

Create the shortest program or function that finds the factorial of a non-negative integer. The factorial, represented with ! is defined as such $$n!:=\begin{...
1 vote
0 answers
103 views

Is there a way to optimize this? [closed]

I tried solving the following problem by following the suggested approach to solving the problem in the problem tutorial. However, the online judge still says my solution exceeds the time limit. Is ...
77 votes
60 answers
12k views

Draw the Ukrainian Flag

As you will probably know, there is a war going on in Ukraine. I noticed that it seems nobody has posted a Ukrainian flag challenge yet, so I thought I'd do it myself in support of Ukraine. The ...
21 votes
11 answers
2k views

Optimal strategy for wandering robots

Consider four agents sitting on four different number lines, all starting at the origin. In this game your only move is to choose one of the four agents to move. When you do that the agent you have ...
27 votes
30 answers
7k views

Smallest subset of characters required for Turing Completeness

In Fewest (distinct) characters for Turing Completeness, the goal is to find the minimum number of characters which make a language Turing Complete...in other words, allow it to do any computation ...
143 votes
74 answers
21k views

Fewest (distinct) characters for Turing Completeness

Summary: For any given language, what is the smallest amount of unique characters for your language to be Turing-Complete? Challenge: For any language of your choice, find the smallest subset of ...
21 votes
14 answers
2k views

Add parentheses to Polish notation

In most programming languages, arithmetic is written with infix notation -- i.e. the operator is put in between the operands -- e.g. 1+2. In contrast, with Polish ...
22 votes
16 answers
2k views

Remove redundant parentheses

Given a string containing some parentheses and some other ASCII printable characters, like this: (abc((123))(k)) your task is to remove any sets of parentheses that ...
17 votes
14 answers
2k views

Count the cells

Given a multi-line string as input containing characters "|", "_" and ...
50 votes
32 answers
4k views

Turing-Complete Language Interpreter

A challenge I thought that would be very cool is to make an interpreter for a Turing-complete language of your choosing. The rules are simple: You may use any language to create this interpreter ...
31 votes
30 answers
8k views

Chicken McNugget Numbers

Description Chicken McNugget numbers are numbers that can be expressed as a sum of \$6\$, \$9\$ or \$20\$ - the initial sizes of the famous Chicken McNuggets boxes sold by McDonald's. In that sum, a ...
21 votes
18 answers
2k views

Permutapalindromic numbers

Given an integer N as input, output the Nth permutapalindromic number. A permutapalindromic number is a strictly positive ...
11 votes
19 answers
2k views

Generate /* line number comments */

Your task is to write a program (or function) that will take a string as input and append text to the beginning of every line that satisfy the following rules: The text appended must contain the line ...
23 votes
13 answers
1k views

Carpet an Airport

In 2015 the Portland International Airport began the replacement of their iconic carpet. I want you to write a program to draw their old carpet in as few bytes as possible. The carpet: ...
15 votes
7 answers
659 views

A better Hexagony template

We once made a Hexagony template without actually knowing it. But after a bit of experience with Hexagony, it becomes apparent that it is not enough; sometimes the source code is too short for the ...
53 votes
70 answers
11k views

I reverse the source code, you negate the output!

Your task, if you wish to accept it, is to write a program that outputs a non-zero number(can be integer or float). The tricky part is that if I reverse your source code, the output must be the ...
42 votes
67 answers
8k views

I reverse the source code, you negate the input!

Blatant rip-off of a rip-off. Go upvote those! Your task, if you wish to accept it, is to write a program/function that outputs/returns its integer input/argument. The tricky part is that if I ...
53 votes
11 answers
4k views

Unfolding the Hexagony source code

Introduction If you're not familiar with Hexagony, it's an esoteric language created by Martin Büttner. The thing is that this language accepts multiple forms for the program. The following programs ...
19 votes
22 answers
2k views

Rearrange to a palindrome

Given a string, shuffle it so that it becomes a palindrome. For example, adadbcc can be arranged into dacbcad, or ...
4 votes
1 answer
113 views

Generate a Kirkman triple system

Given a universe of \$v\$ elements, a Kirkman triple system is a set of \$(v-1)/2\$ classes each having \$v/3\$ blocks each having three elements, so that every pair of elements appears in exactly ...
56 votes
63 answers
8k views

Could you make me a hexagon please?

Today, we're going to make an ASCII hexagon. You must write a program or function that takes a positive integer n, and outputs a hexagon grid of size n, made up of asterisks. For example, a hexagon of ...
2 votes
1 answer
218 views

Optimal strategy to defeat the wizard

Consider the following setup. An evil wizard has ten opaque boxes in front of him. Hidden from you, he chooses a random number of coins \$x \in \{1 \dots 10\}\$ and spreads them uniformly at random ...
19 votes
19 answers
2k views

Multiply numbers by their depth

Given a ragged list, we can define an element's depth as the number of arrays above it, or the amount that it is nested. For example, with the list ...

15 30 50 per page
1
2 3 4 5
265