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
# ben oliver 11.01.2013 | |
# a (functional) python 3.x vigenere encoder / decoder. | |
# encode and decode functions are mathematical, no dictionary lookups. | |
from itertools import cycle | |
from functools import partial | |
from string import ascii_uppercase | |
def transform(crypt_function,k,s): | |
""" (Int -> Int -> Int) -> Char -> Char -> Char """ |
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
// a better name would be - if predicate is True then success, else not success. | |
// using basic logic we can now create logic functions that compute only as much as required | |
// anyBool :: (a -> Bool) -> Bool -> [a] -> Bool | |
function anyBool(pred,success,xs) { | |
for (var i = 0; i < xs.length; i++) { | |
if (pred(xs[i]) === success) { | |
return success }} | |
return !success } |
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
function ifElse(pred,true_fn,else_fn,xs) { | |
for (var i = 0; i < xs.length; i++) { | |
if (pred(xs[i]) === true) { | |
// return matched item, index, array to yes_func | |
return true_fn(xs[i],i,xs) }} | |
// return array to no_func | |
return else_fn(xs) } | |
// what does this do? |
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
import Data.Maybe | |
data Tree a = Node a [Tree a] deriving (Show) | |
t = Node 1 [ Node 2 [ Node 3 [] ], Node 4 [], Node 5 [ Node 6 [] ] ] | |
paths :: Tree a -> [[a]] | |
paths (Node n []) = [[n]] | |
paths (Node n xs) = map ((:) n . concat . paths) xs |
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
// nested classes | static classes | |
public class Main { | |
public static void main(String[] args) { | |
Outer a = new Outer(6); | |
Outer.InnerB b1 = a.new InnerB(); | |
Outer.InnerB b2 = new Outer(7).new InnerB(); | |
Outer.InnerC c1 = new Outer.InnerC(8); |
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
import java.util.concurrent.atomic.AtomicInteger; | |
public class Main { | |
public static void main(String[] args) { | |
String[] words = {"a", "b", "c", "a", "a", "r", "b", "c", "a"}; | |
SharedValue sharedValue = new SharedValue(); |
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
public class Main { | |
public static void main(String[] args) { | |
String[] words = {"a", "b", "c", "a", "a", "r", "b", "c", "a"}; | |
SharedValue sharedValue = new SharedValue(); | |
for (int i = 0; i <= 6; i += 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
public class Main { | |
public static void main(String[] args) { | |
String[] words = {"a", "b", "c", "a", "a", "c", "b", "c", "a"}; | |
SharedValue sharedValue = new SharedValue(); | |
for (int i = 0; i <= 6; i += 3) { | |
Thread t = new Thread(new Worker(words,i,i+2,"a",sharedValue)); |
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
import java.util.ArrayList; | |
public class Main { | |
public static void main(String[] args) { | |
String[] words = {"c", "b", "a", "a", "a", "r", "b", "c", "a", "b", "a", "c"}; | |
SynchronisedInteger sharedValue = new SynchronisedInteger(); | |
ArrayList<Thread> threads = new ArrayList<>(); |
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
import java.util.ArrayList; | |
// next step is to change type from A to B, | |
// map :: (a -> b) -> [a] -> [b] | |
public class Main { | |
public static void main(String[] args) { | |
PartitionedArrayList<Integer> xs = new PartitionedArrayList<Integer>(3); |
OlderNewer