pythonchallenge.com 1-10
This commit is contained in:
parent
f30789450e
commit
4423e9dfce
21 changed files with 1505 additions and 24 deletions
23
python/chess pgn reader/example.pgn
Normal file
23
python/chess pgn reader/example.pgn
Normal file
|
@ -0,0 +1,23 @@
|
|||
[Event "Live Chess"]
|
||||
[Site "Chess.com"]
|
||||
[Date "2021.06.04"]
|
||||
[Round "?"]
|
||||
[White "totallynotntb"]
|
||||
[Black "Enzinhu"]
|
||||
[Result "1-0"]
|
||||
[ECO "A46"]
|
||||
[WhiteElo "953"]
|
||||
[BlackElo "931"]
|
||||
[TimeControl "600"]
|
||||
[EndTime "15:07:16 PDT"]
|
||||
[Termination "totallynotntb won by resignation"]
|
||||
|
||||
1. d4 d6 2. Nf3 Nf6 3. g3 Nbd7 4. Bg2 e5 5. dxe5 Nxe5 6. Nxe5 dxe5 7. Qxd8+ Kxd8
|
||||
8. Bg5 Be7 9. c4 h6 10. Bxf6 Bxf6 11. Nc3 c6 12. O-O Be6 13. b3 Kc7 14. Rad1
|
||||
Rad8 15. e4 Rxd1 16. Rxd1 Rd8 17. Ra1 g5 18. h3 g4 19. hxg4 Bxg4 20. f3 Be6 21.
|
||||
Ne2 Rd2 22. Kf1 b5 23. Ke1 Rd7 24. cxb5 cxb5 25. Nc3 a6 26. f4 exf4 27. gxf4 Rd3
|
||||
28. Ne2 Bh4+ 29. Kf1 f5 30. e5 Bd5 31. Bxd5 Rxd5 32. Ng1 Be7 33. Nh3 h5 34. Rc1+
|
||||
Kb6 35. Rc3 Rd2 36. a4 bxa4 37. bxa4 a5 38. Rc4 Bc5 39. Ke1 Rh2 40. Ng5 h4 41.
|
||||
e6 h3 42. Rxc5 Kxc5 43. e7 Rh1+ 44. Kf2 Rh2+ 45. Kf3 Re2 46. Kxe2 h2 47. e8=Q
|
||||
h1=Q 48. Qe5+ Kb4 49. Qd4+ Ka3 50. Qd6+ Kb3 51. Nf3 Kxa4 52. Ne1 Qh5+ 53. Nf3
|
||||
Qh2+ 54. Nxh2 Kb3 1-0
|
82
python/chess pgn reader/pgn reader.py
Normal file
82
python/chess pgn reader/pgn reader.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
import os
|
||||
import re
|
||||
|
||||
pieces = {
|
||||
'w': {
|
||||
'K': '\u2654',
|
||||
'Q': '\u2655',
|
||||
'R': '\u2656',
|
||||
'B': '\u2657',
|
||||
'N': '\u2658',
|
||||
'P': '\u2659'
|
||||
},
|
||||
'b': {
|
||||
'K': '\u265A',
|
||||
'Q': '\u265B',
|
||||
'R': '\u265C',
|
||||
'B': '\u265D',
|
||||
'N': '\u265E',
|
||||
'P': '\u265F'
|
||||
}
|
||||
}
|
||||
|
||||
filename = input('Enter the name of the .pgn file! ')
|
||||
dir = os.path.dirname(os.path.realpath(__file__))
|
||||
file = open('{0}/{1}.pgn'.format(dir, filename))
|
||||
lines = file.readlines() # Read all lines
|
||||
|
||||
indexOfTurnOne = lines.index([s for s in lines if '1. ' in s][0]) # Find the index of move one
|
||||
turns = lines[indexOfTurnOne:len(lines)] # Find the beginning of the turns
|
||||
turns = re.findall(" ".join(["[^ ]+"] * 3), ' '.join(turns)) # Split on every third space
|
||||
turns = list(map(lambda s: s.replace('\n', ''), turns)) # Remove all new lines from turns
|
||||
|
||||
for turn in turns:
|
||||
i = turns.index(turn)
|
||||
turns[i] = {
|
||||
'number': int(turn.split('.')[0]),
|
||||
'moves': {
|
||||
'w': {
|
||||
'move': turn.split('.')[1].strip().split(' ')[0]
|
||||
},
|
||||
'b': {
|
||||
'move': turn.split('.')[1].strip().split(' ')[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for side in turns[i]['moves']:
|
||||
print(turns[i]['moves'][side])
|
||||
if turns[i]['moves'][side]['move'][0].islower():
|
||||
turns[i]['moves'][side]['piece'] = 'P'
|
||||
elif turns[i]['moves'][side]['move'][0] == 'R' or turns[i]['moves'][side]['move'][0].startswith('O'):
|
||||
turns[i]['moves'][side]['piece'] = 'R'
|
||||
else:
|
||||
turns[i]['moves'][side]['piece'] = turns[i]['moves'][side]['move'][0]
|
||||
|
||||
print(turns[i])
|
||||
|
||||
board = [
|
||||
['bR','bN','bB''bQ','bK','bB','bN','bR'],
|
||||
['bP','bP','bP','bP','bP','bP','bP','bP'],
|
||||
['','','','','','','',''],
|
||||
['','','','','','','',''],
|
||||
['','','','','','','',''],
|
||||
['','','','','','','',''],
|
||||
['wP','wP','wP','wP','wP','wP','wP','wP'],
|
||||
['wR','wN','wB''wQ','wK','wB','wN','wR']
|
||||
]
|
||||
|
||||
def render(turn):
|
||||
global board
|
||||
i = turns.index(turn)
|
||||
for colour in turns[i]['moves']:
|
||||
move = turns[i]['moves'][colour]['move']
|
||||
if len(move) == 2:
|
||||
for row in board:
|
||||
for file in row:
|
||||
if file == '{0}{1}'.format(colour, turns[i]['moves'][colour]['piece']):
|
||||
print('a', )
|
||||
|
||||
return board
|
||||
|
||||
print(render(turns[0]))
|
|
@ -33,7 +33,6 @@ calc.set_beatmap('{0}.osu'.format(id)) # Load the newly written difficulty file
|
|||
calc.calculate() # Calculate the stats
|
||||
calc.close() # Close the calculator to save resources
|
||||
|
||||
|
||||
# Round beatmap stats to be readable
|
||||
stars = {
|
||||
'total': round(calc.stars, 2),
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
certifi==2020.12.5
|
||||
chardet==4.0.0
|
||||
idna==2.10
|
||||
oppai==4.1.0
|
||||
oppaipy==1.0.3
|
||||
requests==2.25.1
|
||||
urllib3==1.26.5
|
BIN
python/pygame pong/__pycache__/Ball.cpython-38.pyc
Normal file
BIN
python/pygame pong/__pycache__/Ball.cpython-38.pyc
Normal file
Binary file not shown.
BIN
python/pygame pong/__pycache__/Paddle.cpython-38.pyc
Normal file
BIN
python/pygame pong/__pycache__/Paddle.cpython-38.pyc
Normal file
Binary file not shown.
|
@ -1,13 +0,0 @@
|
|||
altgraph==0.17
|
||||
cachetools==4.2.2
|
||||
cffi==1.14.5
|
||||
Cython==0.29.23
|
||||
future==0.18.2
|
||||
numpy==1.19.5
|
||||
pefile==2019.4.18
|
||||
py2exe==0.10.4.0
|
||||
pycparser==2.20
|
||||
pygame==2.0.0
|
||||
pyinstaller==4.3
|
||||
pyinstaller-hooks-contrib==2021.1
|
||||
pywin32-ctypes==0.2.0
|
9
python/pythonchallenge.com/1 - Map.py
Normal file
9
python/pythonchallenge.com/1 - Map.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
translation = str.maketrans('abcdefghijklmnopqrstuvwxyz', 'cdefghijklmnopqrstuvwxyzab')
|
||||
|
||||
task = 'g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr\'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.'
|
||||
taskRes = task.translate(translation)
|
||||
print(taskRes)
|
||||
|
||||
nextTask = 'map'
|
||||
nextTaskRes = nextTask.translate(translation)
|
||||
print(nextTaskRes)
|
15
python/pythonchallenge.com/10 - Bull.py
Normal file
15
python/pythonchallenge.com/10 - Bull.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
a = '1'
|
||||
b = ''
|
||||
|
||||
for i in range(0, 30):
|
||||
j = 0
|
||||
k = 0
|
||||
while j < len(a):
|
||||
while k < len(a) and a[k] == a[j]:
|
||||
k += 1
|
||||
b += str(k - j) + a[j]
|
||||
j = k
|
||||
print(b)
|
||||
a = b
|
||||
b = ''
|
||||
print(len(a))
|
12
python/pythonchallenge.com/2 - OCR.py
Normal file
12
python/pythonchallenge.com/2 - OCR.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
import urllib.request
|
||||
import re
|
||||
|
||||
html = urllib.request.urlopen('http://www.pythonchallenge.com/pc/def/ocr.html').read().decode()
|
||||
comments = re.findall('<!--(.*?)-->', html, re.DOTALL)
|
||||
data = comments[-1]
|
||||
|
||||
count = {}
|
||||
for c in data:
|
||||
count[c] = count.get(c, 0) + 1
|
||||
|
||||
print(count) # equality is rare
|
5
python/pythonchallenge.com/3 - Equality.py
Normal file
5
python/pythonchallenge.com/3 - Equality.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
import re
|
||||
|
||||
data = open('equality.txt'.format(dir)).read()
|
||||
matches = re.findall('[^A-Z]+[A-Z]{3}([a-z])[A-Z]{3}[^A-Z]+', data)
|
||||
print(matches)
|
14
python/pythonchallenge.com/4 - linkedlist.py
Normal file
14
python/pythonchallenge.com/4 - linkedlist.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
import urllib.request
|
||||
import re
|
||||
|
||||
uri = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s'
|
||||
num = str(16044 / 2)
|
||||
pattern = re.compile('and the next nothing is (\d+)')
|
||||
|
||||
while True:
|
||||
content = urllib.request.urlopen(uri % num).read().decode()
|
||||
print(content)
|
||||
match = pattern.search(content)
|
||||
if match == None:
|
||||
break
|
||||
num = match.group(1)
|
8
python/pythonchallenge.com/5 - Peak Hell.py
Normal file
8
python/pythonchallenge.com/5 - Peak Hell.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
import pickle
|
||||
import urllib.request
|
||||
|
||||
raw = urllib.request.urlopen('http://www.pythonchallenge.com/pc/def/banner.p')
|
||||
data = pickle.load(raw)
|
||||
|
||||
for line in data:
|
||||
print(''.join([k * v for k, v in line]))
|
17
python/pythonchallenge.com/6 - Channel.py
Normal file
17
python/pythonchallenge.com/6 - Channel.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
import zipfile
|
||||
import re
|
||||
|
||||
f = zipfile.ZipFile('channel.zip')
|
||||
num = '90052'
|
||||
comments = []
|
||||
|
||||
while True:
|
||||
content = f.read('{0}.txt'.format(num)).decode('utf-8')
|
||||
comments.append(f.getinfo('{0}.txt'.format(num)).comment.decode('utf-8'))
|
||||
print(content)
|
||||
match = re.search('Next nothing is (\d+)', content)
|
||||
if match == None:
|
||||
break
|
||||
num = match.group(1)
|
||||
|
||||
print(''.join(comments))
|
11
python/pythonchallenge.com/7 - Oxygen.py
Normal file
11
python/pythonchallenge.com/7 - Oxygen.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
import re
|
||||
from PIL import Image
|
||||
|
||||
img = Image.open('oxygen.png')
|
||||
row = [img.getpixel((x, img.height / 2)) for x in range(img.width)][::7]
|
||||
ords = [r for r, g, b, a in row if r == g == b]
|
||||
msg = ''.join(map(chr, ords))
|
||||
nums = re.findall('\d+', msg)
|
||||
nextLevel = ''.join(map(chr, map(int, nums)))
|
||||
|
||||
print(nextLevel)
|
7
python/pythonchallenge.com/8 - Integrity.py
Normal file
7
python/pythonchallenge.com/8 - Integrity.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
import bz2
|
||||
|
||||
un = b'BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07<]\xc9\x14\xe1BA\x06\xbe\x084'
|
||||
pw = b'BZh91AY&SY\x94$|\x0e\x00\x00\x00\x81\x00\x03$ \x00!\x9ah3M\x13<]\xc9\x14\xe1BBP\x91\xf08'
|
||||
|
||||
print(bz2.decompress(un))
|
||||
print(bz2.decompress(pw))
|
35
python/pythonchallenge.com/9 - Good.py
Normal file
35
python/pythonchallenge.com/9 - Good.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
from PIL import Image, ImageDraw
|
||||
|
||||
first = [146, 399, 163, 403, 170, 393, 169, 391, 166, 386, 170, 381, 170, 371, 170, 355, 169, 346, 167, 335, 170, 329,
|
||||
170, 320, 170, 310, 171, 301, 173, 290, 178, 289, 182, 287, 188, 286, 190, 286, 192, 291, 194, 296, 195, 305,
|
||||
194, 307, 191, 312, 190, 316, 190, 321, 192, 331, 193, 338, 196, 341, 197, 346, 199, 352, 198, 360, 197, 366,
|
||||
197, 373, 196, 380, 197, 383, 196, 387, 192, 389, 191, 392, 190, 396, 189, 400, 194, 401, 201, 402, 208, 403,
|
||||
213, 402, 216, 401, 219, 397, 219, 393, 216, 390, 215, 385, 215, 379, 213, 373, 213, 365, 212, 360, 210, 353,
|
||||
210, 347, 212, 338, 213, 329, 214, 319, 215, 311, 215, 306, 216, 296, 218, 290, 221, 283, 225, 282, 233, 284,
|
||||
238, 287, 243, 290, 250, 291, 255, 294, 261, 293, 265, 291, 271, 291, 273, 289, 278, 287, 279, 285, 281, 280,
|
||||
284, 278, 284, 276, 287, 277, 289, 283, 291, 286, 294, 291, 296, 295, 299, 300, 301, 304, 304, 320, 305, 327,
|
||||
306, 332, 307, 341, 306, 349, 303, 354, 301, 364, 301, 371, 297, 375, 292, 384, 291, 386, 302, 393, 324, 391,
|
||||
333, 387, 328, 375, 329, 367, 329, 353, 330, 341, 331, 328, 336, 319, 338, 310, 341, 304, 341, 285, 341, 278,
|
||||
343, 269, 344, 262, 346, 259, 346, 251, 349, 259, 349, 264, 349, 273, 349, 280, 349, 288, 349, 295, 349, 298,
|
||||
354, 293, 356, 286, 354, 279, 352, 268, 352, 257, 351, 249, 350, 234, 351, 211, 352, 197, 354, 185, 353, 171,
|
||||
351, 154, 348, 147, 342, 137, 339, 132, 330, 122, 327, 120, 314, 116, 304, 117, 293, 118, 284, 118, 281, 122,
|
||||
275, 128, 265, 129, 257, 131, 244, 133, 239, 134, 228, 136, 221, 137, 214, 138, 209, 135, 201, 132, 192, 130,
|
||||
184, 131, 175, 129, 170, 131, 159, 134, 157, 134, 160, 130, 170, 125, 176, 114, 176, 102, 173, 103, 172, 108,
|
||||
171, 111, 163, 115, 156, 116, 149, 117, 142, 116, 136, 115, 129, 115, 124, 115, 120, 115, 115, 117, 113, 120,
|
||||
109, 122, 102, 122, 100, 121, 95, 121, 89, 115, 87, 110, 82, 109, 84, 118, 89, 123, 93, 129, 100, 130, 108,
|
||||
132, 110, 133, 110, 136, 107, 138, 105, 140, 95, 138, 86, 141, 79, 149, 77, 155, 81, 162, 90, 165, 97, 167, 99,
|
||||
171, 109, 171, 107, 161, 111, 156, 113, 170, 115, 185, 118, 208, 117, 223, 121, 239, 128, 251, 133, 259, 136,
|
||||
266, 139, 276, 143, 290, 148, 310, 151, 332, 155, 348, 156, 353, 153, 366, 149, 379, 147, 394, 146, 399]
|
||||
|
||||
second = [156, 141, 165, 135, 169, 131, 176, 130, 187, 134, 191, 140, 191, 146, 186, 150, 179, 155, 175, 157, 168, 157,
|
||||
163, 157, 159, 157, 158, 164, 159, 175, 159, 181, 157, 191, 154, 197, 153, 205, 153, 210, 152, 212, 147, 215,
|
||||
146, 218, 143, 220, 132, 220, 125, 217, 119, 209, 116, 196, 115, 185, 114, 172, 114, 167, 112, 161, 109, 165,
|
||||
107, 170, 99, 171, 97, 167, 89, 164, 81, 162, 77, 155, 81, 148, 87, 140, 96, 138, 105, 141, 110, 136, 111,
|
||||
126, 113, 129, 118, 117, 128, 114, 137, 115, 146, 114, 155, 115, 158, 121, 157, 128, 156, 134, 157, 136, 156,
|
||||
136]
|
||||
|
||||
im = Image.new('RGB', (500,500))
|
||||
draw = ImageDraw.Draw(im)
|
||||
draw.polygon(first, fill='white')
|
||||
draw.polygon(second, fill='black')
|
||||
im.show()
|
BIN
python/pythonchallenge.com/channel.zip
Normal file
BIN
python/pythonchallenge.com/channel.zip
Normal file
Binary file not shown.
1250
python/pythonchallenge.com/equality.txt
Normal file
1250
python/pythonchallenge.com/equality.txt
Normal file
File diff suppressed because it is too large
Load diff
BIN
python/pythonchallenge.com/oxygen.png
Normal file
BIN
python/pythonchallenge.com/oxygen.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 124 KiB |
20
readme.md
20
readme.md
|
@ -1,5 +1,6 @@
|
|||
<!--suppress HtmlDeprecatedAttribute -->
|
||||
<div align="center">
|
||||
<img height="256" src="https://raw.githubusercontent.com/newtykins/the-honk/main/readme.png">
|
||||
<img height="256" src="https://raw.githubusercontent.com/newtykins/the-honk/main/readme.png" alt="">
|
||||
<h1>the honk</h1>
|
||||
</div>
|
||||
|
||||
|
@ -9,8 +10,21 @@
|
|||
|
||||
### GCSE Computer Science
|
||||
|
||||
Here you can find a bunch of random work from my GCSE Computer Science class dumped. I can't be bothered to index it all and a lot of it is boring useless stuff, so only look here if you are incredibly bored or want to see my Python progression.
|
||||
Here you can find a bunch of random work from my GCSE Computer Science class dumped. I can't be bothered to index it all, and a lot of it is boring useless stuff, so only look here if you are incredibly bored or want to see my Python progression.
|
||||
|
||||
### Python
|
||||
|
||||
- [Get PP from a beatmap ID](python/pp%20from%20beatmap%20id)
|
||||
- [Get PP from a beatmap ID](python/pp%20from%20beatmap%20id)
|
||||
- [Pygame Pong](python/pygame%20pong)
|
||||
- [Chess PGN Reader](python/chess%20pgn%20reader)
|
||||
- [pythonchallenge.com](python/pythonchallenge.com)
|
||||
- [1 - Map](python/pythonchallenge.com/1%20-%20Map.py)
|
||||
- [2 - OCR](python/pythonchallenge.com/2%20-%20OCR.py)
|
||||
- [3 - Equality](python/pythonchallenge.com/3%20-%20Equality.py)
|
||||
- [4 - linkedlist](python/pythonchallenge.com/4%20-%20linkedlist.py)
|
||||
- [5 - Peak Hell](python/pythonchallenge.com/5%20-%20Peak%20Hell.py)
|
||||
- [6 - Channel](python/pythonchallenge.com/6%20-%20Channel.py)
|
||||
- [7 - Oxygen](python/pythonchallenge.com/7%20-%20Oxygen.py)
|
||||
- [8 - Integrity](python/pythonchallenge.com/8%20-%20Integrity.py)
|
||||
- [9 - Good](python/pythonchallenge.com/9%20-%20Good.py)
|
||||
- [10 - Bull](python/pythonchallenge.com/10%20-%20Bull.py)
|
Loading…
Reference in a new issue