Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [code-golf]

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, please state this explicitly in the challenge. If source code length is not the primary scoring criterion, consider using another tag instead.

23
votes
16answers
555 views

Custom Number Base Converter

The powers that be want to be able to quickly convert any number they have into their own number base using any format they would like. Input Your program must accept 3 parameters. Number: The ...
7
votes
11answers
199 views

Construct a line graph / conjugate graph

Introduction Given an undirected graph G, we can construct a graph L(G) (called the line graph or conjugate graph) that represents the connections between edges in G. This is done by creating a new ...
11
votes
5answers
279 views

Sequentia Filii Bonacci

Leonardo of Pisa (ca. 1175 - ca. 1245) is better known as Fibonacci. But this is actually a short for the Latin "filius Bonacci" (the son of Bonacci) which was made up during the 18th century (...
12
votes
20answers
1k views

Divide the work

There is a job which can be decomposed into x equally-sized smaller tasks. You have a team of size y <= x, where every member ...
12
votes
6answers
586 views

Graph 5-Coloring

Honestly, I can't believe this hasn't already been asked, but here it is Background Given a simple undirected planar (the graph can be drawn in the plane without intersections) graph, it is a proven ...
10
votes
15answers
2k views

Codegolf Rainbow : Draw in Black-and-White

Introduction: (Source: Wikipedia) When we look at a rainbow it will always have the colors from top to bottom: Red; orange; yellow; green; blue; indigo; violet If we look at these individual rings, ...
11
votes
11answers
1k views

Codegolf Rainbow : Fun with Integer-Arrays

Introduction: (Source: Wikipedia) When we look at a rainbow it will always have the colors from top to bottom: Red; orange; yellow; green; blue; indigo; violet If we look at these individual rings, ...
18
votes
9answers
633 views

Maximum Hamming distance among a list of padded strings

The Hamming distance between two strings of equal length is the number of positions at which the corresponding characters are different. If the strings are not of equal length, the Hamming distance is ...
27
votes
6answers
885 views

Make an alphabeTrie

Consider the following alphabetically sorted list of words: balderdash ballet balloonfish balloonist ballot brooding broom All of the words start with ...
18
votes
0answers
355 views

A Knotty situation [on hold]

sent back to the sandbox­­­­­­­­­­­­­­­­­ ­ ­ ­ ­
33
votes
23answers
6k views

Count Like a Babylonian

Challenge Given an ASCII representation of a Babylonian number as input, output the number in Western Arabic numerals. Babylonian Numeral System How did the Babylonians count? Interestingly, they ...
15
votes
21answers
1k views

Fill up to duplicate ranges

Let \$L\$ be a list of positive integers with no particular ordering, and which can contain duplicates. Write a program or function which outputs a list of positive integers \$M\$ (whose ordering is ...
19
votes
11answers
2k views

A knight's graph on an N-by-N board

In chess, a knight can only move to the positions marked with X relative to its current position, marked with ♞: A Knight's Graph is a graph that represents all legal moves of the knight chess piece ...
21
votes
17answers
1k views

RTA (Reverse-Then-Add) root of a number

The reverse-then-add (RTA) sequence is a sequence obtained by adding a number to its reverse, and repeating the process on the result. For eg., $$ 5 + 5 = 10 \Rightarrow 10 + 01 = 11 \Rightarrow 11 +...
18
votes
4answers
769 views

When in Rome, Count as Romans do?

Background This challenge is inspired by this website, which published the following diagram: This diagram shows us that the longest Roman Numeral expression under 250 is that of 188, which requires ...
-3
votes
1answer
117 views

number decomposition [duplicate]

It's been a while since I posted here, so here we go another day another challenge. Challenge : Given a number(n) split it into it's prime factors. Input : A ...
29
votes
2answers
4k views

Primality testing formula

Your goal is to determine whether a given number n is prime in the fewest bytes. But, your code must be a single Python 2 expression on numbers consisting of only ...
35
votes
31answers
5k views

Display a clock face

Display the 12 numbers on a clock face exactly like this: ...
10
votes
18answers
470 views

Minecraft Language Files Updater

In 1.13, Minecraft language files were switched from being a simple multi-line key=value format to JSON. Challenge Write a program converting from the original format returning a JSON string. Input ...
25
votes
15answers
2k views

Toggle some bits and get a square

Given an integer \$N>3\$, you have to find the minimum number of bits that need to be inverted in \$N\$ to turn it into a square number. You are only allowed to invert bits below the most ...
7
votes
16answers
1k views

Greet according to the time of day

Challenge Write a program that greets a user depending on what time of day (GMT) it is. Output A string (printed or returned) according to these rules: If the time is 06:00 to 11:59 the greeting ...
-7
votes
0answers
92 views

Php arrays code challenge [closed]

Given an array, write a function that will traverse the array and generate the array in a format given in the example below. For example, given the array: ...
8
votes
25answers
1k views

A function to take three integers and return a list of integers and alphabet-letters

Challenge We take three positive integers a, b, and c as input. Using these integers, first ...
6
votes
5answers
318 views

Watch the bookie win

When you roll a die, you have a 6:1 chance of any given option. There's a bookmaker taking bets on die rolls. He owns £20 at the start of the game. The bookmaker offers odds of 4:1, but gamblers ...
12
votes
7answers
1k views

crossed out 44 is still regular 44 ;(

Introduction On March 24th, 2015 @isaacg golfed his Pyth answer from 44 to 42 bytes. Since a crossed out 44 (44) looks a lot like a regular 44, @Optimizer made the following comment: striked out ...
8
votes
15answers
665 views

Scoring 6,5,4 (AKA Ship, Captain, and Crew)

Inspired and looted from this dice challenge by Arnauld Input You are given a 5x1 or 1x5 (your choice) dice matrix which consist of binary 3x3 sub-matrices. Goal Given a valid dice matrix, you are ...
0
votes
1answer
97 views

Symmetric Numbers [duplicate]

write a function to tell if a number is symmetric or not. for example: input: 151 output: True input: 142 output: False and so on: 1111 True, 2390 False, 1226221 True
11
votes
23answers
2k views

Calculate the sum of the first n prime numbers

I'm surprised that this challenge isn't already here, as it's so obvious. (Or I'm surprised I couldn't find it and anybody will mark it as a duplicate.) Task Given a non-negative integer \$n\$, ...
12
votes
6answers
380 views

Golf a Solubility Chart

Given the name of a cation and anion, output "S" (soluble) or "I" (insoluble). The table we will be using is from wikipedia: https://en.wikipedia.org/wiki/Solubility_chart. It is copied at the end of ...
17
votes
7answers
577 views

Split the bits!

We define \$V(x)\$ as the list of distinct powers of \$2\$ that sum to \$x\$. For instance, \$V(35)=[32,2,1]\$. By convention, powers are sorted here from highest to lowest. But it does not affect ...
13
votes
14answers
2k views

Naismith's rule

Naismith's rule helps to work out the length of time needed for a walk or hike, given the distance and ascent. Given a non-empty list of the altitude at points evenly spaced along a path and the ...
7
votes
3answers
157 views

Evaluate Words Based on “Rules” (Skeptics.SE Crossover)

I came across this picture, which I initially questioned and thought about posting to Skeptics. Then I thought they'll only tell me if this one case is true, but wouldn't it be great to know how true ...
-1
votes
0answers
65 views

Shortest quine that is a palindrome. No comments [duplicate]

I challenge you to write the shortest code possible to produce a quine that is a palindrome. The quirk here is that you are not allowed to use any comment functionality. Rules: Shortest code wins ...
19
votes
7answers
2k views

Belarus rushnyk

We've got quite a few national flag challenges already: AU CH FI FR GB GB IS KR NP US... Here's another, somewhat more advanced one: Return or print the decorative pattern from Belarus's national ...
22
votes
22answers
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 ...
11
votes
5answers
306 views

Minimal Centrosymmetrization

Topically related. Objective: Given a matrix of positive integers \$M\$, output the smallest centrosymmetric matrix which contains \$M\$ (this matrix may contain non-positive integers as well). A ...
15
votes
16answers
5k views

Is the bus load legal?

I was in the bus today, and noticed this sign: ...
6
votes
1answer
77 views

Make the super number hyper-pyramid [duplicate]

Challenge Given a positive integer \$n\$, output the \$n\$-dimensional pyramidal list. Example \$n = 1\$: Objects arranged in a 1D pyramid (line) with side length 1 is just by itself. So, the ...
17
votes
10answers
537 views

Decrypt the extended Wechsler format

This challenge is based on a sandbox post by user48538. Since he is no longer active on this site, I took over this challenge. apgsearch, the distributed soup search program for Conway's Game of Life ...
9
votes
2answers
148 views

Optimal Caching

You will be given a sequence of memory requests and a cache size. You must return the least possible number of cache misses under any cache replacement strategy. An optimal strategy is Belady's ...
23
votes
10answers
1k views
+500

Make a Geiger Counter

A Geiger counter is a device that is used to detect radiation. We will be making a Geiger counter program. As we all know, when radiation hits a computer program it removes exactly 1 byte at random. ...
1
vote
2answers
176 views

Bridge Deal Scoring

Goal Given a deal result from Duplicate Contract Bridge, calculate the deal score. Basically the same as iBug's question, which was deleted. I figured out this scoring system while trying to answer ...
21
votes
9answers
2k views

How much is my dice matrix worth?

Input A non-empty binary matrix consisting of 3x3 sub-matrices put side by side. Task Your task is to identify valid dice patterns (as described below) among the 3x3 sub-matrices. Each valid ...
7
votes
2answers
203 views

Python: shortest way to interleave items from two lists

I'm trying to get the shortest way (character possible) to obtain List 3. List 1 and List 2 are already given to me as arguments and are the same length. ...
26
votes
16answers
4k views

Roman Army Shields

Sandbox post (deleted) The old roman army formations are very famous around the world. In these formations roman legionaries grouped in a geometric shape (usually a rectangle) protecting the flanks ...
9
votes
10answers
503 views

The Clock Hands of Doom

You are chained to a chair. Underneath you is a huge volcano. A 12-hour clock next to you ticks ominously, and you see that it has wires leading from the back up to a chain, which will drop you into ...
14
votes
19answers
3k views

Test if a string is parenthesly balanced

We call a parens group the open paren (, its matching close paren ) and everything inside them. A parens group or string is ...
-4
votes
0answers
74 views

When and only when life gives you lemons, make lemonade [duplicate]

Golf a program that has no output (or outputs the empty string) when given any string other than "lemons". When and only when given the string "lemons" it will output "lemonade".
6
votes
2answers
174 views

What associativity was it again

Non-associative operators (for example the subtraction-operator) often are either left- or right associative, such that one has to write less parentheses. Consider for example the following: $$ a-b-c ...
27
votes
73answers
12k views

Is this number evil?

Introduction In number theory, a number is considered evil if there are an even number of 1's in its binary representation. In today's challenge, you will be identifying whether or not a given number ...