2

I am trying to find the first occurrence of "12345" in the decimal expansion of $\pi$ by using MySQL. Possibly by using the Instr function?

But I am stuck because it only displays the first 7 fractional digits.

5
  • Where did you get the value of pi? What datatype is it stored in?
    – Rick James
    Mar 14, 2015 at 19:06
  • You might have done that yourself ... Mar 14, 2015 at 19:15
  • @RickJames Actually I did that by SELECT PI() Mar 14, 2015 at 19:34
  • It'd really help if any of you guys could get MyQL to print pi and then I'll use instr to find the first occurrence of 12345 Mar 14, 2015 at 19:35
  • PI() is good to only about 16 decimal places because it is stored in a DOUBLE datatype.
    – Rick James
    Mar 14, 2015 at 20:40

1 Answer 1

1
USE test
DROP TABLE IF EXISTS pi;
CREATE TABLE pi
(
    num BLOB
) ENGINE=MyISAM;
INSERT INTO pi VALUES
('3.14159265358...');
SELECT LOCATE('12345',num) FROM pi;

Here is the output

+---------------------+
| locate('12345',num) |
+---------------------+
|               49704 |
+---------------------+
1 row in set (0.03 sec)

I had to go to http://www.piday.org/million/ and scroll/Ctrl-F dozens of times until my web browser found it. Then, I pasted about 60000 characters into that line. Then, I ran the code using MySQL 5.6.21 on my laptop in Windows 8.1.

Have Fun !!!

UPDATE 2015-03-14 15:52 EST

BTW I just discovered this website : 100,000 Digits of Pi.

This displays pi to 100,000 digits instantly. 12345 is also there.

UPDATE 2015-03-14 15:57 EST

I tried the INSTR() function

+--------------------+
| instr(num,'12345') |
+--------------------+
|              49704 |
+--------------------+
1 row in set (0.00 sec)

It works as well !!!

1
  • 1
    Happy Pi day. 3/14/15
    – Philᵀᴹ
    Mar 14, 2015 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.