因此,我必须编写一个bash脚本来检查9×9“sudoku”解决方案是否有效,但简化的是我不必将其划分为3×3,而只是检查行和列是否包含任何重复的数字,以及有效数字仅为1-9 ..
这是我的想法,但无法让它工作:
#!/bin/bash
error="false"
count=0
#this would be for columns
#for i in 1 2 3 4 5 6 7 8 9
#do
#cat sudoku.txt | awk -F "" '{ print $'$i'}' | uniq -c | awk '$1 > 1 { count++ } END { print count }'
#done
#and this would be for rows
for i in 1 2 3 4 5 6 7 8 9
do
cat sudoku.txt | awk '{ print FNR=$'$i'}' | uniq -c |
awk '$1 > 1 { count++ } END { print count }' |
awk ' count > 0 { $error="true" } END { print $i }' |
awk '{ if ($error = "true") print "Wrong data!"; else print "Correct data!"; } '
done
最佳答案
$awk '
<