Skip to main content

Questions tagged [rational-numbers]

This challenge involves the manipulation of rational numbers, i.e. those which can be represented as a fraction of integers. Do not use this tag if rational numbers are just one of several admissible input/output formats, but rather if the use of exact rational arithmetic is required.

13 votes
14 answers
4k views

NaN is not equal to NaN

In many programming languages, the floating-point value NaN, or "not a number", in some programming languages generated by the expression ...
3-1-4-One-Five's user avatar
11 votes
10 answers
1k views

Egyptian fraction representations of 1 without prime denominators

Background As noted in this question, for all positive integers \$n>2\$ there exists at least one Egyptian fraction representation (EFR) of \$n\$ distinct positive integers \$a_{1} < a_{2} < \...
Max Muller's user avatar
10 votes
7 answers
776 views

Longest sequence of Egyptian fractions with n as denominator

Background From Wikipedia: An Egyptian fraction is the sum of distinct unit fractions. That is, each fraction in the expression has a numerator equal to 1 and a denominator that is a positive integer, ...
Anm's user avatar
  • 203
11 votes
26 answers
2k views

Find the smallest integer multiple of a Decimal

The Challenge Given a rational number, determine the smallest number which is a positive integer multiple of it. Eg. ...
ATaco's user avatar
  • 10.9k
10 votes
13 answers
2k views

Decimalize a Fraction

Preamble A common pain-point when working with rational numbers and decimals is how infrequently one can represent their rational number as a clean, non-repeating decimal. Let's solve this by writing ...
ATaco's user avatar
  • 10.9k
21 votes
13 answers
2k views

Minkowski's ?(x) for rational x

Here is Minkowski's question mark function: It is a strictly increasing and continuous function from the reals to themselves that, among other unusual properties, maps rational numbers to dyadic ...
Parcly Taxel's user avatar
  • 3,845
16 votes
15 answers
1k views

Find Index of Rational Number in Calkin-Wilf Sequence

Related From Wikipedia: In number theory, the Calkin–Wilf tree is a tree in which the vertices correspond one-to-one to the positive rational numbers. The tree is rooted at the number \$1\$, and any ...
97.100.97.109's user avatar
11 votes
5 answers
611 views

Whole Number Groups

Given a list of fractions, group them so that each group sums to a whole number. This should be done in such a way to maximize the number of non-empty groups. You may assume a solution exists. Order ...
mousetail's user avatar
  • 12.7k
19 votes
10 answers
2k views

Enumerate the rationals

The cardinality of the set \$\mathbb Q\$ of rational numbers is known to be exactly the same as that of the set \$\mathbb Z\$ of integers. This means that it is possible to construct a bijection ...
att's user avatar
  • 20.9k
0 votes
8 answers
398 views

Print ascending proper fractions using integers up to the given input

User inputs an integer. Print out proper fractions using all positive integers up to the user's input, in ascending order. Rule 1: Eliminate equal fractions. Rule 2: Fractions should be in their ...
paki eng's user avatar
  • 175
19 votes
20 answers
3k views

Next digit of rational number

Story: The π was recently computed with accuracy to 100 trillions digits, but it is useless to us. We can't do accurate enough math, because rational numbers are too boring and so we don't know that ...
Jiří's user avatar
  • 1,885
18 votes
12 answers
1k views

In between fractions

Given two positive integer fractions \$x\$ and \$y\$ such that \$x < y\$, give the fraction \$z\$ with the smallest positive integer denominator such that it is between \$x\$ and \$y\$. For example ...
Wheat Wizard's user avatar
  • 99k
1 vote
1 answer
528 views

Best performance on x/(y+z) + y/(x+z) + z/(x+y) = N

Consider the equation $$\frac x {y+z} + \frac y {x+z} + \frac z {x+y} = n$$ for positive integers \$x, y, z\$ and \$n \ge 4\$. Your code will receive \$n\$ as an input, and output three integers \$x, ...
Number Basher's user avatar
12 votes
17 answers
2k views

Infinite Candle Sequence

I have a cake shop that specialises in birthday cakes. The cakes that I sell must have candles placed in a circle. You would probably think I can just divide 360° by the number of candles, but the ...
Matthew Jensen's user avatar
8 votes
7 answers
692 views

Factorials of primes decomposition

You have to decompose a positive integer/fraction as a product of powers of factorials of prime numbers. For example ...
DialFrost's user avatar
  • 5,099

15 30 50 per page
1
2 3 4 5
7