-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Extended the Array unroll-operator (
»op«
) to work with arrays of …
…different sizes Example: [1,2,3] »+« [1]; # => [1+1, 2+1, 3+1] [1,2,3] »+« [1,2]; # => [1+1, 2+2, 3+1] new file: scripts/Rosettacode/Partial_function_application.sf new file: scripts/vigenere_cipher.sf
- Loading branch information
trizen
committed
Sep 10, 2015
1 parent
4ad3793
commit 3b8612a
Showing
4 changed files
with
54 additions
and
2 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
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/ruby | ||
|
||
# | ||
## http://rosettacode.org/wiki/Partial_function_application | ||
# | ||
|
||
func fs(f) { | ||
closure func(*args) { | ||
args.map {f(_)} | ||
} | ||
} | ||
|
||
func double(n) { n * 2 }; | ||
func square(n) { n ** 2 }; | ||
|
||
var fs_double = fs(double); | ||
var fs_square = fs(square); | ||
|
||
var s = (0 .. 3); | ||
say "fs_double(#{s}): #{fs_double(s...)}"; | ||
say "fs_square(#{s}): #{fs_square(s...)}"; | ||
|
||
s = [2, 4, 6, 8]; | ||
say "fs_double(#{s}): #{fs_double(s...)}"; | ||
say "fs_square(#{s}): #{fs_square(s...)}"; |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/ruby | ||
|
||
# | ||
## http://rosettacode.org/wiki/Vigen%C3%A8re_cipher | ||
# | ||
|
||
func s2v(s) { s.uc.scan(/[A-Z]/)»ord»() »-» 65 }; | ||
func v2s(v) { (v »%» 26 »+» 65)»chr»().join }; | ||
|
||
func blacken (red, key) { v2s(s2v(red) »+« s2v(key)) }; | ||
func redden (blk, key) { v2s(s2v(blk) »-« s2v(key)) }; | ||
|
||
var red = "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!"; | ||
var key = "Vigenere Cipher!!!"; | ||
|
||
var black = blacken(red, key); | ||
var ured = redden(black, key); | ||
|
||
assert_eq('WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY', black); | ||
assert_eq('BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH', ured); | ||
|
||
say "** Test passed!"; |