This commit is contained in:
Bartekfiolek 2023-10-15 16:42:49 +02:00
parent 7bed1eaa82
commit 0891a918c7
14 changed files with 381 additions and 0 deletions

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -45,6 +45,8 @@ We własnym repozytorium:
## Zajęcia 1 16.10.2023 Automaty deterministyczne skończone
B00 - zadanie wykonywane wspólnie na zajęciach
B01-B04, B06-B09 - po jedno dla każdego
B05 - jedno dla wszystkich

96
TaskB00/run.py Normal file
View File

@ -0,0 +1,96 @@
# B00 (2021)
#
import sys
class FSA:
def __init__(self):
self.initial_state = '0' # zakładamy dla uproszczenia, że initial state = 0
self.final_states = set()
self.transitions = dict()
self.alphabet = set()
def add_transition(self, state_from, state_to, symbol):
if state_from in self.transitions.keys():
self.transitions[state_from][symbol] = state_to
else:
self.transitions[state_from] = dict()
self.transitions[state_from][symbol] = state_to
def add_final_state(self, state):
self.final_states.add(state)
def get_final_state(self, string):
current_state = self.initial_state
for symbol in string:
current_state = self.transitions[current_state][symbol]
return current_state
def accepts(self, string):
if self.get_final_state(string) in self.final_states:
return True
else:
return False
fsa = FSA()
# def build_fsa(self): #, dfa_desciption
table = open(sys.argv[1]) # dfa_desciption
for line in table:
line = line.rstrip('\n')
if len(line.split('\t')) == 3:
a, b, c = line.split('\t')
fsa.add_transition(a, b, c) #self
fsa.alphabet.add(c) #self
elif len(line.split('\t')) == 1:
fsa.add_final_state(line) #self
else:
assert False
# def run_dfa(self): # , input
for line in sys.stdin: # open(input)
line = line.rstrip()
line_n = list(line)
for i in range(len(line_n)):
if line_n[i] not in fsa.alphabet: #self
line_n[i] = 'x'
if fsa.accepts(line_n): #self
print('YES')
else:
print('NO')
# def run_dfa_and_compare(self, input, expected):
#
# accepts = []
#
# for line in open(input): # sys.stdin
# line = line.rstrip()
#
# line_n = list(line)
#
# for i in range(len(line_n)):
# if line_n[i] not in self.alphabet:
# line_n[i] = 'x'
#
# if self.accepts(line_n):
# accepts.append('YES')
# else:
# accepts.append('NO')
#
# i = 0
# for line in open(expected):
# if line.rstrip() != accepts[i]:
# print('Incorrect in line ' + str(i))
# return
# i = i + 1
# print('Correct')

View File

@ -0,0 +1,13 @@
0 1 0
0 5 1
1 5 0
1 2 1
2 3 1
2 4 0
3 3 1
3 4 0
4 4 0
4 2 1
5 5 1
5 5 0
2

View File

@ -0,0 +1,5 @@
0 0 1
0 1 0
1 1 1
1 0 0
0

96
TaskB03/run.py Normal file
View File

@ -0,0 +1,96 @@
# B00 (2021)
#
import sys
class FSA:
def __init__(self):
self.initial_state = '0' # zakładamy dla uproszczenia, że initial state = 0
self.final_states = set()
self.transitions = dict()
self.alphabet = set()
def add_transition(self, state_from, state_to, symbol):
if state_from in self.transitions.keys():
self.transitions[state_from][symbol] = state_to
else:
self.transitions[state_from] = dict()
self.transitions[state_from][symbol] = state_to
def add_final_state(self, state):
self.final_states.add(state)
def get_final_state(self, string):
current_state = self.initial_state
for symbol in string:
current_state = self.transitions[current_state][symbol]
return current_state
def accepts(self, string):
if self.get_final_state(string) in self.final_states:
return True
else:
return False
fsa = FSA()
# def build_fsa(self): #, dfa_desciption
table = open(sys.argv[1]) # dfa_desciption
for line in table:
line = line.rstrip('\n')
if len(line.split('\t')) == 3:
a, b, c = line.split('\t')
fsa.add_transition(a, b, c) #self
fsa.alphabet.add(c) #self
elif len(line.split('\t')) == 1:
fsa.add_final_state(line) #self
else:
assert False
# def run_dfa(self): # , input
for line in sys.stdin: # open(input)
line = line.rstrip()
line_n = list(line)
for i in range(len(line_n)):
if line_n[i] not in fsa.alphabet: #self
line_n[i] = 'x'
if fsa.accepts(line_n): #self
print('YES')
else:
print('NO')
# def run_dfa_and_compare(self, input, expected):
#
# accepts = []
#
# for line in open(input): # sys.stdin
# line = line.rstrip()
#
# line_n = list(line)
#
# for i in range(len(line_n)):
# if line_n[i] not in self.alphabet:
# line_n[i] = 'x'
#
# if self.accepts(line_n):
# accepts.append('YES')
# else:
# accepts.append('NO')
#
# i = 0
# for line in open(expected):
# if line.rstrip() != accepts[i]:
# print('Incorrect in line ' + str(i))
# return
# i = i + 1
# print('Correct')

