code-golf

Finding closest match in collection of numbers [closed]

∥☆過路亽.° 提交于 2019-11-26 15:41:42
问题 So I got asked today what was the best way to find the closes match within a collection. For example, you've got an array like this: 1, 3, 8, 10, 13, ... What number is closest to 4? Collection is numerical, unordered and can be anything. Same with the number to match. Lets see what we can come up with, from the various languages of choice. 回答1: 11 bytes in J: C=:0{]/:|@- Examples: >> a =: 1 3 8 10 13 >> 4 C a 3 >> 11 C a 10 >> 12 C a 13 my breakdown for the layman: 0{ First element of ] the

What's the shortest code to cause a stack overflow? [closed]

家住魔仙堡 提交于 2019-11-26 12:49:22
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not

Build an ASCII chart of the most commonly used words in a given text [closed]

无人久伴 提交于 2019-11-26 12:49:18
问题 The challenge: Build an ASCII chart of the most commonly used words in a given text. The rules: Only accept a-z and A-Z (alphabetic characters) as part of a word. Ignore casing ( She == she for our purpose). Ignore the following words (quite arbitary, I know): the, and, of, to, a, i, it, in, or, is Clarification: considering don\'t : this would be taken as 2 different \'words\' in the ranges a-z and A-Z : ( don and t ). Optionally (it\'s too late to be formally changing the specifications now

Code Golf: Number to Words

二次信任 提交于 2019-11-26 10:14:28
The code golf series seem to be fairly popular. I ran across some code that converts a number to its word representation. Some examples would be (powers of 2 for programming fun): 2 -> Two 1024 -> One Thousand Twenty Four 1048576 -> One Million Forty Eight Thousand Five Hundred Seventy Six The algorithm my co-worker came up was almost two hundred lines long. Seems like there would be a more concise way to do it. Current guidelines: Submissions in any programming language welcome (I apologize to PhiLho for the initial lack of clarity on this one) Max input of 2^64 (see following link for words,

Evaluating a string of simple mathematical expressions [closed]

泪湿孤枕 提交于 2019-11-26 07:54:03
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . 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 Here is the challenge (of my own invention, though I wouldn\'t be surprised if it has previously appeared elsewhere on the web)

Code Golf: Mathematical expression evaluator (that respects PEMDAS)

岁酱吖の 提交于 2019-11-26 07:24:39
问题 I challenge you to write a mathematical expression evaluator that respects PEMDAS (order of operations: parentheses, exponentiation, multiplication, division, addition, subtraction) without using regular expressions, a pre-existing \"Eval()\"-like function, a parsing library, etc. I saw one pre-existing evaluator challenge on SO (here), but that one specifically required left-to-right evaluation. Sample inputs and outputs: \"-1^(-3*4/-6)\" -> \"1\" \"-2^(2^(4-1))\" -> \"256\" \"2*6/4^2*4/3\"