mirror of
https://github.com/Oxbian/CodingGame.git
synced 2025-06-14 09:28:01 +02:00
Adding the end of the mediums challenges
This commit is contained in:
parent
48a85f6cdf
commit
0435bce734
81
Python/Medium_Challenges/mayan_calculations.py
Normal file
81
Python/Medium_Challenges/mayan_calculations.py
Normal file
@ -0,0 +1,81 @@
|
||||
import sys
|
||||
|
||||
#Function to split a string into a list of n char strings
|
||||
def split(string, size):
|
||||
i=0
|
||||
liste=[]
|
||||
while(i<len(string)):
|
||||
liste.append(string[i:i+size])
|
||||
i+=size
|
||||
return(liste)
|
||||
|
||||
patterns = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [],
|
||||
12: [], 13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: []}
|
||||
|
||||
num_1line, num_2line = [], []
|
||||
separator = "\n"
|
||||
|
||||
l, h = [int(i) for i in input().split()]
|
||||
splitted = []
|
||||
for i in range(h):
|
||||
numeral = input()
|
||||
splitted.append(split(numeral, l))
|
||||
print(f"splitted {splitted}", file=sys.stderr, flush = True)
|
||||
|
||||
# Adding numbers patterns
|
||||
for i in range(h):
|
||||
for j in range (20):
|
||||
patterns[j].append(splitted[i][j])
|
||||
print(patterns, file= sys.stderr, flush=True)
|
||||
|
||||
# Getting all the line of the first number
|
||||
s1 = int(input())
|
||||
for i in range(s1):
|
||||
num_1line.append(input())
|
||||
|
||||
# Getting all the line of the second number
|
||||
s2 = int(input())
|
||||
for i in range(s2):
|
||||
num_2line.append(input())
|
||||
|
||||
operation = input()
|
||||
|
||||
n1, n2 = 0, 0
|
||||
|
||||
while (len(num_1line) != 0 or len(num_2line) != 0):
|
||||
for i in range (20):
|
||||
if separator.join(num_1line[:h]) == separator.join(patterns[i]):
|
||||
n1 += i * 20**(len(num_1line) // h -1)
|
||||
num_1line = num_1line[h:]
|
||||
|
||||
if separator.join(num_2line[:h]) == separator.join(patterns[i]):
|
||||
n2 += i * 20**(len(num_2line) // h -1)
|
||||
num_2line = num_2line[h:]
|
||||
|
||||
print(f"{n1} {operation} {n2}", file=sys.stderr, flush=True)
|
||||
|
||||
result = 0
|
||||
if operation == "+":
|
||||
result = n1 + n2
|
||||
elif operation == "-":
|
||||
result = n1 - n2
|
||||
elif operation == "*":
|
||||
result = n1 * n2
|
||||
elif operation == "/":
|
||||
result = n1 / n2
|
||||
|
||||
#Identify the maximum power we need
|
||||
power = 0
|
||||
while (20**power < result):
|
||||
power+= 1
|
||||
|
||||
# Loop printing the numbers we need
|
||||
for i in range(1,power):
|
||||
quotient = result // (20**(power-i))
|
||||
print(f"Debug: resultat {result}, puissance {20**(power-1)}, quotient {quotient}", file=sys.stderr, flush = True)
|
||||
print(separator.join(patterns[quotient]))
|
||||
result -= 20**(power-i) * quotient
|
||||
print(f"Debug: reste {result}", file=sys.stderr, flush=True)
|
||||
|
||||
# Printing the rest under 20^1
|
||||
print(separator.join(patterns[result]))
|
34
Python/Medium_Challenges/scrabble.py
Normal file
34
Python/Medium_Challenges/scrabble.py
Normal file
@ -0,0 +1,34 @@
|
||||
from collections import defaultdict
|
||||
|
||||
dict = {'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f': 4, 'g': 2, 'h': 4, 'i': 1, 'j': 8, 'k': 5, 'l': 1, 'm': 3, 'n': 1,
|
||||
'o': 1, 'p': 3, 'q': 10, 'r': 1, 's': 1, 't': 1, 'u': 1, 'v': 4, 'w': 4, 'x': 8, 'y': 4, 'z': 10}
|
||||
|
||||
n = int(input())
|
||||
words = [input() for _ in range(n)]
|
||||
letters = input()
|
||||
|
||||
#Function to check if a word is in the scrabble letters
|
||||
def solve(s, t):
|
||||
freq = {'a':0, 'b':0, 'c':0, 'd':0, 'e':0, 'f':0, 'g':0, 'h':0, 'i':0, 'j':0, 'k':0, 'l':0, 'm':0, 'n':0, 'o':0,
|
||||
'p':0, 'q':0, 'r':0, 's':0, 't':0, 'u':0, 'v':0, 'w':0, 'x':0, 'y':0, 'z':0}
|
||||
for i in range(len(s)):
|
||||
freq[s[i]] += 1
|
||||
|
||||
for i in range(len(t)):
|
||||
if freq[t[i]] == 0:
|
||||
return False
|
||||
freq[t[i]] -= 1
|
||||
return True
|
||||
|
||||
# Compare words with the given letters
|
||||
max = 0
|
||||
word = ""
|
||||
for i in range(n):
|
||||
value = 0
|
||||
if (solve(letters, words[i]) == True):
|
||||
for j in range(len(words[i])):
|
||||
value += dict[words[i][j]]
|
||||
if value > max:
|
||||
max = value
|
||||
word = words[i]
|
||||
print(word)
|
@ -41,6 +41,7 @@ __Be careful, a lot of my solutions aren't optimized because I didn't took time
|
||||
|Telephone Numbers| []() | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/Python/Medium_Challenges/telephone_numbers.py) |
|
||||
|The Fall - Chapter 1| []() | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/Python/Medium_Challenges/the_fall_1.py) |
|
||||
|The gift| []() | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/Python/Medium_Challenges/the_gift.py)|
|
||||
|Dwarfs standing on the shoulders of giants| []() | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/Python/Medium_Challenges/dwarfs_standing_on_the_shoulders_of_giants.py)
|
||||
|
||||
|Dwarfs standing on the shoulders of giants| []() | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/Python/Medium_Challenges/dwarfs_standing_on_the_shoulders_of_giants.py) |
|
||||
|Mayan Calculations| []() | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/Python/Medium_Challenges/mayan_calculations.py) |
|
||||
|Scrabble| []() | [x](https://github.com/ARKAGEDON/CodingGame/blob/main/Python/Medium_Challenges/scrabble.py) |
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user