Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My code for YETI #4

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Day_1/day1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import hashlib
import itertools


class CodeBreaker:
def __init__(self):
self.alphanumeric = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
self.target_hash = '4002f685108db38f1af9965f3bc869eb'

def break_code(self):
for p in itertools.product(self.alphanumeric, repeat=4):
x=''.join(str(i) for i in p)
hash = hashlib.md5(x.encode('utf-8')).hexdigest()
#print(x, hash)
if(hash==self.target_hash):
return x


def main():
codeBreaker = CodeBreaker()
print(codeBreaker.break_code())

if __name__=='__main__':
main()
13 changes: 13 additions & 0 deletions Day_2/Day2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

def main():
df = pd.read_csv('./FourVectorTest.csv', header=None, names = ['Px', 'Py', 'Pz', 'E'])
df['phi'] = df.apply(lambda row : np.arctan2(row.Py,row.Px), axis=1)
df['eta'] = df.apply(lambda row : np.arctanh(row.Pz/np.sqrt(row.Px*row.Px + row.Py*row.Py + row.Pz*row.Pz)), axis=1)
plt.hist2d(df['phi'], df['eta'], (1000, 1000))
plt.show()

if __name__=='__main__':
main()
Binary file added Day_2/Figure_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100,000 changes: 100,000 additions & 0 deletions Day_2/FourVectorTest.csv

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions Day_3/Day3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
class MyNumber:
def __init__(self):
self.primes_cache = [] #Is sorted and contains first prime numbers

def is_prime(self, x):
for p in self.primes_cache:
if x % p == 0:
return False
return True

def precalculate_next_n_primes(self, n):
original_length = len(self.primes_cache)
if not n:
return
if not self.primes_cache:
self.primes_cache = [2]
if n == 1:
return
test_number = self.primes_cache[-1] + 1
while True:
if self.is_prime(test_number):
self.primes_cache.append(test_number)
if(len(self.primes_cache) - original_length) >= n:
return
test_number += 1

def get_number(self):
n, nine_primes_ptr = 0, 0

#The three primes cannot be less than or all be among the nine primes for the equality to hold
#Atleast one of the three primes has to be greater than the nine_primes. So we start by making our
#pointer for three primes point at the second last of the nine primes
three_primes_ptr = nine_primes_ptr + 9 - 2
self.precalculate_next_n_primes(10)
while True:
if nine_primes_ptr + 9 > len(self.primes_cache) or three_primes_ptr+3 > len(self.primes_cache):
self.precalculate_next_n_primes(10)

sum_nine = sum(self.primes_cache[nine_primes_ptr: nine_primes_ptr+9])
sum_three = sum(self.primes_cache[three_primes_ptr: three_primes_ptr+3])

if sum_nine > sum_three:
three_primes_ptr += 1
elif sum_three > sum_nine:
nine_primes_ptr += 1
elif sum_nine == sum_three:
n += 1
nine_primes_ptr += 1
if n == 5 :
return sum_nine


def main():
my_number = MyNumber()
print(my_number.get_number())

if __name__ == '__main__':
main()
39 changes: 39 additions & 0 deletions Day_4/Day_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class VigenereEncrypter:
def __init__(self, key, plain_text):
self.plain_text = plain_text
k = []
k.append(key)
if(len(plain_text) != len(key)):
for i in range(len(plain_text) - len(key)):
k.append(key[i%len(key)])
self.key = ''.join(k)

self.d = {}
count=0
for c in 'abcdefghijklmnopqrstuvwxyz0123456789':
self.d[c] = count;
count += 1

self.inv_d = {v: k for k, v in self.d.items()}

def encrypt(self):
cipher_text = []
for i in range(len(self.plain_text)):
x = (self.d[self.plain_text[i]] + self.d[self.key[i]])%36
x += self.d['a']
cipher_text.append(self.inv_d[x])
return ''.join(cipher_text)

def main():
#The building address is 803 S Gay Street and the name is Bijou Theatre
key = 'bijou'
with open('secretCode.txt', 'r') as f:
data = f.read()

encrypter = VigenereEncrypter(key, data)
cipher_text = encrypter.encrypt()
with open('encodedText.txt', 'w') as f1:
f1.write(cipher_text)

if __name__=='__main__':
main()
1 change: 1 addition & 0 deletions Day_4/encodedText.txt

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions Day_5/Day5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import struct
from PIL import Image

def fibonacci(n):
a,b = 0,1

if n == 1:
return a
elif n == 2:
return b

for i in range(n-2):
tmp = a+b
a = b
b = tmp
return b

def calculate_width():
evens,odds = 0,0
even_9th = -1
odd_6th = -1

i = 1
while True:
x = fibonacci(i)
if x%2 == 0:
evens += 1
if evens == 9:
even_9th = x
else:
odds += 1
if odds == 6:
odd_6th = x
if even_9th > - 1 and odd_6th > -1 : #This means both are set now
break
i += 1
return int(even_9th/odd_6th)

def main():
n = calculate_width() #width of image
image_data = []
count = 0
with open('../Day_4/encodedText.txt', 'r') as f:
while True:
block = ''
end = False
for i in range(6):
c = f.read(1)
count += 1
if not c:
count -= 1
end = True
break
block += c
if len(block) < 6:
count -= len(block)
break
if end:
break
image_data.append(struct.unpack('BBB', bytes.fromhex(block)))

length = int(count/n)
im = Image.new('RGB', (n, length))
im.putdata(image_data)
im.show()

if __name__=='__main__':
main()