t.santoni 2 months ago
parent
commit
d44bedafd3
  1. 75
      2022/02.awk/02.awk

75
2022/02.awk/02.awk

@ -0,0 +1,75 @@ @@ -0,0 +1,75 @@
BEGIN {
sout[1] = "rock"
sout[2] = "paper"
sout[3] = "scissors"
map["A"] = 1
map["B"] = 2
map["C"] = 3
map["X"] = 0
map["Y"] = 3
map["Z"] = 6
table[1,1] = 3
table[1,2] = 6
table[1,3] = 0
table[2,2] = 3
table[2,1] = 0
table[2,3] = 6
table[3,3] = 3
table[3,1] = 6
table[3,2] = 0
sum = 0
r = 0
}
function tic_tac_toe(f, s, map, table) {
mf = ""
ms = ""
# print "f: " f, map[f]
# print "s: " s, map[s]
if( (map[f] != "") && (map[s] != "")) {
mf = map[f]
ms = map[s]
return table[mf,ms]
}
return 0
}
function tic_tac_toe_prev(f, s, map, table) {
mf = ""
ms = ""
# print "f: " f, map[f]
# print "s: " s, map[s]
res = -1
if( (map[f] != "") && (map[s] != "")) {
mf = map[f]
ms = map[s]
for(i = 1; i <= 3; i++) {
if(res == -1) {
if(table[mf,i] == ms) {
res = table[mf,i] + i
# print "m>",f,s,mf,i,ms,res
}
}
}
return res
}
return -1
}
{
r = tic_tac_toe_prev($1, $2, map, table)
# print sout[map[$1]] " " sout[map[$2]] ": " r
sum += r
}
END {
print sum
}
Loading…
Cancel
Save