Compare commits
6 Commits
b7642ffd36
...
3c7bf475bb
Author | SHA1 | Date | |
---|---|---|---|
3c7bf475bb | |||
7fa280187b | |||
0efa8136a2 | |||
66203a72cf | |||
4076dbc44e | |||
7af6522140 |
11
00/0.py
Normal file
11
00/0.py
Normal file
@ -0,0 +1,11 @@
|
||||
from utils.Url import Url
|
||||
|
||||
|
||||
def main():
|
||||
solution = 2 ** 38
|
||||
builder = Url()
|
||||
builder.solution = solution
|
||||
print(builder.url)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -1,6 +1,5 @@
|
||||
import string
|
||||
|
||||
URL = 'http://www.pythonchallenge.com/pc/def/map.html'
|
||||
from utils.Url import Url
|
||||
|
||||
SECRET = ("g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq "
|
||||
"ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw "
|
||||
@ -27,13 +26,11 @@ def shift_chars(riddle_string, shift_by_int):
|
||||
|
||||
def main():
|
||||
shifted_secret = shift_chars(SECRET, 2)
|
||||
print('Shifted secret:', shifted_secret)
|
||||
shifted_url = shift_chars(URL, 2)
|
||||
print('Shifted url:', shifted_url)
|
||||
new_url = URL.replace('map', shifted_url.split('/')[-1][:3])
|
||||
print('New url:', new_url)
|
||||
|
||||
|
||||
print(shifted_secret)
|
||||
shifted_url = shift_chars('map', 2)
|
||||
builder = Url()
|
||||
builder.solution = shifted_url
|
||||
print(builder.url)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
29
02/counter.py
Normal file
29
02/counter.py
Normal file
@ -0,0 +1,29 @@
|
||||
from collections import Counter
|
||||
|
||||
from utils.Url import Url
|
||||
|
||||
|
||||
def count_string():
|
||||
with open('string.txt') as file:
|
||||
string = file.read()
|
||||
return Counter(string)
|
||||
|
||||
|
||||
def get_lowest(counted_dict):
|
||||
lowest_string = ''
|
||||
for key in counted_dict:
|
||||
if counted_dict[key] == 1:
|
||||
lowest_string += key
|
||||
return lowest_string
|
||||
|
||||
|
||||
def main():
|
||||
counted = count_string()
|
||||
lowest_string = get_lowest(counted)
|
||||
builder = Url()
|
||||
builder.solution = lowest_string
|
||||
print(builder.url)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
1220
02/string.txt
Normal file
1220
02/string.txt
Normal file
File diff suppressed because it is too large
Load Diff
23
03/find_pattern.py
Normal file
23
03/find_pattern.py
Normal file
@ -0,0 +1,23 @@
|
||||
from utils.Url import Url
|
||||
from utils.read import read_string
|
||||
import re
|
||||
|
||||
|
||||
def find_pattern(pattern_string):
|
||||
string = read_string('string.txt')
|
||||
regex = re.compile(pattern_string)
|
||||
matches = regex.findall(string)
|
||||
return ''.join(matches)
|
||||
|
||||
|
||||
def main():
|
||||
pattern_string = r'[a-z][A-Z]{3}(?P<solution>[a-z]){01}[A-Z]{3}[a-z]'
|
||||
string = find_pattern(pattern_string)
|
||||
builder = Url()
|
||||
builder.slug = 'php'
|
||||
builder.solution = string
|
||||
print(builder.url)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
1250
03/string.txt
Normal file
1250
03/string.txt
Normal file
File diff suppressed because it is too large
Load Diff
53
utils/Url.py
Normal file
53
utils/Url.py
Normal file
@ -0,0 +1,53 @@
|
||||
class Url:
|
||||
"""
|
||||
Class to build the python challenge url with the solution string and an
|
||||
optional slug.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self._url = ''
|
||||
self._slug = 'html'
|
||||
self._solution = ''
|
||||
|
||||
BASE_URL = 'http://www.pythonchallenge.com/pc/def'
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
"""
|
||||
Gets the url string of the builder.
|
||||
:return: url string
|
||||
"""
|
||||
return f'{self.BASE_URL}/{self.solution}.{self.slug}'
|
||||
|
||||
@property
|
||||
def solution(self):
|
||||
"""
|
||||
Returns the solution string
|
||||
:return: solution string
|
||||
"""
|
||||
return self._solution
|
||||
|
||||
@solution.setter
|
||||
def solution(self, solution):
|
||||
"""
|
||||
Sets the solution string
|
||||
:param solution: str
|
||||
"""
|
||||
self._solution = solution
|
||||
|
||||
@property
|
||||
def slug(self):
|
||||
"""
|
||||
Returns the slug string
|
||||
:return: slug string
|
||||
"""
|
||||
return self._slug
|
||||
|
||||
@slug.setter
|
||||
def slug(self, slug):
|
||||
"""
|
||||
Sets the slug string
|
||||
:param slug: str
|
||||
:return: slug string
|
||||
"""
|
||||
self._slug = slug
|
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
14
utils/read.py
Normal file
14
utils/read.py
Normal file
@ -0,0 +1,14 @@
|
||||
"""
|
||||
Sone utility functions that can be reused for the python challenge.
|
||||
"""
|
||||
|
||||
|
||||
def read_string(path):
|
||||
"""
|
||||
Read a string from a file provided by a path string.
|
||||
:param path: A path string
|
||||
:return: file content as a string
|
||||
"""
|
||||
with open(path) as file:
|
||||
string = file.read()
|
||||
return string
|
Loading…
x
Reference in New Issue
Block a user