반응형
반응형

[python] sudoku 만들기 - 랜덤 문제 

#sudoku puzzle create using python chatGPT
import random

def generate_solved_sudoku():
    base  = 3
    side  = base*base
    # pattern for a baseline valid solution
    def pattern(r,c): return (base*(r%base)+r//base+c)%side

    # randomize rows, columns and numbers (of valid base pattern)
    def shuffle(s): return random.sample(s,len(s)) 
    rBase = range(base) 
    rows  = [ g*base + r for g in shuffle(rBase) for r in shuffle(rBase) ] 
    cols  = [ g*base + c for g in shuffle(rBase) for c in shuffle(rBase) ]
    nums  = shuffle(range(1,base*base+1))

    # produce board using randomized baseline pattern
    board = [ [nums[pattern(r,c)] for c in cols] for r in rows ]
    
    return board

def print_sudoku(board):
    for i in range(9):
        if i % 3 == 0 and i != 0:
            print("- - - - - - - - - - - -")
        for j in range(9):
            if j % 3 == 0 and j != 0:
                print("|", end=" ")
            print(board[i][j], end=" ")
        print()

def remove_numbers(board, difficulty_level):
    """
    Remove numbers from the solved Sudoku grid based on the difficulty level.
    """
    if difficulty_level == 'easy':
        num_to_remove = 30  # Easy: 30 numbers removed
    elif difficulty_level == 'medium':
        num_to_remove = 40  # Medium: 40 numbers removed
    else:
        num_to_remove = 50  # Hard: 50 numbers removed
    
    for _ in range(num_to_remove):
        row = random.randint(0, 8)
        col = random.randint(0, 8)
        if board[row][col] != 0:
            board[row][col] = 0

# Generate a solved Sudoku puzzle
solved_sudoku = generate_solved_sudoku()

# Print the solved Sudoku puzzle
print("Solved Sudoku Puzzle:")
print_sudoku(solved_sudoku)

# Create a copy of the solved puzzle
unsolved_sudoku = [row[:] for row in solved_sudoku]

# Remove numbers to create a puzzle
difficulty_level = 'medium'  # Change difficulty level as needed ('easy', 'medium', 'hard')
remove_numbers(unsolved_sudoku, difficulty_level)

# Print the unsolved Sudoku puzzle (the generated puzzle)
print("\nUnsolved Sudoku Puzzle:")
print_sudoku(unsolved_sudoku)
반응형

'프로그래밍 > Python' 카테고리의 다른 글

[python] 알고리즘 - 탐색  (0) 2023.09.27
[python] 알고리즘 - 정렬  (0) 2023.09.27
[python] sudoku 만들기  (0) 2023.09.27
[python] How to send text messages with Python for Free  (0) 2023.09.26
[python] algorithm, 알고리즘  (0) 2023.09.20
반응형

# sudoku using python

def is_valid_move(board, row, col, num):
    """
    Check if placing 'num' at position (row, col) is a valid move.
    """
    # Check the row
    if num in board[row]:
        return False

    # Check the column
    if num in [board[i][col] for i in range(9)]:
        return False

    # Check the 3x3 subgrid
    start_row, start_col = 3 * (row // 3), 3 * (col // 3)
    for i in range(start_row, start_row + 3):
        for j in range(start_col, start_col + 3):
            if board[i][j] == num:
                return False

    return True

def solve_sudoku(board):
    """
    Solve the Sudoku puzzle using backtracking.
    """
    empty_cell = find_empty_cell(board)

    if not empty_cell:
        # Puzzle is solved
        return True

    row, col = empty_cell

    for num in range(1, 10):
        if is_valid_move(board, row, col, num):
            board[row][col] = num

            if solve_sudoku(board):
                return True

            # If the current placement doesn't lead to a solution, backtrack
            board[row][col] = 0

    # No valid move found, need to backtrack
    return False

def find_empty_cell(board):
    """
    Find an empty cell in the Sudoku grid.
    """
    for i in range(9):
        for j in range(9):
            if board[i][j] == 0:
                return (i, j)
    return None

def print_board(board):
    """
    Print the Sudoku grid.
    """
    for i in range(9):
        if i % 3 == 0 and i != 0:
            print("- - - - - - - - - - - -")
        for j in range(9):
            if j % 3 == 0 and j != 0:
                print("|", end=" ")
            print(board[i][j], end=" ")
        print()

# Example Sudoku puzzle (0 represents empty cells)
sudoku_board = [
    [5, 3, 0, 0, 7, 0, 0, 0, 0],
    [6, 0, 0, 1, 9, 5, 0, 0, 0],
    [0, 9, 8, 0, 0, 0, 0, 6, 0],
    [8, 0, 0, 0, 6, 0, 0, 0, 3],
    [4, 0, 0, 8, 0, 3, 0, 0, 1],
    [7, 0, 0, 0, 2, 0, 0, 0, 6],
    [0, 6, 0, 0, 0, 0, 2, 8, 0],
    [0, 0, 0, 4, 1, 9, 0, 0, 5],
    [0, 0, 0, 0, 8, 0, 0, 7, 9]
]

print("Sudoku Puzzle:")
print_board(sudoku_board)
print("\nSolving...\n")

if solve_sudoku(sudoku_board):
    print("Sudoku Solution:")
    print_board(sudoku_board)
else:
    print("No solution exists.")
반응형
반응형

스도쿠 게임

https://sudoku.com/ko

 

지금 무료 스도쿠 퍼즐을 즐겨보세요!

스도쿠의 목표는 9×9 격자를 숫자로 채워, 각 행과 열과 3×3구역이 1에서 9까지의 숫자 모두를 포함하도록 하는 것입니다. 게임을 시작하면, 9×9 격자의 몇몇 칸은 채워져 있습니다. 당신이 해야

sudoku.com

https://sudoku.com/ko/challenges/il-il-seudoku

 

일일 스도쿠 – 따끈따끈한 무료 퍼즐을 언제든지

일일 스도쿠 스도쿠는 전 세계적으로 가장 유명한 클래식 게임 중 하나입니다. 매일 수백만 명의 사람들이 이 퍼즐을 풀고 있죠! 스도쿠 게임의 이점을 생각하면 놀라운 사실은 아닙니다. 스도

sudoku.com

반응형
반응형

사용 중인 VScode 확장프로그램 공유합니다. 

https://marketplace.visualstudio.com/vscode

Classic ASP Syntaxes and Snippets
 https://marketplace.visualstudio.com/items?itemName=jtjoo.classic-asp-html 

Color Highlight
 https://marketplace.visualstudio.com/items?itemName=naumovs.color-highlight 

Javascript (ES6) code snippets
 https://marketplace.visualstudio.com/items?itemName=xabikos.JavaScriptSnippets 

Korean Language pack for Visual Studio Code
 https://marketplace.visualstudio.com/items?itemName=MS-CEINTL.vscode-language-pack-ko 

Material Icon Theme
 https://marketplace.visualstudio.com/items?itemName=PKief.material-icon-theme 

Material Theme
 https://marketplace.visualstudio.com/items?itemName=Equinusocio.vsc-material-theme 

Peacock
 https://marketplace.visualstudio.com/items?itemName=johnpapa.vscode-peacock 

Prettier - Color formatter
 https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode 

saveBackup
 https://marketplace.visualstudio.com/items?itemName=purplestone.savebackup 

반응형
반응형

My Visual Studio Code Setup | 2023

https://medium.com/@piyushyadav0191/my-visual-studio-code-setup-2023-2af8d36a5118

 

My Visual Studio Code Setup | 2023

Visual Studio Code, also known as VS Code, is a free and open-source code editor developed by Microsoft that has taken the developer world…

medium.com

created with 

Visual Studio Code, also known as VS Code, is a free and open-source code editor developed by Microsoft that has taken the developer world by storm. With its sleek interface, extensive customization options, and a vast array of extensions, VS Code has quickly become the go-to choice for developers looking to streamline their workflow and boost productivity. Whether you’re a seasoned developer or just starting out, VS Code is a tool you won’t want to miss.

Topics which I will be talking about

  • My setting Config
  • My Theme
  • My Extensions
  • Surprise

My Setting Config

VS Code settings JSON config includes a variety of configurations to customize your coding experience.

Tip:- You can customize your settings.json file by typing Ctrl + Shift + P, and then typing ‘User Settings’.

{
  "workbench.colorTheme": "Vim Deep Dark", // My Theme
  "workbench.iconTheme": "material-icon-theme", // My Icon Theme
  "editor.fontFamily": "Fira Code", // My Font
  "editor.fontSize": 19, // Font size
  "editor.minimap.enabled": false, // disabled minimap
  "editor.fontLigatures": true, // enabled ligatures
  "editor.formatOnPaste": true, // text will format on pasting the code
  "editor.formatOnSave": true, // text will format if you hit ctrl + S
  "editor.defaultFormatter": "esbenp.prettier-vscode", // formatter 
  "terminal.integrated.fontFamily": "MesloLGS Nerd Font", // terminal font to use icons
  "debug.terminal.clearBeforeReusing": true,// clears your debug terminal before using
  "terminal.integrated.fontSize": 19, // terminal font size
}

How it looks like in VS code

My Theme

Well, if you have read my configuration, then you should already know the name of the theme I am using

Vim Theme

Demo

Vim theme

Apart from this theme, I like to use Andromeda Mariana — Italic

Second Theme demo

Andromeda Mariana

My Extensions

Visual Studio Code (VS Code) is a popular code editor that offers a range of extensions to enhance its functionality. VS Code extensions are add-ons that provide additional features and capabilities to the editor, such as new language support, code snippets, syntax highlighting, debugging tools, and more.

Prisma

Prisma

Only for DATABASE USERS :- Adds syntax highlighting, formatting, auto-completion, jump-to-definition and linting for .prisma files.

MDX

MDX

Language support for MDX

Prettier

Prettier- Code formatter

Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.

Material Icon Theme

Material Icon Theme

Material Design Icons for Visual Studio Code

ES7 Support

ES7

Extensions for React, React-Native and Redux in JS/TS with ES7+ syntax. Customizable. Built-in integration with prettier.

Color Highlight

Color Highlighter

This extension styles css/web colors found in your document.

Github Copilot

Copilot

GitHub Copilot provides autocomplete-style suggestions from an AI pair programmer as you code. You can receive suggestions from GitHub Copilot either by starting to write the code you want to use, or by writing a natural language comment describing what you want the code to do.

Surprise

“Breaking the Norm: Why I swapped VS Code for Vim and never looked back!”

vim

The File Explorer structure that you are seeing is a Tree View lua plugin which is fabulous, and I am able to code faster than ever using shortcuts.

 
반응형
반응형

How to send text messages with Python for Free

https://medium.com/testingonprod/how-to-send-text-messages-with-python-for-free-a7c92816e1a4

 

How to send text messages with Python for Free

This week, I am going to be showing you how to send text messages with Python for free. It’s actually surprisingly easy to do and I thought…

medium.com

What you’ll need

For this post, I’ll be using the following:

It should be noted that if you’re using gmail, like me, you’ll need to setup and use an application password with your account. You can read more information and security warnings on that here: https://support.google.com/accounts/answer/185833?p=InvalidSecondFactor&visit_id=637700239874464736-1954441174&rd=1

import smtplib
import sys
 
CARRIERS = {
    "att": "@mms.att.net",
    "tmobile": "@tmomail.net",
    "verizon": "@vtext.com",
    "sprint": "@messaging.sprintpcs.com"
}
 
EMAIL = "EMAIL"
PASSWORD = "PASSWORD"
 
def send_message(phone_number, carrier, message):
    recipient = phone_number + CARRIERS[carrier]
    auth = (EMAIL, PASSWORD)
 
    server = smtplib.SMTP("smtp.gmail.com", 587)
    server.starttls()
    server.login(auth[0], auth[1])
 
    server.sendmail(auth[0], recipient, message)
 
 
if __name__ == "__main__":
    if len(sys.argv) < 4:
        print(f"Usage: python3 {sys.argv[0]} <PHONE_NUMBER> <CARRIER> <MESSAGE>")
        sys.exit(0)
 
    phone_number = sys.argv[1]
    carrier = sys.argv[2]
    message = sys.argv[3]
 
    send_message(phone_number, carrier, message)
반응형

'프로그래밍 > Python' 카테고리의 다른 글

[python] sudoku 만들기 - 랜덤 문제  (0) 2023.09.27
[python] sudoku 만들기  (0) 2023.09.27
[python] algorithm, 알고리즘  (0) 2023.09.20
[python] GUI 비밀번호 자동 생성기  (0) 2023.09.18
[python] pyperclip  (0) 2023.09.18

+ Recent posts