Skip to content

Instantly share code, notes, and snippets.

@fzmaster
Created December 26, 2010 18:47
Show Gist options
  • Save fzmaster/755560 to your computer and use it in GitHub Desktop.
Save fzmaster/755560 to your computer and use it in GitHub Desktop.
Dados 3 codigos, verificar se algum deles eh primo. Se for retorna True, caso contrario False.
import unittest
def ePrimo(valor):
for i in range(2, valor/2 +1):
if (valor % i) == 0:
return False
return True
def CPN(codigo1, codigo2, codigo3):
"""
Autor: fzmaster
Site: http://www.fzmaster.info
Data: 26/12/2010
Problema: The Cube
http://codingkata.org/katas/unit/cube
Dados 3 codigos (string), verificar se algum deles eh primo. Se for retorna True, caso contrario False
"""
total1 = total2 = total3 = 0
for i in codigo1:
total1 += int(i)
for j in codigo2:
total2 += int(j)
for k in codigo3:
total3 += int(k)
if ePrimo(total1) or ePrimo(total2) or ePrimo(total3):
return True
else:
return False
class ContainPrimeNumberTestCase(unittest.TestCase):
def test_1(self):
assert CPN('12','4','4') == False
def test_2(self):
assert CPN('123','4','4') == False
def test_3(self):
assert CPN('31','7','4') == True
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment