9,223,372,036,854,775,807 = nine quintillion two hundred twenty three quadrillion three hundred seventy two trillion thirty six billion eight hundred fifty four million seven hundred seventy five thousand eight hundred seven
I've been spending a little time on quora lately, looking at computer programming questions mostly. Most of them are pretty wretched, people who have no idea what they are talking about asking questions that don't make any sense, or people asking how to write elementary programs, questions that you might find in the homework for a programming class, but every once in a while you get a real question that prompts me to reply.
I used to think the requests for elementary programs were from people looking for someone to do their homework for them, but then I realized that a lot of these questions were being answered. Now I wonder if they aren't being churned out by someone looking for points from the quora masters and the people who are answering them are just looking for a little something to occupy their mind. Some people do crosswords, some people do jigsaw puzzles, some people play video games and some people write elementary computer programs.
I write basically useless computer programs, but I have a higher purpose, like I am trying to learn something, or I am trying to explain something, or I just want to see if I can do it. I post them on github, though I don't know if anyone has every bothered to look at them. They're up there if you want to take a look. They are all written in C.
Anyway, one question on quora was asking for a program that could translate a number into the corresponding version written out in English words. This is just my speed, so I set down to write one. It wasn't too difficult and I did learn a few things long the way. Supposedly it will translate an integer up to the largest value that can be held in a 64 bit integer. That's it at the top of the page. Yes, the question only asks for three digit numbers, but you know the old saying "in for a pint, in for a pound" or something like that.
That's a lot of numbers. How can I be sure it is translating them correctly? Well, you write a test program to compute the numeric value from the English words. That one was a little more difficult because I was getting tired and making stupid mistakes, but I got it done. For as much testing as I have done everything seems to check out. I could set it up to test all of the numbers, but I am not sure we have enough time. It took 3.4 seconds to test 1,000,000 (one million) numbers. At that rate it would take an hour to test a billion numbers, a week to test a trillion numbers, 25 years to test a quadrillion numbers, 2,500 years to test a quintillion numbers and 25,000 years to test nine quintillion numbers, and double that if we want to include the negative numbers. Ain't nobody got time for that.
You know, someone has probably already written a library function to do this, but I'd have to Google it, and then I'd have to figure out how to a get a hold of it, and read the instructions on how to use it, and that shit isn't any fun, unless it's something I need in order to do what I want to do. Writing it myself was actually fun.
1 comment:
Maybe the requests for elementary programs are being answered by people who haven't forgotten how tough it was starting out and are willing to give a helping hand by sharing their knowledge.
Post a Comment