音符のリストを出力する


27

このタスクは簡単です。A♭からG♯までのすべての音符のリスト(英語の音名を使用)を出力するプログラムまたは関数を作成します。

単一の文字で構成される名前のないすべての音符(つまり、音楽キーボードの黒い音符)には、音符のシャープと1つのフラットの2回ずつ名前を印刷する必要があります。B♯(C)やF♭(E)のように1文字で説明できるシャープまたはフラットなノートは出力しないでください。

出力の例を次に示します。

Ab, A, A#, Bb, B, C, C#, Db, D, D#, Eb, E, F, F#, Gb, G, G#

仕様書

  • プログラムまたは関数は入力を取ってはなりません。

  • メモは、任意の順序で、および標準のI / Oルールで許可されているリスト出力で印刷できます。

  • シャープでフラットなUnicodeシンボル(♯/♭)はb#

  • いつものように、標準の抜け穴は禁止されています。

  • これはであるため、バイト単位の最小のプログラムが勝ちます。



1
"C "代わりに出力でき"C"ますか?
アーナルド

1
@Arnauldはい、できます
TheOnlyMrCat

7
ところで、B#は楽譜にあります。たとえば、C#のキーのキーシグネチャにあり、リーディングトーンとして機能します。
カズ

2
私は知らない、それはCbがここに欠けているように感じる;)
AJFaraday

回答:


13

Malbolge482の 370 353バイト

R1:間のコンマを削除しました(チャレンジでは必要ありません)

R2:数バイト削り取る

('<;_#!=6Z|{8xUwvt,PrqonKmk)"FhCUTdb?`+<;:[Z7YtVU2T|/g-O+i(gJrHc#EC~B{@zZxw:tt'r5Qo"!l/K-hUfe?bP``_Lo~[}|X2VCTR3Q+N`_^9+7Hji3ffdAc~w|u;]\wpon4VUSSQ.PONcb(JI^]#DCYX|@?>=<:u9NMRKo32MFj.C,Ae)>'<%:^"!~5:3WxwwuRts0q(Lnml)"Fhgfe"y?a`_zyxq7YXWlUj0RgfkjMb(JI^c\[Z~BAV?T=Rv987Mq44310FEi-,G@)>b&%#"8=6Z{{yyw/Sut1*)('Km$k(!Efe{zyx>`uz]r8ZXnm3TTih.PkNchg`&HFF[DY}Az

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


12

CP-1610アセンブリ(Intellivision)、31 DECLE 1 = 39バイト

R4で出力ポインタを取得し、スペースで区切ってメモを書き込むルーチン。サンプルコードでは、画面に直接書き込みます。

六角ダンプ(ルーチンのみ)

275 001 2BD 03C 048 1DB 2B8 012 044 2A9 2BA 108 078 201 003 262
261 263 2FA 008 37A 140 225 00B 089 22C 011 2B7 018 210 000

完全なソース

                ROMW    10              ; use 10-bit ROM width
                ORG     $4800           ; map this program at $4800

                ;; ------------------------------------------------------------- ;;
                ;;  test code                                                    ;;
                ;; ------------------------------------------------------------- ;;
4800            SDBD                    ; set up an interrupt service routine
4801            MVII    #isr,     R0    ; to do some minimal STIC initialization
4804            MVO     R0,       $100
4806            SWAP    R0
4807            MVO     R0,       $101

4809            EIS                     ; enable interrupts

480A            MVII    #$200,    R4    ; R4 = backtab pointer
480C            CALL    notes           ; invoke our routine

480F            DECR    R7              ; loop forever

                ;; ------------------------------------------------------------- ;;
                ;;  ISR                                                          ;;
                ;; ------------------------------------------------------------- ;;
      isr       PROC

4810            MVO     R0,       $0020 ; enable display

4812            CLRR    R0
4813            MVO     R0,       $0030 ; no horizontal delay
4815            MVO     R0,       $0031 ; no vertical delay
4817            MVO     R0,       $0032 ; no border extension
4819            MVII    #$D,      R0
481B            MVO     R0,       $0028 ; light-blue background
481D            MVO     R0,       $002C ; light-blue border

481F            JR      R5              ; return from ISR

                ENDP

                ;; ------------------------------------------------------------- ;;
                ;;  routine                                                      ;;
                ;; ------------------------------------------------------------- ;;
      notes     PROC

4820            PSHR    R5              ; save return address

4821            SDBD                    ; R5 = pointer to @@chr
4822            MVII    #@@chr,   R5
4825            CLRR    R3              ; R3 = 0 (space)
4826            MVII    #$12,     R0    ; R0 = bitmask = $12
4828            SWAP    R0,       2     ; extend it to $1212

4829  @@loop    MVI@    R5,       R1    ; R1 = next symbol
482A            MVII    #('A'-32)*8, R2 ; R2 = 'A' character

482C  @@note    SARC    R0              ; right shift the bitmask
482D            BC      @@next          ; skip this note if the carry is set

482F            MVO@    R2,       R4    ; append the note
4830            MVO@    R1,       R4    ; append the symbol
4831            MVO@    R3,       R4    ; append a space

4832  @@next    ADDI    #8,       R2    ; advance to the next note
4834            CMPI    #('H'-32)*8, R2 ; is it now a 'H'?
4836            BLT     @@note          ; if not, process the inner loop

4838            TSTR    R1              ; was the symbol a space?
4839            BNEQ    @@loop          ; if not, process the outer loop

483B            PULR    R7              ; return

483C  @@chr     DECLE   ('#'-32)*8      ; '#'
483D            DECLE   ('b'-32)*8      ; 'b'
483E            DECLE   0               ; space

                ENDP

出力

output

jzIntvのスクリーンショット


1. CP-1610オペコードは、「DECLE」として知られる10ビット値でエンコードされます。このルーチンの長さは31 DECLEで、4820ドルで始まり、483Eで終わります(含まれています)。


9

Python 3、50バイト

print(*map(''.join,zip(3*'ADGBCEF',7*' '+5*'#b')))

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

Python 2:48バイト

このコードは、追加バイトなしでB#とCbを含むように調整できます。これは交換することによって達成することができる56


さらに、単なる文字列を出力するよりも(最終的に)短くなります。

Python 3、51バイト

exit('Ab A A# Bb B C C# Db D D# Eb E F F# Gb G G#')

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

Python 2:50バイト


2
これは非常に創造的なソリューションです
TheOnlyMrCat

7

05AB1E16 15 13 バイト

Au…b #âŽ7×bûÏ

@maxbのおかげで-2バイト。

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

リストとして出力します。単一文字のメモには末尾スペースが付きます。

説明:

Au             # Push the lowercase alphabet, and uppercase it
  b #         # Push string "b #"
      â        # Take the cartesian product of both strings to create all possible pairs:
               #  ["Ab","A ","A#","Bb","B ","B#",...,"Zb","Z ","Z#"]
       Ž7×     # Push compressed integer 1999
          b    # Convert it to a binary string "11111001111"
           û   # Palindromize it to "111110011111110011111"
            Ï  # Only leave the notes in the list at the truthy values (1), (the trailing
               # items beyond the length of this binary string are also discarded)
               # (after which the result is output implicitly)

理由を理解するにŽ7×、この05AB1Eのヒント(大きな整数を圧縮する方法?参照してください1999

Ž7×または₄·<、同じバイトカウントに対して(1000、倍、1ずつ減少)にすることもできます。


3
ある本当に必要?それなしで正常に動作するようです。
maxb

6

ゼリー、18?* 20 バイト

ØAḣ7µp⁾b#Żs6ḣ€4ẎḊ;W€

文字のリストのリストを返すモナドリンク。

* (a)文字のリストと(b)文字の混合リストが許容されるW€場合、18 の末尾を削除します。

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

どうやって?

ØAḣ7µp⁾b#Żs6ḣ€4ẎḊ;W€ - Link: no argument
ØA                   - list of characters     [A-Z]
  ḣ7                 - head to 7              "ABCDEFG"
    µ                - new monadic link (call that X)
      ⁾b#            - list of characters     "b#"
     p               - Cartesian product      ["Ab","A#","Bb","B#","Cb","C#","Db","D#","Eb","E#","Fb","F#","Gb","G#"]
         Ż           - prepend a zero       [0,"Ab","A#","Bb","B#","Cb","C#","Db","D#","Eb","E#","Fb","F#","Gb","G#"]
          s6         - split into sixes    [[0,"Ab","A#","Bb","B#","Cb"],["C#","Db","D#","Eb","E#","Fb"],["F#","Gb","G#"]]
            ḣ€4      - head each to 4      [[0,"Ab","A#","Bb"],["C#","Db","D#","Eb"],["F#","Gb","G#"]]
               Ẏ     - tighten              [0,"Ab","A#","Bb","C#","Db","D#","Eb","F#","Gb","G#"]
                Ḋ    - dequeue                ["Ab","A#","Bb","C#","Db","D#","Eb","F#","Gb","G#"]
                  W€ - wrap each (of X)       ["A","B","C","D","E","F","G"]
                 ;   - concatenate            ["Ab","A#","Bb","C#","Db","D#","Eb","F#","Gb","G#","A","B","C","D","E","F","G"]

@mirabilosこれは20バイトのソースコードです。Unicode文字はそれぞれソースコードのバイトを表します- bytesヘッダー内の単語によってリンクされたコードページを参照してください。
ジョナサンアラン




4

、21バイト

Φ⪪⭆…α⁷⭆b #⁺ι벧↨⊖⊘φ²κ

オンラインでお試しください!リンクは、コードの詳細バージョンです。説明:

    α                   Predefined variable uppercase alphabet
   … ⁷                  First 7 letters i.e. `ABCEDFG`
  ⭆                     Map over characters and join
       b #              Literal string `b #`
      ⭆                 Map over characters and join
          ⁺ιλ           Concatenate outer and inner characters
 ⪪           ²          Split back into substrings of length 2
Φ                       Filter where nonzero
                  φ     Predefined variable 1000
                 ⊘      Halved i.e. 500
                ⊖       Decremented i.e 499
               ↨   ²    Converted to base 2 i.e. [1, 1, 1, 1, 1, 0, 0, 1, 1]
              §     κ   Cyclically indexed by outer index
                        Implicitly print matching values on separate lines

3

Japt23 22バイト

;B¯7
ï"b #" fÏÄ %9%8<6

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

;B          Alphabet
  ¯7        First seven characters ("ABCDEFG")
            Assign to U
ï"b #"       Cartesian product with "b #" ("Ab,A ,A#,Bb,B ,B#,Cb,C ,C#,Db,D ,D#,Eb,E ,E#,Fb,F ,F#,Gb,G ,G#")
f           Filter:
 ÏÄ           Is index + 1
   %9%8       Mod 9 Mod 8
     <6       Less than 6
            End filter ("Ab,A ,A#,Bb,B ,C ,C#,Db,D ,D#,Eb,E ,F ,F#,Gb,G ,G#")

コードには含まれて<6いますが<5、説明の中にあります。
TheOnlyMrCat

@TheOnlyMrCat編集
無知の



2

Ruby、43バイト

p (2..18).map{|i|"FCGDAEB"[i%7]+"b #"[i/7]}

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

範囲0..20を指定すると、すべてのフラット、すべてのナチュラル、すべてのシャープを含む配列が印刷されます。不要なものFb Cb E# B#は、範囲を使用して省略されます2..18

メモは次の順序で印刷されます。 https://en.wikipedia.org/wiki/Circle_of_fifthsます。、つまり毎回7半音(周波数比はほぼ正確に1.5)ずつ昇順で。

これにより、指定された音符の文字順が決まります。各音符は、前の音符より5度上(「5番目」と呼ばれます)になります。たとえば、F->CありますFGABC


私はあなたが五分の一まで上昇するのが好きです。いいね
ウェインコンラッド


2

Zsh、36バイト

<<<${${(F):-{A..G}{b,,#}}//[BE]#???}

見苦しい解決策ですが、2文字節約できます。(F)改行のリストに参加し、//[BE]#???必要な文字列の部分を削除します。

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


Zsh、38バイト

<<<${${:-{A..G}{b,,#}}:#([BE]#|[CF]b)}

ZshがPerlを打ち負かしたとき、私はいつもそれを楽しんでいます(うまくいけば私はすぐに話さないでください...)

<<<${${:-{A..G}{b,,#}}:#([BE]#|[CF]b)}
     ${:-             }                 # empty-fallback, basically an anonymous parameter expansion
         {A..G}{b,,#}                   # Cross product range A-G with b,(nothing),#
   ${                 :#             }  # Remove matching elements
                        ([BE]#|[CF]b)   # B#, E#, Cb, Fb
<<<                                     # Print to stdout

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



1

Brachylog、36バイト

"#b"ẹ,Ẹ↺;Ṇh₇ᵗ↔{∋ᵐc}ᶠ⟨h₅ct₁₄⟩⟨h₁₂ct₅⟩

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

私は現在、パワーセットインデックスをブルートフォース処理しているので、それを取り除くことができます⟨h₅ct₁₄⟩⟨h₁₂ct₅⟩(さらに、出力は出力例と同じ順序である必要はないため、拡張機能により)。一方...サブリストが生成される順序を実際に計算し、その方法でインデックスを計算するために少し時間を割く必要があります...




1

Pyth23 21バイト

s<R7c.>*<r1G7"b #"2 9

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

s<R7c.>*<r1G7"b #"2 9   Implicit: G=lowercase alphabet
         r1G            Convert G to upper case
        <   7           First 7 characters
       *     "b #"      Cartesian product with "b #"
     .>           2     Rotate the above 2 places to the right
    c               9   Chop into pieces of length 9
 <R7                    Trim each to length 7
s                       Flatten, implicit print

編集:2バイトを節約するために部分的に書き換え、以前のバージョン:s%2c*<r1G7"b #"xLG"fhoq オンラインで試してみてください!


1

Commodore C64 / TheC64 Mini(おそらく他のCommodore 8ビットBASICバリアント)-52トークン化されたBASICバイト

 0?"{CTRL+N}Ab A A# Bb B C C# Db D D# Eb E F F# Gb GG#

CTRLキープラスを押すNC64キーボードの大文字/小文字の文字セットで「ビジネスモード」になります。これを1バイト/トークンの文字列で出力できます。40列あるため、GからG#までのスペースは不要です。

この場合、文字列を閉じる必要はありません。これは、 :区切り文字です。

これがCommodore C64(および互換)画面でどのように見えるかを以下に示します。

コモドール64音符


1

、43バイト

圧縮された文字列。

AbAA\#BbBCC\#DbDD\#EbEFF\#GbGG\#(:H<[ $]')'

TIO





0

brainfuck255 115バイト

--[----->+<]>-----[<+>>+>+<<-]>>+<<<-[->+++<]>+++[->>>+>+<
<<<]>>>>--->+++++++[-<<<<.>.>>.<<<.>>>.<<<.>>.>.<<<+>>>>]

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


1
私はこれを支持しますが、それは間違っています。BとCの間、またはEとFの間に黒い音はありません。したがって、出力することは想定されていません。B#、Cb、E#、またはFb。また、小文字を使用しても問題ないという仕様には何も表示されません。
レベルリバーセント

@LevelRiverSt BとCとEとFの間にノートがないことを示すチャレンジはどこにもありませんでした
Krzysztof Szewczyk

All notes without a name consisting of a single letter (i.e. black notes on a musical keyboard) should have their name printed twice, once as the sharp of a note, once as the flat of one. Sharp or flat notes that can be described with a single letter, like B♯ (C) or F♭ (E) should not be outputted.それは私にはかなり明らかなようであり、画面上のOPには編集履歴が表示されていません。
レベルリバーセント



0

T-SQL、124バイト

SELECT value+a
FROM STRING_SPLIT('A-B-C-D-E-F-G','-')
    ,(VALUES('b'),(''),('#'))b(a)
WHERE value+a NOT IN ('B#','E#','Cb','Fb')

改行は表示のみを目的としています。

長いが、簡単なバージョン(50バイト)よりもはるかに興味深い:

PRINT'Ab,A,A#,Bb,B,C,C#,Db,D,D#,Eb,E,F,F#,Gb,G,G#'

0

Z80Golf31 29バイト

00000000: 9d5b dc6d df7f 0603 3e40 d13c cb3a 3008  .[.m....>@.<.:0.
00000010: fff5 7b2f ffaf fff1 20f1 10ec 76         ..{/.... ...v

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

説明

Z80Golfは、Z80 8ビットCPUに基づくシンプルなファンタジーマシンです。プログラムはメモリ位置0x0000にロードされ、残りのメモリはゼロで埋められます。出力はを呼び出すこと0x8000で行われ、レジスタAの値が文字として出力されます。

プログラムは、処理されるデータ、合計6バイトから始まります。バイトの各ペアは、音符の接尾辞と、この音符と組み合わせることができる文字を制御するビットマスクを指定します。バイトを節約するために、サフィックス文字が反転されます(xor 0xff)-これにより、ほとんど副作用のない命令としてデータを実行でき、このデータをスキップするジャンプを削除できます。

               ;    GFEDCBA
    db 0xff^'b', 0b01011011 ; Ab Bb Db Eb Gb
    db 0xff^'#', 0b01101101 ; A# C# D# F# G#
    db 0xff^' ', 0b01111111 ; A  B  C  D  E  F  G
skip_data:

これはCPUがこれをデコードする方法です:

    sbc a, l  ; a subtraction with carry on registers we don't care about
    ld e, e   ; put the E register back into itself. This instruction is useless
              ; but still exists to make the encoding regular.
    call c, 0xdf6d ; if the carry flag is set, call a function. The carry flag isn't set
              ; because of the initial register values (all zeroes) when the sbc above
              ; was executed
    ld a, a   ; as above, put A back into itself.

このデータは、一度に2バイトずつDEレジスタペアに読み込まれます。スタックポインターは、次の要素を指すために使用されます。それは0から始まり、Z80は完全な下降スタックを使用するため、ポップは次のデータペアを読み取ります。すべてのスタック操作は16ビットです。

外側のループは、Bレジスタのデクリメントカウンターを使用して実装されます。Z80は、そのためにdjnz命令形式で特別なサポートを提供します。

    ld b, 3
process_pair:
    ...
    djnz process_pair
    halt

現在の手紙はAレジスタに保持されています。増分はループの開始時にうまく適合するため、実際の開始値より1つ少ない値をロードしますA

process_pair:
    ld a, 'A'-1
    pop de ; D = bitmask, E = suffix character
process_note:
    inc a
    srl d ; put the current bitmask bit in the carry flag
          ; also sets the zero flag if this is the last note in the pair
    jr nc, skip
    ; Print the note. Note that we need to preserve the zero flag to check it in the
    ; loop condition later.
    rst $38 ; Short encoding of call $0038.
            ; Because the program is so short, the memory in the 0038..8000 range
            ; is filled with zeroes, which happens to be the encoding for a no-op.
            ; The execution will therefore fall-through to the character-print hook.
    push af ; Save the letter on the stack (which will be just to the left of the
            ; unprocessed data) to free up A for printing other characters.
            ; (only 16-bit register pairs can be saved, so we also push the flags)
    ld a, e
    cpl     ; Undo the inversion used to make the execution fall-through the data.
            ; Done again each iteration because it takes less bytes to operate
            ; on the A register.
    rst $38 ; Print the suffix.
    xor a   ; Standard assembly practice of setting a register to zero by XORing it
            ; with itself. Saves a byte over a simple `ld a, 0`.
    rst $38 ; Print a null byte as a separator.
    pop af  ; Restore the current letter from the stack.
skip:
    jr nz, process_note ; If the zero flag (last changed at the srl d) is not set,
                        ; loop once again
    djnz process_pair
    halt
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.