All Questions

1
vote
0answers
3 views

Is it Valid Modified UTF-8?

UTF-8 is a relatively simple way to encode Unicode codepoints in a variable-width format such that it doesn't easily confuse code that isn't Unicode aware. UTF-8 overview Bytes in the range of 0-...
15
votes
23answers
401 views

Equal, sum or difference!

Write shortest possible code that will return true if the two given integer values are equal or their sum or difference is 5. Example test cases: ...
14
votes
4answers
385 views

Dig a border trench

Background: Too many illegal immigrants from Blandia are crossing the border to Astan. The emperor of Astan has tasked you with digging a trench to keep them out, and Blandia must pay for the expenses....
27
votes
28answers
3k views

Most Common Multiple

Not to be confused with Least Common Multiple. Given a list of positive integers with more than one element, return the most common product of two elements in the array. For example, the MCM of the ...
137
votes
346answers
25k views

Implement a Truth-Machine

A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does: Gets a ...
21
votes
42answers
3k views

Draw some expanding arrows

This challenge is about printing a series of growing ASCII-art arrows. I'll describe the pattern in words, but it might be easier to look at what the start of this series looks like: ...
26
votes
25answers
2k views

Home on the Range of Lists

This challenge is simply to return a list of lists of integers, similar to the Python range function, except that each successive number must be that deep in lists. Rules: Create a program or a non-...
60
votes
26answers
18k views

“As a child, I was told Spiders felt no emotion.”

The challenge: output this exact ASCII art of a spiderweb in a window: ...
34
votes
18answers
4k views

Visually Explain the Pythagorean Theorem

A common visual explanation of the Pythagorean theorem is as such: The squares are meant to represent the side length's squared, and the areas of a + b = c, just ...
57
votes
42answers
10k views

Oreoorererereoo

Oreoorererereoo Given an input string that is similar to the word "oreo", give an ASCII representation of the cookie that is as wide as the input string (to ensure cookie stability). Rules The ...
0
votes
2answers
76 views

Work out \$x^y\$ using only addition and subtraction [duplicate]

The challenge is to implement a function or program that takes two numbers, \$x\$ and \$y\$ and return the result of \$x^y\$. The program cannot use any other mathematical operation other than \$+\$ ...
67
votes
38answers
6k views

Legen… wait for it…

dary! In events entirely unrelated to what will hopefully happen to me in the next couple of days, I task you to write code that does the following: Print ...
27
votes
24answers
3k views

Setting the time

Imagine the following 24-hour clock that can be controlled by arrow keys: ╔══╗ ┌──┐ ║00║:│00│ ╚══╝ └──┘ HH mm Pressing the up arrow twice (...
9
votes
14answers
948 views

Parentheses sequences in lexicographical order

Challenge Taken from here and also here An n parentheses sequence consists of n (s and n )s. A valid parentheses sequence is ...
15
votes
4answers
3k views

Fake the forecast

The new weather predicting supercomputer has arrived, and it doesn't work. In the meantime your boss wants you to buy the technicians some time by faking the daily wind maps. Your task is to draw a ...
24
votes
15answers
3k views

Matrix Jigsaw Puzzles

Input: An integer n Two equal-sized square matrices (with their width/height being a multiple of n) Output: One of two ...
44
votes
39answers
4k views

Tips for golfing in PowerShell

What general tips do you have for golfing in Windows PowerShell? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to PowerShell (e.g. "...
14
votes
2answers
443 views
+100

Number of \$n\$-carbon alkanes

Given a positive number \$n\$, find the number of alkanes with \$n\$ carbon atoms, ignoring stereoisomers; or equivalently, the number of unlabeled trees with \$n\$ nodes, such that every node has ...
17
votes
39answers
1k views

Sum \$\text{Square}^2\$

Let \$n=42\$ (Input) Then divisors are : 1, 2, 3, 6, 7, 14, 21, 42 Squaring each divisor : 1, 4, 9, 36, 49, 196, 441, 1764 Taking sum (adding) : 2500 Since \$50\times 50=2500\$ therefore we return ...
20
votes
20answers
989 views

Find the “Recursive Size” of a List

Inspired by Find the “unwrapped size” of a list. Define the Recursive Size, RS, of a list containing no lists as its length (number of items contained) and the ...
24
votes
8answers
22k views

Pong in the shortest code

The challenge is simple. Give the shortest code possible to reproduce the classic 2-player game of pong http://en.wikipedia.org/wiki/Pong . The level of graphics and functionality should be as close ...
24
votes
38answers
2k views

Enumerate each series of identical numbers in-place

Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series. Examples ...
46
votes
32answers
6k views

Very Simple Triangles

Write a program or function that takes in a positive integer (via stdin, command line, or function arg) and prints or returns a string of that many of these small triangles tiled together, alternating ...
6
votes
3answers
271 views

Range interval insert which should split into unique ranges

Given a range and a list thereof, while keeping the existing intervals in the list unchanged, split the additional range into sub-intervals and add them to the list, such that all the ranges in the ...
21
votes
7answers
2k views

Score a single dart

Introduction Write a program or function that, given the coordinates of where a dart lands on a dartboard, return the score of that dart. Dart coordinates are given as two integers, ...
9
votes
14answers
282 views

Matrix Jigsaw Puzzle Pieces

(Randomly inspired by https://codegolf.meta.stackexchange.com/a/17272/42963) Given a rectangular matrix of digits (i.e., 0 - 9), output the "pieces" of the matrix ...
14
votes
13answers
4k views

Name of Frankenstein's Monster

Introduction: Since it's almost Halloween, I was just thinking of some random Halloween-themed challenges. Eventually I was reading through Frankenstein's wikipedia page, and came across the ...
55
votes
107answers
13k views

Duck, duck, goose!

Remember the kids game, 'Duck, Duck, Goose'? No? Me neither. The challenge Print the word 'duck' on individual lines an indeterminate amount of times. Print the word 'goose'. Your program ends. The ...
13
votes
20answers
1k views

Compute the Optimal Square Matrix

The optimal matrix (for the rather narrow scope of this challenge) is obtained by "zipping" the elements from the corresponding rows and columns of a square matrix and getting the maximum of each pair....
17
votes
16answers
1k views

How many consecutive descending numbers in my number?

2019 has come and probably everyone has noticed the peculiarity of this number: it's in fact composed by two sub-numbers (20 and 19) representing a sequence of consecutive descending numbers. ...
0
votes
0answers
68 views

One way road algorithm [on hold]

In a certain region all places are the one by road. But one-way traffic for all roads; if you are allowed to go from A to B via the direct route, you can not along that road from B to A. If you want ...
231
votes
240answers
77k views

Add a language to a polyglot

This is an answer-chaining challenge in which each answer builds on the previous answer. I recommend sorting the thread by "oldest" in order to be sure about the order in which the posts are made. ...
113
votes
71answers
22k views

Largest Number Printable

Your goal is to write a program that prints a number. The bigger the number, the more points you'll get. But be careful! Code length is both limited and heavily weighted in the scoring function. Your ...
1
vote
0answers
71 views

Chess move validation [duplicate]

Write a program that accepts chess moves, validate them and shows the results. The program should: Check wheter or not a move is valid Check if a king is in check or in checkmate Process the changes ...
564
votes
259answers
204k views

Produce the number 2014 without any numbers in your source code

Note to challenge writers as per meta consensus: This question was well-received when it was posted, but challenges like this, asking answerers to Do X without using Y are likely to be poorly ...
4
votes
6answers
221 views

Nested lists as printable 2D objects [on hold]

I don't know if something like this exists already (and I'm not finding the right key words) but if not, it felt like it could be an interesting coding puzzle. The challenge is, to take an ...
8
votes
21answers
1k views

Unix timestamp to datetime string

Given a unix timestamp as an input, give a datetime string, in a format like so: "YYMMDD.HHmm" Rules The input is a number (integer) of a millisecond-precise UNIX epoch time (milliseconds since 1970 ...
52
votes
31answers
6k views

Tips for golfing in Bash

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

N times program for the N-th number

Given an array of positive integers A as the input, generate a program that, when repeated for k times, output the ...
19
votes
45answers
2k views

String rotation - output string repeatedly moving first character to the end

The challenge here is to take a string and output all its rotations, by repeatedly moving the first character to the end, once per character in the string, ending with the original string: ...
3
votes
0answers
1k views

The World in the Future [closed]

In the future, the world will change, there's no doubt about it. For that reason, you have to produce a realistic map of the world n years in the future. The ...
9
votes
23answers
659 views

Generate the group table for Z_n

Groups are a widely used structure in Mathematics, and have applications in Computer Science. This code challenge is about the fewest # of characters to create a group table for the additive group Zn. ...
23
votes
26answers
2k views

Enumerate an array, grouping duplicates

The objective of this challenge is to take an array of positive integers, and enumerate its indices, grouping like elements. An enumeration without any duplicates is done by just outputting an array ...
108
votes
218answers
23k 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 ...
25
votes
12answers
2k views

Tips for golfing in Scala

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

Corrupting A Binary File By Interpreting It As Text

Using FTP's ASCII mode to transfer binary files is a bad idea. It is likely to corrupt your data. Badly. Let's simulate this corruption! Your task is to write a program which takes a file as input ...
79
votes
42answers
7k views

2048-like array shift

Assume we want to shift an array like it is done in the 2048 game: if we have two equal consecutive elements in array, merge them into twice the value element. Shift must return a new array, where ...
6
votes
1answer
274 views

Hilbertize an image

For a computer vision app I want to do a mapping of an image, in such a way that every pixel fit hilbert curve, instead of conventional layout. So task could be as follows: Given square 2D image <...
8
votes
26answers
1k views

Halt with 50% non-Halting

Create a program that halts exactly 50% of the time. Be original. Highest voted question wins. By exactly I mean that on each run there is a 50% chance of it halting.
11
votes
10answers
924 views

List the combinations of elements in a set

Given a set of n elements, the challenge is to write a function who lists all the combinations of k elements of in this set. Example ...

15 30 50 per page