Created
January 16, 2013 11:11
-
-
Save danilobellini/4546407 to your computer and use it in GitHub Desktop.
Roleta Romana - Solução em Python para o problema do dojo de PHP que ocorreu no dia 2013-01-15 na iMasters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Jan 16 01:17:27 2013 | |
Copyright (C) 2012 Danilo de Jesus da Silva Bellini | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | |
Especificacão do problema: | |
http://dojopuzzles.com/problemas/exibe/roleta-romana/ | |
""" | |
import pytest | |
from collections import deque | |
def sobrevivente_roleta(pessoas, passos, inicio): | |
vivos = deque(xrange(1, pessoas + 1)) | |
vivos.rotate(-inicio) | |
while len(vivos) > 1: | |
vivos.rotate(1 - passos) | |
vivos.popleft() | |
return vivos.popleft() | |
class TestRoleta(object): | |
tabela_testes = [ | |
(1, 1, 1, 1), | |
(2, 1, 1, 1), | |
(2, 1, 2, 2), | |
(2, 2, 1, 2), | |
(2, 2, 2, 1), | |
(3, 1, 1, 1), | |
(3, 1, 2, 2), | |
(3, 1, 3, 3), | |
(3, 2, 1, 1), | |
(3, 2, 2, 2), | |
(3, 2, 3, 3), | |
(3, 3, 1, 3), | |
(3, 3, 2, 1), | |
(3, 3, 3, 2), | |
(4, 1, 1, 1), | |
(4, 1, 2, 2), | |
(4, 1, 3, 3), | |
(4, 1, 4, 4), | |
(4, 2, 1, 2), | |
(4, 2, 2, 3), | |
(4, 2, 3, 4), | |
(4, 2, 4, 1), | |
(4, 3, 1, 2), | |
(4, 3, 2, 3), | |
(4, 3, 3, 4), | |
(4, 3, 4, 1), | |
(4, 4, 1, 3), | |
(4, 4, 2, 4), | |
(4, 4, 3, 1), | |
(4, 4, 4, 2), | |
(5, 1, 1, 1), | |
(5, 1, 2, 2), | |
(5, 1, 3, 3), | |
(5, 1, 4, 4), | |
(5, 1, 5, 5), | |
(5, 2, 1, 4), | |
(5, 2, 2, 5), | |
(5, 2, 3, 1), | |
(5, 2, 4, 2), | |
(5, 2, 5, 3), | |
(5, 3, 1, 5), | |
(5, 3, 2, 1), | |
(5, 3, 3, 2), | |
(5, 3, 4, 3), | |
(5, 3, 5, 4), | |
(5, 4, 1, 2), | |
(5, 4, 2, 3), | |
(5, 4, 3, 4), | |
(5, 4, 4, 5), | |
(5, 4, 5, 1), | |
(5, 5, 1, 3), | |
(5, 5, 2, 4), | |
(5, 5, 3, 5), | |
(5, 5, 4, 1), | |
(5, 5, 5, 2), | |
] | |
@pytest.mark.parametrize(("pessoas", "passos", "inicio", "saida"), | |
tabela_testes) | |
def test_mapeamento_entrada_saida(self, pessoas, passos, inicio, saida): | |
assert sobrevivente_roleta(pessoas, passos, inicio) == saida | |
if __name__ == "__main__": | |
pytest.main('"%s"' % __file__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment