A Python script to populate MVSM sudoku instances

Life in America

A Python script to populate MVSM sudoku instances

2016年11月21日 技术或者看起来像技术 0

I have originally wrote this script for my own use, but now I’ve decided to share it in case someone need it as well. It will first ask for the size of sudoku puzzle, then prompt you for numerical value in each cell. Hit Enter to skip the empty cell. Voila! The data is now ready to be copied and used in MVSM.

There is no type check at all. That means if you enter, say, a period (.), the whole program will crash and you will lose all data you entered thus far.

Here’s the code, feel free to improve it on your own

# Helper function for generating sudoku instances
# By X. Lin, CSE 294

dim = int(input("Enter the dimension of the sudoku puzzle (# of rows or columns): ")) + 1
print()

table = [[0 for x in range(dim)] for y in range(dim)]
for row in range(1, dim):
    for col in range(1, dim):
        print("Enter the value for cell a(", row, ",", col, ").\n",
              "Hit Enter key directly when no number is present for the given cell: ", sep="")
        val = input()
        print()
        if not val:
            continue
        table[row][col] = int(val)

for row in range(1, dim):
    for col in range(1, dim):
        val = table[row][col]
        if val == 0:
            continue
        print("a(", row, ",", col, ")=", val, ".", sep="", end=" ")
    print()
sudoku-helper
Lin
Follow me at

Lin

博主 at Lin's Treasure
博主真身,目前运维 Lin's Treasure 以及附属的 LTTN。纯属一介普通人,对高技只会操不会做。能熟练开关电脑、敲打电视、弄砸考试云云。目前暂居(大误)万恶之源美帝,深感国内射秽主义大法好。爱前沿CE,爱音乐,爱游泳,爱游戏,爱折腾。资深安卓粉和肠粉。编程菜鸟。若有不足,敬请指教ww
Lin
Follow me at

Latest posts by Lin (see all)

 

说点什么

尚无评论。赶紧抢沙发吧!

avatar
10000
  Subscribe  
订阅