Advertisement

12.07.2005 at 09:55AM PST, ID: 21656633
[x]
Attachment Details

Su DoKu Perl solution

Asked by geotiger in Perl Programming Language

Tags: perl, su

I recently got interested in Su DoKu solver. I am testing the three line solver by Edmund von der Burg. I could not understand why the R sub has to die out in order to get the final result. How could I keep the result and use it later?

You can read about the description of the solver at http://www.ecclestoad.co.uk/blog/.

Here is the code that I am testing:

#!/usr/local/bin/perl

use strict;
use warnings;
use Debug::EchoMessage;
my $self = bless {}, "main";
use integer;

# my @A = split //, <>;
my $q = "";
{local $/; $q = <DATA>; $q =~ s/\s+//g;}
my @A = split //, $q;
# $self->disp_param(\@A);

sub R {
    for my $i ( 0 .. 80 ) {
        next if $A[$i];
        my %t = map {
              $_ / 9 == $i / 9                     # for row
           || $_ % 9 == $i % 9                     # for column
           || $_ / 27 == $i/27 && $_%9/3 == $i%9/3 # for grid
              ? $A[$_]      # $t{$_} = $A[$_]
              : 0 => 1      # $t{0}  = 1
        } 0 .. 80;
        R( $A[$i] = $_ ) for grep { !$t{$_} } 1 .. 9;
# $self->disp_param(\@A);
my $j = "";
map {$j .= $A[$_] } 0..80;
print "$j\n";
        return $A[$i] = 0;
    }
    die @A;      ### WHY could I just return the result here??
}
R;
my $j = "";
map {$j .= $A[$_] } 0..80;
print "$j\n";


__DATA__
006075400
704921000
010080702
580007903
040000070
302090641
005030090
000102305
008750200

Start Free Trial
[+][-]12.07.2005 at 11:21AM PST, ID: 15439012

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.07.2005 at 11:54AM PST, ID: 15439272

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.07.2005 at 11:57AM PST, ID: 15439310

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.07.2005 at 12:08PM PST, ID: 15439401

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.07.2005 at 12:35PM PST, ID: 15439651

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]12.07.2005 at 12:42PM PST, ID: 15439691

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: perl, su
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 2
Solution Grade: A
 
 
[+][-]12.07.2005 at 01:01PM PST, ID: 15439852

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.07.2005 at 01:06PM PST, ID: 15439884

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.07.2005 at 01:08PM PST, ID: 15439899

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.07.2005 at 01:25PM PST, ID: 15440024

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32