Last active
December 17, 2015 12:29
-
-
Save andersonFaro9/5609810 to your computer and use it in GitHub Desktop.
Problema dos Generais Bizantinos
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
********************************************************* | |
#Problema dos Generais Bizantinos | |
Generais cercam uma cidade com suas tropas. | |
- Generais estão separados pelo relevo, somente podem se comunicar através de mensageiros. | |
- Generais só vencem se todos atacarem ao mesmo tempo. | |
#Teoremas: | |
1º - Se 2/3 + 1 dos generais (processos) forem leais (não falharem), | |
existe uma solução (algoritmo) que resultará numa ação comum, | |
independente de possíveis mensagens enviadas pelos traidores. | |
2º - Se 1/3 ou mais dos generais (processos) forem traidores (falharem), | |
não existe solução para este problema. | |
********************************************************* | |
//General.php | |
<?php | |
namespace bizantino; | |
class General | |
{ | |
public function calcular() | |
{ | |
$lealdade = 1; | |
if(($lealdade/3 * 2 + 1 > 0)){ | |
echo "Processo leal..."; | |
} | |
} | |
} | |
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
<?php | |
namespace bizantino; | |
class Traidor | |
{ | |
public function calcular() | |
{ | |
$traidor = 1; | |
if(($traidor/3 * 2 + 1 < 0)){ | |
echo "Processo desleal..."; | |
} | |
} | |
} |
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
<?php | |
use bizantino\General; | |
use bizantino\Traidor; | |
require_once 'General.php'; | |
require_once 'Traidor.php'; | |
$bi = new General(); | |
$bi->calcular(); | |
$bi = new Traidor(); | |
$bi->calcular(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment