code-golf

Perl golf: Print the powers of a number

人盡茶涼 提交于 2019-12-04 16:41:09
What's the shortest Perl one-liner that print out the first 9 powers of a hard-coded 2 digit decimal (say, for example, .37), each on its own line? The output would look something like: 1 0.37 0.1369 [etc.] Official Perl golf rules: Smallest number of (key)strokes wins Your stroke count includes the command line moritz With perl 5.10.0 and above: perl -E'say 0.37**$_ for 0..8' With older perls you don't have say and -E, but this works: perl -le'print 0.37**$_ for 0..8' Update: the first solution is made of 30 key strokes. Removing the first 0 gives 29. Another space can be saved, so my final

Code Golf: Numeric Ranges

我的梦境 提交于 2019-12-04 10:26:55
问题 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. Challenge Compactify a long list of numbers by replacing consecutive runs with ranges. Example Input 1, 2, 3, 4, 7, 8, 10, 12, 13, 14, 15 The input is guaranteed to be in ascending order and will not contain duplicates. Output 1 - 4, 7, 8, 10, 12 - 15 Note that ranges of two numbers should be left as is. ( 7, 8 ; not 7

Code Golf: Towers of Hanoi

孤人 提交于 2019-12-04 10:08:31
问题 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. Rules The Towers of Hanoi is a puzzle, and if you are not very familiar with it, here is how it works: The play field consists of 3 rods, and x number of disks, each next one bigger than the previous one. The disks can be put on the rod, with these RULES : only one disk can be moved at once, and it must be moved on the

Code Golf: Phone Number to Words

醉酒当歌 提交于 2019-12-04 10:00:26
问题 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. Guidelines for code-golf on SO We've all seen phone numbers that are put into words: 1-800-BUY-MORE, etc. What is the shortest amount of code you can write that will produce all the possible combinations of words for a 7 digit US phone number. Input will be a seven-digit integer (or string, if that is simpler), and

Code Golf: Playing Cubes

心已入冬 提交于 2019-12-04 07:34:59
问题 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, that will output playing bricks tower series according to user input. The input will be a series of numbers (positive, negative and zero) that represents the height of the current cube tower following their index. A height of 0 means no tower and is spaced. A cube

Code Golf: Piano

人走茶凉 提交于 2019-12-04 07:26:18
问题 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 output a part of a piano keyboard starting from input note in a given length. Input will be composed of a note ( [ACDFG]#|[A-G] ) to start printing the keyboard from and a positive number representing length of keys to print including the first note. The first key

Code Golf: Validate Sudoku Grid

早过忘川 提交于 2019-12-03 15:33:43
问题 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. Introduction A valid Sudoku grid is filled with numbers 1 to 9, with no number occurring more than once in each sub-block of 9, row or column. Read this article for further details if you're unfamiliar with this popular puzzle. Challenge The challenge is to write the shortest program that validates a Sudoku grid that

Twitter text compression challenge

本秂侑毒 提交于 2019-12-03 13:08:15
问题 Rules Your program must have two modes: encoding and decoding . When encoding : Your program must take as input some human readable Latin1 text, presumably English. It doesn't matter if you ignore punctuation marks. You only need to worry about actual English words, not L337. Any accented letters may be converted to simple ASCII. You may choose how you want to deal with numbers. 123 one two three one hundred twenty three 123 1 2 3 one hundred twenty three one two three one hundred twenty

Code-golf: Output multiplication table to the Console

我怕爱的太早我们不能终老 提交于 2019-12-03 11:15:22
问题 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. I recently pointed a student doing work experience to an article about dumping a multiplication table to the console. It used a nested for loop and multiplied the step value of each. This looked like a .NET 2.0 approach. I was wondering, with the use of Linq and extension methods,for example, how many lines of code it

Code golf: find all anagrams

╄→尐↘猪︶ㄣ 提交于 2019-12-03 08:52:31
问题 A word is an anagram if the letters in that word can be re-arranged to form a different word. Task: The shortest source code by character count to find all sets of anagrams given a word list. Spaces and new lines should be counted as characters Use the code ruler ---------10--------20--------30--------40--------50--------60--------70--------80--------90--------100-------110-------120 Input: a list of words from stdin with each word separated by a new line. e.g. A A's AOL AOL's Aachen Aachen's