Games

Hack World

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

Dec 24, 2024

The Google Willow thing https://scottaaronson.blog/?p=8525

https://www.quantamagazine.org/cryptographers-discover-a-new-foundation-for-quantum-secrecy-20240603/

https://www.quantamagazine.org/physicists-finally-find-a-problem-only-quantum-computers-can-do-20240312/

https://www.quantamagazine.org/magical-error-correction-scheme-proved-inherently-inefficient-20240109/


https://www.quantamagazine.org/how-chain-of-thought-reasoning-helps-neural-networks-compute-20240321/

https://www.quantamagazine.org/how-do-machines-grok-data-20240412/

https://dl.acm.org/doi/10.1145/3442188.3445922

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

https://www.quora.com/What-is-the-application-of-complex-analysis-in-engineering

Maybe the most basic application is the use of Methods of contour integration to evaluate difficult definite integrals.

Liouville's theorem (complex analysis) leads to one of the standard proofs of the Fundamental theorem of algebra.

Studying the Riemann zeta function is an important way to understand the primes: it leads to the Prime number theorem, the Riemann hypothesis, and more generally to a major part of Analytic number theory.

Modular forms are important in mathematics for several reasons, some of which can be found here: Modular Forms, A Computational Approach v0.1 documentation

Similarly, Elliptic functions are closely related both to the study of Elliptic curves and the study of modular forms.

Theta functions are related to both elliptic functions and modular forms, but they also have other applications. For example, they can be used to prove both Fermat's theorem on sums of two squares and Lagrange's four-square theorem.

Analytic continuation https://en.wikipedia.org/wiki/Analytic_continuation leads naturally to the study of Riemann surfaces, which is in turn a gateway to many other beautiful parts of mathematics, including but not limited to Galois theory, Algebraic geometry, Algebraic topology, Hyperbolic geometry, Teichmüller spaces, String theory ...

Complex analysis is used in Analytic combinatorics to analyze the asymptotic behavior of combinatorially defined sequences.

Complex analysis has several applications to the study of Banach algebras in Functional analysis; see, for example, Holomorphic functional calculus.


  1. Electrical Engineering

AC Circuit Analysis: Complex numbers simplify the analysis of alternating current (AC) circuits. Engineers use phasors (complex numbers representing sinusoidal functions) to analyze voltages and currents, making calculations easier.

Signal Processing: Techniques such as Fourier transforms, which utilize complex exponentials, are fundamental in analyzing and processing signals.

  1. Fluid Dynamics Potential Flow Theory: In fluid mechanics, complex potential functions are used to solve problems related to incompressible, irrotational flow. This allows for the analysis of flow patterns around objects, which is critical in aerodynamics and hydrodynamics.

  2. Control Systems Stability Analysis: The stability of control systems is often analyzed using the complex plane, particularly through techniques like root locus and Nyquist plots. The poles of the system’s transfer function, represented in the complex plane, indicate stability.

  3. Vibration Analysis Modal Analysis: Complex numbers help represent oscillatory motions in mechanical systems. The use of complex exponentials can simplify the analysis of vibrations and dynamic responses.

  4. Electromagnetics Maxwell’s Equations: Solutions to Maxwell’s equations, which govern electromagnetic fields, often use complex analysis. Techniques such as the method of complex potentials are employed in electromagnetic field theory.

  5. Heat Transfer Complex Variables in Conformal Mapping: In heat transfer problems, conformal mapping techniques allow engineers to transform complex geometries into simpler ones, making it easier to solve differential equations related to heat conduction.

  6. Numerical Methods Many numerical methods for solving differential equations or optimizing functions can be enhanced by using complex analysis, particularly when dealing with boundary value problems.


https://en.m.wikipedia.org/wiki/Control_theory

Classical SISO system design

