code-golf

Code Golf: Quickly Build List of Keywords from Text, Including # of Instances

丶灬走出姿态 提交于 2020-02-12 08:36:25
问题 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've already worked out this solution for myself with PHP, but I'm curious how it could be done differently - better even. The two languages I'm primarily interested in are PHP and Javascript, but I'd be interested in seeing how quickly this could be done in any other major language today as well (mostly C#, Java, etc).

Joining a set of ordered-integer yielding Python iterators

99封情书 提交于 2020-01-28 03:33:07
问题 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

Code Golf - Banner Generation

那年仲夏 提交于 2020-01-10 06:59:28
问题 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. When thanking someone, you don't want to just send them an e-mail saying "Thanks!", you want to have something FLASHY: Input: THANKS!! Output: TTT H H AAA N N K K SSS !!! !!! T H H A A NNN K K S !!! !!! T HHH AAA NNN KK SSS !!! !!! T H H A A N N K K S T H H A A N N K K SSS !!! !!! Write a program to generate a banner.

Code Golf: Leibniz formula for Pi

不羁岁月 提交于 2020-01-10 06:28:08
问题 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 posted one of my favourite interview whiteboard coding questions in "What's your more controversial programming opinion", which is to write a function that computes Pi using the Leibniz formula. It can be approached in a number of different ways, and the exit condition takes a bit of thought, so I thought it

How to convert numbers to words in Erlang?

你说的曾经没有我的故事 提交于 2020-01-01 06:56:13
问题 I found this interesting question about converting numbers into "words": Code Golf: Number to Words I would really like to see how you would implement this efficiently in Erlang. 回答1: -module(int2txt). -export([convert/1]). convert(0) -> "zero"; convert(N) -> convert1(N). convert1(0) -> ""; convert1(N) when N>=1000 -> join(convert_thou(thoubit(N), 0),convert1(N rem 1000)); convert1(N) when N>=100 -> join(convert1(N div 100),"hundred",convert1(N rem 100)); convert1(N) when N>=20 -> join(tens(

Create, sort, and print a list of 100 random ints in the fewest chars of code

▼魔方 西西 提交于 2019-12-31 09:00:07
问题 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. What is the least amount of code you can write to create, sort (ascending), and print a list of 100 random positive integers? By least amount of code I mean characters contained in the entire source file, so get to minifying. I'm interested in seeing the answers using any and all programming languages. Let's try to keep

Code-Golf: one line PHP syntax

早过忘川 提交于 2019-12-30 02:11:38
问题 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. Explanation PHP has some holes in its' syntax and occasionally in development a programmer will step in them. This can lead to much frustration as these syntax holes seem to exist for no reason. For example, one can't easily create an array and access an arbitrary element of that array on the same line ( func1()[100] is

oneliner scramble program

…衆ロ難τιáo~ 提交于 2019-12-24 05:49:15
问题 It's that time of year again that programmers want to shuffle a list such that no element resides on its original position (at least in the Netherlands, we celebrate Sinterklaas and pick straws for deciding who writes who a poem). Does anyone have a nice Python single statement for that? So, input example: range(10) Output example: [2,8,4,1,3,7,5,9,6,0] Wrong output would be [2,8,4,1,3,5,7,9,6,0] because the 5 is at its original position. This would mean that person 5 must write a poem to

Perl golf: Print the powers of a number

孤者浪人 提交于 2019-12-22 01:41:08
问题 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 回答1: 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

Code Golf: Lights out

爱⌒轻易说出口 提交于 2019-12-20 16:49:17
问题 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 solve the input lights out board. The lights out board is a 2d square grid of varying size composed of two characters - . for a light that is off and * for a light that is on. To solve the board, all "lights" have to be turned off. Toggling a light (i.e. turning off