code-golf

Code Golf: Frobenius Number

Write the shortest program that calculates the Frobenius number for a given set of positive numbers. The Frobenius number is the largest number that cannot be written as a sum of positive multiples of the numbers in the set. Example: For the set of the Chicken McNuggetTM sizes [6,9,20] the Frobenius number is 43, as there is no solution...

Checking whether a number is mathematically a perfect number

The algorithm should check a given number and return 'true' if it is a perfect number or 'false' if it is not. The wikipedia definition of a perfect number: In mathematics, a perfect number is a positive integer that is the sum of its proper positive divisors, that is, the sum of the positive divisors excluding the number it...

Code Golf: XOR Encryption

From: Encryption Co. To: x$*sj4 (that's you) Your mission, should you choose to accept it, is to create a program in the shortest number of keystrokes that Takes two filenames parameters (either command line or stdin), the first is a file containing the key and the second some message. Both files will be plain text. Applies the key t...

Code Golf: Conway's Game of Life

The Challenge: Write the shortest program that implements John H. Conway's Game of Life cellular automaton. [link] EDIT: After about a week of competition, I have selected a victor: pdehaan, for managing to beat the Matlab solution by one character with perl. For those who haven't heard of Game of Life, you take a grid (ideally infinit...

Code Golf: Regex parser

The goal Today's Code Golf challenge is to create a regex parser in as few characters as possible. The syntax No, I'm not asking you to match Perl-style regular expressions. There's already a very reliable interpreter for those, after all! :-) Here's all you need to know about regex syntax for this challenge: A term is defined as a...

Code Golf: Movement in 3 Dimensions

Assuming a 3 dimensional irregular matrix where y = 1.5(x) and z = .5(y). Further assuming an object starts at 0,0,0 and must move positively in at least two dimensions, and must move in all three dimensions (x+1, y+1, z-1 is okay, x+1, y+1, z=z is not). It may move any number of "spaces", but must move the same number in all direction...

Code Golf: Happy Primes!

It's Sunday, time for a round of code golf! Challenge Write the shortest source code by character count to determine if an input number is a "happy prime", "sad prime", "happy non-prime", or "sad non-prime." Input The input should be a integer that comes from a command line argument or stdin. Don't worry about handling big numbers, ...

Code Golf: Calculate Orthodox Easter date

The Challenge Calculate the Date of the Greek Orthodox Easter (http://www.timeanddate.com/holidays/us/orthodox-easter-day) Sunday in a given Year (1900-2100) using the least amount of characters. Input is just a year in the form '2010'. It's not relevant where you get it (Input, CommandLineArgs etc.) but it must be dynamic! Output sho...

Code Golf: JSON Binary Encoding/Decoding

The Challenge Encode ANY series of integers, floats, strings, nulls, booleans and arrays/objects of them, into a binary format and decode it again. The term object refers to a HashMap/Dictionary At the top level there's always a surrounding array or object, depending on the input The Test Input [-1, 0.1, 0, 'Foo', {'b': 8388608.25...

Code Golf: recognize ascii art boxes

Came up with this a while ago while doing some data structure work, though it'd make a good code golf: Given a two dimensional array of characters containing ascii art rectangles, produce a list of coordinates and sizes for the rectangles. Any trivially convertable input or output format is fine (eg: char**, list of strings, lines on ...

Code Golf: draw ascii art stars

Since this week noone has posted a code-golf challenge, I'll give it a try. I do it so you can do something other than playing with swords during those long compile cycles. The challenge: Draw ASCII art stars, given three numbers on standard input (number of spikes, type of star (star is drawn by joining vertices that are n vertices ap...

Solve this PHP puzzle in as few bytes as possible

*EDIT: since some folk's panties are apparently bunching uncomfortably over this, how about just recommending some efficient ways of dealing with similar code? Maybe not specific answers to the problem I posed (my goal anyway, this bit of code golf was merely a means to finding more concise ways of dealing with the basic problems present...

Code Golf: Playing Tetris

The basics: Consider the following tetrominoes and empty playing field: 0123456789 I O Z T L S J [ ] [ ] # ## ## ### # ## # [ ] # ## ## # # ## # ...

Code Golf: Morris Sequence

The Challenge The shortest code by character count that will output the Morris Number Sequence. The Morris Number Sequence, also known as the Look-and-say sequence is a sequence of numbers that starts as follows: 1, 11, 21, 1211, 111221, 312211, ... You can generate the sequence infinitely (i.e, you don't have to generate a specific n...

Async Google Analytics [Javascript Golf]

Unfortunately, this may not be a valid Code-Golf question as it is likely Javascript only; however, since this is likely to be the only useful-in-the-real-world code-golf contest I'm going to go ahead and post it. The Google Analytics Asyncronous Tracking snippet is used by many websites. The script goes a little something like this:...

Difference of sums

I take no credit for this challenge at all. It's Project Euler problem 6: The sum of the squares of the first ten natural numbers is, 1^(2) + 2^(2) + ... + 10^(2) = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)^(2) = 55^(2) = 3025 Hence the difference between the sum of the squares of the first ten ...

Code Golf: DNA Sequences

Let's give the GMO guys something to cry about: Goal: Generate a sequence of DNA base pairs (A, T, G or C), 78 pairs long (not a big gene...), terminated by a newline, and print it. Rules: The lines must be exactly 78 characters long with a terminating newline, and while the program can give the same result if invoked twice in a row, i...