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/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Zoomscript | Zoomscript | print "Sleeping..."
wait 1
println
print "Awake!" |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Standard_ML | Standard ML | open XWindows ;
open Motif ;
val countWindow = fn () =>
let
val ctr = ref 0;
val shell = XtAppInitialise "" "demo" "top" [] [XmNwidth 300, XmNheight 150 ] ;
val main = XmCreateMainWindow shell "main" [XmNmappedWhenManaged true ] ;
val frame = XmCreateForm main "frame" ... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Tcl | Tcl | package require Tk
pack [label .l -text "There have been no clicks yet"]
set count 0
pack [button .b -text "click me" -command upd]
proc upd {} {
.l configure -text "Number of clicks: [incr ::count]"
} |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #C.23 | C# | using System;
class Program
{
static void Main()
{
Console.WriteLine(new DateTime());
}
} |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #C.2B.2B | C++ | #include <iostream>
#include <chrono>
#include <ctime>
int main()
{
std::chrono::system_clock::time_point epoch;
std::time_t t = std::chrono::system_clock::to_time_t(epoch);
std::cout << std::asctime(std::gmtime(&t)) << '\n';
return 0;
} |
http://rosettacode.org/wiki/Sierpinski_pentagon | Sierpinski pentagon | Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.
See also
Sierpinski pentagon
| #Nim | Nim | import math
import imageman
const
Red = ColorRGBU [byte 255, 0, 0]
Green = ColorRGBU [byte 0, 255, 0]
Blue = ColorRGBU [byte 0, 0, 255]
Magenta = ColorRGBU [byte 255, 0, 255]
Cyan = ColorRGBU [byte 0, 255, 255]
Black = ColorRGBU [byte 0, 0, 0]
(W, H) = (640, 640)
Deg72 = degToRad(72.0)
ScaleFactor... |
http://rosettacode.org/wiki/Sierpinski_pentagon | Sierpinski pentagon | Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.
See also
Sierpinski pentagon
| #Perl | Perl | use ntheory qw(todigits);
use Math::Complex;
$sides = 5;
$order = 5;
$dim = 250;
$scale = ( 3 - 5**.5 ) / 2;
push @orders, ((1 - $scale) * $dim) * $scale ** $_ for 0..$order-1;
open $fh, '>', 'sierpinski_pentagon.svg';
print $fh qq|<svg height="@{[$dim*2]}" width="@{[$dim*2]}" style="fill:blue" version="1.1" xmln... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #C.23 | C# | using System;
using System.Collections;
namespace RosettaCode {
class SierpinskiTriangle {
int len;
BitArray b;
public SierpinskiTriangle(int n) {
if (n < 1) {
throw new ArgumentOutOfRangeException("Order must be greater than zero");
}
... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | Sierpinski[n_] :=
Nest[Join @@ Table[With[{a = #[[i, 1]], b = #[[i, 2]], c = #[[i, 3]]},
{{a, (a + b)/2, (c + a)/2}, {(a + b)/2, b, (b + c)/2}, {(c + a)/2, (b + c)/2, c}}],
{i, Length[#]}] &, {{{0, 0}, {1/2, 1}, {1, 0}}}, n]
Graphics[{Black, Polygon /@ Sierpinski[8]}] |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #MATLAB | MATLAB | [x, x0] = deal(cat(3, [1 0]', [-1 0]', [0 sqrt(3)]'));
for k = 1 : 6
x = x(:,:) + x0 * 2 ^ k / 2;
end
patch('Faces', reshape(1 : 3 * 3 ^ k, 3, '')', 'Vertices', x(:,:)') |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #TI-89_BASIC | TI-89 BASIC | Prgm
Local clicks
0 → clicks
1 → ok © System variable also set by Dialog statement
While ok = 1
Dialog
Title "Rosetta Code"
Text "There have been " & string(clicks) & " OKs"
EndDlog
clicks + 1 → clicks
EndWhile
EndPrgm |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Unicon | Unicon |
import gui
$include "guih.icn"
class SimpleApp : Dialog (label)
# -- automatically called when the dialog is created
method component_setup()
# create and add the label
label := Label("label=There have been no clicks yet","pos=50%,33%", "align=c,c")
add (label)
# create and add the button
... |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Clojure | Clojure | (println (java.util.Date. 0)) |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #COBOL | COBOL | IDENTIFICATION DIVISION.
PROGRAM-ID. epoch.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 epoch-date.
03 year PIC 9(4).
03 month PIC 99.
03 dday PIC 99.
PROCEDURE DIVISION.
MOVE FUNCTIO... |
http://rosettacode.org/wiki/Sierpinski_pentagon | Sierpinski pentagon | Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.
See also
Sierpinski pentagon
| #Phix | Phix | --
-- demo\rosetta\SierpinskyPentagon.exw
-- ===================================
--
with javascript_semantics
include pGUI.e
Ihandle dlg, canvas
cdCanvas cddbuffer
constant title = "Sierpinski Pentagon",
scale_factor = 1/(2+cos(2*PI/5)*2),
side_factor = 1+cos(2*PI/5)*2,
angles = sq_mul(2*PI... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #C.2B.2B | C++ | #include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename OutIt>
void sierpinski(int n, OutIt result)
{
if( n == 0 )
{
*result++ = "*";
}
else
{
list<string> prev;
sierpinski(n-1, back_inserter(pr... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #Nim | Nim | import imageman
const
Black = ColorRGBU [byte 0, 0, 0] # For background.
Red = ColorRGBU [byte 255, 0, 0] # For triangle.
proc drawSierpinski(img: var Image; txy: array[1..6, float]; levelsYet: Natural) =
var nxy: array[1..6, float]
if levelsYet > 0:
for i in 1..6:
let pos = if i < 5: i + 2 else... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #Objeck | Objeck | use Game.SDL2;
use Game.Framework;
class Test {
@framework : GameFramework;
@colors : Color[];
@step : Int;
function : Main(args : String[]) ~ Nil {
Test->New()->Run();
}
New() {
@framework := GameFramework->New(GameConsts->SCREEN_WIDTH, GameConsts->SCREEN_HEIGHT, "Sierpinski Triangle");
@... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Vedit_macro_language | Vedit macro language | Reg_Set(10, "There have been no clicks yet")
#1 = 0
repeat (ALL) {
#2 = Dialog_Input_1(3, "`Simple Windowed Application`,
`|@(10)`,
`[&Click me]`,`[&Exit]`",
APP+CENTER, 0, 0)
if (#2 != 1) { break } // ESC or Exit
#1++
Num_Str(#... |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #CoffeeScript | CoffeeScript | console.log new Date(0).toISOString() |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Common_Lisp | Common Lisp | (multiple-value-bind (second minute hour day month year) (decode-universal-time 0 0)
(format t "~4,'0D-~2,'0D-~2,'0D ~2,'0D:~2,'0D:~2,'0D" year month day hour minute second)) |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #D | D | main() {
print(new Date.fromEpoch(0,new TimeZone.utc()));
} |
http://rosettacode.org/wiki/Sierpinski_pentagon | Sierpinski pentagon | Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.
See also
Sierpinski pentagon
| #Processing | Processing |
float s_angle, scale, margin = 25, total = 4;
float p_size = 700;
float radius = p_size/2-2*margin;
float side = radius * sin(PI/5)*2;
void setup() {
float temp = width/2;
size(590, 590);
background(0, 0, 200);
stroke(255);
s_angle = 72*PI/180;
scale = 1/(2+cos(s_angle)*2);
for (int i = 0; i < total; ... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #Clojure | Clojure | (ns example
(:require [clojure.contrib.math :as math]))
; Length of integer in binary
; (copied from a private multimethod in clojure.contrib.math)
(defmulti #^{:private true} integer-length class)
(defmethod integer-length java.lang.Integer [n]
(count (Integer/toBinaryString n)))
(defmethod integer-length java... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #OCaml | OCaml | open Graphics
let round v =
int_of_float (floor (v +. 0.5))
let middle (x1, y1) (x2, y2) =
((x1 +. x2) /. 2.0,
(y1 +. y2) /. 2.0)
let draw_line (x1, y1) (x2, y2) =
moveto (round x1) (round y1);
lineto (round x2) (round y2);
;;
let draw_triangle (p1, p2, p3) =
draw_line p1 p2;
draw_line p2 p3;
d... |
http://rosettacode.org/wiki/Simple_database | Simple database | Task
Write a simple tool to track a small set of data.
The tool should have a command-line interface to enter at least two different values.
The entered data should be stored in a structured format and saved to disk.
It does not matter what kind of data is being tracked. It could be a collection (CDs, coins, base... | #11l | 11l | T Item
String name, date, category
F (name, date, category)
.name = name
.date = date
.category = category
F String()
R .name‘, ’(.date)‘, ’(.category)
V db_filename = ‘simdb.csv’
F load()
[Item] db
L(line) File(:db_filename).read().rtrim("\n").split("\n")
V item = l... |
http://rosettacode.org/wiki/Shortest_common_supersequence | Shortest common supersequence | The shortest common supersequence is a problem closely related to the longest common subsequence, which you can use as an external function for this task.
Task
Given two strings
u
{\displaystyle u}
and
v
{\displaystyle v}
, find the shortest possible sequence
s
{\displaystyle s}
, whic... | #11l | 11l | F scs(String x, y)
I x.empty
R y
I y.empty
R x
I x[0] == y[0]
R x[0]‘’scs(x[1..], y[1..])
I scs(x, y[1..]).len <= scs(x[1..], y).len
R y[0]‘’scs(x, y[1..])
E
R x[0]‘’scs(x[1..], y)
print(scs(‘abcbdab’, ‘bdcaba’)) |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Visual_Basic | Visual Basic | VERSION 5.00
Begin VB.Form Form2
Caption = "There have been no clicks yet"
ClientHeight = 2940
ClientLeft = 60
ClientTop = 600
ClientWidth = 8340
LinkTopic = "Form1"
ScaleHeight = 2940
ScaleWidth = 8340
StartUpPosition = 3 'Windows ... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Web_68 | Web 68 | @1Introduction.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public Licence as published by
the Free Software Foundation, either version 3 of the Licence, or
(at your option) any later version.
Copyright (c) 2012 Sian Mountbatten.
@m cvs simpleapp = "$Id... |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Dart | Dart | main() {
print(new Date.fromEpoch(0,new TimeZone.utc()));
} |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Delphi | Delphi | program ShowEpoch;
{$APPTYPE CONSOLE}
uses SysUtils;
begin
Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', 0));
end. |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Erlang | Erlang | 2> calendar:universal_time().
{{2013,9,13},{8,3,16}}
3> calendar:datetime_to_gregorian_seconds(calendar:universal_time()).
63546278932
4> calendar:gregorian_seconds_to_datetime(63546278932).
{{2013,9,13},{8,8,52}}
11> calendar:gregorian_seconds_to_datetime(0).
{{0,1,1},{0,0,0}}
|
http://rosettacode.org/wiki/Sierpinski_pentagon | Sierpinski pentagon | Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.
See also
Sierpinski pentagon
| #Prolog | Prolog | main:-
write_sierpinski_pentagon('sierpinski_pentagon.svg', 600, 5).
write_sierpinski_pentagon(File, Size, Order):-
open(File, write, Stream),
format(Stream, "<svg xmlns='http://www.w3.org/2000/svg' width='~d' height='~d'>\n",
[Size, Size]),
write(Stream, "<rect width='100%' height='100%' fill=... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #CLU | CLU | sierpinski = proc (size: int) returns (string)
ss: stream := stream$create_output()
for i: int in int$from_to(0, size*4-1) do
c: int := 1
for j: int in int$from_to(1, size*4-1-i) do
stream$putc(ss, ' ')
end
for k: int in int$from_to(0, i) do
if c//2=0 th... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #PARI.2FGP | PARI/GP |
\\ Sierpinski triangle fractal
\\ Note: plotmat() can be found here on
\\ http://rosettacode.org/wiki/Brownian_tree#PARI.2FGP page.
\\ 6/3/16 aev
pSierpinskiT(n)={
my(sz=2^n,M=matrix(sz,sz),x,y);
for(y=1,sz, for(x=1,sz, if(!bitand(x,y),M[x,y]=1);));\\fends
plotmat(M);
}
{\\ Test:
pSierpinskiT(9); \\ SierpT9.png
}
|
http://rosettacode.org/wiki/Simple_database | Simple database | Task
Write a simple tool to track a small set of data.
The tool should have a command-line interface to enter at least two different values.
The entered data should be stored in a structured format and saved to disk.
It does not matter what kind of data is being tracked. It could be a collection (CDs, coins, base... | #Bracmat | Bracmat | whl
' ( arg$:?command
& ( get'db
| (db=1)&lst$(db,db,NEW)
)
& !command
: ( add
& :?name:?tag:?date
& whl
' ( arg$:?argmnt
& arg$:?value
& (!argmnt.!value)
: ( (title|name.?name)
| (category|tag.?tag)
... |
http://rosettacode.org/wiki/Shortest_common_supersequence | Shortest common supersequence | The shortest common supersequence is a problem closely related to the longest common subsequence, which you can use as an external function for this task.
Task
Given two strings
u
{\displaystyle u}
and
v
{\displaystyle v}
, find the shortest possible sequence
s
{\displaystyle s}
, whic... | #Ada | Ada | with Ada.Text_IO;
procedure Shortest is
function Scs (Left, Right : in String) return String is
Left_Tail : String renames Left (Left'First + 1 .. Left'Last);
Right_Tail : String renames Right (Right'First + 1 .. Right'Last);
begin
if Left = "" then return Right; end if;
if Right =... |
http://rosettacode.org/wiki/Shortest_common_supersequence | Shortest common supersequence | The shortest common supersequence is a problem closely related to the longest common subsequence, which you can use as an external function for this task.
Task
Given two strings
u
{\displaystyle u}
and
v
{\displaystyle v}
, find the shortest possible sequence
s
{\displaystyle s}
, whic... | #ALGOL_68 | ALGOL 68 | BEGIN
PRIO SCS = 1;
# returns the shortest common supersequence of x and y #
OP SCS = ( STRING x, y )STRING:
IF x = "" THEN y
ELIF y = "" THEN x
ELIF x[ LWB x ] = y[ LWB y ]
THEN x[ LWB x ] + ( x[ LWB x + 1 : ] SCS y[ LWB y + 1 : ] )
ELIF STRING x y sub = x S... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Wren | Wren | import "graphics" for Canvas, Color
import "input" for Mouse
import "dome" for Window
class SimpleWindowedApplication {
construct new(width, height) {
Window.title = "Simple windowed application"
_fore = Color.white
_clicks = 0
}
init() {
drawControls()
}
update... |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #F.23 | F# | printfn "%s" ((new System.DateTime()).ToString("u")) |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Factor | Factor | USING: calendar calendar.format io ;
0 micros>timestamp timestamp>ymdhms print |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Forth | Forth | include lib/longjday.4th
0 posix>jday .longjday cr |
http://rosettacode.org/wiki/Sierpinski_pentagon | Sierpinski pentagon | Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.
See also
Sierpinski pentagon
| #Python | Python | from turtle import *
import math
speed(0) # 0 is the fastest speed. Otherwise, 1 (slow) to 10 (fast)
hideturtle() # hide the default turtle
part_ratio = 2 * math.cos(math.radians(72))
side_ratio = 1 / (part_ratio + 2)
hide_turtles = True # show/hide turtles as they draw
path_color = "black" # path color
fi... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #COBOL | COBOL | identification division.
program-id. sierpinski-triangle-program.
data division.
working-storage section.
01 sierpinski.
05 n pic 99.
05 i pic 999.
05 k pic 999.
05 m pic 999.
05 c pic 9(18).
05 i-limit pic 999.
05 q ... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #Perl | Perl | my $levels = 6;
my $side = 512;
my $height = get_height($side);
sub get_height { my($side) = @_; $side * sqrt(3) / 2 }
sub triangle {
my($x1, $y1, $x2, $y2, $x3, $y3, $fill, $animate) = @_;
my $svg;
$svg .= qq{<polygon points="$x1,$y1 $x2,$y2 $x3,$y3"};
$svg .= qq{ style="fill: $fill; stroke-width... |
http://rosettacode.org/wiki/Simple_database | Simple database | Task
Write a simple tool to track a small set of data.
The tool should have a command-line interface to enter at least two different values.
The entered data should be stored in a structured format and saved to disk.
It does not matter what kind of data is being tracked. It could be a collection (CDs, coins, base... | #C | C | "Soon Rising","Dee","Lesace","10-12-2000","New Hat Press"
"Brave Chicken","Tang","Owe","04-01-2008","Nowhere Press"
"Aardvark Point","Dee","Lesace","5-24-2001","New Hat Press"
"Bat Whisperer, The","Tang","Owe","01-03-2004","Nowhere Press"
"Treasure Beach","Argus","Jemky","09-22-1999","Lancast"
|
http://rosettacode.org/wiki/Shortest_common_supersequence | Shortest common supersequence | The shortest common supersequence is a problem closely related to the longest common subsequence, which you can use as an external function for this task.
Task
Given two strings
u
{\displaystyle u}
and
v
{\displaystyle v}
, find the shortest possible sequence
s
{\displaystyle s}
, whic... | #C | C | #include <stdio.h>
#include <string.h>
typedef struct link link_t;
struct link {
int len;
char letter;
link_t *next;
};
// Stores a copy of a SCS of x and y in out. Caller needs to make sure out is long enough.
int scs(char *x, char *y, char *out)
{
int lx = strlen(x), ly = strlen(y);
link_t lnk[ly + 1][lx + ... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #XPL0 | XPL0 | include c:\cxpl\stdlib; \standard library provides mouse routines, etc.
def Ww=40, Wh=12, Wx=(80-Ww)/2, Wy=(25-Wh)/2; \window width, etc.
def Bw=11, Bh=4, Bx=Wx+(Ww-Bw)/2, By=Wy+3*(Wh-Bh)/4; \button size & position
int Clicks, Mx, My; \number of clicks and mouse coordinates
[ShowCurso... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Yorick | Yorick | #include "button.i"
window, 0;
btn_click = Button(text="click me", x=.395, y=.65, dx=0.04368, dy=0.0091);
btn_quit = Button(text="quit", x=.395, y=.6, dx=0.02184, dy=0.0091);
count = 0;
msg = "There have been no clicks yet";
finished = 0;
do {
fma;
plt, msg, .395, .7, justify="CH";
button_plot, btn_click;... |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Fortran | Fortran | ' FB 1.05.0 Win64
#Include "vbcompat.bi"
' The first argument to the Format function is a date serial
' and so the first statement below displays the epoch.
Dim f As String = "mmmm d, yyyy hh:mm:ss"
Print Format( 0 , f) '' epoch
Print Format( 0.5, f) '' noon on the same day
Print Format(-0.5, f) '' n... |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #FreeBASIC | FreeBASIC | ' FB 1.05.0 Win64
#Include "vbcompat.bi"
' The first argument to the Format function is a date serial
' and so the first statement below displays the epoch.
Dim f As String = "mmmm d, yyyy hh:mm:ss"
Print Format( 0 , f) '' epoch
Print Format( 0.5, f) '' noon on the same day
Print Format(-0.5, f) '' n... |
http://rosettacode.org/wiki/Sierpinski_pentagon | Sierpinski pentagon | Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.
See also
Sierpinski pentagon
| #Quackery | Quackery | [ $ "turtleduck.qky" loadfile ] now!
[ [ 1 1
30 times
[ tuck + ]
swap join ] constant
do ] is phi ( --> n/d )
[ 5 times
[ 2dup walk
1 5 turn ]
2drop ] is pentagon ( n/d n --> )
forward is pentaflake
[ dup 0 = iff ... |
http://rosettacode.org/wiki/Sierpinski_pentagon | Sierpinski pentagon | Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.
See also
Sierpinski pentagon
| #Racket | Racket | #lang racket/base
(require racket/draw pict racket/math racket/class)
;; exterior angle
(define 72-degrees (degrees->radians 72))
;; After scaling we'll have 2 sides plus a gap occupying the length
;; of a side before scaling. The gap is the base of an isosceles triangle
;; with a base angle of 72 degrees.
(define s... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #Comal | Comal | 0010 DIM part$(FALSE:TRUE) OF 2
0020 part$(FALSE):=" ";part$(TRUE):="* "
0030 INPUT "Order? ":order#
0040 size#:=2^order#
0050 FOR y#:=size#-1 TO 0 STEP -1 DO
0060 PRINT " "*y#,
0070 FOR x#:=0 TO size#-y#-1 DO PRINT part$(x# BITAND y#=0),
0080 PRINT
0090 ENDFOR y#
0100 END |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #Phix | Phix | -- demo\rosetta\SierpinskyTriangle.exw
include pGUI.e
Ihandle dlg, canvas
cdCanvas cddbuffer, cdcanvas
procedure SierpinskyTriangle(integer level, atom x, atom y, atom w, atom h)
atom w2 = w/2, w4 = w/4, h2 = h/2
if level=1 then
cdCanvasBegin(cddbuffer,CD_CLOSED_LINES)
cdCanvasVertex(cddbuff... |
http://rosettacode.org/wiki/Simple_database | Simple database | Task
Write a simple tool to track a small set of data.
The tool should have a command-line interface to enter at least two different values.
The entered data should be stored in a structured format and saved to disk.
It does not matter what kind of data is being tracked. It could be a collection (CDs, coins, base... | #C.23 | C# |
using System;
using System.IO;
namespace Simple_database
{
class Program
{
public static void Main(string[] args)
{
//
// For appropriate use of this program
// use standard Windows Command Processor or cmd.exe
//
// Create cmd.bat file at the same folder with executive version
// of program... |
http://rosettacode.org/wiki/Shortest_common_supersequence | Shortest common supersequence | The shortest common supersequence is a problem closely related to the longest common subsequence, which you can use as an external function for this task.
Task
Given two strings
u
{\displaystyle u}
and
v
{\displaystyle v}
, find the shortest possible sequence
s
{\displaystyle s}
, whic... | #C.23 | C# | public class ShortestCommonSupersequence
{
Dictionary<(string, string), string> cache = new();
public string scs(string x, string y)
{
if (x.Length == 0) return y;
if (y.Length == 0) return x;
if (cache.TryGetValue((x, y), out var result)) return result;
if (x[0] == y[0... |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #FutureBasic | FutureBasic | window 1
print date$
print date$("d MMM yyyy")
print date$("EEE, MMM d, yyyy")
print date$("MMMM d, yyyy ")
print date$("MMMM d, yyyy G")
print "This is day ";date$("D");" of the year"
print
print time$
print time$("hh:mm:ss")
print time$("h:mm a")
print time$("h:mm a zzz")
print
print time$("h:mm a ZZZZ "); date$("M... |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Go | Go | package main
import ("fmt"; "time")
func main() {
fmt.Println(time.Time{})
} |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Groovy | Groovy | def date = new Date(0)
def format = new java.text.SimpleDateFormat('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ')
format.timeZone = TimeZone.getTimeZone('UTC')
println (format.format(date)) |
http://rosettacode.org/wiki/Sierpinski_pentagon | Sierpinski pentagon | Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.
See also
Sierpinski pentagon
| #Raku | Raku | constant $sides = 5;
constant order = 5;
constant $dim = 250;
constant scaling-factor = ( 3 - 5**.5 ) / 2;
my @orders = ((1 - scaling-factor) * $dim) «*» scaling-factor «**» (^order);
my $fh = open('sierpinski_pentagon.svg', :w);
$fh.say: qq|<svg height="{$dim*2}" width="{$dim*2}" style="fill:blue" version="1.1"... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #Common_Lisp | Common Lisp | (defun print-sierpinski (order)
(loop with size = (expt 2 order)
repeat size
for v = (expt 2 (1- size)) then (logxor (ash v -1) (ash v 1))
do (fresh-line)
(loop for i below (integer-length v)
do (princ (if (logbitp i v) "*" " "))))) |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #PicoLisp | PicoLisp | (de sierpinski (N)
(let (D '("1") S "0")
(do N
(setq
D (conc
(mapcar '((X) (pack S X S)) D)
(mapcar '((X) (pack X "0" X)) D) )
S (pack S S) ) )
D ) )
(out '(display -)
(let Img (sierpinski 7)
(prinl "P1")
(prinl (length (car... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #PostScript | PostScript | %!PS
/sierp { % level ax ay bx by cx cy
6 cpy triangle
sierpr
} bind def
/sierpr {
12 cpy
10 -4 2 {
5 1 roll exch 4 -1 roll
add 0.5 mul 3 1 roll
add 0.5 mul 3 -1 roll
2 roll
} for % l a b c bc ac ab
13 -1 roll dup 0 gt {
1 sub
dup 4 cpy 1... |
http://rosettacode.org/wiki/Sierpinski_carpet | Sierpinski carpet | Task
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order N.
For example, the Sierpinski carpet of order 3 should look like this:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #11l | 11l | F sierpinski_carpet(n)
V carpet = [String(‘#’)]
L 1..n
carpet = carpet.map(x -> x‘’x‘’x)
[+] carpet.map(x -> x‘’x.replace(‘#’, ‘ ’)‘’x)
[+] carpet.map(x -> x‘’x‘’x)
R carpet.join("\n")
print(sierpinski_carpet(3)) |
http://rosettacode.org/wiki/Simple_database | Simple database | Task
Write a simple tool to track a small set of data.
The tool should have a command-line interface to enter at least two different values.
The entered data should be stored in a structured format and saved to disk.
It does not matter what kind of data is being tracked. It could be a collection (CDs, coins, base... | #COBOL | COBOL | IDENTIFICATION DIVISION.
PROGRAM-ID. simple-database.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT OPTIONAL database-file ASSIGN Database-Path
ORGANIZATION INDEXED
ACCESS SEQUENTIAL
RECORD KEY data-title
... |
http://rosettacode.org/wiki/Shortest_common_supersequence | Shortest common supersequence | The shortest common supersequence is a problem closely related to the longest common subsequence, which you can use as an external function for this task.
Task
Given two strings
u
{\displaystyle u}
and
v
{\displaystyle v}
, find the shortest possible sequence
s
{\displaystyle s}
, whic... | #C.2B.2B | C++ | #include <iostream>
std::string scs(std::string x, std::string y) {
if (x.empty()) {
return y;
}
if (y.empty()) {
return x;
}
if (x[0] == y[0]) {
return x[0] + scs(x.substr(1), y.substr(1));
}
if (scs(x, y.substr(1)).size() <= scs(x.substr(1), y).size()) {
r... |
http://rosettacode.org/wiki/Shortest_common_supersequence | Shortest common supersequence | The shortest common supersequence is a problem closely related to the longest common subsequence, which you can use as an external function for this task.
Task
Given two strings
u
{\displaystyle u}
and
v
{\displaystyle v}
, find the shortest possible sequence
s
{\displaystyle s}
, whic... | #D | D | import std.stdio, std.functional, std.array, std.range;
dstring scs(in dstring x, in dstring y) nothrow @safe {
alias mScs = memoize!scs;
if (x.empty) return y;
if (y.empty) return x;
if (x.front == y.front)
return x.front ~ mScs(x.dropOne, y.dropOne);
if (mScs(x, y.dropOne).length <= mScs... |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Haskell | Haskell | import System.Time
main = putStrLn $ calendarTimeToString $ toUTCTime $ TOD 0 0 |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Icon_and_Unicon | Icon and Unicon | link printf,datetime
procedure main()
# Unicon
now := gettimeofday().sec
if now = &now then printf("&now and gettimeofday().sec are equal\n")
printf("Now (UTC) %s, (local) %s\n",gtime(now),ctime(now))
printf("Epoch %s\n",gtime(0))
# Icon and Unicon
now := DateToSec(&date) + ClockToSec(&clock)
printf(... |
http://rosettacode.org/wiki/Sierpinski_pentagon | Sierpinski pentagon | Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.
See also
Sierpinski pentagon
| #Ruby | Ruby |
THETA = Math::PI * 2 / 5
SCALE_FACTOR = (3 - Math.sqrt(5)) / 2
MARGIN = 20
attr_reader :pentagons, :renderer
def settings
size(400, 400)
end
def setup
sketch_title 'Pentaflake'
radius = width / 2 - 2 * MARGIN
center = Vec2D.new(radius - 2 * MARGIN, 3 * MARGIN)
pentaflake = Pentaflake.new(center, radius,... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #Cowgol | Cowgol | include "cowgol.coh";
include "argv.coh";
var order: uint8 := 4; # default order
# Read order from command line if there is an argument
ArgvInit();
var argmt := ArgvNext();
if argmt != 0 as [uint8] then
var a: int32;
(a, argmt) := AToI(argmt);
if a<3 or 7<a then
print("Order must be between 3 a... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #Processing | Processing |
PVector [] coord = {new PVector(0, 0), new PVector(150, 300), new PVector(300, 0)};
void setup()
{
size(400,400);
background(32);
sierpinski(new PVector(150,150), 8);
noLoop();
}
void sierpinski(PVector cPoint, int cDepth)
{
if (cDepth == 0) {
set(50+int(cPoint.x), (height-50)-int(cPoint.y), color... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #Prolog | Prolog | sierpinski(N) :-
sformat(A, 'Sierpinski order ~w', [N]),
new(D, picture(A)),
draw_Sierpinski(D, N, point(350,50), 600),
send(D, size, size(690,690)),
send(D, open).
draw_Sierpinski(Window, 1, point(X, Y), Len) :-
X1 is X - round(Len/2),
X2 is X + round(Len/2),
Y1 is Y + Len * sqrt(3) / 2,
send(Window, displa... |
http://rosettacode.org/wiki/Sierpinski_carpet | Sierpinski carpet | Task
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order N.
For example, the Sierpinski carpet of order 3 should look like this:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #Action.21 | Action! | BYTE FUNC InCarpet(BYTE x,y)
DO
IF x MOD 3=1 AND y MOD 3=1 THEN
RETURN (0)
FI
x==/3 y==/3
UNTIL x=0 AND y=0
OD
RETURN (1)
PROC DrawCarpet(INT x0 BYTE y0,depth)
BYTE i,x,y,size
size=1
FOR i=1 TO depth
DO size==*3 OD
FOR y=0 TO size-1
DO
FOR x=0 TO size-1
DO
IF InCa... |
http://rosettacode.org/wiki/Simple_database | Simple database | Task
Write a simple tool to track a small set of data.
The tool should have a command-line interface to enter at least two different values.
The entered data should be stored in a structured format and saved to disk.
It does not matter what kind of data is being tracked. It could be a collection (CDs, coins, base... | #Common_Lisp | Common Lisp | (defvar *db* nil)
(defvar *db-cat* (make-hash-table :test 'equal))
(defvar *db-file* "db.txt")
(defstruct item
"this is the unit of data stored/displayed in *db*"
(title " ")
(category "default")
(date (progn (get-universal-time))))
(defun set-category(new-item)
(setf (gethash (item-category n... |
http://rosettacode.org/wiki/Shortest_common_supersequence | Shortest common supersequence | The shortest common supersequence is a problem closely related to the longest common subsequence, which you can use as an external function for this task.
Task
Given two strings
u
{\displaystyle u}
and
v
{\displaystyle v}
, find the shortest possible sequence
s
{\displaystyle s}
, whic... | #Elixir | Elixir | defmodule SCS do
def scs(u, v) do
lcs = LCS.lcs(u, v) |> to_charlist
scs(to_charlist(u), to_charlist(v), lcs, []) |> to_string
end
defp scs(u, v, [], res), do: Enum.reverse(res) ++ u ++ v
defp scs([h|ut], [h|vt], [h|lt], res), do: scs(ut, vt, lt, [h|res])
defp scs([h|_]=u, [vh|vt], [h|_]=lcs, r... |
http://rosettacode.org/wiki/Shortest_common_supersequence | Shortest common supersequence | The shortest common supersequence is a problem closely related to the longest common subsequence, which you can use as an external function for this task.
Task
Given two strings
u
{\displaystyle u}
and
v
{\displaystyle v}
, find the shortest possible sequence
s
{\displaystyle s}
, whic... | #Factor | Factor | USING: combinators io kernel locals math memoize sequences ;
MEMO:: scs ( x y -- seq )
{
{ [ x empty? ] [ y ] }
{ [ y empty? ] [ x ] }
{ [ x first y first = ]
[ x rest y rest scs x first prefix ] }
{ [ x y rest scs length x rest y scs length <= ]
[ x y rest scs ... |
http://rosettacode.org/wiki/Shortest_common_supersequence | Shortest common supersequence | The shortest common supersequence is a problem closely related to the longest common subsequence, which you can use as an external function for this task.
Task
Given two strings
u
{\displaystyle u}
and
v
{\displaystyle v}
, find the shortest possible sequence
s
{\displaystyle s}
, whic... | #Go | Go | package main
import (
"fmt"
"strings"
)
func lcs(x, y string) string {
xl, yl := len(x), len(y)
if xl == 0 || yl == 0 {
return ""
}
x1, y1 := x[:xl-1], y[:yl-1]
if x[xl-1] == y[yl-1] {
return fmt.Sprintf("%s%c", lcs(x1, y1), x[xl-1])
}
x2, y2 := lcs(x, y1), lcs(x1... |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #J | J | 6!:0''
2011 8 8 20 25 44.725 |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Java | Java | import java.text.DateFormat;
import java.util.Date;
import java.util.TimeZone;
public class DateTest{
public static void main(String[] args) {
Date date = new Date(0);
DateFormat format = DateFormat.getDateTimeInstance();
format.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.... |
http://rosettacode.org/wiki/Sierpinski_pentagon | Sierpinski pentagon | Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.
See also
Sierpinski pentagon
| #Rust | Rust | // [dependencies]
// svg = "0.8.0"
fn sierpinski_pentagon(
mut document: svg::Document,
mut x: f64,
mut y: f64,
mut side: f64,
order: usize,
) -> svg::Document {
use std::f64::consts::PI;
use svg::node::element::Polygon;
let degrees72 = 0.4 * PI;
let mut angle = 3.0 * degrees72;
... |
http://rosettacode.org/wiki/Sierpinski_pentagon | Sierpinski pentagon | Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.
See also
Sierpinski pentagon
| #Scala | Scala | import java.awt._
import java.awt.event.ActionEvent
import java.awt.geom.Path2D
import javax.swing._
import scala.annotation.tailrec
import scala.math.{Pi, cos, sin, sqrt}
object SierpinskiPentagon extends App {
SwingUtilities.invokeLater(() => {
class SierpinskiPentagon extends JPanel {
/* Try to... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #D | D | void main() /*@safe*/ {
import std.stdio, std.algorithm, std.string, std.array;
enum level = 4;
auto d = ["*"];
foreach (immutable n; 0 .. level) {
immutable sp = " ".replicate(2 ^^ n);
d = d.map!(a => sp ~ a ~ sp).array ~
d.map!(a => a ~ " " ~ a).array;
}
d.join('\... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #Python | Python |
# a very simple version
import turtle as t
def sier(n,length):
if n == 0:
return
for i in range(3):
sier(n - 1, length / 2)
t.fd(length)
t.rt(120)
|
http://rosettacode.org/wiki/Sierpinski_carpet | Sierpinski carpet | Task
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order N.
For example, the Sierpinski carpet of order 3 should look like this:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #Ada | Ada | with Ada.Text_Io; use Ada.Text_Io;
procedure Sierpinski_Carpet is
subtype Index_Type is Integer range 1..81;
type Pattern_Array is array(Index_Type range <>, Index_Type range <>) of Boolean;
Pattern : Pattern_Array(1..81,1..81) := (Others =>(others => true));
procedure Clear_Center(P : in out Pattern_Arra... |
http://rosettacode.org/wiki/Simple_database | Simple database | Task
Write a simple tool to track a small set of data.
The tool should have a command-line interface to enter at least two different values.
The entered data should be stored in a structured format and saved to disk.
It does not matter what kind of data is being tracked. It could be a collection (CDs, coins, base... | #D | D | import std.stdio, std.algorithm, std.string, std.conv, std.array,
std.file, std.csv, std.datetime;
private {
immutable filename = "simdb.csv";
struct Item {
string name, date, category;
}
void addItem(in string[] item) {
if (item.length < 3)
return printUsage();
... |
http://rosettacode.org/wiki/Shortest_common_supersequence | Shortest common supersequence | The shortest common supersequence is a problem closely related to the longest common subsequence, which you can use as an external function for this task.
Task
Given two strings
u
{\displaystyle u}
and
v
{\displaystyle v}
, find the shortest possible sequence
s
{\displaystyle s}
, whic... | #Haskell | Haskell | scs :: Eq a => [a] -> [a] -> [a]
scs [] ys = ys
scs xs [] = xs
scs xss@(x:xs) yss@(y:ys)
| x == y = x : scs xs ys
| otherwise = ws
where
us = scs xs yss
vs = scs xss ys
ws | length us < length vs = x : us
| otherwise = y : vs
main = putStrLn $ scs "abcbdab" "bdcaba" |
http://rosettacode.org/wiki/Shortest_common_supersequence | Shortest common supersequence | The shortest common supersequence is a problem closely related to the longest common subsequence, which you can use as an external function for this task.
Task
Given two strings
u
{\displaystyle u}
and
v
{\displaystyle v}
, find the shortest possible sequence
s
{\displaystyle s}
, whic... | #Java | Java | public class ShortestCommonSuperSequence {
private static boolean isEmpty(String s) {
return null == s || s.isEmpty();
}
private static String scs(String x, String y) {
if (isEmpty(x)) {
return y;
}
if (isEmpty(y)) {
return x;
}
if ... |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #JavaScript | JavaScript | document.write(new Date(0).toUTCString()); |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #jq | jq | 0 | todate |
http://rosettacode.org/wiki/Show_the_epoch | Show the epoch | Task
Choose popular date libraries used by your language and show the epoch those libraries use.
A demonstration is preferable (e.g. setting the internal representation of the date to 0 ms/ns/etc., or another way that will still show the epoch even if it is changed behind the scenes by the implementers), b... | #Julia | Julia | using Base.Dates # just using Dates in versions > 0.6
println("Time zero (the epoch) is $(unix2datetime(0)).") |
http://rosettacode.org/wiki/Sierpinski_pentagon | Sierpinski pentagon | Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.
See also
Sierpinski pentagon
| #Sidef | Sidef | define order = 5
define sides = 5
define dim = 500
define scaling_factor = ((3 - 5**0.5) / 2)
var orders = order.of {|i| ((1-scaling_factor) * dim) * scaling_factor**i }
say <<"STOP";
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg... |
http://rosettacode.org/wiki/Sierpinski_triangle | Sierpinski triangle | Task
Produce an ASCII representation of a Sierpinski triangle of order N.
Example
The Sierpinski triangle of order 4 should look like this:
*
* *
* *
* * * *
* *
* * * *
... | #Delphi | Delphi | program SierpinskiTriangle;
{$APPTYPE CONSOLE}
procedure PrintSierpinski(order: Integer);
var
x, y, size: Integer;
begin
size := (1 shl order) - 1;
for y := size downto 0 do
begin
Write(StringOfChar(' ', y));
for x := 0 to size - y do
begin
if (x and y) = 0 then
Write('* ')
e... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #Quackery | Quackery | [ $ "turtleduck.qky" loadfile ] now!
[ 1 & ] is odd ( n --> b )
[ 4 times
[ 2dup walk
1 4 turn ]
2drop ] is square ( n/d --> )
[ dup
witheach
[ odd if
[ ' [ 0 0 0 ] fill
[ 2 1 square ] ]
2 1 fly ]
... |
http://rosettacode.org/wiki/Sierpinski_triangle/Graphical | Sierpinski triangle/Graphical | Produce a graphical representation of a Sierpinski triangle of order N in any orientation.
An example of Sierpinski's triangle (order = 8) looks like this:
| #R | R |
## Plotting Sierpinski triangle. aev 4/1/17
## ord - order, fn - file name, ttl - plot title, clr - color
pSierpinskiT <- function(ord, fn="", ttl="", clr="navy") {
m=640; abbr="STR"; dftt="Sierpinski triangle";
n=2^ord; M <- matrix(c(0), ncol=n, nrow=n, byrow=TRUE);
cat(" *** START", abbr, date(), "\n");
if(... |
http://rosettacode.org/wiki/Sierpinski_carpet | Sierpinski carpet | Task
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order N.
For example, the Sierpinski carpet of order 3 should look like this:
###########################
# ## ## ## ## ## ## ## ## #
###########################
### ###### ###### ###
# # # ## # # ## # # #
### ###### ... | #ALGOL_68 | ALGOL 68 | PROC in carpet = (INT in x, in y)BOOL: (
INT x := in x, y := in y;
BOOL out;
DO
IF x = 0 OR y = 0 THEN
out := TRUE; GO TO stop iteration
ELIF x MOD 3 = 1 AND y MOD 3 = 1 THEN
out := FALSE; GO TO stop iteration
FI;
x %:= 3;
y %:= 3
OD;
... |
http://rosettacode.org/wiki/Shoelace_formula_for_polygonal_area | Shoelace formula for polygonal area | Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by:
abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) -
(sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N])
) / 2
(Where abs returns the absolute value)
Task
Write ... | #11l | 11l | F area_by_shoelace(x, y)
R abs(sum(zip(x, y[1..] [+] y[0.<1]).map((i, j) -> i * j))
-sum(zip(x[1..] [+] x[0.<1], y).map((i, j) -> i * j))) / 2
V points = [(3, 4), (5, 11), (12, 8), (9, 5), (5, 6)]
V x = points.map(p -> p[0])
V y = points.map(p -> p[1])
print(area_by_shoelace(x, y)) |
http://rosettacode.org/wiki/Simple_database | Simple database | Task
Write a simple tool to track a small set of data.
The tool should have a command-line interface to enter at least two different values.
The entered data should be stored in a structured format and saved to disk.
It does not matter what kind of data is being tracked. It could be a collection (CDs, coins, base... | #Erlang | Erlang |
#! /usr/bin/env escript
-compile({no_auto_import,[date/0]}).
main( ["add", Tag | Descriptions] ) -> add( date(), Tag, Descriptions );
main( ["add_date", Date, Tag | Descriptions] ) -> add( date_internal(string:tokens(Date, "-")), Tag, Descriptions );
main( ["print_latest"] ) -> print_latest( contents() );
main( [... |
http://rosettacode.org/wiki/Shortest_common_supersequence | Shortest common supersequence | The shortest common supersequence is a problem closely related to the longest common subsequence, which you can use as an external function for this task.
Task
Given two strings
u
{\displaystyle u}
and
v
{\displaystyle v}
, find the shortest possible sequence
s
{\displaystyle s}
, whic... | #jq | jq | # largest common substring
# Uses recursion, taking advantage of jq's TCO
def lcs:
. as [$x, $y]
| if ($x|length == 0) or ($y|length == 0) then ""
else $x[:-1] as $x1
| $y[:-1] as $y1
| if $x[-1:] == $y[-1:] then ([$x1, $y1] | lcs) + $x[-1:]
else ([$x, $y1] | lcs) as $x2
| ([$x1, $y] | lcs) ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.