forked from crystal-tr/old_tr.crystal-lang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a shorter but better sample code in the homepage
- Loading branch information
Ary Borenszweig
committed
Jun 7, 2015
1 parent
81bcea9
commit dfb409b
Showing
1 changed file
with
6 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,11 @@ | ||
{% highlight ruby %} | ||
# Compute prime numbers up to 100 with the Sieve of Eratosthenes | ||
max = 100 | ||
# A very basic HTTP server | ||
require "http/server" | ||
|
||
sieve = Array.new(max + 1, true) | ||
sieve[0] = false | ||
sieve[1] = false | ||
|
||
(2...max).each do |i| | ||
if sieve[i] | ||
(2 * i).step(max, i) do |j| | ||
sieve[j] = false | ||
end | ||
end | ||
server = HTTP::Server.new(8080) do |request| | ||
HTTP::Response.ok "text/plain", "Hello world!" | ||
end | ||
|
||
sieve.each_with_index do |prime, number| | ||
puts number if prime | ||
end | ||
puts "Listening on http://0.0.0.0:8080" | ||
server.listen | ||
{% endhighlight %} |