This commit is contained in:
Михаил Капелько
2024-04-01 22:59:43 +03:00
parent 110b44030d
commit 4122ffd816
4 changed files with 50 additions and 10 deletions

View File

@@ -0,0 +1,36 @@
// L4: Function.
std::map<int, int> memory_generateConstPlayfield(n: int) {
idGroups: std::map<int, int> = { }
id = 0
for gid in range(0, n):
idGroups[id] = gid
id += 1
idGroups[id] = gid
id += 1
}
return idGroups
}
// L20: Test.
str test_memory_generateConstPlayfield() {
idGroups = memory_generateConstPlayfield(2)
if (
len(idGroups) == 4 and
idGroups[0] == 0 and
idGroups[1] == 0 and
idGroups[2] == 1 and
idGroups[3] == 1
):
return "OK: memory_generateConstPlayfield"
}
return "ERR: memory_generateConstPlayfield"
}
// L36: Run.
print(test_memory_generateConstPlayfield())

View File

@@ -3,9 +3,7 @@
// L4: Function.
std::map<int, int> memory_generateConstPlayfield(
int n
) {
std::map<int, int> memory_generateConstPlayfield(int n) {
std::map<int, int> idGroups;
auto id = 0;
for (auto gid = 0; gid < n; ++gid) {

View File

@@ -1,10 +1,4 @@
IN=main.py
OUT=main-2.cpp
# Simple check. TODO REMOVE later
sed 's|# L4: Function.|// L4: Function.|' $IN > $OUT
# dict[X, Y] -> std::map<X, Y>
sed -E 's|dict\[(.*), (.*)\]|std::map<\1, \2>|' $IN > $OUT
# def functionName(X) -> Y -> Y functionName(X) {
sed -E 's|def (.*) -> (.*):|\2 \1 {|' $OUT > $OUT
sed -Ef sed.pythonToC++ <$IN >$OUT

12
sed.pythonToC++ Normal file
View File

@@ -0,0 +1,12 @@
# #} -> }
s|#}|}|
# # -> //
s|#|//|
# dict[X, Y] -> std::map<X, Y>
s_dict\[(.*), (.*)\]_std::map<\1, \2>_
# def functionName(X) -> Y -> Y functionName(X) {
s|def (.*) -> (.*):|\2 \1 {|