Babylonian spiral: Difference between revisions

m
Automated syntax highlighting fixup (second round - minor fixes)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 42:
Implementation:
 
<syntaxhighlight lang=J"j">
require'stats'
bspir=: {{
Line 60:
Task example:
 
<syntaxhighlight lang=J"j"> 4 10$bspir 40
0 0j1 1j2 3j2 5j1 7j_1 7j_4 6j_7 4j_10 0j_10
_4j_9 _7j_6 _9j_2 _9j3 _8j8 _6j13 _2j17 3j20 9j20 15j19
Line 69:
Also:
 
<syntaxhighlight lang=J"j">
require'plot'
plot bspir 40
Line 81:
=={{header|Julia}}==
{{trans|Python}}
<syntaxhighlight lang="ruby">""" Rosetta Code task rosettacode.org/wiki/Babylonian_spiral """
 
using GLMakie
Line 150:
=={{header|Perl}}==
{{trans|Raku}}
<syntaxhighlight lang="perl">use strict;
use warnings;
use feature <say state>;
Line 208:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/Babylonian_spiral.htm here]. Use left/right arrow keys to show less/more edges.
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo/rosetta/Babylonian_spiral.exw
Line 364:
 
=={{header|Python}}==
<syntaxhighlight lang="python">""" Rosetta Code task rosettacode.org/wiki/Babylonian_spiral """
 
from itertools import accumulate
Line 434:
=== With priority queue ===
Use a priority queue to generate all x, y combinations. The advantage is that we don't need to do any real math, and it is much faster.
<syntaxhighlight lang="python">from itertools import islice, count
import matplotlib.pyplot as plt
import heapq
Line 484:
 
===Translation===
<syntaxhighlight lang="raku" linesline>sub babylonianSpiral (\nsteps) {
my @squareCache = (0..nsteps).hyper.map: *²;
my @dxys = [[0, 0], [0, 1]];
Line 543:
Exact same output; about one tenth the execution time.
 
<syntaxhighlight lang="raku" linesline>my @next = { :x(1), :y(1), :2hyp },;
 
sub next-interval (Int $int) {
Line 594:
{{libheader|Wren-plot}}
Generates an image similar to the OEIS one.
<syntaxhighlight lang="ecmascript">import "dome" for Window
import "graphics" for Canvas, Color
import "./trait" for Indexed, Stepped
10,327

edits