rosetta-stone

Code Golf: The wave

余生颓废 提交于 2019-11-28 16:12:15
The challenge The shortest code by character count to generate a wave from the input string. A wave is generated by elevating (line-1) a higher character, and degrading (line+1) a lower character. Equal characters are kept on the same line (no elevating or degrading done). Input is made of lower case characters and numbers only, letters are considered higher than numbers. Test cases: Input: 1234567890qwertyuiopasdfghjklzxcvbnm Output: z l x v n k c b m j h g y p s f t u o a d w r i 9 q e 8 0 7 6 5 4 3 2 1 Input: 31415926535897932384626433832795028841971693993751058209749445923078164062862

Code Golf: Seven Segments

岁酱吖の 提交于 2019-11-28 15:50:20
问题 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. The challenge The shortest code by character count to generate seven segment display representation of a given hex number. Input Input is made out of digits [0-9] and hex characters in both lower and upper case [a-fA-F] only. There is no need to handle special cases. Output Output will be the seven segment

Code Golf: Decision Tree

99封情书 提交于 2019-11-28 15:49:37
In Google Code Jam 2009, Round 1B , there is a problem called Decision Tree that lent itself to rather creative solutions. Post your shortest solution; I'll update the Accepted Answer to the current shortest entry on a semi-frequent basis, assuming you didn't just create a new language just to solve this problem. :-P Current rankings: 107 Perl 121 PostScript (binary) 132 Ruby 154 Arc 160 PostScript (ASCII85) 170 PostScript 192 Python 196 JavaScript 199 Common Lisp 212 LilyPond 273 Scheme 280 R 281 sed w/ bc 312 Haskell 314 PHP 339 m4 w/ bc 346 C 381 Fortran 462 Java 718 OCaml 759 F# 1554 sed C

Palindrome Golf

孤人 提交于 2019-11-28 15:33:49
问题 The goal: Any language. The smallest function which will return whether a string is a palindrome. Here is mine in Python : R=lambda s:all(a==b for a,b in zip(s,reversed(s))) 50 characters. The accepted answer will be the current smallest one - this will change as smaller ones are found. Please specify the language your code is in. 回答1: 7 characters in J: Not sure if this is the best way, I'm somewhat new to J :) p=:-:|. explanation: |. reverses the input. -: compares. the operands are

Code Golf: Regex parser

独自空忆成欢 提交于 2019-11-28 14:25:05
问题 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

Code Golf New Year Edition - Integer to Roman Numeral

心已入冬 提交于 2019-11-28 09:05:12
Write a program that take a single command line argument N and prints out the corresponding Roman Numeral . Eg N = 2009 should print MMIX. Let's say this should work for 0 < N < 3000. (Had fun playing my first ever round of code golf with the Christmas edition , and thought this could fit for New Year. Googled to see if this has come up before elsewhere and it looks like it hasn't, but let me know if this is too hard or too easy or if the rules need changing. ) Happy MMIX! A. Rex Perl: 69 strokes (count 'em!) Sixty-nine strokes including calling perl in the first place: $ perl -ple's!.!($#.=5x

Code Golf: Lasers

放肆的年华 提交于 2019-11-28 02:33:34
The challenge The shortest code by character count to input a 2D representation of a board, and output 'true' or 'false' according to the input . The board is made out of 4 types of tiles: # - A solid wall x - The target the laser has to hit / or \ - Mirrors pointing to a direction (depends on laser direction) v, ^, > or < - The laser pointing to a direction (down, up, right and left respectively) There is only one laser and only one target . Walls must form a solid rectangle of any size, where the laser and target are placed inside. Walls inside the 'room' are possible. Laser ray shots and

Code Golf: Sierpinski's Triangle

南楼画角 提交于 2019-11-27 20:04:05
问题 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: Tic Tac Toe

混江龙づ霸主 提交于 2019-11-27 11:06:57
Post your shortest code, by character count, to check if a player has won, and if so, which. Assume you have an integer array in a variable b (board), which holds the Tic Tac Toe board, and the moves of the players where: 0 = nothing set 1 = player 1 (X) 2 = player 2 (O) So, given the array b = [ 1, 2, 1, 0, 1, 2, 1, 0, 2 ] would represent the board X|O|X -+-+- |X|O -+-+- X| |O For that situation, your code should output 1 to indicate player 1 has won. If no-one has won you can output 0 or false . My own (Ruby) solution will be up soon. Edit : Sorry, forgot to mark it as community wiki. You

Code Golf: Conway's Game of Life

泄露秘密 提交于 2019-11-27 10:08:28
The Challenge: Write the shortest program that implements John H. Conway's Game of Life cellular automaton. [ link ] EDIT: After about a week of competition, I have selected a victor: pdehaan , for managing to beat the Matlab solution by one character with perl. For those who haven't heard of Game of Life, you take a grid (ideally infinite) of square cells. Cells can be alive (filled) or dead (empty). We determine which cells are alive in the next step of time by applying the following rules: Any live cell with fewer than two live neighbours dies, as if caused by under-population. Any live