Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

Filter by
Sorted by
Tagged with
1
vote
0answers
13 views

Counting King's Hamiltonian Paths through 3-by-N grid

Background A Hamiltonian path is a path on a graph that steps through its vertices exactly once. On a grid, this means stepping through every cell exactly once. On a square grid, a Chess King can move ...
7
votes
7answers
139 views

A long long time ago, in a galaxy … right here

Task Given a positive integer return the geologic era and period it was that many million years ago. Input/output The input is a string or integer; the output is a string. Eras and periods are ...
13
votes
24answers
489 views

Find the perfect square! [closed]

Your task is to turn a square root like this: √12 into a form like this: 2√3 For our purpose, we only need to output the left ...
11
votes
13answers
737 views

Are they collinear?

Task Write a program/function that when given three 2d points in cartesian coordinates as input outputs a truthy value if they are collinear otherwise a falsey value Three points are said to be ...
12
votes
3answers
1k views

Implement a UNIX file system and command line parser

Description Your task is to implement a simple UNIX command parser and file system. Your program will have to implement a file system that can be modified via commands. The starting directory of your ...
14
votes
6answers
661 views

Implement 1-dimensional version of Multi-Take

Background Adám and I were once discussing a way to properly extend some features in Dyalog APL. I came up with the following extension to Take, a function that takes some front or back elements (and ...
11
votes
4answers
380 views

Verify Tents and Trees solution

Background Tents and Trees (try here) is a puzzle played on a square (or rectangular) grid, where the objective is to place tents horizontally or vertically adjacent to each of the trees, so that no ...
8
votes
9answers
1k views

Lumberjaxe Code Golf

Tom the lumberjack is going to do his daily routine: chop trees. After all, it's his job to do so. His boss has ordered him to chop trees in a straight line marked with a special tape to identify them,...
7
votes
8answers
198 views

Is it a geometric sequence or not? [closed]

Well, last time I asked for an arithmetic sequence, now comes the geometric sequence Challenge In this challenge, the input will be an unordered set of numbers and the program should be able to tell ...
4
votes
2answers
967 views

Shortest python3 code for: Find the difference between a number and a power of two not exceeding a given number

So, this is a task from one very popular educational site in Russia: https://acmp.ru/index.asp?main=task&id_task=786&ins=1 Mathematically, you need to find the power of two not exceeding the ...
14
votes
4answers
702 views

Eight days a week

Back in 1965, The Beatles released their hit song 'Eight Days a Week'. In this code-golf challenge we are going to reimagine dates of the 21st century as if there really were eight days a week. Input ...
20
votes
2answers
1k views

Get string “-” with JavaScript using only the symbols from “+[]”

Challenge: Get the JavaScript string value containing only the "-" character using code only containing the following three symbols: ...
-5
votes
4answers
158 views

Is it an Arithmetic Sequence or not? [closed]

Challenge In this challenge, the input will be an ordered set of numbers and the program should be able to tell if the set of numbers is an Arithmetic Sequence. Input The input will be a list ...
17
votes
16answers
2k views

Find the discrete logarithm

Task Write a program/function that when given 3 positive integers \$a, b\$ and \$m\$ as input outputs a positive integer \$x\$ such that \$a^x\equiv b\ (\text{mod}\ m)\$ or that no such \$x\$ exists. ...
22
votes
18answers
1k views

Logo Pack LAPACK

This is the logo for LAPACK, a widely used software library for numerical linear algebra. Your task is to print the logo (color and matrix brackets not required) as this exact string. Trailing ...
14
votes
9answers
1k views

How many numbers can we make?

You are given a non-empty list of positive integers. Your task is to figure out how many distinct numbers can be obtained by applying the following algorithm: Remove either the first or the last item ...
4
votes
5answers
204 views

Divide into 2 isosceles triangles

Given the measures of two of the interior angles of a triangle (x and y; the other angle can be easily calculated with ...
27
votes
23answers
2k views

Print a tongue twister!

The goal of this challenge is to print the following tongue twister: ...
14
votes
3answers
248 views

Identify the smallest possible tile in the matrix

Challenge Given a matrix of digits (0-9), find the smallest (in terms of area) rectangular matrix of digits where one or more copies of itself, possibly rotated, can tile the original matrix. ...
30
votes
9answers
5k views

Is there a face in this image?

Help, I've been diagnosed with prosopagnosia! This means I'm no longer able to recognise faces.... :( Can you help me? The challenge You will be given an image as a matrix of regular ASCII characters ...
23
votes
4answers
3k views

Orientation Oriented Programming

Write a program for a specific language that in different orientations performs different tasks. Your code should have at least two non-empty lines and at least two non-empty columns and should ...
-3
votes
1answer
157 views

Format yourself for codegolf! [duplicate]

Task Your task is to write a program that, taking no input, outputs a string that represents a formatted codegolf answer of itself. The pattern is the following: ...
10
votes
21answers
2k views

How many weekdays?

This a simple question. The start day is a Saturday and let the input be a non-negative number x. The output should be the number of weekdays (Mon-Fri) in the next <...
13
votes
8answers
1k views

Is a statement of propositional logic always true?

The challenge is to golf a program that checks if a statement of propositional calculus/logic is a logical tautology (i.e. it is true for all possible values of the variables). Input Input formulas ...
2
votes
2answers
157 views

Create a text image by manual automation

Challenge Premise It's 2006, and Alice is trying to send Bob their her completed notes on their newly ended expeditions into the labyrinthine school library, which the two of them found suffers from a ...
10
votes
8answers
710 views

Scientific notation in Base-16

Input a scientific notation number (base 10), output scientific notation in base 16 (as defined below). Details In scientific notation, all non-zero numbers are written in the form $$ m \times 10^n $$ ...
21
votes
6answers
2k views

The matrix has U

Given a matrix of size at least 3×3 formed by positive integers, determine if it contains at least one "U" pattern, defined as ...
10
votes
2answers
269 views

The one counting challenge to rule them all!

Background Mathematicians are interested in all kinds of algebraic structures, e.g. groups, rings, boolean algebras. Generally, we have several operations (addition, multiplication, meet, join, etc.), ...
13
votes
4answers
2k views

Archimedes's cattle problem

Compute, O friend, the number of the cattle of the sun which once grazed upon the plains of Sicily, divided according to color into four herds, one milk-white, one black, one dappled and one yellow. ...
6
votes
3answers
344 views

Is this stack of CNN layers valid?

Background This challenge is about Convolutional neural networks, and its two main building blocks, namely Convolutional layer and Pooling layer. For simplicity, we ignore the "depth" of the ...
22
votes
3answers
989 views

Baba is golf, flag is win

If you haven't played the game Baba is You, I think you really should. Whether you’ve played it or not, have a go at implementing it as a code golf. The idea behind this challenge is to have a bit ...
-1
votes
6answers
435 views

LeetCode 552: Student Attendance Record II

I'm posting my code for a LeetCode problem copied here. If you have time and would like to golf for a short solution, please do so. Requirement It has to only pass the LeetCode's Online Judge, if the ...
17
votes
2answers
1k views

Is this a valid Shakashaka solution?

Background Shakashaka is a puzzle on a grid, whose objective is to place some half-squares (right triangles) on the empty cells so that all the remaining contiguous regions form rectangles, either ...
29
votes
11answers
2k views

Implement Entombed's lookup table

Background Entombed is an Atari 2600 game released in 1982, with the goal of navigating through a continuous mirrored maze as it scrolls upwards. In recent times, the game has been subject to research ...
0
votes
0answers
96 views

I am surely the fastest!… asymptotically [duplicate]

Background You are probably familiar with the "asymptotic time complexity" concept, which provides a way to measure how fast an algorithm runs as the input gets larger. For instance, if an ...
10
votes
1answer
292 views

Scoring Quantum Tic-Tac-Toe

In the description of this challenge, the following board will be used as a reference for positions: ABC DEF GHI For instance, in a game of ordinary tic-tac-toe, <...
22
votes
9answers
963 views

Split pythagorean triples into two sets

Task Write a program/function that when given a positive integer \$n\$ splits the numbers from \$1\$ to \$n\$ into two sets, so that no integers \$a, b, c\$, satisfying \$a^2 + b^2 = c^2\$ are all in ...
12
votes
3answers
250 views

Friendly Incenters

The incenter of a triangle is the intersection of the triangle's angle bisectors. This is somewhat complicated, but the coordinate formula for incenter is pretty simple (reference). The specifics of ...
16
votes
25answers
2k views

Turn a sentence into a dictionary

For this challenge, you will be given a long string as an input. With this string, you must create a dictionary. Details: This dictionary will contain all the words from the string - a word being any ...
7
votes
4answers
450 views

Find the date that is n days from January 1st 1984

This challenge is a relatively simple concept that I'm surprised has not been done yet. You will be given only an integer as an input. Your task is to find the date that is this number of days from ...
13
votes
3answers
527 views

Can this polyomino tile the toroidal grid?

Inspired by certain puzzles on Flow Free: Warps. Background We all know that L-triominos can't tile the 3x3 board, and P-pentominos can't tile the 5x5 board. But the situation changes if we allow the ...
20
votes
14answers
1k views

Get to the Zone!

You are playing a famous game called \$1\text{D Array BattleGround}\$. In the game, the player can be stationed in any position from \$0\$ to \$10^5\$. You are a Paratrooper in the game and have the ...
5
votes
0answers
207 views

Find the busiest hour for each stackexchange site [closed]

Input Name of a stackexchange site or any way to uniquely identify the site. Output The hour of the day that had the largest number of answers posted over the previous 24 hours. E.g. 14:00-15:00 GMT. ...
16
votes
6answers
622 views

Represent n as an expression containing all the digits

Related Challenge: Single Digit Representations of Natural Numbers Task Write a program/function that when given a non-negative integer \$n \le 100000\$ outputs an expression which uses all the ...
17
votes
2answers
393 views

What is the fastest safe way down a mountain?

Intro Help! I'm stuck on a snow-covered mountain and I need to get down as fast as possible, preferably without dying. I have a map showing how high each part of the mountain is above the normal ...
17
votes
24answers
3k views

What calculator is this datafile for?

The challenge today is very simple. The task is to determine the TI calculator for which the submitted datafile was made. The datafiles always start with a string ...
18
votes
14answers
2k views

Lucky dice rolls

Lucky dice rolls In pen and paper roleplaying games dice are used for various chance calculations. The usual way to describe a roll is \$n\textbf{d}k\$ where \$n\$ is the number of dice and \$k\$ is ...
11
votes
7answers
645 views

Toroidally magnify-blur a matrix

Task Given a matrix of numbers \$M\$ with \$r\$ rows and \$c\$ columns, and the magnification factor \$n\$, build the matrix with \$rn\$ rows and \$cn\$ columns where the original elements are spaced ...
12
votes
3answers
336 views

Insert parens into a free-form SKI calculus expression

Imagine a simple SKI calculus expression - for example, (((S α) β) γ). As you can see, each node of the rooted tree has exactly two children. Sometimes though, the ...
19
votes
29answers
3k views

Does this month start on a Monday?

June 2020 is a month in which June 1st corresponds to Monday, June 2nd corresponds to Tuesday, ... June 7th corresponds to Sunday. For reference, here's the cal of ...

1
2 3 4 5
196