Questions related to elementary arithmetic.

learn more… | top users | synonyms

3
votes
10answers
310 views

Is 7 l8r than 9? (Is seven later than nine?)

This is a fairly simple code golf challenge. Your program, given an ASCII string, is to parse that string into two strings, which it will evaluate. If the second string is "later" than the first one, ...
16
votes
4answers
589 views

Bowl Filled with Water

You should write a program or function which receives the volume of a bowl and the volume of the water in it as input and outputs or returns an ASCII representation of a bowl with water in it with the ...
15
votes
5answers
1k views

Find the nearest clock hands

Challenge Given a number of seconds past midnight, output the smallest angle between any two hands on a clock face, using as few bytes as possible. You may assume that the number of seconds is ...
0
votes
0answers
60 views

Create a working Stack [duplicate]

Your mission, if you choose to accept it, is to create a stack that can do basic math operations. Explanation: Your stack must be able to do basic arithmetic (+-*/) and must support normal base 10 ...
43
votes
7answers
2k views

Make the Stretchy Snakes Kiss

A stretchy snake looks something like this: <||=|||:)~ Each separate sequence of vertical bars (|) in a stretchy snake, known as a stretchy portion, is individually extendable to twice its ...
7
votes
12answers
764 views

Backwards Long Addition

The standard long addition method: The standard algorithm for adding multidigit numbers is to align the addends vertically and add the columns, starting from the ones column on the right. If a ...
28
votes
29answers
3k views

Chunky vs. Smooth Strings

Consider a string of length N, such as Peanut Butter with N = 13. Notice that there are N-1 pairs of neighboring characters in the string. For Peanut Butter, the first of the 12 pairs is Pe, the ...
29
votes
7answers
3k views

Which Friends characters were really the best friends?

The six main cast members of the American sitcom Friends all agreed that they would be paid the same salary throughout the run of the series (after season 2, at least). But that doesn't mean that they ...
18
votes
12answers
1k views

Evaluating Parentheses and Brackets as Integers

