instruction stringlengths 34 53.1k |
|---|
Given a decimal integer n as input, output the smallest (in terms of absolute value) decimal integer m such that the absolute value of n-m is a binary integer (composed only of 1s and 0s).
n and m can be any integer, positive or negative.
Example
Let n = 702. The closest binary integer is 1000 = |702 - (-298)|, so m = ... |
In this challenge you will receive a list of non-negative integers. Each one represents a mushroom with a cap of that radius centered at that location. So a 0 means that it occupies no space at all, a 1 means that its cap only occupies space above it, a 2 means it occupies space above it and one unit to the left and ... |
For this challenge, we will define the "complement" of a list of integers A as being any list B such that the union of A and B is a list of consecutive integers with no repeats.
In other words, B is the complement of A if
B has all of the integers between the minimum and maximum of A which are missing from A, and
B ha... |
Related.
Given a list of 3 or more positive integers, remove every number X for which there is another number Y in the list and the average of X and Y is also in the list. In other words, if X, Y, and the average of X and Y are all in the input, neither X nor Y should appear in the output.
Note: Pairs of numbers are no... |
So I have the situation where I have one boolean value a and, if that one is true and b<c I want it to end up as true, if a is false and b>c I want it to resolve as true as well. If b=c I want it to be always false, no matter the value b and c are both numbers. My best approach so far is a?b<c:b>c or maybe b^c^a^b<c. I... |
In this challenge you will receive a list of pairs of non-negative integers representing a mushroom forest. Each pair represents a mushroom whose center is at that horizontal coordinate. The only part of the mushroom we care about is the cap (the flat bit at the top).
The first integer in each pair represents which ro... |
Say I have a grid with some obstacles:
----
| X |
| |
|XX |
| |
----
I can fill this with numbers, as distance from the top left corner. But, because there are obstacles in the way some cells will take further to reach than a straight line:
----
|01X5|
|1234|
|XX45|
|7656|
----
This can be done through f... |
In the hovertext of this xkcd:
There's an "encoding" based on replacing runs of roman numerals with their sums. To do this:
Find all runs of at least 1 roman numeral (IVXLCDM)
Replace them with their sums, as numbers
The Roman Numerals are IVXLCDM, corresponding respectively to 1, 5, 10, 50, 100, 500, 1000. You shou... |
The Fibonacci polynomials are a polynomial sequence defined as:
\$F_0(x) = 0\$
\$F_1(x) = 1\$
\$F_n(x) = x F_{n-1}(x) + F_{n-2}(x)\$
The first few Fibonacci polynomials are:
\$F_0(x) = 0\$
\$F_1(x) = 1\$
\$F_2(x) = x\$
\$F_3(x) = x^2 + 1\$
\$F_4(x) = x^3 + 2x\$
\$F_5(x) = x^4 + 3x^2 + 1\$
When you evaluate the Fibo... |
For this challenge, a word is defined as a string of letters, separated by spaces.
Given a string of words, and an integer i representing an index into that string, output the whole word which contains the character at index i.
For example (using 0-based indexing), with the string code golf, and the index 6, the 7th ch... |
In this challenge we considered a frog hopping around a lily pond. To recap the lily pond was represented as a finite list of positive integers. The frog can only jump forward or backwards by a distance equal to the number at its current location. So for example:
[2, 3, 1, 4, 1]
Here the frog is on a 1 so i... |
Related
Sometimes when I use my microwave, I do a little trolling and enter times such as 2:90 instead of 3:30 because they end up being the same time anyway. The microwave happily accepts this and starts counting down from 2:90, displaying times like 2:86 and 2:69 until it gets back to a stage where it can count down... |
Write the shortest program or function that mimics the addition in this XKCD strip:
Input
Two positive decimal integers containing only the digits 150.
Output
The positive decimal integer result of adding the two inputs together in the manner shown above. This output should also only have the digits 150.
Specification... |
In this challenge, you'll print out the SBCS of Jelly, a popular golfing language. Its code page looks like this:
_0
_1
_2
_3
_4
_5
_6
_7
_8
_9
_A
_B
_C
_D
_E
_F
0_
¡
¢
£
¤
¥
¦
©
¬
®
µ
½
¿
€
Æ
Ç
Ð
1_
Ñ
×
Ø
Œ
Þ
ß
æ
ç
ð
ı
ȷ
ñ
÷
ø
œ
þ
2_
!
"
#
$
%
&
'
(
)
*
+
,
-
.
/
3_
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
4... |
FizzBuzz is where a range of positive integers is taken, and numbers divisible by 3 are replaced with "Fizz", divisible by 5 with "Buzz" and divisible by 15 with "FizzBuzz".
I've got some FizzBuzz output here. Unfortunately, it's been shuffled:
4
Fizz
Fizz
Buzz
2
A bit of logic shows us that this is 2, Fizz, 4, Buzz, ... |
Lambda calculus is a system of computation based on single-argument functions; everything in it is such a function. Due to this functional nature, juxtaposition is commonly used to denote function application, grouped from left to right. For example, \$(f g) h=f g h\$ denotes what would conventionally be written \$(f(g... |
There's a payment machine for laundry in my building which does a few frustrating things. The ones relevant to this challenge are:
It doesn't make change. So if you pay over the amount then you are not getting that over-payment back.
It doesn't accept coins smaller than 20c. Meaning the only coins it accepts are 20c... |
Given a string containing a sequence of ascending consecutive positive integers, but with no separators (such as 7891011), output a list of the separated integers. For that example, the output should be [7, 8, 9, 10, 11].
To disambiguate the possible outputs, we add the restriction that the output must always have at l... |
A twin of this.
FizzBuzz is where a range of positive integers is taken, and numbers divisible by 3 are replaced with "Fizz", divisible by 5 with "Buzz" and divisible by 15 with "FizzBuzz". For example, FizzBuzz from 1 to 10 is 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz.
Your challenge is to, given a list of Fizzes, B... |
Goal
You have to print the ASCII printable characters' code page (0x20-0x7E).
The output should look like this:
!"#$%&'()*+,-./
0123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_
`abcdefghijklmno
pqrstuvwxyz{|}~
Rules
The output should be exactly like shown above, but trailing whitespace is OK.
No builtins that triv... |
A pristine program is a program that does not have any errors itself but will error if you modify it by removing any contiguous substring other than the entire program.
A crystalline program is sort of the opposite. It is a program which doesn't have any errors itself but will error if you modify it by adding any 1 cha... |
This challenge will be based on an R language trivia: every release is named and it's a reference to Peanuts comic strips (see here and here).
Task
Given a release name, output its number.
For reference, use the below list:
Great Pumpkin 2.14.0
December Snowflakes 2.14.1
Gift-Getting Season 2.14.... |
In these previous challenges[1][2] I've been dealing with "mushroom forests". To help with these I draw little diagrams of the forests to help. In this challenge we are going to reverse engineer the data from these diagrams.
To recap ha! mushroom forests are a list of pairs of non-negative integers. Each pair repres... |
Given n, k, and p, find the probability that a weighted coin with probability p of heads will flip heads at least k times in a row in n flips, correct to 3 decimal digits after decimal point (changed from 8 because I don't know how to estimate the accuracy of double computation for this (was using arbitrary precision f... |
Background
The monkeys need help organizing their defense and have asked you, Benjamin the code monkey, to create a program that will list all tower upgrade options. Each tower has three unique upgrade "paths", each having a tier represented by a number between 0 and 5 inclusive, 0 meaning no upgrade. Up to two paths m... |
Challenge
Create the image of a progress pride flag.
Output
Dimensions
Rules
Your program must create the image and not just load it from a website
The colours can be just your language's default if it is very difficult / impossible to load RGB values, else they should be: red: (255,0,0), orange: (255,140,0), yello... |
Given a list \$X\$ of 2 or more integers, output whether, for all \$n\$ such that \$0 \leq n < length(X)-2\$, there exists a pair of equal integers in \$X\$ separated by exactly \$n\$ elements.
In other words: output whether, for all overlapping slices/windows of the input, there exists at least one slice/window of eac... |
This is a repost of this challenge
Challenge
There is an old, popular riddle:
Find an English word with 8 letters that, taken away one letter, creates a new valid word. Repeat that until there are no letters left.
Example solution:
starting
staring
string
sting
sing
sin
in
I
Your task is to write a program, which t... |
We all know that any positive integer can be represented as the sum of powers of two. This is how binary representations work. However there's not just one way to do this. The canonical method, used in binary representations represents it as the sum of unique powers of two. For example \$5=2^0+2^2\$. However since \... |
I came across this picture the other day: (Credit to Josep M Batlle I Ferrer)
Your job is to generate this picture. This graph is generated by repeatedly applying newton's method to the graph of:
$$f(x)=\cosh(x)-1$$
In other words, repeatedly apply the following function to every point till the rectangular distance is... |
You want to write your English essay. However, all characters on your keyboard broke other than the arrow keys and the enter key. You want to find out how to place the characters so you can write your essay with the least movement.
Formally, you have to assign to each character of !"$%&'()+,-./0123456789:;<=?[]`abcdef... |
Background
In programming, there is a recursive algorithm called binary exponentiation, which allows for large integer powers to be calculated in a faster way. Given a non-zero base \$x\$ and a non-negative exponent \$n\$, the algorithm goes something like this (based on the example code from Wikipedia):
Function exp_b... |
Background (feel free to skip)
Ordinals are the abstract representation of well-orders. A well-order of a set is a total order, which basically means that every element in the set can be compared against any other element in the set, and one of them is either smaller or larger. Also there are no cycles.
The crucial dif... |
Given a matrix of non-negative numbers (of arbitrary dimension) and a number, get all multi-dimensional indices of the number in that list.
For example, let's say we have the list [[0,1,0],[1,0,0]] and the number 1. In the first list, we see one 1 at the second index. If we were using one-based indices, this would be i... |
Find a bijective function which maps integers to arbitrarily large tuples of integers. Given the input \$n\$, output the tuple it matches to.
Edit: The empty tuple is included in the mapping.
|
I noticed that it seems nobody has posted a non-ASCII (related) USA flag challenge yet, so what better time than the 4th of July?
The Challenge
Draw the current (as of 2022) flag of the United States of America.
Here is the flag:
Specifications
Hoist (height) of the flag: A = 1.0
Fly (width) of the flag: B = 1.9
Hoi... |
Inspired by this accidental misspelling
If you could read the title, then you already know what the challenge is about. If not, then I'll tell you. Easy: simply take each word (single space delimited), and swap the positions of the first two letters. You may assume that the input will contain only lowercase ASCII let... |
Background
When searches return many pages of results, GitHub avoids cluttering their UI by eliding page links. Instead, their UI lets you select:
Pages at the beginning of the results.
Pages near the current page.
Pages at the end of the results.
In this way, no more than 11 page links are ever displayed at one tim... |
Task
In this challenge, your task is to write a program or function which takes an array of paths with an additional boolean indicating it is a file or directory and outputs a file/directory tree in any reasonable format.
Remarks
Some directories can end with a forward slash ("/") but this is not always the case
A par... |
In this challenge you will be given a list of positive integers which represents some range of integers which has been truncated for display. Your job is to find the missing bits and insert ellipses to show that that part has been truncated.
The input will always be strictly ascending and if two consecutive values dif... |
Implement a function or program which raises x to the power of y. Inputs are 16-bit signed integers. That is, both are in the range [-32768, 32767]. The output should be in the same range. I chose this range because it should make it possible to do exhaustive testing to ensure all edge-cases are covered.
If the output ... |
Greeklish, a portmanteau of the words Greek and English, is a way of writing modern Greek using only ASCII characters. This informal way of writing was extensively used in older applications / web forums that did not support Unicode, and were not programmed to show Greek characters. Nowadays, its use is minimized due t... |
If you place the positive integers together and read each set of two adjacent digits at the same time, you get: (A136414)
12, 23, 34, 45, 56, 67, 78, 89, 91, 10, 1, 11, ...
However, if you squash that sequence again:
12, 22, 23, 33, 34, 44, 45, 55, 56, 66, 67, 77, 78, 88, 89, 99, 91, 11, 10, 1, 11, 11
and so on.
Your... |
Given a list of positive integers as input you are to determine if there is a way to pair up the elements such that:
All but one element is in a pair
No element is in more than one pair
Every pair is of equal elements
No two pairs have elements separated by the same distance in the original list
For example if the in... |
Background
I was working on a system where for convenience (not security) people could use four digit codes to identify themselves. I figured this is something that may actually be useful in many real cases, yet is well enough defined that it could make a nice challenge!
Explanation of pin codes and typo resistant sets... |
Background
On a Rubik's cube there are 54 moves that you can execute, for example, turn the right face anti-clockwise, or rotate the top face and the horizontal slice twice. To notate any move, each face (or slice) has a letter assigned to it. To move that face clockwise once, you just write the letter on its own, so f... |
Background
A backronym is an acronym that was formed from an existing word. For example, spam is actually named after the canned meat product as used in the Monty Python sketch, but can be interpreted as "stupid pointless annoying mail".
Challenge
Given a string a, and a word t, capitalise the correct letters of the w... |
Warning: Contains minor Deltarune Chapter 1 Spoilers
Within the Forest section of the first chapter of Deltarune, there are a few puzzles that consist of entering playing-card suits in a certain order to move to the next section. Below is an example of such a puzzle:
The way to solve the puzzle is to do any of the ... |
Given an positive even integer \$ n \$, output the set of "ways to pair up" the set \$ [1, n] \$. For example, with \$ n = 4 \$, we can pair up the set \$ \{1, 2, 3, 4\} \$ in these ways:
\$ \{\{1, 2\}, \{3, 4\}\} \$
\$ \{\{1, 3\}, \{2, 4\}\} \$
\$ \{\{1, 4\}, \{2, 3\}\} \$
This can more formally be described as the ... |
Introduction
Many old chess books use descriptive notation to notate squares on a chessboard, naming the file (column) of the square based on the starting piece positions of White or Black, depending on whose move it is. The ranks (rows) are numbered 1 through 8, with 1 being closest to the player. For example, from Wh... |
In some languages, strings are started and ended with a quote mark ('). And quote itself is escaped by writing it twice sequentially. For example, empty string is written as '', and I'm is written as 'I''m'.
This question is about find out all non-overlapping strings from left to right in such format from the given inp... |
Your task is to output all possible ways to end a game with a tie (all rows, columns, and diagonals are completely filled and do not have 3 X's or 3 O's, and there are exactly 5 X's and 4 O's in total) in Tic-Tac-Toe (assuming X goes first):
OXO XXO XOX OXX
XOX OOX XOX XOO
XOX XXO OXO OXX
XOX XOX OXX XXO
O... |
Related
We start with the string a, and forever append to the string a comma followed by the string quote-escaped, where quote-escaping means doubling all quotes in a string, and then surrounding it with an additional pair of quotes.
In the first few steps we will get:
a
a,'a'
a,'a','a,''a'''
a,'a','a,''a''','a,''a'',... |
Story:
The π was recently computed with accuracy to 100 trillions digits, but it is useless to us. We can't do accurate enough math, because rational numbers are too boring and so we don't know that much digits of them!
Challenge:
Your task will be to write program or function which takes string of digits including dec... |
Given a multi-line string as input containing characters "|", "_" and " " (space), count the number of cells it contains.
A cell is the following structure of 3 characters by 2 lines:
_
|_|
That is, an underscore on one line (the characters to its right and left don’t matter), and "|_|" right below it.
Two cells can ... |
In this challenge you will receive as input a list of binary lists. The list represents a game board with each element representing a location on the board. The list at each location represents the tiles on the board, with a 0 being a white tile (□) and a 1 being a black tile (■). Each place can have any number of t... |
Special String
We call a binary string \$S\$ of length \$N\$ special if :
substring \$S[0:i+1]\$ is lexicographically strictly smaller than substring \$S[i+1:N]\$ for \$ 0\leq i\leq N-2\$,
Note: \$ S[a:b] \$ is substring \$S[a]S[a+1]...S[b-1]\$
Given a binary string \$T\$ of length \$N\$ we are interested in the fi... |
Every now and again, I'll encounter a large string of alphabetical text encoded as numbers from 1-26. Before I knew that I could just google a translator online, I had to personally, painstakingly copy and paste the entirety of the encoded text into a text document and translate it myself.
Thankfully, I did know about ... |
Introduction
Super Mario 64 has a heavily overcomplicated RNG, ably explained here by Pannenkoek.
I thought it might be interesting to implement it.
Challenge
Implement the RNG function, except for the two special cases. (Not part of the below description; everything below is what you should implement.)
Input and outp... |
Given a string \$ x \$, we say another string \$ y \$ is half of it, if both of the following properties are true:
\$ y \$ is a (not necessarily continuous) subsequence of \$ x \$ - there exists a strictly increasing sequence \$ a_i \$ such that \$ y_i = x_{a_i} \$
Each character appears in \$ x \$ exactly twice as ma... |
Given a ragged list, we can define an element's depth as the number of arrays above it, or the amount that it is nested.
For example, with the list [[1, 2], [3, [4, 5]]] the depth of the 2 is 2, as it is nested within two lists: The base list, and the list [1, 2]. The depth of the 4 is 3 as it is nested within three li... |
The exponential generating function (e.g.f.) of a sequence \$a_n\$ is defined as the formal power series \$f(x) = \sum_{n=0}^{\infty} \frac{a_n}{n!} x^n\$.
When \$a_0 = 0\$, we can apply the exponential function \$\exp\$ on this formal power series:
\$\begin{align}
\exp(f(x)) &= \sum_{n=0}^{\infty} \frac{1}{n!} f(x)^n ... |
Given a string, shuffle it so that it becomes a palindrome.
For example, adadbcc can be arranged into dacbcad, or dcabacd, acdbdca and more. Any of these (or all) is acceptable, and duplicates are allowed if outputting all. Something like abc cannot be shuffled into a palindrome, and you can assume it won't be inputted... |
Let’s take a positive integer such as 123. We define the shifted auto-sum of this integer as follows:
123 has 3 digits. We thus consider 3 copies of 123.
We stack each copy on top of each other, shifted by 1 digit each time:
123
123
123
We pad each copy with 0s (excluding the last one) to get a standard column a... |
Suppose you have an array with some known set of values (e.g. a string of \$0\$ and \$1\$) and you want to get all the locations of \$1\$s. Instead of storing a list of all the indices, if the \$1\$s come in "clumps" you can sometimes save space by storing starting and ending indices of "runs" of values -- i.e. substri... |
I haven't. :P So I decided to define one:
A tralindrome is a string which contains three equal-length sections X, Y, Z such that
all characters in the string are included in at least one of the three sections,
X starts at the first character, Y starts at or right after the last character of X, and Z starts at or right... |
Inspired by this question.
Challenge
Let L be a list of n distinct elements. Let P be the set of all (unordered) pairs of positions in P. Let R be a result of applying a pair-swap operation on L by every pair in P in any order.
Example:
L = [1, 7, 8]
P = {(1, 2), (0, 1), (0, 2)}
L = [1, 7, 8] -> [1, 8, 7] -> [8, 1, 7] ... |
Take as input two strings \$A\$ and \$B\$. Output a string \$C\$ that is \$A\$ but with two characters swapped such that the Levenshtein distance \$d(C,B)\$ is as small as possible. You must swap two characters and you cannot swap a character with itself, although you may swap two identical characters in different po... |
Output the area \$A\$ of a triangle given its side lengths \$a, b, c\$ as inputs. This can be computed using Heron's formula:
$$ A=\sqrt{s(s-a)(s-b)(s-c)}\textrm{, where } s=\frac{a+b+c}{2}.$$
This can be written in various ways, such as
$$ A= \frac{1}{4}\sqrt{(a+b+c)(-a+b+c)(a-b+c)(a+b-c)}$$
$$ A= \frac{1}{4}\sqrt{(a^... |
Generate \$T=\{T_1,...,T_x\}\$, the minimum number of \$k\$-length subsets of \$\{1,...,n\}\$ such that every \$v\$-length subset of \$\{1,...,n\}\$ is a subset of some set in \$T\$
Here, \$n > k > v\$ and \$v \ge 2\$
Any number can appear only once in 1 set
Order of numbers is not important
Answer with code & explan... |
This was related to a program I am writing. Although the title is simple, the challenge is a lot more complicated.
Your challenge
You must write a program that takes an input, and your answer must match the sample outputs in this question.
What the program should be is that you must output "HelloWorld" with the length ... |
This is not the same as m-ss-ng-lette-s
Challenge:
Given a string with masked characters, generate all possible words, inclusive of non-meaningfull words.
Rules:
The sequence of the characters in the string does not change.
The masked character (*) will be one of an English alphabets [a-z].
There are no line breaks, s... |
Recently, I've found a rant from 2004 about Internet Explorer's color parsing. Turns out, MS made sure that just about anything will be parsed as a color somehow and I think it makes for a neat challenge.
Well, how does IE parse colors?
Let's give it an input with a length of...
...less than 4 chars:
Replace chars no... |
It is known that any natural number can be decomposed into the sum of three triangular numbers (assuming 0 is triangular), according to Fermat's Polygonal Number Theorem. Your task is to come up with an algorithm of decomposing number into 3 triangular numbers that has the best asymptotic complexity. As an input you ar... |
Write a program or function that takes a character as input and outputs a character. Also, choose a list of 13 distinct ASCII printable characters (32-126). When a character from this list is passed into the program or function, it should output the character at the corresponding position in Hello, world!. This way, ru... |
Background
Here on CGCC, a commonly seen subgenre is radiation-hardening – writing a program that works even if one character is deleted. A similar problem is studied in the field of coding theory: finding an encoding that can be decoded even if one symbol is deleted from the encoded string. In this challenge, we're lo... |
Given a string containing some parentheses and some other ASCII printable characters, like this: (abc((123))(k)) your task is to remove any sets of parentheses that are redundant.
A set of parentheses is redundant if:
It encloses another set of matching parentheses, like ab((123)), or
It encloses the entire string, li... |
We can model a rail network as a directed graph, where each node is a train station and each edge is a train connecting two train stations. We'll assume that each train travels between its corresponding stations at a regular schedule and takes a fixed amount of time
Your code should take a list of trains, where each tr... |
Your task is to write a program that performs case conversion from plain text, and other case formats, into one of the specified formats below. Inputs will be either plain lowercase text, or one of the detailed cases below. You must remove non-alphabetic characters except (space), _ (underscore) and - (hyphen), then ... |
Inspired by this
Your task today: given two strings, find the string with the lowest maximum Levenshtein distance to the input strings. For example, using Steffan and Seggan, the average string will be Steggan. It is distance 2 from Steffan (replace the gg with ff), and 1 from Seggan (add a t). That gives it a maximu... |
Given two non-negative integers e.g. 27, 96 their multiplication expression would be 27 x 96 = 2592.
If now each digits is replaced with a symbol, such that
two digits are replaced with the same symbol if and only if they are equal
we could get something like AB x CD = AECA or 0Q x 17 = 0Z10 or !> x @^ = !x@!.
(follo... |
Knight is the Language of the Month for August 2022, and I noticed that it didn't have a tips page, so here it is!
I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Knight (e.g. "remove comments" is not an answer).
Please post only one tip per answer.
|
During work on some project I needed to draw pixels on screen. I found some put-pixel function in JS, but code was quite big and clumsy - so I wonder, how small put-pixel function can be...
Challenge
Create the smallest put-pixel function.
We count size of whole program: initialization code (if needed), function and co... |
I could not think of a better title.
This is a tips question. I'm asking for tips on golfing my code.
I recently took part in a code golf competition in C. The competition ended and I lost. The problem is:
Input a line with a number n.
Then input n lines, each line contains only a set of cards in descending order, e. ... |
Given two strings: a string s and an alphabet a, implement string projection in the shortest code possible.
String projection returns a string o that contains the characters in s that are in a. The order of the characters in o must match the order of characters in s. So if s = "abcd" and a = "12da34", o = "ad", since o... |
So the golf question was like this:
You are given a number T and then a total of T number of 17-character strings. For each of the strings, output yes if it contains four consecutive identical characters or contains the substring DX, else output no.
The following constraints are promised for each of the 17-character ... |
If the agent is at the origin it always moves right when you choose it.
The goal is to get one agent to 10.
The cost is the sum of the square of the total number of moves (left or right) taken by each individual agent until the first agent gets to 10. You want to minimise the expected cost
Once you have fixed a strateg... |
Let us assume that we have number X.
Let us assume that we have positive integer "components" (C) of this X number.
We can add these components together like C1+C2+...+Cn = X.
We have N as limit of number of components.
We have B as limit of biggest component
Distribution: if we have [8;8;5] then avg of components is ... |
In most programming languages, arithmetic is written with infix notation -- i.e. the operator is put in between the operands -- e.g. 1+2. In contrast, with Polish notation (a.k.a prefix notation), the operator comes before the operands -- e.g. +1 2. As long as the number of operands for each operator is fixed, this mea... |
Given a positive integer n, output all of its anti-divisors in any order.
From OEIS A006272:
Anti-divisors are the numbers that do not divide a number by the largest possible margin. E.g. 20 has anti-divisors 3, 8 and 13. An alternative name for anti-divisor is unbiased non-divisors.
In other words, 1 < m < n is an a... |
We don't have a challenge for conversion between Cartesian and polar coordinates, so ...
The challenge
Write two programs (or functions) in the same language:
one that converts from polar to Cartesian coordinates, and
the other from Cartesian to polar coodrinates.
The score is the sum of the two program lengths in by... |
Challenge
Given a positive-length string \$S\$, a divisor of \$S\$ is another (not necessarily distinct) string for which there exists a number \$a\$ such that when we repeat the divisor \$a\$ times, we get the string \$S\$.
For example, the string abcd is a divisor of the string abcdabcd with \$a=2\$.
Your challenge i... |
In chess, the queen piece can move arbitrarily far in each cardinal and intercardinal direction. What does this mean? Well, I'll show you with an ASCII drawing:
\..|../
.\.|./.
..\|/..
---Q---
../|\..
./.|.\.
/..|..\
It means the queen (notated as Q) can move along these lines (notated as \, |, /, and -), and cannot r... |
We once made a Hexagony template without actually knowing it. But after a bit of experience with Hexagony, it becomes apparent that it is not enough; sometimes the source code is too short for the given hexagon, and you get totally unexpected results.
So I came up with an idea: a template that gives a hint when the cod... |
I noticed that in Microsoft Word, single quotations are either ‘ or ’, but not in Notepad. Your task today is: given a string q, convert all the ' characters (only) to ‘ or ’, according to these rules, and then output it:
If the character before the quote is a space, and after it comes a character, it becomes ‘
If the... |
Something I found while looking through some old files. It seemed like a neat idea for a code golf challenge.
The intro
One of the most popular events at the annual Cyclist's Grand Competition for Charity (CGCC) is the rocket bike parcours. The rules are simple: Inspect the parcours and place a bet on wheather is it po... |
In this game, you can look inside one box at a time chosen by you. When you do that, you can see how many coins there are in that box.
The wizard has one last twist for you. At any point, you can choose to give up on this set of boxes and get him to start the whole process again (with a new random \$x\$). Of course, i... |
Given a universe of \$v\$ elements, a Kirkman triple system is a set of \$(v-1)/2\$ classes each having \$v/3\$ blocks each having three elements, so that
every pair of elements appears in exactly one block
all classes are partitions of the universe.
Kirkman's schoolgirl problem corresponds to the \$v=15\$ case.
Fif... |
If you place a knight on any square of a chessboard, what is the smallest amount of steps to reach every position?
Rules
It is an 8 by 8 board.
The knight starts at an arbitrary position, taken as input.
The knight moves 2 squares in one direction and 1 square in the other, for example, a knight on the square marked N... |
Searching for rotatable numbers, like: 68089
If you consider numbers upside-down,
6 looks like 9,
8 looks like 8,
9 looks like 6 and
0 looks like 0.
The others digits (1, 2, 3, 4, 5 and 7 ) look like nothing...
I wonder how many number could be rotatable between 0 and 1000! The answer is definitively 11: 0, 8, 69, 8... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.