Add: 10->12, 17
This commit is contained in:
46
2015/10.py
Normal file
46
2015/10.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
input = "1"
|
||||||
|
|
||||||
|
def look_and_say(input):
|
||||||
|
s = ""
|
||||||
|
last = 'x'
|
||||||
|
count = 1
|
||||||
|
|
||||||
|
for n in input:
|
||||||
|
if last == 'x':
|
||||||
|
last = n
|
||||||
|
count = 1
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if last == n:
|
||||||
|
count += 1
|
||||||
|
continue;
|
||||||
|
|
||||||
|
s+=f"{count}{last}"
|
||||||
|
|
||||||
|
last=n
|
||||||
|
count=1
|
||||||
|
|
||||||
|
return s+f"{count}{n}"
|
||||||
|
|
||||||
|
|
||||||
|
""" Not worth it
|
||||||
|
def recursive_look_and_say(input):
|
||||||
|
j = len(input)//2
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if j == len(input)-1:
|
||||||
|
return look_and_say(input)
|
||||||
|
|
||||||
|
# Assert 'j' does not divide repeating characters
|
||||||
|
if input[j] != input[j+1]:
|
||||||
|
return recursive_look_and_say(input[:j+1])+ recursive_look_and_say(input[j+1:])
|
||||||
|
|
||||||
|
j+=1
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
# Result
|
||||||
|
|
||||||
|
for i in range(50):
|
||||||
|
input = look_and_say(input)
|
||||||
|
print(len(input))
|
||||||
47
2015/11.py
Normal file
47
2015/11.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
input = "cqjxjnds"
|
||||||
|
|
||||||
|
def match(pattern, string):
|
||||||
|
return re.search(pattern, string) != None
|
||||||
|
|
||||||
|
def rule1(input):
|
||||||
|
matched = 0
|
||||||
|
last = '-'
|
||||||
|
|
||||||
|
for c in input:
|
||||||
|
if ord(c) == ord(last) + 1:
|
||||||
|
matched += 1
|
||||||
|
if matched == 3:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
matched = 1
|
||||||
|
|
||||||
|
last = c
|
||||||
|
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def increment(input):
|
||||||
|
res = ""
|
||||||
|
carry = 1
|
||||||
|
|
||||||
|
for c in reversed(input):
|
||||||
|
if carry != 0:
|
||||||
|
if c=='z':
|
||||||
|
c = chr(ord('a'))
|
||||||
|
carry = carry
|
||||||
|
else:
|
||||||
|
c = chr(ord(c)+carry)
|
||||||
|
carry = 0
|
||||||
|
res = c + res
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(10):
|
||||||
|
while not (rule1(input) and match(r"(.)\1.*(.)\2", input) and not match(r"i|o|l", input)):
|
||||||
|
input = increment(input)
|
||||||
|
print(input)
|
||||||
|
input = increment(input)
|
||||||
37
2015/12.py
Normal file
37
2015/12.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
# Fill Input
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open("12.txt", 'r', encoding='utf-8') as file:
|
||||||
|
input = json.load(file)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
|
||||||
|
# Convert Corrdenate to string
|
||||||
|
|
||||||
|
def recursive_decend(json:any)->int:
|
||||||
|
match json:
|
||||||
|
case dict():
|
||||||
|
sum = 0;
|
||||||
|
for i in json:
|
||||||
|
""" Part 2
|
||||||
|
if json[i] == "red":
|
||||||
|
return 0
|
||||||
|
"""
|
||||||
|
|
||||||
|
sum += recursive_decend(json[i])
|
||||||
|
return sum
|
||||||
|
case list():
|
||||||
|
sum = 0;
|
||||||
|
for i in json:
|
||||||
|
sum += recursive_decend(i)
|
||||||
|
return sum
|
||||||
|
case int():
|
||||||
|
return json
|
||||||
|
case str():
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
print(recursive_decend(input))
|
||||||
|
|
||||||
|
|
||||||
43
2015/17.py
Normal file
43
2015/17.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# Fill Input
|
||||||
|
|
||||||
|
input = ""
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open("17.txt", 'r', encoding='utf-8') as file:
|
||||||
|
input += file.read()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
|
||||||
|
# Check if sum of permutation equal 150
|
||||||
|
def sum_equal_150(input, i):
|
||||||
|
sum = 0
|
||||||
|
for j in range(l):
|
||||||
|
if i & 1<<j:
|
||||||
|
sum += input[j]
|
||||||
|
if sum > 150:
|
||||||
|
return False
|
||||||
|
return sum == 150
|
||||||
|
|
||||||
|
# Reverse sort input
|
||||||
|
input= [ int(x) for x in input.split()]
|
||||||
|
input.sort(reverse=True)
|
||||||
|
|
||||||
|
l = len(input)
|
||||||
|
res1, res2, min_popcount = 0, 0, l
|
||||||
|
|
||||||
|
for i in range(2**l):
|
||||||
|
if not sum_equal_150(input, i):
|
||||||
|
continue
|
||||||
|
|
||||||
|
popcount = i.bit_count()
|
||||||
|
|
||||||
|
if popcount < min_popcount:
|
||||||
|
min_popcount = popcount
|
||||||
|
res2 = 0;
|
||||||
|
|
||||||
|
if popcount == min_popcount:
|
||||||
|
res2 += 1;
|
||||||
|
|
||||||
|
res1 += 1
|
||||||
|
|
||||||
|
print(res1, res2)
|
||||||
Reference in New Issue
Block a user