Last active
January 18, 2020 19:02
-
-
Save qntm/e0daf631d6983d97647ebae841f6aaf1 to your computer and use it in GitHub Desktop.
What is the smallest number which, when expressed in Roman numerals, won't fit in a 280-character Tweet?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <https://twitter.com/Revolvolutionry/status/1165616879009816576> | |
// <https://oeis.org/A036746> | |
const { arabicToRoman, romanToArabic } = require('big-roman') | |
// The entry at index `i` in this array is the smallest Roman numeral | |
// of length `i` | |
const results = [''] | |
const stopAt = 281 | |
let powerOfTen = 0 | |
while (results.length < stopAt) { | |
// Batch up the new watermarks on a per-new-digit basis, otherwise we end | |
// up accidentally trying to e.g. combine new Roman digit 'IV' with | |
// existing high water mark 'II' and then incorrectly noting down 'IVII' as | |
// the smallest Roman numeral of length 4 | |
const batch = {} | |
for (let value = 0; value < 10; value++) { | |
const romanDigit = arabicToRoman(String(value) + '0'.repeat(powerOfTen)) | |
results.forEach(result => { | |
const newRomanNumeral = romanDigit + result | |
const newLength = newRomanNumeral.length | |
if (!(newLength in results) && !(newLength in batch)) { | |
batch[newLength] = newRomanNumeral | |
} | |
}) | |
} | |
for (const newLength in batch) { | |
results[newLength] = batch[newLength] | |
} | |
powerOfTen++ | |
} | |
results.forEach((result, i) => { | |
console.log(i, result, result === '' ? '0' : romanToArabic(result)) | |
}) | |
const answer = results[stopAt] | |
console.log(`First Roman numeral which won't fit in a Tweet: ${answer} = ${romanToArabic(answer)}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first Roman numeral which won't fit in a Tweet is X̅̅̅̅̅̅X̅̅̅̅̅̅X̅̅̅̅̅̅V̅̅̅̅̅̅M̅̅̅̅̅M̅̅̅̅̅M̅̅̅̅̅D̅̅̅̅̅C̅̅̅̅̅C̅̅̅̅̅C̅̅̅̅̅L̅̅̅̅̅X̅̅̅̅̅X̅̅̅̅̅X̅̅̅̅̅V̅̅̅̅̅M̅̅̅̅M̅̅̅̅M̅̅̅̅D̅̅̅̅C̅̅̅̅C̅̅̅̅C̅̅̅̅L̅̅̅̅X̅̅̅̅X̅̅̅̅X̅̅̅̅V̅̅̅̅M̅̅̅M̅̅̅M̅̅̅D̅̅̅C̅̅̅C̅̅̅C̅̅̅L̅̅̅X̅̅̅X̅̅̅X̅̅̅V̅̅̅M̅̅M̅̅M̅̅D̅̅C̅̅C̅̅C̅̅L̅̅X̅̅X̅̅X̅̅V̅̅M̅M̅D̅C̅C̅C̅L̅X̅X̅X̅V̅MMMDCCCLXXXVIII = 38,888,888,888,887,888,888.
I used
big-roman
to work this out.