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
7
votes
3answers
85 views

Array depth of a ragged list

This is not a duplicate of this challenge. Here by an array, I mean a nested list that is "not ragged", i.e., it is either a list of elements, or a list of arrays of the same shape. For ...
16
votes
9answers
432 views

Output every substring ... eventually

You will be given as input an infinite stream of positive integers. Your task is to write a program which outputs an infinite sequence of lists with two requirements: All lists in the output are ...
14
votes
4answers
338 views

Is this continuous terrain?

Very related You're given a piece of ASCII art representing a piece of land, like so: /‾\ __/ ‾\_ \_/‾\ \ Since an overline (...
14
votes
7answers
272 views

Split along groups

You are going to be given a string containing some alphabetic characters along with [ and ]. Your task is to split into ...
8
votes
3answers
240 views

Solve nonimplication-SAT

Background This is Post's lattice: Credit: EmilJ It denotes the lattice of all clones on a two-element set {0, 1}, ordered by inclusion (from Wikipedia). That can ...
15
votes
31answers
1k views

Is it a pure word?

Introduction A pure word (or perfect word), as defined by me, is a word where the sum of the position in the alphabet of each letter in the word is perfectly divisible by the total length of the word. ...
-2
votes
0answers
97 views

Tips for golfing in chicken

What general tips do you have for golfing in Chicken? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Chicken (e.g. "remove ...
-3
votes
0answers
61 views

Is there a way to replace multiple "replace" functions Python3 [duplicate]

For a code-golf challenge, i had to use multiple text.replace(" ","") inside my code. Is there a way to use something like: ...
12
votes
8answers
1k views

Is this a word?

Toki pona is a minimalist constructed language, and thus it has minimalist phonotactics (rules describing what sounds make valid words). Toki Pona has 8 consonant sounds ...
9
votes
1answer
320 views

Universal Command Sequence

Universal Command Sequence Definition An \$n\$-maze is a \$n\times n\$ chessboard which has "walls" on some edges, and a "king" on the board that can move to the 4 adjacent cells, ...
9
votes
10answers
2k views

Mr. ASCII becoming uncanny with your own code

Let's make a little stupid program that simulates the meme "Mr. incredible becoming uncanny", but in this case, our little ASCII friend is going to react to our code length. Objective: ...
17
votes
18answers
641 views

Minimum depth of a ragged list

As input you will be given a ragged list of positive integers containing at least one integer at some level. For example: [[],[[1,2,[3]]],[]] You should output ...
3
votes
9answers
652 views

Generate Fmbalbuena Numbers

My user id is 106959 How to check if the number is Fmbalbuena number? First Step: Check if the number of digits is a multiple of 3: ...
10
votes
8answers
544 views

Expand a Rubik's Cube Commutator

Background We will be using a 3x3 cube for this challenge. Rubik's cubers have their own notation for movements on the cube: Each of the 6 faces has a clockwise turn notated with a single capital ...
16
votes
8answers
776 views

Make every fixed list

We are to define the idea of a fixed list as follows: A fixed list is a list of fixed lists. This definition is recursive so it's useful to look at some examples. The empty list ...
11
votes
14answers
952 views

Lowest integer with no common digits between given bases

Challenge Given a list of bases for positional numeral systems as input, output the lowest positive integer that when represented in those bases they have no common digits. The input list can be ...
14
votes
3answers
209 views

Fill the (possibly leaky) bowl

Challenge: Given an ASCII art of a (possibly leaky) bowl consisting of a random distinct non-whitespace and non-~ character, fill it completely with ...
18
votes
16answers
1k views

Slater-Velez permutation

Let's build a sequence of positive integers. The rule will be that the next number will be the smallest number which: It hasn't already appeared in the sequence Its absolute difference from the ...
-6
votes
4answers
112 views

Indices of square numbers that are also pentagonal [closed]

First 15 numbers of the A046173: ...
16
votes
17answers
1k views

Generate a regular graph

Inspired by this Mathematica.SE post Given two positive integers \$n, k\$ with \$n > k \ge 1\$, output a binary \$n\times n\$ matrix such that every row and column contains exactly \$k\$ 1s, and ...
15
votes
13answers
899 views

Compare shapeless lists

Let's have a ragged list containing no values, only more lists. For example: [[[],[[]],[],[]],[],[[],[],[]],[]] And the list will be finite, meaning that ...
-10
votes
10answers
146 views

Find the square of a number [duplicate]

Your task is to find the square of a number without using the multiplication sign or division sign However, to make this even trickier, no use of any addition sign or even the minus sign can be used ...
-6
votes
2answers
82 views

Multiplying numbers [duplicate]

Your task, is simply to multiply 2 integers given in input, separated by a ",". The catch is, you cannot use the multiplication operator "*", even if it is being used differently, ...
30
votes
14answers
2k views

Iterate your way to a fraction

I recently learned from a comment by MathOverflow user pregunton that it is possible to enumerate all rational numbers using iterated maps of the form \$f(x) = x+1\$ or \$\displaystyle g(x) = -\frac ...
10
votes
2answers
698 views

Can I shorten this Python code for simulating a car driving around

I am trying to write a solution to the following problem using as few characters as possible (to meme my friend and introduce him to golfing). Can any improvements be done to my code? So the problem ...
17
votes
9answers
535 views

Remove consistently dependent smaller integers

Consider this nested array [[1,2,4],[1,2,3],[2,3]] In each subarray in which 1 appears, a 2 appears. You might say that 1's presence is dependent on 2's presence. ...
16
votes
6answers
726 views

Mutually recursive lists

Let's define a simple function \$f\$ which takes an integer and produces a list: \$ f(n) = [g(1),g(2),\dots,g(n)] \\ g(n) = [f(0),f(1),\dots,f(n-1)] \$ We can then calculate the first couple of values ...
21
votes
24answers
2k views

Next Greater Number

The task: Given an integer n, find the next number that follows the following requirements The next greater number is a number where each digit, from left to right,...
-5
votes
5answers
158 views

Make an ed clone

ed is the standard text editor on Unix systems. Your goal is to write an ed clone. Task Write a program that reads an input stream and for every received end of line character, print ...
7
votes
4answers
188 views

Your trees need to be rerooted

In graph theory a tree is just any graph with no cycles. But in computer science we often use rooted trees. Rooted trees are like trees except they have one specific node as the "root", ...
32
votes
10answers
4k views

Who Is Kevin Bacon?

You may know the game The Six Degrees of Kevin Bacon, based on the conjecture that every actor in Hollywood can be connected to Kevin Bacon by no more than 6 "co-star" relations, so Kevin ...
12
votes
4answers
422 views

Encode Antarctic claims

Seven countries lay official claims to parts of Antarctica: Argentina, Australia, Chile, France, New Zealand, Norway, and the United Kingdom. We will focus only on the claims of the main Antarctic ...
20
votes
20answers
893 views

Find the maximum length in a ragged list

Given a ragged list of positive integers find the size of the largest list contained somewhere in it. For example: [1,[1,[8,2,[1,2],5,4,9]],2,[],3] Here the answer ...
14
votes
13answers
899 views

Number of complete rhyme schemes

A rhyme scheme is the pattern of rhymes at the end of the lines in a poem. They are typically represented using letters, like ABAB. We consider two rhyme schemes ...
16
votes
12answers
895 views

Scan a ragged list

hgl has a "scan" function called sc. What it does in general is a little bit abstract, so we will just talk about one specific way you can use it. If we ...
14
votes
15answers
1k views

Encode integers with some others

Input a non-empty array of positive (greater than 0) integers. Output another non-empty array of positive integers which encode the input array. Output array does not use any numbers used in the input ...
17
votes
11answers
1k views

Identify a "reverse checkers" position

Task A reverse checkers position is a chess position where every piece for one player is on one colour and every piece for the other player is on the other colour. Your task is to find if the given (...
6
votes
2answers
240 views

No parentheses shall be omitted

This expression actually has an omitted pair of parentheses. 1 + 2 * 3 To make things clear, it should be, 1 + (2 * 3) Even ...
18
votes
22answers
1k views

Collect the elements of an array

Add++, the Language of the Month, has the "collect" builtin as BC. Your task is to implement this builtin. Consider a non-empty array, where each element ...
5
votes
0answers
111 views

Matching fuzzies [closed]

Introduction Congratulations! You've been selected to do research a a newly discovered animal called a fuzzy, a docile, simple creature that strongly resembles a cotton ball. Fuzzies love to be near ...
15
votes
26answers
2k views

Make every other vowel uppercase

Given a lower case string. Ex: s = 'abcdefghijklmnopqrstuvwxyz' The goal is to make every other vowel uppercase. Desired output here: ...
34
votes
38answers
2k views

Incrementally Increment Identical Integers

Inspired by this Stack Overflow post. Given an ascending-sorted array of possibly duplicated integers, your goal is to increment each number by a counter, starting at 0, that resets for each group. ...
11
votes
4answers
482 views

Tips for golfing in Add++

Add++ is the Language of the Month for January 2022, and so I'm asking for tips for golfing in it. Please stick to tips specific to Add++, and avoid general tips such as "remove whitespace" ...
25
votes
29answers
2k views

Unsort an array

Inspired by this StackOverflow post Given a list where each element appears a maximum of 2 times, we can define it's "sortedness" as the sum of the distances between equal elements. For ...
11
votes
4answers
254 views

Find an autogram using roman numerals

This task builds on: Find all reflexicons using roman numerals An autogram is a sentence that lists the count of its own letters. Below is one of the first documented autograms found by Lee Sallows in ...
15
votes
1answer
356 views

Counting universal n-ary logic gates

Background A classical logic gate is an idealized electronic device implementing a Boolean function, i.e. one that takes a certain number of Boolean inputs and outputs a Boolean. We only consider two-...
14
votes
16answers
802 views

Shuffle a subsequence

Thanks to rak1507 for the suggestion "Random" in this challenge always refers to "uniformly random" - of all possible choices, each has an equal chance of being chosen. Uniform ...
-5
votes
4answers
93 views

Shortest way to remove the first and last element of a list and print both [closed]

The challenge is simple: Print the first and last element of a list and print them Rules: You will take only 1 line of input, and that is the list (e.g. ...
27
votes
20answers
2k views

An ASCII self-referential sequence

The sequence A109648 starts with the following numbers ...
8
votes
16answers
740 views

Minimum difference between cartesian product of 3 elements that add up to a certain number

Let's say I've got a list (or array) of: l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] I want to get the third Cartesian power of the above list, where we take every ...

1
2 3 4 5
217