News for hackers. Stuff that matters.
Re:The Circle of Fifths, Part One by Tycho on Sunday November 25, 2012 @07:58AM (#4828049)
i'd like to see it written without a loop, using map or filter...
Re:The Circle of Fifths, Part One by tinco on Sunday November 25, 2012 @11:14AM (#4828425)
Alright, time to fire up ghci then.. it doesn't work with map or filter, but you get the idea:

  notes = concat $ repeat ["c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b"]
  majorSteps = [1,1,0,1,1,1,0]

  scale key steps =
      key : skip notesFromKey majorSteps
    where
      (_:notesFromKey) = dropWhile ((/=) key) notes

  skip list skips =
      fst $ foldl next ([], list) skips
    where
      next (m, xs) s = (m ++ [xs !! s], drop (s + 1) xs)
edit: cleaned it up a lot. This is Haskell by the way. The loop is replaced by a 'fold' in the skip function that reduces the list by skipping through it taking the skip distances from the skips argument.
Re:The Circle of Fifths, Part One by mifrai on Wednesday November 28, 2012 @05:48PM (#4845228)
Similar concept but a little simpler and avoids manually written recursion.

  notes = cycle ["c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b"]
  majorSteps = [2, 2, 1, 2, 2, 2] :: [Int]

  scale note = map (dropWhile (/= note) notes !!) . scanl (+) 0
I think it's less clear, but if you want to avoid the rescan via (!!), then

  scale note = map head . scanl (flip drop) (dropWhile (/= note) notes)
Both result in

  λ> scale "d" majorSteps
  ["d","e","f#","g","a","b","c#"]
Re:The Circle of Fifths, Part One by kroger on Sunday November 25, 2012 @01:52PM (#4828862)
You can se a solution in Python here: http://news.ycombinator.com/item?id=4828828