Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
ICFP contest 2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
Nathaniel Mattsson
ICFP contest 2024
Commits
8161387d
Commit
8161387d
authored
8 months ago
by
Nathaniel Mattsson
Browse files
Options
Downloads
Patches
Plain Diff
Implement basic spaceshipsolver
parent
947c243e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
spaceshipsolver.py
+54
-0
54 additions, 0 deletions
spaceshipsolver.py
with
54 additions
and
0 deletions
spaceshipsolver.py
0 → 100644
+
54
−
0
View file @
8161387d
import
numpy
as
np
def
spaceshipsolver
(
coordinates
):
velocity
=
np
.
array
([
0
,
0
])
moves
=
""
curr_coords
=
np
.
array
([
0
,
0
])
while
(
coordinates
):
while
((
curr_coords
!=
coordinates
[
0
]).
any
()):
dist_after
=
coordinates
[
0
]
-
curr_coords
-
velocity
if
(
dist_after
[
0
]
>
0
):
if
(
dist_after
[
1
]
>
0
):
moves
+=
'
9
'
velocity
+=
np
.
array
([
1
,
1
])
elif
(
dist_after
[
1
]
<
0
):
moves
+=
'
3
'
velocity
+=
np
.
array
([
1
,
-
1
])
else
:
moves
+=
'
6
'
velocity
+=
np
.
array
([
1
,
0
])
elif
(
dist_after
[
0
]
<
0
):
if
(
dist_after
[
1
]
>
0
):
moves
+=
'
7
'
velocity
+=
np
.
array
([
-
1
,
1
])
elif
(
dist_after
[
1
]
<
0
):
moves
+=
'
1
'
velocity
+=
np
.
array
([
-
1
,
-
1
])
else
:
moves
+=
'
4
'
velocity
+=
np
.
array
([
-
1
,
0
])
else
:
if
(
dist_after
[
1
]
>
0
):
moves
+=
(
'
8
'
)
velocity
+=
np
.
array
([
0
,
1
])
elif
(
dist_after
[
1
]
<
0
):
moves
+=
(
'
2
'
)
velocity
+=
np
.
array
([
0
,
-
1
])
else
:
moves
+=
'
5
'
velocity
+=
np
.
array
([
0
,
0
])
curr_coords
+=
velocity
coordinates
.
pop
(
0
)
return
moves
def
list_coordinates_to_arrays
(
coordinates
):
return
[
np
.
array
(
x
)
for
x
in
coordinates
]
coords
=
input
(
'
coords:
'
)
coords
=
coords
.
split
(
'
.
'
)
for
x
in
range
(
len
(
coords
)):
coords
[
x
]
=
coords
[
x
].
split
(
'
,
'
)
for
k
in
range
(
len
(
coords
[
x
])):
coords
[
x
][
k
]
=
int
(
coords
[
x
][
k
])
coords
=
list_coordinates_to_arrays
(
coords
)
print
(
spaceshipsolver
(
coords
))
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