Write a program that takes in a string of the four characters ()[] that satisfies these points: Every left parenthesis ( has a matching right parenthesis ). Every left bracket [ has a matching right ...
27
votes
5answers
978 views

Compute the Resistance of a 4 Band Color Coded Resistor

Resistors commonly have color coded bands that are used to identify their resistance in Ohms. In this challenge we'll only consider the normal 4-band, tan, axial-lead resistors. We'll express them as: ...
11
votes
6answers
282 views

Maximum Concatenated Product

We are given a list of integers p1, ..., pk (not necessarily distinct) where each has a value between 1 and 9, inclusive. Using each of the p1, ..., pk exactly once, we can form concatenations of ...
11
votes
3answers
504 views

Very Nice Friedman Numbers

A Friedman Number is a positive integer that is equal to a non-trivial expression which uses its own digits in combination with the operations +, -, *, /, ^, parentheses and concatenation. A Nice ...
12
votes
1answer
209 views

Express a number - a modern “Des Chiffres et des Lettres”

Express a number Back in the 60s, the French invented the TV game show "Des Chiffres et des Lettres" (Digits & Letters). The goal of the Digits-part of the show was to come as close as you can to ...
12
votes
1answer
605 views

Two-zero-one-five puzzle

Background This puzzle is a variation on the four fours puzzle (itself the topic of a past question). Like that puzzle, the aim is to find mathematical expressions for different whole numbers, using ...
15
votes
17answers
3k views

Calculating (3 + sqrt(5))^n exactly

Today your goal is to find integers a and b given non-negative integer n such that: You should write a program or a function that takes parameter n and outputs a and b in a format of your choice. ...
13
votes
6answers
375 views

Out-of-Control Rounding Errors

Background You have recently been hired by a small accounting firm. The world of accounting is somewhat foreign to you, so you're not sure whether you are following all the professional guidelines. ...
15
votes
5answers
469 views

Unwise bit operations

I like to golf in dc, but I'm sometimes frustrated because dc doesn't have bitwise operations. Challenge Provide four named functions which implement the equivalent of the c bitwise operations ...
19
votes
19answers
2k views

Find the next 1-sparse binary number

A positive integer N is K-sparse if there are at least K 0s between any two consecutive 1s in its binary representation. So, the number 1010101 is 1-sparse whereas 101101 is not. Your task is to ...
11
votes
3answers
353 views

Computing truncated digits sums of powers of pi

Given a positive integer n output the sum of the first n decimal digits of the fractional part of πn. Example input and outputs: 1 → 1 2 → 14 3 → ...
0
votes
0answers
64 views

Random arithmetic quiz [duplicate]

Given a and b as two random numbers from 0 to 10 and op as a random symbol of arithmetic operations, you should display 10 questions in the format: a op b = to the user, after each question if the ...
6
votes
2answers
352 views

Implement multiplication by a constant with addition and bit shifts

While looking at the ARM instruction set, you notice that the ADD instruction has the so-called "Flexible second operand", which can be abused for quick multiplication. For example, the following ...
1
vote
7answers
269 views

42 in Rod Logic

Write the shortest possible program which takes a numeric input and outputs the result of adding 42 to the input. f(x) -> x + 42 There's only one restriction. Your program can only be composed ...
37
votes
5answers
3k views

Adding Numbers with Regex

I want to try a new type of regex golf challenge, which asks you to solve nontrivial computational tasks with nothing but regex substitution. To make this more possible and less of a chore, you will ...
23
votes
17answers
2k views

Construct a Ladder

Introduction I want to build a ladder. For this, I have scavenged from the junkyard two long boards with holes in them, and I want to place the steps into these holes. However, the holes are not ...
14
votes
16answers
2k views

Different Way Forward

Given a list of integers produce a Forward Difference at a specified order/depth. For the list of integers: (10, 18, -12, 4, 8, -3, -5, 67, 9, 14) The Forward Differences at the various ...
10
votes
12answers
1k views

Apportionment paradox

Given: A natural number S. A list of N rational weights W that sum to 1. Return a list L of N non-negative integers, such that: (1) sum(L) = S (2) sum((S⋅W_i - L_i)^2) is minimal In other ...
10
votes
5answers
834 views

How many ways to write N as a product of M integers?

Given an integer N, count how many ways it can be expressed as a product of M integers > 1. Input is simply N and M, and output is the total count of distinct integer groups. Meaning you can use an ...
-1
votes
6answers
151 views

Double Factorial [duplicate]

Challenge The objective is simple, in the shortest amount of bytes, write a function or program that takes a number and prints its double factorial. The input must be taken from stdin or a function ...
14
votes
7answers
650 views

Sum the powers to n

Directions Write a program that, given an input integer n (n >= 0), outputs the smallest positive integer m where: n = a[1]^b[1] + a[2]^b[2] + a[3]^b[3] + ... + a[k]^b[k] a and b are finite ...
8
votes
2answers
341 views

Hereditary Base Change

Background In this challenge, a base-b representation of an integer n is an expression of n as a sum of powers of b, where each term occurs at most b-1 times. For example, the base-4 representation ...
9
votes
36answers
3k views

Calculate the square of an integer with restrictions [closed]

The Puzzle You have to write a program or function p(n) that returns the square of what is entered into it and you may assume that the input is a non-negative integer. Put in simpler terms, return ...
15
votes
5answers
789 views

Make any number by repeatedly adding 2 numbers

You are given a machine with two 16-bit registers, x and y. The registers are initialized x=1 and y=0. The only operation the machine can do is addition modulo 65536. That is: x+=y - x is replaced ...
18
votes
9answers
862 views

Sum the time durations

Challenge Write the shortest code that can sum all the time durations that appear in the stdin. The program must only consider the strings that match with one of the following patterns and ignore the ...
5
votes
2answers
725 views

Coding a recursive function for highest possible input

Challenge You are given the following function:- which is the same as:- with the base cases q(r, b, L) = 1 whenever r ≤ L, q(r, 0, L) = 0, if r > L and q(r, 0, L) = 1, if r ≤ L. Your task is to ...
7
votes
2answers
604 views

Divide food to the poor equally!

The problem Through a terrible procastination accident you are reborn as Scrooge McDuck for a day. To make the most out of the situation you decide to give away food to the poor. Since you also are a ...
16
votes
10answers
2k views

Undo the square roots

Your job is to convert decimals back into the sum of the square roots of integers. The result has to have an accuracy of at least 6 significant decimal digits. Input: A number indicating the number ...
9
votes
15answers
2k views

Sum of strings without converting

You have to take 2 string inputs and output the sum of these two strings without converting them to int or using any numeric data type. ex. string one = "123"; string two = "456"; string sum = ...
3
votes
8answers
942 views

Wait, but what's e^N?

Objective: The objective is to calculate e^N for some real or imaginary N (e.g. 2, -3i, 0.7, 2.5i, but not 3+2i). This is code golf, so, shortest code (in bytes) wins. So, for example: N = 3, e^N ...
11
votes
5answers
453 views

Generalized Gematria Calculator

Create a bidirectional Gematria calculator, for any given sequence of Unicode characters as the alphabet. Gematri-What? Gematria is a system of assigning numerical values to symbols, developed by ...
14
votes
27answers
4k views

Find i^n, given n

The Challenge In as few characters as possible, find the value of i^n, given n, a positive integer greater than 0. This should be outputted as a String. For those that don't know, i is defined such ...
1
vote
0answers
286 views

Implement multiplication without using any loops, branches or function calls [closed]

I came up with the following in GNU C r=0;m(a,b){x:goto*(int*[]){&&x,&&y}[r+=a&1?0:b,a>>=1,b<<=1,a<1];y:;} One could argue there is a branch here a&1?0:b So ...
32
votes
8answers
2k views

How Many Guineas in a Gross of Threepennies?

Until decimalization in 1971, British money was based on dividing the pound into 240 pennies. A shilling was 12 pennies so 20 shillings made a pound. The smallest denomination was the farthing at one ...
21
votes
18answers
4k views

Multiply two numbers without using any numbers

You are given as input two strings representing positive integers in base 10, such as "12345" and "42". Your task is to output a string containing their product, "518490" in this case. The twist is ...
21
votes
14answers
2k views

Un-round fractions

When you convert a fraction to a decimal number and you want to store that number, you often have to round it, because you only want to use a certain amount of memory. Let's say you can only store 5 ...
1
vote
2answers
179 views

Distribution of Variables [duplicate]

I was annoyed the other day when I got a point off in math class because I didn't distribute the factors of my function. That is, I put (x+2)(x-3) when I should have put x^2 - x - 6. Your job is to ...
11
votes
5answers
1k views

It’s time to do the math

Introduction This is one of my favorite math puzzles. Given a digit (say 3) and the number of times to use that digit (say 5), generate 10 expressions which result to 1, 2, 3, 4, 5, 6, 7, 8, 9 and ...
8
votes
6answers
1k views

Mixed Base Conversion

Background Most people on here should be familiar with several base systems: decimal, binary, hexadecimal, octal. E.g. in the hexadecimal system, the number 1234516 would represent 1*16^4 + 2*16^3 + ...
25
votes
1answer
815 views

Standardise a Phinary Number

Background Most people on here should be familiar with a few integer base systems: decimal, binary, hexadecimal, octal. E.g. in the hexadecimal system, a number abc.de16 would represent a*16^2 + ...
12
votes
6answers
444 views

False Positives on an Integer Lattice

Leaderboard User Language Score ========================================= Ell C++11 293,619,555 feersum C++11 100,993,667 Ell ...
22
votes
4answers
1k views

Multiply with restricted operations

Goal Your goal is to multiply two numbers using only a very limited set of arithmetic operations and variable assignment. Addition x,y -> x+y Reciprocal x -> 1/x (not division x,y -> ...