Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
advent
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
La Fée Verte
advent
Commits
a2913ce3
Commit
a2913ce3
authored
5 years ago
by
La Fée Verte
Browse files
Options
Downloads
Patches
Plain Diff
addning before removing code
parent
1f23ec6c
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
day_5/input.txt
+1
-0
1 addition, 0 deletions
day_5/input.txt
day_5/main.py
+171
-0
171 additions, 0 deletions
day_5/main.py
with
172 additions
and
0 deletions
day_5/input.txt
0 → 100644
+
1
−
0
View file @
a2913ce3
3,9,8,9,10,9,4,9,99,-1,8,99,9999,3,225,1,225,6,6,1100,1,238,225,104,0,1101,72,36,225,1101,87,26,225,2,144,13,224,101,-1872,224,224,4,224,102,8,223,223,1001,224,2,224,1,223,224,223,1102,66,61,225,1102,25,49,224,101,-1225,224,224,4,224,1002,223,8,223,1001,224,5,224,1,223,224,223,1101,35,77,224,101,-112,224,224,4,224,102,8,223,223,1001,224,2,224,1,223,224,223,1002,195,30,224,1001,224,-2550,224,4,224,1002,223,8,223,1001,224,1,224,1,224,223,223,1102,30,44,225,1102,24,21,225,1,170,117,224,101,-46,224,224,4,224,1002,223,8,223,101,5,224,224,1,224,223,223,1102,63,26,225,102,74,114,224,1001,224,-3256,224,4,224,102,8,223,223,1001,224,3,224,1,224,223,223,1101,58,22,225,101,13,17,224,101,-100,224,224,4,224,1002,223,8,223,101,6,224,224,1,224,223,223,1101,85,18,225,1001,44,7,224,101,-68,224,224,4,224,102,8,223,223,1001,224,5,224,1,223,224,223,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,7,677,226,224,102,2,223,223,1005,224,329,101,1,223,223,8,677,226,224,1002,223,2,223,1005,224,344,1001,223,1,223,1107,677,677,224,102,2,223,223,1005,224,359,1001,223,1,223,1107,226,677,224,102,2,223,223,1005,224,374,101,1,223,223,7,226,677,224,102,2,223,223,1005,224,389,101,1,223,223,8,226,677,224,1002,223,2,223,1005,224,404,101,1,223,223,1008,226,677,224,1002,223,2,223,1005,224,419,1001,223,1,223,107,677,677,224,102,2,223,223,1005,224,434,101,1,223,223,1108,677,226,224,1002,223,2,223,1006,224,449,101,1,223,223,1108,677,677,224,102,2,223,223,1006,224,464,101,1,223,223,1007,677,226,224,102,2,223,223,1006,224,479,101,1,223,223,1008,226,226,224,102,2,223,223,1006,224,494,101,1,223,223,108,226,226,224,1002,223,2,223,1006,224,509,101,1,223,223,107,226,226,224,102,2,223,223,1006,224,524,101,1,223,223,1107,677,226,224,102,2,223,223,1005,224,539,1001,223,1,223,108,226,677,224,1002,223,2,223,1005,224,554,101,1,223,223,1007,226,226,224,102,2,223,223,1005,224,569,101,1,223,223,8,226,226,224,102,2,223,223,1006,224,584,101,1,223,223,1008,677,677,224,1002,223,2,223,1005,224,599,1001,223,1,223,107,226,677,224,1002,223,2,223,1005,224,614,1001,223,1,223,1108,226,677,224,102,2,223,223,1006,224,629,101,1,223,223,7,677,677,224,1002,223,2,223,1005,224,644,1001,223,1,223,108,677,677,224,102,2,223,223,1005,224,659,101,1,223,223,1007,677,677,224,102,2,223,223,1006,224,674,101,1,223,223,4,223,99,226
This diff is collapsed.
Click to expand it.
day_5/main.py
0 → 100644
+
171
−
0
View file @
a2913ce3
"""
1202 Program Alarm.
"""
import
itertools
def
get_codes
():
with
open
(
'
input.txt
'
)
as
f
:
return
[
int
(
num
)
for
num
in
f
.
readline
().
strip
().
split
(
'
,
'
)]
def
get_opcode
(
opcode
):
tmp
=
int
(
opcode
)
op
=
tmp
%
100
tmp
//=
100
h
=
tmp
%
10
tmp
//=
10
k
=
tmp
%
10
tmp
//=
10
t
=
tmp
%
10
return
h
,
k
,
t
,
op
def
get_opcode2
(
opcode
):
tmp
=
int
(
opcode
)
op
=
tmp
%
100
tmp
//=
100
h
=
tmp
%
10
tmp
//=
10
k
=
tmp
%
10
tmp
//=
10
t
=
tmp
%
10
if
op
in
(
1
,
2
,
7
,
8
):
t
=
1
if
op
in
(
3
,):
h
=
1
return
(
h
,
k
,
t
),
op
def
op_get_size
(
op
):
if
op
==
1
:
return
4
if
op
==
2
:
return
4
if
op
==
3
:
return
2
if
op
==
4
:
return
2
if
op
==
5
:
return
3
if
op
==
6
:
return
3
if
op
==
7
:
return
4
if
op
==
8
:
return
4
if
op
==
99
:
return
1
def
get_next_command
(
ip
,
codes
):
parm_counts
=
{
1
:
3
,
2
:
3
,
3
:
1
,
4
:
1
,
5
:
2
,
6
:
2
,
7
:
3
,
8
:
3
,
99
:
0
}
modes
,
op
=
get_opcode2
(
codes
[
ip
])
params
=
[
0
,
0
,
0
]
ip
+=
1
for
x
in
range
(
parm_counts
[
op
]):
params
[
x
]
=
codes
[
ip
]
if
modes
[
x
]
==
0
:
params
[
x
]
=
codes
[
params
[
x
]]
ip
+=
1
return
ip
,
op
,
params
def
exec_command
(
ip
,
op
,
params
,
codes
):
if
op
==
1
:
codes
[
params
[
2
]]
=
params
[
0
]
+
params
[
1
]
elif
op
==
2
:
codes
[
params
[
2
]]
=
params
[
0
]
*
params
[
1
]
elif
op
==
3
:
val
=
int
(
input
(
'
Enter input val?
'
))
codes
[
params
[
0
]]
=
val
elif
op
==
4
:
print
(
f
'
Output value = (
{
params
[
0
]
}
)
'
)
elif
op
==
5
:
if
params
[
0
]
!=
0
:
ip
=
params
[
1
]
elif
op
==
6
:
if
params
[
0
]
==
0
:
ip
=
params
[
1
]
elif
op
==
7
:
if
params
[
0
]
<
params
[
1
]:
params
[
2
]
=
1
elif
op
==
8
:
if
params
[
0
]
==
params
[
1
]:
params
[
2
]
=
1
else
:
params
[
2
]
=
0
elif
op
==
99
:
ip
=
-
1
else
:
print
(
f
'
Bad Op Code
{
op
}
'
)
ip
=
-
1
return
ip
def
run_program
(
codes
):
ip
=
0
while
ip
!=
-
1
:
ip
,
op
,
params
=
get_next_command
(
ip
,
codes
)
ip
=
exec_command
(
ip
,
op
,
params
,
codes
)
def
run_computer
(
codes
):
ip
=
0
while
codes
[
ip
]
!=
99
:
p1_mode
,
p2_mode
,
p3_mode
,
op
=
get_opcode
(
codes
[
ip
+
0
])
# print(p1_mode, p2_mode, p3_mode, op)
size
=
op_get_size
(
op
)
if
size
==
1
:
pass
parm1
=
codes
[
ip
+
1
]
outpt
=
parm1
if
p1_mode
==
0
:
parm1
=
codes
[
parm1
]
if
size
==
4
:
parm2
=
codes
[
ip
+
2
]
if
p2_mode
==
0
:
parm2
=
codes
[
parm2
]
outpt
=
codes
[
ip
+
3
]
if
op
==
1
:
codes
[
outpt
]
=
parm1
+
parm2
elif
op
==
2
:
codes
[
outpt
]
=
parm1
*
parm2
elif
op
==
3
:
val
=
int
(
input
(
'
Enter input val?
'
))
codes
[
outpt
]
=
val
elif
op
==
4
:
print
(
f
'
Output value = (
{
parm1
}
)
'
)
else
:
print
(
f
'
Bad Op Code
{
op
}
'
)
break
ip
+=
size
def
main2
():
"""
Drive the program.
"""
codes
=
get_codes
()
new_codes
=
[
code
for
code
in
codes
]
run_computer
(
new_codes
)
def
main
():
"""
Drive the program.
"""
codes
=
get_codes
()
run_program
(
codes
)
if
__name__
==
"
__main__
"
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment