instruction
stringlengths
34
53.1k
Given an input of a positive integer, output the number of steps it takes to find the input via a binary search starting at 1. We are simulating a binary search for the integer that was given as input, in which the simulated searcher can repeatedly guess an integer and be told whether it is too high, too low, or correc...
Introduction Boardgames are a classic play between kids, but there are some kids that feel bored playing a boardgame step by step. Now they want the result to be shown before they put their hands on the board. Challenge Suppose this boardgame: >---#<---X---<X<--#-$ > means the start of the game - means a position w...
Aside of nursing my child, Vitsy, and dabbling in the art of code golf, I also am an avid dubstep fan, listening to all the new dubstep that Monstercat puts out as regularly as I can. I also share a random dubstep of the day, though not regularly, in the Nineteenth Byte. This last bit is what this challenge relates to;...
This challenge is similar to this other, however I made a restriction (see bold text below) that I think would made it much diffent and (I hope) fun either. The Challenge Write a program or a function in any programming language that takes as input the English name of a positive integer n not exceeding 100 and returns...
Here is a very simple language definition: A Variable is any string that does not contain ^, <, >, !, or ? The empty string is a valid variable identifier The value of every variable starts at 0. A Statement is one of (var is a Variable, P is a Program): var^ -> changes var to be equal to 1 more than itself v...
Goal As the title suggests, write a radix sort function (either MSB or LSB is fine) that accepts two parameters: an array of values of any type (you can assume that they are all of the same type / class, etc.) a function (or function pointer, depending on your language) that takes a single parameter of the same type a...
In the fewest bytes possible, determine whether the two values given each match one of the following: First value 2 string or integer - whichever you prefer to case insensitive too case insensitive two case insensitive t0 case insensitive (t zero) Second value b case insensitive be case ins...
The task The credit rating agencies assign ratings to bonds according to the credit-worthiness of the issuer, and the "Big Three" credit rating agencies use a similar (though not identical) tiered rating system. These have a clear, logical order - using the S&P tiers, AAA > AA+ > AA > AA- > A+ > ... > BBB > B > ... > C...
We will be implementing division for arbitrarily large integers. This is code-golf. The task is to write a program or function that implements arbitrary precision integers and Division on them. Note that many things that might make this very easy are disallowed, please make sure to read through the spec. Input You will...
Create a function or program that takes a number as input, and outputs a string where ASCII-code points for the lower and upper case alphabet are substituted by their character equivalents. The upper case alphabet use the code points: 65-90 The lower case alphabet use the code points: 97-122 If any adjacent digits i...
Introduction I have recently started playing clickerheroes again. In the recent patch they introduced a new mechanic to mercenaries: their lifetime. Instead of having a random chance at dying now they have a certain lifespan given by a geometric distribution of p = 0.2. They can be sent on quests to accumulate a premiu...
Introduction My grandpa is a fan of James Bond, but he is always unsure on how to rank his favourite actors. As such, he is always making lists, which is a lot of work. He asked me to produce a program that will make his life easier, but I do not have time for that, I have to work! So I will count on you guys. Challeng...
Based on an idea suggested by Zgarb. A spaceship is moving around a regular 3D grid. The cells of the grid are indexed with integers in a right-handed coordinate system, xyz. The spaceship starts at the origin, pointing along the positive x axis, with the positive z axis pointing upwards. The spaceship will fly along a...
Consider a permutation of the integer values from 1 to N. E.g. this example for N = 4: [1, 3, 4, 2] We'll consider this list to be cyclic, such that 1 and 2 are treated as adjacent. One quantity we can compute for such a list is the total squared difference of adjacent values: (1-3)² + (3-4)² + (4-2)² + (2-1)² = 10 Y...
Van der Waerden's theorem says that For any given positive integers r and k, there is some number N such that if the integers {1, 2, ..., N} are colored, each with one of r different colors, then there are at least k integers in arithmetic progression all of the same color. The least such N is the Van der Waer...
I wanted to ask this question: Convert to and from the factorial number system but I'm a couple of years too late! So, instead you must convert to and from the lairotcaf backwards-factorial number base! The way it works is that the first digit is always 0, the maximum value of the next digit is 1, then 2 and so on. If ...
Given an input of a list of numbers in the format of a shorthand increasing integer sequence, output the sequence in full. Shorthand increasing integer sequence format works by finding every number n with fewer digits than the number preceding it, m. With d as the number of digits in n, the last d digits of m are repla...
Task Write a program or function that will determine if a point in 3D space lies on a 2D parabolic curve. Input 3 points in 3D space vertex of a 2D parabolic curve arbitrary point on the curve arbitrary point in space Input may be taken in any form (string, array, etc.) provided no other data is passed. You may ass...
Challenge Find an expression, at most 100 bytes long, with the longest type signature. Rules Any statically typed language with type inference is allowed The type must be non-ambiguous, but otherwise may include types without defined instances. For example Num [a] and Eq [a] are allowed, even without a defined instanc...
You receive an input with a number and a string with a space in the middle. The string tells you what you need to do with the number, it can be: sqrt - square root of number sqr - square of number cube - cube of number abs - absolute of number round - rounded version of number You need to output the final result of the...
Task The task is very simple. Given a non-empty string containing numbers, uppercase and lowercase letters, output the sum of the remaining numbers. For example: a1wAD5qw45REs5Fw4eRQR33wqe4WE Filtering out all the letters would result into: 1 5 45 5 4 33 4 The sum of these numbers is 1 + 5 + 45 + 5 + 4 + ...
The ancient Greeks had these things called singly and doubly even numbers. An example of a singly even number is 14. It can be divided by 2 once, and has at that point become an odd number (7), after which it is not divisible by 2 anymore. A doubly even number is 20. It can be divided by 2 twice, and then becomes 5. Yo...
A metaquine is a program which is not a quine, but whose output, when run as a program in the same language, is a quine. The goal of this challenge is to write a metaquine. This is code-golf, so shortest code wins, with earliest answer used as a tiebreaker. Note that only full programs are acceptable, due to the defini...
Given a non-empty list/array containing only non-negative integers like this: [0, 0, 0, 8, 1, 4, 3, 5, 6, 4, 1, 2, 0, 0, 0, 0] Output the list with trailing and leading zeroes removed. The output for this would be: [8, 1, 4, 3, 5, 6, 4, 1, 2] Some other test cases: [0, 4, 1, 2, 0, 1, 2, 4, 0] > [4, 1, 2, 0, 1, 2, 4]...
Given 3 positive integers a, b, and n (whose maximum values are the maximum representable integer value in your language), output a truthy value if a ≡ b (mod n), and falsey otherwise. For those unfamiliar with congruency relations, a ≡ b (mod n) is true iff a mod n = b mod n (or, equivalently, (a - b) mod n = 0). Rest...
The task A string S is constructed with the following process: Start with S being the empty string. Insert at some position of S a string of the form ds, where d is a nonzero digit and s is a string of d lowercase ASCII letters. We say ds is a constituent of S. Go to step 2 or stop. Your task is to take such a string...
A variable number of bits is an array of 0 or more bits. So [0, 1] is a variable number of bits, but so is []. Write a function or program that, given an nonnegative integer returns a variable number of bits such that every integer has a one-to-one (bijective) mapping with an array. There are an infinite amount of such...
OEIS A000009 counts the number of strict partitions of the integers. A strict partition of a nonnegative integer n is a set of positive integers (so no repetition is allowed, and order does not matter) that sum to n. For example, 5 has three strict partitions: 5, 4,1, and 3,2. 10 has ten partitions: 10 9,1 8,2 7,3 6,4 ...
Given a series of os representing dots, connect them vertically or horizontally Examples Input: o o o Output: o---o | | o Input: o o o o Output: o---o----o | o Spec If you want the input padded with spaces to form a rectangle, please specify this in your answer There will only be o, spaces, a...
One of the things that makes contract bridge very interesting is its highly complicated "artificial" meta game. This system of scoring hands is a small part of it. Bridge is a trick-taking card game. Each player gets a hand of 13 cards, and the game starts with the bidding. The bidding determines how the rest of the ga...
Imagine a "wire" that has n spaces. Imagine further that there are "electrons" in that wire. These electrons only live for one unit of time. Any spaces in the wire that are adjacent to exactly one electron become an electron. In Game of Life terminology, this is B1/S. For example, this is a wire of length 10, with peri...
In the vein of large number challenges I thought this one might be interesting. In this challenge, we will be using the Residue Number System (RNS) to perform addition, subtraction, and multiplication on large integers. What is the RNS The RNS is one of many ways that people have developed to identify integers. In th...
Sometimes when I'm bored, I take some text and fill the "holes" in the letters. But isn't filling the holes the most boring thing you can do? I think we should automate it, so we could use our time better. Standard code-golf rules apply. Input A string containing sequence of alphanumeric characters (a-z, A-Z, 0-9) and ...
ADFGX cipher encryption The ADFGX cipher was used by the German army in WWI. Write a program to encipher with it! It works as follows: Create a 5x5 Polybius square with a mixed alphabet. The polybias square is labled A D F G X along the top and left. Generate the pairs, so A in its non-mixed position is AA, B is AD an...
Art stolen from What size is the digit? 7-segment digits can be represented in ASCII using _| characters. Here are the digits 0-9: _ _ _ _ _ _ _ _ | | | _| _| |_| |_ |_ | |_| |_| |_| | |_ _| | _| |_| | |_| _| Your job is to parse the art into normal numbers. Notes on numbers Each digit ...
You're given two numbers a and b in base 31 numeral system and number k with no more than 10000 decimal digits. It is known that b is divisor of a. The task is to find last k 31-based-digits of quotient a/b. The solution with fastest proved asymptotics in length of max(a,b) wins. I'll put a bound of 10^5 on length of a...
In Skyrim, the player character can use powerful magic shouts (Thu'ums) to achieve their goals. Every shout consists of three words, however, the player can use the first one or two words to achieve the same effect with less power but at a shorter cooldown. Given a lowercase ASCII Thu'um phrase without punctuation or s...
It's weekend and what are the cool guys doing on weekends? Drinking of course! But you know what's not so cool? Drinking and driving. So you decide to write a program that tells you how loaded you are and when you are gonna be able to drive again without getting pulled over by the cops and loosing your license. The Cha...
In this code golf, you need to get the closest number from another one in a list. The output may be the closest number to the input. Example: value: (Input) 5 --- [1,2,3] --- 3 And, the program may work with negative numbers. Example: value: (Input) 0 --- [-1,3,5] --- -1 value: (Input) 2 --- [1, 5, 3] --- 1 (Because...
Challenges You need to do a program that outputs the input string to hexadecimal! For each character in the input string, convert it's ascii value to hexadecimal and output it out. Example Something = 536f6d657468696e67 Of course, this is code golf, so the shorter code wins!
You need to make a program, that when giving a list and a string, searches on the list for items that contains the string. Examples: Input: th [thing, awesome, potato, example] Output: thing (Because it starts with "th") Input: ing [thing, potato] Output: thing (Because it ends with "ing") Input: tat [thing, potato] ...
To check whether a decimal number is divisible by 7: Erase the last digit. Multiply it by 2 and subtract from what is left. If the result is divisible by 7, the original number is divisible by 7. (also described e.g. here) This rule is good for manual divisibility check. For example: Is 2016 divisible by 7? Subtract...
You are an employee at the hip new grocery store Half Foods, and it's the day before Thanksgiving Christmas Easter. Since the store will be packed with customers rushing to get their foodstuffs, the store needs a traffic manager to send everyone to the appropriate lines. Being lazy, you'd like to automate this so that ...
You are given a table that represents the rankings of S subjects according to a number C of different criteria. The purpose is to compute an overall ranking according to a weighted sum of the C ranking criteria, using one of those criteria (i.e. columns), T, as tie-breaker. The rankings are a S×C table of positive in...
Disclaimer: This challenge is extremely scientifically inaccurate. ;) Given an input of a list of molecules, output what the result would be if they were to all combine via dehydration synthesis, if possible. For the purposes of this challenge, although this description is inaccurate, a dehydration reaction between two...
The Juggler sequence is described as follows. Beginning with an input \$a_1\$, the next term is defined by the recurrence relation $$a_{k+1} = \begin{cases} \left\lfloor a_k ^ \frac 1 2 \right\rfloor,\text{ if } a_k \text{ is even} \\ \left\lfloor a_k ^ \frac 3 2 \right\rfloor,\text{ if } a_k \text{ is odd} \\ \end{cas...
Given an m by n chocolate bar, m,n positive, output the number of ways to break the bar into mn 1 by 1 pieces where each break occurs on a gridline. Order is important. Pieces are also distinguishable, so the two pieces on either end of a 1 by 3 chocolate bar are not equivalent. For instance, for a 2 by 2 block we have...
This is code-golf. In this challenge, we will be writing programs/functions that solve "Knights and Knaves" puzzles. Background You find yourself on an island ... etc. ... every person on the island except for you is either a knight or a knave. Knights can only make true statements. Knaves can only make false statemen...
I have this code : tr ' ' '\n'|sort -n|head -1 The code is pretty simple, it takes a list of integer in the standard input stream (like 5 9 8 7 5 2 -12 -30), it sort the integers and display only the first integer. But i need to ouput 0 if the given list is empty. And i can't find a short way to that. I have a solutio...
The original "Blue Eyes" puzzle is given here (and below). A group of people with assorted eye colors live on an island. They are all perfect logicians -- if a conclusion can be logically deduced, they will do it instantly. No one knows the color of their eyes. Every night at midnight, a ferry stops at the islan...
Most people can't easily do modulus (or work out if a number is divisible by another number) in their heads because long division is harder than addition, subtraction and multiplication. The following method describes a way to calculate modulus in your head, as long as you can remember just a few different numbers. Thi...
Consider an array x such as [1 5 3 4] and a number n, for example 2. Write all length-n sliding subarrays: [1 5], [5 3], [3 4]. Let the minimax of the array be defined as the minimum of the maxima of the sliding blocks. So in this case it would be the minimum of 5, 5, 4, which is 4. Challenge Given an array x and a pos...
Introduction Compute is a esoteric joke language. From the esolangs entry: Compute has no required syntax and has the power to solve any and all problems. It is smart enough to interpret any human language (English, Spanish, Latin, etc), any programming language (C++, Java, brainfuck, etc), or any kind of data you can...
A 1-up quine is a program which is very similar to a quine. The one major difference is that instead of printing itself once, when n copies of the program are concatenated, the result prints the original program n+1 times. Example If your program is Abc123: Abc123 -> Abc123Abc123 Abc123Abc123 -> Abc123Abc123Abc123 ...
We have a Brainf*** to TinyBF converter, but not the other way around, so here's one. Rules: Your interpreter must take a valid TinyBF program, on one line, and it must output the corresponding BrainF*** program, on one line, with optional trailing whitespace/newline. No leading whitespace is allowed The input may or ...
I love BATCH, despite its shocking lack of functional commands, despite even due to its lack of non-integer support. Why? Because this works: SET var=SET %var% i=0 This would evaluate to: SET var=SET SET i=0 Fantastic, isn't it? I've used this technique in a BATCH program before, because it saves bytes! Your challeng...
For each integer n, 0 or higher, output the lowest power of 2 that has two identical sub-strings of n digits in decimal, and the two indices where the digit sub-strings start (0-based). n      Output      Proof (don't output this) 0 => 0 [0 1]        (_1 & 1_) 1 => 16 [0 4]      (65536 & 65536) 1 =...
Challenge Your task is to output the time (in 12 hour time) in ascii art. All characters that will be used are as follows: ___ __ ___ ____ _ _ _____ __ ______ / _ \ /_ | |__ \ |___ \ | || | | ____| / / |____ | | | | | | | ) | __) | | || |_ | |__ / /_ / / | | | | | ...
Question: can you design a Builder Pattern API which verifies at compile time that every field is set exactly once? To be eligible, the size of the compiler output should not be exponential in the number of fields. The best solution will be the shortest implementation for a class of 22 fields. Example of a possible su...
Introduction I think everyone agrees that nice pictures have to have a nice frame. But most challenges on this site about ASCII-Art just want the raw picture and don't care about it's preservation. Wouldn't it be nice if we had a program that takes some ASCII-Art and surrounds it with a nice frame? The Challenge Write ...
Introduction This is how a chessboard looks like. You can see that a1 is a dark square. However, b1 is a light square. The Task The challenge is, given dark, light or both, output all the dark, light or all squares with a separator (like a whitespace or a newline). The order of all the squares does not matter. Test ca...
In this quine variant, your program must output its source code transposed across the diagonal from the top left to the bottom right. For example: your program on four lines outputs yof ono u u r r      p l r i o n g e r s a m The whitespace in the output is not arbitrary. Spaces appear in two situations...
The challenge is to identify the missing number in a string of undelimited integers. You are given a string of digits (valid input will match the regular expression ^[1-9][0-9]+$). The string represents a sequence of integers. For example, 1234567891011. All numbers in the sequence are in the range from 1 and 214748...
Given an input of a string with bytes that may be in either binary, octal, or hex, output the string's ASCII equivalent. Input will be provided in the following format, for example: 501200100001147 which represents 0x50 0o120 0b01000011 0x47 which is equivalent (in ASCII) to PPCG Binary, octal, and hex will always b...
Given an input string containing only letters and numbers, write a program or function that prints the possible printable ASCII characters (Hex 20-7E) that correspond with the string's value in bases 8, 10, and 16 (where possible). The characters must be written in increasing order in terms of the bases with which they...
Write a program or function that given a string (or your language's equivalent), determine if the string is a word, or not, and output a truthy or falsy value. (This is not a duplicate of Is this even a word? The incorrect words are generated in a very different way that I believe makes this a completely different chal...
Challenge Given a natural number, output it in the ASCII form of Agrippa's number system. Description I like odd alphabets and numeral systems. My favorite numeral system is one given by Heinrich Cornelius Agrippa. It gives a succinct way to write numbers in the range [0,9999], where single digits are written as follow...
Consider a 1-dimensional, real-valued vector x that represents observations of some process measured at equally spaced intervals over time. We call x a time series. Let n denote the length of x and x̄ denote the arithmetic mean of x. The sample autocovariance function is defined as for all -n < h < n. This measures t...
Output the provided table of English pronouns exactly, in as few bytes as possible. Code rules The code will take no input The table is tab-delimited Each line begins with a single tab \t if there is no row heading Each line ends in a single newline \n (not \r\n), including the last line There are four tabs between "P...
Write some code that takes a single string as input and outputs MSB-set aligned ASCII. Only ASCII characters less than 128 (0x80) will be in the input. The output format is generated as follows: For each character convert it to its binary representation, remove the MSB (always 0 in the input) and then add a delimiter-...
I'm reproducing the second part of the first day of Advent of Code, with permission from the creator. Santa is trying to deliver presents in a large apartment building, but he can't find the right floor - the directions he got are a little confusing. He starts on the ground floor (floor 0) and then follows the instruct...
The goal is really simple. Receiving a string as input, parse all the HTML entities that correspond to the following characters (including their uppercase variants): áàãâäéèêëíìîïóòõôöúùûüýÿ Parsing rules: Each entity starts with & and ends with ; The first character after the & will be the modified character (letter...
Task Given an image with a line on it, produce or display an image with the line extended till the edge of image. The line is black and the background is white. The image size is 100x100 The image comes in any reasonable format (e.g. jpg, png, ppm, bmp). Line format I'm using a simplified version of Bresenham's line al...
Introduction Nine Mens's Morris (also called Mills) is a board game for two players which is played on the following board (image taken from the linked Wikipedia-page): Each player has 9 men, colored black and white. The concrete rules are not important for this challenge, but check out the Wikipedia-page if you are i...
The Background Imagine the English alphabet written out in a row in capital letters -- ABCDEFGHIJKLMNOPQRSTUVWXYZ. Suppose we have a special variable-width lens such that, when placed over the row, it shows a certain "window" of the alphabet, with letters outside the lens hidden from view. Additionally, this lens has a...
Background Imagine for a moment that you have a mind-numbingly boring job. Every morning, you are given a collection of tasks that you should work on that day. Each task has a certain duration, and once started, it must be completed in one go. Your boss will not tolerate idling, so if there are tasks that you could sti...
In many fonts (specifically in the Consolas font), 5 out of the 10 decimal digits have "holes" in them. We will call these holy digits: 46890 The 5 unholy digits are thus: 12357 An integer may thus be classified as "holy" if it only contains holy digits, and "unholy" otherwise. Because - is unholy, no negative intege...
On Github, there is a list of the 10,000 most common passwords. I've also generated my own list of random passwords. Your job is to identify the difference between the two lists (with 100% accuracy). Therefore, your program needs to accept a string, and return: A truthy value if the password is on the common password...
Given an input of a list of integers representing dates, output an ASCII art timeline like the following: <-----------------------------> A B C D E The above timeline is the output for input [1990, 1996, 1999, 2011, 2016]. Note several things about the timeline: The first line of output is a less ...
Do While False At work today one of my colleagues was describing the use-case for do while(false). The person he was talking to thought that this was silly and that simple if statements would be much better. We then proceeded to waste half of our day discussing the best manner to write something equivalent to: do { ...
Given two arbitrarily precise decimal numbers 0 ≤ x < y ≤ 1, compute the shortest (in digits) binary number b such that x ≤ b < y. Output the binary digits of b after the binary point as an array or a string of zeroes and ones. Note that the empty array means 0.0, by virtue of deleting trailing zeroes. This also makes ...
I define the method of combining a sequence to mean that every number in the sequence is concatenated as a string, then that result is made an integer. [1, 2, 3] -> 123 For every finite sequence of at least 3 consecutive integers, missing exactly one element in the sequence, and this missing element may not be the fir...
Challenge Implement binary search on a list of length 256 with no branches. Specification Input an integer X and a strictly increasing list of integers Output is the greatest element of the list that is less than or equal to X The output will always exist List will always have exactly 256 elements and be strictly incr...
Your objective is to write a program that takes an input, and, when chained together N times, performs "sequential multiplication". What is sequential multiplication, you may ask? It's a sequence with a seed a defined as thus: f(0) = a f(n+1) = f(n)*(f(n)-1) So, let a = 5. Thus, f(0) = 5, f(1) = f(0)*(f(0)-1) = 5*4 = ...
ROT-128 is a variant of ROT-13, where instead of cycling through the 26 letters, you cycle through the 256 possible bytes. Your task is to create a program that outputs the ROT-128 of its own source. The outputted program must also be a valid program and output the original program. Scoring This is code golf, so leas...
Introduction Let's observe the following string: ABCDEFGHIJKLMNOP If we swap the ends of the string, which are these: ABCDEFGHIJKLMNOP ^^ ^^ We get the following result: BACDEFGHIJKLMNPO After that, we delete the ends of the string, which in this case are B and O. The result is: ACDEFGHIJKLMNP If we repe...
You are provided a set of arbitary, unique, 2d, integer Cartesian coordinates: e.g. [(0,0), (0,1), (1,0)] Find the longest path possible from this set of coordinates, with the restriction that a coordinate can be "visited" only once. (And you don't "come back" to the coordinate you started at). Important: You cannot "p...
The first programming language I was exposed to was Sinclair BASIC. Like many BASIC dialects, it requires all source code lines to be numbered. As a result, use of the GO TO command was idiomatic and jumps execution to the given line number (no labels). Also there is a related GO SUB command which can be used as a rud...
Inspired by Project Euler #17, this is your challenge. Write a full program or function that takes a number as input, then print or return how many letters it would take to count up to and including that number in English (starting at one). You do not include spaces, commas, or hyphens, but you should include the word ...
Given a non-flat list of integers, output a list of lists containing the integers in each nesting level, starting with the least-nested level, with the values in their original order in the input list when read left-to-right. If two or more lists are at the same nesting level in the input list, they should be combined ...
Given an input of a list of positive integers with some replaced with 0, output the list with the missing numbers that were changed to 0 replaced. Characteristics of the input list: The list will always have a length of at least 2. Let us define the input list as a and the "original list" (that is, the list before num...
Write a program or function that takes in a non-negative integer N from stdin or as a function argument. It must print or return a string of a hollow ASCII-art square whose sides are each made with N copies of the number N. Specifically: If N is 0, no copies of N are used, so there should be no output (or only a single...
It's simple: Make a proper quine where if you remove any character, it's still a quine. The difference between this and a radiation hardened quine is that if your program is AB, in a radiation hardened quine A would output AB, but here, A would output A. Code golf, all standard rules, standard loopholes apply, no cheat...
Have you ever wondered, when doing shopping, how to pack your products into 2 bags you're carrying so that a total weight would be distributed among them as evenly as possible? Your task is to write a function, that takes a list of positive numbers (lets say integers for simplicity) as an input. It should return two li...
I like patterns in time. My favorite is when the time lines up. For example, all of these line up: 3:45 12:34 23:45 3:21 6:54 This is because each digit in the hour/minute is increasing/decreasing by one each time. Your task is to take the current time and check if it "lines up" in this pattern in a program. (You will...
A histogram is an array of integers that counts the number of times a symbol occurs. For example, for the string "aaabbbabbdebabbbebebdbaaabbabaaaaeebeaabaaba" a histogram is a: 18, b: 18, c: 0, d: 2, e: 6, or [18, 18, 0, 2, 6] in short. If we were to pick a random character out of this string, what would the chance be...
The Inspiration The Challenge I'm tired of seeing the same old-same old clock in my top-right-hand corner of my screen. It's time for a new clock. While the clock clock sated my lack of interesting clock for a little while, it simply will do no longer. Your job: make a better, more interesting clock. The Rules Make a c...
Introduction The middle-square method is used for the generation of pseudorandom numbers. However, this is not a good method in practice, since its period is usually very short and has some severe weaknesses. How does this work? Let's take an example: For the seed, we pick 123456: Seed 123456 The seed squared (see...
We've all heard of the Knight's Tour puzzle: find a route for a knight that passes through all the squares on a chess board. But let's be honest, it's a little bit boring. So, let's give the knight a bit of a challenge. Task Write a program that takes the knight through all the squares on an arbitrary-sized, arbitrary-...
I noticed that my car's odometer was at 101101 when I got to work today. Which is a cool number because it's binary (and a palindrome, but that's not important). Now, I want to know when the next time I'll have a binary odometer reading. I can't read the odometer while I'm driving, because that would be dangerous, so i...