#!/bin/bash result=( 0 0 0 0 0 0 0 0 0 ) function runit () { init 0 0 } function init () { local col=$1 local row=$2 otestuj $col $row tst=$? if [ 0 -eq $tst ]; then return fi result[$row]=$col if [ $row -eq 8 ]; then napisReseni return fi local dalsi=$((row+1)) init 1 $dalsi init 2 $dalsi init 3 $dalsi init 4 $dalsi init 5 $dalsi init 6 $dalsi init 7 $dalsi init 8 $dalsi } function otestuj () { local col=$1 local row=$2 if [ $row -eq 1 ]; then return 1 fi local plus=1 local tmp=0 local i=$((row-1)) while [ $i -gt 0 ]; do if [ $col -eq ${result[$i]} ]; then return 0 fi tmp=$((col+plus)) if [ $tmp -eq ${result[$i]} ]; then return 0 fi tmp=$((col-plus)) if [ $tmp -eq ${result[$i]} ]; then return 0 fi plus=$((plus+1)) i=$((i-1)) done return 1 } function napisReseni { echo ${result[@]} } runit