The system analysis is carried out in the time domain using differential equations, in the complex-s domain with the Laplace transform, or in the frequency domain by transforming from the complex-s domain. Many systems may be assumed to have a second order and single variable system response in the time domain. A controller designed using classical theory often requires on-site tuning due to incorrect design approximations. Yet, due to the easier physical implementation of classical controller designs as compared to systems designed using modern control theory, these controllers are preferred in most industrial applications. The most common controllers designed using classical control theory are PID controllers.

Jan 04, 2025


The overriding ambition is to introduce some modern mathematics to the physicist, some modern physics to the mathematician, and machine learning to both.

https://www.amazon.com/The-Calabi_Yau-LandscapeFrom-Geometry_-to-Physics_-to-Machine-Learning-Lecture-Notes-in-Mathematics/dp/3030775615

https://www.amazon.com/Machine-Learning-Mathematics-Theoretical-Physics-ebook/dp/B0CC5NWDMY

Jan 04, 2025


AIME AMC_12 有意思的题

https://artofproblemsolving.com/wiki/index.php/2024_AIME_I_Problems/Problem_14

https://artofproblemsolving.com/wiki/index.php/2024_AMC_10A_Problems/Problem_25 Art of Problem Solving

Jan 06, 2025


信息学竞赛 (OI) 究竟发生了什么? 信息学奥赛是 “五大联赛” 里选手和教练脱节最快的比赛。希望通过此视频,使各位指导教师认清现实,放弃幻想,接受死亡 https://m.bilibili.com/video/BV1di421f7L5


Quaternion Cube

Jan 18, 2025

https://youtube.com/watch?v=AnbE6mXGabw

https://chandler.io/posts/2025/01/print-it-yourself-quaternion-cube/

Jan 31, 2025

Minesweeper is NP-Complete

https://ocw.mit.edu/courses/es-268-the-mathematics-in-toys-and-games-spring-2010/50a061a2f76a503d8473a072965bc8ff_MITES_268S10_ses11_slides.pdf


Minesweeper


import random
import sys

def generate_board(rows, cols, num_mines):
    # Create a board with all cells set to 0
    board = [[0 for _ in range(cols)] for _ in range(rows)]
    
    # Place mines randomly on the board
    mines_placed = 0
    while mines_placed < num_mines:
        row = random.randint(0, rows - 1)
        col = random.randint(0, cols - 1)
        if board[row][col] != 'M':
            board[row][col] = 'M'
            mines_placed += 1
    
    # Calculate numbers for each cell
    for row in range(rows):
        for col in range(cols):
            if board[row][col] == 'M':
                continue
            # Check adjacent cells for mines
            for i in range(-1, 2):
                for j in range(-1, 2):
                    if 0 <= row + i < rows and 0 <= col + j < cols:
                        if board[row + i][col + j] == 'M':
                            board[row][col] += 1
    return board

def print_board(board, revealed):
    for row in range(len(board)):
        for col in range(len(board[0])):
            if revealed[row][col]:
                print(board[row][col], end=' ')
            else:
                print('.', end=' ')
        print()

def reveal(board, revealed, row, col):
    if board[row][col] == 'M':
        return False
    revealed[row][col] = True
    if board[row][col] == 0:
        for i in range(-1, 2):
            for j in range(-1, 2):
                if 0 <= row + i < len(board) and 0 <= col + j < len(board[0]):
                    if not revealed[row + i][col + j]:
                        reveal(board, revealed, row + i, col + j)
    return True

def play_minesweeper(rows=8, cols=8, num_mines=10):
    board = generate_board(rows, cols, num_mines)
    revealed = [[False for _ in range(cols)] for _ in range(rows)]
    
    while True:
        print_board(revealed, board)
        try:
            row = int(input("Enter row: "))
            col = int(input("Enter column: "))
            if not (0 <= row < rows and 0 <= col < cols):
                print("Invalid input. Try again.")
                continue
            if not reveal(board, revealed, row, col):
                print("Boom! You hit a mine!")
                print_board(board, [[True for _ in range(cols)] for _ in range(rows)])
                break
        except ValueError:
            print("Invalid input. Please enter numbers only.")
            continue

        # Check if the game is won
        if all(revealed[row][col] or board[row][col] == 'M' for row in range(rows) for col in range(cols)):
            print("Congratulations! You've cleared the minefield!")
            print_board(board, [[True for _ in range(cols)] for _ in range(rows)])
            break

if __name__ == "__main__":
    play_minesweeper()


Tetris


import random
import curses

# Define the shapes of the tetrominoes
SHAPES = [
    [[1, 1, 1, 1]],  # I
    [[1, 1], [1, 1]],  # O
    [[0, 1, 0], [1, 1, 1]],  # T
    [[1, 0], [1, 0], [1, 1]],  # L
    [[0, 1], [0, 1], [1, 1]],  # J
    [[1, 1, 0], [0, 1, 1]],  # S
    [[0, 1, 1], [1, 1, 0]],  # Z
]

# Initialize the game board
BOARD_WIDTH = 10
BOARD_HEIGHT = 20
board = [[0 for _ in range(BOARD_WIDTH)] for _ in range(BOARD_HEIGHT)]

def rotate(shape):
    return [list(row) for row in zip(*shape[::-1])]

def check_collision(board, shape, offset):
    off_x, off_y = offset
    for y, row in enumerate(shape):
        for x, cell in enumerate(row):
            try:
                if cell and board[y + off_y][x + off_x]:
                    return True
            except IndexError:
                return True
    return False

def remove_row(board, row):
    del board[row]
    return [[0 for _ in range(BOARD_WIDTH)]] + board

def join_matrices(mat1, mat2, mat2_off):
    off_x, off_y = mat2_off
    for y, row in enumerate(mat2):
        for x, cell in enumerate(row):
            if cell:
                mat1[y + off_y][x + off_x] = cell
    return mat1

def new_board():
    return [[0 for _ in range(BOARD_WIDTH)] for _ in range(BOARD_HEIGHT)]

def add_piece(board, piece):
    shape = SHAPES[piece['shape']]
    piece['x'] = int((BOARD_WIDTH - len(shape[0])) / 2)
    piece['y'] = -2
    return join_matrices(board, shape, (piece['x'], piece['y']))

def new_piece():
    return {'shape': random.randint(0, len(SHAPES) - 1), 'rotation': random.randint(0, 3)}

def draw_board(stdscr, board):
    stdscr.clear()
    for y, row in enumerate(board):
        for x, cell in enumerate(row):
            if cell:
                stdscr.addstr(y, x * 2, '##', curses.color_pair(1))
            else:
                stdscr.addstr(y, x * 2, '  ')
    stdscr.refresh()

def main(stdscr):
    # Initialize curses
    curses.curs_set(0)
    curses.start_color()
    curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
    stdscr.nodelay(1)
    stdscr.timeout(100)

    # Create the board
    piece = new_piece()
    board = new_board()
    board = add_piece(board, piece)
    draw_board(stdscr, board)

    while True:
        # Get user input
        key = stdscr.getch()
        if key == curses.KEY_DOWN:
            piece['y'] += 1
            if check_collision(board, SHAPES[piece['shape']], (piece['x'], piece['y'])):
                piece['y'] -= 1
                board = join_matrices(board, SHAPES[piece['shape']], (piece['x'], piece['y']))
                piece = new_piece()
                board = add_piece(board, piece)
                if check_collision(board, SHAPES[piece['shape']], (piece['x'], piece['y'])):
                    break  # Game over
        elif key == curses.KEY_LEFT:
            piece['x'] -= 1
            if check_collision(board, SHAPES[piece['shape']], (piece['x'], piece['y'])):
                piece['x'] += 1
        elif key == curses.KEY_RIGHT:
            piece['x'] += 1
            if check_collision(board, SHAPES[piece['shape']], (piece['x'], piece['y'])):
                piece