【今年の漢字】(2021年)の質問

 皆さん、【今年の漢字】(2021年)の質問の回答・コメントありがとうございました。【今年の漢字】は、東京オリンピックパラリンピックで日本人選手が金メダルを過去最多の数を獲得したことなどから、またまた「金」でした。(^_^;

 全員不正解でしたが、ベストアンサーは個人的な好みで決めました。(^_^;
 ちなみに、第1位および、2位以下の情報は、次の通りです。

1位 「金」10,422 票(4.66%)
2位 「輪」10,304 票(4.60%)
3位 「楽」 6,165 票(2.76%)
4位 「変」 5,605 票(2.50%)
5位 「新」 4,738 票(2.12%)
6位 「翔」 3,577 票(1.60%)
7位 「希」 2,941 票(1.31%)
8位 「耐」 2,923 票(1.31%)
9位 「家」 2,814 票(1.26%)
10位 「病」 2,812 票(1.26%)
11位 「明」 2,709 票(1.21%)
12位 「結」 2,626 票(1.17%)
13位 「禍」 2,393 票(1.07%)
14位 「五」 2,170 票(0.97%)
15位 「密」 2,136 票(0.95%)
16位 「幸」 2,128 票(0.95%)
17位 「復」 2,068 票(0.92%)
18位 「苦」 1,840 票(0.82%)
19位 「勝」 1,796 票(0.80%)
20位 「命」 1,779 票(0.80%)
※応募総数 223,773 票

※参考URL
2021年「今年の漢字」の募集を開始 | 公益財団法人 日本漢字能力検定

【将棋と囲碁】のアンケート

 皆さん、アンケートの回答ありがとうございました。
 やはり、将棋の方が人気のようです。ちなみに、他のQ&Aサイトで質問すると、将棋人口の方が多いのに、囲碁の回答の方が多いそうです。(^_^;

※参考URL
https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q10252943850

判断推理の履修状況の問題をPythonで解いてみた。

 判断推理の履修状況の対応関係の問題Pythonで解いてみました。

 A~Eの学生5人における政治学、経済学、行政学社会学法律学の5科目の履修状況について次のことがわかているとき、確実にいえるのはどれか。
(ア)5人が履修している科目数はそれぞれ3科目以内である。
(イ)政治学を履修している者は2人いる。
(ウ)経済学を履修している者は2人おり、そのうちの1人はAである。
(エ)行政学を履修している者は3人おり、そのうちの1人はAである。
(オ)社会学を履修している者は3人おり、そのうちの2人はAとDである。
(カ)法律学を履修している者は4人いる。
(キ)AとEが2人とも履修している科目はない。
(ク)Cは政治学社会学も履修していない。
選択肢
1. Bは政治学を履修していない。
2. Bは行政学を履修していない。
3. Cは経済学を履修していない。
4. Dは経済学を履修していない。
5. Dは行政学を履修していない。

 ただし、条件に(ア)~(ク)の名前を付けました。
 政治学をp、経済学をq、行政学をr、社会学をs、法律学をtとして、組合せで回してみました。(^_^;
 A~E各人の履修表は、政治学から順に、履修したら1、履修していないなら0としてリストを作成しました。
 条件(キ)は、「(1,1) in zip(a,e)」で調べました。list(zip())は、tupleのlistになっていました。

● Courses1.py

# coding: UTF-8
# Courses1.py

import itertools
from time import time

# 確実にいえる選択肢を得る
def getAns(cho,lbl='12345'):
    return ','.join([lbl[i] for i in range(len(cho)) if cho[i]])

def toStr(li,sp=',',fm='%s'):
    return fm%sp.join(li)

def main():
    tm = time()  # Timer Start
    choices = [True]*5
    P = 'ABCDE'
    # p:政治学、q:経済学、r:行政学、s:社会学、t:法律学
    for p in itertools.combinations(P,2):                   # 条件(イ)
        if 'C' in p: continue                               # 条件(ク)
        for q in itertools.combinations(P,2):               # 条件(ウ)
            if not 'A' in q: continue                       # 条件(ウ)
            for r in itertools.combinations(P,3):           # 条件(エ)
                if not 'A' in r: continue                   # 条件(エ)
                for s in itertools.combinations(P,3):       # 条件(オ)
                    if not 'A' in s: continue               # 条件(オ)
                    if not 'D' in s: continue               # 条件(オ)
                    if     'C' in s: continue               # 条件(ク)
                    for t in itertools.combinations(P,4):   # 条件(カ)
                        # 各人の履修表を作成
                        a = [int('A' in x) for x in (p,q,r,s,t)]
                        b = [int('B' in x) for x in (p,q,r,s,t)]
                        c = [int('C' in x) for x in (p,q,r,s,t)]
                        d = [int('D' in x) for x in (p,q,r,s,t)]
                        e = [int('E' in x) for x in (p,q,r,s,t)]
                        if not sum(a)<=3: continue          # 条件(ア)
                        if not sum(b)<=3: continue          # 条件(ア)
                        if not sum(c)<=3: continue          # 条件(ア)
                        if not sum(d)<=3: continue          # 条件(ア)
                        if not sum(e)<=3: continue          # 条件(ア)
                        if (1,1) in zip(a,e): continue      # 条件(キ)
                        pass # チェックを潜り抜けたものを表示
                        print('政:%s'%toStr(p,''),end=', ')
                        print('経:%s'%toStr(q,''),end=', ')
                        print('行:%s'%toStr(r,''),end=', ')
                        print('社:%s'%toStr(s,''),end=', ')
                        print('法:%s'%toStr(t,''))
                        pass # 選択肢のチェック
                        choices[0] &= ('B' not in p)
                        choices[1] &= ('B' not in r)
                        choices[2] &= ('C' not in q)
                        choices[3] &= ('D' not in q)
                        choices[4] &= ('D' not in r)

    print("∴%s"%getAns(choices))
    print("Runtime : %.3f [sec]"%(time()-tm))   # Timer Stop & Disp

if __name__ == '__main__':
    main()

●実行結果

政:BE, 経:AC, 行:ACD, 社:ABD, 法:BCDE
政:DE, 経:AC, 行:ABC, 社:ABD, 法:BCDE
∴4
Runtime : 0.031 [sec]

※参考URL
知恵袋で見つけた判断推理の出勤簿の問題をPythonで解いてみた。 - rscのブログ
知恵袋で見つけた判断推理の出勤簿の問題をPythonで解いてみた。(2) - rscのブログ

判断推理のカードの問題をPythonで解いてみた。(5)

 判断推理のカードの問題Pythonで解いてみました。(^_^;

AとBの2人がカードを4枚ずつ持っている。Aはカードに3~6の数字を1つずつ順に書き込んだ。Bも同様にするつもりだったが、途中で1つの数字を抜かしてしまい、4枚目の数字は7であった。2人は任意のカードを1枚ずつ出し、数の大小を比べたが、結果は次の通りであった。

1枚目:Bが2大きい
2枚目:Aが1大きい
3枚目:同じ数
4枚目:Bが2大きい

Bが抜かした数字は次のうちどれか。

1. 3
2. 4
3. 5
4. 6
5. わからない

 1枚抜いて求めたBのsetとAとの数の大小関係から求めたBのsetを比較してみました。(^_^;
 選択肢5の「わからない」とは、選択肢が1~4の一つに決まらなかったということですよね。(^_^;
 ちなみに、自分で解くと、Aの1~4枚目の数字を、(p,q,r,s)とすると、Bのカードの数字は、それぞれ、(p+2,q-1,r,s+2)となります。Bが抜かしたカードをxとして、Bの合計を2通りに表すと、
3+4+5+6+7-x=(p+2)+(q-1)+r+(s+2)
∴25-x=(p+q+r+s)+3
ここで、p+q+r+s=3+4+5+6=18
∴25-x=(18)+3=21
∴x=25-21=4

● Cards5.py

# coding: UTF-8
# Cards5.py

import itertools
from time import time

# 確実にいえる選択肢を得る
def getAns(cho,lbl='12345'):
    return ','.join([lbl[i] for i in range(len(cho)) if cho[i]])

def main():
    tm = time()  # Timer Start
    choices = [True]*4
    A = range(3,7)
    B = range(3,8)
    for n in A:
        b = set(B)-{n}      # set
        for p in itertools.permutations(A):
            a1,a2,a3,a4 = p
            q = (a1+2,a2-1,a3,a4+2)     # tuple
            if not set(q)==b: continue
            pass # チェックを潜り抜けたものを表示
            print(n,p,q)
            pass # 選択肢のチェック
            choices[0] &= (n==3)
            choices[1] &= (n==4)
            choices[2] &= (n==5)
            choices[3] &= (n==6)

    if choices.count(True)==1:
        print("∴%s"%getAns(choices))
    else:
        print("∴5")
    print("Runtime : %.3f [sec]"%(time()-tm))   # Timer Stop & Disp

if __name__ == '__main__':
    main()

●実行結果

4 (3, 4, 6, 5) (5, 3, 6, 7)
4 (4, 6, 3, 5) (6, 5, 3, 7)
4 (5, 4, 6, 3) (7, 3, 6, 5)
4 (5, 6, 3, 4) (7, 5, 3, 6)
∴2
Runtime : 0.000 [sec]

※参考URL
判断推理のカードの問題をPythonで解いてみた。 - rscのブログ
判断推理のカードの問題をPythonで解いてみた。(2) - rscのブログ
判断推理のカードの問題をPythonで解いてみた。(3) - rscのブログ
判断推理のカードの問題をPythonで解いてみた。(4) - rscのブログ

判断推理のカードの問題をPythonで解いてみた。(4)

 判断推理のカードの問題Pythonで解いてみました。(^_^;

 1から9までの数字を一つずつ書いた9枚のカードがある。A~Cの3人がこの中から任意の3枚ずつとったところ、
Aの取ったカードに書かれていた数の合計は13でその中には7が入っていた。
Bの取ったカードに書かれていた数の合計は12で、その中には4が入っていた。
Cの取ったカードに書かれていた数の中に入っていた数は、次のうちではどれか。
1.1、 2.2、 3.5、 4.6、 5.8

 組合せで回した方が速いですが、あえて順列で回してみました。最近はPCが速くなったので、あまり差はないです。(^_^;

● Cards4.py

# coding: UTF-8
# Cards4.py

import itertools
from time import time

# 確実にいえる選択肢を得る
def getAns(cho,lbl='12345'):
    return ','.join([lbl[i] for i in range(len(cho)) if cho[i]])

def main():
    tm = time()  # Timer Start
    choices = [True]*5
    Cards = range(1,10)
    for p in itertools.permutations(Cards):
        a,b,c = p[:3],p[3:6],p[6:]
        if not a[0]< a[1]< a[2]: continue
        if not b[0]< b[1]< b[2]: continue
        if not c[0]< c[1]< c[2]: continue
        if not sum(a)==13: continue     # 条件A-1
        if not 7 in a: continue         # 条件A-2
        if not sum(b)==12: continue     # 条件B-1
        if not 4 in b: continue         # 条件B-2
        pass # チェックを潜り抜けたものを表示
        print('A:',a)
        print('B:',b)
        print('C:',c)
        pass # 選択肢のチェック
        choices[0] &= (1 in c)
        choices[1] &= (2 in c)
        choices[2] &= (5 in c)
        choices[3] &= (6 in c)
        choices[4] &= (8 in c)

    print("∴%s"%getAns(choices))
    print("Runtime : %.3f [sec]"%(time()-tm))   # Timer Stop & Disp

if __name__ == '__main__':
    main()

●実行結果

A: (1, 5, 7)
B: (2, 4, 6)
C: (3, 8, 9)
∴5
Runtime : 0.531 [sec]

※参考URL
判断推理のカードの問題をPythonで解いてみた。 - rscのブログ
判断推理のカードの問題をPythonで解いてみた。(2) - rscのブログ
判断推理のカードの問題をPythonで解いてみた。(3) - rscのブログ
判断推理のカードの問題をPythonで解いてみた。(5) - rscのブログ

【岸田内閣】のアンケート

 皆さん、アンケートの回答ありがとうございました。
 「変わらない」というのが、一番多かったですね。(^_^;