# 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.

105 questions
Filter by
Sorted by
Tagged with
220 views

### Fractions nobody needs (because they can be reduced to a simpler form)

It happened in the 19th century. Georg was bored and started counting the rational numbers. Surprisingly, he discovered that there were no more of them than natural numbers. This insight made Georg ...
249 views

### Counterexample to Shapiro inequality

Input: A positive integer n such that n is even and greater than 12 or n is odd and greater than 23. Output: A list of non-negative integers that violates Shapiro inequality. More precisely, Let s be ...
570 views

### Rabinowitz-Wagon $\pi$ formula

In 1995, Stanley Rabinowitz and Stan Wagon found an interesting algorithm to generate the digits of $\pi$ one by one without storing the previous results. The algorithm is called the spigot ...
• 49.4k
752 views

• 6,299
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 ...
• 1,431
1k views

• 1,548
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 ...
• 2,347
706 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 ...
• 5,097
3k views

### Egyptian fraction representations of 1

An Egyptian fraction is a representation of a rational number using the sum of distinct unit fractions (a unit fraction is of the form $\frac 1 x$ where $x$ is a positive integer). For all[1] ...
• 24.3k
2k views

• 99.6k
3k views

### Phony fractions

Context If a0 and b0 are two decimal numbers, with a and ...
• 14.1k
1k views

### Integer Logarithm

Objective Take $a \in ℤ_{>1}$ and $b \in ℤ_+$ as inputs. Write a function $f$ such that:  f(a,b) = \left\{ \begin{array}{ll} \log_ab & \quad \text{if} \space \log_ab \in ℚ \\...
• 6,299
4k views

### Rational Number RNG

The Objective Build a random number generator whose range is $\left[0,1\right) \cap \mathbb{Q} .$ This is, build a random number generator that can produce any value that's: at least $0 \,;$ ...
• 6,299
2k views

### Approximate the perfect fifth

Starting at 1-TET, give equal temperaments that have better and better approximation of the perfect fifth(just ratio 3/2). (OEIS sequence A060528) The formal description of the sequence, copied from ...
• 6,299
10k views

### Round towards zero

This is a simple task. Given a positive or negative real number, round it to the next whole integer closer to zero. The challenge Take input through any reasonable form (stdin, function, etc.) of one ...
• 2,570
606 views

### Surreal Numbers

Surreal Numbers are one way of describing numbers using sets. In this challenge you will determine the value of a surreal number. Intro A surreal number consists of two sets: a left and right. The ...
• 2,869
723 views

### Satisfying Rounding

Satisfying Rounding You know when you're in science class, and asked to round to 2 sig figs, but your answer is 5.2501...? You should round to ...
• 2,869
2k views

### Ryley's Theorem

S. Ryley proved following theorem in 1825: Every rational number can be expressed as a sum of three rational cubes. Challenge Given some rational number $r \in \mathbb Q$ find three rational ...
• 43.9k
5k views

### Half, Half Half, and, Half

Consider the following number sequence: \\$ 0, \frac{1}{2}, \frac{1}{4}, \frac{3}{4}, \frac{1}{8}, \frac{3}{8}, \frac{5}{8}, \frac{7}{8}, \frac{1}{16}, \frac{3}{16}, \frac{5}{16}, \frac{7}{16}, \...
• 35k
2k views

### Convert a percentage to a "simple" ratio

You run a political website, and have determined that people have a better intuitive understanding when the chance of winning or losing an election is expressed as a ratio ("5 in 7") than when it is ...
• 6,797
2k views

### Mixed Fraction Equality

In elementary school, children learn about proper fractions, where the numerator is less than the denominator, and thus the value of the fraction is less than one. Later, they are taught about ...
• 14k
2k views

### Exact Partial Sum of Harmonic Series

Challenge Given a positive integer N, output the sum of the first N reciprocals as an exact fraction, which is represented as a ...
• 3,528