r/ProgrammerHumor • • Jan 16 '14

[deleted by user]

[removed]

1.3k Upvotes

446 comments sorted by

View all comments

Show parent comment

1

u/FeepingCreature Jan 17 '14

Here's an O(n^2) algorithm (n = 100)

let lookupList = ["1", "2", "Fizz", "4", "Buzz", "Fizz" ...]
for i in 0..100
  let res = ""
  ; for k in 0..100 ;search through the lookup list
  for k in 0..i+1 ;OPTIMIZATION - don't check positions we cannot have reached yet
    if i == k ;if reached the right position
      res = lookupList[k] ;fetch the data
    fi
  end
  print res
end