instruction stringlengths 34 53.1k |
|---|
I have string \$s\$ of length \$n\$ and some constant integer \$k\$ which is at most \$n\$. Give the fastest algorithm to sample a random string with Levenshtein distance \$k\$ from \$s\$ uniformly.
Your algorithm should output any of the strings with edit distance exactly \$k \leq n\$ from the input string \$s\$ with ... |
There are 3 (commonly used) trigonometric functions sin cos and tan each of these functions has an inverse function
You goal is to write 3 programs or functions (one for each inverse trigonometric function asin acos atan) that take a (real) number a input and return the result of the corresponding inverse trigonometric... |
Inspired by this tweet where a user stated the following:
it's insane how much code would be cleaned up if JS got pipes and pattern matching
i often do this since it's the best way to make use of TS inference and pattern matching would make it less hacky
const result = (() => {
if (scenario1) {
return {
t... |
Related
You are a manager at a large number factory. You want to show everyone your business is doing well, by showing randomly chosen samples. Unfortunately, your business is not doing that well. But luckily, you have a bit of ingenuity...
Write a program or function that when given an array of unique, positive numbe... |
The fast growing hierarchy is a way of categorizing how fast functions are growing,
defined the following way (for finite indices):
\$ f_0(n)=n+1 \$
\$ f_k(n)=f_{k-1}^n(n)\$ with \$f^n\$ meaning repeated application of the function f
Examples
f0(5) = 6
f1(3) = f0(f0(f0(3))) = 3+1+1+1= 6
f2(4) = f1(f1(f1(f1(4)))) = 2*... |
Preamble
We've already proven we're good at adding two numbers, but many solutions only operate on tiny numbers like 2³²-1, honestly we can do a lot better.
The Challenge
Given two unsigned, non-negative integers, add them together and return the output.
Input may be taken in any convenient format (String, Array of byt... |
Given two strings of digits, determine which string, if any, has the earliest digit which is lower than the other string's digit at the same index.
Do note that this differs from alphabetization, as shown in the following examples:
Examples
Given inputs 12345000 and 1233999999, the second string would have the earliest... |
Related.
Given a positive integer \$n\$, output all integers \$b\$ (such that \$1<b<n-1\$) where \$n\$ can be written as the sum of any number of consecutive powers of \$b\$.
Example:
Let's say \$n=39\$.
\$3^1+3^2+3^3\$
\$= 3 + 9 + 27\$
\$= 39\$
This does not work for any other \$b\$, so our output is [3].
Test cases... |
Preamble
A common pain-point when working with rational numbers and decimals is how infrequently one can represent their rational number as a clean, non-repeating decimal. Let's solve this by writing a program to decimalize (not to be confused with decimate) them for us!
The Challenge
Given a fraction, check if it can ... |
Pseudo-Quantum Bogosort
Quantum Bogosort is as follows:
Quantumly randomise the list, such that there is no way of knowing what order the list is in until it is observed. This will divide the universe into O(n!) universes; however, the division has no cost, as it happens constantly anyway.
If the list is not sorted, ... |
There are a lot™ of pokemon. One of the defining characteristics of pokemon is their type, of which every1 pokemon has up to two types, a primary type and an optional secondary type. There are mechanical implications to each type, and so it is very useful to know what type a given pokemon is during battle. But there's ... |
Alternatively, guess who's doing a course on operating systems
Round Robin scheduling is a way to schedule ready processes in an operating system. Each process in the queue is run for a certain amount of time (quantum), interrupted after that time (if not yet finished), and then added back to the ready queue for anothe... |
There is a question to basically find the largest sum in an array, such that no two elements are chosen adjacent to each other. The concept is to recursively calculate the sum, while considering and not considering every element, and skipping an element depending on whether the previous element was selected or not.
I u... |
Description
Given a list of positive integers, write the shortest code to find the number count of the longest consecutive sequence of numbers within the list.
Input
A list of positive integers. You can assume the list is not empty and may contain duplicates.
Output
The length of the longest consecutive sequence of num... |
Given a number \$n\$, we have its sum of divisors, \$\sigma(n)\ = \sum_{d | n} {d}\$, that is, the sum of all numbers which divide \$n\$ (including \$1\$ and \$n\$). For example, \$\sigma(28) = 1 + 2 + 4 + 7 + 14 + 28 = 56\$. This is OEIS A000203.
We can now define the sum of sum of divisors as \$S(n) = \sum_{i=1}^{n}{... |
Too bad! I had such a beautiful equation, but I lost all my =+-*, so there is nothing left but a chain of digits, looking like a number: 7512. But was it 7+5=12 or 7-5=1*2 or 7=5*1+2 or 7=5+1*2? Or are there even more valid possibilities?
Your task: For a given positive integer number, return the number of true equatio... |
The way points are assigned on a dice follows a regular pattern, the center dot is present if and only if the number is odd. To represent the even numbers, pairs of dots on opposite sides of the center are added, which will stay present for all successive numbers.
1:
O
2: 3: 4: 5: 6:
O O O O O O ... |
The question score on Stack Exchange is the total number of upvotes minus the total number of downvotes a question receives. However, the reputation gained/lost for every upvote/downvote is different (eg. 10/-2 on Code Golf).
Given the total reputation earned, the reputation gained by an upvote and the reputation lost ... |
American odds (aka moneyline odds) are numbers like \$+150\$ or \$-400\$ used to express how much a winning bet would pay out. Convert odds to a fair win probability like this:
Positive odds \$+n\$ with \$n \geq 100\$ correspond to $$p=\frac{100}{100+n},$$ producing a probability with \$0 < p \leq 1/2\$.
Negative odds... |
Sokobunny 1
You love buns!
You love them so much, that you chased one down a bunburrow. The burrows are like mazes, and YOU WANT TO CATCH THE FLUFFBALLS!!!! However, the buns are smart! You can't catch the bun by by chasing after it, as you wait out of politeness for the buns.
Taken from the game Paquerette Down the Bu... |
The Challenge
Given a rational number, determine the smallest number which is a positive integer multiple of it. Eg.
Given: 1.25
x1: 1.25
x2: 2.5
x3: 3.75
x4: 5
Thus: Answer is 5
Clarifications
Inputs will be a rational number in the range of (0,100] of which the Decimal Representation has no more than 4 ... |
Related.
Given a number \$n\$, Euler's totient function, \$\varphi(n)\$ is the number of integers up to \$n\$ which are coprime to \$n\$. That is, no number bigger than \$1\$ divides both of them.
For example, \$\varphi(6) = 2\$, because the only relevant numbers are \$1, 5\$. This is OEIS A000010.
We can now define th... |
Since programming is predicted to become natural linguisized by the unstoppable advances in LLM technology, perhaps we can code golf LLMs themselves.
Produce the shortest question that is not an arithmetic problem (we know it sucks at multiplication problems) that produces an obvious falsehood from ChatGPT with screens... |
Input
A binary string \$s\$ of length \$n\$ and a positive integer \$k \leq n\$.
Output
The number of binary strings with Levenshtein distance exactly \$k\$ from the string \$s\$.
Example outputs
Each example gives the largest possible output for the given \$(n, k)\$ pair.
k=1, s=1010, output=14
k=2, s=1010, outupt=55... |
What is the shortest regular expression (REGEX) you can create for file extensions for all of the following image file formats (photographs, paintings, sketches, and drawings)?
.ACAD
.AFD
.AFP
.AOM
.AOMA
.APNG
.ASCII
.AVIF
.AVIFAV
.BMP
.BPG
.CABAC
.CDEC
.CDR
.CDRAW
.CGM
.CHEVC
.CIEC
.CIPA
.CMYK
.COLLADA
.CRT
.CWC
.DEEP... |
Playing the game of memory against a machine is highly unfair, because they play almost as good as small children. So let's make the machine play alone, but in a fair way:
Input: 1...26 pairs of lowercase letters in random order like zz or gttg or abcdefghiabcdefghi. You can trust each letter appears exactly twice and... |
Write a program or function that outputs all positive integers with distinct decimal digits (OEIS: A010784)
Examples:
1 2 3 4 5 6 7 8 9 10 12 13 ...
96 97 98 102 103 ...
123456789 123456798 ... 9876543120 9876543201 9876543210
Rules
You can output the list of numbers in any convenient format (string with separators, ... |
Objective
You're on a nonempty list of integers that wraps around. You start at the leftmost entry of the list, and keep jumping to the right to the amount of the integer entry you're at.
Eventually, you'll end up in a cycle. The objective is to output the length of this cycle.
I/O format
Provided that the inputted lis... |
Goal: create a self-referencing tuple satisfying x == (x,) in any version of Python. Standard libraries, matplotlib, numpy, pandas only.
Answers meeting this extra condition are prioritised (which may be impossible): this tuple should also be insertable into a dict or set.
If the extra condition is impossible, apart fr... |
OEIS A090461 details the ‘numbers k for which there exists a permutation of the numbers 1 to k such that the sum of adjacent numbers is a square’. This has also been the subject of Matt Parker’s Numberphile and Alex Bellos’ Monday puzzle.
This code-golf challenge is related to the square sum problem above and asks you ... |
Need to write a JS function compare(a,b) for numbers which return
1 when a > b, 0 when a == b, -1 when a < b.
Also following properties should hold:
compare(NaN, NaN) = 0
NaN is bigger than any other number, so compare(NaN, any) = 1 and compare(any, NaN) = -1.
compare(-0.0, 0.0) = -1 and compare(0.0, -0.0) = 1.
Other ... |
Inspired by this (off topic) post
Given an array of numbers, find the largest sum over a subarray not containing two adjacent elements
[1,2,3,4] -> 6 // [_,2,_,4]
[1,2,3,4,5] -> 9 // [1,_,3,_,5]
[2,2,1,1,2,1,1,2] -> 7 // [2,_,1,_,2,_,_,2]
[3,1,4,1,5,9,2] -> 16 // [3,_,4,_,_,9,_]
[9,8,7,9,9,8] ... |
Subleq is a Turing-complete esolang with only one instruction, SUBLEQ. This instruction takes in three parameters, A, B, and C, all of which are memory addresses. The instruction subtracts the value in memory address A from that in memory address B, storing it in address B. If the value at B is now less than or equal t... |
Given an array of letters in the range 'a' to 'o', compute how to construct the array by successively inserting the letters in alphabetical order. You will always start the insertion with a base array of all the 'o's that are in the array to be reconstructed.
Examples
Let the input array be:
['o', 'b', 'o', 'b', 'a']
... |
Background
Numeric Mahjong is a hypothetical variation of Japanese Mahjong, played with nonnegative integers instead of Mahjong tiles. Given a list of nonnegative integers, it is a winning hand if it satisfies the following:
its length is \$3n+2\$ for some nonnegative integer \$n\$, and
it can be partitioned into \$n\... |
Just because the reverse and palindrome were not too challenging individually :)
Write a program (full program or function) that satisfies the following: given a string input,
the program as-is outputs the input string unchanged.
the program reversed outputs the input string reversed.
the program palindromized outputs... |
Some built-in functions in PHP return mixed types, like file_get_contents that returns both string or false. Union structs in C can be used to simulate this, but is there a way to make it polyglot, that is, can be run in both PHP and C without (major) modification? Macros is often one way.
$result === false
can be rep... |
The task is to calculate the average "funniness" of a given number given the following scoring system:
1 point for each "420" in it
2 points for each "69" in it
3 points if its a palindrome (doesn't count if it's just a single digit)
4 points if it has (not for each) "800813"
5 points for ending in "420"
6 points for ... |
In this challenge, you'll take an answer as input, and print the answer before it. If the answer passed as input is the first answer, print your own submission's source. You'll be passed any answer in the chain up to and including your own answer, but none after it in the chain.
For example, if the first submission is ... |
Write a program that outputs its source code in reverse when run, and outputs its source forwards when I reverse the source. If your program is "abcd", when run with no arguments it should output "dcba", and when I run the program "dcba" it should output "abcd."
This is a quine challenge, so both your forwards and reve... |
Input: an array of length \$n\$ containing integers in the range \$0\$ to \$2n\$.
For each integer \$x\$ in the array, compute the number of integers that occur before \$x\$ that are no larger than \$x\$.
As an example, if the array is
[3, 0, 1, 4, 3, 6]
the output should be equivalent to:
3: 0
0: 0
1: 1
4: 3
3: 3
6: ... |
Barbrack
Your task is to write a program or function that takes a non-negative integer (in decimal or any other convenient base for your language), and output a number in the numbering system Barbrack.
What's that?
Barbrack is a numbering system I made up that can represent non-negative integers. Zero is represented wi... |
Background
From Wikipedia: An Egyptian fraction is the sum of distinct unit fractions. That is, each fraction in the expression has a numerator equal to 1 and a denominator that is a positive integer, and all the denominators differ from each other. The value of an expression of this type is a positive rational number ... |
The autokey cipher is closely related to the Vigenère cipher (both were invented by Blaise de Vigenère). Decryption involves the encrypted message and the key. For simplicity, let us assume all characters in the message and key are lowercase letters (no spaces, numbers or symbols etc.).
How to decrypt the cipher
Conve... |
Your challenge is to print any 100 consecutive digits of π. You must give the index at which that subsequence appears. The 3 is not included.
For example, you could print any of the following:
1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 (index 0)
821480865132823... |
Your task is to write a program \$p\$ which outputs a string \$s\$ with the same length as \$p\$, where \$s \neq p\$.
If I remove the \$n\$th byte from your program to get program \$q\$, then either \$q\$ outputs \$s\$ with the \$n\$th byte removed, or it does something else.
Your score is the number of ways a single b... |
The aim of this post is to gather all the tips that can often be applied to radiation-hardening challenges.
Please only post answers which can apply to a large number of languages, and one tip per answer.
|
In this challenge, we define a range similarly to Python's range function: A list of positive integers with equal differences between them. For example, [1, 2, 3] is a range from 1 to 3 with a skip count of 1, because there is a difference of 1 between each item, and [4, 7, 10, 13] is a range from 4 to 13 with a skip c... |
In this challenge, we define the complement of a list of positive integers as all positive integers not included in that list. For example, the complement of the even numbers [2, 4, 6, 8...] is the odd numbers [1, 3, 5, 7...]. Your challenge is to, given a monotonically increasing, infinite list of positive integers, ... |
Background
The look-and-say sequence begins with \$1\$, each following term is generated by looking at the previous and reading each group of the same digit (eg. \$111\$ is three ones, so \$111 \rightarrow 31\$). The first few terms are
$$ 1, 11, 21, 1211, 111221, 312211, \dots $$
Conway's cosmological theorem says tha... |
The JavaScript compressor RegPack uses a very simple string compression algorithm. Given a piece of code, it will make a list of characters that aren't used in that code and use them to delimit repeated strings that are inserted back into the string.
To show how strings are compressed, it's necessary to show how the de... |
This challenge is to list out all possible words which are built from a pattern of syllables. Words are composed by joining syllables together. Syllables are composed of a number of vowels with some number of consonants optionally to the left and/or right. Your code should take in:
a list of consonants
a list of vowel... |
In this challenge you will take a non-empty (finite) list of (possibly infinite) lists of positive integers, and your task is to output the longest one. An infinite list is longer than a finite list of any length, and any two infinite lists are equally long.
You're guaranteed that there won't be any ties for longest be... |
Transposition is an operation on 2-dimensional arrays that flips every element across the main diagonal:
[[1,2,3], [[1,4],
[4,5,6]] -> [2,5],
[3,6]]
If we call the above array m, then the 2 is the second item of the first row of m, or m[0][1]. The 2 can be thought of as having a coordinate of [0, 1]... |
Given a number \$n\$, you are to compute the sequence of positive numbers where for each number \$a\$, the \$n\$-times multiple \$n\cdot a\$ is missing.
Example
We always start with the sequence of all positive numbers: $$1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, \dots$$
For \$n=2\$, going left-to-right, we first encounter ... |
An even distribution number is a number such that if you select any of it's digits at random the probability of it being any particular value (e.g. 0 or 6) is the same, \$\frac1{10}\$. A precise definition is given later on.
Here are a few examples:
\$\frac{137174210}{1111111111} =0.\overline{1234567890}\$ is an even... |
For each character in your program, the program with that character removed must produce a number smaller than the program with the next character removed. Your base program isn't required to do anything, and may be invalid.
An example submission could be abcd, where bcd outputs 1, acd outputs 4, abd outputs 5, and abc... |
Objective
Given a nonnegative integer, calculate its NDos-size as defined below, and output it.
NDos' numeral system
The concept of NDos-size comes from the numeral system I made. It represents every nonnegative integer by a nested list, as follows:
With the binary expansion of given nonnegative integer, each entry of... |
Here is a challenge:
What is the shortest possible compiled program? Writing one line programs are fun, but they often lean on language libraries that get pulled into the final bits. How lean can you get the 'scaffolding' that supports and hooks into the compiled instructions? This seems like an interesting question be... |
A problem I sometimes encounter is that when writing comments using LaTeX, the comment is too long. Today you will solve this, by writing code which, given a LaTeX math expression, will produce the shortest equivalent expression.
To define equivalent expressions, we will need to specify a (simplified) parser for LaTeX:... |
Input
The code should take an integer \$n\$ between 1 and 1000.
Output
The code should output positive integers with \$n\$ bits. Accompanying each integer should be its full factorization. Each integer should be a uniformly random \$n\$ bit number.
Score
The score for your code will be the number of integers it outputs... |
Challenge:
Given a positive number \$n\$, convert it to binary, and output a sequence where all 1s form a top-left to bottom-right diagonal line, including a leading column of 1s. To give two examples:
\$n=1\$ will result in [1,3,5,9,17,33,65,129,...], with binary values:
1
11
101
1001
10001
100001
1000001
10000001
↓ ... |
The divisors of a natural number form a poset under the relation of "a divides b?", \$a | b\$. This challenge is to produce the number, \$C\$, of non-empty chains of such posets for natural numbers, \$N\$.
This is A253249 in the Online Encyclopedia of Integer Sequences.
That may sound complicated, but it's not really, ... |
Not sure if it's correct to ask such a question on this site, but let's try.
Let a(n) be a sequence of positive integer such that a(1) = 1. To reproduce the sequence a(n) through itself, use the following rule: if binary 1xyz is a term then so are 110xyz and 1XYZ where the last one is the same as 1xyz with rewrite 1 ->... |
The Euclidean GCD Algorithm is an algorithm that efficiently computes the GCD of two positive integers, by repeatedly subtracting the smaller number from the larger number until they become equal. It can be visualised as such:
We start with a MxN grid, where M and N are the numbers. In this example I'll use M=12, N=5:
... |
In crossword terminology, the grid is the region into which the crossword answers are inserted, consisting of white and black squares. The crossword answers, called entries, are inserted into contiguous sequences of white squares in a row or column, separated by black squares.
For straight (American) crosswords, the g... |
This was originally a pure mathematics question, but I think I've got the best chance for an answer here.
The Challenge
For concreteness, consider Peano Arithmetic (PA). For some language L of your choosing, construct a computer program of length at most N bits in L such that:
If it terminates, it outputs a number th... |
You work at a beach. In the afternoon, the sun gets quite hot and beachgoers want to be shaded. So you put out umbrellas. When you put out umbrellas you want to shade the entire beach, with as few umbrellas as possible.
Umbrellas come in many sizes. However, larger umbrellas are susceptible to being pulled away by the ... |
Emmet is a text-editor and IDE plugin for writing HTML code using much fewer keypresses. You might think of it like a code-golfing HTML preprocessor. Its syntax is based on CSS selectors.
Your challenge is to code-golf an implementation of Emmet. Given some Emmet code, output the resulting HTML.
Note that for the purpo... |
This originally came from Give the best Chaitin incompleteness bound, but I realized that there was a fragment of this problem which still potentially gives a good coding challenge.
First Order Logic With Equality
First, I will need to fix an encoding of first order formulas ('For all x there exists y such that ...'). ... |
A fixed-point combinator is a higher order function \$\mathrm{fix}\$ that returns the fixed point of its argument function. If the function \$f\$ has one or more fixed points, then $$\mathrm{fix} f=f(\mathrm{fix} f).$$
The combinator \$Y\$ has such properties. Encoded in lambda calculus: $$Y=\lambda f.(\lambda x.f(x x)... |
The Universal Crossword has a set of guidelines for crossword puzzle submissions.
In this challenge we are going to be concerned with their rules for hidden word themes. A hidden word clue consists of a clue and a word. It can either be a
"word break" or a "bookend".
For a word break the word must not appear as a cont... |
Befunge is a 2-dimensional programming language, with an instruction pointer (IP).
In Befunge-98, the ; character tells the IP to skip characters up until the next ; (Let us call it skipping mode when the IP is skipping characters). Here is an example:
"This part is read into the stack" ; this part is not ; @
I would ... |
In the video game Minecraft, the player can obtain experience points (XP) from various activities. In the game, these are provided as XP "orbs" of various sizes, each of which give the player various amounts of XP. The possible orbs are shown in the image below, along with the smallest and largest amount of XP that orb... |
Task
Here is an interesting math problem:
Let's say that there are \$n\$ indistinguishable unlabeled objects in a bin. For every "round", pull \$k\$ objects randomly out of the bin with equal probability, and apply a label on each object (Nothing happens to objects already having a label). Then put these \$k\$ objects... |
I wrote a code that separates the numbers from 1 to 9999 by comma
void p(n){printf("%d,",n);if(n<9999){p(n+1);}}main(){p(1);}
Is there a way to make this short code without using a repeat statement?
|
In this challenge, you will play the iterated Prisoner's Dilemma, but with a twist: There's also an adversary trying to mess you up!
The Prisoner's dilemma is a scenario in game theory where there are two players, who we'll call the "prisoners", each with two options: cooperate, or defect. Each prisoner does better for... |
The Brits aren't exactly known for being good at memorizing stuff. That's why scientists need newspaper articles to find those who are, and that's why it shouldn't be a surprise that they forget more than a 1000 things per year, including phone numbers, addresses, birthdays and more. Now, it is your duty to help the Br... |
Party time! All of your guests are sitting around a round table, but they have very particular seating requirements. Let's write a program to organize them automatically!
Guests are represented by letters: Female guests are uppercase, males are lowercase. Couples have the same letter, one lower and one upper, like gG, ... |
We already have a challenge for polynomial interpolation: given a list of points, output the coefficients of the polynomial that passes through them.
Hermite interpolation is a generalization of polynomial interpolation. Instead of just specifying the points that the polynomial passes through, we also specify the highe... |
Introduction
Finding the closest power to a number is a common enough problem. But what if you need both the next-highest and next-lowest power? In this challenge you must find the closest powers to a given number - the 'power sandwich' if you will, where the given number is the filling and the powers are the bread. Mm... |
Introduction
This challenge was inspired by a seemingly simple task requested at work that couldn't easily be done in Microsoft Teams. At least not from what we could find!
Task
Your task, if you choose to accept it, is to output the last week day of any month in any year.
Input
You can input the desired month/year in ... |
I was seen multiple shortest "Hello World!" program, but this is the longest program.
The Rules
Each submission must be a full program.
This must be non-interpreted language (for example, JavaScript, Python, HTML, etc.)
Target OS must be Windows, Mac, Linux or MS-DOS.
The challenge
Writing a longest Hello World prog... |
We all know run-length decoding: A list of character-length pairs expands to a string of that many characters, so A1B4C2 expands to ABBBBCC. But what if we stretch this concept to 2 dimensions?
Instead of character-length pairs, in this challenge you will be given character-length-direction triples. For example, using ... |
What is the shortest selector (by character count) to select ALL html elements on a web page, without using asterisk (*)? Some examples are the following:
a,:not(a) /*9 chars*/
:nth-child(n) /*12 chars*/
:link,:not(:link) /*17 chars*/
|
Introduction
This question is inspired by this great question.
Challenge
Given a number \$N>0\$, output the largest integer \$a^b\$ that is smaller or equal to \$N\$, and the smallest integer \$c^d\$ that is greater or equal to \$N\$, where \$b>1\$ and \$d>1\$.
Output should be a list of two integers, the first being s... |
We will think of a partition as a sequence of non-increasing integers.
For a given partition into \$n_1, n_2, \dots, n_k\$ with \$n_1 \geq n_2 \dots n_{k-1} \geq n_k = n\$ we write it out with \$n_i\$ dots on row \$i\$. So for \$6, 1, 1\$ we would write six dots on the first row, one on the second and one on the third... |
Your challenge, should you choose to accept it, is to write a program in a language of your choice that, when given a string (limited to printable ASCII) as input, outputs a new program in the same language that outputs that string without using any characters from that string in the code.
But this task is impossible a... |
Task
Your boss is on another crusade for 'efficiency.' He wants to encourage the use of numbers with fewer syllables, so that they're easier to discuss in meetings. If you want to take some time off work, you're boss would prefer you take 9 days instead of 7. You're boss would prefer a credit card expense of $99,502 ov... |
Given a base \$k\$ as well as two indices (also passed in base \$k\$, call them \$s\$ and \$e\$) return a list containing a frequency count of all base-\$k\$ digits occurring between \$s\$ and \$e\$ inclusive. For example, upon input \$k = 10, s = 1, e = 10\$, we would return the list \$[0: 1, 1: 2, 2: 1, 3: 1, 4:1, 5:... |
Imagine there are \$n\$ people \$\{a_1, a_2, \ldots, a_n\}\$ who enter a room in order and sit down in \$n\$ seats, arranged in a row. Each of these people belong to some gang, indicated by an integer \$\{1, 2, \ldots, k\}\$. These gangs hate the members of the other gangs, so they want to sit as far away from those pe... |
The well-known Urinal Protocol states that each person that takes a urinal will take the one furthest from any other taken urinal. But this fails to account for short urinals; in many cases, a person would prioritize taking a taller urinal in addition to distance.
In the real world, you might struggle to find a restroo... |
Given input \$x \in \left\{0,3,6,...,90\right\}\$, output \$\sin\left(x°\right)\$ using integer and \$+ - \times \div ( ) \sqrt{\cdot}\$(square root), e.g. \$\sin(45°)=\sqrt{1\div 2}\$.
Flexible output format. You needn't do any simplification to output, aka. it's fine to output \$\sin(0°)=\sqrt{42}-\sqrt{6\sqrt{-9+58}... |
My doubles pickleball group often has five people. Four are playing and one is awaiting the next game. We can represent the state of the game with a string of five characters like abCde. This indicates that a and b are playing against c and d with c serving. We want to write a routine that gives the possible positions ... |
Given a list of positive integers, partition the list into two sublists such that the absolute value of the difference of the sums over the two sublists is minimal.
The output of the program should be the (non-negative) difference of these sums.
Examples:
[1,2,3] -> 0 # [1,2], [3]
[2,3,5,7,11] -> 0 # [2,5,7], ... |
You are given an array A of non-negative integers. You can pick any non-empty subset, S from the array A. The score of a subset S is the sum of the elements in S raised to the power of K, i.e. for a subset S={s1,s2,…,sm}, the score of S is (s1+s2+…,sm)K. Output the sum of scores over all possible non-empty subsets of A... |
Your task is to write 2 functions/programs. They may share code.
The first function must, given a string and a character, output a new string that does not contain that character.
The second function must, given the string from the previous function and the excluded character, reconstruct the original string.
All input... |
I encountered some silly code from a game and I figured this would actually turn into a fun golfing problem, so:
Given any ASCII string in the limited char range specified below.
Append as few characters as possible such that, given:
i = 1
sum = 0
for char in string
sum += char.intval * i++
end for
sum % 1000 == 0
W... |
Code Golf Challenge
Given a string of 10 characters:
'abcdefghij'
I want to format it in this pattern and print it in the console in a minimum number of characters:
(abc) def-ghij
My solution:
print(f"({s[0:3]}) {s[3:6]}-{s[6::]}")
|
One element of the list aa, ab, ba, bb, c has been removed, and the remainder shuffled and joined with no separator. Find the missing element.
For example, if the input was aaabbac, this is made by concatenating aa ab ba c, so the output would be bb.
Rules
Standard I/O rules apply.
You must take input as a string (or ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.