Skip to content
Browse files

troco

  • Loading branch information...
1 parent fdcdf1b commit f1a5ab80c28dab3239fbe40e06d383a99508dff9 BoletoPHP Developers committed
View
14 2012/20120808 - troco - python/dojo.log
@@ -0,0 +1,14 @@
+Qua Ago 8 19:16:23 BRT 2012 --- Thiago Belem and Juan Lopes
+Qua Ago 8 19:22:14 BRT 2012 --- Jade Costa and Thiago Belem
+Qua Ago 8 19:32:21 BRT 2012 --- Rodrigo Couto and Jade Costa
+Qua Ago 8 19:38:24 BRT 2012 --- Leandro Thimóteo and Rodrigo Vidal
+Qua Ago 8 19:46:16 BRT 2012 --- Thiago Belem and Leandro Thimóteo
+Qua Ago 8 19:57:02 BRT 2012 --- Juan Lopes and Thiago Belem
+Qua Ago 8 20:02:36 BRT 2012 --- Jacqueline Abreu and Juan Lopes
+Qua Ago 8 20:29:26 BRT 2012 --- Rodrigo Vidal and Jacqueline Abreu
+Qua Ago 8 20:35:08 BRT 2012 --- Jeferson Calazans and Rodrigo Vidal
+Qua Ago 8 20:41:08 BRT 2012 --- Juan Lopes and Jeferson Calazans
+Qua Ago 8 20:49:19 BRT 2012 --- Jade Costa and Juan Lopes
+Qua Ago 8 20:55:58 BRT 2012 --- Fernando Henrique and Jade Costa
+Qua Ago 8 21:09:01 BRT 2012 --- Juan Lopes and Fernando Henrique
+Qua Ago 8 21:14:52 BRT 2012 --- Rodrigo Vidal and Juan Lopes
View
44 2012/20120808 - troco - python/teste_troco.py
@@ -0,0 +1,44 @@
+#coding:utf-8
+import unittest
+from troco import troco
+
+class TestTroco(unittest.TestCase):
+ def test_troco_1(self):
+ self.assertEqual([1], troco(1))
+
+ def test_troco_2(self):
+ self.assertEqual([2], troco(2))
+
+ def test_troco_3(self):
+ self.assertEqual([2, 1], troco(3))
+
+ def test_troco_4(self):
+ self.assertEqual([2, 2], troco(4))
+
+ def test_troco_5(self):
+ self.assertEqual([5], troco(5))
+
+ def test_troco_6(self):
+ self.assertEqual([5, 1], troco(6))
+
+ def test_troco_10(self):
+ self.assertEqual([10], troco(10))
+
+ def test_troco_19(self):
+ self.assertEqual([10, 5, 2, 2], troco(19))
+
+ def test_troco_20(self):
+ self.assertEqual([20], troco(20))
+
+ #def test_troco_50(self):
+ # self.assertEqual([50], troco(50))
+
+ def test_troco_1_e_75(self):
+ self.assertEqual([1, .50, .25], troco(1.75))
+
+ def test_troco_11_com_notas_diferentes(self):
+ self.assertEqual([5, 2, 2, 2], troco(11, [10, 5, 2]))
+
+
+unittest.main()
+
View
29 2012/20120808 - troco - python/troco.py
@@ -0,0 +1,29 @@
+# coding: utf-8
+
+def troco(valor, valores = [100, 50, 20, 10, 5, 2, 1, .50, .25], indice_ultima = 0):
+ if indice_ultima >= len(valores):
+ return None
+
+ if valor < 0:
+ return None
+
+ if valor == 0:
+ return []
+
+ if len(valores) == 0:
+ return None
+
+ pre_resultado1 = troco(valor-valores[indice_ultima], valores, indice_ultima)
+
+ if pre_resultado1 != None:
+ resultado1 = [valores[indice_ultima]] + pre_resultado1
+ else:
+ resultado1 = None
+
+ resultado2 = troco(valor, valores, indice_ultima+1)
+
+ if resultado2 == None or resultado1 != None and len(resultado1) < len(resultado2):
+ return resultado1
+ else:
+ return resultado2
+

0 comments on commit f1a5ab8

Please sign in to comment.
Something went wrong with that request. Please try again.