-
-
Save manveru/5716970 to your computer and use it in GitHub Desktop.
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
#!/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