Question

In: Computer Science

Byzantine Generals Problem and Solutions  Based on the proposed solutions use any code you want to...

Byzantine Generals Problem and Solutions 

Based on the proposed solutions use any code you want to demonstrate one of the solutions.

Include documentation describing your code

include comments in your code describing each step

Solutions

Expert Solution

Python code screenshot

#army 1 has 10 soldiers
army1soldiers=[1,2,3,4,5,6,7,8,9,10]
#army 2 has 10 soldiers
army2soldiers=[11,12,13,14,15,16,17,18,19,20]
#numbers denotes names of each soldiers
#Assume more number of soldiers dont mean assured victory
#enemycity has 10 soldiers too; numbers as identifiers
enemycity=[21,22,23,24,25,26,27,28,29,30]
import random
random.seed(0)
#Assume messenger is sent by army 1 first
#One of the army 1 soldier is chosen as the messenger
messenger = random.choice(army1soldiers)


#messenger carries a secret flag with him to assure
#he is from the same army
#this flag information is only available to the army
#if flag with messenger is his own flag,
#messenger is real,else messenger is replaced
ourcityflag=0
enemycityflag=1
ismessenger="unknown"
noofmessengerssent=0
while ismessenger!="real" or noofmessengerssent==len(army1soldiers):

flagwithmessenger=random.choice([0,1])
if flagwithmessenger==0:

ismessenger="real"

else:

ismessenger="replaced"

noofmessengerssent = noofmessengerssent + 1

if ismessenger=="real":

print("Time to attack. We will win.")

else:

print("All the army 1 members are gone. We will lose.")

Side note

If we simulate this solution to the 2 generals problem, the probability of the army to win are very high.

But 100% guarantee to winning cannot be assured with this solution.


Related Solutions

You cna hand write this if you want, Please code this in C Thank you PROBLEM...
You cna hand write this if you want, Please code this in C Thank you PROBLEM DESCRIPTION: Write a program to implement the following requirement: The program will read from standard input two things - a string str1 on the first line of stdin (this string may be an empty string) - a string str2 on the second line of stdin (this string may be an empty string) Note that stdin does not end with '\n'. The program will output...
PLEASE DO IN C++ AND USE REPL TO WRITE CODE The following problem statement is based...
PLEASE DO IN C++ AND USE REPL TO WRITE CODE The following problem statement is based on a problem in the C++ text by Friedman & Koffman: The results of a survey of the households in your township are available for public scrutiny. Each record (struct-type entity) contains input data for one household, including a four-digit integer identification number the annual income for the household the number of household members. Assuming that no more than 25 households were surveyed, write...
PART 1 You will want to solve this problem as a Punnett square and use that...
PART 1 You will want to solve this problem as a Punnett square and use that to answer the questions below. You may select multiple answers for the genotypes, and just one answer for the phenotypic ratio. Predict the genotypes of the F1 offspring and phenotypic ratios of these offspring that would result from the following fruit fly crosses: Cross B: a cross between a sepia-eyed male and a white-eyed female (male genotype = Xw+Y se se ; female genotype...
Write the pseudo code for this problem based on what you learned from the video. The...
Write the pseudo code for this problem based on what you learned from the video. The purpose is to design a modular program that asks the user to enter the length and width, and then calculates the area. The formula is as follows: Area = Width x Length
I want the code in the following three PHP files without any CSS. Thank you Create...
I want the code in the following three PHP files without any CSS. Thank you Create a Input.php. Create a PHP script that will perform the following tasks: 1. Divide the content area of this page into two sections (Side by Side) 2. On the left side: create a form that accepts the following information from the user a. Text box, Employee Name b. Text box, Employee ID c. Text box, Telephone Number d. Text box, Email Address e. Radio...
HI.... just I want the <tags> of this scenario .... Scenario-based Problem: You are assigned to...
HI.... just I want the <tags> of this scenario .... Scenario-based Problem: You are assigned to develop a web based Online Electronic showroom in the Sultanate of oman using HTML 5 with CSS, basic JavaScript and PHP&MySQL. The website should contain the following webpages:  Homepage  Sign In  Sign Up  About Us  Product Details  Feedback  Contact Us Following are the details about each page: Page-1: HOMEPAGE (Design using Bootstrap) This page should have picture/s,...
You want to study ribosomes in plant cells and plan to use a protocol based on...
You want to study ribosomes in plant cells and plan to use a protocol based on ultracentrifugation in cesium chloride (CsCl) in order to isolate these structures. What do you expect to find?    A.   Only 70S ribosomes     B.   Both 70 and 80S ribosomes     C.   Plants are boring     D.   Only 80S ribosomes
(In C) Note: Can you create an example code of these tasks. use any variables you...
(In C) Note: Can you create an example code of these tasks. use any variables you wish to use. postfix expressions: (each individual text (T), (F), (NOT), etc is a token) F T NOT T F NOT T T T AND F T F NAND (1) Create stack s. (2) For each token, x, in the postfix expression: If x is T or F push it into the stack s. (T = true, F = false) Else if x is...
Problem 4 ..... you can use Matlab Using the same initial code fragment as in Problem...
Problem 4 ..... you can use Matlab Using the same initial code fragment as in Problem 1, add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the impulse response of an IIR bandstop filter with band edge frequencies 750 Hz and 850 Hz and based on a 4th order Butterworth prototype. Name your program p3.sce the below is the Problem 1 initail code .. you can use it Matlab The following cilab code generates a 10-second “chirp”...
Directions: Below you will find a series of proposed solutions to problems. For each one, you...
Directions: Below you will find a series of proposed solutions to problems. For each one, you are tasked with developing 3 justifications for that solution - one through consequence, one through principle, and one through either precedent or analogy. Because you will need three answers for each, you will end up with 15 answers total. EXAMPLE: Solution: Spanking Children should be made illegal Justification through Principle: because it is wrong to cause bodily pain to children Justification through Consequence: because...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT