task_url stringlengths 30 116 | task_name stringlengths 2 86 | task_description stringlengths 0 14.4k | language_url stringlengths 2 53 | language_name stringlengths 1 52 | code stringlengths 0 61.9k |
|---|---|---|---|---|---|
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Prolog | Prolog | dutch_flag(N) :-
length(L, N),
repeat,
maplist(init,L),
\+is_dutch_flag(L) ,
writeln(L),
test_sorted(L),
sort_dutch_flag(L, TmpFlag),
append(TmpFlag, Flag),
writeln(Flag),
test_sorted(Flag).
sort_dutch_flag([], [[], [], []]).
sort_dutch_flag([blue | T], [R, W, [blue|B]]) :-
sort_dutch_flag(T, [R, W, ... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Maple | Maple | plots:-display(plottools:-parallelepiped([2, 0, 0], [0, 0, 4], [0, 3, 0]), orientation = [45, 60]) |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #D | D | import std.stdio, std.string;
struct Board {
enum char spc = ' ';
char[][] b = [[' ']]; // Set at least 1x1 board.
int shiftx, shifty;
void clear() pure nothrow {
shiftx = shifty = 0;
b = [['\0']];
}
void check(in int x, in int y) pure nothrow {
while (y + shifty < ... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Icon_and_Unicon | Icon and Unicon | procedure main()
W := open("Demo", "gl", "size=400,400", "bg=black") | stop("can't open window!")
WAttrib(W, "slices=40", "rings=40", "light0=on, ambient white; diffuse gold; specular gold; position 5, 0, 0" )
Fg(W, "emission blue")
DrawSphere(W, 0, 0, -5, 1)
Event(W)
end |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Haskell | Haskell | import Control.Concurrent
import Data.List
import System.Time
-- Library: ansi-terminal
import System.Console.ANSI
number :: (Integral a) => a -> [String]
number 0 =
["██████"
,"██ ██"
,"██ ██"
,"██ ██"
,"██████"]
number 1 =
[" ██"
," ██"
," ██"
," ██"
," ██"]
number 2 =
["██... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Python | Python | import random
colours_in_order = 'Red White Blue'.split()
def dutch_flag_sort(items, order=colours_in_order):
'return sort of items using the given order'
reverse_index = dict((x,i) for i,x in enumerate(order))
return sorted(items, key=lambda x: reverse_index[x])
def dutch_flag_check(items, order=colo... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | Graphics3D[Cuboid[{0,0,0},{2,3,4}]] |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Delphi | Delphi |
program Dragon_curve;
{$APPTYPE CONSOLE}
uses
Winapi.Windows,
System.SysUtils,
System.Classes,
Vcl.Graphics;
type
TDragon = class
private
p: TColor;
_sin: TArray<double>;
_cos: TArray<double>;
s: double;
b: TBitmap;
FAsBitmap: TBitmap;
const
sep = 512;
depth =... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #J | J | Studio
> Demos...
> opengl simple... [ok]
> sphere [Run]
|
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Icon_and_Unicon | Icon and Unicon |
link graphics
global xsize,
ysize,
fontsize
procedure main(args)
if *args > 0 then xsize := ysize := numeric(args[1])
/xsize := /ysize := 200
WIN := WOpen("size=" || xsize || "," || ysize, "label=Clock", "resize=on") | stop("Fenster geht nicht auf!", image(xsize), " - ", image(ysize... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Racket | Racket |
#lang racket
(define dutch-colors '(red white blue))
(define (dutch-order? balls)
;; drop each color from the front, should end up empty
(null? (for/fold ([r balls]) ([color dutch-colors])
(dropf r (curry eq? color)))))
(define (random-balls)
(define balls
(for/list ([i (random 20)])
... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Raku | Raku | enum NL <red white blue>;
my @colors;
sub how'bout (&this-way) {
sub show {
say @colors;
say "Ordered: ", [<=] @colors;
}
@colors = NL.roll(20);
show;
this-way;
show;
say '';
}
say "Using functional sort";
how'bout { @colors = sort *.value, @colors }
say "Using in-pla... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Maxima | Maxima | load(draw)$
draw3d(xu_grid=100, yv_grid=100, surface_hide=true,
palette=gray, enhanced3d=[x - z / 4 - y / 4, x, y, z],
implicit(max(abs(x / 4), abs(y / 6), abs(z / 8)) = 1,
x,-10,10,y,-10,10,z,-10,10))$ |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #EasyLang | EasyLang | color 050
linewidth 0.5
x = 25
y = 60
move x y
angle = 0
#
func dragon size lev d . .
if lev = 0
x -= cos angle * size
y += sin angle * size
line x y
else
call dragon size / sqrt 2 lev - 1 1
angle -= d * 90
call dragon size / sqrt 2 lev - 1 -1
.
.
call dragon 60 12 1 |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Java | Java | public class Sphere{
static char[] shades = {'.', ':', '!', '*', 'o', 'e', '&', '#', '%', '@'};
static double[] light = { 30, 30, -50 };
private static void normalize(double[] v){
double len = Math.sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
v[0] /= len; v[1] /= len; v[2] /= len;
}
... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #J | J | {{
require'gl2'
coinsert 'jgl2'
clock_face_paint=: {{
try.
'H M S'=. _3{.6!:0''
glclear''
center=. 2-~<.-:glqwh''
glpen 2: glrgb 0 0 0 255
glellipse 1+,0 2*/center
center {{ gllines <.2+(m,m)+,0.97 1*/m*+.j.y}}"0^j.2r12p1*i.12
center {{ gllines <.2+(m,m)+,0.92 0.99*/m... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #REXX | REXX | /*REXX program reorders a set of random colored balls into a correct order, which is the*/
/*────────────────────────────────── order of colors on the Dutch flag: red white blue.*/
parse arg N colors /*obtain optional arguments from the CL*/
if N='' | N="," then N=15 ... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Nim | Nim | import strutils
proc cline(n, x, y: int, cde: string) =
echo cde[0..0].align n+1,
repeat(cde[1], 9*x-1),
cde[0],
if cde.len > 2: cde[2..2].align y+1 else: ""
proc cuboid(x, y, z: int) =
cline y+1, x, 0, "+-"
for i in 1..y: cline y-i+1, x, i-1, "/ |"
cline 0, x, y, "+-|"
for i in 0..4*z-y-3: cl... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Elm | Elm | import Color exposing (..)
import Collage exposing (..)
import Element exposing (..)
import Time exposing (..)
import Html exposing (..)
import Html.App exposing (program)
type alias Point = (Float, Float)
type alias Model =
{ points : List Point
, level : Int
, frame : Int
}
maxLevel = 12
frameCount = ... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #JavaScript | JavaScript | <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Draw a sphere</title>
<script>
var light=[30,30,-50],gR,gk,gambient;
function normalize(v){
var len=Math.sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
v[0]/=len;
v[1]/=len;
v[2]/=len;
return v;
}
function dot(x,y){
var d=x[0]*y[0]+x[1]*y[1]+x[2]*y[2];
return... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Java | Java | import java.awt.*;
import java.awt.event.*;
import static java.lang.Math.*;
import java.time.LocalTime;
import javax.swing.*;
class Clock extends JPanel {
final float degrees06 = (float) (PI / 30);
final float degrees30 = degrees06 * 5;
final float degrees90 = degrees30 * 3;
final int size = 590;
... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Ring | Ring |
# Project : Dutch national flag problem
flag = ["Red","White","Blue"]
balls = list(10)
see "Random: |"
for i = 1 to 10
color = random(2) + 1
balls[i] = flag[color]
see balls[i] + " |"
next
see nl
see "Sorted: |"
for i = 1 to 3
color = flag[i]
for j = 1 to 10
if balls[j] = co... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Ruby | Ruby | class Ball
FLAG = {red: 1, white: 2, blue: 3}
def initialize
@color = FLAG.keys.sample
end
def color
@color
end
def <=>(other) # needed for sort, results in -1 for <, 0 for == and 1 for >.
FLAG[self.color] <=> FLAG[other.color]
end
def inspect
@color
end
end
balls = []
ball... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Openscad | Openscad | // This will produce a simple cuboid
cube([2,3,4]);
|
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Emacs_Lisp | Emacs Lisp | (defun dragon-ensure-line-above ()
"If point is in the first line of the buffer then insert a new line above."
(when (= (line-beginning-position) (point-min))
(save-excursion
(goto-char (point-min))
(insert "\n"))))
(defun dragon-ensure-column-left ()
"If point is in the first column then insert... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #jq | jq | def svg:
"<svg width='100%' height='100%' version='1.1'
xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink'>" ;
# A radial gradient to make a circle look like a sphere.
# "colors" should be [startColor, intermediateColor, endColor]
# or null for ["white", "teal", "black"]
def sphe... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #JavaScript | JavaScript | var sec_old = 0;
function update_clock() {
var t = new Date();
var arms = [t.getHours(), t.getMinutes(), t.getSeconds()];
if (arms[2] == sec_old) return;
sec_old = arms[2];
var c = document.getElementById('clock');
var ctx = c.getContext('2d');
ctx.fillStyle = "rgb(0,200,200)";
ctx.fillRect(0, 0, c.width, c.h... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Run_BASIC | Run BASIC | flag$ = "Red,White,Blue"
print "Random: |";
for i = 1 to 10
color = rnd(0) * 3 + 1
balls$(i) = word$(flag$,color,",")
print balls$(i);" |";
next i
print :print "Sorted: |";
for i = 1 to 3
color$ = word$(flag$,i,",")
for j = 1 to 10
if balls$(j) = color$ then
print balls$(j);" |";
end if
next j
next i |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Rust | Rust | extern crate rand;
use rand::Rng;
// Color enums will be sorted by their top-to-bottom declaration order
#[derive(Eq,Ord,PartialOrd,PartialEq,Debug)]
enum Color {
Red,
White,
Blue
}
fn is_sorted(list: &Vec<Color>) -> bool {
let mut state = &Color::Red;
for current in list.iter() {
if c... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #OxygenBasic | OxygenBasic |
% Title "Cuboid 2x3x4"
'% Animated
% PlaceCentral
uses ConsoleG
sub main
========
cls 0.0, 0.2, 0.7
shading
scale 3
pushstate
GoldMaterial.act
static float ang=45
rotateX ang
rotateY ang
scale 2,3,4
go cube
popstate
end sub
EndScript
|
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #PARI.2FGP | PARI/GP |
\\ Simple "cuboid". Try different parameters of this Cuboid() function.
\\ 4/11/16 aev
Cuboid(a,b,c,u=10)={
my(dx,dy,ttl="Cuboid AxBxC: ",size=200,da=a*u,db=b*u,dc=c*u);
print(" *** ",ttl,a,"x",b,"x",c,"; u=",u);
plotinit(0);
plotscale(0, 0,size, 0,size);
plotcolor(0,7); \\grey
plotmove(0, 0,0);
plotrline(0,dc,da\2)... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #ERRE | ERRE |
PROGRAM DRAGON
!
! for rosettacode.org
!
!$DYNAMIC
DIM RQS[0]
!$INCLUDE="PC.LIB"
PROCEDURE DRAGON
IF LEVEL<=0 THEN
YN=SIN(ROTATION)*INSIZE+Y
XN=COS(ROTATION)*INSIZE+X
LINE(X,Y,XN,YN,12,FALSE)
ITER=ITER+1
X=XN Y=YN
... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Julia | Julia | function draw_sphere(r, k, ambient, light)
shades = ('.', ':', '!', '*', 'o', 'e', '&', '#', '%', '@')
for i in floor(Int, -r):ceil(Int, r)
x = i + 0.5
line = IOBuffer()
for j in floor(Int, -2r):ceil(2r)
y = j / 2 + 0.5
if x ^ 2 + y ^ 2 ≤ r ^ 2
v =... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Julia | Julia |
using Gtk, Colors, Graphics, Dates
const radius = 300
const win = GtkWindow("Clock", radius, radius)
const can = GtkCanvas()
push!(win, can)
global drawcontext = []
function drawline(ctx, l, color)
isempty(l) && return
p = first(l)
move_to(ctx, p.x, p.y)
set_source(ctx, color)
for i = 2:leng... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Scala | Scala | object FlagColor extends Enumeration {
type FlagColor = Value
val Red, White, Blue = Value
}
val genBalls = (1 to 10).map(i => FlagColor(scala.util.Random.nextInt(FlagColor.maxId)))
val sortedBalls = genBalls.sorted
val sorted = if (genBalls == sortedBalls) "sorted" else "not sorted"
println(s"Generated bal... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #SQL | SQL | -- Create and populate tables
CREATE TABLE colours (id INTEGER PRIMARY KEY, name VARCHAR(5));
INSERT INTO colours (id, name) VALUES ( 1, 'red' );
INSERT INTO colours (id, name) VALUES ( 2, 'white');
INSERT INTO colours (id, name) VALUES ( 3, 'blue' );
CREATE TABLE balls ( colour INTEGER REFERENCES colours );
INSERT ... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Pascal | Pascal | program Cuboid_Demo(output);
procedure DoCuboid(sWidth, sHeight, Depth: integer);
const
widthScale = 4;
heightScale = 3;
type
TPage = array of array of char;
var
Cuboid: TPage;
i, j: integer;
Width, Height: integer;
totalWidth, totalHeight: integer;
begin
Width := widthScale ... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #F.23 | F# | open System.Windows
open System.Windows.Media
let m = Matrix(0.0, 0.5, -0.5, 0.0, 0.0, 0.0)
let step segs =
seq { for a: Point, b: Point in segs do
let x = a + 0.5 * (b - a) + (b - a) * m
yield! [a, x; b, x] }
let rec nest n f x =
if n=0 then x else nest (n-1) f (f x)
[<System.STAThread>... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Kotlin | Kotlin | // version 1.0.6
const val shades = ".:!*oe&#%@"
val light = doubleArrayOf(30.0, 30.0, -50.0)
fun normalize(v: DoubleArray) {
val len = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2])
v[0] /= len; v[1] /= len; v[2] /= len
}
fun dot(x: DoubleArray, y: DoubleArray): Double {
val d = x[0] * y[0] + x[... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Kotlin | Kotlin | // version 1.1
import java.awt.*
import java.time.LocalTime
import javax.swing.*
class Clock : JPanel() {
private val degrees06: Float = (Math.PI / 30.0).toFloat()
private val degrees30: Float = degrees06 * 5.0f
private val degrees90: Float = degrees30 * 3.0f
private val size = 590
private val ... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Tcl | Tcl | # The comparison function
proc dutchflagcompare {a b} {
set colors {red white blue}
return [expr {[lsearch $colors $a] - [lsearch $colors $b]}]
}
# The test function (evil shimmer of list to string!)
proc isFlagSorted lst {
expr {![regexp {blue.*(white|red)} $lst] && ![regexp {white.*red} $lst]}
}
# A b... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Perl | Perl | sub cubLine ($$$$) {
my ($n, $dx, $dy, $cde) = @_;
printf '%*s', $n + 1, substr($cde, 0, 1);
for (my $d = 9 * $dx - 1 ; $d > 0 ; --$d) {
print substr($cde, 1, 1);
}
print substr($cde, 0, 1);
printf "%*s\n", $dy + 1, substr($cde, 2, 1);
}
sub cuboid ($$$) {
my ($dx, $dy, $dz) ... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Factor | Factor |
USING: accessors colors colors.hsv fry kernel locals math
math.constants math.functions opengl.gl typed ui ui.gadgets
ui.gadgets.canvas ui.render ;
IN: dragon
CONSTANT: depth 12
TUPLE: turtle
{ angle fixnum }
{ color float }
{ x float }
{ y float } ;
TYPED: nxt-color ( turtle: turtle -- turtle... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Lingo | Lingo | ----------------------------------------
-- Draw a circle
-- @param {image} img
-- @param {integer} x
-- @param {integer} y
-- @param {integer} r
-- @param {integer} lineSize
-- @param {color} drawColor
----------------------------------------
on circle (img, x, y, r, lineSize, drawColor)
props = [:]
props[#shapeTy... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Lambdatalk | Lambdatalk |
1) lambdatalk code
{watch} // displays the watch
{def watch
{watch.init}
{div {@ id="watch"}}
}
{def watch.draw
{lambda {:r :g :b}
{svg {@ style="width:300px; height:300px;"}
{let { {:r :r} {:g :g} {:b :b} {:t {date}} }
{watch.path 150 150 100 20 :r 1 :t}
{watch.path 150 150 120 20 :g 2 :t}
... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #UNIX_Shell | UNIX Shell | COLORS=(red white blue)
# to go from name to number, we make variables out of the color names
# (e.g. the variable "$red" has value "1").
for (( i=0; i<${#COLORS[@]}; ++i )); do
eval ${COLORS[i]}=$i
done
# Make a random list
function random_balls {
local -i n="$1"
local -i i
local balls=()
for (( i=0; i ... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Phix | Phix | --
-- demo\rosetta\draw_cuboid.exw
-- ============================
--
-- Author Pete Lomax, August 2015
-- Translated from XPL0.
-- Ported to pGUI August 2017
--
-- Press space to toggle auto-rotate on and off,
-- cursor keys to rotate manually, and
-- +/- to zoom in/out.
--
-- Note this uses simple ... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Forth | Forth | include turtle.fs
2 value dragon-step
: dragon ( depth dir -- )
over 0= if dragon-step fd 2drop exit then
dup rt
over 1- 45 recurse
dup 2* lt
over 1- -45 recurse
rt drop ;
home clear
10 45 dragon |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Logo | Logo | to sphere :r
cs perspective ht ;making the room ready to use
repeat 180 [polystart circle :r polyend down 1]
polyview
end |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Liberty_BASIC | Liberty BASIC |
WindowWidth =120
WindowHeight =144
nomainwin
open "Clock" for graphics_nsb_nf as #clock
#clock "trapclose [exit]"
#clock "fill white"
for angle =0 to 330 step 30
#clock "up ; home ; north ; turn "; angle
#clock "go 40 ; down ; go 5"
next angle
#clock "flush"
... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #VBScript | VBScript |
'Solution derived from http://www.geeksforgeeks.org/sort-an-array-of-0s-1s-and-2s/.
'build an unsorted array with n elements
Function build_unsort(n)
flag = Array("red","white","blue")
Set random = CreateObject("System.Random")
Dim arr()
ReDim arr(n)
For i = 0 To n
arr(i) = flag(random.Next_2(0,3))
Next
bui... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Visual_FoxPro | Visual FoxPro |
CLOSE DATABASES ALL
LOCAL lcCollate As String, i As Integer, n As Integer
lcCollate = SET("Collate")
SET COLLATE TO "Machine"
*!* Colours table
CREATE CURSOR colours (id I UNIQUE, colour V(5))
INSERT INTO colours VALUES (1, "Red")
INSERT INTO colours VALUES (2, "White")
INSERT INTO colours VALUES (3, "Blue")
*!* Ball... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #PicoLisp | PicoLisp | (de cuboid (DX DY DZ)
(cubLine (inc DY) "+" DX "-" 0)
(for I DY
(cubLine (- DY I -1) "/" DX " " (dec I) "|") )
(cubLine 0 "+" DX "-" DY "|")
(do (- (* 4 DZ) DY 2)
(cubLine 0 "|" DX " " DY "|") )
(cubLine 0 "|" DX " " DY "+")
(for I DY
(cubLine 0 "|" DX " " (- DY I) "/") )
(cubLine... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #POV-Ray | POV-Ray | camera { perspective location <2.6,2.2,-4.2> look_at <0,-.5,0>
aperture .05 blur_samples 100 variance 1/100000 focal_point <2,1,-2>}
light_source{< 60,20,-20> color rgb 2}
sky_sphere { pigment{ gradient z color_map{[0 rgb 0.3][.1 rgb <.7,.8,1>][1 rgb .2]} }}
box { <0,0,0> <3,2,4>
texture {
pigment... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #F.C5.8Drmul.C3.A6 | Fōrmulæ | Const pi As Double = 4 * Atn(1)
Dim Shared As Double angulo = 0
Sub giro (grados As Double)
angulo += grados*pi/180
End Sub
Sub dragon (longitud As Double, division As Integer, d As Double)
If division = 0 Then
Line - Step (Cos(angulo)*longitud, Sin(angulo)*longitud), Int(Rnd * 7)
Else
... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Lua | Lua | require ("math")
shades = {'.', ':', '!', '*', 'o', 'e', '&', '#', '%', '@'}
function normalize (vec)
len = math.sqrt(vec[1]^2 + vec[2]^2 + vec[3]^2)
return {vec[1]/len, vec[2]/len, vec[3]/len}
end
light = normalize{30, 30, -50}
function dot (vec1, vec2)
d = vec1[1]*vec2[1] + vec1[2]*vec2[2] + vec1[... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Locomotive_Basic | Locomotive Basic | 10 mode 1:defint a-y:deg
20 input "Current time (HH:MM)";t$
30 h=val(mid$(t$,1,2))
40 m=val(mid$(t$,4,2))
50 cls
60 r=150:s=-1
70 ph=0:pm=0
80 origin 320,200
90 for a=0 to 360 step 6
100 if a mod 30>0 then z=.9 else z=.8
110 move z*r*sin(a),z*r*cos(a)
120 draw r*sin(a),r*cos(a)
130 next
140 move 0,r
150 for a=0 to 360 ... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Wren | Wren | import "random" for Random
import "/sort" for Sort
var colors = ["Red", "White", "Blue"]
var colorMap = { "Red": 0, "White": 1, "Blue": 2 }
var colorCmp = Fn.new { |c1, c2| (colorMap[c1] - colorMap[c2]).sign }
var NUM_BALLS = 9
var r = Random.new()
var balls = List.filled(NUM_BALLS, colors[0])
while (true) {
fo... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Processing | Processing | size(500, 500, P3D);
background(0);
// position
translate(width/2, height/2, -width/2);
rotateZ(radians(15));
rotateY(radians(-30));
rotateX(radians(-25));
// optional fill and lighting colors
noStroke();
fill(192, 255, 192);
pointLight(255, 255, 255, 400, -400, 400);
// draw box
box(200, 300, 400); |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #FreeBASIC | FreeBASIC | Const pi As Double = 4 * Atn(1)
Dim Shared As Double angulo = 0
Sub giro (grados As Double)
angulo += grados*pi/180
End Sub
Sub dragon (longitud As Double, division As Integer, d As Double)
If division = 0 Then
Line - Step (Cos(angulo)*longitud, Sin(angulo)*longitud), Int(Rnd * 7)
Else
... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #M2000_Interpreter | M2000 Interpreter |
Module CheckIt {
Er$="Pset is a new statement"
If Version<9.4 Then Error Er$
If Version=9.4 then If revision<26 then Error Er$
Form 60, 40
Cls 0 ' Black
Gradient 0,1
Pen 14 ' Yellow
Set Fast !
Refresh 500
Module Sphere (R as long, X0 as long, Y0 as long, fun... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Lua | Lua | Dynamic[ClockGauge[], UpdateInterval -> 1] |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #zkl | zkl | const RED=0, WHITE=1, BLUE=2; var BALLS=T(RED,WHITE,BLUE);
fcn colorBalls(balls){ balls.apply(T("red","white","blue").get).concat(", "); }
reg balls, sortedBalls;
do{
balls=(0).pump(12,List,fcn{ BALLS[(0).random(3)] }); // create list of 12 random balls
sortedBalls=balls.sort(); // balls is read only, sort crea... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Prolog | Prolog | cuboid(D1,D2,D3) :-
W is D1 * 50,
H is D2 * 50,
D is D3 * 50,
new(C, window(cuboid)),
% compute the size of the window
Width is W + ceiling(sqrt(H * 48)) + 50,
Height is H + ceiling(sqrt(H * 48)) + 50,
send(C, size, new(_,size(Width,Height))),
%compute the top-left corner of the front face of the cuboid... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Gnuplot | Gnuplot | # Return the position of the highest 1-bit in n.
# The least significant bit is position 0.
# For example n=13 is binary "1101" and the high bit is pos=3.
# If n==0 then the return is 0.
# Arranging the test as n>=2 avoids infinite recursion if n==NaN (any
# comparison involving NaN is always false).
#
high_bit_pos(n) ... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Maple | Maple | plots[display](plottools[sphere](), axes = none, style = surface); |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | Dynamic[ClockGauge[], UpdateInterval -> 1] |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #ZX_Spectrum_Basic | ZX Spectrum Basic | 10 LET r$="Red": LET w$="White": LET b$="Blue"
20 LET c$="RWB"
30 DIM b(10)
40 PRINT "Random:"
50 FOR n=1 TO 10
60 LET b(n)=INT (RND*3)+1
70 PRINT VAL$ (c$(b(n))+"$");" ";
80 NEXT n
90 PRINT ''"Sorted:"
100 FOR i=1 TO 3
110 FOR j=1 TO 10
120 IF b(j)=i THEN PRINT VAL$ (c$(i)+"$");" ";
130 NEXT j
140 NEXT i |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Pure_Data | Pure Data |
#N canvas 1 51 450 300 10;
#X obj 66 67 gemwin;
#X obj 239 148 cuboid 2 3 4;
#X obj 239 46 gemhead;
#X obj 239 68 scale 0.3;
#X msg 66 45 lighting 1 \, create \, 1;
#X obj 61 118 gemhead;
#X obj 61 140 world_light;
#X msg 294 90 1;
#X obj 239 90 t a b;
#X obj 239 118 accumrotate;
#X connect 2 0 3 0;
#X connect 3 0 8 ... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Go | Go | package main
import (
"fmt"
"image"
"image/color"
"image/draw"
"image/png"
"math"
"os"
)
// separation of the the two endpoints
// make this a power of 2 for prettiest output
const sep = 512
// depth of recursion. adjust as desired for different visual effects.
const depth = 14
var s ... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | Graphics3D[Sphere[{0,0,0},1]] |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #MATLAB_.2F_Octave | MATLAB / Octave | u = [0:360]*pi/180;
while(1)
s = mod(now*60*24,1)*2*pi;
plot([0,sin(s)],[0,cos(s)],'-',sin(u),cos(u),'k-');
pause(1);
end; |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #PureBasic | PureBasic | Procedure Draw_a_Cuboid(Window, X,Y,Z)
w=WindowWidth(Window)
h=WindowHeight(Window)
diag.f=1.9
If Not (w And h): ProcedureReturn: EndIf
xscale.f = w/(x+z/diag)*0.98
yscale.f = h/(y+z/diag)*0.98
If xscale<yscale
Scale.f = xscale
Else
Scale = yscale
EndIf
x*Scale: Y*Scale: Z*Scale
CreateImag... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Gri | Gri | `Draw Dragon [ from .x1. .y1. to .x2. .y2. [level .level.] ]'
Draw a dragon curve going from .x1. .y1. to .x2. .y2. with recursion
depth .level.
The total number of line segments for the recursion is 2^level.
level=0 is a straight line from x1,y1 to x2,y2.
The default for x1,y1 and x2,y2 is to draw horizontally fro... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #MATLAB | MATLAB | figure; sphere |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #MiniScript | MiniScript | // draw a clock hand, then copy it to an image
gfx.clear color.clear
gfx.fillPoly [[60,5], [64,10], [128,5], [64,0]], color.yellow
handImg = gfx.getImage(0,0, 128,10)
clear // clear all displays
// prepare the face sprite
faceImg = file.loadImage("/sys/pics/shapes/CircleThinInv.png")
face = new Sprite
face.image =... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Python | Python | def _pr(t, x, y, z):
txt = '\n'.join(''.join(t[(n,m)] for n in range(3+x+z)).rstrip()
for m in reversed(range(3+y+z)))
return txt
def cuboid(x,y,z):
t = {(n,m):' ' for n in range(3+x+z) for m in range(3+y+z)}
xrow = ['+'] + ['%i' % (i % 10) for i in range(x)] + ['+']
for i,ch i... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Haskell | Haskell | import Data.List
import Graphics.Gnuplot.Simple
-- diamonds
-- pl = [[0,1],[1,0]]
pl = [[0,0],[0,1]]
r_90 = [[0,1],[-1,0]]
ip :: [Int] -> [Int] -> Int
ip xs = sum . zipWith (*) xs
matmul xss yss = map (\xs -> map (ip xs ). transpose $ yss) xss
vmoot xs = (xs++).map (zipWith (+) lxs). flip matmul r_90.
... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Maxima | Maxima | /* Two solutions */
plot3d(1, [theta, 0, %pi], [phi, 0, 2 * %pi],
[transform_xy, spherical_to_xyz], [grid, 30, 60],
[box, false], [legend, false])$
load(draw)$
draw3d(xu_grid=30, yv_grid=60, surface_hide=true,
parametric_surface(cos(phi)*sin(theta),
sin(phi)*sin(theta),
... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref symbols binary
import javax.swing.Timer
-- .+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
class RClockSwing public extends JFrame
-- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
properties c... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Racket | Racket | #lang racket/gui
(require sgl/gl)
; Macro to delimit and automatically end glBegin - glEnd contexts.
(define-syntax-rule (gl-begin-end Vertex-Mode statement ...)
(let () (glBegin Vertex-Mode) statement ... (glEnd)))
(define (resize w h)
(glViewport 0 0 w h))
(define (draw-opengl x y z)
(glClearColor 0.0 0.0... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #HicEst | HicEst | CHARACTER dragon
1 DLG(NameEdit=orders,DNum, Button='&OK', TItle=dragon) ! input orders
WINDOW(WINdowhandle=wh, Height=1, X=1, TItle='Dragon curves up to order '//orders)
IF( LEN(dragon) < 2^orders) ALLOCATE(dragon, 2^orders)
AXIS(WINdowhandle=wh, Xaxis=2048, Yaxis=2048) ! 2048: black, linear, ... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Nim | Nim | import math
type Point = tuple[x,y,z: float]
const shades = ".:!*oe&#%@"
proc normalize(x, y, z: float): Point =
let len = sqrt(x*x + y*y + z*z)
(x / len, y / len, z / len)
proc dot(a, b: Point): float =
result = max(0, - a.x*b.x - a.y*b.y - a.z*b.z)
let light = normalize(30.0, 30.0, -50.0)
proc drawS... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Nim | Nim | import times, os
const
t = ["⡎⢉⢵","⠀⢺⠀","⠊⠉⡱","⠊⣉⡱","⢀⠔⡇","⣏⣉⡉","⣎⣉⡁","⠊⢉⠝","⢎⣉⡱","⡎⠉⢱","⠀⠶⠀"]
b = ["⢗⣁⡸","⢀⣸⣀","⣔⣉⣀","⢄⣀⡸","⠉⠉⡏","⢄⣀⡸","⢇⣀⡸","⢰⠁⠀","⢇⣀⡸","⢈⣉⡹","⠀⠶ "]
while true:
let x = getClockStr()
stdout.write "\e[H\e[J"
for c in x: stdout.write t[c.ord - '0'.ord]
echo ""
for c in x: stdout.write ... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Raku | Raku | sub braille-graphics (%a) {
my ($ylo, $yhi, $xlo, $xhi);
for %a.keys -> $y {
$ylo min= +$y; $yhi max= +$y;
for %a{$y}.keys -> $x {
$xlo min= +$x; $xhi max= +$x;
}
}
for $ylo, $ylo + 4 ...^ * > $yhi -> \y {
for $xlo, $xlo + 2 ...^ * > $xhi -> \x {
my $cell = 0x2800;
$cell += 1 if %... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Icon_and_Unicon | Icon and Unicon | link linddraw,wopen
procedure main()
gener := 12 # generations
w := h := 800 # window size
rewrite := table() # L rewrite rules
rewrite["X"] := "X+YF+"
rewrite["Y"] := "-FX-Y"
every (C := '') ++:= !!rewrite
every /rewrite[c := !C] := c # map all rule characters
... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Ol | Ol |
(import (lib gl))
(import (OpenGL version-1-0))
; init
(glClearColor 0.3 0.3 0.3 1)
(glPolygonMode GL_FRONT_AND_BACK GL_FILL)
(define quadric (gluNewQuadric))
; draw loop
(gl:set-renderer (lambda (mouse)
(glClear GL_COLOR_BUFFER_BIT)
(glColor3f 0.7 0.7 0.7)
(gluSphere quadric 0.4 32 10)
))
|
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #OCaml | OCaml | #!/usr/bin/env ocaml
#load "unix.cma"
#load "graphics.cma"
open Graphics
let pi = 4.0 *. atan 1.0
let angle v max = float v /. max *. 2.0 *. pi
let () =
open_graph "";
set_window_title "OCaml Clock";
resize_window 256 256;
auto_synchronize false;
let w = size_x ()
and h = size_y () in
let rec loop () ... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Retro | Retro | 3 elements d h w
: spaces ( n- ) &space times ;
: --- ( - ) '+ putc @w 2 * [ '- putc ] times '+ putc ;
: ? ( n- ) @h <> [ '| ] [ '+ ] if ;
: slice ( n- ) '/ putc @w 2 * spaces '/ putc @d swap - dup spaces ? putc cr ;
: |...|/ ( - ) @h [ '| putc @w 2 * spaces '| putc 1- spaces '/ putc cr ] iterd ;... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #J | J | require 'plot'
start=: 0 0,: 1 0
step=: ],{: +"1 (0 _1,: 1 0) +/ .*~ |.@}: -"1 {:
plot <"1 |: step^:13 start |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Openscad | Openscad | // This will produce a sphere of radius 5
sphere(5); |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #ooRexx | ooRexx | /* REXX ---------------------------------------------------------------
* 09.02.2014 Walter Pachl with a little, well considerable, help from
* a friend (Mark Miesfeld)
* 1) downstripped an example contained in the ooRexx distribution
* 2) constructed the squares for seconds, minutes, and hours
... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #REXX | REXX | /*REXX program displays a cuboid (dimensions, if specified, must be positive integers).*/
parse arg x y z indent . /*x, y, z: dimensions and indentation.*/
x=p(x 2); y=p(y 3); z=p(z 4); in=p(indent 0) /*use the defaults if not specified. */
pad=left('', in) ... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Java | Java | import java.awt.Color;
import java.awt.Graphics;
import java.util.*;
import javax.swing.JFrame;
public class DragonCurve extends JFrame {
private List<Integer> turns;
private double startingAngle, side;
public DragonCurve(int iter) {
super("Dragon Curve");
setBounds(100, 100, 800, 600)... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #OxygenBasic | OxygenBasic |
% Title "Sphere"
'% Animated
% PlaceCentral
uses ConsoleG
sub main
========
cls 0.0, 0.2, 0.7
shading
scale 10
pushstate
GoldMaterial.act
go sphere
popstate
end sub
EndScript
|
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Perl | Perl | use utf8; # interpret source code as UTF8
binmode STDOUT, ':utf8'; # allow printing wide chars without warning
$|++; # disable output buffering
my ($rows, $cols) = split /\s+/, `stty size`;
my $x = int($rows / 2 - 1);
my $y = int($cols / 2 - 16);
my @chars = map {[ /(...)/g ]}
... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Ring | Ring |
# Project : Draw a cuboid
load "guilib.ring"
paint = null
new qapp
{
win1 = new qwidget() {
setwindowtitle("Draw a cuboid")
setgeometry(100,100,500,600)
label1 = new qlabel(win1) {
setgeometry(10,10,400,400)
... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #JavaScript | JavaScript | var DRAGON = (function () {
// MATRIX MATH
// -----------
var matrix = {
mult: function ( m, v ) {
return [ m[0][0] * v[0] + m[0][1] * v[1],
m[1][0] * v[0] + m[1][1] * v[1] ];
},
minus: function ( a, b ) {
return [ a[0]-b[0], a[1]-b[1] ];
},
... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Pascal | Pascal | use strict;
use warnings;
my $x = my $y = 255;
$x |= 1; # must be odd
my $depth = 255;
my $light = Vector->new(rand, rand, rand)->normalized;
print "P2\n$x $y\n$depth\n";
my ($r, $ambient) = (($x - 1)/2, 0);
my ($r2) = $r ** 2;
{
for my $x (-$r .. $r) {
my $x2 = $x**2;
for my $y (-$r .. $r) {
my $y2 ... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Phix | Phix | --
-- demo\rosetta\Clock.exw
-- ======================
--
with javascript_semantics
include pGUI.e
Ihandle dlg, canvas, hTimer
cdCanvas cd_canvas
procedure draw_hand(atom degrees, atom r, baseangle, baselen, cx, cy)
atom a = PI-(degrees+90)*PI/180,
-- tip
x1 = cos(a)*(r),
y1 = sin(a)*(r)... |
Subsets and Splits
Rosetta Code COBOL Python Hard Tasks
Identifies and retrieves challenging tasks that exist in both COBOL and Python, revealing cross-language programming patterns and difficulty levels for comparative analysis.
Rosetta Code Task Comparisons
Identifies tasks common to both COBOL and Python languages that are described as having difficulty levels, revealing cross-language task similarities and providing useful comparative programming examples.
SQL Code Examples from Training Data
Retrieves raw SQL code examples for the SQL language, which is basic data retrieval without meaningful analysis or patterns.
SQL Code Examples from Training Data
Retrieves raw SQL code examples for the SQL language, which is basic filtering that shows what data looks like but doesn't provide meaningful analysis or patterns.
Select Specific Languages Codes
Retrieves specific programming language names and codes from training data, providing basic filtering but limited analytical value beyond identifying these particular languages.