by laumars · 10y ago · 0 comments
I was thinking more along the lines of using the one line conditional:
condition ? first_expression : second_expression;
eg sub nextq {
(print( "@_\n" ),return) if @_ == (my $size = 8);
foreach my $col(0..$size-1) {
my ($row, $next);
grep ($_ == $col, @_) ? $next=1 : $row=@_;
grep ($_ == $col-$row--, @_) ? $next=1 : $row=@_;
grep ($_ == $col+$row--, @_) ? $next=1 : $row=@_;
nextq(@_,$col) unless $next;
}
}
nextq();
The `$next` ugliness is due to not being allowed to use the `next` inside a one line conditional. There's probably cleaner ways of doing the above though. But that was only a quick hack.This sort of line counting is just for fun.
sub nextq {
my $sz=8;
(print("@_\n"),return) if @_ == $sz;
o: foreach my $col(0..$sz-1) {
my($u,$d)=(scalar(@_),scalar(@_));
for (@_) {next o if($_==$col or $_==$col-$u-- or $_==$col+$d--)}
nextq(@_,$col);
}
}
nextq();Nice code though.