- Twitter: @tomcha_
- 趣味でプログラム書いてます。普段はワードとかエクセル(方眼紙じゃなくて表計算の方)で仕事してます。
- Perl入学式サポーター。
- なにわPerl主催。
This file contains hidden or 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 = 0 | |
| def skip(list, n) | |
| if list.size == 0 | |
| list | |
| elsif n == 0 | |
| list | |
| else | |
| list.shift | |
| skip(list, n - 1 ) |
This file contains hidden or 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
| pro = Proc.new{|n| n % 2 == 0 ? true : false} | |
| list = [3, 5, 6, 8, 1] | |
| def find(list, pro) | |
| if list.size == 0 | |
| return nil | |
| else | |
| i = list.shift | |
| return i if pro.call(i) |
This file contains hidden or 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
| pro = Proc.new{|n| n % 2 == 0 ? true : false} | |
| #list = [2, 4, 6, 8] | |
| list = [3, 5, 7, 9] | |
| def exists(list, pro) | |
| if list.size == 0 | |
| false | |
| elsif list.size == 1 | |
| pro.call(list.shift) | |
| else |
This file contains hidden or 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
| pro = Proc.new{|n| n % 2 == 0 ? true : false} | |
| list = [2, 4,9, 6, 8 ] | |
| #p pro.call(5) | |
| def forall(list, pro) | |
| if list.size == 1 | |
| pro.call(list.shift) | |
| else | |
| pro.call(list.shift) && forall(list, pro) |
This file contains hidden or 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 = [5, 8, 2, 3] | |
| def min(list) | |
| if list.size == 1 | |
| list.shift | |
| else | |
| i = list.shift | |
| list[0] = i if i < list[0] | |
| min(list) | |
| end |
This file contains hidden or 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 = [5, 8, 2, 3] | |
| def max(list) | |
| if list.size == 1 | |
| list.shift | |
| else | |
| i = list.shift | |
| list[0] = i if list[0] < i | |
| max(list) | |
| end |
This file contains hidden or 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] | |
| def length(list) | |
| if list.size == 0 | |
| 0 | |
| else | |
| list.shift | |
| 1 + length(list) | |
| end |
This file contains hidden or 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] | |
| def sum(nums) | |
| if nums.size == 0 | |
| 0 | |
| else | |
| n = nums.shift | |
| n + sum(nums) | |
| end | |
| end |
This file contains hidden or 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
| import Foundation | |
| for i in (1...100){ | |
| var str : String = "" | |
| var randThree = arc4random_uniform(3) | |
| var randFive = arc4random_uniform(5) | |
| if (randThree == 0){ | |
| str = "Fizz" | |
| } | |
| if (randFive == 0){ |