Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 7, 2021. It is now read-only.

Commit b9e3a83

Browse files
Add part2.py
1 parent bbbe6d8 commit b9e3a83

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

‎day3/part1.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import math
22

33

4-
def manhattan(index):
4+
def getcoord(index):
55
root = math.sqrt(index)
66
radius = int(root) if int(root)%2!=0 else int(root) - 1
77
count = index - radius*radius
8-
arc = abs((count % (radius+1)) - ((radius+1)/2))
8+
return int((radius+1)/2), count
9+
10+
def manhattan(index):
11+
rad, count = getcoord(index)
12+
arc = abs((count % (rad*2)) - rad)
13+
return int(arc + rad)
914

10-
return int(arc + ((radius+1) / 2))
1115

1216
def main():
1317
inp = input('[?] The puzzle input: ')
14-
print(manhattan(int(inp)))
18+
print('[*] The answer is: {}'.format(manhattan(int(inp))))
1519

1620

1721
if __name__=='__main__':

‎day3/part2.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from part1 import getcoord
2+
3+
def square(index):
4+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /