code-golf

Joining a set of ordered-integer yielding Python iterators

≡放荡痞女 提交于 2019-11-28 17:18:23
Here is a seemingly simple problem: given a list of iterators that yield sequences of integers in ascending order, write a concise generator that yields only the integers that appear in every sequence. After reading a few papers last night, I decided to hack up a completely minimal full text indexer in Python, as seen here (though that version is quite old now). My problem is with the search() function, which must iterate over each posting list and yield only the document IDs that appear on every list. As you can see from the link above, my current non-recursive 'working' attempt is terrible.

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

Creating the shortest Turing-complete interpreter [closed]

烈酒焚心 提交于 2019-11-28 16:32:33
I've just tried to create the smallest possible language interpreter. Would you like to join and try? Rules of the game: You should specify a programming language you're interpreting. If it's a language you invented, it should come with a list of commands in the comments. Your code should start with example program and data assigned to your code and data variables. Your code should end with output of your result. It's preferable that there are debug statements at every intermediate step. Your code should be runnable as written. You can assume that data are 0 and 1s (int, string or boolean,

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

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

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