-
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.
- Loading branch information
Showing
194 changed files
with
5,976 additions
and
5,982 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,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 /") |
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,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") |
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,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') |
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,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) | ||
} | ||
Oops, something went wrong.