クリスマスクラッカーミステリー電卓


25

プレゼントが開かれました。ミンチパイが食べられました。スターウォーズが視聴されています。クリスマスシーズンが終わりつつあります。今までに、あなたはいくつかのクリスマスクラッカーを引いたかもしれません。運がよければ、通常の役に立たないプラスチックのおもちゃの代わりに、あなたはあなたの友人や親relativeを驚かせるミステリー電卓を獲得したかもしれません。

ここに画像の説明を入力してください

このトリックは、6枚のカードで構成され、それぞれに数字の4x8グリッドが印刷されています。各カードには、整数の異なるサブセットが含まれています[1,63]。マジシャンは、1枚のカードから番号を選び、その番号を秘密にしておくように求めます。次に、魔術師はどのカードにその番号があるかを尋ねます。その知識があれば、魔術師は推測された元の数を魔法のように決定して開示することができます。


6枚のMystery Calculatorカードの完全なセットを次のように正確に出力します。

 1  3  5  7  9 11 13 15
17 19 21 23 25 27 29 31
33 35 37 39 41 43 45 47
49 51 53 55 57 59 61 63
 - - - - - - - - - - -
 2  3  6  7 10 11 14 15
18 19 22 23 26 27 30 31
34 35 38 39 42 43 46 47
50 51 54 55 58 59 62 63
 - - - - - - - - - - -
 4  5  6  7 12 13 14 15
20 21 22 23 28 29 30 31
36 37 38 39 44 45 46 47
52 53 54 55 60 61 62 63
 - - - - - - - - - - -
 8  9 10 11 12 13 14 15
24 25 26 27 28 29 30 31
40 41 42 43 44 45 46 47
56 57 58 59 60 61 62 63
 - - - - - - - - - - -
16 17 18 19 20 21 22 23
24 25 26 27 28 29 30 31
48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63
 - - - - - - - - - - -
32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47
48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63

出力には、最後の改行が1つ含まれている場合と含まれていない場合があります。末尾の空白があってはなりません。各カードは11の-ミシン目で区切られています。

  • 最後の改行を含むmd5sum: 7aa2d9339b810ec62a2b90c5e11d6f4a
  • 最終改行なしのmd5sum: e9abe4e32dca3e8fbfdaa4886fc5efd2

より多くのウィンドウの向きをお持ちの方のために、CRLFスタイルの行末も許可します。その場合、md5は次のとおりです。

  • 最後の改行を含むmd5sum: e4f16ff9752eee2cedb5f97c7b5aec6d
  • 最終改行なしのmd5sum: 78c560eed3b83513e3080117ab5dc5fa

2
私はバブルガムの答えを待っています。
マイクブファルデチ16


先行スペースは許容されますか?
タイタス

@Titus申し訳ありませんが、md5は与えられており、追加の空白はそれらを台無しにします。
デジタルトラウマ

回答:


10

パイソン299の 96 93 91バイト

k=1
while 1:print('%2d '*7+'%2d\n')*4%tuple(n for n in range(64)if k&n),11/(k<32)*' -';k*=2

デフォルト許可されているエラーで終了します

オンラインでお試しください!または、MD5ハッシュを確認します

使い方

k1に初期化した後、次のコードを実行する無限ループに入ります。

print('%2d '*7+'%2d\n')*4%tuple(n for n in range(64)if k&n),11/(k<32)*' -';k*=2

tuple(n for n in range(64)if k&n)j 番目のビットが設定されている64未満のすべての非負整数のタプルを作成します。jはループの反復カウント、つまり2 j = kです。

('%2d '*7+'%2d\n')*4最初にフォーマット文字列を作成し、'%2d %2d %2d %2d %2d %2d %2d \n'それを4回繰り返します。これは、各カードのテンプレートであり、タプルの各整数を2文字にパディングし(スペースを追加)、8個の整数の各グループをスペースで区切り、グループ自体を改行で区切ります。

今、Python 2のprint声明は奇妙な獣です。カンマで区切られたいくつかの式を取り、それらを1つずつ出力します。式がなくなるまで、最初の式を評価し、出力し、次の式を評価し、出力します。最後の式の後にコンマが続く場合を除き、改行が追加されます。また、行の先頭に印刷されない限り、すべての式の前にスペースが追加されます。

