instruction stringlengths 34 53.1k |
|---|
A super prime is a prime whose index in the list of primes is also a prime:
3, 5, 11, 17, 31, 41, 59, 67, 83, 109, 127, 157, 179, 191, 211, 241, 277, 283, 331, 353, 367, 401, 431, 461, 509, 547, 563, 587, 599, 617, 709, 739, 773, 797, 859, 877, 919, 967, 991, ...
For this challenge, an "order 2" super prime is defined... |
The Jaccard index / similarity coefficient, also known as the Tanimoto index / coefficient, is a statistic used for gauging the similarity and diversity of finite sample sets. It was developed by Grove Karl Gilbert in 1884 for the field of weather forecasting [1] and later independently developed by Paul Jaccard [2] wh... |
Heading into the final day of regular season games for the 2023 NBA season, the fifth to ninth seeds in the Western Conference were still very undecided. Four games would determine the seeding:
New Orleans (N) at Minnesota (M)
Utah at LA Lakers (L)
Golden State (G) at Portland
LA Clippers (C) at Phoenix
Let the Boole... |
Your task is to write a program that receives a base 10 number from 0 to 99 and outputs the German name of that number with non-ASCII characters replaced with ASCII equivalents.
German number names
0 -> null
1 -> eins
2 -> zwei
3 -> drei
4 -> vier
5 -> fuenf
6 -> sechs
7 -> sieben
8 -> acht
9 -> neun
10 -> zehn
11 -> e... |
Related but different.
Part II
Taken from the book: Marvin Minsky 1967 – Computation:
Finite and Infinite Machines, chapter 14.
Background
As the Gödel proved, it is possible to encode with a unique positive integer not just any string
but any list structure, with any level of nesting.
Procedure of encoding \$G(x)\$ i... |
The bots are looking for love. Can you help them?
The rules
The goal of this game is find the bot you have the highest compatibility with. However, robots, who are inexperienced at dating are unable to tell how well a date went.
In the game, bots take turns "speed dating" some other bot. After each date, each bot choos... |
You are given two strings \$a\$ and \$b\$ consisting of characters from a to z in lowercase. Let \$n\$ be the length of \$a\$. Let \$m\$ be the length of \$b\$. Let \$a'\$ be the string \$a\$ repeated \$m\$ times. Let \$b'\$ be the string \$b\$ repeated \$n\$ times. Check whether \$a'\$ is lexicographically less than \... |
In this challenge, given a CSV file as a string, you'll return the data contained as a 2d array of strings.
Spec:
The input consists of one or more records, delimited with \r\n (CRLF), \n (line feed), or some other reasonable newline sequence of your choice
A record consists of one or more fields, delimited with , (co... |
In Bloons Tower Defense 6, the strength of different bloons can be measured by their Red Bloon Equivalent (RBE), or the number of single pops it takes to completely defeat the bloon.
The RBE for the bloon types are as follows (sourced from the wiki)
Bloon
RBE
red
1
blue
2
green
3
yellow
4
pink
5
black... |
The alternating factorial is an alternating sum of decreasing factorials. For example, we could calculate the alternating factorial of 4 as follows:
First, calculate the factorials from 4 down to 1:
$$
4!\quad3!\quad2!\quad1!\quad = \\
4\cdot3\cdot2\cdot1\qquad3\cdot2\cdot1\qquad2\cdot1\qquad1\quad= \\
24\quad6\quad2... |
The task here is simple: given a target location on an XY grid, and a rectangle on that grid, find the length of the shortest path from the origin to the target which does not intersect the rectangle.
All parameter values are integers. You can assume that neither the target point nor the origin is inside or on the bord... |
Part I
Previous part was considered encoding of non-empty nested lists with a positive integer.
Reminding the coding procedure \$G(x)\$:
If \$x\$ is a number, \$G(x) = 2^x\$
If \$x\$ is a list \$[n_0, n_1, n_2, n_3, …]\$, \$G(x) = 3^{G(n_0)} \cdot 5^{G(n_1)} \cdot 7^{G(n_2)} \cdot 11^{G(n_3)} \cdot...\$
Bases are cons... |
You are given a string \$s\$ of characters from a to z. Your task is to count how many unique strings of length \$n\$ you can make by concatenating multiple prefixes of the string \$s\$ together.
Since the result can be superlative you can either choose to output the whole result, the result mod \$2^{32}\$ or the resul... |
Objective
Given the distance between two keys in an octave, identify its name.
But there's a caveat. In this challenge, there are 22 keys in an octave, not usual 12.
Here, a porcupine[7] scale will be assumed.
Mapping
White keys are marked bold.
Distance
Name
0
Unison
1
Augmented Unison or Diminished Second
... |
Hertzprung's Problem (OEIS A002464) is the number of solutions to a variant of the Eight Queens Puzzle, where instead of placing \$n\$ queens, you place \$n\$ rook-king fairy pieces (can attack like both a rook and a king); in other words, it's how many possible positions you can place \$n\$ rook-kings on an \$n \times... |
The problem statement here is pretty simple, take two real numbers on the range [0,1) as input and output their sum, with probability 1.
The catch here is that there are a lot of real numbers. There are in fact so many real numbers that it is impossible to fit all of them into any finite data type. As such, any way to ... |
Not a duplicate of the valid move challenge because that asks for specific pieces.
Backstory
The other night I was doing a little trolling with ChatGPT and chess. I was trying to get it to call me out for making illegal moves, as a lot of the time, you can feed it whatever nonsense you want. While doing so, I wondered ... |
A Hankel matrix is a square matrix in which each ascending skew-diagonal from left to right is constant, e.g.:
$$\begin{bmatrix} a & b & c & d \\ b & c & d & e \\ c & d & e & f \\ d & e & f & g \end{bmatrix}.$$
Given a sequence of integers \$\{a_n\}\$, we can construct a sequence of Hankel matrices \$\{H_n\}\$, where \... |
Background
Being in a philosophical mood, I remembered one old idea. I think it is suitable for CG.
Duplicates are not found, but it's of course just a kind of totalistic cellular automaton or erosion.
Given an infinite board filled with empty (let 0) cells. We create a figure - a finite set of non-empty (let 1) cells.... |
Challenge
You are supposed to output the series I recently designed which goes as follows which are pen stroke counts of ascending prime numbers:
2, 3, 2, 4, 3, 5, 6, 5, 7, 7, 7, 10, 4, 6, 7, 4, 4, 4, 7, 6, 8...
Example
This is an illustration of how this series is formed, first, it takes a prime number from in sequen... |
You may have seen something called a "perpetual dice calendar":
Two 6-sided dice can be rearranged and rotated. One die has the numbers 0, 1, 2, 3, 4, and 5. The second die has the numbers 0, 1, 2, 6, 7, and 8. With this, any day of the month—from 1 to 31—can be displayed on the front of the calendar. The 6 can be rot... |
Related
From Wikipedia:
In number theory, the Calkin–Wilf tree is a tree in which the vertices correspond one-to-one to the positive rational numbers. The tree is rooted at the number \$1\$, and any rational number expressed in simplest terms as the fraction \$\frac{a}{b}\$ has as its two children the numbers \$\frac{... |
This is a rewrite of the (currently closed) "Debunking Stroustrup's debunking of the myth “C++ is for large, complicated, programs only”" challenge.
Challenge
Write the shortest program or function that will:
Download http://www.stroustrup.com/C++.html, and
List all URLs contained in the HTML document.
A "URL" for th... |
A sequel to What dice do I need to display every integer up to X?
Numbers are great, but let's take it to the next level. I'd like to have a set of dice that can be arranged and rotated to display any words I want. Think Boggle:
And not just that; I want to specify the number of sides those dice have. The set should c... |
Simplified version of "Signpost" puzzle from Simon Tatham's Portable Puzzle Collection.
How the puzzle is created
We pick up randomly positive integer N and one of permutations of 1…N
with 1 at the first position:
N = 12
Numbers 1 and N always stay open, and 2 is always on the right of 1.
So we look at numbers 2 and 3... |
The Venetian election system was... complicated.
The Great Council came together and put in an urn the ballots of all the councilors who were older than 30. The youngest councilor went to St Mark's Square and chose the first boy he met who drew from the urn a ballot for each councillor and only those 30 who got the wo... |
Given some raw HTML, sanitize it by formatting the spaces, as defined below.
Output rules:
Like many challenges, this one is inspired by XKCD.
First, "untag" all tags with nothing but spaces in them. (<i>te<b> </b>xt</i> becomes <i>te xt</i>). If a tag has nothing in it (like <b></b>, simply delete it and move o... |
Objective
Given an unlabelled binary tree, decide whether it is contiguous in indices.
Indices
This challenge gives one-indexing on binary trees. The exact definition expresses all indices in binary numeral:
The root is indexed 1.
For every node, to get the index of its left child, replace the most significant 1 by 1... |
This is my first codegolf post so let me know if I have missed anything. Thanks :)
Description
You are given a list of numbers with 2 < n <= 6 length i.e. [1, 10] or [75, 9, 9, 8, 2, 100]. Given the basic operators + - / * you must try and generate all possible equations. The list of numbers to pull from is: [1, 1, 2, ... |
I have the code below working. But there must be a better way.
file <- "http://s3.amazonaws.com/assets.datacamp.com/production/course_1127/datasets/tmp_file.csv"
x <- read.csv(file = file)
ts <- xts(x = x, order.by = as.Date(rownames(x), "%m/%d/%Y"))
cd=coredata(ts)
for (j in 1:length(names(ts))) cd[,j]<-cd[,j]/cd[1,... |
Euclidean distance between two lattice points \$(x_1, y_1)\$ and \$(x_2, y_2)\$ on a plane is: \$\sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2}\$.
Imagine now a lattice N x N replicated infinitely many times next to itself. The two points \$(x_1, y_1)\$ and \$(x_2, y_2)\$ also get replicated. Euclidean distance on a torus is t... |
Given an \$m \times n\$ matrix of integers A, there exist a \$m \times m\$ matrix P, an \$m \times n\$ matrix D, and an \$n \times n\$ matrix Q such that:
\$A = P D Q\$.
P and Q are unimodular matrices (i.e. matrices which are invertible and whose inverses are also integer matrices);
D is diagonal;
each diagonal entry... |
Here is Minkowski's question mark function:
It is a strictly increasing and continuous function from the reals to themselves that, among other unusual properties, maps rational numbers to dyadic rationals (those with a power-of-two denominator). Specifically, suppose the continued fraction representation of a rational... |
Here's a very simple little problem that I don't believe has been asked before.
Challenge
Write a program or a function that takes in four positive integers that represents the lengths of movable but unbreakable and unbendable straight fences. Output the area of the largest rectangular yard that can be fully encompasse... |
Challenge
Write a program or function that takes in 4 non-negative integers, A, B, C, and D, that represent two fractions, A/B and C/D, where B and D are non-zero and A <= B and C <= D.
Output an ASCII art depiction of the fractions made of |x- characters on two lines as follows:
The lines will always be the same, min... |
Thunno 2 is a stack-based golfing language with around 400 commands (achieved through overloads) created by me, The Thonnu.
It seems like a good idea to share some tips for golfing in Thunno 2.
Please, one tip per answer, and no tips like “remove comments and whitespace”.
Links:
Tutorial
List of commands
Attempt This... |
The Quine-McCluskey algorithm merges disjunctors in a disjunction like
$$
\lnot x_0 \land \lnot x_1 \land \lnot x_2 \land \lnot x_3 \lor\\
x_0 \land \lnot x_1 \land x_2 \land \lnot x_3 \lor\\
\lnot x_0 \land x_1 \land x_2 \land \lnot x_3 \lor\\
\lnot x_0 \land \lnot x_1 \land \lnot x_2 \land ... |
Consider a sorted array of positive floating point numbers such as:
input = [0.22, 2.88, 6.35, 7.17, 9.15]
For each integer \$i\$ from 1 up to the last value in input rounded up, output the mean of all values less than \$i\$.
In this case the output should be:
[0.22 0.22 1.55 1.55 1.55 1.55 3.15 4.155 4.155 5.154 ]
I... |
Although it's done a few times as sub-challenge of a larger challenge, and we also have a challenge to remove the borders of a square matrix, I couldn't find a challenge to output the borders of a given matrix, so here it is.
Challenge:
Given a rectangular-shaped matrix containing integers as input, output its borders.... |
In this challenge, your input is an integer value. Your task is to find the sum of the range of the sum of the range of n.
Examples:
Input -> Output
1 -> 1
2 -> 6
3 -> 21
4 -> 55
5 -> 120
6 -> 231
7 -> 406
8 -> 666
9 -> 1035
10 -> 1540
This challenge should be fairly simple to co... |
A redox reaction is a chemical reaction in which elements transfer electrons. One element loses electrons, while another gains electrons. Oxidation is the process where an element loses electrons, and reduction is the process where an element gains electrons. Since electrons have a negative charge, the oxidation number... |
Suppose we want to encode a large integer \$x\$ as a list of words in such a way that the decoder can recover \$x\$ regardless of the order in which the words are received. Using lists of length \$k\$ and a dictionary of \$n\$ words, there are \$\binom{n+k-1}k\$ different multisets possible (why?), so we should be able... |
So I got kinda bored and was wondering if it was possible to make this code shorter without modifying anything except a file named coin.py...
from random import*;c=['heads','tails'];print('u win'if choice(c)==input(' / '.join(c)+': ')else'u lose')
The program asks the user for either "heads" or "tails", if the result ... |
Goal
Write a function or a program that when given a string, for example "The quick brown fox jumps over the lazy dog", outputs:
T h e q u
i
e r t h e c
v k
o l
a b
s z r
p y o
m g o d w
u n
... |
This challenge was inspired by this non-challenge about the natural logarithm base \$e\$ and the following pandigital approximation to \$e\$ appearing on a Math Magic page:
$$\left|(1+9^{-4^{7×6}})^{3^{2^{85}}}-e\right|$$
$$\approx2.01×10^{-18457734525360901453873570}$$
It is fairly well-known that
$$e=\lim_{n\to\infty... |
Challenge Description:
An anagram is a word or phrase formed by rearranging the letters of another word or phrase. For example, "listen" and "silent" are anagrams. In this challenge, your task is to write a program or function that takes a list of strings as input and returns the unique anagrams.
Write a program or fun... |
Motivated by this challenge
Background
Let we have a square sheet of flexible material.
Roughly speaking, we may close it on itself four ways:
Here the color marks the edges that connect and the vectors indicate the direction.
The sphere and torus are obtained without flipping the sides, Klein bottle — with one flippi... |
Credit: Marco Verch CC BY 2.0
A two-cube calendar, as shown in the picture, uses two cubes with digits painted on the faces to display the date. For dates in the range 1-9, a leading zero is used ("01", "02", ..., "09").
Now, if you do the math, you might come to the conclusion that these calendars should be impossibl... |
Background
In Python, function arguments are defined within the parentheses following the function name in the function definition. There are different ways to present function arguments, and they can be categorised into three types:
Positional-only arguments,
Positional or keyword arguments, and
Keyword-only argument... |
The resultant of two polynomials is a polynomial in their coefficients that is zero if and only if \$p\$ and \$q\$ have a common root. It is a useful tool for eliminating variables from systems of polynomial equations. For example, it is used in my answer to the code golf challenge Add up two algebraic numbers.
The res... |
Below on the left is a picture of a sorting network that can sort 4 inputs. On the right you can see it sorting the input 3,2,4,1.
A sorting network of size n consists of a set of n horizontal wires where two wires can be connected by a vertical wire. The inputs to a sorting network move from the left to the right on ... |
In this challenge you will write a function that takes a list (ordered set) containing real numbers (the empty list is an exception, as it has nothing) and calculates
$$f(x)=\begin{cases}1 & \text{if } |x|=0 \\ x_1+1 & \text{if } |x|=1 \\
\log_{|x|}\sum_{n=1}^{|x|}{|x|}^{x_n} & \text{otherwise}
\end{cases}$$
where \$|x... |
In any programming language, make a program that outputs infinite subsequent powers of two, starting at any power of two with finite integer exponent. There does not need to be a seperator between outputs.
Note: it only has to theoretically output infinite subequent powers of two given infinite integer size (so you can... |
Given a list, L, of sets of numbers like this:
[[1], [0,2,3], [3,1], [1,2,3]]
Output a single list of numbers such that 2 numbers A and B appear next to each other at least once if and only if B in L[A].
That is all such pairs must exist in the output, and only such pairs may exist in the output, where the order of an... |
Introduction
I would like to drawn a nice spinner by using eight braille patterns on two lines, drawing a square of 8x8 pixel, for showing a kind of snake growing and reducing:
declare -a shapes=([0]=$'\E[A⠁⠀⠀⠀\E[B\E[4D⠀⠀⠀⠀' [1]=$'\E[A⠈⠀⠀⠀\E[B\E[4D⠀⠀⠀⠀' [2]=$'\E[A⠀⠁⠀⠀\E[B\E[4D⠀⠀⠀⠀' [3]=$'\E[A⠀⠈⠀⠀\E[B\E[4D⠀⠀⠀⠀' [4]=$'\E... |
Carcassonne is a tile-based game, where the objective is to construct Roads, Cities and Monasteries, in order to score points. The game works by players taking turns to draw and place tiles to construct a landscape, then claiming roads, cities and monasteries. An example landscape is:
There are \$19\$ distinct tiles (... |
Bitshift Variations in C Minor by Robert Miles is a Code Golf music piece written in C (with some additional bash commands). It was originally presented in a 2016 Computerphile video Code Golf & the Bitshift Variations. You can listen to clean renderings of it here (by Lucia Ceionia).
The original 2016 source code pres... |
Create the shortest program/function/whatever that splits an inputted string along un-nested commas. A comma is considered nested if it is either within parentheses, brackets, or braces.
Input and output
Output should be a list or a string joined with linebreaks. The input may contain any characters. All testcases wil... |
Given a text input such as:
THE QUICK
BROWN FOX
JUMPS OVER
THE LAZY
DOG
render the following output:
/\
\ \
/ \
/ /\/
/ / /\
/ / / /
... |
What is the shortest regular expression equivilant to the following?
ENERO|GENER|GENNAIO|IANUARI|IANUARII|IONAWR|JAANUARIL|JANAIRU|JANAR|JANNEWARIS|JANUAR|JANUARI|JANUARIE|JANUARO|JANUARY|JANUWALE|JANVIER|JANVYE|JENUWARI
The shortest regex, in bytes, wins.
If you are worried about what flavor of regex we are using, th... |
Arturo is a bytecode-compiled/interpreted, garbage-collected general-purpose language filling a role similar to JavaScript, Python and Ruby. It is centered around the concept of blocks, which hold code just as easily as data. It uses fixed-arity prefix syntax and emphasizes the procedural and functional paradigms.
What... |
Background
An interesting way to solve a Sudoku puzzle is to represent it as a Boolean satisfiability problem, and then feed it to a SAT solver.
A Boolean Satisfiability Problem (abbreviated as SAT problem) is a problem in which you are given a set of Boolean expressions, and you need to find a set of values for the va... |
I am working on a code to print all semimagic squares [1] of a given size. I am working with the following definition:
An \$n\times n\$ consists of numbers \$1,2,\cdots, n^2\$.
All numbers must be distinct.
Sum of each row and each column is equal.
According to Ripatti A. (2018) [1]:
\$n\$
number of semimagic squ... |
A digit addition generator of an integer n is any integer x that satisfy the equation x + s(x) = n, with s(x) being the sum of the digits of x. (We will work under base 10 for convenience.)
For example, a digit addition generator for 29 would be 19, because 19 + (1 + 9) = 29. Some numbers have more than one generator. ... |
Task
Given \$n\$, output position of the last odd digit in the decimal representation of \$2^n\$ (counting from the end).
Rules
There are no odd digits for \$n=1,2,3,6,11\$ \$(2, 4, 8, 64, 2048)\$ - you may output anything that is not a positive integer for them (no need to be consistent).
You choose whether to handle... |
Problem
You are given a binary string A of length N.
You can perform the following type of operation on the string A:
Choose two different indices \$i\$ and \$j\$ (\$1 \le i\$, \$j \le N\$)
Change \$A_i\$ and \$A_j\$ to \$Ai \oplus Aj\$. Here \$\oplus\$ represents the bitwise XOR operation.
Input
A binary string con... |
Challenge
Given some JSON data, calculate the maximum depth reached. (Both arrays and dictionaries increase the depth)
Input/Output
The program is expected to read a JSON string from stdin and as soon as the program receives a \n start calculating the max depth, printing it to stdout and terminating the program when do... |
What is Crazyhouse Chess?
Crazyhouse Chess is a chess variant that is basically normal chess except you can place a piece you previously captured back on the board instead of a regular turn.
Bot interface
Only JavaScript bots are allowed.
A bot is a JavaScript function that takes 3 arguments (board, side, bank) and ret... |
Suppose you have a grid of cells that is 6 wide and arbitrarily tall. In each cell is a word. Let the bottom row, which is row #1, be the last 6 words of sample.txt in order. Let the second to last row, which is row #2, be the 6 words before those in order. (etc.)
Then consider what happens when you remove some of the ... |
A regular dodecahedron is one of the five Platonic solids. It has 12 pentagonal faces, 20 vertices, and 30 edges.
Your task is to output the vertex coordinates of a regular dodecahedron. The size, orientation, and position of the dodecahedron are up to you, as long as it is regular.
You may output the coordinates in a... |
What tips do you have for golfing in (,)? I've found that there are so many ways to make code shorter, and I want more ways. I doubt there even are any tips for (,) that are applicable in the majority of programming languages, but if there are, feel free to include them.
Please, one tip per answer.
|
Create A "Hello, World!" program but without any vowels. Winner is the program with the least bytes.
Rules:
No vowels are allowed in the code.
Must print to STDOUT
Must be a full program.
Submissions are measured in Bytes
Any language goes as long as there aren't any vowels
Edit:
Y is only a vowel if there aren't any... |
In probability theory, a Bernoulli variable is a random variable which has a single parameter \$p\$, and is equal to 1 with probability \$p\$, and 0 with probability \$1-p\$.
In this challenge, there are a bunch of independent Bernoulli variables with parameters \$p_1, p_2, ... , p_n\$, and their XOR is calculated. The... |
Given a set of intervals \$\mathcal{I} = \{I_1, \ldots, I_m\}\$, where each interval \$I_j\$ is represented by its bounds \$(a_j, b_j)\$, find a partition \$\mathcal{T}\$ of \$\mathcal{I}\$ of minimal cardinality such that for each set \$T_i \in \mathcal{T}\$ it holds \$\bigcap T_i \ne \emptyset\$. In other words, find... |
Given an input integer from 1, 2, ..., n, the task to write code to make a number as close as possible (as measured by absolute distance) to e using only the four mathematical operations +, -, *, / and parentheses (brackets). You can use any of the integers up to n once but don't have to use all the numbers and you are... |
With roughly one second (plus or minus 10 ms) between outputs, output anything.
The first output must be at most one second after the start of the program, but can be as soon as right when the program starts.
So, the first output can be up to a second after the program starts, the second exactly one second after that, ... |
Inspired by this SO answer about peak detection.
Background
Persistent homology is a fancy term for a fancy math concept, but in this case all we care about is how it can be used for peak detection. In the case of a 1-dimensional array we can describe the algorithm as follows:
We are given an array as input. We begin b... |
The keitai input method is a method for writing Japanese kana on a 12-key phone keypad. Similar to Western keypads, each kana is assigned to a key; when the key is pressed multiple times, it cycles between all kana assigned to that key.
You will be using the following key-kana assignments, with this order of kana (base... |
Given an integer n, your task is to determine whether it is a perfect square that when reversed, is still a perfect square. You may assume n is always positive.
When numbers such as 100 (10x10) are reversed the result may have leading zeros (001) In this case, ignore the leading zeros and treat it as 1 (1x1).
Test case... |
Write a function (or a whole program) that outputs (or prints) an ASCII art of the initial position of Mölkky pins.
Output :
__ __ __
__(07)__(09)__(08)__
(05)__(11)__(12)__(06)
| (03)__(10)__(04) |
| | (01) (02) | |
|__| | | | | |__|
|__| |__| |__|
|__| |__|
Rules :
This is code-go... |
Background
We define the two types of chain to be a string that contains only dashes, "-", or only underscores, "_". We link two chains using one equals sign, "=".
Criteria:
The type of chain must change following an equals sign.
You must link the chains, you can do so multiple times, and it does not matter what lengt... |
A followup to this challenge by Jeremy Collprav, inspired by DLosc solving this in Regenerate. Some sections copied from the linked challenge.
Linking chains
We define a chain to be a string containing exactly one or more of only the - character, or 1 or more of only the _ character, or two chains linked by a =. More f... |
Background
You have been given the task of calculating the number of landmines in a field.
You must calculate the landmine score given a list/string of numbers and the landmine number.
The landmine number tells you where landmines are.
For each digit:
if the left digit plus the right digit is equal to the landmine num... |
Background
You have again been given the task of calculating the number of landmines in a field. However, we have now travelled into the flatlands.
You must calculate the landmine score given a list/string of numbers (which will be 2D) and the landmine number.
The landmine number tells you where landmines are.
For each... |
Background
You are planning your trip away from the Diamond City, and must travel through Diamond Road. However, Diamond Road branches away from Diamond City to different locations.
Out of curiosity, you'd like to measure the total distance of unique roads used for all paths.
We define a path as a string that only cont... |
Given an initial \$n\$-tuple \$t_0=(t_{0,1},...,t_{0,n})\$, we can obtain its corresponding Ducci sequence \$\{t_0, t_1, ...\}\$ by the recurrence \$\displaystyle t_{i+1}=\left(\left|t_{i,1}-t_{i,2}\right|,\left|t_{i,2}-t_{i,3}\right|,...\left|t_{i,n}-t_{i,1}\right|\right)\$.
That is, to obtain the next term of the seq... |
Background
You have again, again been given the task of calculating the number of landmines in a field. But this time, the field is foggy.
You must calculate the landmine score given a list/string of numbers, the landmine number, and the land distance (all are numbers).
The landmine number tells you where landmines are... |
Inspired by the fact that a few related challenges to this could be answered by Vyxal in 0 Bytes using a special flag combination.
Given only one input integer \$n\$, calculate \$f(n,n)\$ where
$$ f(x,y)=
\begin{cases}
x & \text{if } y=0 \\
f(\left(\sum_{k=1}^xk\right),\text{ }y-1) & \text{otherwise}
\end{cases}
$$
If ... |
Background
In the game stick ranger, there is an item which grants the character the ability to get critical hits.
Each time a projectile hits an enemy, it has some probability to be a critical hit (crit). For most weapons this is calculated independently each time, but for one class (the angel) things work differently... |
There is a challenge for multiplying two numbers so I guess this counts too
Given as input a positive real number n compute its natural logarithm.
Your answer should be within \$10^{-6}\$ for \$1 \leq n \leq 10\$ and within \$10^{-3}\$ for \$0.1 \leq n \leq 100\$. You don't need to handle numbers outside this range.
Se... |
Background
You have again x3 been given the task of calculating the number of landmines in a field. But this time, we have no landmine number, and some landmines have exploded.
You must calculate the landmine score given a string of numbers. This is the landscape.
You have no landmine number to start with. Instead, the... |
Conway's Game of Life is a cellular automaton "played" on an infinite grid, filled with cells that are either alive or dead. Once given an initial state, the board evolves indefinitely according to the following rules:
Any live cell with 2 or 3 living neighbours lives to the next state
Any dead cell with exactly 3 liv... |
Background
You have again x4 been given the task of calculating the number of landmines in a field. But this time, the field is not a number field... it's a field of letters. Our landmine letter operator is sick and requires you to cover for them. They left you the following note:
Things work a little differently with... |
Given a number x, find the sum of all primes up to that number.
The input will always be a positive number, bigger than 2. An upper limit isn't defined, so data types can be ignored. Use whichever you want.
This is a code-golf, so the shortest code in bytes wins.
Example for 5:
2 + 3 + 5 = 10
Test cases:
Input
Ou... |
Diagonalize a vector into a matrix.
Input
A vector, list, array, etc. of integers \$\mathbf{v}\$ of length \$n\$.
Output
A \$n \times n\$ matrix, 2D array, etc. \$A\$ such that for each element \$a_i \in \mathbf{v}\$,
$$
A =
\left( \begin{array}{ccc}
a_1 & 0 & \cdots & 0 \\
0 & a_2 & \cdots & 0 \\
\vdots & \vdots & ... |
Background
A ray of light is fired from the top left vertex of an MxN Chamber, where M a denotes the width and N denotes the height of the chamber. The ray of light advances one grid space per second. Given that T is the number of seconds to be simulated, calculate the number of reflections in this time frame.
For exam... |
Output this table:
-2*
-1*
-
0
-
1
2
-1*
0
1
-
2
3
4
1
2
3
-
4
5
6
3
4
-
5
-
6
7
5
6
-
7
-
8
9
6
7
8
-
9
10
11
8
9
10
-
11
12
13
10
11
-
12
-
13
14
You can output one string with two types of split, 1D string array with one type of split, or 2D string array
If your language support mix... |
Your task is it to output a number as a unary string. You get the number of a non-negative integer input in the range of 0 - 2'000'000'000.
Rules
You can choose any character for the digit you like. But it has to be the same everywhere and for every input.
Output a unary string by outputting this character N times. N... |
Balanced ternary is a modified version of ternary (base 3), using the three digits 1,0 and -1 (written as T) to represent numbers.
The balanced ternary representation of -n can be obtained by replacing 1 with T and T with 1 in the balanced ternary representation of n.
Examples:
1 // decimal: 1
T // decimal: -1
... |
My first code golf question post! Hope u like it ;-)
The task is simple. Write either an stdin-stdout program or a function. Input is a 2D array which contains only either characters or the integer 0. You are allowed to replace the integers with the character '0' or null instead in any language (kudos to @SuperStormer ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.