instruction
stringlengths
34
53.1k
Given a real number, convert it to a list of lists, with the negative sign (if any) becoming an empty list, the integer part becoming a list of digits, and the fractional part (if any) becoming a list of digits. The digits must be actual numbers, not strings. Examples 0 → [[0]] 123 → [[1,2,3]] -123 → [[],[1,2,3]] 123.4...
Your task You must write a program, to print a reverse Fibonacci series, given a number. Input A non-negative integer N. Output You must output all the Fibonacci numbers from Fk to F0, where k is the smallest non-negative integer such that Fk ≤ N ≤ Fk+1. Example IN: 5 OUT: 5 3 2 1 1 0 If input isn't a Fibonacci numbe...
As a follow up to my previous challenge Count to 20 with Words!, we will once again be using the word list from that challenge to perform another task. This time, you will be exclusively using: https://github.com/Magic Octopus Urn/wordListsByLength/blob/master/10.txt To choose 26 different words, each starting with a u...
Robber's thread Your task as cops is to select three things: A programming language An OEIS sequence A byte set You are then to secretly write a program in that language that computes the nth term sequence using only the bytes in the set. You will reveal the three pieces of information so that robbers can try to f...
Cops thread Your task as robbers is to find cops solutions and write a program in the language provided that computes the nth term of the sequence using only the bytes in the provided set. The goal will be to crack as many cops answers as possible. With each crack awarding you a single point. Cracks need not be th...
Given two lists of dice rolls for a battle in Risk, your program or function must output how many troops each player loses. Background You do not have to read this, for it is merely background. Skip to "Task" subheading to continue unabated. In the game of Risk, one player can attack another player (in fact, this is ...
The Challenge Given an integer input, return the first Fibonacci number that contains the input within itself along with the index of that Fibonacci number (indexes starting at 0 or 1 - up to you, but please mention which in your answer). For example, if given the input of 12, the program would return 26: 121393 as 12 ...
Doing my history reading and note-taking, I can't help but get tired of writing out all these long dates –– 1784 is six entire pencil lifts! jǝǝz! As you can see, I –– like most challenge posters on this site –– am lazy when it comes to writing stuff. Thus, I ask you to please help me shorten some dates. Of course, you...
In the language Nim, the rules for differentiating identifiers are slightly more relaxed than most other languages. Two identifiers are equivalent or address the same variable if they follow these rules: the first character of both are the same (case sensitive) both strings are the same (case insensitive) after removi...
Given a number n, print the nth prime Fermat number, where the Fermat numbers are of the form 22k+1. This code should theoretically work for any n (i.e. don't hardcode it), although it is not expected to terminate for n > 4. (It should not return 4294967297 for n=5, as 4294967297 is not a prime number.) Do note that wh...
You will be given as input an integer k in the range from -4503599627370496 (−252) to 4503599627370496 (252). As is well known, integers in this range can be represented exactly as double-precision floating-point values. You should output the Hamming weight (number of ones) of the encoding of k in binary64 format. Thi...
Given a list of non-negative integers in any reasonable format, iterate over it, skipping as many elements as every integer you step on says. Here is a worked example: [0, 1, 0, 2, 5, 1, 3, 1, 6, 2] | [] ^ First element, always include it [0, 1, 0, 2, 5, 1, 3, 1, 6, 2] | [0] ^ Skip 0 elements [0, 1, 0, 2, 5, 1, 3...
Challenge Given an image of the sky, you must output the cloud cover in oktas. The image supplied will be an image file (the type is up to you) and the output should be to STDOUT. Oktas In meteorology, an okta is a unit of measurement used to describe the amount of cloud cover at any given location such as a weather st...
Given an integer array of at least two elements, output the Matrix-Vector (defined below) of the array. To compute the Matrix-Vector, first rotate through the size-n input array to create a matrix of size n x n, with the first element of the array following the main diagonal. This forms the matrix portion. For the vect...
Philosophers have long pondered the Trolley problem. Unfortunately, no human has solved this problem yet. Luckily, as programmers we can use computers to solve the problem for us! Input Your program will take as input a (finite) directed graph (with at most one edge from x to y, for any x and y), with a designated nod...
Fermat numbers are positive integers that can be expressed as 22x+1 with an integer x. Let us now define an attribute of a number called "Fermat-ness": The Fermat-ness of the number is one less than the length of the chain of powers of two, starting from the base, with powers of two expanded so as to maximize the ferm...
People keep telling me that the square of a number is the number multiplied by itself. This is obviously false. The correct way to square a number is to make it into a square, by stacking it on top of itself a number of times equal to the number of digits it has, and then reading all the numbers from the resultant sq...
Inspired by Create a binary wall Given a list of positive integers, we can write them out all above each other like so, for [2, 6, 9, 4] as an example: 0010 0110 1001 0100 We can imagine this as a wall: ..#. .##. #..# .#.. However, this is a very weak wall, and it has collapsed! Each 1 (#) falls down until it hits th...
Story There is a woman, named Sarah, whom likes smooth horse rides. She's going to go for a ride down a path too thin to pass any other horses she may come across - and so that her ride can be as smooth as possible she does not want to have to change speed though she would prefer to get to her destination as fast as p...
Your task is to write a program or function that checks if a string is a valid URL. Given a string as input, you will output a truthy value if the input is a valid URL. If it is not, output a falsey value. An input string is considered a valid URL if all of the following criteria are met: Begins with http:// or https:...
The challenge here is simple, and not at all about byte-count. Your job is to output the first 50 characters of the previous quine's source code, concatenated with the first 50 characters of yours starting with the 50 characters I've placed below: abcdefghijklmnopqrstuvwxyzACDEFGHIJKLMNOPQRSTUVWXY So, lets take an exa...
I love sardines, I can't get enough of them, and so does my computer, the Omnilang 5000, which is language agnostic. To give my computer the joy of experiencing sardines, I've decided to feed him a number of programs that are capable of displaying on the screen tins of sardines in various orientations, and showing up t...
Your challenge today is to write a program or function which takes a list l and gives the positions in l at which each successive element of l sorted appears. In other words, output the index of the smallest value, followed by the index of the second smallest value, etc. You can assume that the input array will contain...
You will be given a positive integer N as input. Your task is to build a Semi-Zigzag, of N sides, each of length N. Since it is relatively hard to clearly describe the task, here are some examples: N = 1: O N = 2: O O O N = 3: O O O O O O O N = 4: O O O O O O O O O O ...
Main objective The main objective is to output a text, it doesn't mind which text or where the text gets its output (it can be on a browser window, the default console etc). It just requires the condition that what is output must be indeed "real chars" (the ones in UNICODE for example), it's not considered valid to dis...
A fun pair of equivalences is 1 + 5 = 2 · 3 and 1 · 5 = 2 + 3. There are many like these, another one is 1 + 1 + 8 = 1 · 2 · 5 and 1 · 1 · 8 = 1 + 2 + 5. In general a product of n positive integers equals a sum of n positive integers, and vice versa. In this challenge you must generate all such combinations of positive...
Given an array a that contains only numbers in the range from 1 to a.length, find the first duplicate number for which the second occurrence has the minimal index. In other words, if there are more than 1 duplicated numbers, return the number for which the second occurrence has a smaller index than the second occurrenc...
We have lots of horizontal axis for numbers, but I honestly think they're kind of boring. Your task today is to build me a portion of a diagonal axis between two distinct non-negative integers given as input. How to build a diagonal axis? Let's take an example, with the input 0, 5. Our axis should look like this: 0 ...
BackStory Given a square matrix of alphabets which contain English letters in arbitrary manner. While searching a word in it, you can go left to right horizontally, vertically downwards or diagonally towards left (both upwards and downwards). You have to find the number of matches of a given word in the matrix. For exa...
(inspired by this post over on Puzzling. CAUTION: SPOILERS FOR THAT PUZZLE ARE BELOW.) The standard telephone keypad correlates letters to numbers as follows: 1 -> 2 -> ABC 3 -> DEF 4 -> GHI 5 -> JKL 6 -> MNO 7 -> PQRS 8 -> TUV 9 -> WXYZ 0 -> A given input word is defined to be an Ordered Word if, when translated to k...
Related as it requires you to measure the time between the first and last input. But here you're required to count how many inputs in a period of time. I was assigned a task to stand by a gate and count how many students enter it. The problem is that my memory is not as good as it was when I first started this job. I...
We are going to fold a list of integers. The procedure to do so is as follows, If the list is of even length, make a list of half of its length where the nth item of the new list is the sum of the nth item of the old list and the nth-to-last item of the old list. For example if we had the list [1 2 3 4 5 6 7 8] We ...
As some of you may know, to get a language onto Dennis's wonderful Try It Online!, a Hello, World! program is required. Recently, Dennis pushed up a way to load these programs from the website. Here is a JSON pastebin of the characters used in those programs, by frequency, as of July 27, 2017. Some of those characters ...
English is such an inefficient language. We've got enormous words when there are plenty of two or three letter words we never used! As computer scientists, every keystroke matters. We need to be more efficient. Just think of how many words we could have had! In fact, don't think about it, tell me. Given a string (or li...
I saw Tom Scott's video on FizzBuzz https://www.youtube.com/watch?v=QPZ0pIK_wsc so I felt to write my own more "complex" version,this is what I came up with, its very flexibly and easy to scale, and its easy to add more if cases that can trigger functions. "The challenge": Write a semi-compact "complex FizzBuzz" that c...
Task: Output the Swiss flag. Happy Swiss National Day / Schweizer Bundesfeiertag / Fête nationale suisse / Festa nazionale svizzera / Fiasta naziunala svizra! Details: The flag consists of a white (#FFFFFF) cross on a red (#FF0000) background. The cross consists of a 6x6 square with arms of size 6x7 glued to each sid...
Given a positive integer n as input, output the reversed range sum of n. A reversed range sum is created by making an inclusive range up to n, starting with 1 and including n, reversing each of the numbers inside, and summing it. Example: Here is what would happen for an input of 10: Range: [1,2,3,4,5,6,7,8,9,10] Rever...
This is my first question here, so any suggestions in the comments would be appreciated! Thanks ;) Introduction One very common strategy for the 2048 game is never ever swiping down. This positions all the big numbers at the top, and the lower ones in the bottom. So, if you apply this strategy correctly, your board wil...
It's my friend's birthday soon and since he is a programmer and ASCII art lover, I thought I'd make him some ASCII cake! Sadly, I keep forgetting his current age, so I would like to have a program for my ASCII oven, that bakes a cake with a specified number of candles, so I don't have to do it myself again if I am wron...
The task In this challenge, your task is to write a program in a programming language L that takes a positive integer n, and outputs the sum of the proper divisors of n (sequence A001065 on OEIS). It should return the correct output for any 1 ≤ n ≤ 10 000. Here are the first 10 outputs: 0, 1, 1, 3, 1, 6, 1, 7, 4, 8 Fu...
Given π to an arbitrary number of places, your challenge is to locate indices of π where the index (1,2,3,4...) and the string of numbers from that index carry the same value for the length of the index. That sounds complex, so let's look at an example! Indices will count from +1 upwards through natural whole integers,...
(Inspired by this challenge) Given two input strings, one of which is exactly one character longer than the other, arrange the strings into ASCII art as if they are two halves of a zipper that is only halfway zippered. The longer word forms the bottom of the zipper, and is the first and last character of the combined z...
Given a PPCG User ID, output that user's current username. Examples Input -> Output 61563 -> MD XF 2 -> Geoff Dalgas 12012 -> Dennis foo -> -3 -> Rules Input/output can be taken via any allowed means. The output must be the full username with proper capitalization and spacing, nothing more and nothing less...
Disclaimer: The story told within this question is entirely fictional, and invented solely for the purpose of providing an intro. I have a friend who is an architect, and, after explaining the concept of code-golf and this site to him, he said that I should code something actually useful for a change. I asked him ...
My first code golf post, apologies for any mistakes... Context In rock climbing (bouldering specifically), the V/Vermin (USA) climbing grades start at 'VB' (the easiest grade), and then go 'V0', 'V0+', 'V1', 'V2', 'V3', 'V4', 'V5' etc. up to 'V17' (the hardest grade). Task You will take as input a list/array of climbin...
A lazy physicist has the job to perform the double slit experiment. However, they are lazy and can't be bothered to set up all the equipment themselves and so are going to simulate the effects. They can't program though so are going to need some help. As they are lazy your program should be as short as possible. Given...
Simple challenge: given a series of positive integer numbers, find the number that contains among its digits the longest run of consecutive digits. The trick? It's allowed for the digits in the runs to wrap around the possible values (0123456789) and to run backwards. So both 2345, 89012 and 5432109 are valid runs of c...
Challenge Given an input integer n > 0, output the number of primes (other than n, if n itself is prime) that can be produced by altering one digit in the decimal expansion of n (without changing the number of digits). Examples For example, n = 2. By altering one digit in the decimal expansion of 2, we can come up with...
Disclaimer: The story told within this question is entirely fictional, and invented solely for the purpose of providing an intro. My boss has gotten a new toy robot, and he wants me to help program it. He wants to be able to enter simple arrow instructions to get it to move. These instructions are: ^ (for move fo...
Your task is to write some code that outputs an OEIS sequence, and contains the name of the sequence in the code (A______). Easy enough right? Well here's the catch, your code must also output a second separate sequence when the name of the sequence in the code is changed to the name of the second sequence. Input Out...
In Map inputted ASCII characters, I asked you to .. map inputted ASCII characters. This time, you will do the opposite, by immediately mapping all ASCII characters, and then mapping spaces over them. This program will have practical uses, such as seeing what characters you have left in a restricted-source challenge sub...
Challenge inspiration was this that I saw somewhere: The word "nun" is just the letter n doing a cartwheel Your challenge is to take a string and determine if it is the first letter doing a cartwheel. Rules A string is a letter doing a cartwheel if: The first letter is the same as the last letter. (The letter can't ...
Oh no, I am lost on the way to finding the great treasures of Marakov! And all I have are these useless instructions that look like S10R10D30... I have no idea what they mean! Can you help me? Challenge Given directions consisting of N E S W U D L R 1 2 3 4 5 6 7 8 9 0, output how far I will be from where I started whe...
Super Mario Galaxy features two rhombicuboctahedron-shaped* planets tiled with platforms that shrink as Mario runs across. Should Mario fall into a triangular hole or a gap left by a tile he previously touched, he will be consumed by the black hole at the core. (Watch: Hurry-Scurry Galaxy, Sea Slide Galaxy) Image: Mar...
In mathematics, the factorial, shortened "fact" of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 5! is 1 * 2 * 3 * 4 * 5 = 120 The factorial of 0 is 1, according to the convention for an empty product. These are the regular facts we are used to. ...
In this challenge, we render Ascii user interfaces. +----------------------+ |+-----------++-------+| ||<- Previous||Next ->|| |+-----------++-------+| |== The title == | | | |Lorem ipsum dolor | |sit amet... | |+--------------+ | ||Post a comment| | |+--------------+ ...
My boss now wants me to implement a mechanism that lets him search for an item in an array, and gives him the index/indices where that value occurs. Your Task: Write a program or function that receives an array and a value (String, Integer, Float, or Boolean), and returns the indices of the array at which the value o...
This is a cops-and-robbers challenge, the robbers thread can be found here. Your task is to write some code that outputs an OEIS sequence, and contains the name of the sequence in the code (A______) and outputs a second separate sequence when the name of the sequence in the code is changed to the name of the second s...
This is a cops-and-robbers challenge, the cops thread can be found here. This is the robbers thread, your job here is to take submissions on the cops thread and try to find the hidden sequences. If you find any sequence that can be substituted into the original code to compute that sequence that is a valid crack. P...
The Sequence Everyone knows the only even prime number is 2. Ho-hum. But, there are certain even numbers n where, when concatenated with n-1, they become a prime number. For starters, 1 isn't in the list, because 10 isn't prime. Similarly with 2 (21), and 3 (32). However, 4 works because 43 is prime, so it's the first ...
A prime gap is the difference between two consecutive primes. More specifically, if p and q are primes with p <q and p+1, p+2, ..., _q_−1 are not primes, the primes p and q define a gap of n = q_−_p. The gap is said to be started by p, and to have length n. It is known that arbitrarily large prime gaps exist. That is, ...
The period of a string is the shortest non-zero shift so that the string matches itself, ignoring any parts that overhang. So for example, abcabcab has period 3. By convention we say that if there is no such shift then a string has period equal to its length. So the period of abcde is 5 and the period of a is 1. In m...
Imagine you have two lights. These lights blink on and off at a specific rate: Light 0: Delay 0ms and then blink every 1000ms Light 1: Delay 500ms and then blink every 1000ms Let's simulate these lights for the first 2000ms: 0ms: Light 0 on 500ms: Light 1 on 1000ms: Light 0 off 1500ms: Light 1 off 2000ms: Light 0 ...
Inspired by this question. Champernowne's constant is an infinite decimal number that consists of "0." followed by all natural numbers concatenated together. It begins like so: 0.123456781011121314151617181920212223242526272829303132333435363738394041424344454647484950, etc. The digits of Chamernowne's constant are se...
My little kid has a toy like this: This toy consists of 10 stackable little buckets, that we are going to number from 1 (the smallest one) to 10 (the biggest one). Sometimes he makes small piles and the toy ends up like this: We can represent schematically the piles like this: 1 6 4 9 2 7 5 10 3 8 -------...
A superior highly composite number is an integer where the ratio of its count of divisors to some power of the number is as high as possible. Expressing this as a formula: Let d(n) be the number of divisors of n, including the number itself. For a given integer n, if there exists a number e such that d(n)/n^e is greate...
Given a polynomial function f (e.g. as a list p of real coefficients in ascending or descending order), a non-negative integer n, and a real value x, return:    f n(x) i.e. the value of f (f (f (…f (x)…))) for n applications of f on x. Use reasonable precision and rounding. Solutions that take f as a list of coefficien...
(This challenge is very similar, but this current challenge has additional complications.) Imagine a 2-dimensional room, where the walls are plated with flat mirrors. Suddenly, a beam of light strikes into the room, where a piece of wall is missing! The lightbeam dances around the room, getting reflected by the wall...
I have a bunch of boards I need to stack in as small a space as possible. Unfortunately, the boards fall over if I stack them more than 10 high. I need a program to tell me how to stack the boards to take as little horizontal space as possible, without stacking boards more than ten high, or having boards hanging out ...
As described in this question: Dropsort, designed by David Morgan-Mar, is an example of a linear-time "sorting algorithm" that produces a list that is, in fact, sorted, but contains only some of the original elements. Any element that is not at least as large as the maximum of the elements preceding it is simply remov...
The Dottie number is the fixed point of the cosine function, or the solution to the equation cos(x)=x.1 Your task will be to make code that approximates this constant. Your code should represent a function that takes an integer as input and outputs a real number. The limit of your function as the input grows should b...
Task You're in charge of making a compass, of sorts. Imagine your source code as the compass "needle" where running at different orientations produces distinct output. Supported source code orientations are North, East, South, and West. Example Let's say you have source code: ABCD J K WXYZ We'll consider this the Nor...
Challenge: In the language of your choice, write a program that generates a leaderboard with random scores and outputs it, then take a new score as input and check if it can be placed in the leaderboard, and output which place it is in. Specifications: You must generate a list of 50 "random" scores, in descending orde...
We are used to the term "squaring" n to mean calculating n2. We are also used to the term "cubing" n to mean n3. That being said, why couldn't we also triangle a number? How to triangle a number? First off, let's pick a number, 53716. Position it in a parallelogram, whose side length equals the number of digits of the...
Background When you run tail -f file in bash, the file is outputted and then any subsequent appends. However, when you remove something that has already been displayed, tail outputs: tail: nameoffile: file truncated Your Challenge When given an input f, append tail: [value of f]: file truncated (with trailing & leadin...
One of my favorite mathematical pastimes is to draw a rectangular grid, then to find all of the rectangles that are visible in that grid. Here, take this question, and venture for yourself! Can you count the number of rectangles? +-----+-----+-----+-----+ | | | | | | | | | | +-----+----...
This is the cops' thread. The robbers' thread is here. Your challenge is to write a program or function that, with a certain input, prints the exact string Hello, World! and a newline. Capitalization, spacing and punctuation must be exact. Input may be taken via standard input, a file, or command-line/function argument...
This is the robbers' thread. The cops' thread is here. Your challenge is to take an uncracked submission from the cops' thread and find, for what input or inputs, the program will print Hello, World! and a newline. Capitalization, spacing, and punctuation must be exact. Please comment on the cop's submission when you'v...
Your task is to take a positive number as input, n, and output the length of the longest rep-digit representation of n in any base. For example 7 can be represented as any of the following 111_2 21_3 13_4 12_5 11_6 10_7 7_8 The rep-digits are 111_2 and 11_6, 111_2 is longer so our answer is 3. This is a code-golf ques...
September 1993 is known on Usenet as the September that never ended. Thus, for example, the day this question is being posted is Saturday, September 8740, 1993. Your program or function should take any Gregorian date (with positive year) as input and return the same date as output if it's prior to September 1993 or the...
In the beginning there was NCSA Mosaic, and Mosaic called itself NCSA_Mosaic/2.0 (Windows 3.1), and Mosaic displayed pictures along with text, and there was much rejoicing. 15 years later... And then Google built Chrome, and Chrome used Webkit, and it was like Safari, and wanted pages built for Safari, and so preten...
Note: This challenge has been moved to Polyglot the (non constant) OEIS! to avoid closure. Introduction We all know and love the on-line encyclopedia of integer sequences (OEIS). So what if we made an off-line version? Well, that would be kinda too easy, wouldn't it and how would you select a sequence with our standa...
Given a positive integer n > 1 determine how many numbers can be made by adding integers greater than 1 whose product is n. For example if n = 24 we can express n as a product in the following ways 24 = 24 -> 24 = 24 24 = 12 * 2 -> 12 + 2 = 14 24 = 6 * 2 * 2 -> 6 + 2 + 2 ...
Have you ever found a good challenge to answer, answered it and then found out somebody posted a solution with a better score in the same language? Challenge Write a program/function that takes a PPCG question ID and outputs a leaderboard. A leaderboard consists of the rank, the language, the score, the author and the ...
Reading a book is easy, but printing a book can be a bit tricky. When printing a booklet, the printer needs to have the pages arranged in a certain manner in order to be read from left to right. The way this is done is using a pattern like below n, 1, 2, n-1, n-2, 3, 4, n-3, n-4, 5, 6, n-5, n-6, 7, 8, n-7, n-8, 9, 10,...
Challenge Given the name of a PPCG member, output their PPCG ID number. If the user does not exist, you may report an error or return any non-positive number. If there are multiple members with this name, you may choose to output only one ID or all of them. Test Cases "musicman523" -> 69054 "Dennis" -> 12012 "xnor" ->...
You are the best and most famous hero of the area. Lately there have been rumors that a Hydra has been hanging out in a nearby ravine. Being the brave and virtuous hero that you are you figure you'll go check it out sometime later today. The problem with hydrae is that every time you try to cut off their heads some ne...
Task The prepend,append-Sequence is defined recursively, like this a(1) = 1 a(n) = a(n-1).n , if n is even a(n) = n.a(n-1) , if n is odd where the . represents an integer concatenation. So the first few terms are: 1,12,312,3124,53124,531246,7531246,... This is A053064. Your task is, given an integer a > 0 to return...
Background A Ruth-Aaron pair is a pair of consecutive positive integers n and n+1 such that the sum of the prime factors (counting repeated prime factors) of each integer are equal. For example, (714,715) is a Ruth-Aaron pair, since 714=2*3*7*17, 715=5*11*13, and 2+3+7+17=5+11+13=29. The name Ruth-Aaron pair was chosen...
Surprisingly, I don't think we have a code-golf question for determining if a number is semiprime. A semiprime is a natural number that is the product of two (not necessarily distinct) prime numbers. Simple enough, but a remarkably important concept. Given a positive integer, determine if it is a semiprime. Your ou...
Some two-dimensional esolangs, such as Forked, and some non-esolangs, such as Python, can sometimes require spaces before lines of code. This isn't very golfy. Also, I'm lazy and writing a 2d lang that needs lots of spaces before code. Your task is to write a tool that makes these languages golfier. Of course, this wil...
Disclaimer: The story told within this question is entirely fictional, and invented solely for the purpose of providing an intro. I am an evil farmer, and to drive up the price of wheat in my area, I've decided to burn the fields of all the farmers around me. I would really like to see the fields go up in flames (...
Oh no! There are a bunch of meteoroids on my way through the universe ... what am I and my space ship, the SP4C3, supposed to do? I need to manoeuver my shuttle through these rocks or I am done for! Your Task Write a program that guides my shuttle through a map of asteroids, using as few bytes as possible since I don't...
Background It can be shown that for any integer k >= 0, f(k) = tan(atan(0) + atan(1) + atan(2) + ... + atan(k)) is a rational number. Goal Write a complete program or function which when given k >= 0, outputs f(k) as a single reduced fraction (the numerator and denominator are coprime). Test cases The first few values ...
Inspired by this. Background The evil farmer has decided to burn your wheat field down in order to drive up the prices. To ensure total destruction, he has also soaked your field in gasoline. Even more unfortunately, you happened to be walking on the field when it was lit on fire, and you must get out quickly to surviv...
Inspired by this and this which was inspired by the first question. I've set my farmers' fields on fire, but unfortunately they saw me do it! If I don't deal with this situation they could report me and then I'd get arrested! So, that shouldn't be too hard. All I have to do is kill them with fire! The field will be an ...
The Levenshtein edit distance between two strings is the minimum possible number of insertions, deletions, or substitutions to convert one word into another word. In this case, each insertion, deletion and substitution has a cost of 1. For example, the distance between roll and rolling is 3, because deletions cost 1, ...
In this question I defined a "chain" function as a function that: is a permutation, meaning that every value maps to and is mapped to by exactly one value. and allows any value can be obtained from any other value by repeated applications of the function or its inverse. There are a lot of functions that do this and s...
Inspired by this, this and this. So, now that the evil farmer has set your field on fire, you naturally want to put it out. You have a bunch of friends who all have buckets, and you want a program to figure out where to place everyone to save as much of your wheat as possible. Your Task: Write a program or functio...
Cubically is a fairly new esoteric language capable of creating short, golf-like answers for a very specific subset of problems. It is unique in that it stores memory in the form of a 3x3 Rubik's cube, making calculations far less trivial than in most languages. In Cubically, the programmer must rotate the internal cub...