code-golf

Code-Golf: Modulus Divide

Challenge: Without using the modulus divide operator provided already by your language, write a program that will take two integer inputs from a user and then displays the result of the first number modulus divided number by the second number. Assume all input is positive. Example: Input of first number:2 Input of second numbe...

Code-Golf: one line PHP syntax

Explanation PHP has some holes in its' syntax and occasionally in development a programmer will step in them. This can lead to much frustration as these syntax holes seem to exist for no reason. For example, one can't easily create an array and access an arbitrary element of that array on the same line (func1()[100] is not valid PHP syn...

Code Golf: Zigzag pattern scanning

The Challenge The shortest code by character count that takes a single input integer N (N >= 3) and returns an array of indices that when iterated would traverse an NxN matrix according to the JPEG "zigzag" scan pattern. The following is an example traversal over an 8x8 matrixsrc: Examples (The middle matrix is not part of the input...

Code Golf: Rotating Maze

Code Golf: Rotating Maze Make a program that takes in a file consisting of a maze. The maze has walls given by '#'. The maze must include a single ball, given by a 'o' and any number of holes given by a '@'. The maze file can either be entered via command line or read in as a line through standard input. Please specify which in your s...

Code Golf: ASCII Art number

Possible Duplicate: Code Golf - Banner Generation Post your shortest code to convert a number into a ASCII art digits. Input - Assume that an integer variable called z has already been set containing the number. Output - Print the output to the console. Quality - The lower number of characters, the better. Formatting - Fle...

Code Golf (sort of): a Functional Puzzle

Here's a puzzle: define some higher-order function f such that, using only f and parentheses, you can define the three higher-order functions const, id and bothOn. Those three functions could be defined in a straightforward way and in the Haskell programming language as follows: -- takes two arguments, ignores the second and returning ...

IP addresses range

Given an IP address and mask like 192.168.10.30/24 on STDIN, return the matching range of addresses. i.e. input : 192.168.10.30/24 output: 192.168.10.0-192.168.10.255 input : 127.0.0.0/31 output: 127.0.0.0-127.0.0.1 libraries/packages/... are NOT allowed ...

Code golf: Word frequency chart

The challenge: Build an ASCII chart of the most commonly used words in a given text. The rules: Only accept a-z and A-Z (alphabetic characters) as part of a word. Ignore casing (She == she for our purpose). Ignore the following words (quite arbitary, I know): the, and, of, to, a, i, it, in, or, is Clarification: considering don't: ...

Code golf: "Color highlighting" of repeated text

(Thanks to greg0ire below for helping with key concepts) The challenge: Build a program that finds all substrings and "tags" them with color attributes (effectively highlighting them in XML). The rules: This should only be done for substrings of length 2 or more. Substrings are just strings of consecutive characters, which may inc...

Code Golf: 2D Platformer

The Challenge Reach the end of the level! Bonus points if you hit each of the (C)oin blocks exactly 2 times. Disallowed Hard coding the command sequence in any way. Your favorite "One character language" that happens to do exactly one thing, which is solving this golf. How To Your program receives the level below(without lin...

Code Golf: Pig Latin

Challenge: Take a sentence of input of any length and convert all the words in that sentence to pig latin. If you do not know what pig latin is please read Wikipedia: Pig Latin. Specifications: Assume all words are separated by spaces and all sentences either end with a exclamation, question mark or period. Do not use the variant for...

Code Golf: Four is magic

The puzzle A little puzzle I heard while I was in high school went something like this... The questioner would ask me to give him a number; On hearing the number, the questioner would do some sort of transformation on it repeatedly (for example, he might say ten is three) until eventually arriving at the number 4 (at which point he wo...

Code golf: Digital clock

Possible Duplicate: Code Golf: Seven Segments The task: Write the smallest possible program (least number of characters) that takes input in the hh:mm format and outputs this as a digital clock (seven-segment display). Sample input: 19:27 Sample output: _ _ _ | |_| . _| | | _| . |_ | Sample input: 11:...

Code Golf: The Unisex Restroom Simulation

Background The unisex restroom problem is a classical synchronization problem in computer science. The general class of problems that this simulates is as follows: If you have k types of threads that need to execute tasks using n shared resources, and at any time only one thread type may be using the resources, then it's a generalizati...

Code Golf - Generate nearby page numbers based on the current page

The challenge is to create an algorithm for generating a specifically-sized subset of numbers in a sequence based on the current position in that sequence. While navigating through the many pages of content on a busy site like Stack Overflow or Digg it is often desirable to give the user a way to quickly jump to the first page, the last...

Code Golf: Who has the best poker hand?

I love challenges like this, I'll hopefully submit my answer soon. Which player has the best 7 card hand? Given an unordered list of 9 cards (separated by a space), work out which player has the best poker hand. Here is a list of poker hand rankings. Example input: 2C 5H AS KS 2D 4D QD KH 3S (ie: [[2C 5H] [AS KS] [2D 4D QD KH 3S]]) ...

Code Golf: Build Me an Arc

Challenge The shortest program by character count that accepts standard input of the form X-Y R, with the following guarantees: R is a non-negative decimal number less than or equal to 8 X and Y are non-negative angles given in decimal as multiples of 45 (0, 45, 90, 135, etc.) X is less than Y Y is not 360 if X is 0 And produces on ...

Code-golf: Output multiplication table to the Console

Hi, I recently pointed a student doing work experience to an article about dumping a multiplication table to the console. It used a nested for loop and multiplied the step value of each. This looked like a .NET 2.0 approach. I was wondering, with the use of Linq and extension methods,for example, how many lines of code it would take to...

Shortest way to print "Success"

I have been trying this problem SUCCESS at spoj but I am not able to get optimal solution to that problem I tried int main(){return !puts("Success");} but it takes 45 characters. Any alternate suggestions to solve the problem? People have solved it using 24 characters also. ...

Smallest Google Homepage

Inspired by this and this topic about the fact that Google's homepage isn't validating, just because of performance issues (1 byte less saves gigabytes of data traffic a day), I wondered: What is the smallest possible HTML-file that renders Google Homepage correctly in at least one browser? By Google Hompage I mean the most simple vers...