instruction
stringlengths
34
53.1k
You will take two positive integers n and x as input, and output Euler's totient function (number of positive integers less than x co-prime to x) applied n times. Testcases n x result 1 10 4 2 10 2 3 10 1 1 100 40 2 100 16 3 100 8 4 100 4 5 100 2 6 100 1
Write a program that takes in an integer from 0 to 65535 (216-1) and generates a unique 500×500 pixel image that looks as similar as possible to these 6 real life images of cracked soil: These are thumbnails, click them to see the full-size 500×500 images. The goal here is to make your computer generated images a...
Did you know that a small number can borrow bits from a larger number? Here's an example. Let's say our two numbers 5 and 14. First, write them out in binary: 5 14 000101 001110 First we take the smallest on bit away from the larger number, and we give it to the smallest off bit on the other number. So This bit...
Challenge description On a Cartesian plane, a triangle can be described as a set of three points, each point being one of the triangle's vertices. For instance, coordinates (2, 1), (6, 8), (-7, 3) correspond to the following triangle: As you can see, it does not contain the origin of the plane, i.e. the point (0, 0), ...
My friend made a lisp translator the other day, that is to say it took a string and converted s=>th and S=>Th. It was quite long and I thought that it could be golfed. So the task is to make a program/function that takes an input string, translates it in to lisp and outputs the string Test case Sam and Sally like Sheep...
Introduction A hypercube/tesseract is the 4 dimensional equivalent of a normal cube. It's made by taking a cube net, extending it to the 3rd dimension, then – using the 4th dimension – folding it into a hypercube. It's basically a cube, where each side is a cube. To create a hypercube, you need 16 4d vectors (a vector ...
The program should take a string as input and reverse the consonants in it, while keeping the order of vowels. All the letters will be lowercase, so you don't have to worry about casing. Examples follow. Input: a test case. The consonants here are t,s,t,c,s. They should come in reversed order, i.e. s,c,t,s,t and inse...
If you look at the Fibonacci Numbers, you will notice a pattern in their parity: 0, 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144. Every third number is even, and all the others are odd. This makes sense because an even plus an odd is odd, but an odd plus an odd is even and the sum for a term will always include...
Fibonacci Numbers Fibonacci Numbers start with f(1) = 1 and f(2) = 1 (some includes f(0) = 0 but this is irrelevant to this challenge. Then, for n > 2, f(n) = f(n-1) + f(n-2). The challenge Your task is to find and output the n-th positive number that can be expressed as products of Fibonacci numbers. You can choose to...
Sometimes it really is a struggle to convert Cartesian coordinates (x,y) to Polar coordinates (r,phi). While you can calculate r = sqrt(x^2+y^2) quite easily, you often need some distinction of cases when calculating the angle phi because arcsin,arccos and arctan and all other trigonometric functions have a co-domain t...
Your task is to create a polish notation calculator. For those who don't know what is polish notation, it's a mathematical notation where operators are before the operands. Eg: + 1 2 = 1 + 2 Your calculator should implement integer addition, substraction multiplication and division. Standard loopholes are forbidden but...
An Armstrong number (AKA Plus Perfect number, or narcissistic number) is a number which is equal to its sum of n-th power of the digits, where n is the number of digits of the number. For example, 153 has 3 digits, and 153 = 1^3 + 5^3 + 3^3, so 153 is an Armstrong number. For example, 8208 has 4 digits, and 8208 = 8^4 ...
You would simply take this image and make every color added one to every hexadecimal digit. For example, #49de5f would become #5aef60 (with the 9 looping to an a, and the f looping to a 0.) This would also mean that all white (#ffffff) would become black (#000000) because all f loops back to 0, but all black will beco...
This is Bub. Bub is a soccer player. However, he's not a very good one. He still can't kick the ball to the net! (If you haven't noticed, @ is the ball. _____ | \ O ...
Description Your task is to take a string as input, and convert the first letter of each word to uppercase, and the rest to lowercase. Test Cases Input => Output ISN'T THIS A REALLY COOL TEST CASE??? => Isn't This A Really Cool Test Case??? tHis iS A rEALLY WeiRd SeNTEncE => This Is A Really Weird Sentence I Like This ...
Find the difference between the square of the sums and sum of the squares. This is the mathematical representation: \$\left(\sum n\right)^2-\sum n^2\$ Your program/method should take two inputs, these are your lower and upper limits of the range, and are inclusive. Limits will be whole integers above 0. Your program/m...
The Microsoft FAT file system has a directory table to represent which "files" are in which "folders" on the disk. For the time, these entries crammed a lot of information into a small amount of bits. There are a bunch of technical specifications over on Wiki for the curious, but the challenge here is going to focus on...
Your goal is to create a function or a program to reverse the bits in a range of integers given an integer \$n\$. In other words, you want to find the bit-reversal permutation of a range of \$2^n\$ items, zero-indexed. This is also the OEIS sequence A030109. This process is often used in computing Fast Fourier Transfor...
Nice verb there, in the title. Write a program that given an input string, will "elasticize" this string and output the result. Elasticizing a string is done as follows: The first character is shown once. The second character is shown twice. The third character is shown thrice, and so on. As you can see, the amount of...
Definition Define the nth term of the CRAU sequence as follows. Begin with the singleton array A = [n]. Do the following n times: For each integer k in A, replace the entry k with k natural numbers, counting from 1 to k. Compute the sum of all integers in A. For example, if n = 3, we start with the list [3]. We repla...
Definition Define the nth array of the CURR sequence as follows. Begin with the singleton array A = [n]. For each integer k in A, replace the entry k with k natural numbers, counting up from 1 to k. Repeat the previous step n - 1 more times. For example, if n = 3, we start with the array [3]. We replace 3 with 1, 2, ...
An alternating sign matrix is an n by n matrix consisting of the numbers -1, 0, 1, such that: The sum of each row and column is 1 The nonzero entries in each row and column alternate in sign These matrices generalise permutation matrices, and the number of such matrices for a given n was of interest for some time. Th...
Your task is to create a program that adds random numbers to previous sums in the ultimate number racing showdown. Each racer (column) starts at 0 and adds either 1 or 0 to the previous sum at each step of the race until all of the racers reach the score required to win. The 1 or 0 should be chosen at random (the stand...
Chess pieces (kings, queens, rooks, bishops, and knights) and pawns are on a board, but not on the a1 or h8 square. Your task is to travel from the empty a1 to the empty h8 squares, passing through only empty squares. The rules of movement are as follows: You can proceed from any empty square to any empty square next ...
Inspired by this answer (emphasis mine): We will play a game. Suppose you have some number x. You start with x and then you can add, subtract, multiply, or divide by any integer, except zero. You can also multiply by x. You can do these things as many times as you want. If the total becomes zero, you win. For example,...
Your task is to write a self referential program similar to a quine. The objective is to write a program that will generally print to stdout twice whatever the input is. But when it receives the input of "Tell me about your source" it should output its source (like a quine). Also if it receives the query "tell me about...
Given the input of the first number and the second number (both positive integers, zero exluded), determine in how many ways could you make the second out of the first, using following actions: +1,+2 and *3. Operations are simply applied from left to right. Examples: Input: 1 2. Output: 1. I.e, you could only get 2 b...
My preferred way to approximate a derivative is the central difference, its more accurate than forward difference or backward difference, and I'm too lazy to go higher-order. But the central difference requires a data point on either side of point you are evaluating. Normally this means you end up not having a derivati...
Background Euler's totient function φ(n) is defined as the number of whole numbers less than or equal to n that are relatively prime to n, that is, the number of possible values of x in 0 < x <= n for which gcd(n, x) == 1. We've had a few totient-related challenges before, but never one which is just calculating it. Th...
For this golf, you will need to use more than one language. The task A Rube Goldberg machine is a contraption that takes an enormous number of complicated steps in order to execute a very simple task. The goal of this golf is to output Rube Goldberg... but not directly. The machine Your "machine" is the source code tha...
You have to write an interpreter for a cool language called Chicken! You should read a Chicken program from a file, standard input, program or function arguments, or whatever is most convenient for your language, as well as input to the program. You should print or return the result of interpreting the program accordi...
Update: There are 6 mazes. They are included in the controller. There is a tar.gz of the mazes and their .bmp files here (dropbox). There is also a utility for making more mazes at that link (the maze_4.txt file is incorrect in archive). At this point, please feel free to run your own entry and update your score. Detai...
Basing on this SO question. Challenge is rather simple: given a date period in the format YYYYMM output it in the format MMMYY. Rules: The input will be a number or a string exactly 6 characters long, consisting only of digits. Last two digits will be between 01 and 12. Output must be in the form MMMYY, where MMM repr...
You've got a set of tiles with the symbols from the periodic table. Each symbol appears once. You're thinking up words to make but you want to know if it's possible or not. The Challenge Write a program in your favourite language that will take in a string as an input parameter. You may assume that input is not null, h...
GOAL : To Implement a character counting program This is how this counting system works : input of the program is a set of printable ASCII characters . the program counts each type of character , and outputs the number of each character , starting from first mentioned character to last mentioned character . Example :...
Task Given a UTF-8 string (by any means) answer (by any means) an equivalent list where every element is the number of bytes used to encode the corresponding input character. Examples ! → 1 Ciao → 1 1 1 1 tʃaʊ → 1 2 1 2 Adám → 1 1 2 1 ĉaŭ → 2 1 2 (single characters) ĉaŭ → 1 2 1 1 2 (uses combining overlays) チャオ → 3 3...
Palindromic dates are dates that appear as palindromes: the string of digits can be read the same way backwards as forwards. For the North American date format (MM/DD/YYYY), the next few palindromic dates are: 02/02/2020 12/02/2021 03/02/2030 The Challenge Create a function that returns all palindromic dates in a consi...
Index sum and strip my matrix Given a matrix/2d array in your preferable language Input: The matrix will always have an odd length The matrix will always be perfectly square The matrix values can be any integer in your language (positive or negative) Example: 1 2 3 4 5 6 7 2 3 4 5 6 7 8 3 4 50 6 7 8 ...
As the title -- although discretely -- hints, I only pay with dollars. The challenge Write a function/program that takes a string as input, which is a monetary value preceded by a symbol. ex) £4.99. Then, return that same amount converted to USD. Input You will get a string as input. It will have the currency symbol f...
Introduction A while back I stumbled across the tiny encryption algorithm (TEA) and since then I have recommended it whenever special cryptographic security properties were un-needed and a self-implementation was a requirement. Now today, we want to take the name *tiny* encryption algorithm literally and your task will...
Over at our friends at Puzzling.SE, the following puzzle was posted: Is this chromatic puzzle always solvable? by Edgar G. You can play it here. Puzzle explanation Given a m x n grid with tiles of three different colours, you may select any two adjacent tiles, if their colours are different. These two tiles are then co...
Input You are given a 2D map with balls and ground in it. It looks like this: 1 5 2 3 4 __________________________ Each number is a ball, and the _ is ground level. The underscore _ character is not allowed in any other line than ground level line. There are only spaces, newl...
Challenge description Let's call a two-dimentional, rectangular array (meaning its every subarray has the same length), a grid. Every unit of a grid is either an empty space or a border. In a grid of characters, empty space is represented by a single whitespace; any other character is treated as a border. Sample grids ...
There have been some tax rate calculator problems here that depend on defined rates (specifically US federal rates), but none that have done it for arbitrary lists. Your task is to build a program or function that will take an arbitrary list of marginal tax brackets and calculate the effective amount of tax paid on a g...
Given a positive integer n, simplify the square root √n into the form a√b by extracting all square factors. The outputted a,b should be positive integers with n = a^2 * b with b as small as possible. You may output a and b in either order in any reasonable format. You may not omit outputs of 1 as implicit. The outputs...
Ninja Assassins - which ninja stays alive some basic information given an int N as the number of ninjas, return the number of the winning ninja. At the end only 1 ninja survives,the question is which one? what was his number?. Each ninja kills the ninja who stands after him. Afterwards, he passes the sword to the firs...
Challenge Write a program or function that given a string, returns a valid Brainfuck program that when compiled and executed as Brainfuck, returns that string.. Assume all inputs are encoded as ASCII. Assume the outputted BF program will execute in an environment with an infinite tape. Assume the pointer starts at c...
In the game Stratego, the main game mechanic is when you attack an opponent's piece with yours. In this challenge, you job is to simulate one of these battles and say who survives. Specs You will get as input a pair of string representing Stratego pieces. The pieces are one of "S 1 2 3 4 5 6 7 8 9 10 B" (S is the Spy, ...
Introduction We -- especially the geeks among us, who tend to be fans -- all remember this old Far Side cartoon: Clearly, Professor Schwartzman could have brushed up on his programming skills just a wee bit more before he put his invention to use. But can you replicate it yourself... using as few bytes as possible? In...
Graham's number \$G\$ is defined in this way: \begin{align*} u(3,n,1) & = 3^n \\ u(3,1,m) & = 3 \\ u(3,n,m) & = u(3,u(3,n-1,m),m-1) \end{align*} Then, \begin{align*} g_1 & = u(3,3,4) \\ g_2 & = u(3,3,g_1) \\ g_3 & = u(3,3,g_2) \\ & \vdots \\ G & = u(3,3,g_{63}) \end{align*} You are given that \$u(3,3,2)=7625597484987\$...
The esoteric programming language evil has an interesting operation on byte values which it calls "weaving". It is essentially a permutation of the eight bits of the byte (it doesn't matter which end we start counting from, as the pattern is symmetric): Bit 0 is moved to bit 2 Bit 1 is moved to bit 0 Bit 2 is moved to...
In scientific computing, it is often desirable to decompose some large domain into smaller "subdomains", then parallelize the computation by performing the work on each subdomain in parallel and the interaction of a subdomain with its neighboring subdomains. Since these interactions are typically data sync points, mini...
Everybody loves nested lists! However, sometimes it's hard to make a nested list. You have to decide if you want to nest it deeper, or if you need to nest it shallower. So for your challenge, you must "Autonest" a list. To autonest a list, compare every pair of items in the list. If the second item is smaller, separat...
Fred is a quasi-friendly guy, but in reality he is mean. Because of this, Fred lives alone in a small apartment in Los Altos, CA. Fred is so mean because he is very particular about water. He, therefore, needs your help with figuring out what his water bill is. Your job is to write a function or program that returns h...
Introduction Aron Nimzowitsch was a leading chess master and a influential chess writer. In his book 'My System', the first chapter deals about the importance of the center and why you should dominate it. The simple reason is that your pieces have more possible direct next moves when being in the center which again giv...
We already have challenges to check if a string of brackets is fully matched and to count the number of balanced strings. It remains for us to generate these strings, but it will not be so easy… A Dyck word is a string, of length 2n, consisting of n opening and n closing parentheses (( and )) fully matched (that is to ...
Your task is to create a program will transform each letter of a text typed on a AZERTY keyboard to the equivalent on a QWERTY keyboard, using the same keystrokes. Example: Hello; Zorld1 => Hello, World! List of character to convert: A <=> Q Z <=> W , => m ? => M M => : 1 => ! 9 => ( ; => , § => ? 0 => ) ) => - ù => '...
You probably know Conway's Game of Life, the famous cellular automaton invented by mathematician John Conway. Life is a set of rules that, together, allow you to simulate a two-dimensional board of cells. The rules decide which cells on the board live and which ones die. With some imagination, you could say that Life ...
Note: the first half of this challenge comes from Martin Ender's previous challenge, Visualize Bit Weaving. The esoteric programming language evil has an interesting operation on byte values which it calls "weaving". It is essentially a permutation of the eight bits of the byte (it doesn't matter which end we start cou...
When doing weightlifting, I want to make a specific weight by attaching several plates to a bar. I have the following plates: 6 plates of 1 kg each 6 plates of 2.5 kg each 6 plates of 5 kg each 6 plates of 10 kg each The bar itself weighs 10 kg. It's only allowed to attach the plates in pairs - they are attached at e...
This challenge is a simple ascii-art one. Given two inputs, describing the height and width of a Lego piece, you have print an ASCII art representation of it. Here is how the Lego pieces are supposed to look: (4, 2) ___________ | o o o o | | o o o o | ----------- (8, 2) ___________________ | o o o o o o o o | | o o ...
Given 3 bytes or RGB as input, calculate the nearest CMYK values, and output them. create either a function with parameters and return value or a program that operates on stdin/stdout use the color profile of your choice, but provide a reference input may be either separate numeric values in range [0;255] or a 6 digit...
In the classic days of Starbucks before these newfangled sticker-printers and wireless drivethrough headset palmtop scanner dealies, in the heady days of 2000-ish, Starbucks had a concise system for describing beverages with a strict syntax and accompanying encoded form. Vertically on the cup there are a series of labe...
Input: An integer Output: Sum of the input itself + the length of the input + each individual digit of the input. nr + nr-length + {sum of digits} = output Examples: Input: 99 Output: 99 (nr) + 2 (nr-length) + (9 + 9) (digits) → 119 Input: 123 Output: 123 + 3 + (1 + 2 + 3) → 132 Challenge rules: The input can also co...
In the arcade version of the game, Pac-Man eats pac-dots. However, in this challenge, he's hungry for alphanumeric characters and punctuation in a string. Your task is to create a function that feeds Pac-Man a string, evaluates if he can eat it or not, and returns the string with Pac-Man's location in it. Pac-Man (<) e...
Introduction Your mission in life is simple: Prove people wrong on the internet! To do this you usually carefully analyze their statements and point out the contradiction in them. It's time to automate this, but as we are lazy, we want to prove people wrong with the least effort (read: shortest code) possible. Specific...
Challenge description Let's take a positive integer n, reverse its digits to get rev(n) and get the absolute value of the difference of these two numbers: |n - rev(n)| (or abs(n - rev(n))). Example: n = 5067 rev(n) = 7605 |n - rev(n)| = |5067 - 7605| = |-2538| = 2538 After repeating this operation sufficiently many t...
I was browsing esolangs, and chanced upon this language: https://github.com/catseye/Quylthulg. One interesting thing about this language, is that it doesn't use prefix, postfix, or infix, it uses all three of them, calling it "panfix" notation. Here is an example. To represent normal infix 1+2 in panfix, it becomes: +1...
Your challenge is simple: GIven an integer N, ouput every list of positive integers that sums to N. For example, if the input was 5, you should output [1, 1, 1, 1, 1] [1, 1, 1, 2] [1, 1, 3] [1, 2, 2] [1, 4] [2, 3] [5] These lists do not have to be output in any particular order, nor do the numbers inside each list. Fo...
Your task is "simple" should you choose to accept it. Write an HQ9+ compiler in a language of your choice. HQ9+ has four commands (as you may be able to tell) H prints "Hello, World!" Q prints out the source code (this can either be the compiled source or HQ9+ source for the purpose of this challenge),9 prints out the...
There is a parade marching through a city! There are 3 main groups of marchers: the (B)and, Poster (C)arriers, and (F)lag Holders. Also, every (P)oliceman in the whole city is on duty. Flag holders (F) can march anywhere in the parade, but two flag holders cannot march next to each other, unless three or more flag hold...
Given the coordinates of several points on a plane, and the radius of a circle surrounding each point, draw polygons representing the circles and the edges where the circles meet. Straight edges will always fall along circle-circle intersection lines, but might not follow the full length of these lines. Per mbomb007's ...
Based on this question from Code Review Given a non-empty string of printable ASCII characters, output the second non-repeating character. For example, for input DEFD, output F. Input A single string, in any suitable format. Output The second character that doesn't repeat, when reading left-to-right, again in a suit...
You should a program in language X, which will only output its source code (i.e function as a quine) when it is not a monday. On monday it should output some string with a levehnstein distance of 4 from the source code. i.e if the code is aaaa on sunday it should output aaaa and on monday it could output ....aaaa or bb...
Input: Two integers. Preferably decimal integers, but other forms of numbers can be used. These can be given to the code in standard input, as arguments to the program or function, or as a list. Output: Their sum. Use the same format for output integers as input integers. For example, the input 5 16 would lead to the o...
Let's parse and process Key-Language! Given the input of a sequence of keyboard keypresses and/or special keys, write a program, function, etc. that outputs the product when all the actions are processed based on the following keyboard: +-------------------------------------------------------+ | ~ | ! | @ | # | $ | % |...
The C preprocessor is not turing-complete, but you can do some pretty cool stuff with it. The challenge is to make an integer adder with it. You can use any representation you like: base 2, base 10, unary, separate each digit with a comma, etc. Whatever you do, you may only use the C preprocessor. The rules are simple:...
Given a list of integers, create a boolean mask such that the true indices can be used to filter the distinct values from the list. Which index is selected as the true one does not matter as long as only one of them is selected for each set of indices corresponding to identical values. The input will be a non-empty lis...
A bag, also called a multiset, is an unordered collection. You can call it a set that allows duplicates, or a list (or an array) that is not ordered/indexed. In this challenge, you are asked to implement bag operations: addition, difference, multiplication, division, counting and equality test. Operations The specified...
There are numerous reasons for trying to obfuscate input. These include preventing decompiling, and being a nuiscance. With this in mind your challenge should your choose to accept it is to write a meta-obfuscator. Your code must in some Language X receive input as a String, and output a program in language X that out...
THE TASK DEFINITIONS Consider the points {1,2,3,4,5} and all their permutations. We can find the total number of possible permutations of these 5 points by a simple trick: Imaging filling 5 slots with these points, the first slot will have 5 possible numbers, the second 4 (as one has been used to fill the first slot) t...
Inspiration. Task Reverse runs of odd numbers in a given list of 2 to 215 non-negative integers. Examples 0 1 → 0 1 1 3 → 3 1 1 2 3 → 1 2 3 1 3 2 → 3 1 2 10 7 9 6 8 9 → 10 9 7 6 8 9 23 12 32 23 25 27 → 23 12 32 27 25 23 123 123 345 0 1 9 → 345 123 123 0 9 1
Write some code to do the following: Take as its input a signed integer in either signed decimal or signed octal (explained below) If the number is decimal convert it to octal. If it's octal, convert it to decimal Output the number! Instead of starting with a 0, negative octal numbers will start with a Z (capital zed...
Task Find a sequence of all numbers between min and max where every number differs from every other number in the sequence by at least "d" digits. Example of sub-sequence For min = 0, max = 1000 and d = 2, the following is part of one possible solution sequence: 123 ← Good 132 ← Good 145 ← Good 146 ← Bad Notes This i...
On TeX.SE the Help Centre says that the following is on topic: Formats like LaTeX, ConTeXt and plain TeX Engines like pdfTeX, LuaTeX and XeTeX Distributions like TeX Live, MiKTeX, and MacTeX Related software and tools, BibTeX, MakeIndex, Lyx, etc. I wanted you to write a program to tell me whether my TeX is in the on-...
This is a mirror: |. I just found out that you can stick a mirror in the middle of a string if the string can be mirrored on itself! For example, the string abccba. If you cut it in half the two halves are mirror images of each other: abc <--> cba So, we can stick a mirror in the middle of the string, and our new st...
Consider the following definitions taken from The number of runs in a string by W. Rytter. Note that word, string and substring are all roughly synonyms. A run in a string is a nonextendable (with the same minimal period) periodic segment in a string. A period p of a word w is any positive integer p such that w[i...
Challenge description Given a list / array of items, display all groups of consecutive repeating items. Input / output description Your input is a list / array of items (you can assume all of them are of the same type). You don't need to support every type your language has, but is has to support at least one (preferab...
Input: n Output: A list of length n, with each element being the nth happy prime. Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number either equals 1, or it loops endlessly in a cycle which does not include 1. A happy number is a number...
There are already 30 challenges dedicated to pi but not a single one asks you to find the nth decimal, so... Challenge For any integer in the range of 0 <= n <= 10000 display the nth decimal of pi. Rules Decimals are every number after 3. Your program may be a function, or a full program You must output the result in ...
Domain name trading is big business. One of the most useful tools for domain name trading is an automatic appraisal tool, so that you can easily estimate how much a given domain is worth. Unfortunately, many automatic appraisal services require a membership/subscription to use. In this challenge, you will write a si...
July 1st is Canada day (yay Canada)! Or is it? It seems that the Wikipedia page for this day has a lot of Canada related content, but is there another day which is more Canadian? Your task is to write a program or function which takes a date (month and day) as input and returns or outputs the number of mentions of "Ca...
Introduction and Credit Today without a fancy prelude: Please implement takewhile. A variation of this (on a non-trivial data structure) was an assignment at my university functional programming course. This assignment is now closed and has been discussed in class and I have my professor's permission to post it here (I...
Task: Make a program that leaves a comment on this question. The content should be 1234567890123456. Edits: You may leave your usernames and passwords as U and P if you are using username and password. (if applicable) No URL Shorteners (if applicable) You may not use the browser console.
Background Countless generations of children have wondered where they would end up if they dug a hole directly downwards. It turns out that this would, unsurprisingly, be rather dangerous, but anyway... Antipodes are points that are directly opposite each other on the Earth's surface. This means that if a line was draw...
[This question is a follow up to Compute the runs of a string ] A period p of a string w is any positive integer p such that w[i]=w[i+p] whenever both sides of this equation are defined. Let per(w) denote the size of the smallest period of w . We say that a string w is periodic iff per(w) <= |w|/2. So informa...
The goal here is to simply reverse a string, with one twist: Keep the capitalization in the same places. Example Input 1: Hello, Midnightas Example Output 1: SathginDim ,olleh Example Input 2: .Q Exmaple Output 2: q. Rules: Output to STDOUT, input from STDIN The winner will be picked 13th of July on GMT+3 12:00 (One...
Your task is to, with an input number p, find the smallest positive cannonball number of order p that is NOT 1. Definition A cannonball number (of order p) is a number which is both: An p-gonal number (See this page). and an p-gonal pyramid number. The nth p-gonal pyramid number is the sum of the 1st to nth p-gonal n...
Consider the following table for the function d(n), which calculates the number of factors that n is divisible by without a remainder: n | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ... d(n) | 1 | 2 | 2 | 3 | 2 | 4 | 2 | 4 | 3 | 4 | 2 | 6 | ... Going from left to right, it is possible to determine the "c...
A set is sum-free if no two (not necessarily distinct) elements when added together are part of the set itself. For example, {1, 5, 7} is sum-free, because all members are odd, and two odd numbers when added together are always even. On the other hand, {2, 4, 9, 13} is not sum-free, as either 2 + 2 = 4 or 4 + 9 = 13 ad...