Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
manman4 committed Dec 20, 2020
1 parent 61dfaa4 commit 312ba42
Show file tree
Hide file tree
Showing 194 changed files with 5,976 additions and 5,982 deletions.
54 changes: 27 additions & 27 deletions 15/150102_01/150102_01.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
def calc(num1, num2, operator)
a, b = num1.to_f, num2.to_f
return a + b if operator == "+"
return a - b if operator == "-"
return a * b if operator == "*"
return a / b if operator == "/"
end

def solveRPN(str)
stack = []
datas = str.split(" ")
datas.each{|data|
# dataが数字のとき
if data =~ /\d/
stack << data
# dataが記号のとき
else
p2 = stack.pop
p1 = stack.pop
stack << calc(p1, p2, data)
end
}
stack
end

puts solveRPN("10 4 3 + 2 * -")
puts solveRPN("12 2 / 3 /")
def calc(num1, num2, operator)
a, b = num1.to_f, num2.to_f
return a + b if operator == "+"
return a - b if operator == "-"
return a * b if operator == "*"
return a / b if operator == "/"
end

def solveRPN(str)
stack = []
datas = str.split(" ")
datas.each{|data|
# dataが数字のとき
if data =~ /\d/
stack << data
# dataが記号のとき
else
p2 = stack.pop
p1 = stack.pop
stack << calc(p1, p2, data)
end
}
stack
end

puts solveRPN("10 4 3 + 2 * -")
puts solveRPN("12 2 / 3 /")
18 changes: 9 additions & 9 deletions 15/150625/150625.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
# ROT13
p str.tr("A-Za-z", "N-ZA-Mn-za-m")
p str.tr("A-Za-z", "N-ZA-Mn-za-m").tr("A-Za-z", "N-ZA-Mn-za-m")
p str.tr("\x41-\x5a\x61-\x7a", "\x4e-\x5a\x41-\x4d\x6e-\x7a\x61-\x6d")
p str.tr("\x41-\x5a\x61-\x7a", "\x4e-\x5a\x41-\x4d\x6e-\x7a\x61-\x6d").tr("\x41-\x5a\x61-\x7a", "\x4e-\x5a\x41-\x4d\x6e-\x7a\x61-\x6d")
# ROT47
p str.tr("\x21-\x7e", "\x50-\x7e\x21-\x4f")
p str.tr("\x21-\x7e", "\x50-\x7e\x21-\x4f").tr("\x21-\x7e", "\x50-\x7e\x21-\x4f")
str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
# ROT13
p str.tr("A-Za-z", "N-ZA-Mn-za-m")
p str.tr("A-Za-z", "N-ZA-Mn-za-m").tr("A-Za-z", "N-ZA-Mn-za-m")
p str.tr("\x41-\x5a\x61-\x7a", "\x4e-\x5a\x41-\x4d\x6e-\x7a\x61-\x6d")
p str.tr("\x41-\x5a\x61-\x7a", "\x4e-\x5a\x41-\x4d\x6e-\x7a\x61-\x6d").tr("\x41-\x5a\x61-\x7a", "\x4e-\x5a\x41-\x4d\x6e-\x7a\x61-\x6d")
# ROT47
p str.tr("\x21-\x7e", "\x50-\x7e\x21-\x4f")
p str.tr("\x21-\x7e", "\x50-\x7e\x21-\x4f").tr("\x21-\x7e", "\x50-\x7e\x21-\x4f")
38 changes: 19 additions & 19 deletions 15/150830_01/150830_01.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
@ary = ('A'..'Z').to_a

# y = a * x + b
def affine(a, b, str)
h = {}
(0..25).each{|i| h[@ary[i]] = @ary[(a * i + b) % 26]}
(0..str.size - 1).each{|i| str[i] = h[str[i]]}
str
end

def decode(a, b, str)
g = {}
(0..25).each{|i| g[@ary[(a * i + b) % 26]] = @ary[i]}
(0..str.size - 1).each{|i| str[i] = g[str[i]]}
str
end

p affine(5, 11, 'THEMAGICWORDSARESQUEAMISHOSSIFRAGE')
p decode(5, 11, 'CUFTLPZVRDSAXLSFXNHFLTZXUDXXZKSLPF')
@ary = ('A'..'Z').to_a

# y = a * x + b
def affine(a, b, str)
h = {}
(0..25).each{|i| h[@ary[i]] = @ary[(a * i + b) % 26]}
(0..str.size - 1).each{|i| str[i] = h[str[i]]}
str
end

def decode(a, b, str)
g = {}
(0..25).each{|i| g[@ary[(a * i + b) % 26]] = @ary[i]}
(0..str.size - 1).each{|i| str[i] = g[str[i]]}
str
end

p affine(5, 11, 'THEMAGICWORDSARESQUEAMISHOSSIFRAGE')
p decode(5, 11, 'CUFTLPZVRDSAXLSFXNHFLTZXUDXXZKSLPF')
42 changes: 21 additions & 21 deletions 15/150830_02/150830_02.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
@ary = ('A'..'Z').to_a

# y = a * x + b
def affine(a, b, str)
h = {}
(0..25).each{|i| h[@ary[i]] = @ary[(a * i + b) % 26]}
(0..str.size - 1).each{|i| str[i] = h[str[i]]}
str
end

def decode(a, b, str)
g = {}
(0..25).each{|i| g[@ary[(a * i + b) % 26]] = @ary[i]}
(0..str.size - 1).each{|i| str[i] = g[str[i]]}
str
end

(0..11).each{|i|
p affine(7 ** i, 0, @ary.join)
}

@ary = ('A'..'Z').to_a

# y = a * x + b
def affine(a, b, str)
h = {}
(0..25).each{|i| h[@ary[i]] = @ary[(a * i + b) % 26]}
(0..str.size - 1).each{|i| str[i] = h[str[i]]}
str
end

def decode(a, b, str)
g = {}
(0..25).each{|i| g[@ary[(a * i + b) % 26]] = @ary[i]}
(0..str.size - 1).each{|i| str[i] = g[str[i]]}
str
end

(0..11).each{|i|
p affine(7 ** i, 0, @ary.join)
}
Loading

0 comments on commit 312ba42

Please sign in to comment.