Skip to content

Instantly share code, notes, and snippets.

View feilongjiang's full-sized avatar
🤔
Hmmmmm

Feilong Jiang feilongjiang

🤔
Hmmmmm
View GitHub Profile
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
/*
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
* Copyright Huawei Technologies Co., Ltd. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
@feilongjiang
feilongjiang / MagicSquare.py
Created May 6, 2017 08:11
Odd & Double Even Magic Square
# -*- coding: utf-8 -*-
# 奇阶幻方
def odd_magic_square(n):
matrix = [[0 for i in range(n)] for i in range(n)]
# x, y 的初始位置以及从1开始赋值
num, x, y = 1, 0, int(n / 2)
while num != n ** 2 + 1:
matrix[x][y] = num
# 通过x0,y0检测右上方是否已填入数字
x0, y0 = x - 1, y + 1