feat: aggiunta la directory 05_patron_slands

This commit is contained in:
alessandro.rabiti 2025-04-02 22:03:52 +02:00
parent c0529108c2
commit aaef21008e
9 changed files with 233 additions and 32 deletions

View file

@ -107,3 +107,9 @@ For example, consider the same shorter file:
Now, the initial compass offset would be 81. The corrections in file order are now +55, +76, -54, and +31. The calculation to find the actual compass offset is now 81+55+76-54+31 = 189. So, the actual compass offset for this file is 189 milliradians. Now, the initial compass offset would be 81. The corrections in file order are now +55, +76, -54, and +31. The calculation to find the actual compass offset is now 81+55+76-54+31 = 189. So, the actual compass offset for this file is 189 milliradians.
Considering your file, what is the actual compass offset in milliradians now? Considering your file, what is the actual compass offset in milliradians now?
## Answers:
Part 1: 30
Part 2: -64
Part 3: 344

View file

@ -119,3 +119,9 @@ Function C: RAISE TO THE POWER OF 3
For this sample file, the highest quality room that the client could afford is 5496. So, the answer for this sample file is 5496. For this sample file, the highest quality room that the client could afford is 5496. So, the answer for this sample file is 5496.
Consider the list of the room qualities and the pricing functions given to you. What is the highest-quality room that the client can afford? Consider the list of the room qualities and the pricing functions given to you. What is the highest-quality room that the client can afford?
## Answers:
Part 1: 15096503329243
Part 2: 1040140609435765472
Part 3: 5237

View file

@ -101,3 +101,9 @@ For example, consider the same sample inventory list:
There are 4 uniquely labelled boxes when pile 1 and pile 2 are combined. There are 6 uniquely labelled boxes when pile 2 and pile 3 are combined. Continuing the process, there are 8 when pile 3 and pile 4 are combined, 8 when pile 4 and pile 5 are combined, and 9 when pile 5 and pile 6 are combined. So, the maximum number of uniquely labelled boxes in two adjacent piles (for this file) is 9. There are 4 uniquely labelled boxes when pile 1 and pile 2 are combined. There are 6 uniquely labelled boxes when pile 2 and pile 3 are combined. Continuing the process, there are 8 when pile 3 and pile 4 are combined, 8 when pile 4 and pile 5 are combined, and 9 when pile 5 and pile 6 are combined. So, the maximum number of uniquely labelled boxes in two adjacent piles (for this file) is 9.
Considering your file, what is the maximum number of uniquely labelled boxes in two adjacent piles? Considering your file, what is the maximum number of uniquely labelled boxes in two adjacent piles?
## Answers:
Part 1: 49528
Part 2: 40490
Part 3: 975

View file

@ -111,3 +111,11 @@ NNNNNNBBVVVVVVVVV
The first line is compressed to 2N1B1U5S1D2S4Z8M and now takes up 142 memory units. The second line is compressed to 1P1W3A1S1Y1B3R7E and now takes up 127 memory units. After compression, the third line takes up 61 memory units, the fourth line takes up 154 memory units, and the fifth line takes up 55 memory units. So, the message will take up 539 memory units after applying this lossless compression scheme. The first line is compressed to 2N1B1U5S1D2S4Z8M and now takes up 142 memory units. The second line is compressed to 1P1W3A1S1Y1B3R7E and now takes up 127 memory units. After compression, the third line takes up 61 memory units, the fourth line takes up 154 memory units, and the fifth line takes up 55 memory units. So, the message will take up 539 memory units after applying this lossless compression scheme.
What is the number of memory units required to store your message on the aeolian transmitter if you compress the message using this lossless compression scheme? What is the number of memory units required to store your message on the aeolian transmitter if you compress the message using this lossless compression scheme?
## Answers:
Part 1: 132305
Part 2: 27304
Part 3: 44282

View file

@ -2,9 +2,12 @@
with open("data.py", "r") as f: with open("data.py", "r") as f:
lines = f.readlines() lines = f.readlines()
# definisco la funzione per convertire le lettere maiuscole nei corrispettivi numeri # definisco la funzione per convertire le lettere maiuscole nei corrispettivi numeri ed i numeri (stringa) nei corrispettivi valori
def letters_to_numbers(text): def letters_to_numbers(text):
return [ord(char) - 64 for char in text.upper() if 'A' <= char <= 'Z'] return [ord(char) - 64 if 'A' <= char <= 'Z' else ord(char) - 48
for char in text.upper()
if ('A' <= char <= 'Z') or ('0' <= char <= '9')
]
# creo la variabile per la somma dei caratteri # creo la variabile per la somma dei caratteri
somma = 0 somma = 0
@ -12,39 +15,41 @@ somma = 0
# per ogni stringa in input (una per riga) # per ogni stringa in input (una per riga)
# lancio la funzione di conversione e sommo il numero di "celle di memoria" # lancio la funzione di conversione e sommo il numero di "celle di memoria"
for line in lines: for line in lines:
#numeri = letters_to_numbers(line.strip()) # definisco una variabile per salvare il valore della lettera corrente nella stringa
# calcolo lunghezza totale della stringa (senza a capo) l = line.strip("\n")[0]
total_len = len(line.strip("\n")) # definisco una variabile per salvare il numero di occorrenze della lettera corrente
# calcolo del numero di lettere da tagliare c = 0
cut = int(total_len/10) # definisco una nuova stringa con solo la prima lettera della stringa originale
# calcolo del numero di caratteri da tenere s = ''
resto = total_len - (2*cut)
# definisco una variabile per ciclare solo fino alla lunghezza richiesta
l = 0
# per ogni riga (tolto a capo) eseguo la funzione per convertire la lettera in numero # per ogni riga (tolto a capo) eseguo la funzione per convertire la lettera in numero
for i in line.strip("\n"): for i in line.strip("\n"):
# se il carattere precedente e' diverso da quello attuale
if l != i:
# aggiungo alla stringa il numero di ricorrenze dell'attuale lettera
s += str(c)
# aggiungo la nuova lettera alla stringa
s += l
# associo alla variabile l il nuovo valore della stringa originale
l = i
# setto ad 1 il count
c = 0
# se se il carattere precedente e' uguale a quello attuale incremento il contatore c
if l == i:
c += 1
# prima di finire il ciclo for aggiungo alla stringa il numero di ricorrenze dell'attuale lettera
s += str(c)
# prima di finire il ciclo for aggiungo la nuova lettera alla stringa
s += l
if l == cut: # aggiungo una variabile per il conteggio parziale dei valori
l = 0 parz = 0
break for i in s:
numero = letters_to_numbers(i) # salvo nella variabile c il valore convertito dell'attuale carattere
# sommo alla variabile, la quota di numeri della prima parte di lettere c = letters_to_numbers(i)
somma += numero[0] # aggiungo il valore numerico alla variabile
l += 1 parz += int(c[0])
# sommo alla variabile la cifra numerica della parte centrale della stringa # sommo il parziale al totale
somma += (sum(int(x) for x in str(resto))) somma += parz
l = 0
# come per il for sopra, ma per le ultime cifre della stringa
for i in reversed(line.strip("\n")):
if l == cut:
l = 0
break
numero = letters_to_numbers(i)
somma += numero[0]
l += 1
print ("Result: ", somma) print ("Result: ", somma)

