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
// The algorithm itself | |
xt::xarray<int> next_pytharogian_triangles(xt::xarray<int> const& previous_stage) | |
{ | |
static const xt::xarray<int> stacked_matrices = { | |
{ -1, 2, 2 }, | |
{ -2, 1, 2 }, | |
{ -2, 2, 3 }, | |
{ 1, 2, 2 }, | |
{ 2, 1, 2 }, | |
{ 2, 2, 3 }, |
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
def pythagorean_triples(filter): | |
current = np.array([[3, 4, 5]]) # Initial seed | |
yield from current # Yield first triple | |
while current.shape[0]: # While work to do | |
current = next_pythagorean_triples(current) # Next iteration | |
current = filter(current) # Filter desired triples | |
yield from current # Yield each triple |
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
[3 4 5] | |
[15 8 17] | |
[21 20 29] | |
[ 5 12 13] | |
[35 12 37] | |
[65 72 97] | |
[33 56 65] | |
[77 36 85] | |
... |
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
def pythagorean_triples(): | |
current = np.array([[3, 4, 5]]) # Initial seed | |
yield from current # Yield first triple | |
while True: | |
current = next_pythagorean_triples(current) # Next iteration | |
yield from current # Yield each triple |
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
def next_pythagorean_triples(previous): | |
matrices = np.array( | |
[[-1, 2, 2], | |
[-2, 1, 2], | |
[-2, 2, 3], | |
[1, 2, 2], | |
[2, 1, 2], | |
[2, 2, 3], | |
[1, -2, 2], | |
[2, -1, 2], |
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
#include <xtensor/xtensor.hpp> | |
#include <xtensor-blas/xlinalg.hpp> | |
xt::xarray<int> next_pytharogian_triples(xt::xarray<int> const& previous_stage) | |
{ | |
static const xt::xarray<int> stacked_matrices = { | |
{ -1, 2, 2 }, | |
{ -2, 1, 2 }, | |
{ -2, 2, 3 }, | |
{ 1, 2, 2 }, |
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
%{ worker | | |
clock: max(worker.clock, logEntry.time) + 1, | |
eventLog: [logEntry | worker.eventLog] } |
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
{:reply, sortedLog, worker} |
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
def handle_call(:get_history, _from, worker) do | |
... | |
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
Eventually.assertUntil 100, 5, fn() -> | |
same_history = | |
Dispatcher.get_workers() | |
|> Enum.map(fn w -> Worker.get_history(w) end) | |
|> all_equal | |
assert same_history == true | |
end |