Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GroupProject
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joe Stephenson
GroupProject
Commits
5a8c5dc1
Commit
5a8c5dc1
authored
Oct 22, 2024
by
David Palmer
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
b6ef2782
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lightswitches.py
+102
-0
102 additions, 0 deletions
lightswitches.py
with
102 additions
and
0 deletions
lightswitches.py
0 → 100644
+
102
−
0
View file @
5a8c5dc1
class
LightPuzzle
:
def
__init__
(
self
):
self
.
statearray
=
[[
1
,
0
,
1
],
[
0
,
0
,
0
],
[
1
,
0
,
1
]]
self
.
solved
=
False
def
PrintPuzzle
(
self
):
i
=
3
for
row
in
self
.
statearray
:
rowprint
=
"
"
.
join
([
str
(
tile
)
for
tile
in
row
])
print
(
str
(
i
)
+
"
|
"
+
rowprint
)
i
-=
1
print
(
"
_ _ _
"
)
print
(
"
1 2 3
"
)
print
()
def
FlipTile
(
self
,
x
,
y
):
self
.
statearray
[
y
][
x
]
=
self
.
ChangeState
(
self
.
statearray
[
y
][
x
])
if
y
>
0
:
self
.
statearray
[
y
-
1
][
x
]
=
self
.
ChangeState
(
self
.
statearray
[
y
-
1
][
x
])
if
y
<
len
(
self
.
statearray
)
-
1
:
self
.
statearray
[
y
+
1
][
x
]
=
self
.
ChangeState
(
self
.
statearray
[
y
+
1
][
x
])
if
x
>
0
:
self
.
statearray
[
y
][
x
-
1
]
=
self
.
ChangeState
(
self
.
statearray
[
y
][
x
-
1
])
if
x
<
len
(
self
.
statearray
[
y
])
-
1
:
self
.
statearray
[
y
][
x
+
1
]
=
self
.
ChangeState
(
self
.
statearray
[
y
][
x
+
1
])
def
ChangeState
(
self
,
number
):
return
0
if
number
==
1
else
1
def
TakeEdit
(
self
):
valid
=
False
while
not
valid
:
ToChange
=
input
(
"
What part of the puzzle would you like to flip? Enter coordinates in the format X,Y (1-3):
"
)
if
ToChange
==
""
:
quit
()
XY
=
ToChange
.
split
(
"
,
"
)
if
len
(
XY
)
!=
2
or
not
XY
[
0
].
isdigit
()
or
not
XY
[
1
].
isdigit
():
print
(
"
Invalid input. Please enter two numbers separated by a comma.
"
)
elif
int
(
XY
[
0
])
>
3
or
int
(
XY
[
0
])
<
1
or
int
(
XY
[
1
])
>
3
or
int
(
XY
[
1
])
<
1
:
print
(
"
Invalid input. Coordinates must be between 1 and 3.
"
)
else
:
valid
=
True
self
.
FlipTile
(
int
(
XY
[
0
])
-
1
,
3
-
int
(
XY
[
1
]))
def
StartPuzzle
(
self
):
for
i
in
range
(
10
):
if
i
==
9
:
print
(
"
You have
"
,
10
-
i
,
"
go left
"
)
else
:
print
(
"
You have
"
,
10
-
i
,
"
goes left
"
)
self
.
PrintPuzzle
()
self
.
TakeEdit
()
self
.
CheckSolved
()
if
self
.
solved
:
print
(
"
Puzzle solved!
"
)
break
def
CheckSolved
(
self
):
for
row
in
self
.
statearray
:
if
0
in
row
:
return
self
.
solved
=
True
lights
=
LightPuzzle
()
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