All Questions
Tagged with code-golf arithmetic
508
questions
8
votes
7
answers
681
views
Complex Exponentiation [closed]
As the title says! Raise one complex number to the power of another.
(a+bi)^(c+di)(using the principal branch of the complex logarithm)
Requires four inputs a, b, c, d. You can combine a, b, c, d into ...
16
votes
19
answers
1k
views
Infer pluses and minuses
The problem
Consider an equation such as "3 ± 2 ± 4 ± 1 = 4" and determine if there exists a sequence of pluses and minuses that makes it arithmetically correct. If it exists, ...
-2
votes
8
answers
1k
views
Number of cigarettes that can be made from a given number of butts
Assumption
A cigarette can be made by combining four cigarette butts. Cigarette butts last infinitely until smoked.
Explanation
Say you have 31 butts. That means, you can make 7 cigarettes from 28 ...
11
votes
12
answers
2k
views
Solve a squared cryptarithm
Inspired by Greg Martin's "Shiny cryptarithm" puzzle.
A cryptarithm is a game consisting of a mathematical equation among unknown numbers, whose digits are represented by letters of the ...
20
votes
14
answers
1k
views
Number of ways to partition n into n = K + ꓘ
In this challenge you are asked to find in how many ways we can express a positive integer n as the sum of two positive integers ...
23
votes
12
answers
4k
views
80% of respondents agreed…
Sometimes I see a claim like "80% of respondents agreed" and I think "what was your sample size? 5?" because, of course, with a sample size of 5 it's possible to get 80% to agree ...
13
votes
21
answers
4k
views
German pharmacy payment
Your task is to calculate the amount you have to pay for prescribed medication at a pharmacy in Germany. The amount is simply based on the full price of the item, which will be your input. It is a ...
24
votes
23
answers
4k
views
American odds to probabilities
American odds (aka moneyline odds) are numbers like \$+150\$ or \$-400\$ used to express how much a winning bet would pay out. Convert odds to a fair win probability like this:
Positive odds \$+n\$ ...
9
votes
11
answers
743
views
Otteretto Classic game scoring method
Brief description of the game
In the game Otteretto Classic (which you can test directly in your browser; try it!) the player has to form palindromic sequences using adjacent cells on a square grid. ...
44
votes
18
answers
3k
views
Compare Two Fractions With ASCII Art
Challenge
Write a program or function that takes in 4 non-negative integers, A, B, C, and D, that represent two fractions, A/B and C/D, where B and D are non-zero and A <= B and C <= D.
Output ...
22
votes
26
answers
4k
views
Given 4 fence lengths, what's the largest rectangular yard you can make?
Here's a very simple little problem that I don't believe has been asked before.
Challenge
Write a program or a function that takes in four positive integers that represents the lengths of movable but ...
24
votes
5
answers
2k
views
Add two real numbers ... probably
The problem statement here is pretty simple, take two real numbers on the range [0,1) as input and output their sum, with probability 1.
The catch here is that there are a lot of real numbers. There ...
13
votes
72
answers
3k
views
Summing the Digits of a Number
Challenge
Given a non-negative integer, find the sum of its digits.
Rules
Your program must take a non-negative integer as input.
Your program should output the sum of the digits of the input ...
12
votes
9
answers
1k
views
Parse basic arithmetic into an AST
Introduction
An abstract syntax tree (AST) is a tree of tokens that shows their connection to each other and syntactical meaning. They are commonly used in compilers and static analysis tools, as ...
16
votes
15
answers
1k
views
Division between two strings
Inverse function of this challenge
To (properly) multiply an string by an integer, you split the string into characters, repeat each character a number of times equal to the integer, and then stick ...