instruction
stringlengths
34
53.1k
This problem is from Five programming problems every Software Engineer should be able to solve in less than 1 hour which itself is an interesting read. The first few problems are trivial, but the fourth one can be a bit more interesting. Given a list of integers separated by a single space on standard input, print ou...
Given a positive integer (0 and above, no maximum), convert it into a grade following these rules: A = 100+ B = 90 - 99 C = 80 - 89 D = 70 - 79 E = 60 - 69 F = 59 and less. This felt a little boring, so make the grade a + if it's 7,8 or 9 and a - if it's 0,1 or 2. Ignore this for the F and A cases. An exampl...
What general tips do you have for golfing in Befunge 93? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Befunge 93 (e.g. "remove comments" is not an answer). Please post one tip per answer.
What general tips do you have for golfing in LOLCODE? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to LOLCODE. (e.g. "remove comments" is not an answer). Please post one tip per answer.
The Pauli matrices are a set of 2x2 matrices which appear very commonly in quantum physics (no, you don't need to know any quantum physics for this challenge). If we include the identity in the set, the four matrices are: σ0 = σ1 = σ2 = σ3 = [1 0] [0 1] [0 -i] [1 0] [0 1] [1 0] [i ...
Prelude: This task is taken from Five Problems Every Software Engineer Should Be Able to Solve in Less Than an Hour, which I really recommend. The task: Write a program that outputs all possibilities to put + or - or nothing between the numbers 1, 2, ..., 9 (in this order) such that the result is always 100. Winning ...
The Question Given a set of 9 numbers, m[], which contains only numbers 1 through 9 in a random order, with no two numbers being the same, create a program in any language which rearranges the number to be in numerical order (1, 2, 3, etc. etc.) by only switching two numbers which are next to each other (ie. 1, 3, 2 → ...
We are given a list of integers p1, ..., pk (not necessarily distinct) where each has a value between 1 and 9, inclusive. Using each of the p1, ..., pk exactly once, we can form concatenations of digits, to achieve a new list of numbers; we then output the product of this new list. The goal is to maximize this product ...
The Question Given a two dimensional array, o[][], create a 2-dimensional graph such that o[xCoordinate][yCoordinate] is the hue of the point at (xCoordinate, yCoordinate), and the value and saturation are always 100. Let the hue go from -50 to 50, where -50 and 50 are 0 and 100 respectively. Rules You may use any lan...
This is a relatively quick one, but I'm sure you'll like it. Codegolf a program that will take input in the form of a sentence and then provide the output with the first letter capitalized in each word. Rules: Submissions may not be in the form of a function. So no: function x(y){z=some_kind_of_magic(y);return z;} as ...
Given a positive integer, n, along with n non-negative integers, write a program or function that prints or returns the smallest non-negative integer that can be obtained by additions and subtractions between those numbers. You must use all of the input numbers. The winner is the algorithm with the smallest big O time ...
Write a program that takes in an integer N via stdin or the command line. If N is 0, the single letter O must be printed to stdout. If N is positive, this horizontal ASCII art double helix, drawn N segments wide, must be printed. If N is 1, the output is: /\ O O \/ If N is 2, the output is: /\ /\ O / O \/ \/ ...
You should write a program or function which receives a string as input and outputs or returns if the input is an ASCII tree. _ \/ / \_/ | | ASCII trees consist of characters / \ | _ spaces and newlines. The non-whitespace characters connect two edge points of their cells by a line segment: / connects the bot...
The Question A Sophie Germain prime is a prime \$p\$ such that \$2p+1\$ is prime as well. For example, 11 is a Sophie Germain prime because 23 is prime as well. Write the shortest program to calculate Sophie Germain primes in ascending order Rules The Sophie Germain primes must be generated by your program, not from a...
Introduction A family of seals are stranded upon an iceberg in the Arctic Circle. There is a radio transmitter located on the iceberg which the seals can use to call for help. However, only the daddy seal knows how to operate the radio transmitter. And worse, the ice is very slippery this time of year, so the seals wil...
Lets play a game of Meta tic-tac-toe! This is a king-of-the-hill tournament of Meta tic-tac-toe. The rules of Meta tic-tac-toe are as follows: All of the regular rules of tic-tac-toe apply. There are nine boards arranged to make one master board. Like so: 0|1|2 || 0|1|2 || 0|1|2 ----- || ----- || ----- 3|4|5 || 3|4...
Most common computer keyboard layouts have the decimal digit keys 1234567890 running along at their top, above the keys for letters. Let a decimal digit's neighborhood be the set of digits from its own digit key and from the digit keys immediately to the left and right, if they exist. For example, the neighborhood of ...
We have 40 sticks of same widths but different heights. How many arrangements are there possible to put them next to each other so that when we look from right we see 10 sticks and when we look from left we again see exactly 10 sticks? For example such an ordering is: Black sticks are hidden, red sticks are the ones y...
aBOTcalypse Design a bot to compete in a King-of-the-Hill challenge! Here's a replay of a default bot game. The board is 2D, like a side-scrolling video game (but without any scrolling). A valid bot must accept a multiline string representation of the region of the board it can see, and output a move for the bot. Mecha...
Input: Any Brainfuck program. This includes brainfuck programs with comments such as +++COMMENT[>+++<-].. Output: A program in one of the below languages that produces the same output as the Brainfuck program on all inputs. It should produce the same output exactly as the interepreter on this website There are no code-...
On my website, users enter their date of birth in the style xx.xx.xx - three two-digit numbers separated by dots. Unfortunately, I forgot to tell the users exactly which format to use. All I know is that one section is used for the month, one for the date, and one for the year. The year is definitely in the 20th centur...
You have been collecting data from a Advanced Collecting Device Controller™ for a long time. You check the logs, and to your horror you discover that something has gone terribly wrong: the data only contains the last bits of the numbers! Luckily, you know the starting value and that the value never changes fast. That ...
In this challenge fake marquee text is text that is shown part by part, in a scrolling-like fashion. Some examples: testing 4 t te tes test esti stin ting ing ng g hello 2 h he el ll lo o foobarz 3 f fo foo oob oba bar arz rz z Something a bit longer 10 S So Som Some ...
Introduction In this challenge, you are given a directed graph with self-loops, and your task is to convert it to an undirected graph without self-loops. Input Your input is a directed graph with vertex set {0, 1, ..., n-1} for some natural number n ≥ 0 (or {1, 2, ..., n} if you use 1-based indexing). The graph is give...
You should write a program or function which given a list of tetris blocks as input outputs or returns the biggest gap between two points in the same height level which the pieces can connect. The 7 types of tetris pieces are the following: We will refer to these pieces by the letters I, J, L, O, S, T and Z respective...
A binary string is a string which contains only characters drawn from 01. A balanced binary string is a binary string which contains exactly as many 0​s as 1​s. You are given a positive integer n and an arbitrary number of masks, each of which is 2n characters long, and contains only characters drawn from 012. A binary...
A magic sequence is a sequence of non-negative integers x[0..n-1] such that there are exactly x[i] instances of i For instance, 6,2,1,0,0,0,1,0,0,0 is a magic sequence since there are 6 0's, 2 1’s, and so on. Write a function which when given n, outputs all magic sequences of length n The program that can produce the ...
Overview This is a bot battle to see who can survive the longest. These bots increase their power by being attacked, though, so you need to think carefully before you shoot. Each turn, you can choose a bot to attack, or defend. Attacking will lower its life and increase its power. Last bot standing wins. Bots Each bot ...
The goal of this challenge is to receive an input and output that input but with sentence order reversed. Example Input: Hello friend. What are you doing? I bet it is something I want to do too! Example Output: I bet it is something I want to do too! What are you doing? Hello friend. As you can tell from the examples...
Scralphabet A normal bag of Scrabble tiles contains the following letters (? is a blank tile, which can stand for any other letter): AAAAAAAAABBCCDDDDEEEEEEEEEEEEFFGGGHHIIIIIIIIIJKLLLLMMNNNNNNOOOOOOOOPPQRRRRRRSSSSTTTTTTUUUUVVWWXYYZ?? The letters have the following value: {"A": 1,"B": 3,"C": 3,"D": 2,"E": 1,"F": 4,"G":...
You should write a program or function which receives a string describing the floor as input and outputs or returns the area of the simplest meta-tiling which could create the given pattern of the floor. The floor is a part of a square grid. Every square tile is colored either azure or black (represented by a and b in ...
Order and Chaos is a variant of Tic-Tac-Toe played on a 6x6 board. What makes the game unique, however, is that both players can place either an X or an O! Each turn (starting with Order), a player places an X or O in any unoccupied square. Winning is simple. Order wins if there are 5 Xs or Os (vertically, horizontally...
You goal is to implement the operation of XOR (carryless) multiplication, defined below, in as few bytes as possible. If we think of bitwise XOR (^) as binary addition without carrying 101 5 ^ 1001 9 ---- 1100 12 5^9=12 we can perform XOR multiplication @ by doing binary long-multiplication but doin...
Given two strings, a parent string and a query string respectively, your task is to determine how many times the query string, or an anagram of the query string; appears in the parent string, in a case-sensitive search. Examples of Behaviour Input 1 AdnBndAndBdaBn dAn Output 1 4 Explanation The substrings are highlig...
The Doctor, in trying to escape from the Dalek forces has decided to send them in a spin by traveling in various pockets of space in a spiral motion. Depending on the nature of the available space-time, The Doctor needs to enter into the TARDIS controls the height and width of the section of space and his entry point w...
Instructions Given an unknown input string i with a value of either heads or tails, return 1 for heads or -1 for tails with the shortest code. Sample not golfed code (55b): if(i == "heads"){ print(1); }else{ print(-1); } Sample golfed code (16b): print("t">i||-1) Javascript was used for the example but it's ...
Once upon a time long long ago... when there was no money or stocks yet, people were trading sheep. Even before (but close to) the invention of abacus, the great-grandfather of Warren Buffet decided it was hard to keep track of sheep. He wanted to collect all his belongings and clear all his debt, so that he could inve...
Write a function or program that processes a block of text and returns the new text. Smallest valid program wins. Each line in the block of text will have the following format: 12:34,56 The first number is the line ID, the other two comma separated numbers are references to other lines. In the input text the numbers c...
You have to write a function/program that takes input via the stdin/command-line arguments/function arguments, mixes up characters in a string, and then output the final string via the stdout. Input will first contain a string (not empty or null), a space, and then an even number of non-negative numbers all separated b...
In this challenge you will take two inputs One input will be a string of numbers of any length which you will put into an array/table/whatever you call it in your language Ex: 10 10 145 20 53 102 20 Would become arraynameofyourchoice = {10, 10, 145, 20, 53, 102, 20} You can assume the input will have spaces in betwee...
Credits to Calvin's Hobbies for nudging my challenge idea in the right direction. Consider a set of points in the plane, which we will call sites, and associate a colour with each site. Now you can paint the entire plane by colouring each point with the colour of the closest site. This is called a Voronoi map (or Voron...
The Sierpinski triangle is a set of points on the plane which is constructed by starting with a single triangle and repeatedly splitting all triangles into four congruent triangles and removing the centre triangle. The right Sierpinski triangle has corners at (0,0), (0,1) and (1,0), and looks like this: Some equivale...
The Specs Your program must read the image from one file and write the results to another file, the name of at least the first of which should be taken from the input You may accept and return any image format or formats, as long as you specify in your answers which ones you are using An exception should be thrown if ...
Write the shortest program that prints this ASCII art section of a hexagonal tiling or honeycomb: __ __/ \__ __/ \__/ \__ / \__/ \__/ \ \__/ \__/ \__/ / \__/ \__/ \ \__/ \__/ \__/ / \__/ \__/ \ \__/ \__/ \__/ \__/ \__/ \__/ No input should be taken. Output to stdout or your lan...
To each of these nine confusingly similar words, assign a number 1-9 in any way you like: though through thorough Thoreau throw threw trough tough troll Write a program that takes in a string. If the input is one of these nine words, output the number you assigned to it. If the input is not one of the words above, the...
The Challenge: Given any input that can be typed on a keyboard, move the text along by N chars. Here is the QWERTY keyboard to be used. You can ignore the modifier keys (Shift, Caps, Enter, Delete and Tab). Once you reach one side (for example |) loop back round, so | goes to Q if N = 1. Spaces do not have to be moved...
Write the smallest program you can to create affine fractals. You may use any method you feel like that generates the same results as the rules below. You don't have to use any ideas from the suggested methods! Your program will take two inputs, the first to define the pattern in the format 074 made of three digits fro...
A simple golf to start the week! You're given three arrays: the base array B, the value array V and the index array I. You should produce another array where the values from V are inserted into B at the indices specified by I. Here is an example: Base: [5, 1, 4, 1, 3] Values: [0, 0, 7] Indices: [5, 0, 3] The indic...
You are given a string and two characters. You have to print the string between these characters from the string. Input Input will first contain a string (not empty or null). In the next line, there will be two characters separated by a space. Challenge Return the string between the two characters Example Hello! What's...
Instructions Barry is a not so good backend developer in charge of a small API that should give you information about purchases made in a client's shop. However, he hasn't done a great job and your boss tells you to fix it client-side instead. Ideally you should receive comma-separated values such as 927,2,45,90 which ...
Recently at Puzzling.SE, there was a problem that I wrote about determining which two bottles out of a larger number are poisoned when the poison only activates if both components are drunk. It ended up being quite the ordeal, with most people managing to get it down to 18 or 19 prisoners using completely different alg...
Oh no! Nemo, our small clown fish is lost in this ASCII ocean and his dad Marlin is trying to find him. Your task is to get Marlin to Nemo safely. But beware, we have a feeding frenzy Bruce on the loose, so better avoid him at all costs! Details You are given a rectangular ASCII ocean grid containing only lowercase alp...
This is a successor to my previous Code Golf challenge, which may be found here. This time, you are trying to determine what the contents of colors.txt should be. Your task is to take from the input the path to an image and a number of colours, and write to colors.txt a list of that many colors chosen for that image. R...
Background (F#) Let there be trees: type Tree<'T> = Node of 'T * Tree<'T> list Now lets fold them nicely with a function called... foldTree f:('a -> 'b -> 'c) -> g:('c -> 'b -> 'b) -> a:'b -> t:Tree<'a> -> 'c ...taking two functions f and g, an initial state a and of course a tree structure t. Similar to the well kno...
A musical string is any string that can be played on a piano keyboard. For those of us who weren't forced to learn the piano as kids, here is what the keyboard looks like. So the string feed a dead cabbage is a musical string because every single letter corresponds to one of these nots. Your challenge is to write a pr...
A bunch of cars are lined up at a 4-way stop sign waiting to proceed. Everyone is confused about who gets to go next, who is going which way, etc. Clearly suboptimal. Your job is to schedule the traffic at the stop sign in an optimal fashion. You receive as input 4 strings of turn requests, one for each of the four c...
Introduction Arithmetic Gaol is a special facility that incarcerates positive integers. However, recently, the positive integers have been trying to escape. Therefore the wardens have decided to, um, eliminate some of the positive integers to send a message to the other integers. They have hired a software engineer to ...
This is a follow-up of CodeGolf - Ignore the noise #1 the only problem being that Barry has made things even worse for us. Lets see what happened Update I've added code to create random input and expected output because I'm not that good at explaining what I want, and I guess that sometimes words are more mislead...
Challenge You will be given a table as input, drawn with ASCII | and _. Your task is to set the chairs around it. Example Input: ____ | | | | | | | | |____| Output: _^_^_ < > | | < > | | <_ _ _> v v Those chairs are made of <> and v^. Another example: The line must have as many chairs ...
The seam carving algorithm, or a more complex version of it, is used for content-aware image resizing in various graphics programs and libraries. Let's golf it! Your input will be a rectangular two dimensional array of integers. Your output will be the same array, one column narrower, with one entry removed from each r...
This challenge is inspired by a puzzle I played, consisting of foam pieces like these: which have to be assembled into 3D cubes, like these: The puzzle pieces can be viewed as grids of 5 * 5 squares, whose middle 3 * 3 squares are always solid, while the 16 squares on the edges can be solid or empty. A piece will be ...
Two words are isomorphs if they have the same pattern of letter repetitions. For example, both ESTATE and DUELED have pattern abcdca ESTATE DUELED abcdca because letters 1 and 6 are the same, letters 3 and 5 are the same, and nothing further. This also means the words are related by a substitution cipher, here with t...
Write a full program or a function that takes a positive integer N as input via STDIN/command line/ARGV or function arguments and prints an ASCII double knot corresponding to the N to STDOUT. The ASCII double knot looks like this: __ __ __ __ __ __ / \/ \/ \/ \/ \/ \ | /\/ /\/ /\/ /\/ /\/ /\ | | \/ /\/ /\...
You are given a string. Output the string with one space per words. Challenge Input will be a string (not null or empty), surrounded with quotes(") sent via the stdin. Remove leading and trailing spaces from it. Also, if there are more than one space between two words (or symbols or whatever), trim it to just one space...
A Flow Snake, also known as a Gosper curve, is a fractal curve, growing exponentially in size with each order/iteration of a simple process. Below are the details about the construction and a few examples for various orders: Order 1 Flow Snake: ____ \__ \ __/ Order 2 Flow Snake: ____ ____ \__ \ \__ \__/ / __ ...
Edit: Allowed to reuse whitespaces. Your task is to write n programs (or functions, or bodies of functions without using parameters or the function names) in the same language. The kth program should output the (cardinal) number k in standard English in lowercase (with an optional trailing newline). So the first progr...
Two strings are "Caesar equivalent" if the distance (counting up) between the corresponding characters are the same. Yes, I made this term up. Here's an example: "Abc" and "Cde" are equivalent because distance from a-c == 2 distance from b-d == 2 distance from c-e == 2 The capitalization doesn't make any difference. "...
This is a rather easy challenge. Challenge Input will contain a string (not null or empty) of maximum length 100. Output the number of vowels in each word of the string, separated by spaces. Rules The string will not be more than 100 characters in length. The string will only contain alphabets A-Z , a-z and can also c...
Any regular hexagon can be tiled with diamonds, for instance like so: ______ /_/_/\_\ /_/\_\/\_\ /\_\/_/\/_/\ \/_/\_\/_/\/ \_\/_/\_\/ \_\_\/_/ We'll consider the above a tiling of size 1 (since the diamonds' sides are made of one / or \ each). The same tiling of size 2 would look like: ____________ ...
Background (Based on a true, heart-wrenching story) In my time, I've played around with Lisp and similar languages often. I've written with them, ran them, interpreted them, designed them, and made machines write with them for me... And if there is one thing that bothers me, it's seeing Lisp that does not comply with m...
Background An atomic bomb has exploded near the fencepost factory! Since fenceposts are essential for the survival of our civilization, we must rescue as many as possible. We are sending radiation-resistant robots to search the area, and it is your task to program their artificial vision. Input Your input is a rectangu...
Your goal is to write a program that, given a number N and a string as input, will return a string containing every Nth word of the original string, starting from the first word. Sample inputs/outputs: N = 2, str = "This is a sentence" "This a" -- N = 2, str = "The quick brown fox jumped over the lazy dog." "The brow...
You are given a multi-dimensional array of integers. Each dimension has a fixed size (so that it would be always rectangular if it is 2D). Your program should calculate the sums in each dimension and append the sums as the new last items in that dimension. Assume the input and output arrays are A and B, and the size of...
In today's episode of AAOD, we are going to construct a Chinese Shrine of varying heights. Consider the following examples for height (N) 1 to 6 N = 1: . | . ]#[ . \_______/ . ]###[ . \__]#.-.#[__/ |___| |___| |___|_|___| ####/_\#### |___| /_____\ N = 2: . ...
K is a programming language in the APL family designed by Arthur Whitney. While the official interpreter is closed-source and commercial, a trial version with a workspace limit of 32 bits of addressing space (which shouldn't pose problems for code golf) can be found at the Kx Systems website. This version bundled as pa...
Here is another short string related code-golf. You must write a full program that reads a string (from STDIN or as command line arguments, as long as you specify which) and wips the flords around (flips the words around). A valid flord wip must Flip all of the beginning consonants. (All of the leading consonants up t...
Finding the Deadlock When programming a multithreading application one must take good care to avoid deadlocking the various threads when accessing shared resources. A deadlock occurs when a thread attempts to access a resource that's locked in another thread at the same time that the other thread is trying to access a ...
The contest is over! Intro This is an interactive king-of-the-hill contest where the controller is fully contained in a Stack Snippet at the bottom of the question. The controller automatically reads the answers and plays through games. Anyone can run it at any time right in their browser. The mechanics of this contest...
It's time... to count the votes! Today there are local elections in my entire country. Here, the number of seats for each party is decided using the D'Hondt method. Your goal is to implement a program or function that will decide how many seats each party gets, in the shortest amount of bytes. For this method there are...
A polyglot is a program which can be run by several different language's interpreters/compilers without failing. For example, the stackoverflow 404 page contains a polyglot which runs in Python, Perl, Ruby, C, brainfuck and befunge, each time printing 404 to stdout. Now, my challenge is to create a polyglot which, whe...
Shrink each word in a string of group of strings to single letters delineated by spaces or punctuation. Example I'm a little teapot, short and stout. Here is my handle, here is my spout. When I get all steamed up - hear me shout! Tip me over and pour me out. becomes I' a l t, s a s. H i m h, h i m s. W I g a s u -...
Write a self replicating program, in the source code filename H.*, contianed in an empty folder then manually compile and run or just run the program if your chosen language is dynamic, and it should then just create a new source file, e.*, with the same exact source code, and automatically compile/run that new program...
Introduction Clarence is a data entry clerk who works at an internet service provider. His job is to manually enter the IP addresses of all of the ISP's customers into the database. He does this using a keypad which has the following layout: 123 456 789 .0 The distance between the centre of horizontally or vertically a...
Given the size of the chess board and initial position of the knight, calculate the probability that after k moves the knight will be inside the chess board. Note: The knight makes its all 8 possible moves with equal probability. Once the knight is outside the chess board it cannot come back inside. Input Inputs ar...
Let \$n > 0\$. Let \$X = 1, 2,...,n\$ and \$Y = n+1, n+2, ..., 2n\$. Define \$a(n)\$ as the number of permutations \$p\$ of \$Y\$ such that every element of \$X + p(Y)\$ is prime. For example: n = 2 X = [1,2] Y = [3,4] p_0(Y) = [3,4] => X + p0(Y) = [4,6] => No p_1(Y) = [4,3] => X + p1(Y) = [5,5] => Yes a(2) = 1 In as ...
This is a byte sized challenge where you have to convert an input temperature in one of the three units (Celsius, Kelvin and Fahrenheit) to the other two. Input You would be provided with a temperature as a number followed by a unit (separated by space). The temperature can be an integer or a floating point number (23 ...
...at least for some definition of "self-modification". The Task In this challenge, your task is to write three strings A, B and C that satisfy the following properties. The string B has length at least 1. For every n ≥ 0, the string ABnC is a valid program (meaning full runnable program or function definition) in you...
Background: Every war eventually comes to an end, but the end is never absolute. The Stone Maze Chess scenario takes place after a game of chess is finished. The enemy King is dead and the pieces is lost in vacuity almost out of faith, multiplying. The winning side has moved on except for the Hero who is left behind wi...
Consider the process of: Taking a non-negative integer N. e.g. 27. Spliting it into integers N - floor(N/2) and floor(N/2) (a 'bigger' and 'smaller' half) and writing them in that order. e.g.27 becomes 14 13. Removing the space to join the integers into a new, much larger integer. e.g. 14 13 becomes 1413. Repeating st...
Resistors commonly have color coded bands that are used to identify their resistance in Ohms. In this challenge we'll only consider the normal 4-band, tan, axial-lead resistors. We'll express them as: xyzt Where x is the first band for the first significant figure, y is the second band for the second significant figur...
What is the shortest amount of code that can find the minimum of an inputted polynomial? I realize that you can import packages like Numpy and others, but using only user defined functions, what is the shortest way to do this? For example, if 6x6 + 4x3-12 is entered (ignore parsing issues), what would be the shortest a...
Introduction My niece wants to make a race car track. She has wooden parts that fit together to form the track. Each part is square shaped and contains a different shape. I'll use the pipe drawing characters to illustrate: │: the road that goes vertically ─: the road that goes horizontally ┌ ┐ └ ┘: the roads that turn...
Objective: A guru once said a perfect code selfie is best shot diagonally from upper left corner. A code selfie is almost like a Quine - but rotated 45 degree clockwise. Your mission is to code a program that outputs a code selfie. Rules: You can use any programming language. Your programs should not take any input fr...
This challenge is quite simple. You will take an input which will be a year from 1801 to 2400, and output if it is a leap year or not. Your input will have no newlines or trailing spaces: 1954 You will output in any way that you like that clearly tells the user if it is or isn't a leap year (I will accept y or n for y...
Today's XKCD is a sports-tournament style bracket, where the contestants are well-known names, put into groups of possibly confusing names. Give the probability that a given contestant will win the entire tournament, based on each contestant in a given round having an equal chance of winning that round. Input The name ...
The Challenge Consider the following diagram of the Fifteen Puzzle in its solved state: _____________________ | | | | | | 1 | 2 | 3 | 4 | |____|____|____|____| | | | | | | 5 | 6 | 7 | 8 | |____|____|____|____| | | | | | | 9 | 10 | 11 | 12 | |____|____|____|____| | | | ...
There are two pieces of wood. Both consist of a straight body and some extra blocks below the body. An example piece with extra blocks at (0-indexed) positions 0,4,7,9,10: XXXXXXXXXXX X X X XX The piece can be represented as a 01 binary sequence with the ith character showing if there is a block at the ith position...
Background I have a string in Python which I want to convert to an integer. Normally, I would just use int: >>> int("123") 123 Unfortunately, this method is not very robust, as it only accepts strings that match -?[0-9]+ (after removing any leading or trailing whitespace). For example, it can't handle input with a dec...
The species of geese known as Alex A are known for residing in triangular grids consisting of 64 cells: (Picture taken from this unrelated Project Euler problem.) We'll label each cell with the numbers 0 to 63 starting from the top row and then moving from left to right on each row below that. So the top cell is 0 and...
I found this sequence while working on Evolution of OEIS, but never got around to posting it as an answer. After writing a reference implementation in Mathematica, I thought this is a fun exercise to do as a separate challenge though, so here we go. Let's build a numeric fission reactor! Consider a positive integer N. ...