Tagged Questions
0
votes
2answers
137 views
How to shorten this J code? (Or write shorter code in another language)
I decided to learn J so that I could better take part in code golfing. Starting it off relatively simple, I tried writing a solution to this problem:
Find the sum of all the multiples of 3 or 5 ...
16
votes
5answers
446 views
Shortest common superstring
Given a list of strings s_0, s_1, ..., s_n find the shortest string S that contains each of s_0, s_1, ..., s_n as a substring.
Examples:
S('LOREM', 'DOLOR', 'SED', 'DO', 'MAGNA', 'AD', ...
-4
votes
6answers
131 views
Return the number of digits in any given number
Objective
Given any terminating, rational number, return the number of digits the number contains. Do not count zeros if they're the last digits.
Examples
0 returns 1
-1 returns 1
6.23 returns 3
...
1
vote
0answers
177 views
Write a Polish notation interpreter, then change it to RPN in shortest number of chars
Write a program to convert Polish prefix notation to infix notation, then change it to an RPN-to-infix converter in the shortest number of chars.
Your score is 100 minus the number of characters ...
1
vote
2answers
129 views
Find the generating function of a sequence [duplicate]
Given a set of space-delimited integers, you've gotta either return a function that can generate that sequence, or return "There isn't any such function".
Sample input:
"1 11 41 79"
- x^3+x^2-1
...
2
votes
2answers
120 views
Zebra stripe command output
I have a script:
$ cat ~/zebra.pl
#!/bin/perl
use Term::ANSIColor;
$Term::ANSIColor::EACHLINE = "\n";
my $zebra = 1; # Are zebras black with white stripes, or white with black stripes?!
my $black ...
19
votes
21answers
2k views
Shortest code to determine if a string is a palindrome
A palindrome is some string that is spelled the same way both backwards and forwards. For instance, 'Eva, can I stab bats in a cave?' is a palindrome (EVACANISTAB | BATSINACAVE)
For this code golf, ...
7
votes
3answers
220 views
Advanced Code Golf - Disk Operations, and File Allocation
Good Afternoon Golfgeneers.
This is reasonably long and detailed question. Given what it was asking, it needed to be. If you have any questions, please ask them. If there is anything that isn't ...
7
votes
7answers
335 views
Sibling Rivalry
Objective Requirements
A main 'parent' file and a 'child' file.
The parent file creates a new child file that contains code that must execute after creation.
The child file that is created must ...
3
votes
4answers
188 views
Count characters in lo..ol and print a phrase [duplicate]
Assuming 'lol' with a variavle number of 'o's. Print a the following phrase:
What does 1st, 2nd, 3rd, 4th ... 'o' stand for?
Examples:
lol -> What does 1st 'o' stand for?
loooool -> What ...
12
votes
19answers
877 views
Give the smallest number that has N divisors
Your function takes a natural number and returns the smallest natural number that has exactly that amount of divisors, including itself.
Exemples:
f(1) = 1 [1]
f(2) = 2 [1, 2]
f(3) = 4 [1, 2, 4]
...
17
votes
12answers
620 views
Incrementing Numbers, Over Multiple Sessions
Good Evening Golf Agents,
Your mission is on behalf of notorious entertainment giant Eviltronic Arts. As part of their nefarious plan for world enslavement and entertainment, they must sell as many ...
1
vote
1answer
170 views
Implement DFA/NFA/epsilon-NFA
Write the shortest code that implements a:
DFA
NFA
epsilon-NFA
The program should accept as input:
a string(that we want to see if is accepted or not)
the delta function, represented in ...
12
votes
21answers
1k views
The world ends in ed
Taken straight from the ACM Winter Programming Contest 2013. You are a person who likes to take things literally. Therefore, for you, the end of The World is ed; the last letters of "The" and "World" ...
2
votes
0answers
182 views
chess - calculate all legal moves from fen string ignoring castling and en passant
Write the shortest code that calculates all possible (legal) moves of current player from a given FEN string. What is FEN string? (Wikipedia)
Shortest code wins, language doesn't matter.
Output ...
0
votes
0answers
60 views
Minimalist web server [duplicate]
The challenge is to make the shortest fully functioning web server possible. You should give fully working code that can serve static pages from a given local directory. The code can be in any free ...
11
votes
3answers
1k views
Solve Rubik's cube
Write the shortest program that solves Rubik's cube (3*3*3) within a reasonable amount of time and moves (say, max. 5 seconds on your machine and less than 1000 moves).
The input is in the format:
...
4
votes
4answers
449 views
Print ASCII histogram
The challenge is to give as short code as possible to print an ASCII histogram of a set of data.
Input. The number of bins followed by a number of integers representing the data. The data are space ...
8
votes
6answers
907 views
Pong in the shortest code
The challenge is simple. Give the shortest code possible to reproduce the classic 2-player game of pong http://en.wikipedia.org/wiki/Pong . The level of graphics and functionality should be as close ...
7
votes
4answers
697 views
Breakout in half an hour
When I was a young teen I had a very boastful friend who claimed he could code up breakout (http://en.wikipedia.org/wiki/Breakout_(video_game)) in half an hour. Half an hour later he had done a great ...
4
votes
5answers
444 views
Cropping an image succintly
I am constantly frustrated by how complicated it is to write graphical programs that would have been only a few lines of code 20+ years ago. Since the invention of the mouse this has become even ...
6
votes
1answer
321 views
Simple redstone simulator
Redstone is a material in the game Minecraft, and it is used for many complex contraptions. For this program, you will only need to simulate three items: the redstone wire (noted with R), redstone ...
10
votes
24answers
2k views
Emulate a 7-segment display
Task
The task is to display any of the 128 possible states of a
7-segment display.
Your program should accept a string of 7 characters ("bits") that are either 0 or 1.
First bit of input corresponds ...
3
votes
4answers
289 views
Convert the Binary Champernowne Constant to Decimal
The Champernowne constant is a transcendental decimal number whose digits are the concatination of all positive integers.
C10 = 0.12345678910111213141516...10
The binary version of this is
C2 = ...
0
votes
0answers
210 views
Generate Esolangs
Given a file named hello_world that contains 2-100 bytes of printable ASCII, create a Turing-complete language in which hello_world is a valid program that prints "Hello World!". The output should be ...
7
votes
1answer
192 views
Cryptographic quine variant
Create a program that prints the MD5 sum of its source in the form:
MD5 sum of my source is: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
No cheating - you can't just read the source file and compute its sum. ...
12
votes
20answers
1k views
Write a program that uses all printable non-alphanumeric ASCII symbols
In particular, use each of these symbols at least once in your source code:
! " # $ % & ' () * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
Symbols inside comments, string literals, ...
2
votes
1answer
240 views
Determine the original sequence
Write a program that will determine the original sequence given five variations. The original sequence will be contain n unique elements in any order. A variation is made by making a copy of the ...
6
votes
8answers
503 views
The Strange Unsorting Machine for Nefarious Purposes
Good Evening Golfers!
Your challenge is to completely unsort a series of numbers.
Input
Exactly 100 integers will be fed to your program. Your program may accept the input either as a file, or via ...
4
votes
9answers
503 views
Ode-cay Olf-gay
Write a program which accepts a sentence into stdin, and writes that sentence to stdout in pig latin.
Here are some test cases which your program should handle:
Input:
Read your script
Output:
...
5
votes
8answers
673 views
Turing Machine Simulator
Write a Turing machine simulator.
For simplicity we can assume statuses as integer, symbols as char, blank symbol equals whitespace
5-tuple in the form of current state, input symbol, next state, ...
7
votes
6answers
462 views
Find the Pisano Period of a number
Input: An integer 0 < n < 2^30, taken from stdin.
Output: The Pisano period of n (the length of the cycle of the Fibonacci sequence mod n)
Input is smaller than 2^30 so that intermediate ...
16
votes
30answers
2k views
Print this diamond
This question has been spreading like a virus in my office. There are quite a variety of approaches:
Print the following:
1
121
12321
1234321
123454321
12345654321
...
10
votes
4answers
717 views
Create a GUI Piano
Challenge
Create a GUI Keyboard with as few characters as possible.
Example
Because this was an assignment in one of my courses, I can't show the source code. However, here is a screen shot of my ...
5
votes
8answers
504 views
calculate days of a month
I would like to see the shortest expression to calculate the days (or the last day) of a month in any language.
Considering y as the number of year and m as month.
Basic rules
without date / time ...
2
votes
2answers
411 views
Help johnny to solve this Puzzle
Scenario
Little Johnny wants to play with his friends today. But his babysitter won't let him go! After a lot of begging, the heartless nanny gives him her brand new electronic puzzle and says: "If ...
13
votes
4answers
801 views
Star programming!
The challenge
Write a program or function that prints stars! The program will receive two parameters by standar input: Size of the star and number of points of the star. A star can be any size ...
5
votes
4answers
640 views
A simple Knight's problem
How many ways are there to place a black and a white knight on an N * M chessboard such that they do not attack each other?
A knight can move two squares horizontally and one square vertically, or ...
13
votes
26answers
2k views
Print custom alphabet
The Challenge
Display the alphabet from a given letter read from console input. If the letter is uppercase, you have to display the alphabet uppercased. The alphabet printed must end in the precedent ...
4
votes
7answers
596 views
Find the nth Fibonnaci Prime, in the shortest code
The challenge is rather simple:
Take a positive whole number n as input.
Output the nth Fibonacci prime number.
Input can be as an parameter to a function (and the output will be the return ...
7
votes
4answers
505 views
Generate Friedman numbers
A Friedman number is a number that can be expressed by applying basic mathematical operations(^,/,*,+,-) to all it's digits. The operations need not be applied to each individual digit, but all the ...
3
votes
9answers
522 views
Day of the week for a given date of this year. Do not use any date tools
Please write a program that takes as input two numbers 'day of the month' and 'month number' for any day of this year (2012) and outputs day of the week.
Examples:
% ruby ./golf.rb 14 07 # 14th of ...
5
votes
7answers
316 views
Topographic Strings
Here is some example input, so I can explain what the problem is:
((1 2)(3 (4 5) moo)) (i (lik(cherries)e (woohoo)))
Think of this line of text as a topographic map of some mountains. Each set of ...
2
votes
1answer
317 views
Lenient typing test
A typing speed test loads up a dictionary of words, and gives you one to type: pinball. You, with your fast but inaccurate fingers, type in pinbnal. Darn it!
Make a program that will print out a ...
4
votes
3answers
317 views
Code Golf: Mix the nuts so that none of the same kind are touching
Input:
Input is a randomized array of nuts (in your language), the possible nuts follow. Your program must have a way of representing each kind of nut, such as an integer code. Program must be able ...
3
votes
8answers
457 views
Pythagorean Triplets
The Pythagorean Theorem states that for a right triangle with sides a, b, and c, a2+b2=c2.
A Pythagorean triplet is a set of three numbers, where a2+b2=c2, a
To extend this even further, a primitive ...
8
votes
3answers
568 views
Universal (rule-bending) Code Golf solver
Code golf always involves some answers that bend the rules more or less by breaking constraints that the challengers took for granted or just haven't thought about and didn't list in the rules. One of ...
2
votes
16answers
432 views
Arithmetic Sequences
An arithmetic sequence is a sequence of numbers of the form a,a+n,a+2n,a+3n, etc. In this case, a and n will both be either integers or decimals.
Given two inputs, a, n, and a top number value, ...
5
votes
9answers
599 views
Tower of hanoi solver
For reference as to what the tower of Hanoi is, either Google it or look on the Wikipedia page.
Your code should be able to do 2 things, and they are the following:
Accept user input that specifies ...
8
votes
8answers
537 views
Build a typing speed test / measuring CPM
The Rules
It's time to build a typing speed test in your language of choice!
1. You provide a file with a dictionary of choice (every 'word' in it must be newline delimited). Pipe it in via stdin or ...
