There is a story that the Jews were oppressed and there were harsh decrees and Rav Yonason Eibschitz was challenged by the governor to write "am yisroel chai l'olmei ad" for every Jew who lived in his town on a 2 by 4 mezuzah klaf; if he did so, the governor would stop the harsh decrees. The Rav was given an hour and indeed he managed to create a snaking puzzle with thousands of combinations of "am yisroel chai l'olmei ad".
What is the origin of this story? Supposedly it is in his sefer Tiferes Yonason but I looked and found nothing.
What math equation would be used to prove this?