首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >做一个随机的鼓环

做一个随机的鼓环
EN

Code Golf用户
提问于 2020-01-07 00:31:14
回答 4查看 581关注 0票数 14

随机生成的鼓环听起来好吗?

drum循环5\times 32矩阵A,由1s和0s组成

  1. A_{1,1}=A_{1,17}=A_{2,9}=A_{2,25}=1
  2. 对于每一个ii第四行都有完全不同的1s,其中f(1)=3, f(2)=2, f(3)=6, f(4)=8, f(5)=5
  3. 对于每个j\equiv 1\bmod 4jth列正好有一个1,并且
  4. 对于每个j\not\equiv 1\bmod 4j第四列最多只有一个1

在这里,行为五个鼓中的每一个提供指令,每一列代表一个节拍。特别是,第一行对应于踢,而第二行对应于圈套。

编写最短的代码,从一组鼓循环中均匀地绘制矩阵。

可以随意使用您的代码来绘制一个随机的鼓循环,在本网站上实现鼓循环,然后在您的文章中发布一个指向您的创建的链接。(请注意,我们只使用这个在线节拍器的前5行。)

Edit 1:我们使用的是基于1的索引:行索引是\{1,\ldots,5\},列索引是\{1,\ldots,32\}

Edit 2:从当前提交的文件来看,我最初问题的答案似乎是“是的”:随机生成的鼓环听起来不错。下面是指向当前示例的链接:

EN

回答 4

Code Golf用户

发布于 2020-01-07 10:32:45

05AB1E,65 字节数

代码语言:javascript
复制
31Ý©8ˆ24ˆ40¯ǝ0ˆ16ˆ®¯KΩˆ48¯¦¦ǝ•Wk¤]•3ôεćи}˜.ržw8и«®¯K.r.¡4Ö}é˜ǝb€¦

输出作为字符串的转置列表。

在网上试试。 (页脚漂亮-将其打印为预期的行/列)。请随意删除页脚以查看实际结果。)

解释:

代码语言:javascript
复制
31Ý                # Push a list in the range [0,31]
   ©               # Store it in variable `®` (without popping)
8ˆ                 # Add 8 to the global array
  24ˆ              # Add 24 to the global array as well
     40¯ǝ          # Replace the values at the indices of the global array with 40
0ˆ                 # Add 0 to the global array
  16ˆ              # Add 16 to the global array as well
     ®             # Push the [0,31] list from variable `®` again
      ¯K           # Remove all values of the global array (the [0,8,16,24])
        Ω          # Pop and push a random index from this list
         ˆ         # Add it to the global array as well
            ¯¦¦    # Push the global array with the first two (8,24) removed
          48   ǝ   # Replace the values at the remaining three indices with 48
•Wk¤]•             # Push compressed integer 533636834
      3ô           # Split it into parts of size 3: [533,636,834]
        ε          # Map over each integer
         ć         #  Extract head; pop and push remainder and head
          и        #  Repeat the remainder the head amount of times
                   #   i.e. 533 becomes [33,33,33,33,33]
        }˜         # After the map: flatten the list of list of integers
          .r       # And randomly shuffle it
            žw8и   # Then push a list of 8 32s
                «  # And merge it to the end of the list
®                  # Push the [0,31] list from variable `®` again
 ¯K                # Remove all indices stored in the global array
                   # (the [0,8,16,24] and one random index)
   .r              # Randomly shuffle these remaining indices
     .¡            # Group the remaining indices by:
       4Ö          #  Where this (0-based) index is divisible by 4
                   #  (which would be i % 4 == 1 for the corresponding 1-based index)
     }é            # After the group by, sort the two inner lists by length,
                   # so the indices divisible by 4 are before the other indices
       ˜           # And flatten it to a single list
ǝ                  # Then insert the shuffled integers at those shuffled indices
 b                 # Convert each integer to a binary string
                   # (32=100000;33=100001;34=100010;36=100100;40=101000;48=110000)
  €¦               # And then remove the leading "1" from each
                   # (after which the resulting list is output implicitly)

看这个05AB1E我的尖端(部分)如何压缩大整数?)来理解为什么•Wk¤]•533636834

票数 1
EN

Code Golf用户

发布于 2020-01-07 18:23:25

果冻,43字节

代码语言:javascript
复制
32s8Zs4ZḢ;FẊḣ⁴ƲƊḢŒœ;FẊ$ƲFṙ-“¥©€Þı‘œṖ;¹Ṭz0ZṖ

在网上试试!

返回代表鼓循环的1s和0的32x5矩阵的niladic链接。页脚只需将其连在一起并用换行符分隔。

解释

代码语言:javascript
复制
32                                          | 32
  s8                                        | Split into groups of 8
    Z                                       | Transpose
     s4                                     | Split into groups of 4
       Z                                    | Transpose
               Ɗ                            | Following as a monad:
        Ḣ                                   | - Head
         ;    Ʋ                             | - Concatenate to following as a monad:
          F                                 |   - Flatten
           Ẋ                                |   - Shuffle list
            ḣ⁴                              |   - First 16
                       Ʋ                    | Following as a monad:
                Ḣ                           | - Head
                 Œœ                         | - Odd/even indexed items
                   ;  $                     | - Concatenate to:
                    F                       |   - Remainder of list flattened
                     Ẋ                      |   - Shuffled
                        F                   | Flatten
                         ṙ-                 | Rotate right 1 item
                           “¥©€Þı‘œṖ        | Split list before positions 4, 6, 12, 20, 25
                                    ;¹      | Concatenate to 32 (because 32 was the beginning of this niladic link)
                                      Ṭ     | Convert from lists of numeric indices to logical lists with 1s at those positions
                                       z0   | Transpose with 0 as filler
                                         Z  | Transpose
                                          Ṗ | Remove last (the sixth list introduced with the 32 above)
票数 1
EN

Code Golf用户

发布于 2020-01-07 20:48:54

Python 3,180个字节

代码语言:javascript
复制
from random import*
r=range
s=sample
a=s(s([x for x in r(32)if x%4],16)+[x*8+4 for x in r(4)],20)
print([[i in t for i in r(32)]for t in[[0,16,a[0]],[8,24],a[1:7],a[7:15],a[15:]]])

在网上试试!

打印表示鼓循环的逻辑矩阵。

票数 1
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/197757

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档