All Questions

Filter by
Sorted by
Tagged with
8
votes
4answers
389 views

The fourth power (Juzuk)

In 1939 Juzuk described a way to generate the fourth powers of natural numbers. Group the natural numbers like this: ...
78
votes
101answers
13k views

Hello World 0.0!

source: Dilbert, September 8, 1992 I'm hoping to add a new twist on the classic "Hello World!" program. Code a program that outputs Hello World! without: String/...
32
votes
14answers
2k views

Draw a Suanpan abacus

Write the shortest program that takes a single integer as input and prints out a Suanpan abacus Testcases Input: 314159 Output: ...
8
votes
2answers
636 views

Simple Geometric problem

This problem (see below) has been given as a High School Programming League code golf challenge. The shortest codes submitted during the contest were: 177 bytes in Ruby, 212 bytes in Python 2.5, 265 ...
15
votes
10answers
3k views

Calculate digits of Pi

This is a somewhat different task. Calculate 1024 hexadecimal digits of π, beginning at the 1024th hexadecimal place. Formally: Your program should complete in less then 1 minute and produce the ...
14
votes
3answers
476 views

Permutation group operation

There is a well-known bijection between the permutations of n elements and the numbers 0 to n!-1 such that the lexicographic ordering of the permutations and the corresponding numbers is the same. For ...
29
votes
36answers
11k views

Determine if 4 points form a square

Write a function that takes 4 points on the plane as input and returns true iff the 4 points form a square. The points will have integral coordinates with absolute values < 1000. You may use any ...
10
votes
7answers
787 views

Circles of text

Find a way to make circles of a given radius using characters in a console. Please specify the font name and size. Also, please provide at least one example of the output. For example: Input: ...
46
votes
78answers
7k views

Answer to life, the universe, and everything

Task Given a String as input, your task is to output 42 only if the input String happens to be exactly the following : ...
12
votes
8answers
1k views

Quine Challenge I

Challenge In this task you have to write a program that will take input an integer N (-1e9 <= N < 0 && 0 < N <= +1e9), then compute T = (abs(N) % M+1),if N is positive ...
7
votes
2answers
625 views

GolfScript - The missing function

The GolfScript language has one serious lack, no float or fixed point handling. Remedy this by creating a function F for converting an integer number, given as a string, to a string representing 1 / ...
20
votes
46answers
2k views

Detect rotated strings

Read two strings from stdin. Output Yes if one string is a rotated version of the other. Otherwise output ...
12
votes
1answer
3k views

Solve the 8 Puzzle

The 8 Puzzle is the smaller variant of the 15Puzzle (or the Sliding puzzle). You have a 3x3 grid which is filled with numbers from 0-8 (0 denotes the blank tile) ...
7
votes
4answers
559 views

Obtain a number from 4 numbers using any combination of mathematical operations [closed]

Given 4 numbers n1, n2, n3, n4, and a goal n5, obtain n5 using n1 through n4 combined with any operations. Eg. Given four numbers 2,3,4,5 and the goal as 8, output (one of many) is ...
5
votes
8answers
801 views

Code Golf: Number of paths!

Challenge Consider a square matrix of order N(N rows and N columns). At each step you can move one step to the right or one step to the top. How many possibilities are to reach (N,N) from ...
8
votes
2answers
575 views

Turn 2D boolean array into (rectilinear) polygons

Challenge Write a program which, given a 2-dimensional boolean array (equivalently, a monochromatic bitmap), outputs a series of polygons that describe the outline of the region that is “true” (1). ...
85
votes
133answers
11k views

Determine whether strings are anagrams

Challenge Given two strings, work out if they both have exactly the same characters in them. Example Input word, wrdo This returns true because they are the ...
18
votes
49answers
3k views

Chessboard pattern

Input: a positive number, smaller then 80, from stdin or as a command-line argument. Output: A square chessboard pattern, the size of the input number. The dark fields are represented by the letter '...
3
votes
1answer
362 views

Check printer - Convert to English text from the input value.

Check printer function (or subroutine) - Convert to English text from the input value. 12.34 -> "twelve dollars and thirty four cents". For the range .01 to 9999.99 assuming valid input.
6
votes
3answers
576 views

Break the broken hash [closed]

Some time ago, I found this unused hash function (written in Java) in our codebase: ...
17
votes
4answers
2k views

ASCII art Bresenham line drawing

