Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963

    Thumbs up Sudoku Solver for Mainframe users

    Same rules as for Windows users:

    One query solve any level of Sudoku in seconds.

    The query is ready to run in SPUFI, or another Mainframe applications.

    ================================================== ==

    1. Fill up the Source table, where "0" for unknown cells of Sudoku.

    Source (line, sudoku_str) as
    (
    select 1, '041705098'
    from sysibm.sysdummy1
    union all
    select 2, '050308000'
    from sysibm.sysdummy1
    union all
    select 3, '000040000'
    from sysibm.sysdummy1
    union all
    select 4, '205000031'
    from sysibm.sysdummy1
    union all
    select 5, '900000005'
    from sysibm.sysdummy1
    union all
    select 6, '170000802'
    from sysibm.sysdummy1
    union all
    select 7, '000030000'
    from sysibm.sysdummy1
    union all
    select 8, '000107020'
    from sysibm.sysdummy1
    union all
    select 9, '410602750'
    from sysibm.sysdummy1
    )
    2. After you finish with Source table, Run the query

    3. All you can find in the attachment.

    ================================================== ==


    Thanks. Lenny
    Attached Files Attached Files
    Last edited by Lenny77; 06-29-12 at 13:01.

  2. #2
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963

    Exclamation Hello DB2 Forum

    Hi Michael and Eugene.

    Join me on DB2 Forum !

    Lenny

  3. #3
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963

    Wink This Solver is working in Windows as well as Mainframe

    Yes. This Solver is working everywhere.

    I just changed the width of the line because the mainframe line width
    not exceeding 80 characters.

    Lenny

  4. #4
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963
    HAPPY GURU PURNIMA for ALL of you and Independent Day, too !

    Lenny

  5. #5
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963

    Thumbs up About stopper and how they are improve performance

    I found somewhere this very high level Sudoku:

    Code:
    Source (line, sudoku_str) as
      (
      select 1, '800000000'
        from sysibm.sysdummy1
      union all
      select 2, '003600000'
        from sysibm.sysdummy1
      union all
      select 3, '070090200'
        from sysibm.sysdummy1
      union all
      select 4, '050007000'
        from sysibm.sysdummy1
      union all
      select 5, '000045700'
        from sysibm.sysdummy1
      union all
      select 6, '000100030'
        from sysibm.sysdummy1
      union all
      select 7, '001000068'
        from sysibm.sysdummy1
      union all
      select 8, '008500010'
        from sysibm.sysdummy1
      union all
      select 9, '090000400'
        from sysibm.sysdummy1
      )
    The result

    Sudoku Solution
    Line 1: | 8 | 1 | 2 | 7 | 5 | 3 | 6 | 4 | 9 |
    Line 2: | 9 | 4 | 3 | 6 | 8 | 2 | 1 | 7 | 5 |
    Line 3: | 6 | 7 | 5 | 4 | 9 | 1 | 2 | 8 | 3 |
    Line 4: | 1 | 5 | 4 | 2 | 3 | 7 | 8 | 9 | 6 |
    Line 5: | 3 | 6 | 9 | 8 | 4 | 5 | 7 | 2 | 1 |
    Line 6: | 2 | 8 | 7 | 1 | 6 | 9 | 5 | 3 | 4 |
    Line 7: | 5 | 2 | 1 | 9 | 7 | 4 | 3 | 6 | 8 |
    Line 8: | 4 | 3 | 8 | 5 | 2 | 6 | 9 | 1 | 7 |
    Line 9: | 7 | 9 | 6 | 3 | 1 | 8 | 4 | 5 | 2 |
    I have got spending more than 4 minutes (!).

    I was shocked, because usually Solver spend the seconds.

    I guess what really happened.
    The Solver does not stop after it found the first solved Sudoku.

    I found the easiest solution of the problem:
    We have to add only one short sentence to our solver, which will stop execution on the first found solution.

    This sentence is "Fetch First Row Only".
    We have to put it in the right place, that it.

    Code:
    with
      Source (line, sudoku_str) as
      (
      select 1, '800000000'
        from sysibm.sysdummy1
    ....
    ....
    ....
      ) SL9 
    Fetch First Row Only  ) ii
    )
    select line_1 "Sudoku Solution" 
    from sud_solution_tbl  
    ....
    ....
    ....
    union all
    select line_9 "Sudoku Solution" from sud_solution_tbl 
      ;
    Now we got the solution for this very hard Sudoku in 3 seconds.

    Lenny
    Last edited by Lenny77; 07-05-12 at 15:33.

  6. #6
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963
    I am going on Vacation in Scandinavia which has never been before.
    See all of you after 2 weeks.


    ! Bye-Bye !

    Yours Lenny
    Last edited by Lenny77; 07-07-12 at 09:09.

  7. #7
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963
    Vacation in Scandinavia was great !

    Now back to reality.

    Lenny

  8. #8
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963
    The reality also is not so bad. In NY hot and humid now. Yesterday the small hurricane was happened.

    Lenny

  9. #9
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963

    Wink Just one more solved by DB2 Sudoku

    Level-4 Sudoku, solved in 1 second.

    Code:
    Source (line, sudoku_str) as 
    (
    select 1, '072000000'
      from sysibm.sysdummy1
    union all
    select 2, '100680090'
      from sysibm.sysdummy1
    union all
    select 3, '003004000'
      from sysibm.sysdummy1
    union all 
    select 4, '010093080'
      from sysibm.sysdummy1
    union all
    select 5, '300000007'
      from sysibm.sysdummy1
    union all
    select 6, '054700010'
      from sysibm.sysdummy1
    union all
    select 7, '000400600'
      from sysibm.sysdummy1
    union all
    select 8, '030005041'
      from sysibm.sysdummy1
    union all
    select 9, '000000870'
      from sysibm.sysdummy1
    )
    Line 1: | 8 | 7 | 2 | 3 | 5 | 9 | 1 | 6 | 4 |
    Line 2: | 1 | 4 | 5 | 6 | 8 | 7 | 3 | 9 | 2 |
    Line 3: | 9 | 6 | 3 | 2 | 1 | 4 | 7 | 5 | 8 |
    Line 4: | 2 | 1 | 7 | 5 | 9 | 3 | 4 | 8 | 6 |
    Line 5: | 3 | 9 | 8 | 1 | 4 | 6 | 5 | 2 | 7 |
    Line 6: | 6 | 5 | 4 | 7 | 2 | 8 | 9 | 1 | 3 |
    Line 7: | 5 | 8 | 1 | 4 | 7 | 2 | 6 | 3 | 9 |
    Line 8: | 7 | 3 | 9 | 8 | 6 | 5 | 2 | 4 | 1 |
    Line 9: | 4 | 2 | 6 | 9 | 3 | 1 | 8 | 7 | 5 |
    Lenny

  10. #10
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963
    It's not a lot of people can understand how it works.
    Feel free to ask me questions about.

    Lenny

  11. #11
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963

    Wink One more Sudoku for Sudoku fans

    Code:
    Source (line, sudoku_str) as 
    (
    select 1, '007052609'
      from sysibm.sysdummy1
    union all
    select 2, '006000300'
      from sysibm.sysdummy1
    union all
    select 3, '000800001'
      from sysibm.sysdummy1
    union all 
    select 4, '400180003'
      from sysibm.sysdummy1
    union all
    select 5, '000000000'
      from sysibm.sysdummy1
    union all
    select 6, '700039005'
      from sysibm.sysdummy1
    union all
    select 7, '800005000'
      from sysibm.sysdummy1
    union all
    select 8, '004000800'
      from sysibm.sysdummy1
    union all
    select 9, '503690100'
      from sysibm.sysdummy1
    )
    The Result:

    Line 1: | 1 | 8 | 7 | 3 | 5 | 2 | 6 | 4 | 9 |
    Line 2: | 2 | 5 | 6 | 9 | 4 | 1 | 3 | 8 | 7 |
    Line 3: | 3 | 4 | 9 | 8 | 7 | 6 | 5 | 2 | 1 |
    Line 4: | 4 | 6 | 5 | 1 | 8 | 7 | 2 | 9 | 3 |
    Line 5: | 9 | 3 | 2 | 5 | 6 | 4 | 7 | 1 | 8 |
    Line 6: | 7 | 1 | 8 | 2 | 3 | 9 | 4 | 6 | 5 |
    Line 7: | 8 | 7 | 1 | 4 | 2 | 5 | 9 | 3 | 6 |
    Line 8: | 6 | 9 | 4 | 7 | 1 | 3 | 8 | 5 | 2 |
    Line 9: | 5 | 2 | 3 | 6 | 9 | 8 | 1 | 7 | 4 |
    Lenny

  12. #12
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963

    Wink Test

    Try to solve this Sudoku manually, then run my Solver and compare the solutions:


    Code:
    Source (line, sudoku_str) as 
    (
    select 1, '003509040'
      from sysibm.sysdummy1
    union all
    select 2, '000700006'
      from sysibm.sysdummy1
    union all
    select 3, '080000010'
      from sysibm.sysdummy1
    union all 
    select 4, '008907051'
      from sysibm.sysdummy1
    union all
    select 5, '206050809'
      from sysibm.sysdummy1
    union all
    select 6, '950608400'
      from sysibm.sysdummy1
    union all
    select 7, '060000090'
      from sysibm.sysdummy1
    union all
    select 8, '800004000'
      from sysibm.sysdummy1
    union all
    select 9, '020105700'
      from sysibm.sysdummy1
    )
    Solution:

    Line 1: | 6 | 1 | 3 | 5 | 8 | 9 | 2 | 4 | 7 |
    Line 2: | 5 | 4 | 2 | 7 | 1 | 3 | 9 | 8 | 6 |
    Line 3: | 7 | 8 | 9 | 2 | 4 | 6 | 5 | 1 | 3 |
    Line 4: | 4 | 3 | 8 | 9 | 2 | 7 | 6 | 5 | 1 |
    Line 5: | 2 | 7 | 6 | 4 | 5 | 1 | 8 | 3 | 9 |
    Line 6: | 9 | 5 | 1 | 6 | 3 | 8 | 4 | 7 | 2 |
    Line 7: | 1 | 6 | 5 | 8 | 7 | 2 | 3 | 9 | 4 |
    Line 8: | 8 | 9 | 7 | 3 | 6 | 4 | 1 | 2 | 5 |
    Line 9: | 3 | 2 | 4 | 1 | 9 | 5 | 7 | 6 | 8 |
    Thanks. Lenny

  13. #13
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963
    Hi Vishal ! It always nice to talk with you !

    Lenny

  14. #14
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963
    Congratulation with Great Indian Holiday !

    Lenny

  15. #15
    Join Date
    Aug 2008
    Location
    Toronto, Canada
    Posts
    2,361
    Quote Originally Posted by Lenny77 View Post
    Hi Michael and Eugene
    Quote Originally Posted by Lenny77 View Post
    Hi Vishal
    Are you talking to yourself...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •