Skip to content

Instantly share code, notes, and snippets.

@tasuten
Created September 20, 2013 18:37
Show Gist options
  • Save tasuten/6641868 to your computer and use it in GitHub Desktop.
Save tasuten/6641868 to your computer and use it in GitHub Desktop.
挑戦者求む!【言語指定】Restricted Words by @cielavenir cielavenir│CodeIQ https://codeiq.jp/ace/cielavenir/q431 の私の回答です。
#!/usr/bin/env ruby
# encoding : utf-8
# Timeの現在時刻のUNIXタイムから、まず0と1を作る
time = Time.now.to_i
zero = time
one = time
if time.zero?
# zero = time
one = - ~time # ~0が-1なのでそのまた-で+1
else
zero = time - time
one = (time ** zero).abs # timeが負ならばtime ** zeroは-1となるのでabs
end
# 2, 4, 8, 16, 32, 64を作る
two = one + one
four = two * two
eight = four * two
sixteen = eight * two
thirtytwo = sixteen * two
sixtyfour = thirtytwo * two
# 配列に、上記の1, 2, 4, 8, 32, 64を使ってASCIIコードの値を直に計算値として入れていく
str = Array.new
str.push(sixtyfour + eight) # H
str.push(sixtyfour + thirtytwo + four + one) # e
str.push(sixtyfour + thirtytwo + eight + four) # l
str.push(sixtyfour + thirtytwo + eight + four) # l
str.push(sixtyfour + thirtytwo + eight + four + two + one) # o
str.push(thirtytwo) # SP
str.push(sixtyfour + sixteen + four + two + one) # W
str.push(sixtyfour + thirtytwo + eight + four + two + one) # o
str.push(sixtyfour + thirtytwo + sixteen + two) # r
str.push(sixtyfour + thirtytwo + eight + four) # l
str.push(sixtyfour + thirtytwo + four) # d
str.push(eight + two) # LF
# 出来た配列を順にASCII文字として表示していく
str.each { |c| print c.chr }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment