Skip to content

Instantly share code, notes, and snippets.

// 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 },
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
[3 4 5]
[15 8 17]
[21 20 29]
[ 5 12 13]
[35 12 37]
[65 72 97]
[33 56 65]
[77 36 85]
...
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
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],
#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 },
%{ worker |
clock: max(worker.clock, logEntry.time) + 1,
eventLog: [logEntry | worker.eventLog] }
{:reply, sortedLog, worker}
def handle_call(:get_history, _from, worker) do
...
end
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