未分類

下の図のように○と×をある規則にしたがって並べていくとき

投稿日:

○×○○××○○○××××○○○○××××××××○・・・

(1)最初から数えて50番目は○×どちら?
(2)はじめて×の数の総和が○の数の総和の2倍になるのは、最初から数えて何番目?
 また、次に×の数の総和が○の総和の2倍になるのは、最初から数えて何番目?
(3)×の数の総和が○の数の総和の2倍になるのは、全部で何回起こるか。

新高2の学校春課題より抜粋。
ただ解いても面白くないので、練習がてら、スクリプトで解決。

結果
>>python 20210403.py
[ n=2 turn=1 o=1 x=1 S(o)=1 S(x)=1 Q1=? Q2first=0 Q2second=0 Q3=0 ] <<< turn(1) is done.
[ n=6 turn=2 o=2 x=2 S(o)=3 S(x)=3 Q1=? Q2first=0 Q2second=0 Q3=0 ] <<< turn(2) is done.
[ n=13 turn=3 o=3 x=4 S(o)=6 S(x)=7 Q1=? Q2first=0 Q2second=0 Q3=0 ] <<< turn(3) is done.
[ n=25 turn=4 o=4 x=8 S(o)=10 S(x)=15 Q1=? Q2first=0 Q2second=0 Q3=0 ] <<< turn(4) is done.

[ n=45 turn=5 o=5 x=15 S(o)=15 S(x)=30 Q1=? Q2first=45 Q2second=0 Q3=1 ] <<< Q2:gotcha!!
[ oxooxxoooxxxxooooxxxxxxxxoooooxxxxxxxxxxxxxxx ]

[ n=46 turn=5 o=5 x=16 S(o)=15 S(x)=31 Q1=? Q2first=45 Q2second=0 Q3=1 ] <<< turn(5) is done.

[ n=50 turn=6 o=4 x=0 S(o)=19 S(x)=31 Q1=o Q2first=45 Q2second=0 Q3=1 ] <<< Q1:gotcha!!
[ oxooxxoooxxxxooooxxxxxxxxoooooxxxxxxxxxxxxxxxxoooo ]

[ n=63 turn=6 o=6 x=11 S(o)=21 S(x)=42 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< Q2:gotcha!!
[ oxooxxoooxxxxooooxxxxxxxxoooooxxxxxxxxxxxxxxxxooooooxxxxxxxxxxx ]

[ n=84 turn=6 o=6 x=32 S(o)=21 S(x)=63 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< turn(6) is done.
[ n=155 turn=7 o=7 x=64 S(o)=28 S(x)=127 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< turn(7) is done.
[ n=291 turn=8 o=8 x=128 S(o)=36 S(x)=255 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< turn(8) is done.
[ n=556 turn=9 o=9 x=256 S(o)=45 S(x)=511 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< turn(9) is done.
[ n=1078 turn=10 o=10 x=512 S(o)=55 S(x)=1023 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< turn(10) is done.
[ n=2113 turn=11 o=11 x=1024 S(o)=66 S(x)=2047 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< turn(11) is done.
[ n=4173 turn=12 o=12 x=2048 S(o)=78 S(x)=4095 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< turn(12) is done.
[ n=8282 turn=13 o=13 x=4096 S(o)=91 S(x)=8191 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< turn(13) is done.
[ n=16488 turn=14 o=14 x=8192 S(o)=105 S(x)=16383 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< turn(14) is done.
[ n=32887 turn=15 o=15 x=16384 S(o)=120 S(x)=32767 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< turn(15) is done.
[ n=65671 turn=16 o=16 x=32768 S(o)=136 S(x)=65535 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< turn(16) is done.
[ n=131224 turn=17 o=17 x=65536 S(o)=153 S(x)=131071 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< turn(17) is done.
[ n=262314 turn=18 o=18 x=131072 S(o)=171 S(x)=262143 Q1=o Q2first=45 Q2second=63 Q3=2 ] <<< turn(18) is done.

26万2314番目まで調べさせました。
○の総数が171個、×の総数が26万2143個でした。
○の総数を二倍した程度で×の総数に追いつくことはこの後ないでしょう。
というわけでQ3の答えは2個でいいでしょう。

-未分類


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

文房具。

小野田教室には、文房具が好きなゼミ生がいました。 最近の文房具は、遊び心があるものも多く、見ているだけでも楽しいですよね。 (私も文房具好きだからかもしれません。。。) このゼミ生は普段、教室に入って …

「9割は親」という本の要約(括弧内は私見)

この本良すぎて3冊買いました。2冊は配る用です。 結論:デジタル機器の制限と家庭ルールと褒めること、9割は親が不登校克服の鍵 p.24 子の言う悩みを解決しても、不登校は解決しない p.25 正しい親 …

no image

not は文頭の方へ持ってくるべきか

モリテツのショート動画を以下に要約しました。モリテツ氏と米国人のChokaさんが話します。 モリテツ氏 “I think that will not work.”を日本では間違 …

no image

説明の極意

中学生に知ってほしくない(検索してほしくない、YouTubeを見始めるきっかけを1つでも減らしたい)のと、氏の名前でアクセス数を稼ぎたいわけじゃないので、少しでも検索されないようにしたくて、敢えて話し …

友達との勉強会。

中学生には、 『違うクラスの子と情報交換するつもりで行きなさい』 と生徒には言っています。 友達同士でいると、ついつい脱線しちゃいますよね??   高校生には、『行くな』と言ってあります。 …

最近の投稿

サイト内検索

カテゴリー

アーカイブ