2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

数独難問に挑戦します。

Last updated at Posted at 2016-11-02

最近、数独にはまっています。
my codeを書いて、最難問に挑戦します。

問題の引用先

http://forum.enjoysudoku.com/the-hardest-sudokus-new-thread-t6539.html

package『sudoku』と my function と
スピード(実行時間)、正確さ(解けるかどうか)で
勝負してみます。
勝負の行方は?

問題Ⅰ

Rating Program: gsf's sudoku q1
Rating: 99529
Poster: eleven

 1 2 . | 4 . . | 3 . .  
 3 . . | . 1 . | . 5 .  
 . . 6 | . . . | 1 . .  
-------+-------+------ 
 7 . . | . 9 . | . . .  
 . 4 . | 6 . 3 | . . .  
 . . 3 | . . 2 | . . .  
-------+-------+------ 
 5 . . | . 8 . | 7 . .  
 . . 7 | . . . | . . 5  
 . . . | . . . | . 9 8  

package 『sudoku』

sudoku.r
library(sudoku)
# install.packages("sudoku")
system.time({
  solveSudoku(sudoku, verbose=TRUE)
})
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
 [1,]    1    2    8    4    6    5    3    7    9
 [2,]    3    7    4    2    1    9    8    5    6
 [3,]    9    5    6    8    3    7    1    4    2
 [4,]    7    6    5    1    9    8    4    2    3
 [5,]    2    4    9    6    7    3    5    8    1
 [6,]    8    1    3    5    4    2    9    6    7
 [7,]    5    9    2    3    8    6    7    1    4
 [8,]    4    8    7    9    2    1    6    3    5
 [9,]    6    3    1    7    5    4    2    9    8
   ユーザ   システム       経過  
     26.84       0.13      27.50 

my function

my_function.r
system.time({
  answer <- sudoku.solver(sudoku,3)
})
answer
   ユーザ   システム       経過  
      5.65       0.00       5.65 
> answer
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
 [1,]    1    2    8    4    6    5    3    7    9
 [2,]    3    7    4    2    1    9    8    5    6
 [3,]    9    5    6    8    3    7    1    4    2
 [4,]    7    6    5    1    9    8    4    2    3
 [5,]    2    4    9    6    7    3    5    8    1
 [6,]    8    1    3    5    4    2    9    6    7
 [7,]    5    9    2    3    8    6    7    1    4
 [8,]    4    8    7    9    2    1    6    3    5
 [9,]    6    3    1    7    5    4    2    9    8

問題Ⅱ

Rating Program: gsf's sudoku q2
Rating: 99743
Poster: eleven

 1 2 . | 3 . . | . . 4  
 3 5 . | . . . | 1 . .  
 . . 4 | . . . | . . .  
-------+-------+------ 
 . . 5 | 4 . . | 2 . .  
 6 . . | . 7 . | . . .  
 . . . | . . 8 | . 9 .  
-------+-------+------ 
 . . 3 | 1 . . | 5 . .  
 . . . | . . 9 | . 7 .  
 . . . | . 6 . | . . 8    

package 『sudoku』

sudoku.r
library(sudoku)
# install.packages("sudoku")
system.time({
  solveSudoku(sudoku, verbose=TRUE)
})
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
 [1,]    1    2    6    3    9    5    7    8    4
 [2,]    3    5    9    8    4    7    1    6    2
 [3,]    8    7    4    6    2    1    9    5    3
 [4,]    9    8    5    4    1    6    2    3    7
 [5,]    6    3    1    9    7    2    8    4    5
 [6,]    2    4    7    5    3    8    6    9    1
 [7,]    7    6    3    1    8    4    5    2    9
 [8,]    4    1    8    2    5    9    3    7    6
 [9,]    5    9    2    7    6    3    4    1    8
   ユーザ   システム       経過  
     37.59       0.05      38.24

my function

my_function.r
system.time({
  answer <- sudoku.solver(sudoku,3)
})
answer
   ユーザ   システム       経過  
      2.69       0.00       2.76 
> answer
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
 [1,]    1    2    6    3    9    5    7    8    4
 [2,]    3    5    9    8    4    7    1    6    2
 [3,]    8    7    4    6    2    1    9    5    3
 [4,]    9    8    5    4    1    6    2    3    7
 [5,]    6    3    1    9    7    2    8    4    5
 [6,]    2    4    7    5    3    8    6    9    1
 [7,]    7    6    3    1    8    4    5    2    9
 [8,]    4    1    8    2    5    9    3    7    6
 [9,]    5    9    2    7    6    3    4    1    8

結果

my function の圧勝です!!!

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?