1
$\begingroup$

How would one search for a string of digits in a large digit sequence? For example, I'd like to search for 351814 in Euler's number. I'm not too keen on computer science, I'm a pure math major, so I don't really know how to begin. I also wouldn't know how to run said code.

Any help would be greatly appreciated.

$\endgroup$

closed as off-topic by Raphael Apr 27 '14 at 11:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Use the Unix utility grep. $\endgroup$ – Yuval Filmus Apr 22 '14 at 2:26
  • 1
    $\begingroup$ "I'm not too keen on computer science" -- I take it you don't the CS answer, "use any of countless string matching algorithms" (which would be too broad) but a programming/computer literacy answer. As such, your question is offtopic; I recommend Stack Overflow or Super User (but be aware, yours is a very basic question solved by rudimentary library functions resp. CTRL+F). $\endgroup$ – Raphael Apr 27 '14 at 11:40
4
$\begingroup$

Use your web browser. You can get the first 2 million or so digits in this link, and then use your browser's searching facilities. I was able to locate 351814 within the first 2 million digits (though not within the first 1 million digits, available in a separate link). By the way, I found both links on Wikipedia.

$\endgroup$
0
$\begingroup$

Are you asking for a method to going about doing this using a programming language or an algorithm you could implement?

Assuming you had a string containing the digits of Euler's Number you could use a built in function like the following:

(In Java) : eulerNumberString.indexOf("351814");
(In C++) : https://stackoverflow.com/questions/13195353/how-to-find-substring-from-string

If you want an algorithm the simplest I could think of would be to go through the string of digits from start to end looking for the start of your sequence. Once you find it, say "3" in your example, you would check to see if the next five digits are "51814". If not, then start from the next character after that "3" (you could optimize this) and look for the next "3" to try again.

$\endgroup$
  • $\begingroup$ Don't make up algorithms for problems that have already been solved! We've had over fifty years of computer scientists coming up with smart algorithms so you don't have to use the simplest thing you can think of. For example, your "you could optimize this" is, essentially, "Use Knuth–Morris–Pratt." $\endgroup$ – David Richerby Apr 27 '14 at 11:54

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