cancel
Showing results for 
Search instead for 
Did you mean: 
SJT
Valued Contributor
Valued Contributor

Q derives from the mathematical notation Ken Iverson developed at Harvard. Years before, when Ken was a young man in Alberta, a farmer he worked for asked him if he knew how to use a certain tool. Ken didn’t. “Well,” said the farmer, “you won’t learn it younger.” 

Amending past folly, I’ve hired someone to teach me guitar at last. Part of my homework is to map notes to the frets on the guitar neck. Here’s my assignment. Can you complete it as a single expression in q?

My guitar homeworkMy guitar homework

 

4 Comments
rak1507
New Contributor III

Is it possible to have an example? Notes can map to multiple spots, so it is unclear.

cillianreilly
New Contributor III
q)progression:"C#D#EF#G#A#B"
q)notes:flip progression mod[;12]til[13]+/:progression?
q)notes"EADGBE"
"EADGBE"
"F###CF"
"#BEA##"
"GCF#DG"
"###B##"
"ADGCEA"
"####F#"
"BEAD#B"
"CF##GC"
"##BE##"
"DGCFAD"
"######"
"EADGBE"

First row is the open strings, and runs as far as the 12th fret, at which point the pattern repeats. Also works for alternative tunings:

q)notes"DADGBE"    // Drop D
q)notes"DADGAD"    // DADGAD
davidcrossey
Moderator Moderator
Moderator

Very nice @cillianreilly !
Just to make your solution visually easier to read, I've casted to symbols:

q)progression:`$("C";"C#";"D";"D#";"E";"F";"F#";"G";"G#";"A";"A#";"B")
q)notes:flip progression mod[;12]til[13]+/:progression?
q)notes `$'"EADGBE"
E  A  D  G  B  E
F  A# D# G# C  F
F# B  E  A  C# F#
G  C  F  A# D  G
G# C# F# B  D# G#
A  D  G  C  E  A
A# D# G# C# F  A#
B  E  A  D  F# B
C  F  A# D# G  C
C# F# B  E  G# C#
D  G  C  F  A  D
D# G# C# F# A# D#
E  A  D  G  B  E

And to satisfy @SJT for a one-liner, condensed as:

{flip x mod[;12]til[13]+/:x?y}[`$("C";"C#";"D";"D#";"E";"F";"F#";"G";"G#";"A";"A#";"B");`$'"EADGBE"]

Look forward to seeing how others approach this problem.

SJT
Valued Contributor
Valued Contributor

Love the train of unaries, @cillianreilly !

My teacher made something of C# also being D♭, so 

 

q)note:{flip(x?`$'y)rotate\:x}[`$"`"vs"C`C#|Db`D`D#|Eb`E`F`F#|Gb`G`G#|Ab`A`A#|Bb`B"]
q)note "EADGBE"
E     A     D     G     B     E
F     A#|Bb D#|Eb G#|Ab C     F
F#|Gb B     E     A     C#|Db F#|Gb
G     C     F     A#|Bb D     G
G#|Ab C#|Db F#|Gb B     D#|Eb G#|Ab
A     D     G     C     E     A
A#|Bb D#|Eb G#|Ab C#|Db F     A#|Bb
B     E     A     D     F#|Gb B
C     F     A#|Bb D#|Eb G     C
C#|Db F#|Gb B     E     G#|Ab C#|Db
D     G     C     F     A     D
D#|Eb G#|Ab C#|Db F#|Gb A#|Bb D#|Eb

 

 

Contributors