Compare commits

...

3 Commits

Author SHA1 Message Date
HOME-VM-TOSCHOOL
753d0ea1db zad B02 2023-10-31 20:49:46 +01:00
HOME-VM-TOSCHOOL
188518f062 zad B01 2023-10-31 20:47:14 +01:00
HOME-VM-TOSCHOOL
889518e47a better output B0 2023-10-31 20:47:05 +01:00
6 changed files with 138 additions and 6 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"cSpell.words": [
"csvfile"
]
}

View File

@ -3,7 +3,6 @@ import csv
from numpy import append from numpy import append
print(sys.argv)
if len(sys.argv) == 1: if len(sys.argv) == 1:
print("Default arguments parsed") print("Default arguments parsed")
sys.argv.append("fsa_description.arg") sys.argv.append("fsa_description.arg")
@ -23,19 +22,26 @@ with open(sys.argv[1], "r", newline="", encoding="utf8") as csvfile:
with open(sys.argv[2], "r", newline="", encoding="utf8") as csvfile: with open(sys.argv[2], "r", newline="", encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|") filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
test1_in = list(filereader) test_in = list(filereader)
with open(sys.argv[3], "r", newline="", encoding="utf8") as csvfile: with open(sys.argv[3], "r", newline="", encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|") filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
test1_out = list(filereader) test_out = list(filereader)
for word in test1_in: for i, word in enumerate(test_in):
current_state = 0 current_state = 0
if len(word) != 0: if len(word) != 0:
for letter in word[0]: for letter in word[0]:
current_state = fsa_description_map[(current_state, letter)] current_state = fsa_description_map[(current_state, letter)]
print(str(i + 1) + "\t", end="")
if current_state == accepting_state: if current_state == accepting_state:
print("YES") print("YES\t", end="")
if "YES" != test_out[i][0]:
print(" ERROR", end="")
else: else:
print("NO") print("NO", end="")
if "NO" != test_out[i][0]:
print(" ERROR", end="")
print()

View File

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

48
TaskB01/run.py Normal file
View File

@ -0,0 +1,48 @@
from logging import ERROR
import sys
import csv
from numpy import append
if len(sys.argv) == 1:
print("Default arguments parsed\n")
sys.argv.append("fsa_description.arg")
sys.argv.append("test.in")
sys.argv.append("test.exp")
with open(sys.argv[1], "r", newline="", encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
fsa_description = list(filereader)
accepting_state = int(fsa_description[-1][0])
fsa_description = fsa_description[:-1]
fsa_description_map = {}
for item in fsa_description:
tuple = (int(item[0]), item[2])
fsa_description_map[tuple] = int(item[1])
with open(sys.argv[2], "r", newline="", encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
test_in = list(filereader)
with open(sys.argv[3], "r", newline="", encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
test_out = list(filereader)
for i, word in enumerate(test_in):
current_state = 0
if len(word) != 0:
for letter in word[0]:
current_state = fsa_description_map[(current_state, letter)]
print(str(i + 1) + "\t", end="")
if current_state == accepting_state:
print("YES\t", end="")
if "YES" != test_out[i][0]:
print(" ERROR", end="")
else:
print("NO", end="")
if "NO" != test_out[i][0]:
print(" ERROR", end="")
print()

View File

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

47
TaskB02/run.py Normal file
View File

@ -0,0 +1,47 @@
import sys
import csv
from numpy import append
if len(sys.argv) == 1:
print("Default arguments parsed\n")
sys.argv.append("fsa_description.arg")
sys.argv.append("test.in")
sys.argv.append("test.exp")
with open(sys.argv[1], "r", newline="", encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
fsa_description = list(filereader)
accepting_state = int(fsa_description[-1][0])
fsa_description = fsa_description[:-1]
fsa_description_map = {}
for item in fsa_description:
tuple = (int(item[0]), item[2])
fsa_description_map[tuple] = int(item[1])
with open(sys.argv[2], "r", newline="", encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
test_in = list(filereader)
with open(sys.argv[3], "r", newline="", encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
test_out = list(filereader)
for i, word in enumerate(test_in):
current_state = 0
if len(word) != 0:
for letter in word[0]:
current_state = fsa_description_map[(current_state, letter)]
print(str(i + 1) + "\t", end="")
if current_state == accepting_state:
print("YES\t", end="")
if "YES" != test_out[i][0]:
print(" ERROR", end="")
else:
print("NO", end="")
if "NO" != test_out[i][0]:
print(" ERROR", end="")
print()