The Animal-Alphabetical Sequence is an infinite string of letters built accordingly to the following procedure:
Start with the letter
A
;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:
A
ADDAX
ADDAXDINGODINGOADDAXXERUS
ADDAXDINGODINGOADDAXXERUSDINGOINDRINYALAGECKOOTTERDINGOINDRINYALAGECKOOTTERADDAXDINGODINGOADDAXXERUSXERUSEAGLEROBINURIALSQUID
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:
ADDAXDINGODINGOADDAXXERUSDINGOIND...
The Challenge
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.
Notes
The first letter is the
0
-th.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.
Test Cases
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
FOSSA
,JAMBU
,VIXEN
, andZEBRA
can be ignored, because none of the other animal names contain these letters and it always starts withA
. (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\$