Last active
August 29, 2015 14:14
-
-
Save jirkapenzes/56f8670bf9ff4eb1e938 to your computer and use it in GitHub Desktop.
TopMonks coffee - presentation samples
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
(defprotocol Event | |
(scheduled-time [this]) | |
(execute [this])) | |
(defn simulate [event] | |
(synchronize-time (scheduled-time event)) | |
(execute event)) | |
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 interface Event { | |
public double getScheduledTime(); | |
public void execute(); | |
} | |
// ... | |
public void simulate(Event event) { | |
synchronizeTime(event.getScheduledTime()); | |
event.execute(); | |
} |
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
(defn work [initial-task] | |
(loop [tasks (list initial-task)] | |
(when (not-empty tasks) | |
(let [task (peek tasks)] | |
(recur | |
(into (pop tasks) (execute taks))))))) |
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 static void work(Task initialTask) { | |
ArrayList<Task> tasks = new ArrayList<Task>(); | |
tasks.add(initialTask); | |
while (!tasks.isEmpty()) { | |
Task task = tasks.remove(0); | |
List<Task> newTasks = task.execute(); | |
tasks.addAll(newTasks); | |
} | |
} |
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
(defn sum-even-fibonacci [limit] | |
(loop [first 0 | |
second 1 | |
sum 0] | |
(if (<= second limit) | |
(let [new-sum | |
(if (= (mod second 2) 0) | |
(+ sum second) | |
sum)] | |
(recur second (+ first second) new-sum)) | |
sum))) | |
(println "Result: " (sum-even-fibonacci 4000000)) |
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 static void main(String[] args) { | |
int limit = 4000000; | |
int first = 0; | |
int second = 1; | |
int sum = 0; | |
while (second <= limit) { | |
if (second % 2 == 0) { | |
sum += second; | |
} | |
int newFirst = second; | |
int newSecond = first + second; | |
first = newFirst; | |
second = newSecond; | |
} | |
System.out.println("Result: " + sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://docs.google.com/presentation/d/1RZ7-5So0TcN6A-1mLbshcX7kF-cJkhvtSFbFay33emI/edit?usp=sharing