instruction stringlengths 34 53.1k |
|---|
Taken from this question at Stack Overflow. Thanks also to @miles and @Dada for suggesting test inputs that address some corner cases.
The challenge
Given an array of integer values, remove all zeros that are not flanked by some nonzero value.
Equivalently, an entry should be kept either if it's a nonzero or if it's a ... |
Write a program or function that given two integers a, b outputs a string containing a decimal number representing the fraction a/b exactly.
If a/b is integer, simply output the value, without a decimal dot or leading zeroes:
123562375921304812375087183597 / 2777 -> 44494913907563850333124661
81 / 3 -> 27
-6 / 2 -> -3
... |
What general tips do you have for golfing in Common Lisp? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Common Lisp (e.g. "remove comments" is not an answer).
Please post one tip per answer.
|
Of course, the SE network is very knowledgeable about how to be respectful in the restroom, but for those of you who need a recap, being respectful means flushing the toilet, etc. Most importantly, though, it means using the stall as far away from others as possible.
The challenge
Given a blueprint of a set of stalls ... |
Given an input number n from 1 to 26 (or 0 to 25), output the alphabet reading left-to-right up to and including that corresponding letter, with a=1, b=2, c=3, .... The twist is the letters must also be repeated vertically corresponding to their position in the alphabet. Odd numbers (when 1-indexed) should be balanced ... |
Y'know, we've had a lot of "alphabet" challenges recently. (one two three four five.) While I love a good challenge, and those challenges were very fun, I think it's time for a change of pace. We need to exclude such challenges in the future. It's time for automation!
You're going to find some alphabets for me, and for... |
You are to print this exact text:
ABABABABABABABABABABABABAB
BCBCBCBCBCBCBCBCBCBCBCBCBC
CDCDCDCDCDCDCDCDCDCDCDCDCD
DEDEDEDEDEDEDEDEDEDEDEDEDE
EFEFEFEFEFEFEFEFEFEFEFEFEF
FGFGFGFGFGFGFGFGFGFGFGFGFG
GHGHGHGHGHGHGHGHGHGHGHGHGH
HIHIHIHIHIHIHIHIHIHIHIHIHI
IJIJIJIJIJIJIJIJIJIJIJIJIJ
JKJKJKJKJKJKJKJKJKJKJKJKJK
KLKLKLKLKLKLKLKL... |
For all you American folk out there, remove the "s" in "maths".
Ugh, my maths teacher gave me so much algebra to do. There's just lines and lines of meaningless junk like Expand (x+1)(x+6) and Factorise x^2+2x+1.
My hands are literally dying from the inside.
So I figured out a way to hack the system - why not write a p... |
Challenge description
Multiplification (totally not a made-up word) is a process in which you take two positive integers: a and b, and produce another integer which is equal to a repeated ("glued together") b times. For example, multiplifying 3 by 7 gives 3333333. Similarly, 103 multiplified by 5 is 103103103103103.
In... |
There are so many different ways to express whether something is true or not! The goal of this challenge is to produce a standardized output of truthy or falsy for various input truthy and falsy values.
For the purposes of this challenge, the following inputs are considered truthy:
A string representing a signed integ... |
The goal of this challenge is to reduce a list of string to a shorter more general list of string.
Input
The Input is provided with space between the string (a b c) or in list form (["a","b", "c"]). It's a list list of string that can be of the following form :
aaa
aaaX
aaaX/Y
With aaa any set of non capital alphabet... |
We see a lot of challenges here asking for a function to create a sequence from the OEIS. While these challenges are fun, as a programmer I see an opportunity for automation.
Your challenge is to make a program that takes the index of a sequence (e.g. A172141) and some integer n (e.g. 7), and pulls the appropriate val... |
Every year, Dyalog Ltd. holds a student competition. The challenge there is to write good APL code. However, this is a multiple-holes (common theme is manipulation of data of any type and structure, especially special handling of empty data) code-golf version of the Phase I problems – open to any language. Enjoy!
Objec... |
Intro
The challenge is to create a program/function that prints the intersection of its own source code and a given string input. This is code golf and to be more precise:
Let I be the input set
{"a","b","c"}
Let S be the source code set
{"b","f"}
Then the intersection is what they share
I ∩ S = {"b"}
Inpu... |
For this challenge, you will be writing a program or function which outputs (or prints) (in a reasonable format, i.e single string or an array of lines) a chess board which indicates all the possible moves of a piece given an empty board.
There are 5 chess pieces (for this challenge a pawn may be ignored):
Bishop (Mo... |
Write a program or function that takes in a nonempty single-line string. You may assume it only contains printable ASCII excluding space.
Print or return an ASCII art lozenge shape similar to a lemon or lime made from the prefixes of the string.
Suppose the input string is n letters long. Then, such a shape consists of... |
A Proth number, named after François Proth, is a number that can be expressed as
$$N = k \times 2^n + 1$$
Where \$k\$ is an odd positive integer and \$n\$ is a positive integer such that \$2^n > k\$. Let's use a more concrete example. Take 3. 3 is a Proth number because it can be written as
$$ 3 = (1 \times 2^1) + 1 $$... |
Write a function or program that takes string inputs, fully-spelled, English month names in title case: January, February, March, etc. (null/CR/LF terminated OK, delimited with some non-alpha character if you so choose) and either
compares two inputs, returning a Truthy value if the second input is greater (in month o... |
Write a program or a function in your favorite programming language that will take as input a number n (integer or non-integer) between 0 and 100 inclusive, and output the corresponding grade as outlined below:
If 0 < n <= 40, then output E.
If 40 < n <= 55, then output D.
If 55 < n <= 65, then output C.
If 65 < n <= ... |
Introduction
Inspired by Dyalog Ltd.'s 2016 student competition. The challenge there is to write good APL code, but this is a code-golf and it is open to all languages. Derived from this closed challenge.
The real challenge here is to combine the various (quite trivial) parts of the problem in a byte-efficient way by r... |
The Challenge
Output a list of years that starts with the current year and ends 120 years ago. The birth year of every living human would be included in this list.
Details
The list should be in descending order.
Every built-in function to manipulate arrays and/or lists is allowed.
Shortest code in bytes wins.
When run ... |
Sometimes when I'm typing out an IPv4 address, I get all the numbers right, but I forget to type one or more periods. I'd like to have a program (or function) that takes my broken IPv4 address and outputs all possible valid placements of the missing periods.
Input
The input will always be a string that is a transformat... |
You want to make a string where the (1-indexed) character at index n is n. When n is less than 10, this is easy: "123456789". When n is 12, for example, it becomes impossible, since numbers greater than 9 (in base 10) take up more than one character. We can compromise by dividing the string into two-character substring... |
About the Series
This is a guest entry for the Random Golf of the Day series.
First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You can find the leaderboard along with some more information abo... |
There's quite a lot of work that's been done in the world of chess. For example, there is a standardized file format, .pgn, that describes a chess game, including the list of moves. Additionally, there's another file format .fen, that describes a board position. The challenge today is to convert a list of chess move... |
Last week, we worked to create the shortest 1-D string using the top 10,000 words in the English language. Now, lets try the same challenge in 2D!
What you need to do is to take all of the above words, and put them in a rectangle as small as possible, allowing for overlaps. For example, if your words were ["ape","pen... |
This is the first part of a three part challenge. The next parts will be released on August 13 and 14.
This challenge series was inspired by another challenge series. You can view the original one at Random Golf of the Day #1: Shuffle an Array.
Instructions
Your goal in this code golf is to reverse a URL, but not full... |
Introduction
Sometimes, my boxes are too small to fit anything in it. I need you to make a box expander! So, what makes a box a box in this challenge.
OOOO
O O
O O
O O
OOOO
The corners of the box are always spaces. The box itself can be made out of the same character. That character can be any printable ASC... |
Today we'll look at a sequence \$a\$, related to the Collatz function \$f\$:
$$f = \begin{cases}
n/2 & \text{if } n \equiv 0 \text{ (mod }2) \\
3n+1 & \text{if } n \equiv 1 \text{ (mod }2) \\
\end{cases}$$
We call a sequence of the form \$z, f(z), f(f(z)), …\$ a Collatz sequence.
The first number in our sequence, \$a(... |
You are to write a program or function that outputs this exact text:
OPQRSTU
NQPONMV
MREDCLW
LSFABKX
KTGHIJY
JUVWXYZA
IHGFEDCB
May also be lowercase and trailing spaces and newlines are allowed.
Standard loopholes are disallowed
This is code-golf, so smallest byte count wins.
|
Integers are tedious to represent in Brain-Flak. There are 8 operators:
() Evaluates to 1, but does not push anything on any stack
[] Evaluates to an indeterminate value for the purposes of this question
{} Removes the top of the stack and evaluates to it
<> Switches to or back from the alternate st... |
The Challenge
Your challenge is to write a program that evaluates the following function:
f(x, t) = d^x / dt^x (sin t)
That is, the x-th derivative of sin t. In case you aren't familiar with calculus, here is a table of derivatives for the sine function:
...
f(-1, t) = -cos t
f(0, t) = sin t
f(1, t) = cos t
f(2, t)= -s... |
Write a program or function that takes in a nonempty single-line string. The string will either be zero or more spaces followed by one period (a particle), such as . or ., or the string will be a sequence of one or more alternating forward and back slashes (a wave) that could start with either one, such as \ o... |
Your task is to, given an image, compress it to 100000 bytes or less, while following all of the below rules:
No cheating/loopholes.
Your code must not be optimized to work best only on the test set of images, but rather produce a good output in general.
Colours that do not exist in the original input image must also ... |
Introduction
As some of you may know, URLs actually have a list of characters that do special things. For example, the / character separates parts of the URL, and the ?, &, and = characters are used to pass query parameters to the server. In fact, there is a bunch of characters with special functions: $&+,/:;=?@. When ... |
Executive summary: test whether an input sequence of integers is "admissible", meaning that it doesn't cover all residue classes for any modulus.
What is an "admissible" sequence?
Given an integer m ≥ 2, the residue classes modulo m are just the m possible arithmetic progressions of common difference m. For example, wh... |
The challenge: Write a script to print the alphabet, but you can't use any ASCII strings in your program. Unicode escape characters are allowed (if thats what you call them).
External libraries are allowed, as long as a link to the documentation is provided, and an online example if possible.
As this is code-golf, the ... |
In this challenge we'll compute an infinite minimal admissible sequence.
The sequence for this challenge starts with a(1) = 1.
We continue this sequence by finding a(n) as the smallest possible number such that a(n) > a(n-1) and for every prime p, the set {a(i) mod p : 1 ≤ i ≤ n} has at most p-1 elements.
Write a progr... |
Challenge description
A Langford string of order N is defined as follows:
The length of the string is equal to 2*N,
The string contains first N letters of the English alphabet, each letter appearing twice,
For each pair of the same letters, there are M letters between them, where M is that letter's position in the alp... |
Definition
Two integers are coprime if they share no positive common divisors other than 1.
a(1) = 1
a(2) = 2
a(n) is the smallest positive integer which is coprime to the a(n-1) and a(n-2) and has not yet appeared, for integer n >= 3.
Task
Given positive integer n, output/print a(n).
Example
a(11) = 6 because 6 i... |
Introduction
Sharp edges are, frankly, just plain dangerous so, given a PNG as input, blur the image using the method described below and blunt those damned sharp edges.
Method
To get the RGB value of each pixel, use the following three equations:
$$R = \sqrt{\frac{1.5\times\sum^n_{a=1}R^2_a}{n}}$$
$$G = \sqrt{\frac{1.... |
A ballot number, which we'll label B, is the number of ways of arranging the numbers from 1 through B(B+1)/2 into a triangle, such that each row and column is in any increasing order. The first four ballot numbers are:
a(0) = 1
a(1) = 1
a(2) = 1
a(3) = 2
a(3) is 2, which means that there are 2 ways of arranging the nu... |
For this challenge, when given a list of (x,y) points your submission needs to output a polynomial function that goes through all of them.
For example, if your points were [(0,0), (2,5)], you could return y = 2.5*x or y = x + 1/4x^2.
All points passed in will consist only of integers
Two points will never have the sam... |
Disclaimer: Levenshtein coding is completely unrelated to the Levenshtein edit distance metric.
<Insert long story about why Levenshtein codes need to be calculated here.>
The code
Levenshtein coding is a system of assigning binary codes to nonnegative integers that retains some weird property in probability which isn'... |
In arithmetic, an n-smooth number, where n is a given prime number, is mathematically defined as a positive integer that has no prime factors greater than n. For example, 42 is 7-smooth because all its prime factors are less than or equal to 7, but 44 is not 7-smooth because it also has 11 as a prime factor.
Define a p... |
Consider a grammar over the alphabet {0, 1, ?, :} defined by the production rule
s → 0 ┃ 1 ┃ 0 ? s : s ┃ 1 ? s : s
Given a string generated from s, parse it as an expression where ?: is right-associative (for example, a?B?X:Y:c?d:e?f:g means a?(B?X:Y):(c?d:(e?f:g))) and evaluate it with the following semantics:
eval(... |
A right-truncatable prime is a prime where every prefix is a prime (in base 10). A left-truncatable prime is exactly the opposite, where every postfix is a prime (primes that start with 0 aren't allowed). Both of these sequences are finite (There are only 83 Right-truncatables, while there are 4260 Left-truncatables)... |
As a programmer or computer scientist one might encounter quite a lot of trees - of course not the woody growing-in-the-wrong-direction kind, but the nice, pure mathematical kind:
*<- root (also a node)
/|\<- edge
* * *<- inner node
| / \
* * *<- leaf (also a node)
|
*
Naturally over time we all have put tog... |
Challenge
Using data from the API here, output the names of the three countries with the most Olympic gold medals at the 2016 Rio Olympic Games (i.e. the first element of the returned list).
For example, at the time of posting (18:23 UTC+1, Monday, 15th August), the USA, the UK and China have the most gold medals, so t... |
What is the shortest way to see if an input is a wordinian using any programming language?
A wordinian is a word that contains words of length 1 to the original word's length. For example,
bin
'I' is a word
'in' is a word
'bin' is a word
Or,
stage
'a' is a word
'ta' is a word (yes it is)
'age' is a word
's... |
OEIS: A167171
A dense number is a number that has exactly as many prime divisors as non-prime divisors (including 1 and itself as divisors). Equivalently, it is either a prime or a product of two distinct primes. The first 100 dense numbers are:
2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 31, 33, 34,... |
You are little speck on a Cartesian plane. Pondering your existence, you decide to roam around your plane and touch things. You notice that every coordinate pair you visit has a light switch. To entertain yourself, you decide to toggle every switch that you come across.
The Challenge: Create a program that will take an... |
Challenge
In this challenge you have to take a number as input and output the corresponding letter of the alphabet, and vice versa. (1 <=> A, 2 <=> B) etc.
1 -> A
2 -> B
...
26 -> Z
A -> 1
B -> 2
...
Z -> 26
Rules
This is code-golf, so shortest code in bytes wins.
The input will only consist of either an uppercase l... |
The purpose of this challenge is to produce an ASCII version of the cover of this great album by the rock band Pink Floyd.
The brick junctions are made of characters _ and |. Bricks have width 7 and height 2 characters, excluding junctions. So the basic unit, including the junctions, is:
_________
| |
| |
_... |
Task
Your task is to print or output all positive numbers in which every multi-digit substring in its decimal representation is also prime. If the number has at least 2 digits, this would imply that the number itself also needs to be prime.
Example
6197 is in the sequence because every multi-digit substring in 6197 is... |
Introduction
I've previously created two challenges where the idea is to reconstruct an object using as few query-type operations as possible; this will be the third.
The task
Your inputs shall be a non-empty string S over the alphabet abc and its length, and your output shall be S.
With no restrictions, this would of ... |
"Fit Numbers"
Sam has a "brilliant" idea for compression! Can you help?
Here is a rundown of Sam's compression scheme. First take in a base 10 representation of any natural number strictly smaller than 2^16, and write it as a binary string without any leading zeros.
1 -> 1
9 -> 1001
15 ->1111
13 ->1101
16 -> 10000
17... |
Randall Munroe (author of XKCD) held a survey to give names to colors. The main outcome is a list of names for the 954 most common RGB monitor colors.
For ease of programming, here is the list in plain text: http://xkcd.com/color/rgb.txt. Beware, the first line is not data, but contains the license.
Write a program or ... |
Given an integer N as input, output the Nth permutapalindromic number.
A permutapalindromic number is a strictly positive integer such that there is at least one permutation of its digits that results in a palindrome (i.e. a number that is its own reverse).
For example, 117 is a permutapalindromic number since its digi... |
Definition
Here is the process to describe a number:
For each number from 0 to 9 that is present in the number:
Write down the frequency of that digit and then the digit.
For example, for the number 10213223:
There is 1 occurrence of 0,
2 occurrences of 1,
3 occurrences of 2,
2 occurrences of 3.
Therefore, the numb... |
See also: Parsing
Introduction
You're working on a government programming team, who have been programming the speed cameras. However, the group of people who have programmed the speed calculator have taken up too much space, so you have to make the number plate recognition software as small as possible.
Challenge
Given... |
Briefing
The difficulty of a Code Golf question can be calculated as such:
$$\text{clamp} \left( \left\lceil \left( \frac v a \div 700 \right) \times 10 \right\rceil, 0, 10 \right)$$
Where \$v\$ is the number of views a question has
and \$a\$ is the number of answers a question has
and \$⌈x⌉\$ is the ceiling operator.
... |
Inspired by Input ∩ Source Code.
Task
Your task is to determine whether the input is a permutation of the source code.
Input
A string. Input is flexible; it should be able to handle the character encoding used for the source code.
Output
You may only have two possible outputs, one when the input is a permutation ... |
Some people say curiosity killed the cat. Other say it was the box and poison. The RSPCA say Erwin Schrödinger needs to lose the right to own pets.
With animal rights activists outside his house. The cat murderer scientist Schrödinger has finally come up with his greatest invention. A special, radioactive mix of unobta... |
Write a program or function that takes as input three positive integers x, y, and a and returns or outputs the maximum number of whole a✕1 rectangles that can be packed (axis-aligned) into an x✕y rectangle. Although the result will always be an integer, the program need not give the result using an integer type; in pa... |
Task
Given positive integer n, output a(n) where a is the sequence defined below:
a(n) is the smallest positive integer not yet appeared so that the sum of the first n elements in the sequence is divisible by n.
Example
a(1) is 1 because it is the smallest positive integer that has not appeared in the sequence, and 1 ... |
Given two positive integers, 'a' and 'b', output an ascii-art "box" that is a characters wide and b characters tall. For example, with '4' and '6':
****
* *
* *
* *
* *
****
Simple right? Here's the twist: The border of the box must be the characters of "a" and "b" alternating. This starts at the top left corner, ... |
Write a program or function that takes in a 4×4 text grid consisting of exactly 4 A's, 4 B's, 4 C's, and 4 D's, such as:
ACDC
BBCA
BADD
ABCD
The ABCD's may be in any arrangement but there will always be 4 of each. You can assume the input is valid. If desired you can also assume it has a trailing newline and/or that i... |
Recently, I was introduced to a puzzle game known as Solitaire Chess. I'll summarize the rules here:
The board is a 4x4 checkerboard.
All pieces are the same color (no teams) and all pieces can capture any other piece.
Every move must be a capture. No moving to empty squares.
There must be exactly one piece remaining ... |
The Stern-Brocot sequence is a Fibonnaci-like sequence which can be constructed as follows:
Initialise the sequence with s(1) = s(2) = 1
Set counter n = 1
Append s(n) + s(n+1) to the sequence
Append s(n+1) to the sequence
Increment n, return to step 3
This is equivalent to:
Amongst other properties, the Stern-Brocot... |
Frank has been working IT his whole life. Each day he responds to tickets, organizes equipment, and reports to his boss. One day, near the closing time on friday, Frank is doing his final inventory and sorting come cables in the supply closet. Suddenly, the door closes and locks from the outside! Such audacity! Frank s... |
Description
We consider a slightly simplified version of Tetris where each move consists of:
rotating the piece clockwise, 0 to 3 times
positioning the piece at a given column
fast drop
The goal is to determine the number of completed lines, given a list of such Tetris moves.
Completed rows are removed as pieces are ... |
Extended Train Swapping Problem
Part 1: Normal Train Swapping Problem
In the 1996 CCC (Canadian Computing Competition), the first Stage 2 problem was a Train Swapping Problem. You can visit the link here. Essentially, you have a bunch of numbered trains, and you want to find out how many train swaps you need to get the... |
Intro:
A Frobenius number is a number which cannot be made from numbers in a set.
For example, 43 is the Frobenius number of the set {6, 9, 20}, because you cannot get 43 from those numbers, and it is the largest number which cannot be made.
42 is not a Frobenius number of the set {6, 9, 20}, because it can be made fro... |
I find it fascinating how the letters "H" and "I" are very similar. "H" is a horizontal stroke surrounded by two vertical strokes; "I" is a vertical stroke surrounded by two horizontal strokes (depending on your font). I bet this could be nested... You know what that reminds me of? Fractals!!!
Let's define the "IHIH" p... |
Implement this key cipher
Goal
Use the algorithm (explained in the Algorithm section) to implement a certain cipher.
The program must read input from STDIN or the closest available equivalent, use the algorithm to generate the ciphertext and a key.
The ciphertext and the key will be written to STDOUT or the closest ava... |
See Also: Recognition
Introduction
You've now been taken off the speed camera development team (let's face it, your code is nowhere near production code standards) and are now working on a program to extract information about the car from the number plates. Of course, you've caught the code golf bug and want to write t... |
In the following markup without changing it or using JS, implement the behavior to show only the ul element of div which name is clicked in the first ul (before div). Name is content of li in top ul and it matches the content of the first li in ul you want to show. Elements that have {content} are just fillers and have... |
Your task is to display the letter "A" alone, without anything else, except any form of trailing newlines if you cannot avoid them, doing so in a program and/or snippet. Code that returns (instead of printing) is allowed.
Both the lowercase and uppercase versions of the letter "A" are acceptable (that is, unicode U+006... |
Your task is to take an input, for example:
a,b,4,5
And produce an output, which per this example is aaaabbbbb
a,b,4,5 means: the lowercase character "a" is repeated 4 times, and is then followed by the lowercase character "b" repeated 5 times, making the total number of characters 4+5=9
Another example: the input a,B,... |
Olympic vine-swingers perform their routines in standard trees. In particular, Standard Tree n has vertices for 0 up through n-1 and edges linking each nonzero vertex a to the vertex n % a below it. So, for example, Standard Tree 5 looks like this:
3
|
2 4
\ /
1
|
0
because the remainder when 5 is divided b... |
Introduction
It's 2600 BC and people are building pyramids now. They already made the basis of the pyramid but don't know how to continue. So, they called you for help.
The rules of making a pyramid is quite simple. For the layer above the previous layer, all you need to do is follow this step-by-step hand guide:
Cut ... |
Slimes are cube shaped enemies in Minecraft that break into multiple smaller versions of themselves when killed. For the purposes of this challenge we'll depict them as an 8×8 pixel image with 3 colors:
← True 8×8 version.
The precise RGB colors are:
0, 0, 0 for the eyes and mouth
110, 170, 90 for the central, darke... |
Challenge
Write a program which, using the XML data from the site here, display the name of the programme which is currently showing on BBC 1.
Information
All times are given at London time (GMT+1 at the time of posting and GMT+0 after the 30th October). Therefore, you should convert your local time to London time.
Eac... |
Task
Your task is to print this exact text:
A
BCD
EFGHI
JKLMNOP
QRSTUVWXY
ZABCDEFGHIJ
KLMNOPQRSTUVW
XYZABCDEFGHIJKL
MNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLM
NOPQRSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMNOPQRSTUV
WXYZ... |
Since this SE community is about golfing, I thought a golf-related challenge would be appropriate.
Explanation
Normally, the objective of golf is to finish a hole (and consequently, the entire round) with the least amount of strokes. This is a simple version of golf: Play until you hole the ball and sum up your score. ... |
I made my own sequence recently (called the Piggyback sequence), and it works like this:
P(1), P(2) and P(3) = 1.
For all P(n) where n>3, the sequence works like this:
P(n) = P(n-3) + P(n-2)/P(n-1)
So, continuing the sequence:
P(4) = 1 + 1/1 = 2
P(5) = 1 + 1/2 = 3/2
= 1.5
P(6) = 1 + 2/(3/2) = 7/3
= 2.33333...
P(7) = 2... |
In a programming language of your choice, write 95 programs, each of which outputs a different one of the 95 printable ASCII characters without that character occurring anywhere in the program.
For example, if your language was Python, your program that outputs the character P might be
print(chr(80))
because P has ASC... |
I'm new to ES6 and code-golfing. Here's the original function:
function puzzle(n, x) {
return n * Math.pow(2, x);
}
And here's what I have so far:
let puzzle=(n,x)=>n*2<<(x-1)
But the solution requires lesser characters. I went through the 'Code Golfing with ES6' thread, but couldn't find a better way.
Any he... |
Task
Given integers x and y which are both at least 2, find the smallest positive number whose y-th power is divisible by x.
Example
Given x=96 and y=2, the output should be 24 since 24 is the smallest positive n satisfying n^2 is divisible by 96.
Testcases
x y output
26 2 26
96 2 24
32 3 4
64 9 2
27 3 3
Scoring
This... |
In races in which racers go around at least one turn of a curved track, the starting positions for each racer are staggered, so that each racer travels the same distance around the track (otherwise, the racer in the innermost lane would have a huge advantage).
Given the lengths of the major and minor axes (or semi-majo... |
Enterprise Quality Code!
TL;DR
Answers will consist of a full program (of length < 30k) prints the the first N Prime numbers (as a base 10 representation without leading zeros unless the chosen language only supports unary or other based output) separated by newlines (optional trailing linefeed).
You may post cracks ... |
For my CS class, my instructor has given us the assignment of creating a rectangle made of asterisks with diagonal lines drawn through it in Java.
He also told us to write it in as few bytes as possible. I've gotten it down to 190 bytes, but I need to find a few to simplify this code even more to decrease bytes. Can an... |
Introduction
Dice 10,000 is a dice game which can be played with 6 dice and something to write. Players roll the dice multiple times a turn and gain a score at the end of it. The player who reaches 10,000 point first wins the game. Calculating the score of one roll is your job in this challenge.
Look here for the full ... |
In Golfenhagen, The people are allowed, and encouraged, to melt down old coins for scrap metal, if the smelter can make a profit off of it. There are 5 coins that make the Golfenhagen mint. The half-penny(0.5)(H), the penny(1)(P), the tea (5)(T), the flag (10)(F), and the driver (25)(D). Golfenhagen also mints bills, i... |
Lets say you saw your friend enter his or her password into their Android phone. You don't remember how they made the pattern but you remember what the pattern looks like. Being the concerned friend that you are you want to know how secure their password is. Your job is to calculate all the ways that a particular pa... |
Here's a nice easy challenge:
Given a string that represents a number in an unknown base, determine the lowest possible base that number might be in. The string will only contain 0-9, a-z. If you like, you may choose to take uppercase letters instead of lowercase, but please specify this. You must output this lowest p... |
Working with old files from DOS, I found an ancient text animation format, that specify how much time each frame must be shown in the screen. It's very simple:
F1W5F2W3
This example above indicates that Frame 1 must be shown for 5 units of time, and frame 2 for 3 units more. Now I want to convert it to:
1, 1, 1, 1, ... |
Challenge
Your program will take in a string from stdin, and output multiple lines to stdout.
An example of input looks like this:
My favorite Chipotle order:
B1113YNNY
Let's break it down:
The first character is either A (burrito), or B (burrito bowl).
The second character is 1 (black beans), or 2 (pinto beans). ... |
You have been assigned the task of installing new locks to the company's building. However, the locks you use are quite unusual: they require some combination of keys to open. Now, you want to figure out which locks are the most secure, so you can prioritize the most important locations.
The keys you use are numbered b... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.