Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code. If you want to score by characters instead of bytes, please state this explicitly in the challenge. If source code length is not the primary scoring criterion, consider using another tag instead.

Filter by
Sorted by
Tagged with
1
vote
2answers
840 views

Swaps needed to sort an array in bubble sort method

Write shortest code that detect how many swaps (minimum) are needed to sort (in increasing order) any array of unique positive integers. It should be fast enough to detect number of swaps in array of ...
12
votes
16answers
806 views

Find one-handed words

'exaggerated' is an example of a word which can be typed on the left hand, on a normal qwerty keyboard map. 'monopoly' is an example for the right hand. Searching the unix ...
5
votes
4answers
544 views

Implement Oplop

Oplop is an algorithm to generate website specific passwords based on a master password and a keyword. It is described here: http://code.google.com/p/oplop/wiki/HowItWorks There's an online ...
-5
votes
14answers
860 views

Square of the number of ones

I'm solving problem: in file "a.in" given the number N - length of the number consists of ones. Need to gets square of it, and put this in file "a.out". This is my shortest solution(150 bytes): ...
1
vote
5answers
675 views

Pluralize it!​​

The challenge: Write a program or function in any language that takes as an argument (command-line or function) a single English word. It returns or outputs the pluralized form of the word. (To ...
31
votes
66answers
6k views

Determine if a number is divisible by 13 (without using 13 itself) [closed]

Your challenge, should you choose to accept it, is to create a function or a program that outputs "yes" if a given number is divisible by 13 and outputs "no" if it isn't. Rules: - You're not allowed ...
11
votes
8answers
1k views

ASCII ruler generation

The challenge is to generate an ASCII character count ruler in the following format: ...
6
votes
3answers
674 views

Implementing a firewall

Your program reads from standard input and prints to standard output. The first thing you'll be receiving on stdinput will be the ruleset for your firewall (until you encounter a double newline). We'...
7
votes
4answers
812 views

Convert __DATE__-style string to sortable string

Goal is to write the shortest possible C89 and C99-compliant single-module C program which will compute and print out a single-line string whose sort order will correspond with the date given by the ...
16
votes
6answers
1k views

Generate Random Boggle Board

Generate a 4x12 grid of letters / spaces: Each die should appear precisely once, location randomly chosen. Locations should be approximate a uniform random permutation of the dice. Display a random ...
19
votes
17answers
3k views

Print a Cantor Set

The Challenge Build a N-Leveled Cantor Set. The Cantor ternary set is created by repeatedly deleting the open middle thirds of a set of line segments. The program receives one parameter ...
19
votes
3answers
3k views

Hashiwokakero: Build bridges!

Hashiwokakero ("build bridges" in Japanese) is a puzzle where you are tasked with connecting a group of islands with bridges. The rules are: Bridges must run either vertically or horizontally between ...
38
votes
9answers
5k views

Text compression and decompression — “Nevermore.”

With the recent discussion about the use of compression tools in code golf, I thought it would be a nice challenge to write your own text compressor and decompressor. Challenge: Write two programs: ...
7
votes
12answers
1k views

“First time” test

What is the shortest C expression that is defined to evaluated to false the first time and true for every time after that: Reference implementation: ...
6
votes
1answer
658 views

String manipulation

The challenge is to manipulate strings using basic Vim-like commands Input: A string of text to be transformed. The input alphabet is [a-z]. A string of legal commands Output: The transformed ...
5
votes
5answers
561 views

An Old Irish Blessing, reasked (without using encodings)

How much can you golf a program to print "An Old Irish Blessing" without using unprintable ASCII characters? That restricts us to ASCII characters 32-126 (better still, 32,65-90,97-122 and 13(CR)) ...
43
votes
37answers
14k views

Outputting ordinal numbers (1st, 2nd, 3rd)

I would like to generate (as a return result of a function, or simply as the output of a program) the ordinal suffix of a positive integer concatenated to the number. Samples: ...
29
votes
2answers
3k views

ASCII art 3D StreetView

Input: You get a series of integers (fed via stdin or prompt). Every pair of integers in this series represents a building's WIDTH [valid range: 1..10] and HEIGHT [valid range: 0..10] Assume input to ...
11
votes
30answers
4k views

First-n Fibonacci sequence elements

There is a well known question here that asks for a short (least characters) fibonacci sequence generator. I would like to know if someone can generate the first N elements only, of the fibonacci ...
18
votes
20answers
2k views

Find columns where all characters are the same

I came across this question on SO and thought it'd make a nice golf challenge. So here it is: Challenge: Write a program that reads a sequence of character strings, one per line, and outputs a list ...
4
votes
2answers
806 views

HangOver ACM problem!

there is only one rule: get accept for this problem http://acm.ut.ac.ir/sc/problemset/view/1032! to submit your code, you need to create an account(if you don't want to do so, just post your code ...
8
votes
8answers
2k views

Ascending Pea Pattern generator

For those who are not familiarized with the Pea Pattern, it is a simple mathematical pattern. There are multiple variations of this pattern, but we will focus in one: Ascending Pea Pattern It ...
19
votes
9answers
5k views

Generating PBM bitmap files from ASCII text

The PBM (Portable BitMap) format is a very simple ASCII black and white bitmap format. Here's an example for the letter 'J' (copy-pasted from the wikipedia link): P1 # This is an example bitmap of ...
17
votes
31answers
2k views

Finding Not-Quite-Prime Numbers

Your challenge, should you chose to accept it, is to code-golf a function that returns true or false (or some similar meaningful representation of yes and no) if a number meets the following criteria: ...
12
votes
3answers
1k views

Convert from Infix Notation to Prefix Notation

Given an arithmetic expression, which can include parentheses (()), exponents (^), division (...
9
votes
3answers
693 views

Shortest route through a one-way system

My home town, Rhyl, has a one-way traffic system which seems to have been designed to keep people away from their destination for as long as possible. Your task, should you choose to attempt it, is to ...
6
votes
5answers
2k views

Show Ulam's spiral

Similar to this but in this one you need to write spiral starting from the center where: space means composite number .(dot) means prime number. Size of the ...
6
votes
24answers
4k views

determine longest group of consecutive numbers

INPUT: 10 random numbers each number is greater than 0 and less than 100 list of numbers is presorted, lowest to highest the list will not contain any duplicate numbers CHALLENGE: Write a function ...
11
votes
13answers
2k views

Hello World Rainbow

Dealing with colors in non-markup languages often complicates things. I would like to see some variations of how color is used in different languages. The object of this competition is to output '...
25
votes
9answers
9k views

Recreate a 'Snake' game in a console/terminal

Games are fun this codegolf here was so fun I had to make a version for other classic games similar in complexity. Shortest Way of creating a basic Space Invaders Game in Python This time, however, ...
4
votes
3answers
8k views

List of paths to nested dictionary

Given a list of nested menu items, ...
2
votes
17answers
685 views

The group of sequential positive numbers with the highest sum?

Given the following list of numbers, find the group of sequential positive numbers with the highest sum. Example input: 12 2 35 -1 20 9 76 5 4 -3 4 -5 19 80 32 -1 ...
15
votes
12answers
2k views

Convert from binary to negabinary

Given a binary integer inclusively between 0 and 1111111111111111 (i.e. a 16-bit unsigned integer) as input, output the same ...
14
votes
47answers
5k views

Print the amount of ones in a binary number without using bitwise operators

Description Given a number, print the amount of 1s it has in binary representation. Input A number >= 0 in base 10 that ...
21
votes
4answers
2k views

Optimal short-hand roman numeral generator

Goal: Write a function that takes a number as input and returns a short-hand roman numeral for that number as output. Roman Numeral Symbols: ...
4
votes
14answers
963 views

Write the shortest code to match a tail-repeating string where one character falls off the head in each repetition

In this code-golf, you will attempt to match a string that is tail-repeating with one character falling off the head on each iteration. The code needs to be able to accept a string, and return to the ...
6
votes
3answers
1k views

Write a base X to base Y function [duplicate]

Create a function 'baseXtoY' which: converts an integer or string n, which is a base x number (hexadecimal, binary, etc) into a ...
7
votes
9answers
4k views

ASCII Tux (Linux Penguin) [closed]

I once hacked upstart on my Ubuntu box so that a colored, themeable ASCII Tux displayed on the screen with the boot messages scrolling beneath him. I'm curious to ...
5
votes
1answer
3k views

Shortest Way of creating a basic Space Invaders Game in Python

Your challenge is to create a basic version of Space Invaders in Python Rules Program must be not written in Py3K All levels must be randomly generated There must be a HUD showing the players score ...
79
votes
53answers
26k views

Shortest code that raises a SIGSEGV

Write the shortest code that raises a Segmentation Fault (SIGSEGV) in any programming language.
7
votes
7answers
2k views

Shortest code that return SIGSEGV among the given languages [duplicate]

I come across a question in a coding competion "write a code that returns SIGSEGV(Segmentation fault ) " . Points were given on the basis of length of code. The prgramming languages available ...
4
votes
5answers
474 views

Celsius - Fahrenheit anagram

Task Make a complete program or a function which calculates sum of all temperatures which, when written in Celsius and Fahrenheit scale, are anagram of each other. Description For example, ...
11
votes
3answers
486 views

The Sleigh Packing problem

Santa's elves need help in determining if their current batch of presents will fit into santa's sleigh. Write the shortest program possible in the language of your choice to help them out. ...
0
votes
0answers
229 views

Python - Reverse Polish Notation [duplicate]

Possible Duplicate: Reverse Polish notation Create a function named rpn in python to evaluate a string written in Reverse Polish notation Numbers must be ...
14
votes
5answers
1k views

Simulate any 1D cellular automaton

The Challenge You are to write a complete program that takes seven numbers from STDIN, and prints the two dimensional history of the cellular automaton (CA) to STDOUT. This is code golf. Input ...
18
votes
1answer
1k views

Lose at tic-tac-toe

Write a program that a will play a game of Misère tic-tac-toe. That is, the goal is to force your opponent to take three in a row. Accept on standard input either an 'X' or an 'O'(the letter, not ...
14
votes
19answers
6k views

Say “Hello” to the world in ASCII art

Challenge: Produce the following output using as few chars as possible: ...
18
votes
1answer
1k views

I used to solve code golf puzzles like you, but then I took an arrow in the knee

Getting hit in the knee with arrows seems to be the injury of choice right now. As such, I propose the following golf challenge. You have an adventurer that looks like this: ...
22
votes
4answers
3k views

ASCII animated snow scene

Write the shortest program to turn any piece of ASCII art into an animated snow scene that begins to form from the falling snow (non-golfed JavaScript example last updated 2011-12-19). Input ...
-7
votes
7answers
903 views

Smple way to get min & max

You will take a set of input numbers, and output the minimum and maximum of the set. You can either write two programs, with 1 program doing each function, or one combined program. Here's an example ...