instruction_seed stringlengths 34 53.1k | _source stringclasses 1
value |
|---|---|
What general tips do you have for golfing in Nim? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Nim (e.g. "remove comments" is not an answer).
Please post one tip per answer.
| stackexchange_codegolf |
In Fewest (distinct) characters for Turing Completeness, the goal is to find the minimum number of characters which make a language Turing Complete...in other words, allow it to do any computation possible with any other language. In this challenge, we'll be doing somewhat of the opposite, and finding the minimum numbe... | stackexchange_codegolf |
Given 2 brainfuck code snippets A and B, output some brainfuck code C which has the same behavior as running B with the input of As result. Note that C must work for any input that match the following assumptions, as if it were given to A.
You can assume:
Finite input.
both A and B halt.
EOF is consistently 0 or consi... | stackexchange_codegolf |
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... | stackexchange_codegolf |
Gimbap(김밥) is Korean food, somewhat looks like sushi roll.
Here is Korean emoticon represent Gimbap : @))))))))))
Your quest is make ASCII Gimbap cutter.
Rule
Input is string made with only @ and ).
Output cuts every valid Gimbap with ), and then add @ between them. So for example @)) to @) @).
Valid Gimbap starts wi... | stackexchange_codegolf |
I have been recently told to read an entire physics textbook by the new year (true story, unfortunately). I need your help to determine what chapters I should read each day. This is where you come in.
Input
Two dates, in any format. The second date will always be later than the first.
A list of chapter numbers. This c... | stackexchange_codegolf |
You have to write a program, if its source code is reversed, then it will error.
For example, if your source is ABC, then reversing it and writing CBA should crash/throw an error. And ABC itself should be a vaild program (I mean your primary source should be a valid program). Output of the main source code can be empty... | stackexchange_codegolf |
The task is to count the number of distinct substrings of length k, for k = 1,2,3,4,.....
Output
You should output one line per k you manage to complete with one number per output line. Your output should be in order of increasing k until you run out of time.
Score
Your score is the highest k you can get to on my compu... | stackexchange_codegolf |
Adapted from Tips for restricted source in Python
Just like code-golf, restricted-source pushes one to exploit quirks and hidden features of the Powershell language. Now, We already have a place to collect all these tips for code-golf, those for restricted-source remain transmitted by word of mouth or hidden deep wit... | stackexchange_codegolf |
The Challenge
Given a list of integers, the "bittiest" number among them is the one with the most bits on - that is, the largest amount of bits set to 1 in its 32-bit two's complement representation.
Write a function (or a program) that takes as input a list of integers between \$ -2^{31} \$ and \$ 2^{31}-1 \$ (the ran... | stackexchange_codegolf |
In this challenge, your task is to detect (vertical) Skewer Symmetry. This means that one half of the pattern can be produced by mirroring the other half along a vertical axis, and then moving it vertically.
For example, the following pattern has skewer symmetry:
asdf
jkl;fdsa
;lkj
Because if you start from th... | stackexchange_codegolf |
The goal of this challenge is the write the shortest function/program to take input text, encrypt it using the method below, and return the result.
As an example, I will use the string hello world.
First, get the input text.
hello world
Second, convert the string into ternary (base 3). Use this key:
a = 000
b = 001
c ... | stackexchange_codegolf |
Miller-Rabin test
Given a base \$b\$ and an odd number \$n\$:
Write \$n\$ as \$2^{s}\times d + 1\$ where \$d\$ is odd
\$n\$ is a strong probable prime if either:
\$b^d\equiv 1 \pmod n\$
\$b^{d\cdot2^r}\equiv -1 \pmod n\$
for any non-negative \$r\$ strictly less than \$s\$.
A strong probable prime which is composite ... | stackexchange_codegolf |
I'm trying to read 4 ints in C in a golfing challenge and I'm bothered by the length of the code that I need to solve it:
scanf("%d%d%d%d",&w,&x,&y,&z)
that's 29 chars, which is huge considering that my total code size is 101 chars. I can rid of the first int since I don't really need it, so I get this code:
scanf("%*... | stackexchange_codegolf |
Help! I printed a bunch of rational numbers with no spaces or other delimiters other than the / in the fractions. There is, however, good news! All the numbers are positive. There are no improper fractions, every numerator is less than its denominator and any integers are represented directly, not as fractions. Any non... | stackexchange_codegolf |
This is a more difficult version of It's a find-a-movie challenge .
Input
Your code should take a BBFC rating and a number from 1 to 5 as input. It can do this in any way you find convenient.
Output
Your code should return the name of any movie which has a) that film rating and b) that number of stars in a Guardian fi... | stackexchange_codegolf |
Laguerre polynomials are nontrivial solutions to Laguerre's equation, a second-order linear differential equation: \$xy''+(1-x)y'+ny=0\$. For a given value of \$n\$, the solution, \$y\$, is named \$L_n(x)\$. To avoid trivial solutions, the polynomials are non-constant except for \$n=0\$.
The polynomials can be found wi... | stackexchange_codegolf |
The famous game of Qwirkle has simple but intricate rules (See part 2 of this question for a summary of the rules!)
The Challenge
You are somehow (text input, function parameter, whatever) given a board of a Qwirkle game, like a snapshot from any current timeframe within a game. This board can be anything from complet... | stackexchange_codegolf |
Challenge
You need to generate a program or function that takes in a positive integer N, calculates the first N terms of the Fibonacci sequence in binary, concatenates it into a single binary number, converts that number back to decimal, and then outputs the decimal as an integer.
For example
1 -> [0] -> 0 to decimal o... | stackexchange_codegolf |
Modern regular expressions (regexes) have many features (\d, {n,m}, \1, etc.), but to define a regular language (modern regexes can define broader classes of languages, in their defense), all you need are three operators: concatenation (+), union (|), and the Kleene star (*). Here are some examples:
a - Matches the str... | stackexchange_codegolf |
Consider a potentially self-intersecting polygon, defined by a list of vertices in 2D space. E.g.
{{0, 0}, {5, 0}, {5, 4}, {1, 4}, {1, 2}, {3, 2}, {3, 3}, {2, 3}, {2, 1}, {4, 1}, {4, 5}, {0, 5}}
There are several ways to define the area of such a polygon, but the most interesting one is the even-odd rule. Taking any p... | stackexchange_codegolf |
Introduction
Given five points in the plane, your task is to compute the area of the ellipse passing through these points.
You can assume that exactly one non-degenerate ellipse can be constructed with the given input values.
Rules
Input is 10 integers in any convenient form, corresponding to the x and y coordinates of... | stackexchange_codegolf |
Children are very good at classifying objects and counting them. Computers seem to have more trouble. This is a simplified version of this problem. Can you write a small program that can classify and count objects in an image?
The problem: Given an image containing one or more circles and rectangles, return 2 integers
... | stackexchange_codegolf |
A magic word is a word whose Braille spelling contains precisely 26 dots (because the Morse code alphabet can be circularly encoded within). For example:
⠎ ⠝ ⠥ ⠛ ⠛ ⠇ ⠽ snuggly
⠏ ⠕ ⠇ ⠽ ⠛ ⠕ ⠝ polygon
⠝ ⠥ ⠛ ⠛ ⠑ ⠞ ⠽ nuggety
⠽ ⠕ ⠛ ⠓ ⠥ ⠗ ⠞ yoghurt
are all magic words.
Objective:
Craft a program to identify 77 such mag... | stackexchange_codegolf |
Given two strings as input, return the result of XORing the code-points of one string against the code points of the other.
For each character in the first input string, take the code-point (e.g. for A, this is 65) and XOR the value against the corresponding index in the second string and output the character at the co... | stackexchange_codegolf |
Introduction
Ah, INTERCAL...
As much as I'd like encourage everyone to Try it Online, text output is just painful.
According to the docs it uses the "Turing Text Model".
While an... interesting concept, using it is about as much fun as shooting yourself in the foot.
And what do we do with a task like this? Automate it.... | stackexchange_codegolf |
The code has a lot of names, but is very simple:
1 2 3 4 5
1 A B C D E
2 F G H I J
3 L M N O P
4 Q R S T U
5 V W X Y Z
A letter is coded by its coordinates, with the row first, then the column. Ex:
M = 3, 2
V
1 2 3 4 5
1 A B C D E
2 F G H I J
>3 L M N O P
4 Q R S T U
5 V W X Y Z
Note the letter 'K' i... | stackexchange_codegolf |
The Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different.
Let P be a binary string of length n and T be a binary string of length 2n-1. We can compute the n Hamming distances between P and every n-length substring of T in order from left to ri... | stackexchange_codegolf |
Given integers k and n, generate a sequence of n unique k-tuples of pairwise coprime integers. Every such tuple must occur once eventually, that is, for any existing k-tuple of pairwise coprime integers, some n will eventually generate it.
The output may be printed or evaluated in any list/tuple-like form.
Definitions
... | stackexchange_codegolf |
Chat room: https://chat.stackexchange.com/rooms/106513/easter-bunny-challenge
Git repo: https://github.com/ajfaraday/easter_bunny_hunt
The garden is a 2-dimensional grid with 49 rows and 49 columns.
The Easter Bunny™️ is in the center of the garden, minding his own business, holding on to 100 Easter eggs.
Unfortunat... | stackexchange_codegolf |
There are radiation hardened quines, palindromic quines, but has anyone tried both?!
I think not!
Rules
So the challenge here is to make a quine that if any symbol is deleted it prints its original source code, and the quine needs to be the same read forward and backwards(before radiation damage)! All code will be scor... | stackexchange_codegolf |
Task
This one is simple. We want to compress a URL, but don't trust URL shorteners.
Write a program that prints to stdout (or a 0-argument function that returns) the following, working URL:
http://a.b.c.d.e.f.g.h.i.j.k.l.m.n.oo.pp.qqq.rrrr.ssssss.tttttttt.uuuuuuuuuuu.vvvvvvvvvvvvvvv.wwwwwwwwwwwwwwwwwwwwww.xxxxxxxxxxxx... | stackexchange_codegolf |
It's Christmas everybody, and here's a code-golf challenge to celebrate. You need to make a program to print out a present. Specifically, the words "Merry Christmas". BUT, there is a catch: this program must only work if it is the 25th of December. If the code is run on any other day, then the program should crash.
Thi... | stackexchange_codegolf |
I have a problem for a cyber club that asks you to print:
ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!
Using Brainf**k in 29 bytes or less without using the ',' character.
I have a working code:
++++++++++[>++++++>+++++++++<<-]>-->.<[>-.<-]
However my loop is too long, sending me 16 bytes over the limi... | stackexchange_codegolf |
Task
Given two positive integers a, b and a Unicode mathematical inequality symbol c, determine if a c b is true.
You many take the character or its Unicode codepoint for the input c. You may output your language's truthy/falsy values, or two distinct values for true and false respectively.
Standard code-golf rules app... | stackexchange_codegolf |
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
Santa and the Elves are secretly preparing for a new tourist train service, called "North Pole Railroads". The train will travel through various sightseeing spots near the North Pole.
As a part of this project, they want to know how ma... | stackexchange_codegolf |
A shape is chiral if no amount of rotation can make it look like it's mirror image. In this puzzle we will be writing chiral computer programs.
For this puzzle we will think of a program as a rectangular matrix of characters. As such all solutions to this challenge must be rectangular (that is all lines must be of th... | stackexchange_codegolf |
We already have challenges dealing with simulating vanilla Conway's Game of Life, Wireworld and rule 110, but so far none corresponding to a (specific) non-totalistic rule. So here is one.
In June 2000 David Bell described the Just Friends rule, which uses the same square grid and two states as regular Life but has the... | stackexchange_codegolf |
Part 1 of the challenge revolved around converting the letters into specific unicode characters.
Lore
In this part we receive the output from the function made in Part 1, which now has to be arranged in an artistic manner.
Aim
Take 1 word as input which has already undergone transformation in the function made in Part ... | stackexchange_codegolf |
My Precalc teacher has one of his favorite problems that he made up (or more likely stole inspired by xkcd) that involves a row of n urinals. "Checkmate" is a situation in which every urinal is already occupied OR has an occupied urinal next to them. For instance, if a person is an X, then
X-X--X
is considered checkmat... | stackexchange_codegolf |
Your task is to output a square sandbox of size n+2 with / characters in the corners and | for the sides, and - for the top, with n**2 layers of sand (.) overflowing out of the sandbox of width n+2
Testcases
1
->
/-/
|.|
/./
...
2
->
/--/
|..|
|..|
/../
....
....
....
....
3
->
/---/
|...|
|...|
|...|
/.../
.....
...... | stackexchange_codegolf |
There are a bunch of different casing conventions, like camelCase, PascalCase, snake_case etc. It's annoying juggling all of these, so instead of choosing one like a sensible person, why not cursedly mix all of them together?
Your challenge is to, given a list of words (only containing lowercase letters), convert them ... | stackexchange_codegolf |
In chess, fork means to target two pieces with just one piece, and one of the best pieces for forking is the knight.
In this challenge, you will be given three coordinates in a to h and 1 to 8 (like a8 or e7) format. The first and second coordinates are for two other random pieces, and the third is the knight's coordin... | stackexchange_codegolf |
Loading Circle Animation
Challenge
Write a full program that takes no input (or has an unused input) that displays exactly the following ASCII animation for as long as possible or only 8 frames.
Frame 1:
#
#
# #
##
Frame 2:
##
#
#
##
Frame 3:
##
# #
#
#
Frame 4:
##
# #
# #
(Note that the line at the end... | stackexchange_codegolf |
Given a unix timestamp as an input, give a datetime string, in a format like so: "YYMMDD.HHmm"
Rules
The input is a number (integer) of a millisecond-precise UNIX epoch time (milliseconds since 1970 January 1st 00:00:00.000 UTC).
The values must be padded with zeroes if they are 1 character instead of 2. (e.g.: for "D... | stackexchange_codegolf |
One day, I saw the challenge to multiply two strings and I thought I might be able to do one better.
That challenge was fake. It was elementwise maximum. It was not real multiplication. So I set out to make something real. Real division between two strings.
I quickly realized that this would make an amazing challenge,... | stackexchange_codegolf |
What does "jelly" mean in the title?. Robber's thread
Jelly has an "Evaluate the argument as Python 3" atom, ŒV which takes a string as an argument as evaluates that string as Python 3 code: Try it online!.
It also has compressed strings, delimited with “...» that can compress any string containing printable ASCII (plu... | stackexchange_codegolf |
I have made a short script that will pull dns txt records down from a server and combine them into a single string.
DNS txt records are:
1.website.com
2.website.com
3.website.com
Each of these are iterated through using the single digit number.
The double quotes at the beginning and the end of the strings are trimmed
T... | stackexchange_codegolf |
Background
Consider a sequence defined as follows:
The first element is 0;
The second element is 4;
From the third element onwards, its value can be calculated by:
Taking the set of integers from 0 up to the previous element of the sequence (inclusive or exclusive, it doesn't matter);
Removing any integers that have... | stackexchange_codegolf |
Input
An integer n and a pair of distinct integer valued (x, y) coordinates on the boundary of the grid. The coordinates are indexed from 1. For example, n=10 and (1,2), (10, 7).
The points will always be on different sides of the grid and neither of them will be \$(1, 1)\$.
Output
The number of integer points in an n... | stackexchange_codegolf |
Kuznetsov's Sequence
(I made the name up, don't bother with Wikipedia or Google)
Given any number n > 0, let r represent the reverse of the number n. Iterate until the final result is zero, passing the result of each iteration back into the function using recursion or a methodology of your choice by performing the bel... | stackexchange_codegolf |
A stretchy snake looks something like this:
<||=|||:)~
Each separate sequence of vertical bars (|) in a stretchy snake, known as a stretchy portion, is individually extendable to twice its width, and is drawn with alternating slashes (/,\) once extended.
The particular snake above has two such stretchy portions, givin... | stackexchange_codegolf |
Your task is to create either a console "app" or a function which allows the user to bet on certain numbers or retire / claim rounds.
Bets
Your program or function will prompt for a command after an action, and the bet is the most important, crucial to the operation of the app.
A bet looks something like this:
bet 5
b... | stackexchange_codegolf |
The Challenge
Given an integer, calculate its score as described below.
The score is calculated by raising each digit of the input Integer to the power n, where n denotes the index of the digit in Input (beginning with 1) when counted from left to right (the index of leftmost digit should be 1), and then summing them a... | stackexchange_codegolf |
The goal of this challenge is to print the following tongue twister:
She sells seashells by the seashore,
The shells she sells are seashells, I'm sure.
So if she sells seashells on the seashore,
Then I'm sure she sells seashore shells.
This is more complicated than just calling your language's print equivalent. Since ... | stackexchange_codegolf |
The 32-point compass is... interesting, to say the least.
By Denelson83 (Own work) [GFDL or CC-BY-SA-3.0], via Wikimedia Commons
Your challenge is to take a degree measure, and convert it into a direction on the 32-point compass.
Each direction is 11.25 (360 / 32) degrees farther than the previous. For example, N (nor... | stackexchange_codegolf |
ello all, I hope this finds you well.
There are 118 elements on the Periodic table at the moment, each one corresponds to the number of protons in an atom's nuclei.
Each element also has a 'symbol'. Hydrogen has 'H', Helium has 'He' and so on. I want to know about these!
Challenge:
Given 1 string as input, output true ... | stackexchange_codegolf |
Imagine enumerating the elements of rhombi which grow [1],[1,3,1],[1,3,5,3,1],… (only odd numbers such that they align nicely). This would look like as follows, note that you always begin enumerating with 1:
01
1 02 03 04
1 2 3 4 05 06 07 08 09 …
5 10 11 12
... | stackexchange_codegolf |
Can you think of a regular expression that does not match itself?
| stackexchange_codegolf |
Description
The Caesar cipher is a cipher, where every letter in the alphabet will be rotated by a secret number.
If the rotation is \$7\$, then a -> h, g -> n, v -> c and z -> g.
Today, we're playing Caesar's Cipher with ASCII chars, (0-127 inclusive).
So, with rotation \$7\$, b -> i, Z -> a, x -> DEL (127),
But, even... | stackexchange_codegolf |
We have a challenge to calculate the hyperfactorial and one to count the trailing zeros of the factorial, so it seems logical to put them together and count the trailing zeros in the hyperfactorial.
As a recap, the hyperfactorial of a number, H(n) is simply Πiⁱ, that is, 1¹·2²·3³·4⁴·5⁵·…·nⁿ. It can be defined recursiv... | stackexchange_codegolf |
Write a program or function with the following functionality:
The program/function first attempts to write the string Hello, world! to the standard output stream. (No other forms of output are acceptable for this challenge, as the focus is very much on the I/O rather than the trivial behaviour of the program itself.) ... | stackexchange_codegolf |
The PGP Word List is a set of 512 English words for verbally communicating strings of bytes, such as authentication codes or hashes. It is used in secure VoIP software as well as in some other important applications, such as the DNSSEC Root KSK Ceremonies held four times a year.
It consists of 256 two-syllable words a... | stackexchange_codegolf |
In this challenge, you need to parse morgue files from the roguelike game Dungeon Crawl Stone Soup and output it to STDOUT.
What are these morgue files??
When you die, a text file is generated with that character's data inside. You can see what equipment the character had, what happened during the last few turns, and h... | stackexchange_codegolf |
Your friend Jack is a picky eater. He only likes certain foods, and he only likes to eat a certain amount of them each day. Despite this, Jack has very strict calorie and macronutrient goals that he strives to meet with his diet. To complicate things further, Jack's cravings change day by day, and he will only eat the ... | stackexchange_codegolf |
It is very hard to remember my password, so I came up with a way to generate a password.
The way I generate my password is from a word or a sentence, following these steps:
Start from left to right
Find the count of each letter
Put letter with its count in an order
Letters with higher repetition will be in the end
... | stackexchange_codegolf |
Given an integer \$x_1\$ and some black box function \$f: ℤ → ℤ\$ find a fixed point of \$f\$ in the sequence defined by \$x_{k+1} := f(x_k)\$.
Details
A value \$x\$ is said to be a fixed point of \$f\$ if \$x = f(x)\$.
For instance if \$f(x) = \text{round}(\frac{x}{\pi})\$ and we have a starting point \$x_1 = 10\$ t... | stackexchange_codegolf |
Given two inputs, a distance \$d\$ and a number \$n\$ output a list of \$n\$ random colors which each have distance \$d\$ from the previous.
Background
A random walk is a path which is defined by choosing a random direction and (usually) fixed distance to go at each step. We will be taking a random walk through the RGB... | stackexchange_codegolf |
In Minecraft, pistons are blocks that can move other blocks. However, they can only move at most twelve blocks, and won't work at all if any obsidian is in the way. Also, slime blocks are sticky and stick to other blocks, except for obsidian.
Your challenge
Take as input a 5x5 matrix or similar, containing one piston a... | stackexchange_codegolf |
I haven't. :P So I decided to define one:
A tralindrome is a string which contains three equal-length sections X, Y, Z such that
all characters in the string are included in at least one of the three sections,
X starts at the first character, Y starts at or right after the last character of X, and Z starts at or right... | stackexchange_codegolf |
The task is simple: write assembly that computes the order of magnitude of an integer using as few clock cycles as possible.
Order of magnitude is defined as log10, not log2.
The range of valid input is 0 to 1012, inclusive. Behaviour for input outside that range is undefined.
Values should be rounded down to the near... | stackexchange_codegolf |
Input
The board: A 2D container (matrix, list of lists, etc.) of letters like:
["B", "C", "C", "C", "C", "B", "B", "C", "A", "A"],
["B", "A", "C", "B", "B", "A", "B", "B", "A", "A"],
["B", "C", "B", "C", "A", "A", "A", "B", "C", "B"],
["B", "B", "B", "A", "C", "B", "A", "C", "B", "A"],
["A", "A", "A", "C", "A... | stackexchange_codegolf |
Convert a string containing digits as words into an integer, ignoring leading zeros.
Examples
"four two" -> 42.
"zero zero zero one" -> 1.
Assumptions
Submissions can assume that:
The input string is comprised of space-separated digit words.
All words are valid (in the range "zero".."nine") and lowercase. Behaviour ... | stackexchange_codegolf |
Implement a function or program that can run simplified BitCycle code. The functions you must implement are:
<^>v: Change the direction of a bit to the direction this is pointing.
+: Turn all 0s left and all 1s right.
\ and /: Reflect one bit 90 degrees, then become inactive. In regular BitCycle, this is displayed as -... | stackexchange_codegolf |
You love watching the snow falling outside, but you know it won't be snowing much longer. You could take a video, but decide to make a snow animation because ... um ... you need to practice your animation skills!
Snow
Snow is simply the * symbol here. Half of the snow moves at 1 char per frame, while the other half mov... | stackexchange_codegolf |
A Latin square of order n is text which is arranged as a square of n lines by n columns, contains n different characters, and each character appears once in each line and column. For example, here is a Latin square of order 9:
Code gOlf
ode gOlfC
de gOlfCo
e gOlfCod
gOlfCode
gOlfCode
OlfCode g
lfCode gO
fCode gOl
M... | stackexchange_codegolf |
The goal of this challenge is the write the shortest function/program to take input text, encrypt it using the method below, and return the result.
As an example, I will use the string hello world.
First, get the input text.
hello world
Second, convert the string into ternary (base 3). Use this key:
a = 000
b = 001
c ... | stackexchange_codegolf |
Find the moves that bring a chess squad to a given destination.
You control a chess squad consisting of a king and several other pieces, on a larger chess board. Your army is placed so that no piece is further than K=8 squares away (horizontally and vertically) from your king. You will receive a destination square for ... | stackexchange_codegolf |
This is a cake:
_========_
| |
+________+
| |
+________+
| |
+________+
It is 8 wide, 3 tall, and 1 deep.
You must write a program that makes a cake from 3 inputs. The first input controls how many underscores there are in the middle and =s on the top. Here's the first cake with a width of 10 inst... | stackexchange_codegolf |
I'm surprised this hasn't been posted before!
The Consistent Overhead Byte Stuffing (COBS) algorithm is used to delimit byte streams.
We choose a frame marker (we'll use 0x00) and wherever 0x00 occurs in the stream it is replaced with the number of bytes until the next 0x00 occurs (we'll call this a milestone). This re... | stackexchange_codegolf |
Given a URI like:
postgres://username:password@hostname:PORT/dbname
Extract it all into an array data-structure, like so:
['postgres', 'username', 'password', 'hostname', 'PORT', 'dbname']
More info: http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax
Rules
No use of external libraries or web-services
Scoring
Y... | stackexchange_codegolf |
Hearts is a 4-player game that uses the following scoring rules:
Everyone starts with score 0.
Each round every player gets a non-negative amount of points. The sum of the points is 26, and at least one player gets 13 or more points.1
The points are then added to the players' score except if a player gets 26 points. I... | stackexchange_codegolf |
Given a string s and a positive integer N, gradually duplicate each character more and more until N duplicates, and then staying at N duplicates until N characters away from the end, then step down again.
For example, given abalone and 3:
a we start with 1 copy
bb then 2 copies
aaa then 3 copies, which is our sec... | stackexchange_codegolf |
What general tips do you have for golfing in C? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C (e.g. "remove comments" is not an answer). Please post one tip per answer. Also, please include if your tip applies to C89 and/or C99 and if it only works o... | stackexchange_codegolf |
In 1988, the International Mathematical Olympiad (IMO) featured this as its final question, Question Six:
Let \$a\$ and \$b\$ be positive integers such that \$ab + 1\$ divides \$a^2 + b^2\$. Show that \$\frac{a^2 + b^2}{ab + 1}\$ is the square of an integer.
(IMO problems)
This can be proven using a technique called ... | stackexchange_codegolf |
Warning: Wouldn't you rather answer a challenge about ponies?1
If you have read The Hostile Hospital, you would know that the Baudelaire orphans, from one of the scraps of paper recovered from the Quagmire's notebooks, they discover a name, "Ana Gram". Later on, they realize that means the word "anagram", not a name.... | stackexchange_codegolf |
For this challenge, submissions should be a program or function shaped like a right triangle, which produces a right triangle of the same size.
What is a right triangle?
For this challenge, a right triangle consists of 1 or more lines, each containing a number of characters (assume all non-newline characters are the sa... | stackexchange_codegolf |
The task
Most Casio calculators featured a variable M, which has 3 operators related to it: M, M+, and M-
M, as you can expect, returns the value stored in the variable.
M+ takes the number on the left and add it to M.
M- does the same thing as M+, but subtract instead.
To make the challenge just a bit more difficult, ... | stackexchange_codegolf |
Given \$a\$ and \$b\$, both odd \$n+1\$-bit integers, compute \$a/b\$ to a precision of \$n+1\$ bits in the 2-adic integers. That is, compute \$c\$ such that \$a = bc\, (\mathop{\rm mod} 2^{n+1})\$. \$n\$ should be your language's native integer size, or if native integers are bigints, take it as a parameter. If your l... | stackexchange_codegolf |
Introduction:
After I posted two rainbow-related challenges: Codegolf Rainbow : Fun with Integer-Arrays 1 and Codegolf Rainbow : Draw in Black-and-White 2, the following comment was made by @ChrisM in the ASCII (Draw in Black-and-White) challenge:
Maybe you know this and it's by design (I know that rainbows are not rh... | stackexchange_codegolf |
We all know that \$(-a) \times (-a) = a \times a\$ (hopefully), but can you prove it?
Your task is to prove this fact using the ring axioms. What are the ring axioms? The ring axioms are a list of rules that two binary operations on a set have to follow. The two operation are addition, \$+\$, and multiplication, \$\... | stackexchange_codegolf |
You are given the positions of the minute and hour hands of an analog clock as an angle of clockwise rotation from the top (12). So a hand pointing at 9 is at an angle if 270, and a hand pointing exactly in between 12 and 1 is at an angle of 15.
Input will be two integer angles (in any order of your choice) between 0 a... | stackexchange_codegolf |
Task
Write a polyglot in two languages that when run, outputs the name of the language it is run in. Additionally, this program must also output the other language's name if the source code is reversed
Example:
Program ABC in language foo outputs foo. ABC in language bar outputs bar. CBA in language foo outputs bar, an... | stackexchange_codegolf |
Inspired by a question over at Stack Overflow. The title here is entirely my fault.
The challenge
Given a list of positive integers containing at least two entries, replace each number by the minimum of all entries excluding itself.
Test cases
[4 3 2 5] -> [2 2 3 2]
[4 2 2 5] -> [2 2 2 2]
[6 3 5 5 8] -> [3 5... | stackexchange_codegolf |
With this challenge we pay homage to everyone around the whole world fighting against the coronavirus crisis; particularly represented are the people tied to medicine, as the Rod of Asclepius is a symbol associated with medicine and health care.
For that matter, we resort to some ASCII art found at asciiart.eu (wrongfu... | stackexchange_codegolf |
I have previously posted a challenge, smallest number of steps for a knight in chess.
Now I would like to go a step further by adding the possibility to choose your piece.
If you place a piece on any square of a chessboard, what is the smallest number of steps to reach every possible position?
Rules
It is an 8 by 8 bo... | stackexchange_codegolf |
Your challenge is to create a regex that matches every string permutation of itself, and nothing else. The match must also be case-sensitive.
So, for example, if your regex is:
ABC
It should match (and only match) these strings:
ABC
ACB
BAC
BCA
CAB
CBA
It shouldn't match things like:
AABC (contains an extra A)
ABCD (... | stackexchange_codegolf |
You just recently got a new phone, but you don't quite like the way it vibrates, you've decided you want to create your own vibration patterns. So, you've written a program where you used the keywords long, short and pause to make your phone vibrate according to these keywords.
Task
Create a small program that accepts ... | stackexchange_codegolf |
Given an input string, determine the number of regions that a page will be split into.
Consider the letter P. It has one enclosed region within the letter. Assume that each letter splits the page by one or more regions (i.e. a box is drawn around the character).
Input
A string of 0 or more characters. You may assume th... | stackexchange_codegolf |
Introduction
This is one is pretty straightforward. We will be drawing a snake in ascii. This was inspired by that old snake game where you have to collect the fruit and you continuously grow.
Definition
Given a positive integer N that represents the snake's length, draw a snake so that it has a body of n plus a head a... | stackexchange_codegolf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.