Skip to content

Instantly share code, notes, and snippets.

View styd's full-sized avatar
🏡
Working From Home

Adrian Setyadi styd

🏡
Working From Home
  • Bekasi, Indonesia
  • 23:33 (UTC +07:00)
View GitHub Profile
@styd
styd / Prime.rb
Last active October 12, 2017 10:50
A stupid job post on Upwork asking to write this. An easy US$ 8 I missed (didn't get the job). :(
#!/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
@styd
styd / Josephus.rb
Last active November 13, 2017 10:09
Josephus Problem
#!/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
@styd
styd / Palindrome.rb
Last active November 16, 2017 09:54
Strict and non-strict palindrome. Default is not strict.
#!/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]/

Keybase proof

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: