Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
arc
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Buckworth, Titus Frederick Christian C
arc
Commits
d2e15eb5
Commit
d2e15eb5
authored
3 months ago
by
tbuckworth
Browse files
Options
Downloads
Patches
Plain Diff
close to a solution for 2
parent
06a8d30f
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
json_tests.py
+3
-2
3 additions, 2 deletions
json_tests.py
main.py
+5
-0
5 additions, 0 deletions
main.py
prolog/solution_2.pl
+134
-0
134 additions, 0 deletions
prolog/solution_2.pl
task.py
+5
-1
5 additions, 1 deletion
task.py
with
147 additions
and
3 deletions
json_tests.py
+
3
−
2
View file @
d2e15eb5
...
...
@@ -10,7 +10,7 @@ from task import Task
class
TaskTester
(
unittest
.
TestCase
):
@classmethod
def
setUpClass
(
cls
):
cls
.
task_dict
=
load_task
(
)
#
"data/training/
0b148d64
.json")
cls
.
task_dict
=
load_task
(
"
data/training/
d4f3cd78
.json
"
)
cls
.
task
=
Task
(
cls
.
task_dict
)
# Example of accessing input/output grids for the first example
cls
.
output_grid
=
cls
.
task
.
train_examples
[
0
].
output_grid
.
grid
...
...
@@ -29,12 +29,13 @@ class TaskTester(unittest.TestCase):
self
.
assertTrue
((
out_grid
==
self
.
output_grid
).
all
())
def
test_task_class
(
self
):
solution
=
"
solution_
1
"
solution
=
"
solution_
2
"
res
=
self
.
task
.
try_solution
(
solution
)
self
.
assertTrue
(
res
)
def
test_task_empty
(
self
):
res
=
self
.
task
.
try_solution
(
"
empty_solution
"
)
self
.
assertFalse
(
res
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
main.py
+
5
−
0
View file @
d2e15eb5
...
...
@@ -144,6 +144,11 @@ def colour_names2idx(colour_names):
colour_to_idx
=
{
colour
:
idx
for
idx
,
colour
in
zip
(
df
.
int
,
df
.
name
)}
# Vectorize the mapping function
vectorized_mapping
=
np
.
vectorize
(
colour_to_idx
.
get
)
incorrect_colours
=
np
.
unique
(
colour_names
[
~
np
.
isin
(
colour_names
,
df
.
name
)])
if
len
(
incorrect_colours
)
>
0
:
raise
IndexError
(
f
"
Incorrect colour names:
{
'
|
'
.
join
(
incorrect_colours
)
}
\n
"
f
"
Must be one of:
{
'
,
'
.
join
(
df
.
name
)
}
"
)
# Apply the mapping to the 2D array
arr_idx
=
vectorized_mapping
(
colour_names
)
return
arr_idx
...
...
This diff is collapsed.
Click to expand it.
prolog/solution_2.pl
0 → 100644
+
134
−
0
View file @
d2e15eb5
all_rows
(
Rs
):-
setof
(
R
,
C
^
Colour
^
input_colour
(
R
,
C
,
Colour
),
Rs
).
all_cols
(
Cs
):-
setof
(
C
,
R
^
Colour
^
input_colour
(
R
,
C
,
Colour
),
Cs
).
row
(
R
):-
all_rows
(
Rs
),
member
(
R
,
Rs
).
column
(
C
):-
all_cols
(
Cs
),
member
(
C
,
Cs
).
nrow
(
NR
):-
all_rows
(
Rs
),
length
(
Rs
,
NR
).
ncol
(
NC
):-
all_cols
(
Cs
),
length
(
Cs
,
NC
).
min
(
A
,
B
,
B
):-
A
<
B
.
min
(
B
,
A
,
B
):-
A
>=
B
.
min
([
Min
],
Min
).
min
([
H
|
T
],
Min
):-
min
(
T
,
MinT
),
min
(
H
,
MinT
,
Min
).
left_wall
(
C
):-
input_colour
(
_
,
C
,
grey
),
input_colour
(
_
,
C2
,
grey
),
C2
>
C
.
right_wall
(
C
):-
input_colour
(
_
,
C
,
grey
),
input_colour
(
_
,
C2
,
grey
),
C2
<
C
.
top_wall
(
R
):-
input_colour
(
R
,
_
,
grey
),
input_colour
(
R2
,
_
,
grey
),
R
<
R2
.
bottom_wall
(
R
):-
input_colour
(
R
,
_
,
grey
),
input_colour
(
R2
,
_
,
grey
),
R2
>
R
.
left_wall_unique
(
W
):-
setof
(
C
,
left_wall
(
C
),
L
),
min
(
L
,
W
).
right_wall_unique
(
W
):-
setof
(
C
,
right_wall
(
C
),
L
),
min
(
L
,
W
).
top_wall_unique
(
W
):-
setof
(
C
,
top_wall
(
C
),
L
),
min
(
L
,
W
).
bottom_wall_unique
(
W
):-
setof
(
C
,
bottom_wall
(
C
),
L
),
min
(
L
,
W
).
gap_horizontal
(
R
,
C
):-
input_colour
(
R
,
C
,
black
),
RT
is
R
+
1
,
input_colour
(
RT
,
C
,
grey
),
RB
is
R
-
1
,
input_colour
(
RB
,
C
,
grey
).
gap_vertical
(
R
,
C
):-
input_colour
(
R
,
C
,
black
),
CT
is
C
+
1
,
input_colour
(
R
,
CT
,
grey
),
CB
is
C
-
1
,
input_colour
(
R
,
CB
,
grey
).
output_colour
(
R
,
C
,
grey
):-
input_colour
(
R
,
C
,
grey
).
output_colour
(
R
,
C
,
teal
):-
row
(
R
),
column
(
C
),
top_wall_unique
(
RT
),
R
<
RT
,
bottom_wall_unique
(
RB
),
R
>
RB
,
left_wall_unique
(
CT
),
C
>
CT
,
right_wall_unique
(
CB
),
C
<
CB
.
output_colour
(
R
,
C
,
teal
):-
row
(
R
),
column
(
C
),
gap_horizontal
(
R
,
CG
),
CG
=<
C
,
input_colour
(
R
,
CL
,
grey
),
CL
<
C
.
output_colour
(
R
,
C
,
teal
):-
row
(
R
),
column
(
C
),
gap_horizontal
(
R
,
CG
),
CG
>=
C
,
input_colour
(
R
,
CL
,
grey
),
CL
>
C
.
output_colour
(
R
,
C
,
teal
):-
row
(
R
),
column
(
C
),
gap_vertical
(
RG
,
C
),
RG
=<
R
,
input_colour
(
RB
,
C
,
grey
),
RB
<
R
.
output_colour
(
R
,
C
,
teal
):-
row
(
R
),
column
(
C
),
gap_vertical
(
RG
,
C
),
RG
>=
R
,
input_colour
(
RB
,
C
,
grey
),
RB
>
R
.
This diff is collapsed.
Click to expand it.
task.py
+
5
−
1
View file @
d2e15eb5
import
numpy
as
np
from
main
import
run_prolog_program
,
prolog2FOL_array
,
FOL2grid
,
grid2FOL
,
FOL2prolog
from
main
import
run_prolog_program
,
prolog2FOL_array
,
FOL2grid
,
grid2FOL
,
FOL2prolog
,
array_and_plot_grid
class
Grid
:
...
...
@@ -28,6 +28,10 @@ class Example:
result
=
same
.
all
()
if
not
result
:
print
(
f
"
output incorrect due to
{
(
~
same
).
sum
()
}
/
{
np
.
prod
(
same
.
shape
)
}
cells
"
)
array_and_plot_grid
(
self
.
input_grid
.
grid
)
array_and_plot_grid
(
out_grid
)
array_and_plot_grid
(
self
.
output_grid
.
grid
)
raise
Exception
return
result
class
Task
:
...
...
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