#!/usr/bin/env perl @result = qw(0 0 0 0 0 0 0 0 0); &runit; sub runit { init(0,0); } sub init { my $col = @_[0]; my $row = @_[1]; my $test = &otestuj($col,$row); if ($test == 0) {return;} @result[$row] = $col; if ($row == 8) { &napisReseni; return; } my $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); } sub otestuj { my $col = @_[0]; my $row = @_[1]; if ($row == 1) {return 1;} my $plus = 1; my $tmp = 0; my $i = $row - 1; while ($i > 0) { if ($col == @result[$i]) {return 0;} $tmp = $col + $plus; if ($tmp == @result[$i]) {return 0;} $tmp = $col - $plus; if ($tmp == @result[$i]) {return 0;} $plus = $plus + 1; $i = $i - 1; } return 1; } sub napisReseni { $, = " "; print "@result[1,2,3,4,5,6,7,8]\n"; }