rosetta-stone

Code Golf: Running Water

≡放荡痞女 提交于 2019-11-29 19:25:36
The challenge The shortest code by character count to identify and mark water depressions in the ASCII representation of a land from input. Input will be an ASCII representation of a landscape, having hills, valleys and flat lands. The program should simulate what the landscape would look like if if was flooded - filling all valleys with water (character x ). The landscape will always start and stop with the character _ and will be at least 2 characters long, making the shortest input __ . A hill is defined as a raise, and should not be filled with water: __ _/ \_ A valley is defined as a

Code Golf: Four is magic

佐手、 提交于 2019-11-29 19:13:51
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 would finish with four is magic ). Any number seems to be transformable into four eventually, no matter what. The goal was to try to figure out the transformation function and then be able to reliably proctor this puzzle yourself. The solution The transformation

Code Golf: Regex parser

梦想与她 提交于 2019-11-29 19:11:10
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 single literal character, or a regular expression within grouping parentheses () . The * (asterisk) character represents a Kleene star operation on the previous TERM. This means zero or more of the previous term, concatenated together. The + (plus) character

The Skyline Problem‍​​

可紊 提交于 2019-11-29 18:46:01
I just came across this little problem on UVA's Online Judge and thought, that it may be a good candidate for a little code-golf. The problem: You are to design a program to assist an architect in drawing the skyline of a city given the locations of the buildings in the city. To make the problem tractable, all buildings are rectangular in shape and they share a common bottom (the city they are built in is very flat). The city is also viewed as two-dimensional. A building is specified by an ordered triple (Li, Hi, Ri) where Li and Ri are left and right coordinates, respectively, of building i

Code Golf: Build Me an Arc

时光毁灭记忆、已成空白 提交于 2019-11-29 05:33:11
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 standard output an ASCII "arc" from the starting angle X to the ending angle Y of radius R , where: The vertex of the arc is represented by o Angles of 0 and 180 are represented by - Angles of 45 and 225 are represented by / Angles of 90 and 270 are

Code-Golf: Friendly Number Abbreviator

冷暖自知 提交于 2019-11-28 19:58:41
问题 Based on this question: Is there a way to round numbers into a friendly format? THE CHALLENGE - UPDATED! (removed hundreds abbreviation from spec) The shortest code by character count that will abbreviate an integer (no decimals). Code should include the full program. Relevant range is from 0 - 9,223,372,036,854,775,807 (the upper limit for signed 64 bit integer). The number of decimal places for abbreviation will be positive. You will not need to calculate the following: 920535 abbreviated

Fibonacci Code Golf

一笑奈何 提交于 2019-11-28 17:33:23
问题 Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. Generate the Fibonacci sequence in the fewest amount of characters possible. Any language is OK, except for one that you define with one operator, f , which prints the Fibonacci numbers. Starting point: 25 14 characters in Haskell : f=0:1:zipWith(+)f(tail f) f=0:scanl(+)1f 回答1: RePeNt, 9 , 8 chars 1↓[2?+1] Or 10 chars

Code Golf: Sierpinski's Triangle

梦想的初衷 提交于 2019-11-28 17:12:57
The challenge The shortest code, by character count to output an ASCII representation of Sierpinski's Triangle of N iterations made from the following ASCII triangle: /\ /__\ Input is a single positive number. Test cases Input: 2 Output: /\ /__\ /\ /\ /__\/__\ Input: 3 Output: /\ /__\ /\ /\ /__\/__\ /\ /\ /__\ /__\ /\ /\ /\ /\ /__\/__\/__\/__\ Input: 5 Output: /\ /__\ /\ /\ /__\/__\ /\ /\ /__\ /__\ /\ /\ /\ /\ /__\/__\/__\/__\ /\ /\ /__\ /__\ /\ /\ /\ /\ /__\/__\ /__\/__\ /\ /\ /\ /\ /__\ /__\ /__\ /__\ /\ /\ /\ /\ /\ /\ /\ /\ /__\/__\/__\/__\/__\/__\/__\/__\ /\ /\ /__\ /__\ /\ /\ /\ /\ /__\/_

Code Golf: Musical Notes

允我心安 提交于 2019-11-28 16:41:24
The challenge The shortest code by character count, that will output musical notation based on user input. Input will be composed of a series of letters and numbers - letters will represent the name of the note and the number will represent the length of the note. A note is made of 4 vertical columns. The note's head will be a capital O , stem, if present will be 3 lines tall, made from the pipe character | , and the flag(s) will be made from backward slash \ . Valid note lengths are none, 1/4 of a note, 1/8 of a note, 1/16 of a note and 1/32 of a note. | |\ |\ |\ | | |\ |\ | | | |\ O O O O O

Code Golf: Collatz Conjecture

旧时模样 提交于 2019-11-28 16:27:29
Inspired by http://xkcd.com/710/ here is a code golf for it. The Challenge Given a positive integer greater than 0, print out the hailstone sequence for that number. The Hailstone Sequence See Wikipedia for more detail.. If the number is even, divide it by two. If the number is odd, triple it and add one. Repeat this with the number produced until it reaches 1. (if it continues after 1, it will go in an infinite loop of 1 -> 4 -> 2 -> 1... ) Sometimes code is the best way to explain, so here is some from Wikipedia function collatz(n) show n if n > 1 if n is odd call collatz(3n + 1) else call