Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created October 29, 2020 01:56
Show Gist options
  • Save ZechCodes/1e04b50ad284962cce22e11ba3110a8c to your computer and use it in GitHub Desktop.
Save ZechCodes/1e04b50ad284962cce22e11ba3110a8c to your computer and use it in GitHub Desktop.
Challenge 141 - Apocalyptic Numbers

Challenge 141 - Apocalyptic Numbers

A number n is apocalyptic if 2^n contains a string of 3 consecutive 6s (666 being the presumptive "number of the beast").

Create a function that takes a number n as input. If the number is apocalyptic, find the index of 666 in 2^n, and return "Repent! X days until the Apocalypse!" (X being the index). If not, return "Crisis averted. Resume sinning.".

Examples

apocalyptic(109) ➞ "Crisis averted. Resume sinning."

apocalyptic(157) ➞ "Repent! 9 days until the Apocalypse!"
# 2^157 -> 182687704666362864775460604089535377456991567872
# 666 at 10th position (index 9)

apocalyptic(175) ➞ "Crisis averted. Resume sinning."

apocalyptic(220) ➞ "Repent! 6 days until the Apocalypse!"
import unittest
def apocalyptic(number: int) -> str:
return "" # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual("Repent! 9 days until the Apocalypse!", apocalyptic(157))
def test_2(self):
self.assertEqual("Crisis averted. Resume sinning.", apocalyptic(175))
def test_3(self):
self.assertEqual("Repent! 6 days until the Apocalypse!", apocalyptic(220))
def test_4(self):
self.assertEqual("Crisis averted. Resume sinning.", apocalyptic(333))
def test_5(self):
self.assertEqual("Repent! 138 days until the Apocalypse!", apocalyptic(499))
def test_6(self):
self.assertEqual("Repent! 49 days until the Apocalypse!", apocalyptic(666))
def test_7(self):
self.assertEqual("Crisis averted. Resume sinning.", apocalyptic(1003))
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment