Calculating the largest known prime in Ruby
JP Camara explains how to calculate the largest known prime number using Ruby 3.4 with GMP support, achieving a result of 41,024,320 digits after overcoming initial errors.
Read original articleJP Camara discusses the process of calculating the largest known prime number, specifically 2 ** 136,279,841 - 1, using Ruby. In earlier versions of Ruby, such as 3.4.0-preview2, attempting this calculation resulted in a warning and an output of Infinity. However, with the upcoming Ruby 3.4, the calculation can be performed correctly, provided that the GNU Multiple Precision Arithmetic Library (GMP) is installed. The author details the steps to install Ruby with GMP support, which is crucial for handling large number calculations. After successfully setting up the environment, the calculation completes in about five seconds, producing an output of 41,024,320 digits. This achievement was inspired by a keynote at RubyConf 2024, where it was highlighted that Ruby 3.4 could handle such calculations. The author humorously reflects on the initial frustration and the eventual success, celebrating the newfound capability with fellow Ruby enthusiasts.
- Ruby 3.4 can calculate the largest known prime number with the right setup.
- The GNU Multiple Precision Arithmetic Library (GMP) is essential for large number calculations in Ruby.
- The calculation of 2 ** 136,279,841 - 1 produces an output of 41,024,320 digits.
- Initial attempts without GMP resulted in errors and frustration.
- The process was inspired by a keynote at RubyConf 2024.
Related
10B Integers Walk into an Array
Donald Raab's experiment with Pharo Smalltalk demonstrated storing 10 billion SmallInteger instances, showcasing 64-bit addressing advantages over Java's limitations, while emphasizing future programming capabilities for large datasets.
GIMPS Discovers Largest Known Prime Number: 2^136279841 – 1
GIMPS announced the discovery of the largest known prime number, 2^136279841-1, with over 41 million digits, made by Luke Durant using cloud-based GPU technology on October 12, 2024.
Demystifying the regular expression that checks if a number is prime (2016)
The article presents a regex method in Java for determining prime numbers, explaining its components and providing examples across programming languages to aid understanding for readers of all skill levels.
Can humans say the largest prime number before we find the next one?
A new initiative, "Say the Prime," invites individuals to record and upload videos of themselves vocalizing segments of the largest known prime number, promoting creativity and collaboration among participants.
Man spent $2M to find new largest prime number
A new largest known prime number, M136279841, has been discovered with 41,024,320 digits by Luke Durant using a $2 million GPU-based supercomputer, marking a significant advancement in prime number research.
```python
import sys sys.set_int_max_str_digits(0) # Allows for printing very large numbers.
x = (2 * 136_279_841) - 1
print(x)
```
Related
10B Integers Walk into an Array
Donald Raab's experiment with Pharo Smalltalk demonstrated storing 10 billion SmallInteger instances, showcasing 64-bit addressing advantages over Java's limitations, while emphasizing future programming capabilities for large datasets.
GIMPS Discovers Largest Known Prime Number: 2^136279841 – 1
GIMPS announced the discovery of the largest known prime number, 2^136279841-1, with over 41 million digits, made by Luke Durant using cloud-based GPU technology on October 12, 2024.
Demystifying the regular expression that checks if a number is prime (2016)
The article presents a regex method in Java for determining prime numbers, explaining its components and providing examples across programming languages to aid understanding for readers of all skill levels.
Can humans say the largest prime number before we find the next one?
A new initiative, "Say the Prime," invites individuals to record and upload videos of themselves vocalizing segments of the largest known prime number, promoting creativity and collaboration among participants.
Man spent $2M to find new largest prime number
A new largest known prime number, M136279841, has been discovered with 41,024,320 digits by Luke Durant using a $2 million GPU-based supercomputer, marking a significant advancement in prime number research.