60
05_patron_slands/data.py Normal file
View file

@ -0,0 +1,60 @@
(-390, 175)
(-102, 364)
(-16, 281)
(-141, -370)
(86, -251)
(400, -55)
(-341, 157)
(124, -45)
(125, 166)
(106, 103)
(29, 261)
(336, -190)
(-278, 380)
(139, 13)
(310, -59)
(221, -34)
(168, 179)
(-226, -142)
(172, -323)
(-371, 212)
(383, 350)
(-227, -332)
(-300, 222)
(323, -313)
(-259, 285)
(44, 108)
(220, -388)
(-109, 34)
(-5, -138)
(21, 263)
(-24, -311)
(87, -220)
(-128, -380)
(117, 143)
(-149, -100)
(-390, -193)
(356, 198)
(270, 329)
(-327, 126)
(-354, 161)
(392, -316)
(-5, -68)
(10, -36)
(-323, 173)
(371, -279)
(-94, -273)
(-192, -241)
(97, 115)
(-78, 398)
(-257, 170)
(-20, -200)
(-13, -56)
(381, 333)
(264, -290)
(-95, 10)
(295, 258)
(-16, -132)
(-132, -141)
(-364, -133)
(-368, -98)

View file

@ -0,0 +1,60 @@
(-390, 175)
(-102, 364)
(-16, 281)
(-141, -370)
(86, -251)
(400, -55)
(-341, 157)
(124, -45)
(125, 166)
(106, 103)
(29, 261)
(336, -190)
(-278, 380)
(139, 13)
(310, -59)
(221, -34)
(168, 179)
(-226, -142)
(172, -323)
(-371, 212)
(383, 350)
(-227, -332)
(-300, 222)
(323, -313)
(-259, 285)
(44, 108)
(220, -388)
(-109, 34)
(-5, -138)
(21, 263)
(-24, -311)
(87, -220)
(-128, -380)
(117, 143)
(-149, -100)
(-390, -193)
(356, 198)
(270, 329)
(-327, 126)
(-354, 161)
(392, -316)
(-5, -68)
(10, -36)
(-323, 173)
(371, -279)
(-94, -273)
(-192, -241)
(97, 115)
(-78, 398)
(-257, 170)
(-20, -200)
(-13, -56)
(381, 333)
(264, -290)
(-95, 10)
(295, 258)
(-16, -132)
(-132, -141)
(-364, -133)
(-368, -98)

View file

@ -0,0 +1,8 @@
(-16, -191)
(92, 186)
(157, -75)
(39, -132)
(-42, 139)
(-74, -150)
(200, 197)
(-106, 105)

42
05_patron_slands/part1.py Normal file
View file

@ -0,0 +1,42 @@
import re
# importo dal file data.py le stringhe date
with open("data.py", "r") as f:
lines = f.readlines()
ma = 0
mi = 0
for line in lines:
myx = 0
myy = 0
# tolgo l'a capo
strip_line = line.strip("\n")
# tolgo la prima parentesi
strip_line_a = strip_line.strip("(")
# tolgo la seconda parentesi
strip_line_b = strip_line_a.strip(")")
# otengo una lista con i due valori numerici
split = strip_line_b.split(",")
print ("Split: ", split)
# ottengo la prima coordinata
x = split[0]
print ("x: ", split[0])
# ottengo la seconda coordinata
y = split[1]
print ("y: ", split[1])
# ottengo la distanza Manhattan
man = abs(myx - int(x)) + abs(int(y) - myy)
print ("man: ", man)
# se l'attuale valore della distanza Manhattan e'
# maggiore di quello salvato, sovrascrivo
if man > ma:
ma = man
# se l'attuale valore della distanza Manhattan e'
# minore di quello salvato o uguale a zero, sovrascrivo
if man < mi or mi == 0:
mi = man
diff = ma - mi
print ("Result Max", ma)
print ("Result Min", mi)
print ("Result", diff)