各反復では、最初に書式文字列をタプルに適用した結果を出力します。行の先頭にあるため、スペースは追加されません。

次に、の結果を印刷(試行)します11/(k<32)*' -'k <32の場合、この式はに評価され' - - - - - - - - - - -'ます。繰り返しますが、行の先頭にあるため、スペースは追加されません。この式の後にコンマがないためprint、改行を追加します。ただし、6回目の反復では、k = 2 5 = 32であるため、評価しようとすると11/(k<32)*' -'、キャッチされていないZeroDivisionErrorが発生します。これにより、ループが終了し、プログラムがすぐに終了します。


7

C(gcc)、105バイト

o;main(i){for(;i<384;i++%64||puts(" - - - - - - - - - - -"))i&1<<i/64&&printf("%2d%c",i%64,++o%8?32:10);}

5

Python 2、132バイト

for c in range(6):s=" ".join("%2d"%n for n in range(64)if n&1<<c);print"\n".join([s[24*i:24*i+23]for i in range(4)]+[" -"*11]*(c<5))

Pythonでは、シーケンスの分割は面倒です。

オンラインでお試しください


5

ゼリー27 26バイト

Ts8GW
⁾ -ẋ11W
63RBUz0Ñ€j¢Y

オンラインでお試しください!または、MD5ハッシュを確認します

使い方

63RBUz0Ñ€j¢Y  Main link. No arguments.

63R           Range 63; yield [1, ..., 63].
   B          Binary; convert each integer to base 2.
    U         Upend; reverse the binary representations.
     z0       Zip with filler 0; transpose rows and columns, filling gaps in
              the (non-rectangular) matrix with zeroes.
       р     Map the first helper link over the new rows.
          ¢   Yield the return value of the second helper link.
         j    Join the left result, separating by the right result.
           Y  Join the results, separating by line feeds.

Ts8G          First helper link. Argument: A (array of 1's and 0's)
T             Truth; get all indices of 1's.
 s8           Split the indices into chunks of length 8.
   G          Grid; convert the 2D array into a string, separating row items
              by spaces, rows by linefeeds, and left-padding each integer
              with spaces to equal lengths.
    W         Wrap the generated string in an array.


⁾ -ẋ11W       Second helper link. No arguments.

⁾ -           Yield " -".
   ẋ11        Repeat the string 11 times.
      W       Wrap the generated string in an array.

2
このGビルトインは、この課題に対して非常に強力です。同じことをするのに約10バイト必要でした。
DLosc 16

5

ピップ49 48 44バイト

43バイトのコード、-Sフラグの場合は+1 。

