Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Niklas Rieken
tcs_pdfs
Commits
8f9bc584
Commit
8f9bc584
authored
Mar 25, 2018
by
Niklas Rieken
Browse files
rm old pumping game
parent
2d8d8186
Changes
1
Hide whitespace changes
Inline
Side-by-side
FoSAP/pumpgame.py
deleted
100644 → 0
View file @
2d8d8186
import
sys
import
random
# language {a^n b^n : n \in IN}
def
L
(
w
):
i
=
0
mid
=
False
for
a
in
w
:
if
a
not
in
[
'a'
,
'b'
]:
return
False
if
a
==
'a'
and
not
mid
:
i
+=
1
if
a
==
'a'
and
mid
:
return
False
if
a
==
'b'
and
mid
:
i
-=
1
if
a
==
'b'
and
not
mid
:
r
=
i
mid
=
True
i
-=
1
if
i
!=
0
or
2
*
r
<
n
:
return
False
return
True
n
=
random
.
randint
(
1
,
10
)
print
(
"Alice claims the language [[a^n b^n : n in IN]] is regular and there exists an automaton with {0} states."
.
format
(
n
))
w
=
input
(
"Choose a word in the language of length >= {0}: "
.
format
(
n
))
if
not
L
(
w
):
sys
.
exit
(
"Your word is not in the language or your word is too short, you lose!"
)
k
=
random
.
randint
(
0
,
n
-
1
)
l
=
random
.
randint
(
k
+
1
,
n
)
x
=
w
[:
k
]
y
=
w
[
k
:
l
]
z
=
w
[
l
:]
print
(
"Alice chooses the decomposition x = {0}, y = {1}, z = {2}."
.
format
(
x
,
y
,
z
))
i
=
int
(
input
(
"Choose a natural number i sucht that xy^iz is not in the language: "
))
wp
=
x
+
(
y
*
i
)
+
z
if
not
L
(
wp
):
print
(
"w' = xy^{0}z is not in the language, you win."
.
format
(
i
))
else
:
sys
.
exit
(
"w' = xy^{0}z is in the language, you lose."
.
format
(
i
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment