feat: primo commit, completati primi due esercizi
This commit is contained in:
commit
c41cabedd0
16 changed files with 1299 additions and 0 deletions
109
01_compass_calibration/README.md
Normal file
109
01_compass_calibration/README.md
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
# Codyssi - Compass Calibration!
|
||||
|
||||
## Part 1
|
||||
Difficulty Rating: 1
|
||||
|
||||
Following analysis of the data from the drones surveying the Atlantic Ocean, your lab is confident that they’ve located the fabled city of Atlantis!
|
||||
|
||||
Your team has been handpicked for this once-in-a-lifetime research mission. What an honor! Over the course of this trip, you know you’ll be facing a host of natural and supernatural threats. Luckily, your trusty laptop is waterproof, so you should be fine. Probably.
|
||||
|
||||
Soon enough, you and your team find yourselves in a sturdy land vehicle built for all-terrain travel, which will autonomously drive to the beach. There’s just one small issue: the autonomous vehicle isn’t driving itself…
|
||||
|
||||
“Look! It’s the navigation module! It must be faulty…”
|
||||
|
||||
Excellent! That’s not a hard fix: you’ll just have to recalibrate the vehicle’s compass!
|
||||
|
||||
You start the calibration diagnostics: 600 numbers and a long sequence of symbols appear on the monitor. Each number represents a reading in milliradians.
|
||||
|
||||
The first number in the file represents the initial compass offset. However, this isn’t the actual compass offset.
|
||||
|
||||
The following numbers represent the magnitudes (sizes) of the corrections to the initial compass offset. So, the second number corresponds to the first correction, the third number corresponds to the second correction, and so on.
|
||||
|
||||
The sequence of symbols is 599 characters in length and consists of “+” and “-”, representing the sign of each correction. The first symbol corresponds to the first correction, the second symbol corresponds to the second correction, and so on.
|
||||
|
||||
The vehicle’s actual compass offset, measured in milliradians, is calculated by adding all the corrections to the initial compass offset.
|
||||
|
||||
For example, consider this shorter file, with only 10 numbers and 9 symbols:
|
||||
|
||||
8
|
||||
1
|
||||
5
|
||||
5
|
||||
7
|
||||
6
|
||||
5
|
||||
4
|
||||
3
|
||||
1
|
||||
-++-++-++
|
||||
|
||||
|
||||
The initial compass offset in this file is 8. The first correction is -1, the second correction is +5, the third correction is +5, and so on. To calculate the actual compass offset, the following calculation is performed: 8-1+5+5-7+6+5-4+3+1 = 21. So, for this shorter input, the actual compass offset is 21 milliradians.
|
||||
|
||||
Now, considering your file, what is the actual compass offset of the vehicle in milliradians?
|
||||
|
||||
(The answer is a number; do not enter ‘milliradians’ as part of your answer.)
|
||||
|
||||
## Part 2
|
||||
Difficulty Rating: 1
|
||||
|
||||
You enter the actual compass offset into the vehicle, and you notice that the navigation system is still faulty. Perhaps you missed something?
|
||||
|
||||
“Oh! The sequence of symbols is stated to be displayed in reverse order!”
|
||||
|
||||
Ah. You’ve missed a key instruction. No worries; it happens to the best of us.
|
||||
|
||||
As the sequence of symbols is in reverse order, the last symbol now corresponds to the first correction, the second-last symbol now corresponds to the second correction, and so on. You’ll still have to determine the actual compass offset by adding all the corrections to the initial compass offset.
|
||||
|
||||
For example, consider the same shorter file:
|
||||
|
||||
8
|
||||
1
|
||||
5
|
||||
5
|
||||
7
|
||||
6
|
||||
5
|
||||
4
|
||||
3
|
||||
1
|
||||
-++-++-++
|
||||
|
||||
|
||||
The initial compass offset in this file is still 8; however, some of the corrections have changed! The first correction is now +1, the second correction is +5, the third correction is now -5, and so on. To calculate the actual compass offset now, the following calculation is performed: 8+1+5-5+7+6-5+4+3-1 = 23, and so the actual compass offset is now 23 milliradians.
|
||||
|
||||
Considering your file, what is the new actual compass offset of the vehicle in milliradians?
|
||||
|
||||
## Part 3
|
||||
Difficulty Rating: 2
|
||||
|
||||
You’ve taken a step in the right direction, but the navigation system still seems a little defective! Whatever caused this issue, it better not be another missed instruction…
|
||||
|
||||
Oh, would you look at that, another team member spots another instruction that you somehow missed. This is going great, isn’t it?
|
||||
|
||||
The initial compass offset and all the corrections are meant to be 2-digit numbers!
|
||||
|
||||
The instruction states that the readings are represented by the two numbers on pairs of consecutive lines. This means that the first reading is represented by lines 1 and 2, the second is represented by lines 3 and 4, the third is represented by lines 5 and 6, and so on.
|
||||
|
||||
For each pair of lines, the first number represents the tens digit of the reading, and the second number represents the ones digit of the reading.
|
||||
|
||||
Though, this means that you won’t use all of the symbols in the file.
|
||||
|
||||
For example, consider the same shorter file:
|
||||
|
||||
8
|
||||
1
|
||||
5
|
||||
5
|
||||
7
|
||||
6
|
||||
5
|
||||
4
|
||||
3
|
||||
1
|
||||
-++-++-++
|
||||
|
||||
|
||||
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?
|
||||
BIN
01_compass_calibration/__pycache__/matrix.cpython-313.pyc
Normal file
BIN
01_compass_calibration/__pycache__/matrix.cpython-313.pyc
Normal file
Binary file not shown.
601
01_compass_calibration/matrix.py
Normal file
601
01_compass_calibration/matrix.py
Normal file
|
|
@ -0,0 +1,601 @@
|
|||
n="""4
|
||||
9
|
||||
5
|
||||
1
|
||||
8
|
||||
8
|
||||
9
|
||||
4
|
||||
5
|
||||
5
|
||||
3
|
||||
1
|
||||
5
|
||||
8
|
||||
7
|
||||
3
|
||||
2
|
||||
3
|
||||
4
|
||||
7
|
||||
4
|
||||
8
|
||||
8
|
||||
1
|
||||
1
|
||||
5
|
||||
6
|
||||
9
|
||||
1
|
||||
7
|
||||
7
|
||||
9
|
||||
1
|
||||
6
|
||||
8
|
||||
2
|
||||
9
|
||||
4
|
||||
4
|
||||
5
|
||||
1
|
||||
1
|
||||
8
|
||||
3
|
||||
8
|
||||
3
|
||||
2
|
||||
1
|
||||
3
|
||||
2
|
||||
4
|
||||
9
|
||||
3
|
||||
5
|
||||
3
|
||||
7
|
||||
7
|
||||
9
|
||||
3
|
||||
6
|
||||
8
|
||||
9
|
||||
2
|
||||
2
|
||||
1
|
||||
9
|
||||
1
|
||||
4
|
||||
9
|
||||
8
|
||||
9
|
||||
8
|
||||
4
|
||||
9
|
||||
9
|
||||
6
|
||||
2
|
||||
3
|
||||
7
|
||||
3
|
||||
5
|
||||
9
|
||||
8
|
||||
1
|
||||
2
|
||||
8
|
||||
2
|
||||
3
|
||||
3
|
||||
9
|
||||
4
|
||||
6
|
||||
5
|
||||
1
|
||||
7
|
||||
4
|
||||
9
|
||||
5
|
||||
7
|
||||
5
|
||||
1
|
||||
8
|
||||
4
|
||||
1
|
||||
1
|
||||
4
|
||||
9
|
||||
5
|
||||
8
|
||||
1
|
||||
8
|
||||
7
|
||||
2
|
||||
2
|
||||
6
|
||||
7
|
||||
9
|
||||
9
|
||||
4
|
||||
7
|
||||
3
|
||||
9
|
||||
5
|
||||
2
|
||||
9
|
||||
7
|
||||
3
|
||||
4
|
||||
1
|
||||
1
|
||||
8
|
||||
9
|
||||
4
|
||||
5
|
||||
8
|
||||
7
|
||||
2
|
||||
5
|
||||
1
|
||||
3
|
||||
5
|
||||
9
|
||||
3
|
||||
8
|
||||
4
|
||||
7
|
||||
2
|
||||
8
|
||||
2
|
||||
6
|
||||
6
|
||||
9
|
||||
6
|
||||
8
|
||||
7
|
||||
5
|
||||
7
|
||||
5
|
||||
1
|
||||
1
|
||||
9
|
||||
3
|
||||
9
|
||||
8
|
||||
2
|
||||
4
|
||||
8
|
||||
1
|
||||
8
|
||||
3
|
||||
6
|
||||
4
|
||||
3
|
||||
8
|
||||
2
|
||||
1
|
||||
4
|
||||
7
|
||||
7
|
||||
9
|
||||
6
|
||||
3
|
||||
3
|
||||
8
|
||||
3
|
||||
8
|
||||
3
|
||||
1
|
||||
7
|
||||
6
|
||||
3
|
||||
8
|
||||
1
|
||||
3
|
||||
2
|
||||
3
|
||||
7
|
||||
9
|
||||
2
|
||||
6
|
||||
3
|
||||
7
|
||||
2
|
||||
4
|
||||
6
|
||||
2
|
||||
7
|
||||
2
|
||||
8
|
||||
6
|
||||
9
|
||||
5
|
||||
5
|
||||
3
|
||||
2
|
||||
7
|
||||
8
|
||||
3
|
||||
3
|
||||
4
|
||||
7
|
||||
9
|
||||
9
|
||||
3
|
||||
7
|
||||
5
|
||||
5
|
||||
7
|
||||
1
|
||||
8
|
||||
4
|
||||
4
|
||||
2
|
||||
5
|
||||
8
|
||||
9
|
||||
5
|
||||
2
|
||||
5
|
||||
4
|
||||
5
|
||||
6
|
||||
5
|
||||
1
|
||||
2
|
||||
4
|
||||
7
|
||||
8
|
||||
9
|
||||
6
|
||||
6
|
||||
5
|
||||
4
|
||||
3
|
||||
1
|
||||
6
|
||||
2
|
||||
6
|
||||
4
|
||||
8
|
||||
9
|
||||
2
|
||||
5
|
||||
4
|
||||
6
|
||||
3
|
||||
1
|
||||
8
|
||||
2
|
||||
8
|
||||
7
|
||||
5
|
||||
9
|
||||
4
|
||||
1
|
||||
4
|
||||
9
|
||||
5
|
||||
7
|
||||
3
|
||||
5
|
||||
6
|
||||
6
|
||||
9
|
||||
8
|
||||
7
|
||||
2
|
||||
3
|
||||
5
|
||||
6
|
||||
4
|
||||
8
|
||||
8
|
||||
2
|
||||
5
|
||||
9
|
||||
9
|
||||
7
|
||||
1
|
||||
9
|
||||
3
|
||||
4
|
||||
9
|
||||
9
|
||||
8
|
||||
9
|
||||
6
|
||||
7
|
||||
2
|
||||
5
|
||||
7
|
||||
6
|
||||
1
|
||||
3
|
||||
6
|
||||
1
|
||||
3
|
||||
7
|
||||
3
|
||||
7
|
||||
1
|
||||
2
|
||||
8
|
||||
3
|
||||
8
|
||||
7
|
||||
6
|
||||
9
|
||||
1
|
||||
4
|
||||
9
|
||||
8
|
||||
1
|
||||
4
|
||||
1
|
||||
5
|
||||
8
|
||||
2
|
||||
7
|
||||
7
|
||||
2
|
||||
6
|
||||
8
|
||||
7
|
||||
1
|
||||
5
|
||||
6
|
||||
4
|
||||
4
|
||||
9
|
||||
8
|
||||
6
|
||||
6
|
||||
2
|
||||
9
|
||||
6
|
||||
4
|
||||
9
|
||||
8
|
||||
7
|
||||
7
|
||||
9
|
||||
4
|
||||
4
|
||||
9
|
||||
3
|
||||
6
|
||||
7
|
||||
3
|
||||
6
|
||||
9
|
||||
3
|
||||
3
|
||||
4
|
||||
6
|
||||
2
|
||||
3
|
||||
7
|
||||
2
|
||||
3
|
||||
4
|
||||
2
|
||||
3
|
||||
3
|
||||
6
|
||||
5
|
||||
5
|
||||
4
|
||||
4
|
||||
7
|
||||
4
|
||||
8
|
||||
5
|
||||
3
|
||||
8
|
||||
1
|
||||
3
|
||||
2
|
||||
7
|
||||
2
|
||||
5
|
||||
1
|
||||
2
|
||||
4
|
||||
4
|
||||
7
|
||||
7
|
||||
9
|
||||
5
|
||||
3
|
||||
1
|
||||
8
|
||||
7
|
||||
2
|
||||
6
|
||||
5
|
||||
8
|
||||
8
|
||||
7
|
||||
3
|
||||
9
|
||||
9
|
||||
3
|
||||
3
|
||||
6
|
||||
1
|
||||
5
|
||||
2
|
||||
2
|
||||
4
|
||||
5
|
||||
4
|
||||
8
|
||||
1
|
||||
3
|
||||
3
|
||||
2
|
||||
4
|
||||
4
|
||||
2
|
||||
7
|
||||
1
|
||||
1
|
||||
7
|
||||
8
|
||||
5
|
||||
1
|
||||
2
|
||||
4
|
||||
7
|
||||
4
|
||||
7
|
||||
9
|
||||
6
|
||||
3
|
||||
5
|
||||
2
|
||||
6
|
||||
5
|
||||
5
|
||||
6
|
||||
7
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
4
|
||||
3
|
||||
7
|
||||
2
|
||||
9
|
||||
5
|
||||
7
|
||||
6
|
||||
6
|
||||
3
|
||||
5
|
||||
1
|
||||
3
|
||||
5
|
||||
4
|
||||
1
|
||||
1
|
||||
1
|
||||
6
|
||||
7
|
||||
4
|
||||
5
|
||||
5
|
||||
5
|
||||
2
|
||||
4
|
||||
1
|
||||
7
|
||||
3
|
||||
4
|
||||
8
|
||||
2
|
||||
7
|
||||
5
|
||||
7
|
||||
3
|
||||
9
|
||||
7
|
||||
1
|
||||
1
|
||||
3
|
||||
9
|
||||
4
|
||||
1
|
||||
8
|
||||
2
|
||||
7
|
||||
9
|
||||
2
|
||||
2
|
||||
7
|
||||
5
|
||||
6
|
||||
8
|
||||
7
|
||||
7
|
||||
1
|
||||
4
|
||||
3
|
||||
7
|
||||
6
|
||||
3
|
||||
6
|
||||
5
|
||||
7
|
||||
5
|
||||
7
|
||||
3
|
||||
1
|
||||
9
|
||||
4
|
||||
7
|
||||
5
|
||||
9
|
||||
7
|
||||
4
|
||||
2
|
||||
3
|
||||
8
|
||||
8
|
||||
9
|
||||
6
|
||||
4
|
||||
5
|
||||
5
|
||||
8
|
||||
8
|
||||
9
|
||||
6
|
||||
1
|
||||
7
|
||||
9
|
||||
6
|
||||
8
|
||||
2
|
||||
8
|
||||
2
|
||||
4
|
||||
9
|
||||
5
|
||||
4
|
||||
9
|
||||
3
|
||||
6
|
||||
3
|
||||
7
|
||||
4
|
||||
6
|
||||
8
|
||||
9
|
||||
1
|
||||
7
|
||||
8
|
||||
7
|
||||
4
|
||||
1
|
||||
5
|
||||
8
|
||||
7
|
||||
2
|
||||
8
|
||||
1
|
||||
7
|
||||
3
|
||||
1
|
||||
7
|
||||
2
|
||||
1
|
||||
8
|
||||
9
|
||||
3
|
||||
4
|
||||
5
|
||||
2"""
|
||||
s="""+-------++---+--+++++-----+--++++-+--+-+--++--+++--+-----++--++--++-+++------++-+++--+---+-+++-+-++-+-+-++-+++---+-+++-+-+--++---+-+++--+-++++-+++-+-+-+-+-++-+---+-+-++-+--++-+--+-+---++++-+-----+++-++-++++--+-+++-++++-+-+-+------++++------++----++-++---+---+------+-++-+-+-----+++++++--+++--+-+--+++---++-++--+-+-++--+++--+-----++---++---++--+++++--+----++++--++----+--++----+-++++--++--++---++----+++-+++++--++-++-++---+++--++-++++++++----++--+++-+-+++-+--+++++-+-++-+--+---+---+--+-+--++-++--+-+-++++-+++---+-+-+-+++-+--+-+--++--+--++--++-++++-++-+--+-----++++--++--+---+++-++-+--+--+++-++--++++-"""
|
||||
32
01_compass_calibration/part1.py
Normal file
32
01_compass_calibration/part1.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import importlib.util
|
||||
|
||||
# Import del file con le liste di numeri ed operatori
|
||||
data = "matrix.py"
|
||||
|
||||
spec = importlib.util.spec_from_file_location("matrix", data)
|
||||
matrix = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(matrix)
|
||||
|
||||
# creo una lista vuota
|
||||
num = []
|
||||
|
||||
# per ogni riga della lisa dei numeri estraggo il valore
|
||||
# mi serve perche' se no prende l'andare a capo come valore
|
||||
for line in matrix.n.splitlines():
|
||||
num.append(line)
|
||||
|
||||
# creo la variabile per sommare i valori
|
||||
# la definisco con il valore del primo numero
|
||||
# converto la stringa contenuta nella lista in intero
|
||||
result = int(num[0])
|
||||
|
||||
# ciclo insieme tutti i numeri e gli operatori, partendo dal
|
||||
#secondo numero della lista dei valori
|
||||
for n, op in zip(num[1:], matrix.s):
|
||||
if op == '+':
|
||||
result += int(n)
|
||||
if op == '-':
|
||||
result -= int(n)
|
||||
|
||||
#stampo il risultato
|
||||
print("result =", result)
|
||||
36
01_compass_calibration/part2.py
Normal file
36
01_compass_calibration/part2.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import importlib.util
|
||||
|
||||
# Import del file con le liste di numeri ed operatori
|
||||
data = "matrix.py"
|
||||
|
||||
spec = importlib.util.spec_from_file_location("matrix", data)
|
||||
matrix = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(matrix)
|
||||
|
||||
# creo una lista vuota
|
||||
num = []
|
||||
|
||||
# per ogni riga della lisa dei numeri estraggo il valore
|
||||
# mi serve perche' se no prende l'andare a capo come valore
|
||||
for line in matrix.n.splitlines():
|
||||
num.append(line)
|
||||
|
||||
# creo la variabile per sommare i valori
|
||||
# la definisco con il valore del primo numero
|
||||
# converto la stringa contenuta nella lista in intero
|
||||
result = int(num[0])
|
||||
|
||||
#inverto la stringa degli operatori
|
||||
s_inverted = matrix.s[::-1]
|
||||
|
||||
|
||||
# ciclo insieme tutti i numeri e gli operatori (invertiti), partendo dal
|
||||
#secondo numero della lista dei valori
|
||||
for n, op in zip(num[1:], s_inverted):
|
||||
if op == '+':
|
||||
result += int(n)
|
||||
if op == '-':
|
||||
result -= int(n)
|
||||
|
||||
#stampo il risultato
|
||||
print("result =", result)
|
||||
44
01_compass_calibration/part3.py
Normal file
44
01_compass_calibration/part3.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import importlib.util
|
||||
|
||||
# Import del file con le liste di numeri ed operatori
|
||||
data = "matrix.py"
|
||||
|
||||
spec = importlib.util.spec_from_file_location("matrix", data)
|
||||
matrix = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(matrix)
|
||||
|
||||
# creo una lista vuota
|
||||
num = []
|
||||
|
||||
# per ogni riga della lisa dei numeri estraggo il valore
|
||||
# mi serve perche' se no prende l'andare a capo come valore
|
||||
for line in matrix.n.splitlines():
|
||||
num.append(line)
|
||||
|
||||
#inverto la stringa degli operatori
|
||||
s_inverted = matrix.s[::-1]
|
||||
|
||||
# creo una nuova lista di lunghezza pari alla meta' dei numeri a disposizione
|
||||
elementi = int(len(num)/2)
|
||||
|
||||
# scorro i tre array, i numeri in posizione pari sono unita', i numeri in
|
||||
# posizione dispari (faccio per 10) sono decine e poi sommo tutto nella nuova lista
|
||||
new_num = [0] * elementi
|
||||
for n, (d, u) in enumerate(zip(num[::2], num[1::2])):
|
||||
new_num[n] += int(u) + (int(d)*10)
|
||||
|
||||
# creo la variabile per sommare i valori
|
||||
# la definisco con il valore del primo numero
|
||||
# converto la stringa contenuta nella lista in intero
|
||||
result = int(new_num[0])
|
||||
|
||||
# ciclo insieme tutti i numeri e gli operatori (invertiti), partendo dal
|
||||
#secondo numero della lista dei valori
|
||||
for n, op in zip(new_num[1:], s_inverted):
|
||||
if op == '+':
|
||||
result += int(n)
|
||||
if op == '-':
|
||||
result -= int(n)
|
||||
|
||||
#stampo il risultato
|
||||
print("result =", result)
|
||||
121
02_absurd_arithmetic/README.md
Normal file
121
02_absurd_arithmetic/README.md
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
# Codyssi - Absurd Arithmetic!
|
||||
|
||||
## Part 1
|
||||
Difficulty Rating: 1
|
||||
|
||||
You and your team are now on course to the seaside. It’s getting pretty late though, so why not rest? After all, you’ll probably need it.
|
||||
|
||||
You arrive at the nearest hotel. You walk in, and registration goes quite well!
|
||||
|
||||
Well, up until the peculiar payment process.
|
||||
|
||||
The hotel accepts normal currency, but they calculate their prices in exponentialis pecunia. Oddly, its exchange rate to standard currencies increases exponentially.
|
||||
|
||||
Why would anyone ever use this?
|
||||
|
||||
“Don’t worry, we have a machine that converts from exponentialis pecunia to standard currency. I just need the book of room pricings… Here it is… Wait, it’s not here? Oh no…”
|
||||
|
||||
The clerk has lost her pricing book—you’ll have to help her calculate the room prices!
|
||||
|
||||
“There are 3 pricing functions used to calculate room prices. To calculate the price of a room, you start with the quality of the room. First, apply function C, then apply function B, and then apply function A. The resulting value is the one-night price of a room in exponentialis pecunia.”
|
||||
|
||||
To figure out if you’ll have enough money to stay for the night, a good point to start would be to consider the median-quality room.
|
||||
|
||||
You remind yourself that the median is the middle value in a sorted list.
|
||||
|
||||
For example, consider the following list with 11 room qualities and 3 different pricing functions:
|
||||
|
||||
Function A: ADD 495
|
||||
Function B: MULTIPLY 55
|
||||
Function C: RAISE TO THE POWER OF 3
|
||||
|
||||
5219
|
||||
8933
|
||||
3271
|
||||
7128
|
||||
9596
|
||||
9407
|
||||
7005
|
||||
1607
|
||||
4084
|
||||
4525
|
||||
5496
|
||||
|
||||
|
||||
For these room qualities, the median quality is 5496. Applying function C, you get 166012263936. Applying function B to that result gives you 9130674516480. Finally, applying function A to that result gives 9130674516975. So the one-night price of the median-quality room, in exponentialis pecunia, is 9130674516975.
|
||||
|
||||
Consider the list of 101 room qualities and the 3 pricing functions given to you. What is the one-night price of the median-quality room in exponentialis pecunia?
|
||||
|
||||
(Enter your answer as a single number without commas.)
|
||||
|
||||
## Part 2
|
||||
Difficulty Rating: 2
|
||||
|
||||
When converted to normal currency, that actually seems quite cheap!
|
||||
|
||||
Though, each member of your team will probably need their own rooms, won’t they…
|
||||
|
||||
“Oh, about that, the hotel charges extra fees for booking more than one room. To calculate the total one-night price for many rooms, you first sum all the rooms’ qualities. Then, you apply function C, then B, then A on the sum. This will give you the one-night price of the rooms in exponentialis pecunia.”
|
||||
|
||||
To get a (very, very generous) upper bound estimate of the total price for your team, you decide to calculate the total price of booking all the rooms with even-numbered room qualities for one night.
|
||||
|
||||
For example, consider the same list with 11 room qualities and 3 different pricing functions:
|
||||
|
||||
Function A: ADD 495
|
||||
Function B: MULTIPLY 55
|
||||
Function C: RAISE TO THE POWER OF 3
|
||||
|
||||
5219
|
||||
8933
|
||||
3271
|
||||
7128
|
||||
9596
|
||||
9407
|
||||
7005
|
||||
1607
|
||||
4084
|
||||
4525
|
||||
5496
|
||||
|
||||
|
||||
The even-numbered room qualities are 7128, 9596, 4084, and 5496. Their sum is 26304, so by applying the 3 pricing functions in the correct order, the total one-night price of booking these rooms is 1000986169836015.
|
||||
|
||||
Considering your file, what is the total one-night price of all the rooms with an even-numbered room quality, in exponentialis pecunia?
|
||||
|
||||
## Part 3
|
||||
Difficulty Rating: 2
|
||||
|
||||
The upper bound still seems quite reasonable! You and your team members choose rooms and pay for your stay—off to a good night’s sleep!
|
||||
|
||||
As the rest of your team members head to their rooms, you notice the clerk bring out an abnormally large pile of paper. She begins to write furiously, and she seems quite stressed. You’ve gotten too curious now…
|
||||
|
||||
“I have to calculate some room prices since, you know, I lost the pricing book. Come to think of it, you calculated your room prices quite quickly… Do you mind helping me out?”
|
||||
|
||||
She won’t get any sleep without your help, so you can’t really say no, can you?
|
||||
|
||||
She explains the situation to you. A client wants to book a room for one night. He can pay at most 15000000000000 exponentialis pecunia, and he wants the highest quality room that he can afford.
|
||||
|
||||
You’ll have to determine the quality of the room that fits the client’s request.
|
||||
|
||||
For example, consider the same list with 11 room qualities and 3 different pricing functions:
|
||||
|
||||
Function A: ADD 495
|
||||
Function B: MULTIPLY 55
|
||||
Function C: RAISE TO THE POWER OF 3
|
||||
|
||||
5219
|
||||
8933
|
||||
3271
|
||||
7128
|
||||
9596
|
||||
9407
|
||||
7005
|
||||
1607
|
||||
4084
|
||||
4525
|
||||
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?
|
||||
BIN
02_absurd_arithmetic/__pycache__/data.cpython-313.pyc
Normal file
BIN
02_absurd_arithmetic/__pycache__/data.cpython-313.pyc
Normal file
Binary file not shown.
104
02_absurd_arithmetic/data.py
Normal file
104
02_absurd_arithmetic/data.py
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
a = 160
|
||||
b = 97
|
||||
c = 3
|
||||
qr = """7785
|
||||
2080
|
||||
6554
|
||||
6447
|
||||
6575
|
||||
4626
|
||||
7337
|
||||
2930
|
||||
9889
|
||||
2894
|
||||
6288
|
||||
7679
|
||||
5434
|
||||
3987
|
||||
2069
|
||||
6270
|
||||
1974
|
||||
2328
|
||||
7251
|
||||
4671
|
||||
1948
|
||||
4825
|
||||
7298
|
||||
8749
|
||||
1153
|
||||
6904
|
||||
9938
|
||||
1855
|
||||
9577
|
||||
4850
|
||||
7004
|
||||
2152
|
||||
7829
|
||||
4256
|
||||
2632
|
||||
3849
|
||||
9689
|
||||
9839
|
||||
6538
|
||||
1038
|
||||
9044
|
||||
5371
|
||||
6273
|
||||
6439
|
||||
3902
|
||||
4700
|
||||
2710
|
||||
5647
|
||||
1385
|
||||
9923
|
||||
6336
|
||||
4275
|
||||
2354
|
||||
7509
|
||||
5237
|
||||
2012
|
||||
2051
|
||||
6221
|
||||
1259
|
||||
5379
|
||||
3270
|
||||
5432
|
||||
1577
|
||||
7091
|
||||
1478
|
||||
8347
|
||||
6969
|
||||
9682
|
||||
2686
|
||||
2888
|
||||
2198
|
||||
2276
|
||||
5437
|
||||
4051
|
||||
6935
|
||||
6410
|
||||
1674
|
||||
1217
|
||||
4624
|
||||
3389
|
||||
2138
|
||||
8049
|
||||
7633
|
||||
5545
|
||||
4987
|
||||
8038
|
||||
6979
|
||||
3480
|
||||
5392
|
||||
6344
|
||||
1417
|
||||
7574
|
||||
2089
|
||||
7494
|
||||
7757
|
||||
3655
|
||||
8975
|
||||
5695
|
||||
1038
|
||||
1057
|
||||
9406"""
|
||||
26
02_absurd_arithmetic/part1.py
Normal file
26
02_absurd_arithmetic/part1.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# importo la funzine per fare la mediana
|
||||
import statistics
|
||||
# importo il file con le variabili
|
||||
import data
|
||||
|
||||
# creo una lista vuota
|
||||
qrn = []
|
||||
|
||||
# ciclo tutti i valori dati per popolare la lista
|
||||
# data la stringa multilinea iniziale
|
||||
for line in data.qr.splitlines():
|
||||
qrn.append(line)
|
||||
|
||||
|
||||
#print("Median of data-set is : % s "
|
||||
# % (statistics.median(qrn)))
|
||||
|
||||
# calcolo la mediana
|
||||
p_result = statistics.median(qrn)
|
||||
|
||||
# applico le tre funzioni
|
||||
c_function = int(p_result) ** data.c
|
||||
b_function = c_function * data.b
|
||||
a_function = b_function + data.a
|
||||
|
||||
print("Result : ", a_function)
|
||||
31
02_absurd_arithmetic/part2.py
Normal file
31
02_absurd_arithmetic/part2.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# importo la funzine per fare la mediana
|
||||
import statistics
|
||||
# importo il file con le variabili
|
||||
import data
|
||||
|
||||
# creo una lista vuota
|
||||
qrn = []
|
||||
|
||||
# ciclo tutti i valori dati per popolare la lista
|
||||
# data la stringa multilinea iniziale
|
||||
for line in data.qr.splitlines():
|
||||
qrn.append(line)
|
||||
|
||||
# creo una nuova lista in cui inserisco i valori
|
||||
# presenti nella lista qrn se dividendoli per 2
|
||||
# hanno resto zero
|
||||
qrn_even = [int(val) for val in qrn if int(val) % 2 == 0]
|
||||
|
||||
# aggiungo una variabile per sommare i valori pari della lista
|
||||
qrn_even_sum = 0
|
||||
|
||||
# sommo tutti i valori pari della lista
|
||||
for x in qrn_even:
|
||||
qrn_even_sum += x
|
||||
|
||||
# applico le tre funzioni
|
||||
c_function = qrn_even_sum ** data.c
|
||||
b_function = c_function * data.b
|
||||
a_function = b_function + data.a
|
||||
|
||||
print("Result : ", a_function)
|
||||
42
02_absurd_arithmetic/part3.py
Normal file
42
02_absurd_arithmetic/part3.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# importo la funzine per fare la mediana
|
||||
import statistics
|
||||
# importo il file con le variabili
|
||||
import data
|
||||
|
||||
# creo una lista vuota
|
||||
qrn = []
|
||||
|
||||
# ciclo tutti i valori dati per popolare la lista
|
||||
# data la stringa multilinea iniziale
|
||||
for line in data.qr.splitlines():
|
||||
qrn.append(line)
|
||||
|
||||
# conto il numero degli elementi della lista
|
||||
elementi = int(len(qrn))
|
||||
|
||||
# creo una nuova lista di zeri lunga come qrn
|
||||
qrn_new = [0] * elementi
|
||||
|
||||
# per ogni valore della lisat calcolo il risultato e lo salvo
|
||||
# nella nuva lista
|
||||
for x in range(len(qrn)):
|
||||
qrn_new[x] = (((int(qrn[x]) ** data.c)) * data.b) + data.a
|
||||
|
||||
# definisco una nuova variabile vuota
|
||||
value = 0
|
||||
|
||||
# valore massimo sopra il quale possiamo scartare i risultati
|
||||
max_pec = 15000000000000
|
||||
|
||||
# ciclo per ogni valore, se magire del max, esce
|
||||
# se maggiore dell'attuale valore parziale salvato, sovrascrive
|
||||
for i in qrn_new:
|
||||
if int(i) < max_pec:
|
||||
if int(i) > value:
|
||||
value = int(i)
|
||||
|
||||
# una volta ottenuto il massimo valore consentito sotto la soglia indicata
|
||||
# ritorno al valore di partenza
|
||||
value_orig = round(((value - data.a) / data.b) ** (1/data.c))
|
||||
|
||||
print("Result : ", value_orig)
|
||||
38
03_supplies_in_surplus/README.md
Normal file
38
03_supplies_in_surplus/README.md
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
Codyssi - Supplies in Surplus!
|
||||
|
||||
Part 1
|
||||
Difficulty Rating: 1
|
||||
|
||||
After a refreshing night of sleep, you’ve arrived at the seaside!
|
||||
|
||||
There: a wooden Greek warship, complete with masts and sails. That must be the vessel you’ll use for your journey. Oddly, there seem to be very few technological devices on the ship…
|
||||
|
||||
“Ah, you must be the team from the lab! I’m the captain of the vessel ODC-US. My crew will be at your service for your journey to Atlantis. We’ll be setting sail soon, but we’ve received a surplus of supplies from the lab—there’s no way we could load all this onto the ship.”
|
||||
|
||||
Sure enough, there are clearly too many piles of boxes to load onto the ship. You’ll probably only have enough space for essentials, especially since the captain’s crew is also on the ship.
|
||||
|
||||
One of the crewmates hands you an inventory list, and he explains the situation to you.
|
||||
|
||||
|
||||
Each box has one number label. Boxes with the same number label contain the same items.
|
||||
|
||||
Each line in the list contains two ranges of numbers.
|
||||
|
||||
Each range of numbers represents the numbers on the boxes in each pile. For example, 3-5 represents a pile with 3 boxes, labelled 3, 4, and 5 respectively.
|
||||
|
||||
|
||||
First, you’ll have to figure out the total number of boxes in all of the piles combined.
|
||||
|
||||
For example, consider the (smaller) inventory list below:
|
||||
|
||||
8-9 9-10
|
||||
7-8 8-10
|
||||
9-10 5-10
|
||||
3-10 9-10
|
||||
4-8 7-9
|
||||
9-10 2-7
|
||||
|
||||
|
||||
The first range, 8-9, contains 2 boxes. The second range, 9-10, contains 2 boxes. The third range, 7-8, contains 2 boxes. The fourth range, 8-10, contains 3 boxes. By continuing this process, we can determine that the total number of boxes (for this file) is 43.
|
||||
|
||||
Considering your file, what is the total number of boxes in all of the piles?
|
||||
BIN
03_supplies_in_surplus/__pycache__/data.cpython-313.pyc
Normal file
BIN
03_supplies_in_surplus/__pycache__/data.cpython-313.pyc
Normal file
Binary file not shown.
100
03_supplies_in_surplus/data.py
Normal file
100
03_supplies_in_surplus/data.py
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
l="""483-998 676-938
|
||||
533-877 124-715
|
||||
650-826 759-866
|
||||
89-269 986-995
|
||||
143-544 547-569
|
||||
903-944 865-956
|
||||
36-609 586-780
|
||||
821-972 871-951
|
||||
14-178 125-234
|
||||
571-822 578-823
|
||||
428-615 518-888
|
||||
513-556 253-596
|
||||
915-973 923-956
|
||||
752-917 911-937
|
||||
513-729 558-626
|
||||
773-892 377-857
|
||||
174-564 985-1000
|
||||
917-983 937-997
|
||||
456-895 720-993
|
||||
562-565 565-980
|
||||
709-833 34-529
|
||||
495-982 869-977
|
||||
246-943 761-970
|
||||
20-73 783-975
|
||||
273-738 423-847
|
||||
26-320 320-448
|
||||
450-621 473-573
|
||||
8-676 242-616
|
||||
607-890 322-940
|
||||
295-300 296-975
|
||||
388-970 74-612
|
||||
230-346 237-820
|
||||
897-1000 617-755
|
||||
26-988 368-417
|
||||
996-997 827-849
|
||||
823-912 851-873
|
||||
10-669 597-689
|
||||
496-892 187-258
|
||||
420-659 491-532
|
||||
178-992 223-820
|
||||
455-818 295-404
|
||||
620-794 734-788
|
||||
959-983 968-985
|
||||
364-462 26-702
|
||||
771-787 772-952
|
||||
687-709 702-706
|
||||
521-788 213-450
|
||||
145-557 18-783
|
||||
300-905 328-381
|
||||
911-947 231-501
|
||||
142-652 189-986
|
||||
166-934 734-782
|
||||
54-781 455-990
|
||||
481-508 695-719
|
||||
215-313 221-303
|
||||
611-821 613-643
|
||||
155-725 332-763
|
||||
682-926 668-836
|
||||
480-764 16-408
|
||||
737-853 566-594
|
||||
345-633 662-699
|
||||
160-265 245-822
|
||||
5-325 65-330
|
||||
434-538 520-645
|
||||
830-974 958-969
|
||||
363-374 512-857
|
||||
190-443 336-718
|
||||
833-893 875-961
|
||||
840-990 527-882
|
||||
936-943 943-956
|
||||
903-957 945-996
|
||||
96-823 452-664
|
||||
794-963 823-916
|
||||
956-992 752-862
|
||||
113-438 600-731
|
||||
988-989 859-925
|
||||
409-933 519-894
|
||||
273-963 821-953
|
||||
517-896 596-759
|
||||
116-529 637-708
|
||||
434-976 593-788
|
||||
36-481 68-361
|
||||
47-536 503-577
|
||||
292-696 159-287
|
||||
228-734 733-856
|
||||
228-674 349-402
|
||||
379-570 34-475
|
||||
142-657 591-796
|
||||
349-393 229-760
|
||||
180-314 261-280
|
||||
192-280 215-590
|
||||
974-984 976-977
|
||||
349-924 447-775
|
||||
658-818 363-649
|
||||
668-910 780-839
|
||||
93-234 133-798
|
||||
109-413 984-992
|
||||
268-450 781-808
|
||||
942-956 946-999
|
||||
672-757 753-906"""
|
||||
15
03_supplies_in_surplus/part1.py
Normal file
15
03_supplies_in_surplus/part1.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import data
|
||||
|
||||
# splitto la lista data per togliere gli spazi e gli "a capo"
|
||||
split = data.l.split()
|
||||
|
||||
# aggiungo una variabile per sommare i range
|
||||
somma = 0
|
||||
|
||||
for i in split:
|
||||
# splitto nuovamente per non avere il carattere - e separare i due numeri
|
||||
splot = i.split("-")
|
||||
diff = (int(splot[1]) - int(splot[0]))
|
||||
somma += (int(splot[1]) - int(splot[0]) + 1)
|
||||
|
||||
print ("Result :", somma)
|
||||
Loading…
Add table
Reference in a new issue