Movatterモバイル変換


[0]ホーム

URL:


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

Commit18cc7a2

Browse files
committed
Added day 2017-17
1 parent088c54a commit18cc7a2

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

‎2017/17-Spinlock.py‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -------------------------------- Input data -------------------------------- #
2+
importos
3+
4+
test_data= {}
5+
6+
test=1
7+
test_data[test]= {"input":3,
8+
"expected": ['Unknown','Unknown'],
9+
}
10+
11+
test='real'
12+
input_file=os.path.join(os.path.dirname(__file__),'Inputs',os.path.basename(__file__).replace('.py','.txt'))
13+
test_data[test]= {"input":344,
14+
"expected": ['996','1898341'],
15+
}
16+
17+
# -------------------------------- Control program execution -------------------------------- #
18+
19+
case_to_test='real'
20+
part_to_test=2
21+
verbose_level=1
22+
23+
# -------------------------------- Initialize some variables -------------------------------- #
24+
25+
puzzle_input=test_data[case_to_test]['input']
26+
puzzle_expected_result=test_data[case_to_test]['expected'][part_to_test-1]
27+
puzzle_actual_result='Unknown'
28+
29+
30+
# -------------------------------- Actual code execution -------------------------------- #
31+
32+
spinlock= [0]
33+
34+
ifpart_to_test==1:
35+
position=0
36+
foriinrange (1,2017+1):
37+
position+=puzzle_input
38+
position%=len(spinlock)
39+
spinlock=spinlock[:position+1]+ [i]+spinlock[position+1:]
40+
position+=1
41+
position%=len(spinlock)
42+
43+
puzzle_actual_result=spinlock[(position+1)%len(spinlock)]
44+
45+
46+
else:
47+
position=0
48+
number_after_zero=0
49+
spinlock_length=1
50+
foriinrange (1,50000000+1):
51+
position+=puzzle_input
52+
position%=spinlock_length
53+
spinlock_length+=1
54+
ifposition==0:
55+
number_after_zero=i
56+
position+=1
57+
position%=spinlock_length
58+
59+
puzzle_actual_result=number_after_zero
60+
61+
62+
63+
# -------------------------------- Outputs / results -------------------------------- #
64+
65+
ifverbose_level>=3:
66+
print ('Input : '+puzzle_input)
67+
print ('Expected result : '+str(puzzle_expected_result))
68+
print ('Actual result : '+str(puzzle_actual_result))
69+
70+
71+
72+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp