I hereby claim:
- I am styd on github.
- I am styd (https://keybase.io/styd) on keybase.
- I have a public key ASAnzyUjJAHKFwcivUpUxNg_jSZWczIGOt0DN1QJIpvx7wo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
The goal of this is to have an easily-scannable reference for the most common syntax idioms in Ruby and Rust so that programmers most comfortable with Ruby can quickly get through the syntax differences and feel like they could read and write basic Rust programs.
What do you think? Does this meet its goal? If not, why not?
Ruby:
#!/usr/bin/env ruby | |
class String | |
def palindrome?(strict = false) | |
return true if length.zero? || length == 1 | |
i = -1 | |
j = length | |
length.times do | |
loop do | |
i += 1 | |
break if strict || self[i] =~ /[A-z0-9]/ |
#!/usr/bin/env ruby | |
# | |
# Josephus Problem | |
# https://www.youtube.com/watch?v=uCsD3ZGzMgE | |
# | |
def who_will_live?(n) | |
a = 1 | |
begin | |
a <<= 1 | |
end until a > n |
#!/usr/bin/env ruby | |
print "Enter a number: " | |
input = gets.to_i | |
divisors = [] | |
(2...input).each do |i| | |
divisors << i if input % i == 0 | |
end | |
if divisors.empty? | |
puts "#{input} is a prime number" | |
else |