Write the shortest possible program that draws a Bresenham line in ASCII art. Your program should take two integers x and y (...
12
votes
12answers
2k views

Hitting 495 (Kaprekar) [duplicate]

Input: A three digit number from stdin or as an argument not all digits are the same may start with one or two zero's Process Order the input-digits ascending and descending to form two new ...
4
votes
4answers
298 views

Rotate Cartesian coordinates.

Write a program rotates some Cartesian coordinates through an angle about the origin (0.0,0.0). The angle and coordinates will be read from a single line of stdin in the following format: ...
-3
votes
3answers
335 views

Shorten this code while fixing a major bug [closed]

I found the code below today after much hair pulling. Shorten it down (code golf) and fix the bug that I found (bonus). ...
11
votes
7answers
3k views

Implement Shamir's Secret Sharing reconstruction

Shamir's secret sharing scheme is a simple way of protecting a secret by splitting it into several parts needed to reconstruct it. Your task is to implement Shamir's Secret Sharing reconstruction ...
12
votes
1answer
811 views

Break the broken cipher

I have designed a simple random generator that cycles two numbers in a chaotic way using a multiply and modulus method. It works great for that. If I were to use it as a cipher generator it would ...
10
votes
20answers
887 views

Calculate probability of getting half as many heads as coin tosses.

Write a program that, given a small positive even integer from standard input, calculates the probability that flipping that many coins will result in half as many heads. For example, given 2 coins ...
10
votes
13answers
2k views

Draw a BCD Binary clock

Create a BCD binary clock in ASCII. As implied, it shall display time in six columns of dots: (source: Wikimedia Commons) Each column is a binary-coded digit, reading hours, minutes and seconds ...
8
votes
8answers
2k views

Output a playable crossword grid

Write a program to produce a file containing a crossword grid that the user can print out and work the puzzle on. Input A filename representing a crossword grid file and optionally a second ...
4
votes
6answers
686 views

Write a program to perform set operations.

Your task is to write a program to perform set operations. The operations and arguments are taken from command line in the format program operation [argument]. ...
14
votes
49answers
7k views

Sum of positive integers. [closed]

Problem: Given a set of integers, find the sum of all positive integers in it. Input: t – number of test cases [t < 1000] On each of next t lines, an integer N [-1000 ≤ N ≤ 1000] Output The ...
9
votes
14answers
1k views

Numbers, Sums, Products

Given a 20×20 grid of non-negative integers, find a 3×3 sub-grid where the product of the sums of the individual lines hits the maximum. Spoken in formulas: Given the 3×3 sub-grid the function to ...
11
votes
14answers
968 views

Percentage of work days in a month

Given a year and a month, find out the percentage of work days in said month. Work days are Monday through Friday with no regard to holidays or other special things. The Gregorian calendar is used. ...
12
votes
13answers
988 views

Make a number palindrome

Write a function that takes a number as an argument and makes it a palindrome by appending minimum number of digits. The number will be at max of 100 digits. ...
26
votes
19answers
4k views

My Word can beat up your Word

PROBLEM Given two words, find the winner in a digital root battle. Define the digital root of a word this way: Each letter of the alphabet is assigned a number: A = 1, B = 2, C = 3, ..., Z = 26 ...
13
votes
1answer
1k views

Implement PCRE in your language.

Note: After trying this myself, I soon realized what a mistake this was. Therfore, I am modifying the rules a bit. The minimum required functionality: Character classes (...
10
votes
14answers
2k views

Guess the number

Description Create a fully working "Guess the number" game. The game is played by two players as follows: player one chooses a number (A) between 1 and N player two tries to guess A choosing a ...
8
votes
7answers
396 views

Shortest Port Scanner

Write the shortest program that will attempt to connect to open ports on a remote computer and check if they are open. (It's called a Port Scanner) Take input from command line arguments. ...
40
votes
86answers
7k views

What's my name? Produce the name of the language indirectly [closed]

Produce only the name of a programming language using only the facilities of the language itself. The name of the language can only be invoked indirectly, i.e., from non custom environment variables, ...
54
votes
21answers
5k views

Add a feature to a programming language [closed]

Your task is to tack on a feature to a programming language, either by implementing a very clever library, or by processing the input text and/or tweaking the compilation process. Ideas: Add PHP-...
4
votes
2answers
379 views

Implement cdbmake

Write the shortest program to build a cdb database, using the following syntax for input: +klen,dlen:key->data followed by a newline. Example: ...
-3
votes
9answers
370 views

Mixed up output [duplicate]

Write a function or program that outputs the following lines <input> time: ...
17
votes
7answers
2k views

The Tic Tac Toe Dictionary

A TicTacToe game can be represented by a string denoting the sequence of positions as the players make their move. 0 1 2 3 4 5 6 7 8 Assume ...
9
votes
5answers
433 views

Golfed fixed point combinator

Write a fixed point combinator in as few characters as possible, in the language of your choice. free form (i.e., whatever's shortest): whole program, actual function, code snippet you may not use ...
4
votes
1answer
1k views

How would you count score in a Scrabble® game? [closed]

Let's say that we are programming a game that lets you play Scrabble®. We have a board with tiles placed on it, and empty cells are either normal or have multiplier properties (double or triple the ...
7
votes
4answers
2k views

Noughts and Crosses (aka Tic-Tac-Toe)

Write a Notes and Crosses application. User interface is optional. You can output the computers move in text: eg 1x1 (meaning ...
23
votes
61answers
6k views

Reinvent the For loop [closed]

For loops are used extensively in many languages, but what would you do if no languages supported them? Create a way to execute a basic ...
19
votes
19answers
2k views

Run-Length Encoding [duplicate]

Write a program uses run-length encoding to shorten a list of non-negative integers it has to read in. You can assume the non-negative integers can fit in 32bit signed integers. Input Format The ...
14
votes
12answers
1k views

Day of the week of the next Feb 29th

Write a function which takes a date and returns the day of the week of the next February 29th after that date. The input is a string in the ISO Extended format: YYYY-MM-DD (e.g. May 27th, 2010 would ...
29
votes
29answers
4k views

Render “Digital Clock Style” Numbers

Write the shortest program which will take a string of numbers (of up to at least 20 length) as input, and display the output using the standard digital clock style numbers. For instance for input 81,...

15 30 50 per page