instruction stringlengths 34 53.1k |
|---|
Take an input list L containing positive integers, and insert the least amount of integers into the sequence, so that you make it a continuous one.
Example:
L = 4 2 6 1
Out: 4 3 2 3 4 5 6 5 4 3 2 1
The input and output formats are optional.
Test cases:
L = 1
Out: 1
L = 10 4
Out: 10 9 8 7 6 5 4
L = 13 13
Out: 13 13
... |
Take two positive integers N and M and create the concatenated cumulative sums of [N], with M iterations. Output the result of the last iteration.
Definition of the concatenated cumulative sum:
Start with a number N and define a sequence X = [N]
Append to X the cumulative sums of X
Repeat step 2 M times.
The cumulati... |
Given two positive integers p and q, your task is to return the array A created by applying the following algorithm:
Start with A = [p, q] and d = 2
For each pair (x, y) of contiguous numbers in A whose sum is divisible by d, insert (x + y) / d between x and y.
If at least one matching pair was found, increment d and ... |
The problem #6 of IMO 2009 reads:
Let a 1, a 2, a 3, ..., a n, be distinct positive integers and let T be a set of n-1positive integers not containing a 1+a 2+a 3+...+a n, A grasshopper is to jump along the real axis, starting at the point 0 and making n jumps to the right with lengths a 1, a 2, a 3, ..., a n in so... |
Your task: write a program/function that when given a string containing only ASCII characters, outputs/returns the string in reverse-ish.
Example:
1) Input
Hello, World!
2) Number unique characters in input. (Input string separated by pipes (|) for readability)
H|e|l|l|o|,| |W|o|r|l|d|!
1 2 3 4 5 6 7 8 9 10
3) ... |
Introduction / Background
In a recent discussion in the crypto chat I was challenged to discuss / help with the Fermat primality test and Carmichael numbers. This test is based on the premise that a^(p-1) mod p==1 will always hold for primes p, but not always for composites. Now a carmichael number is essentially the F... |
Note: this challenge has been posted on the sandbox.
Introduction
This challenge is inspired by 2009 Putnam B1, a problem in an undergraduate mathematics competition. The problem is as follows:
Show that every positive rational number can be written as a quotient of products of factorials of (not necessarily distinct... |
For the purpose of this challenge, a Prime Power of a Prime (PPP) is defined as a number that can be defined as a prime number to the power of a prime number. For example, 9 is a PPP because it can be represented as 3^2. 81 on the other hand is not a PPP because it can only be represented as 3^4, and 4 is not prime. ... |
This is part of a cops-and-robbers challenge. Go here for the robbers' part.
The Cops' Challenge
You should write a program or function in a language of your choice, which outputs the string Haystack. However, it must be possible to remove some subset of characters from your program (without reordering the rest), such ... |
This is part of a cops-and-robbers challenge. Go here for the cops' part.
The Robbers' Challenge
A cop's answer can be cracked by removing any subset of characters from the Haystack program, so that it outputs Needle instead of Haystack (while still being a valid submission in the same language). You don't have to find... |
One way to represent a natural number is by multiplying exponents of prime numbers. For example, 6 can be represented by 2^1*3^1, and 50 can be represented by 2^1*5^2 (where ^ indicates exponention). The number of primes in this representation can help determine whether it is shorter to use this method of representat... |
If Abe goes, then Beth and Diana go. If Beth goes, then Catherine goes. If Catherine goes, then Diana goes. If Diana goes, then Ezra goes. Only three people go. Who goes?
Challenge
Given a list of several pairings of people, such that in each pairing the second person goes if the first person goes, and a positive integ... |
This challenge is similar to my previous one, but has a twist that makes it significantly more difficult.
There are n people on a 2D plane. Using distances between them we're going to find their positions. You may make four assumptions:
There are at least 3 people.
The first person is at position (0, 0).
The second pe... |
The "prime ant" is an obstinate animal that navigates the integers and divides them until there are only primes left!
Initially, we have an infinite array A containing all the integers >= 2 : [2,3,4,5,6,.. ]
Let p be the position of the ant on the array. Initially, p = 0 (array is 0-indexed)
Each turn, the ant will mo... |
Unlike most languages, Python evaluates a<b<c as it would be done in mathematics, actually comparing the three numbers, as opposed to comparing the boolean a<b to c. The correct way to write this in C (and many others) would be a<b && b<c.
In this challenge, your task is to expand such comparison chains of arbitrary le... |
I saw another prime challenge coming by in PPCG, and I do love me some primes. Then I misread the introductory text, and wondered what the creative brains here had come up with.
It turns out the question posed was trivial, but I wonder if the same is true of the question I (mis)read:
\$6\$ can be represented by \$2^1\... |
For the purpose of this challenge, a smaller-base palindrome (SBP) is a number which is palindromic in a base between 1 and itself (exclusive), and is not a repdigit in the same base. For example, 5 is a SBP because it is a palindrome in base 2 (101). The first few SBPs are 5,9,10,16,17,20,21,23,25,26,27,28,29,33...
... |
There have been a lot of prime-/prime factorization-related challenges recently, so I thought it might be interesting to go the other way.
Given:
a positive integer n, and
a non-empty list of positive integers f
write a full program or a function to find the smallest integer i such that i >= n and i is a product of n... |
Consider a bridge of length B formed by tiles labeled with the digits of the positive integers concatenated. For example, if B was 41, then it would look like this:
-----------------------------------------
12345678910111213141516171819202122232425
Now imagine a train of length T crossing the bridge. The leftmost poi... |
Given an integer n, print out n * reversed(n)
reversed(n) is the number you get when you reverse the digits of n.
reverse(512) = 215
reverse(1) = 1
reverse(101) = 101
>>>>>>>>
func(5) = 5*5 = 25
func(12) = 12*21 = 252
func(11) = 11*11 = 121
func(659) = 659*956 = 630004
Shortest code wins!
Leaderboard
var QU... |
According to RollingStone, below are the 26 greatest singers of all time:
Aretha Franklin Al Green
Ray Charles Robert Plant
Elvis Presley Mick Jagger
Sam Cooke Tina Turner
John Lennon Freddie Mercury
Marvin Gaye Bob Marley
Bob Dylan Smoke... |
Alphabet Rain
The Task:
The basic premise is to print out the input string and then repeat each character vertically, based on it's (0-indexed) position in the (case-insensitive) alphabet A-Z. A is at location 0 so is not repeated, e is at position 4 so is repeated 4 times, P is at position 15 so is repeated 15 times, ... |
For the purpose of this challenge, a multi-base prime is a prime which, when written in base 10, is prime in one or more bases smaller than 10 and larger than 1 as well. All single-digit primes are trivially multi-base primes. 11 is also a multi-base prime, as 11 in binary is 3, which is prime (it is also prime in ba... |
Given a matrix, sum its values up/down or left/right to form an X, fold it up, and return the list. I describe the algorithm here:
Algorithm
Your input will be a odd-sized square matrix of integers within your language's reasonable numerical capacity.
Let's take the following matrix as an example:
1 2 3 2 1
0 3 2 3 0
4... |
Lets define a pointer sequence to be any sequence such that a(n) = a((n-1)-(a(n-1))) forall n greater than some finite number. For example if our sequence begun with
3 2 1
Our next term would be 2, because a(n-1) = 1, (n-1)-1 = 1, a(1) = 2 (this example is zero index however it does not matter what index you use the... |
Most of us are probably familiar with the concept of triangular and square numbers. However, there are also pentagonal numbers, hexagonal numbers, septagonal numbers, octagonal numbers, etc. The Nth Nagonal number is defined as the Nth number of the sequence formed with a polygon of N sides. Obviously, N >= 3, as th... |
We haven't had a string question for a while (5 days to be precise), so let's go for one.
Given a string s and a positive integer n, take every nth element of s, repeat it n times, and put it back into s.
For example, if n = 3 and s = "Hello, World!", every third character is Hl r!. You then repeat each character n tim... |
Given a nonempty finite list of integers, output a truthy value if there are exactly two equal entries and all other entries are distinct, and a falsey value otherwise.
Examples
truthy:
[1,1]
[1,2,1]
[1,6,3,4,4,7,9]
falsey:
[0]
[1,1,1]
[1,1,1,2]
[1,1,2,2]
[2,1,2,1,2]
[1,2,3,4,5]
|
Write a function or program that given a list of non negative integers, arranges them such that they form the largest possible number.
INPUT
[50, 2, 1, 9]
OUTPUT
95021
INPUT
0
OUTPUT
0
INPUT
(Interesting one)
[7, 76]
OUTPUT
776
RULES
standard loopholes apply.
Depending on your language you can use int(32) / in... |
Siteswap is a notation for juggling patterns.
The other siteswap puzzle is great and it explains siteswap in greater detail than here. This puzzle is meant to be a bit simpler! Numberphile recently interviewed Colin Wright which helped develop the notation. The part at ~16min will be useful for this challenge. Another ... |
Let's define a sequence of integer square roots. First, a(1) = 1. Then, a(n) is the smallest positive integer not seen before such that
sqrt(a(n) + sqrt(a(n-1) + sqrt(... + sqrt(a(1)))))
is an integer. Some examples:
a(2) is 3 because it's the smallest integer such that sqrt(a(2) + sqrt(a(1))) = sqrt(a(2) + 1) is int... |
Zeroless numbers are numbers that do not contain 0 as one of their decimal digits.
Given an integer K, return the Kth zeroless number. K will be non-negative if you choose 0-indexing, or positive if you choose 1-indexing instead. Note that this is OEIS A052382.
This is code golf, so the shortest code in bytes wins.
Tes... |
Many people consider RPS to be a game of chance. If both players play unpredictably, the best strategy is to play randomly. However, let's introduce a bit of predictability to it.
Each bot will have a chance to tell the other bot what it's going to play simultaneously. Then there is a pause in which each bot will know... |
Challenge
Given a string input, output the demolished version of it.
The Process
P
r Pr r
o o o
g g g
r r r rogr r
a -> a -> a -> a -> a -> -> -> -> ->
m m m m m
m m ... |
Given a string as input, print a new string with each letter pushed to the right by its respective alphabet index.
We all know that A is a slow and Z is a fast letter. This means that Z gets shifted to the right by 25 spaces, A doesn't get shifted at all and B gets shifted by 1 space.
Your program only has to handle up... |
Given two integers, which may be negative, zero, or positive, \$a\$ and \$b\$ (taken in any reasonable format, including inputting a plain complex number), convert it to \$a + bi\$ where \$i\$ is the imaginary number (square root of negative one). Then, raise it to the power of a third (positive integer) input variable... |
There are quite a few means in mathematics, such as the arithmetic mean, the geometric mean, and many others...
Definitions and Task
Note that these are the definitions for two positive integers*:
The root mean square is the square root of the sum of their squares halved ().
The arithmetic mean is their sum, halved ()... |
A subsequence is any sequence that you can get from another by deleting any amount of characters. The distinct non-empty subsequences of 100 are 0, 1, 00, 10, 100. The distinct non-empty subsequences of 1010 are 0, 1, 00, 01, 10, 11, 010, 100, 101, 110, 1010.
Write a program or function that given a positive integer n ... |
Here is the code which I want to shorten.
n=input()
while n:
s=raw_input()
x,r,g,b=(int(x) for x in s.split())
a=x/r%2
c=x/g%2
d=x/b%2
r=((a*10+c)*10)+d
if r==0:e="black"
elif r==100:e="red"
elif r==1:e="blue"
elif r==10:e="green"
elif r==101:e="magenta"
elif r==11:e="cyan"
elif r==110:e="yellow"
else:e="... |
Task:
Take a string as input and if it meets the requirements, accept the password.
Input: a string, e.g. someString, asjk23t89h, 123456789abcdef.
Output: two distinct values representing "secure" and "insecure", e.g. 0/1, true/false, secure/insecure.
Password requirements:
In order for a password to be determined as s... |
The binary-square-diagonal-sequence is constructed as follows:
Take the sequence of positive natural numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, ...
Convert each number to binary: 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, ...
Concatenate them: ... |
Former US Secretary of Defense, Donald Rumsfeld, famously popularized the phrase "known knowns." Here we're going to distill his remarks into a four-line stanza.
Specifically, output this text:
known knowns
known unknowns
unknown knowns
unknown unknowns
Capitalization doesn't matter (for example, Known unKnowns is fin... |
You will be given a 2-D array A of integers, and a length N. Your task is to find within the array the straight line (horizontal, vertical or diagonal) of N elements that yields the highest total sum, and return that sum.
Example
N = 3, A =
3 3 7 9 3
2 2 10 4 1
7 7 2 5 0
2 1 ... |
This is Hole-1 from The Autumn Tournament of APL CodeGolf. I am the original author of the problem there, and thus allowed to re-post it here.
Given a list of numbers, produce a horizontal bar chart of # characters for how many numbers fit into each of ten equal-sized groups. For example, if the data ranges from 0-100... |
Task
The letters spell out actual words, but if you replace each letter with a digit from 0–9, it also “spells” an arithmetic equation. The trick is to figure out which letter maps to each digit. All the occurrences of each letter must map to the same digit, no digit can be repeated, and no “word” can start with the di... |
A000330 - OEIS
Task
Your task is simple, generate a sequence that, given index i, the value on that position is the sum of squares from 0 upto i where i >= 0.
Example:
Input: 0
Output: 0 (0^2)
Input: 4
Output: 30 (0^2 + 1^2 + 2^2 + 3^2 + 4^2)
Input: 5
Output: 55 (0^2 + 1^2 + 2^2 + 3^2 + 4^... |
TASK
print integers n, where 12 <= n <= 123456789, and all pairs of consecutive digits in n have the same positive difference between them (e.g. 2468 but not 2469).
NO INPUT.
Output:
12
13
14
15
16
17
18
19
23
24
25
26
27
28
29
34
35
36
37
38
39
45
46
47
48
49
56
57
58
59
67
68
69
78
79
89
123
135
147
159
234
246
258
3... |
A number is in base-b simplified Goodstein form if it is written as
b + b + ... + b + c, 0 < c ≤ b
The simplified Goodstein sequence of a number starts with writing the number in base-1 simplified Goodstein form, then replacing all 1's with 2's and subtracting 1. Rewrite the result in base-2 simplified Goodstein for... |
This is Hole-3 from The Autumn Tournament of APL CodeGolf. I am the original author of the problem there, and thus allowed to re-post it here.
Given:
a number of turns (please state if no movements is 0, otherwise we'll assume it is called 1) and
a list of one or more starting positions (in any form, e.g. 0 or 1 ind... |
We all know what a quine is. An inverted quine is a non-empty program that prints the inverse of its source code without reading its source code, and consists solely of printable-ASCII characters (space through ~).
Here, “inverse of the source code” means the following: the output of your program must contain each pri... |
(no, not those ones)
The Challenge
You'll be given two inputs. The first is a positive integer n > 0, which is used to output an n x n right triangle of the numbers 1, 2, 3, ... n. This triangle starts in a corner and increases horizontally and vertically by one and diagonally by two. See examples below for clarificati... |
Definition and Rules
A golfy array is an array of integers, where each element is higher than or equal to the arithmetic mean of all the previous elements. Your task is to determine whether an array of positive integers given as input is golfy or not.
You do not need to handle the empty list.
Default loopholes apply.... |
Definition
Let's call an (infinite) integer sequence universal if it contains every finite integer sequence as a contiguous subsequence.
In other words, the integer sequence (a1, a2, …) is universal if and only if, for each finite integer sequence (b1, …, bn), there is an offset k such that (ak+1, …, ak+n) = (b1, …, bn... |
The "prime frog" is a strange animal that jumps between integers, until it arrives on 3 or 19...
Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).
For a given integer n >= 2:
Let f be the position of the frog. It is initially set to n
if f = 3 or f = 19 : the fro... |
WPA2, the actual encryption standard that secures all modern wifi networks, has been cracked... This challenge has nothing to do with the way that the WPA2 was cracked, however is is about computing the 64-digit hexadecimal key that corresponds to a given WPA-PSK pass-phrase.
A wireless network with WPA-PSK encryption ... |
This is Hole-9 from The Autumn Tournament of APL CodeGolf. I am the original author of the problem there, and thus allowed to re-post it here.
Given a simple (rectangular, non-jagged) Boolean array (of one or more dimensions) return a list of thusly shaped arrays where the first array is identical to the input and the... |
Common words should still be avoided to be used as passwords. This challenge is about coding a very simple program that munges a given password (Modify Until Not Guessed Easily).
Input
A word, which is a string written in the alphabet abcdefghijklmnopqrstuvwxyz. It does not matter if the letters are lowercase or upper... |
A person has two first names if their last name is also a common first name. You are tasked with determining which full names in a list are two first names.
John Smith
John Doe
Luke Ryan
Ryan Johnson
Jenna Jackson
Tom John
Any name that occurs in the first name column is potentially a first name. If the number of occu... |
An LTL Formula l is defined by the following grammar (where <x> describes the non-terminal symbol x):
<l> ::= <b> | F <l> | G <l> | X <l> | (<l> U <l>) | (<l> W <l>) | (<l> R <l>)
| (<l> & <l>) | (<l> \| <l>) | !<l>
<b> ::= BVar | True | False | (<i> < <i>) | (<i> <= <i>) | (<i> > <i>) | (<i> >= <i>)
... |
To celebrate the 2497th anniversary of the Greek victory at Salamis in 480 BC. Draw the lambda blazon.
The lambda blazon was the lambda painted on greek shields like so:
Puzzle: Given a positive odd integer n, produce an ascii art image of the above shield.
Specifications:
n=1:
( /\ )
n=3:
( /\ )
| / \ |
( /... |
Life-like cellular automaton are cellular automaton that are similar to Conway's Game of Life, in that they operate on a (theoretically) infinitely large square grid, where each cell has exactly 8 neighbours, and is one of 2 states, namely alive and dead.
However, these Like-like versions are different in a crucial way... |
We are searching for a sequence
Take the natural numbers
1,2,3,4,5,6,7,8,9,10,11,12,13,14...
Convert to base-2
1,10,11,100,101,110,111,1000,1001,1010,1011,1100,1101,1110...
Concatenate the above numbers
110111001011101111000100110101011110011011110...
Partition this number in Prime-Chunks
(chunks containing a prime num... |
Expand an array to all directions by duplicating the outer elements
You will be given two inputs: an array and the expansion degree
For example if I give you [[1,2,3][4,5,6][7,8,9]] and 3,
you must output:
1 1 1 1 2 3 3 3 3
1 1 1 1 2 3 3 3 3
1 1 1 1 2 3 3 3 3
1 1 1 1 2 3 3 3 3
4 4 4 4 5 6 6 6 6
7 7 7 7 8 9 9 9 9
7 ... |
Consider the array of positive integers:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ...
Then, concatenate them:
1234567891011121314151617181920212223242526...
And then split them into chunks of variable length, each length being equal to the Nth positive integer:
[1][23][456][7891][01112][131415][1617181][92021222][3... |
Given an integer n >= 2, output the largest exponent in its prime factorization. This is OEIS sequence A051903.
Example
Let n = 144. Its prime factorization is 2^4 * 3^2. The largest exponent is 4.
Test Cases
2 -> 1
3 -> 1
4 -> 2
5 -> 1
6 -> 1
7 -> 1
8 -> 3
9 -> 2
10 -> 1
11 -> 1
12 -> 2
144 -> 4
200 -> 3
500 -> 3
1024... |
Task:
Make a program that draws the following figure line by line.
Your program should wait for one-second after drawing each line(it can be longer, just has to be a noticeable difference) .
Your program can only draw line by line (you cannot jump to another point or re-draw over a line)
Given a positive integer n, pr... |
Task
Your task is to output a single integer, with one restriction: its digits must be a permutation of [1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6].
For example, you could output 653443653152432, 413265345463352, or any of the other 15-digit integers whose digits are a permutation of the list.
Rules
Your code must t... |
This is the PPCG Prime
624 digits long
77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777711111111111111111111111111111111111111111111111111111111111111111111111111111118888888811888888881118888881118888881118811111... |
Inclusion-Exclusion lets you calculate the sizes of some unions and intersections between sets knowing some of the other values. I won't explain it exactly, but your challenge is to visualize inclusion-exclusion on a Venn Diagram.
Because I'm nice, you'll be using rectangles, not circles.
You will be given a list of re... |
Introduction:
Since it's almost Halloween, I was just thinking of some random Halloween-themed challenges. Eventually I was reading through Frankenstein's wikipedia page, and came across the following text:
The creature
Part of Frankenstein's rejection of his creation is the fact that he does not give it a name, which... |
Given a, b, c the length of the three sides of a triangle, say if the triangle is right-angled (i.e. has one angle equal to 90 degrees) or not.
Input
Three positive integer values in any order
Output
Either a specific true output (true, 1, yes, ...) or a specific false output (false, 0, no, ...)
Example
5, 3, 4 ... |
Every positive integer can be expressed as the sum of at most three palindromic positive integers in any base b≥5. Cilleruelo et al., 2017
A positive integer is palindromic in a given base if its representation in that base, without leading zeros, reads the same backwards. In the following, only base b=10 will be c... |
We have objects that oscillate between two integer points, [l, r], at the speed of one unit per time unit, starting at l on t=0. You may assume l < r. For example, if an object oscillates on [3, 6], then we have:
t=0 -> 3
t=1 -> 4
t=2 -> 5
t=3 -> 6
t=4 -> 5
t=6 -> 4
t=7 -> 3
t=8 -> 4
Etc. But objects oscillate continu... |
Non-math explanation
This is an explanation that is meant to be approachable regardless of your background. It does unfortunately involve some math, but should be understandable to most people with a middle school level of understanding
A pointer sequence is any sequence such that \$a(n+1) = a(n-a(n))\$.
Lets pick apar... |
How can I shorten:
p=gets.to_i
a=gets
b=gets.to_i
If my input is an integer, followed by a string, followed by an integer?
|
Let's say you have a positive integer N. First, build a regular polygon, that has N vertices, with the distance between neighbouring vertices being 1. Then connect lines from every vertex, to every other vertex. Lastly, calculate the length of all lines summed up together.
Example
Given the input N = 6, build a hexagon... |
iOS 11 has a bug that makes the result of 1+2+3 to be 24. This is related to the animation speed, but anyway:
The task is to make 1 + 2 + 3 == 24. But only that. So you should provide a function that correctly sums most sequences but returns 24 when the arguments are 1, 2 and 3 in any order.
Example inputs:
1 2 => 3
3 ... |
related
What's assignable to what?
In this challenge you will be given two types, A and B and determine if A is assignable to B, B is assignable to A, or neither.
The Type System
(I will use t to represent any type)
Basic Types
Basic types are represented by a single capital letter, such as X. They are basically class... |
Write a non-empty program or function that when called outputs a single value, 1 or 0, and when called
multiple times, the output numbers produce the binary representation of your program's source code
(in the same code page from which your code is compiled/interpreted).
For instance, if your source code was abc (in AS... |
Given a positive integer n, output the smallest base b >= 2 where the representation of n in base b with no leading zeroes does not contain a 0. You may assume that b <= 256 for all inputs.
Test Cases
1 -> 2 (1)
2 -> 3 (2)
3 -> 2 (11)
4 -> 3 (11)
5 -> 3 (12)
6 -> 4 (12)
7 -> 2 (111)
10 -> 4 (22)
17 -> 3 (122)
20 -> 6 (... |
There's never really been a definitive ASCII-cards challenge AFAIK. So, using the following deck of ASCII cards:
.------..------..------..------..------..------..------..------..------..------..------..------..------.
|2.--. ||3.--. ||4.--. ||5.--. ||6.--. ||7.--. ||8.--. ||9.--. ||T.--. ||J.--. ||Q.--. ||K.--. ||A.--.... |
Challenge
Given a list, determine if grouping the list into runs of increasing and decreasing elements will result in a list of equal-sized lists.
In other words, "turning points" of the list are spaced out evenly.
Example
Here's an example: 0, 3, 7, 5, 2, 3, 6
0, 3, 7 increases, 7, 5, 2 decreases, and 2, 3, 6 increase... |
I've been really interested with sequences that follow the property
\$a(n+1) = a(n - a(n))\$
recently, so here's another question about these sequences. In particular we are concerned with sequences from the integers to the natural numbers.
A periodic sequence with the above property is an n-Juggler if and only if it... |
Your task today is to write a program or function that takes an array of integers, and counts the number of times, reading it left to right, that the value changes. This is easier to show with an example: [1 1 1 2 2 5 5 5 5 17 3] => [1 1 1 **2** 2 **5** 5 5 5 **17** **3**] => 4
Test case:
Input | Output
[] ... |
Inspired by this video by tecmath.
An approximation of the square root of any number x can be found by taking the integer square root s (i.e. the largest integer such that s * s ≤ x) and then calculating s + (x - s^2) / (2 * s). Let us call this approximation S(x). (Note: this is equivalent to applying one step of the ... |
The Illuminati commands you (with their mind control) to output the following string:
^
/_\
/_|_\
/_|_|_\
/_|/o\|_\
/_|_\_/_|_\
/_|_|_|_|_|_\
/_|_|_|_|_|_|_\
/_|_|_|_|_|_|_|_\
/_|_|_|_|_|_|_|_|_\
Rules:
Trailing spaces are allowed for each line.
Leading spaces in each line... |
Task
Create a program or a function that is valid in multiple programming languages, and when compiled/interpreted as a different language outputs "Hello, World!" in a different natural language.
For example, a valid solution might output Hello World! (English) when compiled and run as C, Hallo Welt! (German) when comp... |
Given a textual representation (case-insensitive full name or 3 character abbreviation) of a month return the number of days in the month.
For example, december, DEC, and dec should all return 31.
February can have either 28 or 29 days.
Assume the input is a month in one of the correct forms.
|
Your task is to make a program that measures how fast you can type the letters of the English alphabet.
The program shall only accept lowercase letters a to z in alphabetical order.
Each letter is echoed as typed on the same line (without new line or any other separators between letters).
If you type an invalid char... |
Suppose an infinite tiling of hexagons composed of |/\ characters.
/ \ / \ / \ / \
| | | | |
\ / \ / \ / \ / etc.
| | | |
\ / \ / \ /
Given input n > 0, output a triangular portion of that tiling as depicted in the below examples, anchored with a _ in the middle of a hexagon:
n=1
\_/
n=2
\/ \/
... |
Given an email address, the result of a transformation applied to that email address, and a second email address, return the output of the same transformation applied to the second email address.
The email addresses will all have the following structure:
A string of positive length containing alphanumeric characters an... |
Upon the rumor that Codegolf will have a Rock-Paper-Scissors tournament you look into the topic of square-free words. A word made of the letters R, P, S is square-free if it does not contain a sequence that repeats twice. That is to say, the word can not be written as
a x x b
where a and b are words of any length and ... |
Note: In this post, the terms 'character' and 'color' mean essentially the same thing
This image:
can be represented as
....'''333
.eeee'''3e
..dddd33ee
%%%dd####e
(mapping colors to ascii characters)
The four color theorem states that
"given any separation of a plane into contiguous regions, producing a figure cal... |
Challenge:
Inputs:
A string containing printable ASCII (excluding spaces, tabs and new-lines)
A boolean †
Output:
The parts of the String are divided into four groups:
Lowercase letters
Uppercase letters
Digits
Other
Based on the boolean, we either output the highest occurrence of one (or multiple) of these four gr... |
In this thread we use 32-bit signed integers (assuming the usual two's complement). For simplicity I shall call this type Int32. The range is from -2147483648 through 2147483647. Any two values can be successfully multiplied (the result is an Int32 as well) since we use multiplication without overflow checking (we only... |
Write the shortest code measured by byte count to generate an ASCII grid composed of rhombi, given the following parameters:
m - number of complete rhombi in one row
n - number of rows
s - side of the smallest rhombus
r - level of nesting - how many rhombi are there inside the "base ones" (which are fonud between the... |
Your challenge is to write N snippets of code such that, when you concatenate the first K ≥ 1 together, they produce the number K. The higher N, the better. Here's the catch: you may not use any character more than once across your snippets.
Rules
You may use the same character multiple times in one (and only one) sni... |
Web safe colors are in intervals of 51, they include 0, 3, 6, 9, c, and, f as digits in hex (such as #993333), or 0, 51, 102, 153, 204, 255 in decimal. Your task today is convert a given color to a web safe one. You may read more about web safe colors on Wikipedia.
Input
You will take in 3 integers between 0, 255 inclu... |
Code a program or function to construct an interactive canvas on the screen of at least 400 pixels x 400 pixels in size. The canvas can be any color you wish, bordered or borderless, with or without a title bar, etc., just some form of obvious canvas.
The user will click on two distinct areas of the canvas and the prog... |
For the purposes of this challenge, a polyphthong is defined as a contiguous slice of a String, that only contains vowels, and has length at least 2. Given a non-empty String as input, your task is to output all the polyphthongs it contains.
For example, "abeoic" has the following contiguous slices (space-separated):
a... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.