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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
my $kyo = <<"EOS"; | |
ココニ | |
経典ヲ | |
記述セヨ | |
EOS |
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
#!/usr/bin/env ruby | |
# coding:utf-8 | |
list = [1, 2, 3, 4] | |
sumproc = Proc.new{|initval, enum| | |
initval + enum | |
} | |
minproc = Proc.new{|initval, enum| |
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
list = [1, 3, 5] | |
pro = Proc.new{|i| | |
arr ||= [] | |
(0..i).each do |j| | |
arr << j | |
end | |
arr | |
} | |
def collect(list, pro) |
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
list = [1, 3, 5] | |
#pro = Proc.new{|i| 0..i } | |
pro = Proc.new{|i| | |
res ||= [] | |
(0..i).each do |j| | |
res << j | |
end | |
res | |
} |
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
list = [1, 2, 3, 4, 5, 6, 7] | |
pro = Proc.new{|i| i % 2 == 0 ? true : false} | |
def partition(list, pro) | |
@tlist ||= [] | |
@flist ||= [] | |
if list.size == 0 | |
[@tlist, @flist] | |
else | |
i = list.shift |
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
list = [1, 2, 3, 4, 5, 6] | |
pro = Proc.new{|i| i % 2 == 0 ? true : false} | |
def filter(list, pro) | |
@newlist ||= [] | |
if list.size == 0 | |
@newlist | |
else | |
i = list.shift | |
@newlist << i if pro.call(i) |
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
list = [1, 2, 3, 4, 5] | |
pro = Proc.new{|i| i * 2} | |
class Map | |
def self.map(list, pro) | |
@newlist ||= [] | |
if list.size == 0 | |
@newlist | |
else | |
i = list.shift |
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
list = [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
n = 3 | |
pro = Proc.new{|n| n % 2 == 0 ? true : false} | |
class Rec | |
def self.whileTake(list, n, pro) | |
@newlist ||= [] | |
if list.size == 0 | |
@newlist | |
elsif n == 0 |
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
list = [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
n = 3 | |
pro = Proc.new{|n| n % 2 == 0 ? true : false} | |
def whileSkip(list, n, pro) | |
if list.size == 0 | |
list | |
elsif n == 0 | |
list | |
else |
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
list = [1, 2, 3, 4, 5, 6, 7] | |
n = 3 | |
def take(list , n) | |
if list.size < n | |
list | |
elsif list.size == n | |
list | |
else | |
list.pop |