Compare commits
No commits in common. "960bc6219d6bba5026349fa3c44e14b14cbbd220" and "753d0ea1db207cb5a9f51145df5afc7723e46925" have entirely different histories.
960bc6219d
...
753d0ea1db
13
.vscode/settings.json
vendored
13
.vscode/settings.json
vendored
@ -1,16 +1,5 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"csvfile"
|
||||
],
|
||||
"[plaintext]": {
|
||||
"editor.quickSuggestions": {
|
||||
"other": false,
|
||||
"comments": false,
|
||||
"strings": false
|
||||
},
|
||||
"editor.insertSpaces": false
|
||||
},
|
||||
"cSpell.enableFiletypes": [
|
||||
"!plaintext"
|
||||
],
|
||||
]
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
0 1 0
|
||||
0 0 1
|
||||
1 0 0
|
||||
1 1 1
|
||||
0
|
@ -1,55 +0,0 @@
|
||||
import sys
|
||||
import csv
|
||||
import os
|
||||
|
||||
from numpy import append
|
||||
|
||||
DIR = os.path.dirname(__file__)
|
||||
|
||||
|
||||
def join_path(filename: str) -> str:
|
||||
return os.path.join(DIR, filename)
|
||||
|
||||
|
||||
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(join_path(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(join_path(sys.argv[2]), "r", newline="", encoding="utf8") as csvfile:
|
||||
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
|
||||
test_in = list(filereader)
|
||||
|
||||
with open(join_path(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()
|
@ -1,5 +0,0 @@
|
||||
0 1 0
|
||||
0 0 1
|
||||
1 0 0
|
||||
1 1 1
|
||||
1
|
@ -1,78 +0,0 @@
|
||||
import sys
|
||||
import csv
|
||||
import os
|
||||
|
||||
from numpy import append
|
||||
|
||||
DIR = os.path.dirname(__file__)
|
||||
alfabet = "01"
|
||||
|
||||
|
||||
def join_path(filename: str) -> str:
|
||||
return os.path.join(DIR, filename)
|
||||
|
||||
|
||||
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(join_path(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:
|
||||
for letter in item[2]:
|
||||
if letter not in alfabet:
|
||||
print("ERROR - letter not in alfabet: ", letter)
|
||||
exit(-1)
|
||||
tuple = (int(item[0]), letter)
|
||||
fsa_description_map[tuple] = int(item[1])
|
||||
|
||||
states = {}
|
||||
for item in fsa_description_map:
|
||||
states[item[0]] = states[item[0]] + item[1] if item[0] in states else item[1]
|
||||
|
||||
|
||||
from collections import Counter
|
||||
|
||||
|
||||
# check if all letters are used once
|
||||
def is_permutation(str1, str2):
|
||||
return Counter(str1) == Counter(str2)
|
||||
|
||||
|
||||
for state in states:
|
||||
if not is_permutation(states[state], alfabet):
|
||||
print("ERROR - alfabet doesn't match: ", states[state], alfabet)
|
||||
exit(-1)
|
||||
|
||||
|
||||
with open(join_path(sys.argv[2]), "r", newline="", encoding="utf8") as csvfile:
|
||||
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
|
||||
test_in = list(filereader)
|
||||
|
||||
with open(join_path(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()
|
@ -1,11 +0,0 @@
|
||||
0 1 1
|
||||
0 0 023456789x
|
||||
1 1 1
|
||||
1 2 9
|
||||
1 0 02345678x
|
||||
2 0 x
|
||||
2 3 0123456789
|
||||
3 0 x
|
||||
3 4 0123456789
|
||||
4 4 0123456789x
|
||||
4
|
@ -1,87 +0,0 @@
|
||||
import sys
|
||||
import csv
|
||||
import os
|
||||
|
||||
from numpy import append
|
||||
|
||||
DIR = os.path.dirname(__file__)
|
||||
alfabet = "0123456789x"
|
||||
|
||||
|
||||
def join_path(filename: str) -> str:
|
||||
return os.path.join(DIR, filename)
|
||||
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
print("Default arguments parsed\n")
|
||||
sys.argv.append("fsa_description.arg")
|
||||
sys.argv.append("simple.in")
|
||||
sys.argv.append("simple.exp")
|
||||
|
||||
with open(join_path(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 num, item in enumerate(fsa_description):
|
||||
for letter in item[2]:
|
||||
if letter not in alfabet:
|
||||
print("ERROR - letter not in alfabet: ", letter, "| line:", num)
|
||||
exit(-1)
|
||||
if (int(item[0]), letter) in fsa_description_map:
|
||||
print("ERROR - duplicate letter:", letter, "| line:", num)
|
||||
exit(-1)
|
||||
tuple = (int(item[0]), letter)
|
||||
fsa_description_map[tuple] = int(item[1])
|
||||
|
||||
states = {}
|
||||
for item in fsa_description_map:
|
||||
states[item[0]] = states[item[0]] + item[1] if item[0] in states else item[1]
|
||||
|
||||
|
||||
from collections import Counter
|
||||
|
||||
|
||||
# check if all letters are used once
|
||||
def is_permutation(str1, str2):
|
||||
return Counter(str1) == Counter(str2)
|
||||
|
||||
|
||||
for state in states:
|
||||
if not is_permutation(states[state], alfabet):
|
||||
print("ERROR - alfabet doesn't match: ", states[state], alfabet)
|
||||
exit(-1)
|
||||
|
||||
|
||||
with open(join_path(sys.argv[2]), "r", newline="", encoding="utf8") as csvfile:
|
||||
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
|
||||
test_in = list(filereader)
|
||||
|
||||
with open(join_path(sys.argv[3]), "r", newline="", encoding="utf8") as csvfile:
|
||||
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
|
||||
test_out = list(filereader)
|
||||
|
||||
|
||||
is_difference = []
|
||||
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", word, end="")
|
||||
is_difference.append(i)
|
||||
else:
|
||||
print("NO\t", end="")
|
||||
if "NO" != test_out[i][0]:
|
||||
print("ERROR", word, end="")
|
||||
is_difference.append(i)
|
||||
print()
|
||||
|
||||
if len(is_difference) != 0:
|
||||
print(is_difference)
|
@ -1,19 +0,0 @@
|
||||
0 1 h
|
||||
1 2 a
|
||||
2 3 m
|
||||
3 4 l
|
||||
4 5 e
|
||||
5 6 t
|
||||
1 1 h
|
||||
2 1 h
|
||||
3 1 h
|
||||
4 1 h
|
||||
5 1 h
|
||||
6 6 abcdefghijklmnopqrstuvwxyz
|
||||
0 0 abcdefgijklmnopqrstuvwxyz
|
||||
1 0 bcdefgijklmnopqrstuvwxyz
|
||||
2 0 abcdefgijklnopqrstuvwxyz
|
||||
3 0 abcdefgijkmnopqrstuvwxyz
|
||||
4 0 abcdfgijklmnopqrstuvwxyz
|
||||
5 0 abcdefgijklmnopqrsuvwxyz
|
||||
6
|
101
TaskB06/run.py
101
TaskB06/run.py
@ -1,101 +0,0 @@
|
||||
import sys
|
||||
import csv
|
||||
import os
|
||||
|
||||
from numpy import append
|
||||
|
||||
DIR = os.path.dirname(__file__)
|
||||
alfabet = "abcdefghijklmnopqrstuvwxyz "
|
||||
|
||||
|
||||
def join_path(filename: str) -> str:
|
||||
return os.path.join(DIR, filename)
|
||||
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
print("Default arguments parsed\n")
|
||||
sys.argv.append("fsa_description.arg")
|
||||
sys.argv.append("shakespeare_ascii_lower.in")
|
||||
sys.argv.append("shakespeare_ascii_lower.exp")
|
||||
|
||||
with open(join_path(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 = {}
|
||||
is_error = False
|
||||
for num, item in enumerate(fsa_description):
|
||||
for letter in item[2]:
|
||||
if letter not in alfabet:
|
||||
print("ERROR - letter not in alfabet: ", letter, "| line:", num + 1)
|
||||
exit(-1)
|
||||
if (int(item[0]), letter) in fsa_description_map:
|
||||
print("ERROR - duplicate letter:", letter, "| line:", num + 1)
|
||||
is_error = True
|
||||
tuple = (int(item[0]), letter)
|
||||
fsa_description_map[tuple] = int(item[1])
|
||||
|
||||
if is_error:
|
||||
exit(-1)
|
||||
|
||||
states = {}
|
||||
for item in fsa_description_map:
|
||||
states[item[0]] = states[item[0]] + item[1] if item[0] in states else item[1]
|
||||
|
||||
|
||||
from collections import Counter
|
||||
|
||||
|
||||
# check if all letters are used once
|
||||
def is_permutation(str1, str2):
|
||||
return Counter(str1) == Counter(str2)
|
||||
|
||||
|
||||
def find_missing_letters(str1, str2) -> str:
|
||||
missing_letters = ""
|
||||
for char in str2:
|
||||
if char not in str1:
|
||||
missing_letters += char
|
||||
return missing_letters
|
||||
|
||||
|
||||
for state in states:
|
||||
if not is_permutation(states[state], alfabet):
|
||||
print(
|
||||
f"ERROR - state {state} doesn't match: {states[state]} | {alfabet} | diff - {find_missing_letters(states[state], alfabet)}"
|
||||
)
|
||||
exit(-1)
|
||||
|
||||
|
||||
with open(join_path(sys.argv[2]), "r", newline="", encoding="utf8") as csvfile:
|
||||
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
|
||||
test_in = list(filereader)
|
||||
|
||||
with open(join_path(sys.argv[3]), "r", newline="", encoding="utf8") as csvfile:
|
||||
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
|
||||
test_out = list(filereader)
|
||||
|
||||
|
||||
is_difference = []
|
||||
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", word, end="")
|
||||
is_difference.append(i)
|
||||
else:
|
||||
print("NO\t", end="")
|
||||
if "NO" != test_out[i][0]:
|
||||
print("ERROR", word, end="")
|
||||
is_difference.append(i)
|
||||
print()
|
||||
|
||||
if len(is_difference) != 0:
|
||||
print(is_difference)
|
@ -1,22 +0,0 @@
|
||||
0 1 o
|
||||
1 2 p
|
||||
2 3 h
|
||||
3 4 e
|
||||
4 5 l
|
||||
5 6 i
|
||||
6 7 a
|
||||
1 1 o
|
||||
2 1 o
|
||||
3 1 o
|
||||
4 1 o
|
||||
5 1 o
|
||||
6 1 o
|
||||
7 7 abcdefghijklmnopqrstuvwxyz
|
||||
0 0 abcdefghijklmnpqrstuvwxyz
|
||||
1 0 abcdefghijklmnqrstuvwxyz
|
||||
2 0 abcdefgijklmnpqrstuvwxyz
|
||||
3 0 abcdfghijklmnpqrstuvwxyz
|
||||
4 0 abcdefghijkmnpqrstuvwxyz
|
||||
5 0 abcdefghjklmnpqrstuvwxyz
|
||||
6 0 bcdefghijklmnpqrstuvwxyz
|
||||
7
|
101
TaskB07/run.py
101
TaskB07/run.py
@ -1,101 +0,0 @@
|
||||
import sys
|
||||
import csv
|
||||
import os
|
||||
|
||||
from numpy import append
|
||||
|
||||
DIR = os.path.dirname(__file__)
|
||||
alfabet = "abcdefghijklmnopqrstuvwxyz "
|
||||
|
||||
|
||||
def join_path(filename: str) -> str:
|
||||
return os.path.join(DIR, filename)
|
||||
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
print("Default arguments parsed\n")
|
||||
sys.argv.append("fsa_description.arg")
|
||||
sys.argv.append("simple.in")
|
||||
sys.argv.append("simple.exp")
|
||||
|
||||
with open(join_path(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 = {}
|
||||
is_error = False
|
||||
for num, item in enumerate(fsa_description):
|
||||
for letter in item[2]:
|
||||
if letter not in alfabet:
|
||||
print("ERROR - letter not in alfabet: ", letter, "| line:", num + 1)
|
||||
exit(-1)
|
||||
if (int(item[0]), letter) in fsa_description_map:
|
||||
print("ERROR - duplicate letter:", letter, "| line:", num + 1)
|
||||
is_error = True
|
||||
tuple = (int(item[0]), letter)
|
||||
fsa_description_map[tuple] = int(item[1])
|
||||
|
||||
if is_error:
|
||||
exit(-1)
|
||||
|
||||
states = {}
|
||||
for item in fsa_description_map:
|
||||
states[item[0]] = states[item[0]] + item[1] if item[0] in states else item[1]
|
||||
|
||||
|
||||
from collections import Counter
|
||||
|
||||
|
||||
# check if all letters are used once
|
||||
def is_permutation(str1, str2):
|
||||
return Counter(str1) == Counter(str2)
|
||||
|
||||
|
||||
def find_missing_letters(str1, str2) -> str:
|
||||
missing_letters = ""
|
||||
for char in str2:
|
||||
if char not in str1:
|
||||
missing_letters += char
|
||||
return missing_letters
|
||||
|
||||
|
||||
for state in states:
|
||||
if not is_permutation(states[state], alfabet):
|
||||
print(
|
||||
f"ERROR - state {state} doesn't match: {states[state]} | {alfabet} | diff - {find_missing_letters(states[state], alfabet)}"
|
||||
)
|
||||
exit(-1)
|
||||
|
||||
|
||||
with open(join_path(sys.argv[2]), "r", newline="", encoding="utf8") as csvfile:
|
||||
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
|
||||
test_in = list(filereader)
|
||||
|
||||
with open(join_path(sys.argv[3]), "r", newline="", encoding="utf8") as csvfile:
|
||||
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
|
||||
test_out = list(filereader)
|
||||
|
||||
|
||||
is_difference = []
|
||||
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", word, end="")
|
||||
is_difference.append(i)
|
||||
else:
|
||||
print("NO\t", end="")
|
||||
if "NO" != test_out[i][0]:
|
||||
print("ERROR", word, end="")
|
||||
is_difference.append(i)
|
||||
print()
|
||||
|
||||
if len(is_difference) != 0:
|
||||
print(is_difference)
|
@ -1,19 +0,0 @@
|
||||
0 1 j
|
||||
1 2 u
|
||||
2 3 l
|
||||
3 4 i
|
||||
4 5 e
|
||||
5 6 t
|
||||
1 1 j
|
||||
2 1 j
|
||||
3 1 j
|
||||
4 1 j
|
||||
5 1 j
|
||||
6 6 abcdefghijklmnopqrstuvwxyz
|
||||
0 0 abcdefghiklmnopqrstuvwxyz
|
||||
1 0 abcdefghiklmnopqrstvwxyz
|
||||
2 0 abcdefghikmnopqrstuvwxyz
|
||||
3 0 abcdefghklmnopqrstuvwxyz
|
||||
4 0 abcdfghiklmnopqrstuvwxyz
|
||||
5 0 abcdefghiklmnopqrsuvwxyz
|
||||
6
|
101
TaskB08/run.py
101
TaskB08/run.py
@ -1,101 +0,0 @@
|
||||
import sys
|
||||
import csv
|
||||
import os
|
||||
|
||||
from numpy import append
|
||||
|
||||
DIR = os.path.dirname(__file__)
|
||||
alfabet = "abcdefghijklmnopqrstuvwxyz "
|
||||
|
||||
|
||||
def join_path(filename: str) -> str:
|
||||
return os.path.join(DIR, filename)
|
||||
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
print("Default arguments parsed\n")
|
||||
sys.argv.append("fsa_description.arg")
|
||||
sys.argv.append("simple.in")
|
||||
sys.argv.append("simple.exp")
|
||||
|
||||
with open(join_path(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 = {}
|
||||
is_error = False
|
||||
for num, item in enumerate(fsa_description):
|
||||
for letter in item[2]:
|
||||
if letter not in alfabet:
|
||||
print("ERROR - letter not in alfabet: ", letter, "| line:", num + 1)
|
||||
exit(-1)
|
||||
if (int(item[0]), letter) in fsa_description_map:
|
||||
print("ERROR - duplicate letter:", letter, "| line:", num + 1)
|
||||
is_error = True
|
||||
tuple = (int(item[0]), letter)
|
||||
fsa_description_map[tuple] = int(item[1])
|
||||
|
||||
if is_error:
|
||||
exit(-1)
|
||||
|
||||
states = {}
|
||||
for item in fsa_description_map:
|
||||
states[item[0]] = states[item[0]] + item[1] if item[0] in states else item[1]
|
||||
|
||||
|
||||
from collections import Counter
|
||||
|
||||
|
||||
# check if all letters are used once
|
||||
def is_permutation(str1, str2):
|
||||
return Counter(str1) == Counter(str2)
|
||||
|
||||
|
||||
def find_missing_letters(str1, str2) -> str:
|
||||
missing_letters = ""
|
||||
for char in str2:
|
||||
if char not in str1:
|
||||
missing_letters += char
|
||||
return missing_letters
|
||||
|
||||
|
||||
for state in states:
|
||||
if not is_permutation(states[state], alfabet):
|
||||
print(
|
||||
f"ERROR - state {state} doesn't match: {states[state]} | {alfabet} | diff - {find_missing_letters(states[state], alfabet)}"
|
||||
)
|
||||
exit(-1)
|
||||
|
||||
|
||||
with open(join_path(sys.argv[2]), "r", newline="", encoding="utf8") as csvfile:
|
||||
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
|
||||
test_in = list(filereader)
|
||||
|
||||
with open(join_path(sys.argv[3]), "r", newline="", encoding="utf8") as csvfile:
|
||||
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
|
||||
test_out = list(filereader)
|
||||
|
||||
|
||||
is_difference = []
|
||||
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", word, end="")
|
||||
is_difference.append(i)
|
||||
else:
|
||||
print("NO\t", end="")
|
||||
if "NO" != test_out[i][0]:
|
||||
print("ERROR", word, end="")
|
||||
is_difference.append(i)
|
||||
print()
|
||||
|
||||
if len(is_difference) != 0:
|
||||
print(is_difference)
|
@ -1,22 +0,0 @@
|
||||
0 1 m
|
||||
1 2 a
|
||||
2 3 c
|
||||
3 4 b
|
||||
4 5 e
|
||||
5 6 t
|
||||
6 7 h
|
||||
1 1 m
|
||||
2 1 m
|
||||
3 1 m
|
||||
4 1 m
|
||||
5 1 m
|
||||
6 1 m
|
||||
7 7 abcdefghijklmnopqrstuvwxyz
|
||||
0 0 abcdefghijklnopqrstuvwxyz
|
||||
1 0 bcdefghijklnopqrstuvwxyz
|
||||
2 0 abdefghijklnopqrstuvwxyz
|
||||
3 0 acdefghijklnopqrstuvwxyz
|
||||
4 0 abcdfghijklnopqrstuvwxyz
|
||||
5 0 abcdefghijklnopqrsuvwxyz
|
||||
6 0 abcdefgijklnopqrstuvwxyz
|
||||
7
|
101
TaskB09/run.py
101
TaskB09/run.py
@ -1,101 +0,0 @@
|
||||
import sys
|
||||
import csv
|
||||
import os
|
||||
|
||||
from numpy import append
|
||||
|
||||
DIR = os.path.dirname(__file__)
|
||||
alfabet = "abcdefghijklmnopqrstuvwxyz "
|
||||
|
||||
|
||||
def join_path(filename: str) -> str:
|
||||
return os.path.join(DIR, filename)
|
||||
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
print("Default arguments parsed\n")
|
||||
sys.argv.append("fsa_description.arg")
|
||||
sys.argv.append("simple.in")
|
||||
sys.argv.append("simple.exp")
|
||||
|
||||
with open(join_path(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 = {}
|
||||
is_error = False
|
||||
for num, item in enumerate(fsa_description):
|
||||
for letter in item[2]:
|
||||
if letter not in alfabet:
|
||||
print("ERROR - letter not in alfabet: ", letter, "| line:", num + 1)
|
||||
exit(-1)
|
||||
if (int(item[0]), letter) in fsa_description_map:
|
||||
print("ERROR - duplicate letter:", letter, "| line:", num + 1)
|
||||
is_error = True
|
||||
tuple = (int(item[0]), letter)
|
||||
fsa_description_map[tuple] = int(item[1])
|
||||
|
||||
if is_error:
|
||||
exit(-1)
|
||||
|
||||
states = {}
|
||||
for item in fsa_description_map:
|
||||
states[item[0]] = states[item[0]] + item[1] if item[0] in states else item[1]
|
||||
|
||||
|
||||
from collections import Counter
|
||||
|
||||
|
||||
# check if all letters are used once
|
||||
def is_permutation(str1, str2):
|
||||
return Counter(str1) == Counter(str2)
|
||||
|
||||
|
||||
def find_missing_letters(str1, str2) -> str:
|
||||
missing_letters = ""
|
||||
for char in str2:
|
||||
if char not in str1:
|
||||
missing_letters += char
|
||||
return missing_letters
|
||||
|
||||
|
||||
for state in states:
|
||||
if not is_permutation(states[state], alfabet):
|
||||
print(
|
||||
f"ERROR - state {state} doesn't match: {states[state]} | {alfabet} | diff - {find_missing_letters(states[state], alfabet)}"
|
||||
)
|
||||
exit(-1)
|
||||
|
||||
|
||||
with open(join_path(sys.argv[2]), "r", newline="", encoding="utf8") as csvfile:
|
||||
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
|
||||
test_in = list(filereader)
|
||||
|
||||
with open(join_path(sys.argv[3]), "r", newline="", encoding="utf8") as csvfile:
|
||||
filereader = csv.reader(csvfile, delimiter="\t", quotechar="|")
|
||||
test_out = list(filereader)
|
||||
|
||||
|
||||
is_difference = []
|
||||
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", word, end="")
|
||||
is_difference.append(i)
|
||||
else:
|
||||
print("NO\t", end="")
|
||||
if "NO" != test_out[i][0]:
|
||||
print("ERROR", word, end="")
|
||||
is_difference.append(i)
|
||||
print()
|
||||
|
||||
if len(is_difference) != 0:
|
||||
print(is_difference)
|
Loading…
Reference in New Issue
Block a user