instruction stringlengths 34 53.1k |
|---|
Assume you're writing in one method, (or whatever you call them) with 3 inputs: the first string, a character that contains a +, - or * symbol, and the second string.
Example in Java:
public String strCalc(String str1, char sym, String str2) {
//code...
}
What it should return:
str1 sym str2 ans
A + A = B
... |
To "function nest" a string, you must:
Treat the first character as a function, and the following characters as the arguments to that function. For example, if the input string was Hello, then the first step would be:
H(ello)
Then, repeat this same step for every substring. So we get:
H(ello)
H(e(llo))
H(e(l(lo)))
H(... |
What general tips do you have for golfing in Starry? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Starry (e.g. "remove comments" is not an answer).
Please post one tip per answer.
|
From Wikipedia:
The centroid of a non-self-intersecting closed polygon
defined by n vertices (x0,y0),
(x1,y1), ...,
(xn−1,yn−1) is the point (Cx,
Cy), where
and where A is the polygon's signed area,
In these formulas, the vertices are assumed to be numbered in order of
their occurrence along the polygon... |
This question wants you to golf batch programms. In Batch you can use
set x=averylongbatchcommand
%x% arg1
which expands to
set x=averylongbatchcommand
averylongbatchcommand arg1
Your task is it to expand these statements.
As you can also use set for arithmetic purposes like this:
set x = 0
set /a x= %x%+1
you sho... |
Monopoly Board
For this code-golf challenge we will be building the board game Monopoly.
Rules:
Take no input.
Output a 11x11 board where each ASCII character forming the board is the first letter of each space of the U.S. version of the Monopoly board.
The characters must be separated by spaces.
Go should start in th... |
The Eulerian number A(n, m) is the number of permutations of [1, 2, ..., n] in which exactly m elements are greater than the previous element. These are also called rises. For example, if n = 3, there are 3! = 6 permutations of [1, 2, 3]
1 2 3
< < 2 elements are greater than the previous
1 3 2
< > 1 ...
2 1 3
> ... |
This programming puzzle is inspired by another question which has been asked here yesterday but which was deleted by the author...
The challenge:
Create an executable binary (Windows .EXE or Linux binary) using Visual C# (or your favorite C# IDE) which prints the following text to the standard output:
Main() is the mai... |
Given a number N, draw a left aligned NxN board of numbers, leaving 1 blank (as a space) (I will show diagrams with N=5)
2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
Your job is to construct the Sieve of Eratosthenes, step by step. First, start with 2. It's prime, so leave it there, and re... |
The challenge is to write codegolf for the permanent of a matrix.
The permanent of an \$n\times n\$ matrix \$A = a_{i,j}\$) is defined as
$$\text{perm}(A) = \sum_{\sigma \in S_n} \prod^n_{i=1} a_{i,\sigma(i)}$$
Here \$S_n\$ represents the set of all permutations of \$[1, n]\$.
As an example (from the wiki):
$$\text{per... |
We've all been burned by the grammar police on the internet. What we need is a regex that can be used in place of "there", "their", and "they're". This would shift burden of grammar parsing from the writer to the reader (a sort of "client-side" grammar, if we you will). So, here's what I have to start with:
the([re]|[i... |
Using the shortest JS (ES5) code possible, as measured in number of characters, gather all the ids on a page for foobar elements into a comma-delimited string. For example:
<div>
<foobar id="456"></foobar>
<foobar id="aaa"></foobar>
<foobar id="987"></foobar>
<div>
Should give "456,aaa,987"
You cannot use ES6 o... |
There's a river and there are wolves and chickens on one side of the river. They have a raft and they all need to get to the other side. However, the raft cannot travel on its own. The raft will sink if more than two animals are on it. None of the animals want to get wet because the river's cold and dirty. None of the ... |
...counted!
You will pass your program a variable which represents a quantity of money in dollars and/or cents and an array of coin values. Your challenge is to output the number of possible combinations of the given array of coin values that would add up to the amount passed to the code. If it is not possible with t... |
Let's define f(n) as the maximal number of regions obtained by joining n points around a circle by straight lines. For example, two points would split the circle into two pieces, three into four, like this:
Make sure when you are drawing the lines, you don't have an intersection of more than two lines.
Your task
Given... |
Can these rectangles fill a rectangular space?
Given a bunch of rectangles, you are asked whether or not they can be arranged to fill a rectangular space.
Specs
Given a bunch of arbitrary m x n rectangles; 0 <= m, n <= 1000, determine whether or not it is possible to arrange them so that they cover exactly a rectangula... |
This problem is "inspired" from a question that was originally asked on Quora (not for code golfing). I just want to make it a challenge for you guys (and my first problem submission here).
Given an array of integer elements v and an integer d (we assume that d is lower or equal to the array's length), consider all th... |
Consider the natural sequence up-to 6 (disregard 1):
2,3,4,5,6
We start scanning from the left (in this case from 2), search for a number divisible by 2 (here 4) and then remove both the numbers from the list (here 2 & 4), such that the list reduces to:
3,5,6
We continue the same process, here leftmost is 3, so we... |
Your task is to print this exact text:
אבגדהוזחטיכךלמםנןסעפףצץקרשת
(You are allowed to print a trailing newline)
SHA256 hash of the UTF-8 encoding of the text:
0ab6f1e0bf216a0db52a4a5a247f95cba6f51496de7a24dfd01f3985dfcf6085
Base64 encoding:
15DXkdeS15PXlNeV15bXl9eY15nXm9ea15zXnted16DXn9eh16LXpNej16bXpden16jXqdeq
Ru... |
It is Friday and I am tired, so let's do a quick one! Take no input, however you should output all thirteen different numbered cards in a standard deck of cards. You should output 2 through Ace (Suit agnostic).
Each card has a top that is denoted with a space and ten _ and another space .
The second row from the to... |
This is a code golf challenge I thought of with a mathematical bent. The challenge is to write the shortest code possible such that it is an open question whether or not the code terminates. An example of what I mean could be the following piece of python code, adapted from an anwser to this cs stackexchange question.
... |
The Goldbach conjecture states that every even number greater than two can be expressed as the sum of two primes. For example,
4 = 2 + 2
6 = 3 + 3
8 = 5 + 3
However, once we get to 10 something interesting happens. Not only can 10 be written as
5 + 5
but it can also be written as
7 + 3
Since 10 can be expressed as t... |
Your task is to generate a random digit following these steps:
First, generate 10 random digits to make a binary number, 50% 0, and 50% 1:
010011001
If it is all zeros, generate a new one.
Convert this to decimal:
153
For each digit, write that amount of alternating 0s and 1s (first digit = 1s, second digit = 0s, thi... |
Tetration, represented as \${}^ba\$, is repeated exponentiation. For example, \${}^32\$ is \$2^{2^2}\$, which is \$16\$.
Given two numbers \$a\$ and \$b\$, print \${}^ba\$.
Test cases
1 2 -> 1
2 2 -> 4
5 2 -> 3125
3 3 -> 7625597484987
etc.
Scientific notation is acceptable.
Remember, this is code-golf, so the code w... |
Fairly obviously, you have to print the Greek alphabet. But I thought I'd make it slightly more interesting, so there's a twist: when your program is ran with an argument (anything), it should output the Greek alphabet in lowercase.
Information
Greek alphabet (Capitals): ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ
Greek alphabet (Lower... |
The challenge is to write the fastest code possible for computing the permanent of a matrix.
The permanent of an n-by-n matrix A = (ai,j) is defined as
Here S_n represents the set of all permutations of [1, n].
As an example (from the wiki):
In this question matrices are all square and will only have the values -1 a... |
A "triplet bracket" (that I made up for this challenge) is one of the following:
(...+...)
[...:...]
{...|...}
<...-...>
A balanced triplet bracket string (BTBS for short) is either an empty string, two BTBSes concatenated, or one of the above triplet brackets with each ... replaced with a BTBS.
Your task is to write ... |
Given an array of any depth, draw its contents with borders of +-| around each subarray. Those are the ASCII characters for plus, minus, and vertical pipe.
For example, if the array is [1, 2, 3], draw
+-----+
|1 2 3|
+-----+
For a nested array such as [[1, 2, 3], [4, 5], [6, 7, 8]], draw
+-----------------+
|+-----+--... |
I don't know about you all but I'm not preparing for Halloween––never did never will––but, my neighbor is, so we'll help her out.
She needs help figuring out which brand of candy she has, but she has so much candy she would not be able to finish before Halloween.
She has:
Snickers
KitKat
Starburst
GummyBears
Twix
Inp... |
This is different from Print the Greek alphabet! because it is in words.
This is different from "Hello, World!" because the output is different and much longer, leading to different techniques.
This is different from We're no strangers to code golf, you know the rules, and so do I because the output is different and mu... |
Minesweeper is a popular puzzle game where you must discover which tiles are "mines" without clicking on those tiles. Each tile is either a mine (represented by *) or a clue, i.e. a number from 0 to 8 representing how many of the 8 neighboring tiles are mines. Your task today is to take a board containing the mines and... |
Consider the number 99999999. That number is obviously a palindrome. The largest prime factor of 99999999 is 137. If you divide 99999999 by 137, you get 729927. This number is also a palindrome.
The largest prime factor of 729927 is 101. 729927/101=7227 which again is a palindrome.
The largest prime factor of 7227 is... |
This challenge was inspired by this Wendy's commercial from 1984.
Illustration by T S Rogers
Your task is to find a hexadecimal 0xBEEF on a binary bun.
The 'beef' consists of the following pattern:
1 0 1 1 (0xB)
1 1 1 0 (0xE)
1 1 1 0 (0xE)
1 1 1 1 (0xF)
And the 'bun' consists of a 12x12 binary matrix, such as:
1 ... |
Introduction
Suppose you have a ruler with numbers from 0 to r-1.
You place an ant between any two of the numbers, and it starts to crawl erratically on the ruler.
The ruler is so narrow that the ant cannot walk from one position to another without walking on all the numbers in between.
As the ant walks on a number for... |
100 Prisoners and a light bulb
You may have seen this puzzle over on the puzzles exchange or perhaps heard it somewhere else. If you are unfamiliar with this puzzle check out: 100 Prisoners and a Light bulb
The gist of this puzzle is that there are 100 prisoners, each one is separated from one another and must go into... |
Background:
Jack is a pumpkin that enjoys spooking the citizens of the villages near his pumpkin patch every Halloween. However, every year after someone lights the candle inside of him, he has a limited amount of time to spook everyone before the candle burns out, thus being unable to spook any more villagers because... |
(inspired by this question over on Math)
The Definitions
Given an n x n square matrix A, we can call it invertible if there exists some n x n square matrix B such that AB = BA = In, with In being the identity matrix of size n x n (the matrix with the main diagonal 1s and anything else 0), and AB and BA representing usu... |
The Zen of Python must surely be one of the most beautiful Easter eggs in any language. (It is created by writing import this)
So why not create a version for your own language?
For those who don't have access to Python 2 or 3, your code should output the following:
The Zen of [YOUR LANGUAGE]
Beautiful is better than ... |
Halloween is almost here, the holiday after which most people need to wean themselves off a hollow diet of sugar.
Write a program that takes in a positive integer. If the integer is less than 31 (1 through 30), output this ASCII-art jack-o'-lantern, looking to the right as if looking forward to Halloween:
_____I_____
... |
This challenge is straightforward, but hopefully, there are plenty of avenues you can approach it:
You need to print/return a valid JSON object of at least 15 characters, not counting unessential whitespace. Your program should work without any input.
In the interest of clarity, a JSON object starts and ends with curl... |
Introduction
Emoji use a particular alphabet for their national flags, which allows one to put two symbols together to create the appropriate flag.
Your challenge, is to transform any uppercase letter into the appropriate Flag Identifier.
This may be much harder for languages that do not innately handle Unicode.
Each ... |
Again inspired by a task for Programming 101 here's another challenge.
Input:
A positive integer n >= 3. (has to be odd)
Output:
n lines of asterisks, where the first line has n asterisks and every new line has two asterisks less than the line before. Until hitting 1 asterisk. From there every new line has two aster... |
Task
Given an input n, calculate the n-th decimal digit of pi
Rules
Answer can be a full program or a function.
Input must be taken from stdin or from function arguments.
Output must be either sent to stdout, the return value of a function, or written to a file.
all n values between 0 and 20000 must be supported (can ... |
Sequence:
We start at 1.
We first add the current 1-indexed value to the previous number in the sequence.
Then we apply the following mathematical operations in order if they apply to this current value:
Divisible by 2? => Addition
Divisible by 3? => Subtraction
Divisible by 4? => (Addition AND) Multiply
Not divisib... |
Golf Challenge
Given the below ASCII "Green".
| |
| |> |
| | |
| O |
| |
| |
| |
| |
| |
| |
Let | Denote a wall
Let | Denote half the flag pole
Let > Denote the flag on the pole
Let O Denote the hole
Let o Denote the ball
The dimens... |
You've seen the amazing alphabet triangle, the revenge of the alphabet triangle and now it's time for the revenge of the revenge of the alphabet triangle!
Introducing...
THE ALPHABET DIAMOND!
Your task is to output this exact text, lowercase/uppercase does not matter, though newlines do:
bcdefghijklmnopqrstuvwxyzazyxw... |
We've had a lot of alphabet challenges. For this challenge, you are passed the output of an alphabet challenge, and you need to output the pattern scaled to size N.
For example, if N=5 and you were passed the L-phabet:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
BBCDEFGHIJKLMNOPQRSTUVWXYZ
CCCDEFGHIJKLMNOPQRSTUVWXYZ
DDDDEFGHIJKLMNOPQR... |
Your task is to print this exact text:
z
yz
xyz
wxyz
vwxyz
uvwxyz
tuvwxyz
stuvwxyz
rstuvwxyz
qrstuvwxyz
pqrstuvwxyz
opqrstuvwxyz
nopqrstuvwxyz
mnopqrstuvwxyz
lmnopqrstuvwxyz
klmnopqrst... |
Since Halloween is coming up I thought I might start a fun little code golf challenge!
The challenge is quite simple. You have to write a program that outputs either trick or treat.
"The twist?" you may ask. Well let me explain:
Your program has to do the following:
Be compilable/runnable in two different languages. D... |
N in a row
Input:
The character and a 2-Dimensional array.
The array with a size of N x N where 1 <= N <= 26, it will be filled randomly like so:
N = 1
A
N = 2
B | A
-----
A | B
N = 3
A | B | C
----------
B | A | B
----------
C | A | C
As N increases by 1, so does the number of letters. A = 1, B = 2, C = 3. There wi... |
According to this site a general rule recommended by The U.S. Government Printing Office Style Manual is
Capitalize all words in titles of publications and documents, except
a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and
nor.
This might not be true as I'm unable to find such a recommendation i... |
The task:
You have to input 2 numbers and output the results of several operations done with them.
Details:
Input 2 floating point numbers, x != 0 and y != 0 via stdin, command line or function arguments.
Output x+y,
x*y,
x^y (pow(x,y), not x XOR y),
x-y,
y-x,
x/y and
y/x on ST... |
Monday, October 31st, is Halloween. And it got me thinking -- I wonder what other months have the last day of the month also be a Monday?
Input
A positive integer in any convenient format representing a year, 10000 > y > 0.
The input can be padded with zeros (e.g., 0025 for year 25) if
required.
Output
A list of the... |
Cheat is a card game where you're trying to get rid of your hand. A turn looks something roughly like this:
Determine what card rank you have to play that turn. In most variants this is one rank higher than the previous turn.
Play 1-4 cards, face down. These don't have to match the valid rank. If they don't, it's cons... |
Your task is to print this exact text:
az za
abyz zyba
abcxyz zyxcba
abcdwxyz zyxwdcba
abcdevwxyz zyxwvedcba
abcdefuvwxyz ... |
The goal is simple: Output a nonzero real solution x to the equation sin(x) = -mx, given input m, in the fewest number of bytes.
Specifications:
Your answer must be correct to 3 significant figures.
You may output any real solution other than the trivial solution x=0. You can assume m is such that at least one soluti... |
The goal is to output the number of the months given as input in a compact concatenated form which is still parsable if one knows the construction rules:
If either:
January is followed by January, February, November or December; or
November is followed by January or February
There must be a separator placed between.
... |
Given the width and height of a line in characters, draw it using ascii characters.
Input
Two integers separated by a space, the first one being the width, the second one being the height.
Example: 5 3
Output
An oblique line formed with the characters /\|_, that has the width and height given in the input. The characte... |
This is different from My Word can beat up your Word as it is less complex and only requires you to calculate it, and not compare them.
To find the digital root, take all of the digits of a number, add them, and repeat until you get a one-digit number. For example, if the number was 12345, you would add 1, 2, 3, 4, and... |
In Chinese, numbers are written as follows:
1 一 2 二 3 三 4 四 5 五 6 六 7 七 8 八 9 九 10 十
For numbers above 10, it is expressed as the number of tens and the number of ones. If there is only one ten, you do not need to explicitly say one, and if there are no ones, you don't need to put anything after:
11 十一
24 二十四
83 八十三
90... |
xkcd is everyone's favorite webcomic, and you will be writing a program that will bring a little bit more humor to us all.
Your objective in this challenge is to write a program which will take a number as input and display that xkcd and its title-text (mousover text).
Input
Your program will take a positive integer a... |
Bailey–Borwein–Plouffe Iterations
We've seen a few pi challenges on PPCG, but none that specifically dictate the algorithm you should be using. I'd like to see implementations of the Bailey–Borwein–Plouffe algorithm in any language up to iteration n. The formula is as follows:
Your algorithm should output each iterati... |
Input
An array that can contain arrays or positive, consecutive, ascending integers. The arrays can have any number of arrays inside of them, and so on and so forth. No arrays will be empty.
Output
This array simplificated
How to simplificate an array
We will use the array, [1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]... |
The cool stuff
The following rosace can help calculate numbers modulo 7.
In order to do that, you must start at 0 and turn clockwise a number of steps given by the first digit. Then, for each successive digit, follow the arrow and then turn clockwise the number of steps given by that digit.
Here is how you proceed for... |
Here's an ASCII pumpkin carved into a Jack-o-Lantern. Isn't it cute?
((^v^))
Here's an ASCII ghost. Look how spooky it is!
\{O.O}/
Obviously, the pumpkins have to be on the ground, with a space between them so they don't rot.
Ghosts, however, like to stand on top of pumpkins, so they're even spookier. However, they h... |
A Pythagorean triple consists of three positive integers a, b, and c, such that a2 + b2 = c2. Such a triple is commonly written (a, b, c), and a well-known example is (3, 4, 5). If (a, b, c) is a Pythagorean triple, then so is (ka, kb, kc) for any positive integer k. A primitive Pythagorean triple is one in which a, b... |
(Note: this is an easier spin-off of my previous challenge Find the Infinity Words!, which is a spin-off of my other previous challenge Find the Swirling Words! :) )
Definition of a Wavy Word:
If you connect with curves all the characters of a Wavy Word on the alphabet (A-Z) you obtain the path of a wave continuously ... |
Chained Binary Operations
Here's a challenge involving truth tables and binary operations. For this specific challenge, your task is to use the following table of operations:
To create a function that takes in two inputs f(p,a), where p is the initial truthy/falsy value and a is a list of tuples representing multiple ... |
Given a string that contains only lowercase letters, encode that string with the alphabet cipher.
To encode with the alphabet cipher (I will be using the example hello):
First, convert each letter in the string to a number depending on its position in the alphabet (a = 1, b = 2, etc.) Example: 8 5 12 12 15
Pad each nu... |
Given a string to encode, and a number of columns (the key), encode the string as follows:
I will be using the example Hello, world! and the key 3
First, write out the number of columns:
1 2 3
Next, write the text starting from the upper left, one character per column, and when you run out of columns, go to the next l... |
Your task is to write some code in Python 2 or 3 such that this expression:
(a+b)(c+d) == a*c + b*c + a*d + b*d
will evaluate to True without raising any exceptions.
To clarify, I will copy your code into a file, then from the file import *. Then I will type the expression into the console and verify that it is True.
... |
Intro
The Switching sequence is defined like so:
Start with n people standing in a circle (6 for this example).
1 2
6 3
5 4
Starting from person 1, the person that is to the left of the "chosen" person is removed.
1
6 3
5 4
The removed person can "switch" the removal method up:
If the removed person is ... |
I am interested in seeing programs which don't ask for any input, print a googol copies of some nonempty string, no less, no more, and then stop. A googol is defined as \$10^{100}\$, i.e., 1 followed by a hundred 0's in decimal.
Example output:
111111111111111111111111111111111111111111111111111111111111111111111111...... |
Your task is to print the titles of the questions with the five highest scores (upvotes minus downvotes) here on CodeGolf.SE, while skipping over any closed, locked and on-hold questions.
Currently these are:
Produce the number 2014 without any numbers in your source code
Showcase your language one vote at a time
Ameri... |
Given an odd integer N (5 <= N <= 51), generate a maze with side length N that follows the following requirements:
The maze must be composed of the characters | - and +. It must use the | character as a vertical wall, the - character as a horizontal wall, and if that wall turns, the character + should be used.
The wid... |
Background
Bathroom Etiquette, when pertaining to the available urinals, states that the next urinal to be filled in should be the one that minimizes the total discomfort. The total discomfort equation is given by the following set of equations:
dist(x,y) = linear distance between person x and person y in Urinal Units... |
Your challenge is to write a program or function that, when given two strings of equal length, swaps every other character and outputs/returns the resulting strings in either order.
Examples
"Hello," "world!" --> "Hollo!" "werld,"
"code" "golf" --> "codf" "gole"
"happy" "angry" --> "hnpry" "aagpy"
"qwerty" "dvorak" -->... |
A simple Markov Model will be used in this question. For more information about Markov Chains, see http://setosa.io/ev/markov-chains/.
Take a string. For this example, we will use the word:
reader
Now, for each character, take the characters that appear after each occurence of the character in the string. (`^` repre... |
The challenge
Output an array or string representation of Dürer's famous magic square:
that is,
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1
Some properties of this square, which can perhaps be exploited, are:
It contains each integer from 1 to 16 exactly once
The sum of each column or row, as well as the the sum... |
When babies open their mouths, they're not just spewing gibberish. They're actually talking in a highly advanced, adult-proof cipher...
The Baby-talk Cipher
When a baby talks, it could look something like gogooa gagooook aagaaoooy
Each single-space separated section represents a character (so the example above represen... |
The challenge
Your task is to animate Adve the Adventurer moving through a creepy (i.e. Halloween) maze. Adve is a •; he's character fluid, though, so he does not mind being represented by a different character.
To animate Adve, you print out each frame; a frame is the map with his current location in it. Adve moves on... |
Introduction
I defined the class of antsy permutations in an earlier challenge.
As a reminder, a permutation p of the numbers from 0 to r-1 is antsy, if for every entry p[i] except the first, there is some earlier entry p[i-k] such that p[i] == p[i-k] ± 1.
As a fun fact, I also stated that for r ≥ 1, there are exactly ... |
A string is pairable if it can be split into subtrings, each of which is a string repeated twice consecutively. For example, aabaaababbbaba is pairable as:
aaba aaba
b b
ba ba
Given a non-empty string of a's and b's, output a Truthy value if it's pairable and a Falsey value if it isn't.
Pairable:
aa
abaaba
bbababbb
aa... |
Given a sequence of 625 32-bit unsigned integers (that is, in the range [0, 2**32)), output which of the following pseudorandom number generators generated the sequence:
Linear Congruential Generator
Xorshift
Mersenne Twister
Specifically, the C implementations of these three generators used for this challenge are as... |
Seems like an impossible task right? Well, it's actually not that hard. If we write the word Infinity as 8-bit binary ASCII code, we'll get:
01001001 01101110 01100110 01101001 01101110 01101001 01110100 01111001
This can be concatenated, and converted to the decimal value 5291279215216915577. Now that's a number we c... |
Review
First, let's review the Simple Substitution Cipher.
To encode a string in the Simple Substitution Cipher, replace each letter in your string with another letter.
A letter may not be used to replace more than one existing letter.
For example, if I was encoding the text Hello world, my name is Oliver! I like code... |
Background
Back in the late 90's / first 00's when Flash Web Design was so much cool that noone could live without having a full Flash website, or at least an animated widget, I was hired to develop a "horse races viewer" in Flash/Actionscript, in the shape of an 80's videogame style animation, so the site's visitors c... |
Given a number as input, determine how many significant figures it has. This number will should be taken as a string because you have to do some special formatting. You'll see what I mean soon (I think).
A digit is a sig-fig if at least one of the following apply:
Non-zero digits are always significant.
Any zeros bet... |
Given a positive integer n, output the 2^n binary sequences of length n sorted in the following precise ordering.
Test cases:
0:
0 or 1 (defining this is a matter of debate)
1:
0
1
2:
00
01
10
11
3:
000
001
010
100
011
101
110
111
4:
0000
0001
0010
0100
1000
0011
0101
1001
0110
1010
1100
0111
1011
1101
1110
1111
e... |
Your task is to palindromize a string as follows:
Take the string.
abcde
Reverse it.
edcba
Remove the first letter.
dcba
Glue it onto the original string.
abcdedcba
But here's the catch: since this challenge is about palindromes, your code itself also has to be a palindrome.
Remember, this is code-golf, so the code... |
Given a palindrome generated according to this challenge, depalindromize it.
Test cases
abcdedcba -> abcde
johncenanecnhoj -> johncena
ppapapp -> ppap
codegolflogedoc -> codegolf
As this is about depalindromizing, your code cannot be a palindrome.
Remember, this is code-golf, so the code with the fewest bytes wins.
|
Background
When I was in elementary school, we used to play a game in math class that goes as follows.
All kids sit in a big circle and take turns counting, starting from 1.
However, the following numbers must be skipped while counting:
Numbers that are multiples of 3.
Numbers that have a 3 in its decimal representat... |
inspired by Count down from infinity
Given a non-negative integer N, output the number of repetitions of the following steps it takes to reach 0:
Convert N to binary (4812390 -> 10010010110111001100110)
Flip each bit (10010010110111001100110 -> 01101101001000110011001)
Trim leading zeroes (01101101001000110011001 -> 1... |
Note: this is heavily inspired by this question.
Task:
Your task is to generate the nth prime, when each character of your program is repeated n times in place.
Let's say your program is:
Derp
Every character in there is repeated once, so it should output 2.
When every character is duplicated in place, like so:
DDeerr... |
Given a string, first square it as follows:
First, write the string.
abcde
Next, write the string rotated one left.
abcde
bcdea
Keep doing this until you have written len(string) lines.
abcde
bcdea
cdeab
deabc
eabcd
Now, read from the string like this:
----+
+--+|
|+>||
|+-+|
+---+
Which gives:
abcdeabcdcbaedcbcdea... |
Your task is to determine the palindromic degree of a given non-empty string.
To do this, loop until one of the following conditions are met:
The string is not a palindrome.
You encounter a string that has already been encountered.
And do the following:
If it is a palindrome, add one to the degree.
Depalindromize.
... |
Introduction:
Like Twitter and Instagram and others, I wanted to display numbers like 1.2K and 3.8 M instead of 1,222 or 3,823,456.
But that's not all! As we all know, there might be some human beings which undoubtely won't like these abbreviations and will try to reverse them. So, 1.2k will become 1,200 and 3.8 M will... |
The program should take input the number, the start of the range and the end of the range, and output how many integers the number appears between the start and end of the range, inclusive. Both programs and functions are allowed.
Example Inputs
For example:
//Input example 1
3,1,100
//Input example 2
3
1
100
//Input e... |
Given N (2 <= N), print N lines of the letter Fibonacci series like this (i.e. N = 5)
First, start with a and b:
a
b
Next, add the two lines.
a
b
ab
Keep adding the last two lines.
a
b
ab
bab
Keep going...
a
b
ab
bab
abbab
And we're done.
Remember, this is code-golf, so the code with the fewest bytes wins.
|
This is my first code golf exercise for you:
Your input is two integers n and k. You can assume n >= 1 and k >= 1
You have to output all numbers from 1 to n (inclusively) and replace every element that is a multiple of k or that contains k with "Shaggy".
you can take the input in any convenient form and output it in a ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.