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.

Filter by
Sorted by
Tagged with
11
votes
5answers
597 views

Define the finite field GF(9)

\$GF(9)\$ or \$GF(3^2)\$ is the smallest finite field whose order isn't a prime or a power of two. Finite fields of prime order aren't particurlarly interesting and there are already challenges for \$...
1
vote
1answer
88 views

2D Path Drawing [duplicate]

(This is not a duplicate of Follow the path, as this challenge have invalid path detection and use ><^v in the output.) Task So your task is to take in the ...
15
votes
22answers
2k views

Integer Interpretator

The Challenge Given a finite list of integers, split it into the fewest partitions possible such that no partition contains a number more than once. Rules Input can be in any format and any order. ...
12
votes
14answers
630 views

Linear dependences over the field with two elements

The \$d\$-dimensional vector space \$\mathbb{F}_2^d\$ over the field with two elements \$\mathbb{F}_2\$ is the set of vectors of \$d\$ bits. Addition of vectors is bitwise xor. A linear dependence is ...
5
votes
4answers
306 views

Play flip--flop

Flip flop is a memory / arithmetic game that I played in high school. Some number of players stand in a circle. The players take turns. On the nth turn, the current ...
5
votes
2answers
189 views

Two stack sorting

This challenge is inspired by the same task I read some time ago in CACM. There are many ways to sort stuff. Most attempt to sort in as few operations as possible (= as fast as possible). However, it ...
7
votes
3answers
368 views

Decode ascii and reversed words sentence

In a challenge of CodingGame, there is a challenge that ask you to decode a string composed by reversed words ('Hello world' > 'olleH dlrow') then each characters converted into ascii value separeted ...
22
votes
25answers
3k views

Even and Odd Numbers

Sandbox Adapted from exercise 4 of 100 little Keg exercises The ability to repeat chunks of code within a program is an important part of any programming language. Also just as important is the ...
16
votes
10answers
1k views

Fill the Golfeek gutter

Golfeek is the working name of an esolang I'm occasionally working on. One distinctive feature of this language is that each statement is encoded as a sequence of bits rather than a sequence of bytes. ...
9
votes
1answer
690 views

Make a Lost Compass

Lost is a 2-Dimensional programming language where the instruction pointer starts at a random location, moving in a random direction. A description of the language can be found at the bottom of the ...
9
votes
0answers
157 views

Compare Dowker Knotation

Dowker notation is a common way of representing mathematical knots. Dowker notation can be derived from a knot diagram in the following way (based on the description from the wikipedium): We will ...
3
votes
1answer
353 views

Challenge: Functioning Blackjack Game [closed]

This is kept fairly original: Write a program that creates a standard blackjack game: input "h" means hit or draw another card input "s" means stand, or take what you have already Rules: cards ...
17
votes
11answers
3k views

Advent calendar

Let's build an advent Calendar for this Christmas! Many Advent calendars for children take the form of a large rectangular card with numbered windows for each day of December starting from 1 ( ...
17
votes
12answers
1k views

Check if simple regex matches string

A simple regex is either: _ (which matches the empty string) Any lowercase letter a to z (...
18
votes
3answers
470 views

On the Subject of Memory

This challenge is from a game called Keep Talking And Nobody Explodes. Memory is a fragile thing but so is everything else when a bomb goes off, so pay attention! – from the manual The Objective A ...
15
votes
1answer
243 views

Can this knot be colored with 3 colors?

In this challenge you will be asked to take a knot and determine if it can be colored in a particular way. First we draw a diagram of the knot. We use the standard way of drawing knots where we put ...
0
votes
6answers
269 views

Give me the first day of next month

Simple question! Given a string that contains a date in ISO8601 format, print the first of the next month in ISO8601 format. Example inputs: 2018-05-06 ...
80
votes
45answers
16k views

Sleep for 1000 years

Some sleep commands implement a delay of an integer number of seconds. However, 232 seconds is only about 100 years. Bug! What if you need a larger delay? Make a ...
5
votes
5answers
442 views

Generate an ASCII art representation of a ribbon plot

Sandbox post In this code-golf challenge, you are provided with a series of y values at even x-values as well as a console width and height. The desired output is an ASCII-art representation of a ...
22
votes
19answers
6k views

I shift the source code, you shift the input!

Sandbox A spin-off of a rip-off of a rip-off of a rip-off of a rip-off. Go upvote those! Your task, if you accept it, is to write a program/function that outputs/returns its input/argument. The ...
10
votes
2answers
534 views

Play Big 2 by yourself, as fast as you can

Introduction Big 2 is a card game popular in East Asia and South East Asia, in which 4 players are dealt 13 cards each (ie, an equal division of a standard deck without jokers). The goal is to empty ...
-2
votes
7answers
299 views

Interpreting the Wolfram Code

Introduction An elementary cellular automaton is a cellular automaton that is 1-dimensional and has 2 states, 1 and 0. These cellular automata are categorized based on a simple code: the Wolfram code,...
13
votes
10answers
2k views

Help me pair my left and right socks!

Inspired by Help me pair my socks, and the fact that I have some pairs of socks where the left sock is distinct from the right. Background Again, I have a huge pile of socks. And a machine that can ...
3
votes
2answers
1k views
3
votes
0answers
213 views

Count the length of head movement

Once upon a time I wanted to order custom tokens for a board game. They say they can do it, and then they present me their price list. I was confused because they charge per inch of head movement, and ...
25
votes
13answers
3k views

Who's next to me in the queue?

Problem 4 in the 2019 BMO, Round 1 describes the following setup: There are \$2019\$ penguins waddling towards their favourite restaurant. As the penguins arrive, they are handed tickets numbered ...
15
votes
16answers
2k views

Roll for Initiative!

Roll for Initiative! Introduction In tabletop games like Dungeons and Dragons, when you begin a battle, all involved parties roll for initiative. In DnD 5e, this is ...
20
votes
38answers
4k views

Round up my number

Sandbox Given two positive integers a and b, return the smallest multiple of b that is greater than or equal to a. Examples Definitions: true = ...
24
votes
13answers
3k views

How many atoms in the hydrocarbon?

How many atoms in the hydrocarbon? A hydrocarbon is a chemical compound which consists of only hydrogen and carbon atoms. For this challenge, we will only consider the three simplest kinds of ...
0
votes
1answer
244 views

Find all possible dates [closed]

You get a string which contains an integer between 1000 and 99999999 as input. The input string might contain leading zeroes but ...
13
votes
3answers
254 views

Is this board Latin-style?

Inspired by Flow Fit: Sudoku, a brand-new mobile puzzle game (as of Nov 2019). Background A Latin square is a square grid of side length \$ n \$ filled with \$ n \$ different symbols, where each row ...
22
votes
12answers
2k views

Next Shared Totient

The totient function \$\phi(n)\$, also called Euler's totient function, is defined as the number of positive integers \$\le n\$ that are relatively prime to (i.e., do not contain any factor in common ...
1
vote
0answers
89 views

Parallel resistance in electric circuits in C [duplicate]

What are some tips on how to shorten this code even further? The code is meant to compute the parallel resistance of an electric circuit. Using scanf ...
8
votes
2answers
356 views

Draw a fully-rendered path from direction changers

(Note: this challenge is distinct from my other challenge (Draw a path made from direction changers) because of it's rendering of direction (horizontal or vertical), crossing points and single or ...
22
votes
5answers
3k views

Is this platform game level winnable?

Given a level from a simple platform game, your task is to make a program or function to determine if a level is winnable. Platform game levels are 4 characters tall and any number of characters wide. ...
33
votes
28answers
4k views

How many times, are they multiples?

You are given three parameters: start(int), end(int) and list(of int); Make a function that returns the amount of times all the numbers between start and end are multiples of the elements in the list....
7
votes
3answers
661 views

What is a short code for generating this matrix in R?

I can see that it is 101 'moving to the right' but I cannot think of a short way to generate it in R language. \$\begin{bmatrix} 0 & 1 & 0 & 0 & 0 & 0 \\ 1 & 0 & 1 & 0 ...
1
vote
1answer
135 views

An “Iniative” game mechanic [closed]

This challenge is inspired by turn based videogames like "Heroes of Might and Magic" Implement this game mechanic: There is some units(Imps, Swordsmans etc...) in our game Every unit have an integer ...
15
votes
16answers
910 views

Find the length of a number's “base-jumping” path

Consider a positive integer N written in base b. A sequence is generated from this number by finding the largest digit ...
17
votes
4answers
1k views

Can Alice win the game?

Can Alice win the game? The game's rules are as follows. First, a finite non empty set of positive integers \$X\$ is defined. Then, Alice and Bob take turns choosing positive integers, with Alice ...
32
votes
38answers
4k views

Decode the Dreaded Alphabet Cypher™️

This challenge is inspired by one of my other challenges: Pointlessly make your way down the alphabet That challenge asked you to take a string of text, and for each letter produce a sequence of ...
16
votes
15answers
3k views

Stack Exchange Answerer

Oof! You've been coding the whole day and you even had no time for Stack Exchange! Now, you just want to rest and answer some questions. You have T minutes of free time. You enter the site and see N ...
1
vote
3answers
161 views

Simulate move left for 2048 [duplicate]

I have a fixed length vector of 4 elements. The inputs of which are always 0 or 2^n for n = 1 to 15 (so n = 0 excluded i.e. 2^0 = 1 will not appear) ...
17
votes
18answers
2k views

Clockwise matrix rotation

The title pretty much describes it all. Given as input a \$n \times m\$ matrix and an integer \$i\$ create a complete function/program that returns the matrix \$i\$ times clockwise rotated by \$90^\...
8
votes
4answers
335 views

Rock Paper Scissors (Sorta) Quine

Create three programs, which we'll call Rock, Paper, and Scissors. Each program must be unique, and accept input. If a program gets any input which is not one of the programs Rock, Paper or ...
13
votes
1answer
430 views

Circular robot instructions

This challenge is based on Project Euler problem 208. Also related to my Math Stack Exchange question, Non-self-intersecting "Robot Walks". You have a robot that moves in arcs which are \$1/n\$ of a ...
28
votes
4answers
4k views

How close are we, really?

Please note: this is a restricted-source challenge — see details below! Each natural number \$n\$ has 10 faces: its decimal representations in bases \$1\$ through to \$10\$. For example, the 10 faces ...
-1
votes
1answer
180 views

Chopping Unicode Bytes [closed]

Introduction Each Unicode codepoint can be represented as a sequence of up to 4 bytes. Because of this, it is possible to interpret some 2, 3, or 4-byte characters as multiple 1-byte characters. (See ...
9
votes
5answers
496 views

Country name mashup generator

Part 1 of the task is here Flags Mashup Bot is a small Twitter bot that generates a new country name based on two random country names and tweets the result every couple of minutes. Task Your task ...
31
votes
23answers
5k views

Draw the Ionising Radiation Hazard Symbol

Draw the ionising-radiation-hazard-symbol in an arbitrary colour on a distinctly coloured background. The specific proportions were published in the June 27th 1974 issue of the Federal Register of the ...