0
TaskB04/test.out Normal file
View File

View File

@ -0,0 +1,56 @@
0 0 0
0 1 1
0 0 2
0 0 3
0 0 4
0 0 5
0 0 6
0 0 7
0 0 8
0 0 9
0 0 x
1 0 0
1 0 1
1 0 2
1 0 3
1 0 4
1 0 5
1 0 6
1 0 7
1 0 8
1 2 9
1 0 x
2 3 0
2 3 1
2 3 2
2 3 3
2 3 4
2 3 5
2 3 6
2 3 7
2 3 8
2 3 9
2 0 x
3 4 0
3 4 1
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 0 x
4 4 0
4 4 1
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9
4 4 x
4

96
TaskB05/run.py Normal file
View File

@ -0,0 +1,96 @@
# B00 (2021)
#
import sys
class FSA:
def __init__(self):
self.initial_state = '0' # zakładamy dla uproszczenia, że initial state = 0
self.final_states = set()
self.transitions = dict()
self.alphabet = set()
def add_transition(self, state_from, state_to, symbol):
if state_from in self.transitions.keys():
self.transitions[state_from][symbol] = state_to
else:
self.transitions[state_from] = dict()
self.transitions[state_from][symbol] = state_to
def add_final_state(self, state):
self.final_states.add(state)
def get_final_state(self, string):
current_state = self.initial_state
for symbol in string:
current_state = self.transitions[current_state][symbol]
return current_state
def accepts(self, string):
if self.get_final_state(string) in self.final_states:
return True
else:
return False
fsa = FSA()
# def build_fsa(self): #, dfa_desciption
table = open(sys.argv[1]) # dfa_desciption
for line in table:
line = line.rstrip('\n')
if len(line.split('\t')) == 3:
a, b, c = line.split('\t')
fsa.add_transition(a, b, c) #self
fsa.alphabet.add(c) #self
elif len(line.split('\t')) == 1:
fsa.add_final_state(line) #self
else:
assert False
# def run_dfa(self): # , input
for line in sys.stdin: # open(input)
line = line.rstrip()
line_n = list(line)
for i in range(len(line_n)):
if line_n[i] not in fsa.alphabet: #self
line_n[i] = 'x'
if fsa.accepts(line_n): #self
print('YES')
else:
print('NO')
# def run_dfa_and_compare(self, input, expected):
#
# accepts = []
#
# for line in open(input): # sys.stdin
# line = line.rstrip()
#
# line_n = list(line)
#
# for i in range(len(line_n)):
# if line_n[i] not in self.alphabet:
# line_n[i] = 'x'
#
# if self.accepts(line_n):
# accepts.append('YES')
# else:
# accepts.append('NO')
#
# i = 0
# for line in open(expected):
# if line.rstrip() != accepts[i]:
# print('Incorrect in line ' + str(i))
# return
# i = i + 1
# print('Correct')

View File

0
TaskB06/simple.out Normal file
View File

6
TaskX02/run.py Normal file
View File

@ -0,0 +1,6 @@
import sys
count = 0
for line in sys.stdin:
count += 1
print(count)

1
TaskX02/simple.out Normal file
View File

@ -0,0 +1 @@
3

4
TaskX03/run.py Normal file
View File

@ -0,0 +1,4 @@
import sys
for line in sys.stdin:
print(str(len(line)-1) + ' ' + line, end='')