Compare commits

..

No commits in common. "6ddcc106ecf2956217ba36c5014c4b005b4d07bf" and "0478a8789aa1684eaebe2eeea6381904f6df13da" have entirely different histories.

3 changed files with 0 additions and 124 deletions

View File

@ -1,21 +0,0 @@
#!/usr/bin/env python3
if __name__ == '__main__':
total = 0
with open("input", "r", encoding="utf-8") as sheet:
remainder = []
for line in sheet:
values = list(map(int, line.split()))
values.sort()
result = ""
i = 1
while i < len(values) and result == "":
j = 0
while j >= 0 and j < i and result == "":
remainder = values[i] % values[j]
if remainder == 0:
result = int(values[i] / values[j])
j += 1
i += 1
total += result
print(total)

View File

@ -1,41 +0,0 @@
#!/usr/bin/env python3
if __name__ == '__main__':
target = 277678
xstep = 1
ystep = 1
origin = [0, 0]
square = 1
pointer = origin
def inc_step(step):
if step >= 0:
return int(-1 * (step + 1))
else:
return int(-1 * (step - 1))
while square < target:
i = 1
while i <= abs(xstep) and square < target:
square += 1
if xstep >= 0:
pointer[0] += 1
else:
pointer[0] += -1
i += 1
xstep = inc_step(xstep)
i = 1
while i <= abs(ystep) and square < target:
square += 1
if ystep >= 0:
pointer[1] += 1
else:
pointer[1] += -1
i += 1
ystep = inc_step(ystep)
if square == target:
xloc = pointer[0]
yloc = pointer[1]
distance = abs(xloc) + abs(yloc)
print(f"dist to square {target} is {int(abs(xloc))}+{int(abs(yloc))}={distance}")

View File

@ -1,62 +0,0 @@
spiral memory!
i think i'll keep a live count of the current position relative to square 1,
slowly stepping one by one through each square sequentially.
my input is only 277678, so this should be fine!
i notice that the pointer starts at square 1, at, say, (0,0),
and then moves one square right, then one up,
then two left, then two down,
then three right, three up, etc
seems like it follows the pattern:
(x1 , y1 ) = (0 , 0 )
(x2 , y2 ) = (x1 + 1 , y1 )
(x3 , y3 ) = (x2 , y1 + 1)
(x5 , y5 ) = (x3 - 2 , y3 )
(x7 , y7 ) = (x5 , y3 - 2)
(x10, y10) = (x5 + 3 , y7 )
etc.
i'll just for loop this shit
something like: (copied to 1spiral_memory.py and worked further from there)
(the following is my first rough sketch. see 1spiral_memory.py)
target = 277678
xstep = 1
ystep = 1
origin = (0, 0)
square = 1
pointer = origin
def inc_step(step):
if step >= 0:
return int(-1 * (step + 1))
else:
return int(-1 * (step - 1))
while square < target:
i = 1
while i <= abs(xstep) and square < target:
square += 1
if xstep >= 0:
pointer += (1, 0)
else:
pointer -= (1, 0)
i += 1
xstep = inc_step(xstep)
i = 1
while i <= abs(ystep) and square < target:
square += 1
if ystep >= 0:
pointer += (0, 1)
else:
pointer -= (0, 1)
ystep = inc_step(ystep)
if square == target:
xloc = pointer[0]
yloc = pointer[1]
distance = abs(xloc) + abs(yloc)