Skip to content

Commit f48ede2

Browse files
committed
automatic updates to README.md with status
1 parent 39eb7d9 commit f48ede2

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

estomagordo-python3/golf.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
from os import fsencode, fsdecode, listdir, system, name
22
from io import StringIO
33
from contextlib import redirect_stdout
4-
# import sys
54

65
path = 'estomagordo-python3\\'
76
golf = 'golf\\'
7+
readme = 'README.md'
8+
9+
rm = []
10+
with open(path + golf + readme, 'r') as f:
11+
for line in f.readlines():
12+
rm.append(line)
813

914
system('cls' if name == 'nt' else 'clear')
1015
print("Welcome to the golfing experience part of estomagordo's 2017 Advent of Code submissions!\nThe following golfing solutions have been found.")
@@ -47,5 +52,32 @@
4752
eqstr = 'EQUALS' if golfsult == regusult else 'DOES NOT EQUAL'
4853
percentage = round(100.0 * float(golflen) / float(regulen), 2)
4954

50-
print('\n{}\nGolfed result {} the regular result. The solution was shortened from {} to {} chars, or {}% of the original.'.format(
51-
name, eqstr, str(regulen), str(golflen), percentage))
55+
output = '\n{}\nGolfed result {} the regular result. The solution was shortened from {} to {} chars, or {}% of the original.'.format(
56+
name, eqstr, str(regulen), str(golflen), percentage)
57+
58+
namenl = name + '\n'
59+
60+
exists = namenl in rm
61+
62+
if exists:
63+
i = rm.index(namenl) + 1
64+
prevresult = rm[i]
65+
topos = prevresult.find(' to ')
66+
charspos = prevresult.find(' chars,')
67+
68+
resultstr = prevresult[topos + 4: charspos]
69+
oldlen = int(resultstr)
70+
71+
if golflen < oldlen:
72+
rm[i] = output
73+
else:
74+
rm.append(output + '\n')
75+
76+
print(output)
77+
78+
if rm[-1][-1] == '\n':
79+
rm[-1] = rm[-1][:-1]
80+
81+
with open(path + golf + readme, 'w') as f:
82+
for line in rm:
83+
f.write(line)

estomagordo-python3/golf/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,24 @@ The intent is to keep the code as short as possible, "golfed", see [Code Golf](h
44

55
The one being that, at least for the time being, all solutions will read text files, the same text files that the ordinary solutions use.
66

7-
That is, a golfed solution to challenge 10a would use the text file `input_10.txt`, rather than a one character long file name, or something altogether different. This may change in an upcoming version, if there is enough time.
7+
That is, a golfed solution to challenge 10a would use the text file `input_10.txt`, rather than a one character long file name, or something altogether different. This may change in an upcoming version, if there is enough time.
8+
9+
Results so far:
10+
11+
1a.py
12+
Golfed result EQUALS the regular result. The solution was shortened from 253 to 96 chars, or 37.94% of the original.
13+
14+
1b.py
15+
Golfed result EQUALS the regular result. The solution was shortened from 256 to 103 chars, or 40.23% of the original.
16+
17+
4a.py
18+
Golfed result EQUALS the regular result. The solution was shortened from 207 to 78 chars, or 37.68% of the original.
19+
20+
4b.py
21+
Golfed result EQUALS the regular result. The solution was shortened from 241 to 103 chars, or 42.74% of the original.
22+
23+
9a.py
24+
Golfed result EQUALS the regular result. The solution was shortened from 678 to 181 chars, or 26.7% of the original.
25+
26+
9b.py
27+
Golfed result EQUALS the regular result. The solution was shortened from 548 to 153 chars, or 27.92% of the original.

0 commit comments

Comments
 (0)