instruction stringlengths 34 53.1k |
|---|
What general tips do you have for golfing in JavaScript? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to JavaScript (e.g. "remove comments" is not an answer).
Note: Also see Tips for Golfing in ECMAScript 6 and above
|
BlackJack
As I had a blast working on the
original KOTH challenge, I wanted to
come up with another one. For me, the fun
of these AI challenges is in refining
a comparatively simple bot which plays
a very simple game subtly. Due to the
probabilistic nature of card games, I
think that blackjack could be a... |
The Great Pyramid of Giza, the largest pyramid in Egypt, is not only the oldest of the Seven Wonders of the Ancient World, but it is also the only one to remain largely intact. The Egyptian Pyramids can take up to 20 years to build and are so big that Al-Aziz Uthman, son of the great Saladin who crushed the Crusaders, ... |
The square number digit density (SNDD) of a number - invented by myself - is the ratio of the count of square numbers found in consecutive digits to the length of the number. For instance, 169 is a 3-digit number containing 4 square numbers - 1, 9, 16, 169 - and thus has a square number digit density of 4/3, or 1.33. ... |
Sleep Sort is an integer sorting algorithm I found on the Internet. It opens an output stream, and for each input numbers in parallel, delay for the number seconds and output that number. Because of the delays, the highest number will be outputted last. I estimate it has O(n + m), where n is the number of elements and ... |
Pascal's Triangle is a familiar mathematical construct with many interesting properties. It is constructed by starting with a 1 on top, and generating the numbers in the next row from the sum of the number to the left and right in the row above (with implied 0's around the boundary):
1
1 1
1 2 1
1 3 3 1
1 4 ... |
Given an expression of one-letter variables ([a-z]), operators (*, +, &) and parenthesis, expand it using the following axioms:
a * b != b * a
a * b * c = (a * b) * c = a * (b * c)
a + b = b + a
a + b + c = (a + b) + c = a + (b + c)
a * (b + c) = a * b + a * c
a & b = b & a
a & (b + c) = a & b + a & c
| Comm | Asso... |
Code 39, developed in 1974, is one of the most commonly used symbologies, or types, of barcodes, although it is the UPC/EAN system that is most often seen in retail sales. Code 39 barcodes can encode uppercase letters, numbers, and some symbols and are trivial to print from computer software using a special font. This ... |
Where input is binary, convert it to a decimal number (base 10), reverse the decimal number and output it. Vice versa for decimal (base 10) input: reverse it, convert it to binary and output the binary number.
Sample Input:
00000001
00000010
255
00011000
Sample Output
1
2
1000101000
42
other Sample Input
78
35
01011... |
You task is to write a small program, that counts the points of a Skat hand. A Skat deck has cards 7 to 10, Jack, Queen, King and Ace (called Unter, Ober, König and Daus). We use the German suits, which have Acorns, Leaves, Hearts and Bells instead of Clubs, Spades, Hearts and Diamonds. The points are determined by the... |
Why is the number 6174 so interesting? As defined by Wikipedia
Take any four-digit number, using at
least two different digits. (Leading
zeros are allowed.)
Arrange the digits in ascending and
then in descending order to get two
four-digit numbers, adding leading
zeros if necessary.
Subtract the smaller num... |
Task
Write a function/program which takes \$n\$ as a parameter/input and prints/returns the number of topologies (which is demonstrated below) on the set \$\{1,2,...,n\}\$.
Definition of Topology
Let \$X\$ be any finite set, and assume that \$T\$, which is subset of the power set of \$X\$ (i.e. a set containing subse... |
Following the interest in this question, I thought it would be interesting to make answers a bit more objective and quantitative by proposing a contest.
The idea is simple: I have generated a binary file containing 50 million gaussian-distributed doubles (average: 0, stdev 1). The goal is to make a program that will so... |
The challenge is to implement a box blur in any language. The input will be as a 32-bit uncompressed bitmap, BGRA, preceded by one byte defining the radius of the blur and one byte defining the width of the image. The output should be in the same format as the input (minus the blur radius, of course).
Fastest code wins... |
Task
Make a simple IRC bot which does simple task like greeting user.
Detail
(You may see this RFC document.)
Write a complete program that perform these:
The program inputs nickname and realname from the user.
All nickname and realname which form is [A-Za-z0-9]+ should be allowed, but it isn't important whether ... |
Write a function (or equivalent subprogram) to accept a single integer valued argument and return a (similarly typed) value found by reversing the order of the base-10 digits of the argument.
For example given 76543 return 34567
|
What are your tips for code golfing using Clojure?
The aim of this question is to collect a list of techniques that are specific to Clojure and can be used in general code-golfing problems.
|
Code a daily horoscope for the 12 zodiac signs, it needs to be self-sustained (no external ressources), quite randomized but fixed by zodiac sign for each day.
It needs to extract three "variables" from 1 to 3 :
love
work
money
Each one ranked from 1 to 3.
Ex. of variables that can be used (vars fixed for a d... |
A string x generates a string y if y is a substring of an infinite repeat of x. For example abc generates bcabcab.
Write a program to find the shortest, lexicographically smallest string that will generate the input. You are given on standard input a single line of text. You should print the generating string to sta... |
Task
Write a program or a function that calculates a week-day name of a date which a user inputs.
Input & Output
Input is a string, YYYYMMDD.
Example of input values:
20110617 : June 17, 2011
19040229 : February 29, 1904
06661225 : December 25, 666
00000101 : January 1, 0
99991231 : December 31, 9999
You may assume t... |
As I have seen many questions asking tips for golfing in their interested language, I decided to ask for my favorite language: Groovy. People can give some tips and tricks that will be used in golfing with Groovy.
|
The Seven-Eleven problem is find 4 positive numbers (with two decimal digits, A.BC) such that their sum is equal to their product and is equal to 7.11.
a + b + c + d = a * b * c * d = 7.11
0 < a <= b <= c <= d
Write the shortest program to compute all non-decreasing quadruples. Precomputing the values is not allowed.
|
Matthew likes solving puzzles. Whenever he manages to solve one he skips
around happily. Recently he really needs to do this as a meteor shower
has opened craters and holes in the ground in which he wouldn't like to
fall.
You are given a part of landscape that Matthew wants to cross, hopefully
arriving healthy at t... |
Another date-manipulating problem :P
Task
Write a program or a function that calculates the difference between two dates given by a user.
Input & Output
Similar to the previous one, inputs are two YYYYMMDDs, separated by a space , a comma ,, or a minus sign -.
Example of input values:
20100101-20010911
20110620-20121... |
What general tips do you have for golfing in PHP? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to PHP (e.g. "remove comments" is not an answer). Please post one tip per answer.
|
Create a function that takes a string of a pinyin syllable as the argument, and returns true of the combination exists, false otherwise.
Use "v" for "ü".
Here is a full list of combinations.
http://www.pinyin.info/rules/initials_finals.html
Examples
f("bu") == true
f("zheng") == true
f("nv") == true
f("ri") == true
f("... |
We all heard of testing compilers using randomly generated inputs. Your task is to write a program to generate a valid program (including no undefined behavior) in your favorite language. The generating program language doesn't have to be the same as the generated program language.
Your program will receive an integer ... |
Your task is to write a program to print the sum of the ASCII codes of the characters of the program itself. You are not allowed to open any file (Any input such as command line arguments, standard input or files is prohibited).
The program that prints the lowest number (i.e. has the lowest sum of ASCII codes) wins.
He... |
Write a simple program that copies itself when executed.
Your program should be some kind of executable file on Windows, Linux, etc.., should generate new executable file, which is identical to your original executable file, with random name, and quits.
Your program shouldn't involve any kind of file reading or copying... |
Let's say we have a non-negative integer that is "hefty" (that is, "heavy") if its average digit value is greater than 7.
The number 6959 is "hefty" because:
(6 + 9 + 5 + 9) / 4 = 7.5
The number 1234 is not, because:
(1 + 2 + 3 + 4) / 4 = 2.5
Write a function, in any language,
HeftyDecimalCount(a, b)
which, when prov... |
Write a program that checks if a given positive integer can be represented as sum of two or more consecutive positive integers.
Example:
43 can be represented as 21 + 22
10 = 1+2+3+4
but 4 cannot be represented in this way.
Input spec: positive integer (as argument or stdin)
Output spec: truthy or falsy
Sample i/o
43 ... |
You are given n (200 ≤ n < 250) as a command line argument. Print 10 prime numbers with n digits. Your program should run under 1s and must be shorter than 5000 bytes (excluding).
Sum the digits of all your 500 primes. Program with the largest sum wins.
An example (more here):
$ ./find_large_primes 200
580216645856397... |
Write the shortest program that generates guitar tabs for the chords given as input.
So that the guitarists among you don't have an advantage, and to make it deterministic (and probably easier to code), here are the only forms of the chords authorized:
Major chords:
E F F# G G# A A# B C C# D D#
e 0... |
I'm not a 100% sure if this qualifies under this stack exchange; however, I asked this question on the stats stackexchange with no answers. I wonder if you can solve it:
Traffic light synchronization nowadays is not a tedious project, Image:
For a personal research project I'm trying to build a statistical model to s... |
Goal:
Create and save file in Vim containing at least 25 ASCII characters. The exact keystrokes used during the creation and saving of this file must also produce identical contents in Windows Notepad (without having to save in Notepad).
Rules:
For the purposes of this challenge, Vim begins open in command mode.
The m... |
Researchers recently discovered an interesting bee colony that lives in an
infinite field of honeycomb:
Each cell can house a bee or not. In fact, the lives of those creatures
appear to be a bit ... chaotic. It could be calculated that a colony
always starts with the following pattern:
(Bee drawn by
Emmanuel Bou... |
You are dealt five cards from a single deck. Implement a strategy for Jacks or Better Video Poker that has an expected revenue of at least 99.46%. Output the cards you want to hold.
The shortest code wins.
You are not required to implement the suggested strategy. Optimum play is also acceptable.
Input is read from stan... |
A woman works at a lottery ball factory. She's instructed to open up a lottery ball creation kit composed of 1 red rubber ball and n strips of digits from 0 through 9.
She's instructed to do the following:
Starting with 1, write the current number on the ball using the digits available on the n strips.
Put unused... |
Given a sequence of integers find the largest sum of a subsequence (integers on consecutive positions) of the sequence. The subsequence can be empty (in which case the sum is 0).
Input is read from standard input, one integer per line. The largest sum must be written to standard output.
I wrote a small generator for yo... |
Interpret a triple of 32-bit integers as a vector of 32 integers modulo 5. Write an addition routine for these vectors.
Example:
def add32((a0,a1,a2),(b0,b1,b2)):
c0 = c1 = c2 = 0
m = 1
for i in range(32):
a = ((a0//m)&1) + 2*((a1//m)&1) + 4*((a2//m)&1)
b = ((b0//m)&1) + 2*((b1//m)&1) + 4... |
Given the following input to the program:
List of block start characters
List of block end characters
A string to format
format the string with the blocks delimited by the two character sets indented.
Formatting is done with two spaces per level and the parentheses are placed as shown in the example below. You may as... |
You are Tom Sawyer and you have to paint a fence of 102400 m long. Luckily, your friends decided to help you in exchange of various things. Each friend will paint L meters, starting from S with color C. S, L are integer amount of meters and 1 ≤ C ≤ 97. Getting bored you decide to find out how many meters of each color ... |
Two numbers are said to be 'amicable' or 'friends' if the sum of the proper divisors of the first is equal to the second, and viceversa. For example, the proper divisors of 220 are: 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110 which sum up to 284. 284's proper divisors are 1, 2, 4, 71 and 142, which sum to 220, thus 220 a... |
Your task is to draw the mandelbrot set in ascii. It should look something like
The complex number c lies in the mandelbrot set, when the sequence z(n+1) = z(n)^2 + c, z(0) = 0 remains bounded.
For the purpose of this challenge you can consider the sequence bounded for c if |z(32)| < 2.
Plot the mandelbrot set on the ... |
Create a Markov Chain generator, which generates (and outputs) an Order 4 text chain. It must be able to support all plain text formatting used on this question, so be sure to check for punctuation (parentheses count for example, but HTML doesn't need to be accounted for fortunately)! You could even use this question i... |
The aim of this task is to identify, clean up, and mark out all the faces in any given 'image'.
What's in a face?
A face will be a ZxZ square where Z is an odd integer greater than 1. The top left and right corners and the centre will be 'O' characters, and the bottom line will be a '\' and a '/' surrounding enough '_'... |
Write the shortest function to generate the American Soundex code for a surname only containing the uppercase letters A-Z. Your function must produce output consistent with all the linked page's examples (given below), although it need not and should not remove prefixes. Hyphens in the output are optional. Have fun!
No... |
Write the shortest function that takes one string, and returns a regular expression that matches anything EXCEPT the input string, in parenthesis. Escape necessary characters like Perl quotemeta.
Input:
helloworld
Output:
([^h]|h[^e]|he[^l]|hel[^l]|hell[^o]|hello[^w]|hellow[^o]|hellowo[^r]|hellowor[^l]|helloworl[^d... |
An undulant number is a number where its digits alternate between up and down like the following number: 461902 or 708143, or even 1010101, but not 123, because
2 < 3.
Write a program or function which returns a truthy value if a number is undulant, and a falsy value otherwise. The shortest code wins.
Note: Single di... |
Create the shortest function to print a magic square of given size.
A magic square is a NxN matrix of distinct numbers and the sum of each row, column and diagonal is equal to a constant.
A magic square of size 4 is:
07 12 01 14
02 13 08 11
16 03 10 05
09 06 15 04
And the constant is 34.
The function should be able to... |
Real-world programs often use libraries like ICU to support Unicode.
The puzzle is to create the smallest possible function that can determine whether a given Unicode character is lowercase, uppercase, or neither (a commonly used Unicode character property).
You may indicate the property in any way (whatever is shortes... |
Possible Duplicate:
Golf you a quine for great good!
People have proposed short quines in various languages.
Puzzle: Find the shortest non-trivial quine in a language of your choice, and prove that it is the shortest. ("Trivial" quines are such things as the empty program, and text that will be echoed directly.)
I e... |
In The Art of Computer Programming, Knuth describes an algorithm to compute short addition chains. The algorithm works by computing a tree known as the Power Tree. The tree is rooted at 1, and each level is computed from the previous. Suppose we've computed level k. Then, for each node (n) in level k, and each ance... |
You are responsible for building a new freeway. However, it leads through
mountainous lands and therefore needs numerous bridges and tunnels. The
freeway itself should stay at a single level.
Input
You are given a rough ASCII description of how the mountains look like on
standard input, such as the following:
... |
Can you solve the eight queens puzzle at compile-time?
Pick any suitable output format.
I'm particularly interested in a C++ template metaprogramming solution, but you can use languages that have similar constructs, like, for example, Haskell's type system.
Ideally your metaprogram would output all solutions. No hardco... |
This is yet another challenge about the Fibonacci numbers.
The goal is to compute the 20'000'000th Fibonacii number as fast as possible. The decimal output is about 4 MiB large; it starts with:
28543982899108793710435526490684533031144309848579
The MD5 sum of the output is
fa831ff5dd57a830792d8ded4c24c2cb
You have ... |
On that challenge you have to solve that challenge.
Contest is over! Check the end of the question
Specs:
Write the smallest code (Any language*).
The score of an answer is the sum of:
Code length without whitespace.
Number of answers using that same language squared.
Length of the name of the biggest language on the... |
Machine epsilon is an important floating point number to know when doing numerical calculations. One way to understand it is when this relation
1 + machine_epsilon > 1
does not hold. One (iterative) way to extract it is executing a small program like the one above:
10 EPS=1
20 EPS=EPS/2
30 EPS1 = 1+EPS
40 IF EPS1 > 1 ... |
Time to dig up your old trigonometry notes from high school! The challenge is to solve the unknown sides and angles of different triangles. And as is customary in code golf, the smallest working code wins.
This is not a trivial problem; my reference implementation in python is currently down to 838 837 characters, but ... |
Given an 8x8 grid of letters representing the current state of a game of chess, your program's task is to find a next move for white that results in checkmate (the answer will always be mate in one move).
Input
Input will be on STDIN - 8 lines of 8 characters each. The meanings of each character are as follows:
K/k - k... |
Given an ascii musical score, you must be able to output the note and its corresponding length. The score will contain between 5 and 15 notes inclusive, and is transcribed on a stave. A stave is made up of five horizontal lines comprising of - (minus) characters separated by lines of spaces. The bottom line in the s... |
I'm too lazy to write a JavaDoc comment myself, there's a lot of typing and it is mostly boilerplate. Write a program to generate a JavaDoc comment with $ as a placeholder given a method specification.
Example input:
Integer method(int arg1, String arg2) throws InvalidArgumentException, NullPointerException
Example ou... |
Make a story out of your programming.
Example in JavaScript:
self.book = {
"story": function() {
var once = "upon",
aTime = setTimeout(function() {
// Code would continue...
}, 1000)
}
};
self.book.story();
Stipulations:
Must run error-free before, during, and ... |
A triangle-shaped table is constructed such the first row is "1, 3, 5, 7, ..., 99"
Each subsequent row has the following properties:
One less element than the row above
Each element is the sum of the two elements above it
Like so:
1 3 5 7 9 11 ....
4 8 12 16 20 ....
...............
This co... |
The reference implementation of CRC32 computes a lookup table at runtime:
/* Table of CRCs of all 8-bit messages. */
unsigned long crc_table[256];
/* Flag: has the table been computed? Initially false. */
int crc_table_computed = 0;
/* Make the table for a fast CRC. */
void make_crc_table(void)
{
unsigned long c;... |
According to some controversial story, the odrer of ltteres in a wrod deos not mttaer much for raednig, as lnog as the frist and lsat lteter macth with the orignial wrod.
So, for fun, what would be the shortest function to randomize letter order in a word while keeping the first and the last letter in place?
Here's my ... |
Inspired by this question.
Create a program that prompts the user to store some data, and when the program is quitting, spit out the program itself, except the session data changed.
The user then open the newly generated program, and can recall the data from the previous program.
Commands
KEY VALUE: sets session varia... |
Generic Lorem Ipsum:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris felis
dolor, bibendum at tincidunt vel, imperdiet eget libero. Cras vel
felis purus. Phasellus a vestibulum enim. Sed eu orci ac nisl sodales
scelerisque in id mi. Duis et nunc et nisl blandit aliquet ornare sed
risus. Sed arc... |
Given a list of words and a grid of letters, find all the words in the grid and remove any letters which are not part of any of the words. The words could be forwards, backwards, up, down or diagonal. You may assume that no word in the list will occur in more than one place in the grid.
Input will always be: a list of ... |
I'm a code golf novice, but I'm eager to give it a go.
My challenge is: Write the shortest program in C which takes in a date D as input and outputs the date D + 1 day
Rules:
program must compile only with gcc progname.c -o progname So no compiler/makefile tricks (if there are any) - compiler warnings don't matter
The... |
I'd like to see you create code (in any programming language) that output working BF (Brain***k) code. Your program have a single character input on stdin. The input should be one digit ("0", "1", "2", "3", "4", "5", "6", "7", "8" or "9").
Your code should output BF-code that when interpreted with a normal BF-interpret... |
Write a program which prompts a user to input two integers A and B, the program should determine whether A is greater than or lesser than B without the use of greater than [>] or less than [<] operators (and similar operators or methods like .compare) and should output :
Integer A is greater than B.
Rules : No Bra... |
I just looked and saw that there are 399 questions on this wondrous "Programming Puzzles & Code Golf" site!!! That means that...THIS IS THE 400th question!!! To celebrate this momentous occasion, here are your goals:
Write a piece of code that is EXACTLY 400 bits.
That's right...BITS!!!
For the risk of redundancy a... |
Given an integer n, enumerate all possible full binary trees with n internal nodes. (Full binary trees have exactly 2 children on every internal node). The tree structure should be output as a pre-order traversal of the tree with 1 representing an internal node, and 0 representing an external node (Null).
Here are exam... |
(This code golf task is related to Code-Golf: Lights Off!. The same puzzle is used, but the task is different.)
Introduction
"Lights Out" is a puzzle in which you should switch off all lights in a 5x5 grid. However, when you swap a light from on to off, or from off to on, the four adjacent lights will swap as well!
Fo... |
Conway's Game of Life is the classic example of cellular automation. The cells form a square grid and each has two states: alive or dead. On each turn, each cell simultaneously updates according to its state and those of its eight neighbours:
A live cell remains alive if it has exactly two or three live neighbours
A d... |
Given n points, choose a point in the given list such that the sum of distances to this point is minimum ,compared to all others.
Distance is measured in the following manner.
For a point (x,y) all 8 adjacent points have distance 1.
(x+1,y)(x+1,y+1),(x+1,y-1),(x,y+1),(x,y-1),(x-1,y)(x-1,y+1),(x-1,y-1)
EDIT
More cleare... |
This is an interesting one.
I have written a short program in objective-c to encode a string into a brainf_ck string, this is what it looks like:
NSString *input; // set this to your input string
NSMutableString *output = [[NSMutableString alloc] init];
int currentPosition = 0;
for (int i = 0; i<[input length]; i++) {
... |
A spoonerisation is swapping the first letter/pronounceable syllable of two or more words.
Example: A lack of pies = A pack of lies. Bad salad = Sad ballad (ish) :)
Challenge: Write a program to spoonerise two words in the shortest characters possible.
Rules:
If the first letter is a consonant, you must include subseq... |
Choose Your Own Adventure books are a form of interactive literature where the reader must
make decisions that affect the outcome of the story. At certain points in the story, the
reader has multiple options that can be chosen, each sending the reader to a different page
in the book.
For example, in a fantasy setting, ... |
Given a space-separated list of integers, your task is to find the next integer in the sequence.
Each integer in the sequence is the result of applying a single mathematical operation(+,-,* or /) to the previous integer, and each sequence is made up of a variable number of such operations (but no more than 10). No sequ... |
Matthias Goergens has a 25,604-character (down from the original 63,993-character) regex to match numbers divisible by 7, but that includes a lot of fluff: redundant parentheses, distribution (xx|xy|yx|yy rather than [xy]{2}) and other issues, though I'm sure a fresh start would be helpful in saving space. How small c... |
Rules:
In this game you start at the top of a rectangular grid of size N x M made up of walls and open spaces. The input is N lines of M characters, where a . specifies an open space and a x specifies a wall. Your program should output the smallest number K such that there exists a path from the top left corner to the ... |
Given a non-negative integer n, enumerate all palindromic numbers (in decimal) between 0 and n (inclusive range). A palindromic number remains the same when its digits are reversed.
The first palindromic numbers (in base 10) are given here:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101,
111, ... |
This is a teaser a friend of mine sent. It seems straightforward, but I can't seem to get my head around it, probably due to my lack of sleep.
You have 16 bits available.
Compose a function, and find a way to know when the function has run approximately one million times.
You MAY NOT use any additional memory space o... |
This comes from one of my favorite interview questions, though apparently it is now a fairly well-known puzzle. I have no way of knowing, but if you have already heard the answer it would be polite to let others try instead.
Task:
Write a function that takes as input a singly-linked list and returns true if it loops ba... |
Here's a problem to which I don't know the answer. Suppose you have an ordered list of integers with an operator in between each consecutive pair. Let's restrict ourselves to three operations that are closed over the integers, namely addition, multiplication and subtraction. Is there a good way to find the order we sho... |
Taking an array of records. For example
[
name: 'eventA', timestamp: '2011-08-27 15:34:00',
name: 'eventB', timestamp: '2011-08-28 13:31:00',
name: 'eventC', timestamp: '2011-08-29 10:34:00',
name: 'eventD', timestamp: '2011-08-30 16:36:00',
]
How can I sort these by timestamp in a descending using a standard natural ... |
This is an ai-player challenge. Your goal is to reach the number 2011 as quickly as possible, or to get as close to it as you can.
Rules:
A "hole" consists of a rectangular grid of digits (0-9).
Your total starts at 0.
You may start at any digit on the grid. This is your first "stroke."
For each subsequent stroke, you... |
Challenge:
Given a Sudoku board on standard input, find the minimum number of numbers added to make the board unique.
Specifics/Rules:
The input is formatted as follows (all whitespace is significant)
516|827|943
278|394|615
349|615|872
---+---+---
98 |4 2|156
465|189|237
12 |5 6|489
---+---+---
892|743|561
634|951|72... |
The challenge
Given a bagatelle board like the one below:
| |
| /\ / |
| \ /|
| \ \ /\ \ |
| \ / \ |
|\ / / \ |
| \ / \ |
| \ |
| \ / \ /\ \ |
|\ / / \ /|
| / |
| /\ ... |
Build a regex that will accept a regex string as input and check if it's valid. Basically, your regex should be able to validate itself. (Any invalid regex should not be validated, so you can't use .*. ;))
Your flavor must be fully supported by well known implementations (Perl, sed, grep, gawk, etc), and it must fully ... |
This is a code-golf challenge: Given a specific board in the game of Othello (Reversi), find a move for Black that will capture the maximum number of White pieces.
(Obviously, this may not be the true "optimal" play for Black, but to keep things simple we are only interested in finding the move that will capture the mo... |
A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-1.
So the sequence [4,1,2,4] has absolute differences [3,1,2] which is equivalent to the set [1,2,3] (1 to n-1 where n is the length of original sequence) so it i... |
Suppose a codegolf challenge doesn't count whitespace in the length of your program. Cheat this system by encoding your script into whitespace, and golf a script which decodes and executes embedded whitespace.
Example
My solution to JBernardo's Meta Golf Challenge was to encode Sage (or Python) code into whitespace, a... |
Your goal is to write a flag semaphore encoder, which will convert a given sentence into the corresponding flag semaphore characters, according to the semaphore system described on Wikipedia.
Assume that the input is a single sentence provided through stdin (or equivalent). Your output should be a series of semaphore c... |
Your job, should you choose to not refuse it, is to write a program that will "golf" a piece of given code in your language of choice.
Basic functionality:
Remove extraneous whitespace
Remove comments
'Advanced' functionality:
Combine declarations (int x; int y; int z; to int x, y, z;)
Use shorter variations of basi... |
Objective
Given an arbitrary chessboard as standard input (in which each piece is on a square), produce as standard output a list of moves needed to regularize, or set up, the chessboard. The moves need not be legal, yet no piece may be placed above another. The program must warn about any missing or additional pieces;... |
Here is a real question somebody asked me. Suppose you have n teams, one terrain.
Each team must play each other team exactly once.
The number of times a team plays two matches in a row should be minimized.
The problem is hard if not optimized. Your program should be able to answer this question for up to 6 teams (at... |
From codegolf.com (not loading as of Sept 15, 2011) was one that was driving me crazy. Print to STDOUT a clock of an exacting form, reading time from STDIN and marking an h at the hour and m at minute (rounded down to a multiple of 5) and an x if they overlap, unused ticks are marked with an o, so that
echo "23:13" | ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.