随机生成的鼓环听起来好吗?
drum循环是5\times 32矩阵A,由1s和0s组成
A_{1,1}=A_{1,17}=A_{2,9}=A_{2,25}=1,i,i第四行都有完全不同的1s,其中f(1)=3, f(2)=2, f(3)=6, f(4)=8, f(5)=5,j\equiv 1\bmod 4,jth列正好有一个1,并且j\not\equiv 1\bmod 4,j第四列最多只有一个1。在这里,行为五个鼓中的每一个提供指令,每一列代表一个节拍。特别是,第一行对应于踢,而第二行对应于圈套。
编写最短的代码,从一组鼓循环中均匀地绘制矩阵。
可以随意使用您的代码来绘制一个随机的鼓循环,在本网站上实现鼓循环,然后在您的文章中发布一个指向您的创建的链接。(请注意,我们只使用这个在线节拍器的前5行。)
Edit 1:我们使用的是基于1的索引:行索引是\{1,\ldots,5\},列索引是\{1,\ldots,32\}。
Edit 2:从当前提交的文件来看,我最初问题的答案似乎是“是的”:随机生成的鼓环听起来不错。下面是指向当前示例的链接:
发布于 2020-01-07 10:32:45
31Ý©8ˆ24ˆ40¯ǝ0ˆ16ˆ®¯KΩˆ48¯¦¦ǝ•Wk¤]•3ôεćи}˜.ržw8и«®¯K.r.¡4Ö}é˜ǝb€¦输出作为字符串的转置列表。
在网上试试。 (页脚漂亮-将其打印为预期的行/列)。请随意删除页脚以查看实际结果。)
解释:
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。
发布于 2020-01-07 18:23:25
32s8Zs4ZḢ;FẊḣ⁴ƲƊḢŒœ;FẊ$ƲFṙ-“¥©€Þı‘œṖ;¹Ṭz0ZṖ返回代表鼓循环的1s和0的32x5矩阵的niladic链接。页脚只需将其连在一起并用换行符分隔。
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)https://codegolf.stackexchange.com/questions/197757
复制相似问题