python

しょっちゅう忘れることを書いておく。

33

321 views

パリティチェックサンプル

# coding:UTF-8

def get_row(records, row):
    return records[row]


def get_col(records, col):
    cols = [r[col] for r in records]
    return cols


def get_col_wakariyasui(records, col):
    cols = []
    for record in records:
        cols.append(record[col])
    return cols


if __name__ == '__main__':
    records = [
        [0, 1, 1, 0],
        [1, 0, 1, 0],
        [1, 0, 1, 0],
        [1, 1, 0, 0]
    ]

    y_parities = [0, 1, 0, 0]
    x_parities = [1, 1, 1, 0]

    # 行の誤りを調べる
    error_row = 0
    for i in range(4):
        row = get_row(records, i)
        # TODO ここでパリティと比較する
        y_parity = y_parities[i]
        total = sum(row)
        if total % 2 == y_parity:
            print("{}行目に誤りなし".format(i))
        else:
            error_row = i

    # 列の誤りを調べている
    error_col = 0
    for i in range(4):
        col = get_col(records, i)
        # TODO ここでパリティと比較する
        x_parity = x_parities[i]
        total = sum(col)
        if total % 2 == x_parity:
            print("{}列目に誤りなし".format(i))
        else:
            error_col = i

    print("{}行目{}列目の値が誤っています".format(error_row, error_col))

Page 33 of 56.

前のページ 次のページ



[添付ファイル]


お問い合わせ

プロフィール

マッスル

自己紹介

本サイトの作成者。
趣味:プログラム/水耕栽培/仮想通貨/激辛好き
プログラムは趣味と勉強を兼ねて、のんびり本サイトを作っています。
フレームワークはdjango。
仮想通貨はNEMが好き。
水耕栽培は激辛好きが高じて、キャロライナ・リーパーの栽培にチャレンジ中。

サイト/ブログ

https://www.osumoi-stdio.com/pyarticle/

ツイッター

@darkimpact0626