File tree 1 file changed +49
-0
lines changed
Roadmap/35 - REPARTIENDO LOS ANILLOS DE PODER/python
1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ import math
2
+
3
+
4
+ def is_prime (n : int ) -> bool :
5
+ if n <= 1 :
6
+ return False
7
+ for i in range (2 , int (n ** 0.5 ) + 1 ):
8
+ if n % i == 0 :
9
+ return False
10
+ return True
11
+
12
+
13
+ def first_prime_in_range (end : int ) -> int :
14
+ for num in range (0 , end + 1 ):
15
+ if is_prime (num ):
16
+ return num
17
+ return - 1 # Return -1 if no prime number is found
18
+
19
+
20
+ def main ():
21
+ sauron = 1
22
+ dwarves = 0
23
+ elfs = 0
24
+ men = 0
25
+
26
+ try :
27
+ rings = int (input ("> " ))
28
+ rings -= 1
29
+
30
+ dwarves = first_prime_in_range (rings ) if first_prime_in_range (rings ) != - 1 else 0
31
+ rings -= dwarves
32
+
33
+ if dwarves != 0 and rings % 2 != 0 :
34
+ elfs = math .ceil (rings / 2 )
35
+ men = rings - elfs
36
+
37
+ print (f"Sauron - { sauron } " )
38
+ print (f"Enanos - { dwarves } " )
39
+ print (f"Elfos - { elfs } " )
40
+ print (f"Hombres - { men } " )
41
+ else :
42
+ print ("No se ha podido hacer el reparto" )
43
+
44
+ except Exception as e :
45
+ print ("Número incorrecto" )
46
+
47
+
48
+ if __name__ == '__main__' :
49
+ main ()
You can’t perform that action at this time.
0 commit comments