The Animal-Alphabetical Sequence is an infinite string of letters built accordingly to the following procedure:
Start with the letter
Replace each letter with the name of the animal starting with such letter in the table below;
Go back to step 2.
For instance, the first four steps of the procedure give:
Note that the string obtained at each step is a prefix of the string obtained at the next step. Hence, the procedure does indeed converge to a well-defined infinite string:
Write a function that takes as input an integer
n in the range
[0, 2^31 - 1] and returns as output the
n-th letter of the Animal-Alphabetical Sequence.
The first letter is the
Letters can be uppercase or lowercase.
It must be possible to run the program in the Try It Online interpreter and get the result in at most 5 minutes.
1511763812 -> M 1603218999 -> I 2049234744 -> X 2060411875 -> K 2147483647 -> D
Table of Animal Names
ADDAX BISON CAMEL DINGO EAGLE FOSSA GECKO HORSE INDRI JAMBU KOALA LEMUR MOUSE NYALA OTTER PRAWN QUAIL ROBIN SQUID TIGER URIAL VIXEN WHALE XERUS YAPOK ZEBRA
ZEBRAcan be ignored, because none of the other animal names contain these letters and it always starts with
A. (And as mentioned by @Arnauld, TIO always times out after 60 seconds, so is the time limit we'll have to work with 60 seconds or 300 seconds?) \$\endgroup\$