Skip to content

Commit dd34a08

Browse files
authoredOct 25, 2023
Add files via upload
1 parent ba6d55e commit dd34a08

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2205
-0
lines changed
 
13.7 KB
Loading
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class LamportClock:
2+
def __init__(self):
3+
self.clock = 0
4+
5+
def get_time(self):
6+
return self.clock
7+
8+
def tick(self):
9+
self.clock += 1
10+
11+
def main():
12+
# Create two Lamport clocks
13+
clock1 = LamportClock()
14+
clock2 = LamportClock()
15+
16+
# Simulate events and clock updates
17+
print(f'Initial Clock 1: {clock1.get_time()}')
18+
print(f'Initial Clock 2: {clock2.get_time()}')
19+
20+
clock1.tick()
21+
print(f'Clock 1 after tick: {clock1.get_time()}')
22+
23+
clock2.tick()
24+
print(f'Clock 2 after tick: {clock2.get_time()}')
25+
26+
# Compare clock values
27+
if clock1.get_time() < clock2.get_time():
28+
print('Clock 1 is behind Clock 2')
29+
elif clock1.get_time() > clock2.get_time():
30+
print('Clock 2 is behind Clock 1')
31+
else:
32+
print('Clock 1 and Clock 2 are synchronized')
33+
34+
if __name__ == "__main__":
35+
main()

0 commit comments

Comments
 (0)
Please sign in to comment.