Created
November 26, 2017 21:00
-
-
Save kylebrandt/1beabdb76ebd8fb941dc0d1ff29b4a49 to your computer and use it in GitHub Desktop.
drum limb combinations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/bits" | |
"sort" | |
) | |
type Limb byte | |
const ( | |
RH Limb = 1 << iota | |
LH | |
RF | |
LF | |
) | |
func (l Limb) Count() int { | |
return bits.OnesCount(uint(l)) | |
} | |
func (l Limb) StrikeString() string { | |
s := make([]string, 4) | |
if l&RH != 0 { | |
s[0] = "RH" | |
} | |
if l&LH != 0 { | |
s[1] = "LH" | |
} | |
if l&RF != 0 { | |
s[2] = "RF" | |
} | |
if l&LF != 0 { | |
s[3] = "LF" | |
} | |
return fmt.Sprintf("%-2s %-2s %-2s %-2s", s[0], s[1], s[2], s[3]) | |
} | |
func main() { | |
sets := []Limb{} | |
for i := 1; i < 16; i++ { | |
if Limb(i).Count() == 1 { | |
continue | |
} | |
sets = append(sets, Limb(i)) | |
} | |
sort.Slice(sets, func(i, j int) bool { return sets[i].Count() < sets[j].Count() }) | |
for i := len(sets) - 1; i >= 0; i-- { | |
fmt.Println(sets[i].StrikeString()) | |
} | |
} | |
/* | |
String Sort | |
RH LH RF LF | |
RH LH RF | |
RH LH LF | |
RH LH | |
RH RF LF | |
RH RF | |
RH LF | |
LH RF LF | |
LH RF | |
LH LF | |
RF LF | |
Limb Count Sort | |
4x1 | |
RH LH RF LF | |
3x4 | |
LH RF LF | |
RH RF LF | |
RH LH LF | |
RH LH RF | |
2x6 | |
RF LF | |
LH LF | |
RH LF | |
LH RF | |
RH RF | |
RH LH | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment