instruction
stringlengths
34
53.1k
Given a sequence \$S\$ with length \$n\$ of exactly one each of whole numbers from \$1\$ to \$n\$, your task is to return a number \$\sigma\$ indicating how shuffled it is. Definition of shuffledness Humans perceive shuffling randomness locally [Citation Needed], so the shuffledness of a sequence is based on the abilit...
You are given an array \$A\$, which may contain duplicate elements. In each swap, you may swap the value of any two indices \$i, j\$ (i.e. switch the values of \$A_i\$ and \$A_j\$). What is the least amount of swaps needed to sort the array, and what are the corresponding swapped indices? Scoring This is code-golf, so ...
Your task is to make a program which interprets the language it is run in, but also works in many languages. Let's say you make a Brainfuck-Underload self-interpreglot, as it will be called. Run in Brainfuck, this program should be a Brainfuck interpreter; run in Underload, it should be a Underload interpreter. Your pr...
Introduction Your job is to write a function or program that detects if a number a is less than a number b. But... You are not allowed to use built-in alternatives for equals, less than, greater than, less than or equal to, greater than or equal to, or not equal to operators. (Writing your own implementation is allowed...
The Levenshtein distance between two strings is the minimum number of single character insertions, deletions, or substitutions to convert one string into the other one. The challenge is to compute the average Levenshtein distance between two independent and uniformly random chosen binary strings of length n each. Your...
Output a random triple \$(x,y,z)\$ of real numbers such that \$x+y+z=\frac{3}{2}\$ Each of \$x,y,z\$, taken alone, is uniformly distributed from \$0\$ to \$1\$. Please explain in your answer what distribution your code produces and why it meets these conditions. In particular, please include a demonstration that with...
Significantly harder version of Spanning tree of a rectangular grid. Background A spanning tree (Wikipedia) of an undirected graph is a subgraph that is a tree which includes all of the vertices of the original graph. The following is an example of a spanning tree of a 4-by-4 grid graph. Task Given two positive intege...
Introduction In a list of strings, there is a certain length you can shorten strings to before they become indistinguishable. This is a pretty bad explanation, so here is an example. ['hello', 'help', 'helmet'] ['hell', 'help', 'helme'] ['hell', 'help', 'helm'] ['hel', 'hel', 'hel'] <- At this point the strings are i...
In golf, a knowledgable caddie helps an already good golfer to be even better. In this challenge, you build a "caddie" to help you code golf. In particular, your caddie will compress golfed code in such a way that another program can uncompress and then run the code. A good caddie will compress golfed code to be much s...
Given a non-empty list/vector of positive integers, write a function to check the following conditions in as few bytes as possible. Take the first integer (the key, or k1) and check that the next k1 values have no duplicate values, excluding instances of k1. Take the last integer (the second key, or k2) and check tha...
Given a sequence of base-10 digits, output the longest list of integers that contains all the digits exactly once, in the order in which they appeared in the input, without repeating any integers. Examples Input: 12345 Output: [1, 2, 3, 4, 5] Input: 12123 Output: [1, 2, 12, 3] Input: 10010 Output: [100, 1, 0] Input:...
In this task you are expected to provide a list output given an input tq program. The tq programs will not contain whitespace inside them. What is tq, in the first place? tq is a lazy-evaluated language that is designed with the idea that array items should be accessable during the definition of them. In tq, there is n...
Introduction Nine-Ball is a popular pool game played casually and as a competitive sport. There is one of each numbered ball, with the numbers 1 to 9. The game starts with all 9 of the balls in a diamond shaped rack, like so: 1 2 3 4 9 6 5 7 8 The 1 ball is always at the front of the diamond, and the 9 ball is a...
Input The input will be a year between 1583 and 2239. We just want to know when Hannukah was or will be in that year. This is information used by millions of people every year and put in calendars across the world. What could be easier? Output The Gregorian date of the first evening of Hannukah that year. That is the ...
Write the smallest program that maps strings injectively to outputs and maps itself to 2020. To be clear, your program \$p\$ must have the following properties: every possible input string \$s\$ has a well-defined output \$p(s)\$, for every pair of strings \$s\$ and \$t\$ with \$s\neq t\$, it holds that \$p(s)\neq p(t...
Related: Is this quadrilateral cyclic? Background A tangential quadrilateral is a quadrilateral which has an incircle: Examples include any square, rhombus, or a kite-like shape. Rectangles or parallelograms in general are not tangential. Task Given the four vertices of a quadrilateral (as Cartesian coordinates), dete...
I am trying to find the shortest code in python 3, to solve this problem: You are driving a little too fast, and a police officer stops you. Write code to take two integer inputs, first one corresponds to speed, seconds one is either 1 or 0, corresponding to True and False respectively to indicate whether it is birthd...
Create a program that generates a drum fill. Your program will output a pattern of L (left hand hits), 'R' (right hand hits), and K for kick drum hits. Rules The pattern must never have more than 2 of the same hits consecutively. The pattern must be loopable, so it mustn't have more than 2 of the same hits when it lo...
Do randomly generated drum loops sound good? A drum loop is a \$5\times 32\$ matrix \$A\$ of \$1\$s and \$0\$s such that \$A_{1,1}=A_{1,17}=A_{2,9}=A_{2,25}=1\$, for each \$i\$, the \$i\$th row has exactly \$f(i)\$ different \$1\$s, where \$ f(1)=3, f(2)=2, f(3)=6, f(4)=8, f(5)=5\$, for each \$j\equiv 1\bmod 4\$, the ...
Just over seven years ago, everybody suddenly stopped talking about the Maya people. It is time to rectify that! For clarification, I am talking about the Mesoamerican Long Count Calendar. Your program will have as input a date in the Gregorian Calendar, and as output the corresponding date from the aforementioned Meso...
Question Write a program to accept one string on the console only and print back its letters arranged in alphabetical order. The string must only have the following characters: 0123456789abcdefghijklmnopqrstuvwxyz Rules The ascending alphabetical order is defined in the given string. All repeated characters must be ...
Posted from sandbox The Intro What is an ACU? This challenge is based on the concept of money and since this is an international community, we all use different currencies, so in keeping with our spirit of inclusiveness, I have invented a new currency called Arbitrary Currency Units (ACUs) specifically for this challen...
In LLAMA, you want to dump cards from your hand as quickly as you can, but you might not be able to play what you want. Each player starts a round with six cards in hand; the deck consists of llama cards and cards numbered 1-6, with eight copies of each. On a turn, the active player can play a card or draw a card. To p...
Challenge Write a program or function that converts a 32 bit binary number to its quad-dotted decimal notation (often used for representing IPv4) Quad-dotted decimal A quad-dotted decimal is formed like so: Split the binary representation into its 4 individual bytes Convert each byte into denary place "." between each...
Given two nonempty arrays of natural numbers \$a\$ and \$b\$, return the shortest nonempty array of pairs of natural numbers \$q\$ such that the sequence of first elements of \$q\$ consists of a whole number of repeated copies of \$a\$, and the sequence of second elements of \$q\$ consists of a whole number of repeated...
Challenge Create 2 programs A and B The output of program A is exactly program B The output of program B is exactly program A Neither program should depend on inputs to yield the correct output A and B are not identical programs A and B are of different programming languages Neither program may be equivalent to i...
Suppose we have two different types of coin which are worth relatively prime positive integer amounts. In this case, it is possible to make change for all but finitely many quantities. Your job is to find the largest amount that cannot be made with these two types of coin. Task Input: A pair of relatively prime integer...
If \$f(x) = x + \sum_{i>1} a_ix^i\$ and \$g(x)=x+\sum_{i>1}b_ix^i\$ then there is a composite power series \$f(g(x))\$ also of this form. Given a power series \$f\$ the goal is to find a compositional inverse \$f^{-1}\$ so that \$f(f^{-1}(x))=x\$. One approach to this is recursive: start with a guess \$g_1(x)=x\$ for t...
Challenge Write a complete program that prints out the time it took to execute a certain part of itself. That part must include a process whose total number of operations (and therefore execution time) is dependent on a user-substituted numeric value - this can be denoted in any way in your code (uppercase N for exampl...
Background The special linear group \$ SL_2(\mathbb{Z}) \$ is a multiplicative group of \$ 2 \times 2 \$ matrices whose elements are integers and determinant is 1. It is known that every member of \$ SL_2(\mathbb{Z}) \$ is a product of some sequence of the following two matrices \$ S \$ and \$ T \$ (reference pdf): $$ ...
This is a version of this question which should not have such a straightforward solution and so should be more of an interesting coding challenge. It seems, for example, very likely there is no easy to find closed form solution, even though we have only increased the bound by one from the previous version. Having said ...
Inspired by this blog post. Write a program that outputs 99 distinct programs (in the same language) that output the string I love you. How the programs are separated from one another in the output will be defined by you. However, Each byte of output can only belong to at most 1 of the 99 programs. Constraints for Out...
Special thanks to Bubbler and AdmBorkBork for supplying feedback about this challenge Keta (Keyboard tacit — clever naming, I know!) is a golfing language I’ve been working on recently. One of it’s features is it’s most probably unique bracket autocompletion system, which will hopefully allow for shorter programs. The...
Background Perfect shuffle algorithms like Fisher-Yates shuffle don't produce great results when it comes to music playlist shuffling, because it often produces clusters of songs from the same album. In an attempt to solve this problem, Spotify introduced an interesting shuffle algorithm in 2014. At the end of the arti...
You are given 4 positive integers: volume of the first container (v1), volume of the second container (v2), volume of the liquid in the first container (l1), and volume of the liquid in the second container (l2). Your task is to move some of the liquid from container 1 to container 2, making the amount of empty space i...
In musical notation, groups of notes shorter than one beat are joined together by a line at the bottom called a beam. Here are a few bars of music with the beams highlighted: (Taken from Second Suite in F by Gustav Holst; you can hear how these notes sound at 0:13 in this video.) You may notice that beam #6 is above t...
Challenge Write a program or function that takes a number \$n\$ and returns the smallest \$k\$ such that concatenation \$n'k\$ is a square. This sequence is described by A071176 on the OEIS. I/O Examples input --> output 1 --> 6 (4^2) 10 --> 0 (10^2) 35 --> 344 (188^2) 164 --> 836 (406^2) 284 --> 2596 (168...
Inputs: The program or function should take 2 vector-like (e.g. a list of numbers) O and V of the same number of dimensions, and a number T (all floating-point numbers or similar) Constraints: T >= 0 All elements of Vector O will be in the range [0,1) Output: The program or function should output the N dimensional c...
In this fastest-code challenge, you are provided with a set of \$n\$ identical blocks and need to determine how many unique buildings can be constructed with them. Buildings must satisfy the following rules: No overhangs - each block must either be on the ground or supported by one or more blocks directly underneath i...
Challenge: Input: a string, consisting of only printable ASCII characters Output: a truthy/falsey value whether its characters are in alphabetical order (based on their UTF-8 unicode values), from any starting point inside the string including wrap-around by going left-to-right For example: xyzabc would give a truthy r...
Introduction The telephone numbers or involution numbers are a sequence of integers that count the ways \$n\$ telephone lines can be connected to each other, where each line can be connected to at most one other line. These were first studied by Heinrich August Rothe in 1800, when he gave a recurrence equation where th...
The Challenge Write two programs P and Q such that: P and Q are written in the same language The output of P is Q The output of Q is P P and Q are both non-empty Simple enough. Surely that's been done here before. Where this gets interesting is the scoring. Scoring P and Q are selfish, they don't want to sheir their...
It's a normal truth machine but instead of taking input, it uses the first character of the program. Thus, internal. The 0 and 1 are plain characters, i.e. ASCII code 0x30 and 0x31 respectively. Example: 0abcd prints 0 and halts, and 1abcd prints 1 infinitely. Then your submission is abcd, whose score is 4 bytes. The 0...
In math a magic square is an N×N grid of numbers from 1 to N2 such that every row, column, and diagonal sums to the same total. For example here's a 3×3 magic square: In this challenge we'll extend the idea to magic code squares where, instead of numbers, each grid cell is any non-newline character. They can be be rep...
The challenge - given a numeric list L and an integer N as inputs, write a function that: finds the bucket sizes for L such that it is split into N whole buckets of equal or near-equal size, and returns for each element in L the minimum of that element's bucket. Example - L=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] N=...
The McGill Billboard Project annotates various audio features of songs from a random sample of the Billboard charts. I scraped this data to produce the following file of chord progressions: chords.txt Write the shortest code that outputs the above file (or its contents). Edit: Here's a quick description of the notation...
The challenge is to implement a program or function (subsequently referred to as "program") that takes a nonnegative integer \$n\$ as input and returns \$n\over\sqrt{2}\$ (the input divided by the square root of two) as output, rounded to a nonnegative integer. You may take your input and output in any reasonable forma...
Creating a golfing language can be hard. Let's help budding golfing language creators out and provide some helpful tips on how to create one. I'm looking for tips on: The design process Implementation Community engagement One tip per answer would be appreciated, and tips like "don't create a new language, use an exis...
Background One of the commonly meme'd aspects of javascript is its incredibly loose type coercion that allows for +!![]+[+[]] == '10' this technique can also be used to create letters as seen in the following example: [[][[]]+[]][+[]][-~[]] == 'n' [undefined+[]][+[]][-~[]] // [][[]] -> undefined ['undefined'][+[]][-~[]...
Something unusual: a code golf question with a purpose. I occasionally find myself in scenarios resembling the following: Suppose you have two computers, A and B. Both of them have a fresh copy of Windows 10 installed. It comes with all the usual stuff, like notepad and paint and a browser, but no extras, like a Linu...
Super permutations Input: A string The program should loop through all lengths of the input (decrementing one each time), generate all combinations with replacement of the string, then make permutations out of the generated combinations, and display all of the strings. They can be separated with anything (doesn't need...
Write a program/method that: Becomes a quine when the input matches the source code; Doesn't halt otherwise. This is code-golf, so shortest solution wins. Avoid any standard loopholes.
A "simple circular" word is a word whose chords do not intersect. The chords of a word may be seen by laying out the alphabet in a circle, and then connecting the word's consecutive letters. Examples of Simple Circular Words ROLE LAKE BALMY Failing Example A word fails to be simple circular if any of its chords in...
This challenge is about the number of orderings which contain at most \$n\$ classes and at most \$k\$ of the \$k^{\text{th}}\$ class. One way to represent such an ordering is as a sequence of positive integers with these three restrictions: A number may only appear after all lower numbers have appeared All numbers whi...
Inspired by this question on the puzzling stack exchange. Rules Given 5 stacks of 5 cards with numbers from 1 to 7, output the moves needed to empty all stacks. A move is defined as the index of a column to pull the card off of, and a move is only valid if: The stack is non-empty The value of the card at the top of ...
Background We define the prime-counting function, \$\pi(x)\$, as the number of prime numbers less than or equal to \$x\$. You can read about it here. For example, \$\pi(2) = 1\$ and \$\pi(6) = 3\$. It can be shown, using dark magic, that \$ \lim_{x \to \infty} \frac{\pi(x)}{x/\log x} = 1 \$ which means we can approxima...
The 3Blue1Brown Youtube channel released a video a year ago called "Why do colliding blocks compute pi?" which describes a model where a block A of mass \$a\$ slides into a block B of mass \$b\$, which then pushes block B into a wall, causing it to bounce off the wall and then collide again with block A. The miracle of...
Write a program using the fewest bytes of source code which given a list of strings finds all elements which are still in the list when any character is deleted. For example, given a list of all English words boats would be output because oats, bats, bots, boas, boat are all English words and thus would be in the list....
Challenge: Your challenge is to write an interpreter for Whitespace. Given a string consisting of spaces, tabs, newlines, and potentially other characters, as well as possible inputs for the Whitespace program itself, output the result of the given Whitespace program. Here is an overview of the Whitespace language and ...
Tonight, 31 January 2020, Brexit will happen and the United Kingdom will leave the European Union, the first time that the number of EU member states will decrease. Your job is to take a date and output the number of EU1 members on that date, according to the following table: | Start | End | Number of memb...
Consider \$3\$ binary strings of length \$n\$ chosen independently and uniformly at random. We are interested in computing the exact expected minimum Hamming distance between any pair. The Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different....
Requirements: Take a single word as input with only lowercase alphabetical characters (a-z) Output a string where every other character is repeated, with the first repeated character being the second character in the string Example: Input: abcde Output: abbcdde Winning Criteria: Standard code golf. Shortest number of...
You're at integer coordinates \$(x,y)\$ facing one of North, South, East, or West. Your goal is to walk home to \$(0,0)\$. At each step, you may do one of: Walk one step in the current facing direction, that is to whichever of \$(x+1,y)\$, \$(x-1,y)\$, \$(x,y-1)\$, or \$(x,y+1)\$ you're facing. Rotate 90 degrees left,...
Generator functions This gives the context for why this challenge came to life. Feel free to ignore. Generator functions are a nice way of encoding the solution to a problem of combinatorics. You just write some polynomials, multiply them and then your solution is the coefficient of one of the terms. For example, how m...
Alice and Bob are perfect logicians trapped on an island with a puzzle generator. Although they can instantly solve the Riemann hypothesis and P=NP just by thinking about it, rather than doing anything useful, they amuse themselves by giving each other puzzles. The setup is as follows: a positive integer n is chosen by...
Intro/Background I was looking at a Flybuys card at Coles recently and noticed that if I took something like this: Source, randomly found on the Internet And swapped some words around, I'd get this: After I finished laughing (don't judge my sense of humour please), I said to myself: "I need a program that can gener...
When you look at the last decimal digit of each power of a non-negative integer a repeating pattern forms. For example, 3: 3^1 = 3 3^2 = 9 3^3 = 27 3^4 = 81 3^5 = 243 3^6 = 729 3^7 = 2187 3^8 = 6561 3^9 = 19683 The last digits go 3971 which repeats indefinitely. In fact any number we choose that en...
In this task you will take as input a non-negative integer \$n\$, and output the number of pairs of non-negative integers \$a,b\$ such that both are palindromes*, \$a \leq b\$, and \$a+b = n\$. For example if \$n\$ is \$22\$ then the valid pairs are \$ \begin{array}{c|c} a & b \\ \hline 0 & 22 \\ 11 & 11 \\ \end{arra...
Background SKI combinator calculus, or simply SKI calculus, is a system similar to lambda calculus, except that SKI calculus uses a small set of combinators, namely S, K, and I instead of lambda abstraction. Unlike lambda calculus, beta reduction is possible only when a combinator is given enough arguments to reduce. T...
Definition We say a pair of integers \$(a,b)\$, where \$0<a<b<N\$ and \$N\$ is an integer larger than 4, is an inverse neighbor pair respect to \$N\$ if \$ab\equiv1\text{ }(\text{mod }N)\$ and \$1\le b-a\le\log_2{N}\$. There may be no such pairs respect to some integers \$N\$. To illustrate the definition, consider \$...
Disclaimer: This challenge is inspired by a coding error I once made. Okay, time for a maths lesson. A normal mean average looks like this: Work out the sum of all numbers in a list then divide by the size of the list. But what if we don't know all the numbers at the time we're working out the average? We need a way ...
You have your very heavy cubical box on a flat floor at position (0,0). All you can do with it is roll it in four cardinal directions (east, north, west, south). Your task is to bring it to a target position, such that the side facing up is the same as before your manipulations. Make a program or function which receive...
This challenge takes place on the snub square tiling. Start by choosing any triangle, and color it \$c_1\$. Next, find all tiles which touch this triangle at any vertex, and color them \$c_2\$. Next, find all tiles which share a vertex with any \$c_2\$-colored tile, and color these \$c_3\$. Continue this process ad inf...
The sequence Given an integer \$n>0\$, we define \$a(n)\$ as the lowest positive integer such that there exists exactly \$n\$ positive integers smaller than \$a(n)\$ whose sum of digits is equal to the sum of the digits of \$a(n)\$. Edit: this sequence has since been published as A332046 First terms n | a(n) | sum of...
I started a CodeWars kata in Python, just two days ago, related to code golf. Task: Given two congruent circles a and b of radius r, return the area of their intersection rounded down to the nearest integer, in less than 128 chars. Has to be a one-liner. Version: Python 3.6 External libraries: You may import NumPy as ...
Remove every pair of newline characters, that means every two newline characters appearing together are elided, whereas unaccompanied newline characters remain present. Example: echo -ne 'a\n\nb\nc\n\n\n\nd\n\n\n' | your-command should output the same as echo -ne 'ab\ncd\n' Watch out, some POSIX tools have implementa...
Task This one is simple. We want to compress a URL, but don't trust URL shorteners. Write a program that prints to stdout (or a 0-argument function that returns) the following, working URL: http://a.b.c.d.e.f.g.h.i.j.k.l.m.n.oo.pp.qqq.rrrr.ssssss.tttttttt.uuuuuuuuuuu.vvvvvvvvvvvvvvv.wwwwwwwwwwwwwwwwwwwwww.xxxxxxxxxxxx...
An old test for programmers, taken from here (Note: in italian). Along a road (denoted by '_'), there is a Magical Piper (denoted by 'P') and several mice (represented by the two characters 'o' and '~', that denote respectively the head and the tail of the small rodents). Write a program that prints how many mice are g...
Mountain range number A number is a mountain range number if the inequalities satisfied by their consecutive digits alternate. In a way, looking at the number's digits should exhibit a /\/\/\... or a \/\/\/... pattern. More formally, if our number n has \$k\$ digits $$n = d_1d_2d_3\cdots d_k$$ then n is a mountain rang...
Given an integer n>0, write a program that will output an "isosceles" Triangle out of #'s of height n. Examples: n=3 # ### ##### n=1 # n=5 # ### ##### ####### ######### This would be invalid: # ### ##### ####### #########
Consider an eight bit number in which an even position bit will never be 1 if one of its neighbors is 0 (considering MSB and LSB as neighbors). There are fewer than 64 such numbers, so there is at least some reversible mapping of them to 6 bit numbers. Your task is to write a pair of functions (or code blocks or your l...
After seeing some impossibly short solutions in this SE, I began to wonder what code someone could come up with to build a pseudo-random number generator. Now given that I am new to programming, I have absolutely no idea what such generator should look like, or what language to write them in. But that did not stop me f...
I assume everyone here is familiar with the Caesar Cipher that shifts letters to a certain index. https://en.wikipedia.org/wiki/Caesar_cipher for those who still needs introduction. But, we can all agree that plain Caesar is unfun and way too easy. So here's a version that also shifts characters around. This version fi...
Your Goal: Given an odd integer input n greater than 1, generate a random English word of length n. An English word is one in which the odd (1-based) indices are consonants and the even (1-based) indices are vowels, the vowels being aeiou. Random For the purposes of this challenge, you are to sample from the vowels and...
Task Inputs \$b \leq 100\$ and \$n \geq 2\$. Consider \$n\$ binary strings, each of length \$b\$ sampled uniformly and independently. We would like to compute the expected minimum Hamming distance between any pair. If \$n = 2\$ the answer is always \$b/2\$. Correctness Your code should ideally be within \$\pm0.5\$ o...
The magic music box (MMB) This explains the motivation for the challenge, feel free to ignore. The magic music box is a word game played by a group of people, where one is the owner of the magic music box and the other people are trying to put words inside the magic music box. Rules for the game with humans: the game g...
The harmonic series is the "infinite sum" of all the fractions of the form \$\frac1n\$ for \$n\$ positive integer. I.e. the harmonic series is $$\frac11 + \frac12 + \frac13 + \frac14 + \cdots$$ It is well-known that this sum diverges, which means that if you define $$ H_n = \frac11 + \frac12 + \cdots + \frac1n$$ Then t...
Introduction to Mahjong tiles Mahjong (麻雀) is a board game that originates from China. Mahjong tiles used in this challenge are in Unicode points U+1F000 – U+1F021: They are categorized as: Winds (風牌): (East Wind), (South Wind), (West Wind), (North Wind) Dragons (三元牌): (Red Dragon), (Green Dragon), (White Dragon) Te...
Definition For any \$a\equiv1\ (\text{mod }8)\$ and \$n\ge3\$, there are exactly 4 roots to the equation \$x^2\equiv a\ (\text{mod }2^n)\$. Now, let \$x_k(a)\$ be the smallest root to the equation \$x^2\equiv a\ (\text{mod }2^k)\$, then $$\{x_3(a),x_4(a),x_5(a),x_6(a),\cdots\}$$ is a smallest square root sequence (SSRS...
This should be easy: given an arbitrary string, your program will give it a name. Requirements Your program will accept an input of a UTF8 string, and output a string representing the input's "name", how you define this name is arbitrary, but it must comply with some conditions. I/O Ranges The input will at most be 382...
Simple task, write a program/function that returns error if and only if presented with itself. The program must give a valid output for any input other than itself. For the error part, you can only use errors already built in errors that comes with your language of choice. New/ self-defined error messages are not allow...
Based on this question from Code Review. Given precisely three positive integers, return the product of all of the distinct inputs. If none of the inputs are distinct, return 1. That is, implement the function: \$ f(a,b,c) = \cases{1 & $a = b = c $ \\ a & $ b = c $ \\ b & $ a = c $ \\ c & $ a = b $ \\ a b c & otherwise...
Bowling Bowling is a game where, essentially, each player gets 10 turns to: Take 2 attempts at knocking down 10 pins arranged in a triangle. between turns the pins are reset from the 1st to the 2nd attempt the pins are left as-is The arrangement of the pins resembles the following scheme, with the pins numbered 0-9: ...
Working on something in probability theory, I stumbled across another combinatorical exercise. These are always fun to solve, searching for intelligent approaches. Of course, one can use brute force for the following task, but this challenge is restricted complexity, so this is not allowed. Task Given an integer Input ...
I didn't invent this challenge, but I find it very interesting to solve. For every input number, e.g.: 4 Generate a range from 1 to that number: [1 2 3 4] And then, for every item in that list, generate a list from 1 to that number: [[1] [1 2] [1 2 3] [1 2 3 4]] Then, reverse every item of that list. [[1] [2 1] [3 2...
The computational parity of an integer is defined as 1 if the integer has an odd number of set bits, and 0 otherwise. (src). Input You will receive one nonnegative integer that you will take the parity of. Optionally, you may take the size of the integer in bytes or bits as an argument, but you must specify this in yo...
Task Write a function/program that, given three positive integers a, b and c, prints a Truthy value if a triangle (any triangle) could have side lengths a, b and c and outputs a Falsy value otherwise. Input Three positive integers in any sensible format, for example: three distinct function arguments, f(2, 3, 5) a lis...
Find the most important character The challenge is to write a program that outputs the most occurrent character in the input string, excluding these bracketing characters ()[]{}. Each submission should consist only of non-trivial* characters. Each solution is scored using the formula in the scoring section. Bracketi...
A doubling sequence is an array of numbers where each subsequent number is at least twice the previous number. Given an ordered list of numbers, determine if the numbers in the list (\$n_{x}\$) have the property that: \$n_1 \times 2 \le n_2\$ \$n_2 \times 2 \le n_3\ ...\$ and so on until reaching the end of the list. I...
Problem description Vertices \$V\$ of directed graph \$G=(V,E)\$ represent gossipping ladies; edge \$(u,v) \in E\$ signifies that lady \$u\$ knows of lady \$v\$ (which does not imply that lady \$v\$ knows of lady \$u\$). Assume that each lady knows of herself. Intuitively, lady \$a\$ gossips about every lady \$b\$ she ...