Fi,6{IiP" -"X11P(sX2-#_._M2**iBA_FI,64)<>8}

オンラインでお試しください!

説明

                                             s is space (preinitialized)
Fi,6{                                     }  For i in range(6):
     Ii                                      If i is nonzero (i.e. all except 1st loop):
       P" -"X11                              Print hyphens
                                 FI,64       Range(64), filtered on this function:
                          2**iBA_              2**i bitwise AND with argument (is nonzero)
                         M                   To each remaining number, map this function:
                   2-#_                        2-len(argument)
                 sX                            ^ that many spaces
                       ._                      prepended to argument
                (                     )<>8   Group list into length-8 sublists
               P                             Print (-S flag joins on space then newline)

4

ルビー、90バイト

1.upto(383){|i|print (j=i%64)<1?' -'*11+$/:"%2d%s"%[j,j+1&15>>i/256>0?' ':$/]*(j>>i/64&1)}

非ゴルフ

かなり簡単です。追加の説明が必要になる可能性があるのは、数字の後にスペースではなく改行を付ける場合だけです。これj+1%16==0は、最初の4枚のカードとj+1%8最後の2 枚の== 0のときに起こります。したがって、スペースまたは改行が必要かどうかを判断するために、式15>>i/64/4または同等の15>>i/256論理積がとられjます。

1.upto(383){|i|                              #Count starting at 1 instead of 0 to supress - -  before 1st card
  print (j=i%64)<1?                          #j=number to consider for card. If 0,
    ' -'*11+$/:                              #print - - -... else print
     "%2d%s"%[j,j+1&15>>i/256>0?' ':$/]*     #j formatted to 2 spaces followed by a space (or if j+1 divisible by 16 or 8 depending on card, a newline.) 
     (j>>i/64&1)                             #only print appropriate numbers for this card, i.e. when this expression evaluates to 1
}

3

JavaScript(ES6)、150バイト

f=
_=>[1,2,4,8,16,32].map(m=>[...Array(64)].map((_,i)=>` ${i}`.slice(-2)).filter(i=>i&m).join` `.replace(/(.{23}) /g,`$1
`)).join(`
${` -`.repeat(11)}
`)
;document.write(`<pre>`+f())


2

Perl 6の 194の116  86バイト

put join "\n{' -'x 11}\n",map {join "\n",.[^32].rotor(8)».fmt('%2s')},(1,3...63),(2,{|($_ X+1,4)}...*),(4,{|($_ X+1,2,3,8)}...*),(8,{|((1...7,16)X+$_)}...*),(16,{|((1...15,32)X+$_)}...*),32..63

それを試してみてください

for 1..383 {print !($/=$_%64)??"{' -'x 11}\n"!!$/+>($_/64)%2??$/.fmt('%2d')~(($/+1)+&(15+>($_/256))??' '!!"\n")!!''}

それを試してみてください

for 1..383 {$_%64||put ' -'x 11;$_+&(1+<($_/64))&&printf "%2d%c",$_%64,++$/%8??32!!10}

それを試してみてください

(MD5の結果については、デバッグセクションを確認してください)
最後の2つは、RubyとCの実装からインスピレーションを受けた/転写されました


2

05AB1E、71バイト

63L©DÉÏ®À2ô®ÉÏ®ÀÀÀ4ô®ÉÏ®Á8ô®ÈÏ63®Á16ô®ÈÏ63D32sŸ)˜32ôvy8ôvy.B}„ -11×})¨»

オンラインでお試しください!

このアプローチは、試さないでください。正直に言うと、これは恥ずべきことではないでしょう。マトリックス操作は私の強力なスーツではないので、6つのシーケンスすべてをブルートフォースで生成し、それらを一緒にずんぐりとポンピングしようとしました。


TFWでは、数年前の自分の答えが表示されます¯\(º_o)/¯。
魔法のタコUr

1

バッチ、249バイト

@echo off
set s=
for %%i in (1 2 4 8 16 32)do for /l %%j in (0,1,63)do call:c %%i %%j
exit/b
:c
if %2==0 if %1 gtr 1 echo  - - - - - - - - - - -
set/an=%1^&%2
if %n%==0 exit/b
set n=  %2
set s=%s%%n:~-3%
if not "%s:~23%"=="" echo%s%&set s=

末尾のCRLFを出力します。


1
@DigitalTraumaそれを試す最良の方法は、実際にWine(askubuntu.com/a/54271)を必要とするか、VMをダウンロードする(developer.microsoft.com/en-us/microsoft-edge/tools/vms)(私はあなたにIE8を搭載したWindows 7をダウンロードして、スペースを節約します。または、以前は利用可能であったWindows XP + IE6 VMを試してみてください)
Ismael Miguel

1

JavaScript(ES6)、103 102バイト

f=(k=1,n=z=0)=>n>>6?k>>5?'':' -'.repeat(11)+`
`+f(k*2):(n&k?(n>9?'':' ')+n+`
 `[++z&7&&1]:'')+f(k,++n)

MD5:7AA2D9339B810EC62A2B90C5E11D6F4A

テスト


1

bash / Unixユーティリティ、125 124バイト

b='- - - - ';for ((x=1;x<33;x*=2));{ for n in {0..63};{ ((x&n))&&printf \ %2d $n;};echo $b$b$b;}|fold -w24|sed -e\$d -es/.//

編集:最後の正規表現から不要な^を削除しました。とにかく、正規表現は常に行の先頭で一致します。


1

PHP、102バイト

for(;$c<6;$n%32||$c+=print str_pad("
",25," -"),$n%2**$c||$b+=1<<$c)printf("
"[$n++%8]."%3d",++$b%64);

先行改行を印刷しますが、後続改行はなし、各行に先行スペースを1つ出力します。で実行する-nr、オンラインで試してください

PHP <5.6の場合は、交換してください2**$c(1<<$c)。PHP 5.5はの&~1<<$c?:代わりに使用できます%2**$c||
PHP <5.5の場合は、交換してください"\n"[$n++%8]($n++%8?"":"\n")


ダッシュは、先頭のスペースのために1文字離れています。最初のstr_padパラメーターにスペースを追加(2番目のコード行の前にスペースを挿入)して修正します。

代わりに先頭のスペースを削除すると、いくつかいじると3つの追加バイトが必要ですprintf("%c%2d",$n++%8?32:10,++$b%64);し、23代わりに25

先頭の改行を末尾の改行に変えると、さらに3バイトかかります。

for(;$c<6;$n%32||$c+=print str_pad("",22," -")."
",$n%2**$c||$b+=1<<$c)printf("%2d%c",++$b%64,++$n%8?32:10);

PHP、109バイト

for($c=1;~$c&64;$n%32||$c<<=print str_pad("",22," -")."
",$n%$c||$b+=$c)printf("%2d%c",++$b%64,++$n%8?32:10);

すべての仕様に一致し、すべてのPHPバージョンで動作します。


1

Python 2、89バイト

i=0;exec"print('%2d '*7+'%2d\\n')*4%tuple(j for j in range(64)if j&2**i)+' -'*11;i+=1;"*6

オンラインでお試しください!

説明:

# initialize outer counter variable
i=0
           # generate a formatting string for a single row of numbers
           # %2d will left pad an integer with spaces, up to string length 2
           # the \\n is so that exec will interpret it as a character rather than a literal line break
           '%2d '*7+'%2d\\n'
          # create a formatting string of 4 lines of 8 numbers
          (.................)*4
                               # format the string with a generated tuple of numbers that have a 1 in the current bit slot
                               # (or more literally, bitwise j AND 2^i is not zero)
                               %tuple(j for j in range(64)if j&2**i)
                                                                    # add the perforation break
                                                                    +' -'*11
     # print the generated string, then increment the counter
     print..................................................................;i+=1
# execute the following statements 6 times
exec"............................................................................."*6

良い。ただし、 `---`セパレーターはカード間にのみ表示され、最後に余分なセパレーターは表示されません。
デジタルトラウマ

@DigitalTrauma Dang、そして私はデニスよりも少ないバイト数を取得できることを誇りに思っていました。指摘してくれてありがとう!
トリガー測定

1

05AB1E、29 バイト

63L2вíƶ0ζε0K8ô§2j»}„ -11׶.øý

港から@Emignaここの05AB1Eの答えは、その後私はこの挑戦の要求に応じてそれを印刷するために追加のコードを追加しました。

オンラインそれを試してみたりmd5sumを確認します

説明:

63L          # Create a list in the range [1,63]
   2в        # Convert each number to binary as lists of 0s and 1s
     í       # Reverse each binary list
      ƶ      # Multiply each binary digit by its 1-based index [1,length] (so [1,63])
       0ζ    # Zip/transpose; swapping rows/columns, with "0" as filler
ε            # Map each inner list to:
 0K          #  Remove all 0s
   8ô        #  Split it into (four) lists of size 8
     §       #  Cast each integer to string (bug, shouldn't be necessary..)
      2j     #  And pad leading spaces to make each string size 2
        »    #  Join the inner lists by spaces, and then all strings by newlines
}„ -         # After the map: push string " -"
    11×      # Repeated 11 times to " - - - - - - - - - - -"
       ¶.ø   # Surround it with newlines: "\n - - - - - - - - - - -\n"
          ý  # And join the mapped strings with this delimiter-string
             # (after which the result is output implicitly)

0

JavaScript、234バイト。

for(a=[[],[],[],[],[],[]],i=1;i<64;i++)for(j=0;j<6;j++)i&2**j?a[j].push(i<10?" "+i:i):0;for(j=0;j<6;j++){for(s=[],i=0;i<4;)s.push(a[j].slice(i*8,++i*8).join(" "));b=s.join(n="\n");a[j]=b.substr(0,b.length)};a.join(n+" -".repeat(11)+n)

後で説明を書きます。

場合はconsole.log要求され、バイト数は247バイトになります。


サイトへようこそ!出力を配列に入れていますか?Javascriptはわかりませんが、変数を介して出力することはできないため、ログを記録する必要があります。
ウィートウィザード
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.