Skip to content

Instantly share code, notes, and snippets.

@manveru
Forked from jcoene/gist:5034155
Last active December 18, 2015 03:19
Show Gist options
  • Save manveru/5716970 to your computer and use it in GitHub Desktop.
Save manveru/5716970 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# This program adds up the numbers 1 through 10,000 using 100 threads.
# Challenge A: Does this solution have any problems? If so, explain.
# Challenge B: Propose an alternate implementation that does not use threads.
n = 10000
p (1..n).reduce(:+) # by iteration
p (n / 2) * (n + 1) # by math
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment