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/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...
#Julia
Julia
using Memoize   @memoize function scs(x, y) if x == "" return y elseif y == "" return x elseif x[1] == y[1] return "$(x[1])$(scs(x[2:end], y[2:end]))" elseif length(scs(x, y[2:end])) <= length(scs(x[2:end], y)) return "$(y[1])$(scs(x, y[2:end]))" else return "...
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...
#Kotlin
Kotlin
// version 1.1.2   fun lcs(x: String, y: String): String { if (x.length == 0 || y.length == 0) return "" val x1 = x.dropLast(1) val y1 = y.dropLast(1) if (x.last() == y.last()) return lcs(x1, y1) + x.last() val x2 = lcs(x, y1) val y2 = lcs(x1, y) return if (x2.length > y2.length) x2 else y...
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...
#Kotlin
Kotlin
// version 1.1.2   import java.util.Date import java.util.TimeZone import java.text.DateFormat   fun main( args: Array<String>) { val epoch = Date(0) val format = DateFormat.getDateTimeInstance() format.timeZone = TimeZone.getTimeZone("UTC") println(format.format(epoch)) }
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...
#Lasso
Lasso
date(0.00) date(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
#VBA
VBA
Private Sub sierpinski(Order_ As Integer, Side As Double) Dim Circumradius As Double, Inradius As Double Dim Height As Double, Diagonal As Double, HeightDiagonal As Double Dim Pi As Double, p(5) As String, Shp As Shape Circumradius = Sqr(50 + 10 * Sqr(5)) / 10 Inradius = Sqr(25 + 10 * Sqr(5)) / 10 ...
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
#Wren
Wren
import "graphics" for Canvas, Color import "dome" for Window import "math" for Math   var Deg72 = 72 * Num.pi / 180 // 72 degrees in radians var ScaleFactor = 1 / (2 + Math.cos(Deg72) * 2) var Palette = [Color.red, Color.blue, Color.green, Color.indigo, Color.brown] var ColorIndex = 0 var OldX = 0 var OldY = 0   class...
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: * * * * * * * * * * * * * * * ...
#Draco
Draco
word SIZE = 1 << 4;   proc nonrec main() void: unsigned SIZE x, y; for y from SIZE-1 downto 0 do for x from 1 upto y do write(' ') od; for x from 0 upto SIZE - y - 1 do write(if x & y ~= 0 then " " else "* " fi) od; writeln() od corp
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:
#Racket
Racket
  #lang racket (require 2htdp/image) (define (sierpinski n) (if (zero? n) (triangle 2 'solid 'red) (let ([t (sierpinski (- n 1))]) (freeze (above t (beside t t))))))  
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:
#Raku
Raku
my $levels = 8; my $side = 512; my $height = get_height($side);   sub get_height ($side) { $side * 3.sqrt / 2 }   sub triangle ( $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: 0;"} if $fill; ...
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_W
ALGOL W
begin for depth := 3 do begin integer dim; dim  := 1; for i := 0 until depth - 1 do dim := dim * 3; for i  := 0 until dim - 1 do begin for j := 0 until dim - 1 do begin integer d; d := dim div 3; while d not = 0 ...
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 ...
#360_Assembly
360 Assembly
* SHOELACE 25/02/2019 SHOELACE CSECT USING SHOELACE,R15 base register MVC SUPS(8),POINTS x(nt+1)=x(1); y(nt+1)=y(1) LA R9,0 area=0 LA R7,POINTS @x(1) LA R6,NT do i=1 to nt LOOP L R...
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 ...
#Action.21
Action!
INCLUDE "H6:REALMATH.ACT"   PROC Area(INT ARRAY xs,ys BYTE count REAL POINTER res) BYTE i,next REAL x1,y1,x2,y2,tmp1,tmp2   IntToReal(0,res) IntToReal(xs(0),x1) IntToReal(ys(0),y1) FOR i=0 TO count-1 DO next=i+1 IF next=count THEN next=0 FI IntToReal(xs(next),x2) IntToReal(ys(next),y2)...
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...
#Forth
Forth
+: betty 1974.03.03;coworker;reading; +: geea 1980.01.01;friend;sketch writer; +: tom 1991.03.07;family member;reading; +: alice 1987.09.01;coworker;classical music; +: gammaQ3.14 3045.09.09;friend;watch movies, star walking;
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...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
ClearAll[RosettaShortestCommonSuperSequence] RosettaShortestCommonSuperSequence[aa_String, bb_String] := Module[{lcs, scs, a = aa, b = bb}, lcs = LongestCommonSubsequence[aa, bb]; scs = ""; While[StringLength[lcs] > 0, If[StringTake[a, 1] == StringTake[lcs, 1] \[And] StringTake[b, 1] == StringTake[lcs, 1], ...
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...
#Nim
Nim
proc lcs(x, y: string): string = if x.len == 0 or y.len == 0: return let x1 = x[0..^2] let y1 = y[0..^2] if x[^1] == y[^1]: return lcs(x1, y1) & x[^1] let x2 = lcs(x, y1) let y2 = lcs(x1, y) result = if x2.len > y2.len: x2 else: y2   proc scs(u, v: string): string = let lcs = lcs(u, v) var ui, vi = 0 ...
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...
#Perl
Perl
sub lcs { # longest common subsequence my( $u, $v ) = @_; return '' unless length($u) and length($v); my $longest = ''; for my $first ( 0..length($u)-1 ) { my $char = substr $u, $first, 1; my $i = index( $v, $char ); next if -1==$i; my $next = $char; $next .= lcs(...
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...
#Limbo
Limbo
implement Epoch;   include "sys.m"; sys: Sys; include "draw.m"; include "daytime.m"; daytime: Daytime; Tm: import daytime;   Epoch: module { init: fn(nil: ref Draw->Context, nil: list of string); };   init(nil: ref Draw->Context, nil: list of string) { sys = load Sys Sys->PATH; daytime = load Daytime Daytime->PATH;...
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...
#Lingo
Lingo
now = the systemDate put now -- date( 2018, 3, 21 )   babylonianDate = date(-1800,1,1)   -- print approx. year difference between "babylonianDate" and now put (now-babylonianDate)/365.2425 -- 3818.1355
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...
#LiveCode
LiveCode
put 0 into somedate convert somedate to internet date put somedate   -- output GMT (localised) -- Thu, 1 Jan 1970 10:00:00 +1000  
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
#zkl
zkl
const order=5, sides=5, dim=250, scaleFactor=((3.0 - (5.0).pow(0.5))/2); const tau=(0.0).pi*2; // 2*pi*r orders:=order.pump(List,fcn(n){ (1.0 - scaleFactor)*dim*scaleFactor.pow(n) });   println( #<<< 0'|<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/...
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: * * * * * * * * * * * * * * * ...
#DWScript
DWScript
procedure PrintSierpinski(order : Integer); var x, y, size : Integer; begin size := (1 shl order)-1; for y:=size downto 0 do begin Print(StringOfChar(' ', y)); for x:=0 to size-y do begin if (x and y)=0 then Print('* ') else Print(' '); end; PrintLn(''); ...
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:
#Ring
Ring
  load "guilib.ring"   new qapp { win1 = new qwidget() { setwindowtitle("drawing using qpainter") setgeometry(100,100,500,500) label1 = new qlabel(win1) { setgeometry(10,10,400,400) settext("") } new qpushbu...
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:
#Ruby
Ruby
Shoes.app(:height=>540,:width=>540, :title=>"Sierpinski Triangle") do def triangle(slot, tri, color) x, y, len = tri slot.append do fill color shape do move_to(x,y) dx = len * Math::cos(Math::PI/3) dy = len * Math::sin(Math::PI/3) line_to(x-dx, y+dy) line_to...
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: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#APL
APL
carpet←{{⊃⍪/,⌿3 3⍴4 0 4\⊂⍵}⍣⍵⊢⍪'#'}
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 ...
#Ada
Ada
with Ada.Text_IO;   procedure Shoelace_Formula_For_Polygonal_Area is type Point is record x, y : Float; end record;   type Polygon is array (Positive range <>) of Point;   function Shoelace(input : in Polygon) return Float is sum_1 : Float := 0.0; sum_2 : Float := 0.0; tmp : const...
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...
#Go
Go
package main   import ( "encoding/json" "fmt" "io" "os" "sort" "strings" "time" "unicode" )   // Database record format. Time stamp and name are required. // Tags and notes are optional. type Item struct { Stamp time.Time Name string Tags []string `json:",omitempty"` 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...
#Phix
Phix
with javascript_semantics function longest_common_subsequence(sequence a, b) sequence res = "" if length(a) and length(b) then if a[$]=b[$] then res = longest_common_subsequence(a[1..-2],b[1..-2])&a[$] else sequence l = longest_common_subsequence(a,b[1..-2]), ...
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...
#LotusScript
LotusScript
  Sub Click(Source As Button) 'Create timestamp as of now Dim timeStamp As NotesDateTime Set timeStamp = New NotesDateTime ( Now )   'Assign epoch start time to variable Dim epochTime As NotesDateTime Set epochTime = New NotesDateTime ( "01/01/1970 00:00:00 AM GMT" ) ''' These two commands only to get epoc...
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...
#Lua
Lua
print(os.date("%c", 0))
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: * * * * * * * * * * * * * * * ...
#E
E
def printSierpinski(order, out) { def size := 2**order for y in (0..!size).descending() { out.print(" " * y) for x in 0..!(size-y) { out.print((x & y).isZero().pick("* ", " ")) } out.println() } }
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:
#Rust
Rust
// [dependencies] // svg = "0.8.0"   const SQRT3_2: f64 = 0.86602540378444;   fn sierpinski_triangle( mut document: svg::Document, mut x: f64, mut y: f64, mut side: f64, order: usize, ) -> svg::Document { use svg::node::element::Polygon;   if order == 1 { let mut points = Vec::new();...
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:
#Seed7
Seed7
$ include "seed7_05.s7i"; include "draw.s7i"; include "keybd.s7i"; include "bin64.s7i";   const proc: main is func local const integer: order is 8; const integer: width is 1 << order; const integer: margin is 10; var integer: x is 0; var integer: y is 0; begin screen(width + 2 * margin...
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: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#AppleScript
AppleScript
----------------------- CARPET MODEL ---------------------   -- sierpinskiCarpet :: Int -> [[Bool]] on sierpinskiCarpet(n)   -- rowStates :: Int -> [Bool] script rowStates on |λ|(x, _, xs)   -- cellState :: Int -> Bool script cellState   -- inCarpet :: Int -> Int ...
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 ...
#ALGOL_60
ALGOL 60
begin comment Shoelace formula for polygonal area - Algol 60; real array x[1:33],y[1:33]; integer i,n; real a; ininteger(0,n); for i:=1 step 1 until n do begin inreal(0,x[i]); inreal(0,y[i]) end; x[i]:=x[1]; y[i]:=y[1]; a:=0; for i:=1 step 1 until n do ...
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 ...
#ALGOL_68
ALGOL 68
BEGIN # returns the area of the polygon defined by the points p using the Shoelace formula # OP AREA = ( [,]REAL p )REAL: BEGIN [,]REAL points = p[ AT 1, AT 1 ]; # normalise array bounds to start at 1 # IF 2 UPB points /= 2 THEN # the points do not have 2 coordin...
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...
#Haskell
Haskell
import Control.Monad.State import Data.List (sortBy, nub) import System.Environment (getArgs, getProgName) import System.Directory (doesFileExist) import System.IO (openFile, hGetContents, hClose, IOMode(..), Handle, hPutStrLn)   -- for storing dates data Date = Date Integer Int Int deriving (Show, Read, Eq, Ord)  ...
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...
#Python
Python
  # Use the Longest Common Subsequence algorithm   def shortest_common_supersequence(a, b): lcs = longest_common_subsequence(a, b) scs = "" # Consume lcs while len(lcs) > 0: if a[0]==lcs[0] and b[0]==lcs[0]: # Part of the LCS, so consume from all strings scs += lcs[0] ...
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...
#Racket
Racket
#lang racket   (struct link (len letters))   (define (link-add li n letter) (link (+ n (link-len li)) (cons letter (link-letters li))))   (define (memoize f) (local ([define table (make-hash)]) (lambda args (dict-ref! table args (λ () (apply f args))))))   (define scs/list (memoize (lambda ...
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...
#Raku
Raku
sub lcs(Str $xstr, Str $ystr) { # longest common subsequence return "" unless $xstr && $ystr; my ($x, $xs, $y, $ys) = $xstr.substr(0, 1), $xstr.substr(1), $ystr.substr(0, 1), $ystr.substr(1); return $x eq $y ?? $x ~ lcs($xs, $ys) !! max(:by{ $^a.chars }, lcs($xstr, $ys), lcs($xs, $ystr) ); }...
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...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
DateString[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...
#MATLAB_.2F_Octave
MATLAB / Octave
d = [0,1,2,3.5,-3.5,1000*365,1000*366,now+[-1,0,1]]; for k=1:length(d) printf('day %f\t%s\n',d(k),datestr(d(k),0)) disp(datevec(d(k))) end;
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: * * * * * * * * * * * * * * * ...
#Elixir
Elixir
defmodule RC do def sierpinski_triangle(n) do f = fn(x) -> IO.puts "#{x}" end Enum.each(triangle(n, ["*"], " "), f) end   defp triangle(0, down, _), do: down defp triangle(n, down, sp) do newDown = (for x <- down, do: sp<>x<>sp) ++ (for x <- down, do: x<>" "<>x) triangle(n-1, newDown, sp<>sp) ...
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:
#Sidef
Sidef
func sierpinski_triangle(n) -> Array { var triangle = ['*'] { |i| var sp = (' ' * 2**i) triangle = (triangle.map {|x| sp + x + sp} + triangle.map {|x| x + ' ' + x}) } * n triangle }   class Array { method to_png(scale=1, bgcolor='white', fgcolor='black') {   static gd = require('GD...
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: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#Applesoft_BASIC
Applesoft BASIC
100 HGR 110 POKE 49234,0 120 DEF FN M(X) = X - INT (D * 3) * INT (X / INT (D * 3)) 130 DE = 4 140 DI = 3 ^ DE * 3 150 FOR I = 0 TO DI - 1 160 FOR J = 0 TO DI - 1 170 FOR D = DI / 3 TO 0 STEP 0 180 IF INT ( FN M(I) / D) = 1 AND INT ( FN M(J) / D) = 1 THEN 200BREAK 190 ...
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 ...
#APL
APL
shoelace ← 2÷⍨|∘(((1⊃¨⊢)+.×1⌽2⊃¨⊢)-(1⌽1⊃¨⊢)+.×2⊃¨⊢)
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 ...
#AutoHotkey
AutoHotkey
V := [[3, 4], [5, 11], [12, 8], [9, 5], [5, 6]]   n := V.Count() for i, O in V Sum += V[i, 1] * V[i+1, 2] - V[i+1, 1] * V[i, 2] MsgBox % result := Abs(Sum += V[n, 1] * V[1, 2] - V[1, 1] * V[n, 2]) / 2
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#11l
11l
...>echo L(i) 0..10 {print("Hello World"[0..i])} > oneliner.11l && 11l oneliner.11l && oneliner.exe H He Hel Hell Hello Hello Hello W Hello Wo Hello Wor Hello Worl Hello World
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...
#J
J
HELP=: 0 :0 Commands:   DBNAME add DATA DBNAME display the latest entry DBNAME display the latest entry where CATEGORY contains WORD DBNAME display all entries DBNAME display all entries order by CATEGORY   1) The first add with new DBNAME assign category names. 2) lower case arguments verbatim. 3) UPPER CASE: substitu...
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...
#REXX
REXX
/*REXX program finds the Shortest common supersequence (SCS) of two character strings.*/ parse arg u v . /*obtain optional arguments from the CL*/ if u=='' | u=="," then u= 'abcbdab' /*Not specified? Then use the default.*/ if v=='' | v=="," then v= '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...
#Ring
Ring
  # Project : Shortest common supersequence   str1 = "a b c b d a b" str2 = "bdcaba" str3 = str2list(substr(str1, " ", nl)) for n = 1 to len(str3) for m = n to len(str2)-1 pos = find(str3, str2[m]) if pos > 0 and str2[m+1] != str3[pos+1] insert(str3, pos, str2[m+1]) ok ...
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...
#Ruby
Ruby
require 'lcs'   def scs(u, v) lcs = lcs(u, v) u, v = u.dup, v.dup scs = "" # Iterate over the characters until LCS processed until lcs.empty? if u[0]==lcs[0] and v[0]==lcs[0] # Part of the LCS, so consume from all strings scs << lcs.slice!(0) u.slice!(0) v.slice!(0) elsif u[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...
#Maxima
Maxima
timedate(0); "1900-01-01 10:00:00+10:00"
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...
#min
min
0 datetime puts!
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...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   import java.text.DateFormat   edate = Date(0) zulu = DateFormat.getDateTimeInstance() zulu.setTimeZone(TimeZone.getTimeZone('UTC')) say zulu.format(edate) return  
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...
#NewLISP
NewLISP
(date 0) ->"Thu Jan 01 01:00:00 1970"
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: * * * * * * * * * * * * * * * ...
#Elm
Elm
import String exposing (..) import Html exposing (..) import Html.Attributes as A exposing (..) import Html.Events exposing (..) import Html.App exposing (beginnerProgram) import Result exposing (..)   sierpinski : Int -> List String sierpinski n = let down n = sierpinski (n - 1) space n = repeat (2 ^ (n - 1)) ...
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:
#Tcl
Tcl
package require Tcl 8.5 package require Tk   proc mean args {expr {[::tcl::mathop::+ {*}$args] / [llength $args]}} proc sierpinski {canv coords order} { $canv create poly $coords -fill black -outline {} set queue [list [list {*}$coords $order]] while {[llength $queue]} { lassign [lindex $queue 0] x1 y1 x2 ...
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: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#Arturo
Arturo
inCarpet?: function [x,y][ X: x Y: y while [true][ if or? zero? X zero? Y -> return true if and? 1 = X % 3 1 = Y % 3 -> return false   X: X / 3 Y: Y / 3 ] ]   carpet: function [n][ loop 0..dec 3^n 'i [ loop 0..dec 3^n 'j [ ...
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 ...
#BASIC256
BASIC256
arraybase 1 dim array = {{3,4}, {5,11}, {12,8}, {9,5}, {5,6}}   print "The area of the polygon = "; Shoelace(array) end   function Shoelace(p) sum = 0 for i = 1 to p[?][] -1 sum += p[i][1] * p[i +1][2] sum -= p[i +1][1] * p[i][2] next i sum += p[i][1] * p[1][2] sum -= p[1][1] * p[i][...
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 ...
#C
C
  #include<stdlib.h> #include<stdio.h> #include<math.h>   typedef struct{ double x,y; }point;   double shoelace(char* inputFile){ int i,numPoints; double leftSum = 0,rightSum = 0;   point* pointSet; FILE* fp = fopen(inputFile,"r");   fscanf(fp,"%d",&numPoints);   pointSet = (point*)malloc((numPoints + 1)*sizeof(...
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#ACL2
ACL2
$ acl2 <<< '(cw "Hello.")'
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Ada
Ada
echo 'with Ada.text_IO; use Ada.text_IO; procedure X is begin Put("Hello!"); end X;' > x.adb; gnatmake x; ./x; rm x.adb x.ali x.o x
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Aikido
Aikido
echo 'println ("Hello")' | aikido
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...
#Java
Java
import java.io.*; import java.text.*; import java.util.*;   public class SimpleDatabase {   final static String filename = "simdb.csv";   public static void main(String[] args) { if (args.length < 1 || args.length > 3) { printUsage(); return; }   switch (args[0].t...
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...
#Sidef
Sidef
func scs(u, v) { var ls = lcs(u, v).chars var pat = Regex('(.*)'+ls.join('(.*)')+'(.*)') u.scan!(pat) v.scan!(pat) var ss = (u.shift + v.shift) ls.each { |c| ss += (c + u.shift + v.shift) } return ss }   say 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...
#Tcl
Tcl
proc scs {u v} { set lcs [lcs $u $v] set scs ""   # Iterate over the characters until LCS processed for {set ui [set vi [set li 0]]} {$li<[string length $lcs]} {} { set uc [string index $u $ui] set vc [string index $v $vi] set lc [string index $lcs $li] if {$uc eq $lc} { if {$vc eq $lc} { # P...
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...
#Nim
Nim
import times   echo "Epoch for Posix systems: ", fromUnix(0).utc echo "Epoch for Windows system: ", fromWinTime(0).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...
#Objective-C
Objective-C
#import <Foundation/Foundation.h>   int main(int argc, const char *argv[]) { @autoreleasepool {   NSDate *t = [NSDate dateWithTimeIntervalSinceReferenceDate:0]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; [dateForma...
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...
#OCaml
OCaml
open Unix   let months = [| "January"; "February"; "March"; "April"; "May"; "June"; "July"; "August"; "September"; "October"; "November"; "December" |]   let () = let t = Unix.gmtime 0.0 in Printf.printf "%s %d, %d\n" months.(t.tm_mon) t.tm_mday (1900 + t.tm_year)
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: * * * * * * * * * * * * * * * ...
#Erlang
Erlang
-module(sierpinski). -export([triangle/1]).   triangle(N) -> F = fun(X) -> io:format("~s~n",[X]) end, lists:foreach(F, triangle(N, ["*"], " ")).   triangle(0, Down, _) -> Down; triangle(N, Down, Sp) -> NewDown = [Sp++X++Sp || X<-Down]++[X++" "++X || X <- Down], triangle(N-1, NewDown, Sp++Sp).
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:
#Wren
Wren
import "graphics" for Canvas, Color import "dome" for Window   class Game { static init() { Window.title = "Sierpinski Triangle" var size = 800 Window.resize(size, size) Canvas.resize(size, size) Canvas.cls(Color.white) var level = 8 sierpinskiTriangle(level, ...
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: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#Asymptote
Asymptote
path across(path p, real node) { return point(p, node + 1/3) + point(p, node - 1/3) - point(p, node); }   path corner_subquad(path p, real node) { return point(p, node) -- point(p, node + 1/3) -- across(p, node) -- point(p, node - 1/3) -- cycle; }   path noncorner...
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 ...
#C.23
C#
using System; using System.Collections.Generic;   namespace ShoelaceFormula { using Point = Tuple<double, double>;   class Program { static double ShoelaceArea(List<Point> v) { int n = v.Count; double a = 0.0; for (int i = 0; i < n - 1; i++) { a += v[i...
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Aime
Aime
$ src/aime -c 'o_text("Hello, World!\n");'
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#ALGOL_68
ALGOL 68
$ a68g -e 'print(("Hello",new line))'
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#AppleScript
AppleScript
osascript -e 'say "Hello, World!"'
http://rosettacode.org/wiki/Show_ASCII_table
Show ASCII table
Task Show  the ASCII character set  from values   32   to   127   (decimal)   in a table format. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioin...
#11l
11l
L(i) 16 L(j) (32 + i .. 127).step(16) String k I j == 32 k = ‘Spc’ E I j == 127 k = ‘Del’ E k = Char(code' j) print(‘#3 : #<3’.format(j, k), end' ‘’) print()
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...
#Julia
Julia
Name,Birthdate,State,Relation,Email Sally Whittaker,1988-12-05,Illinois,friend,sally@mail.com Belinda Jameson,1994-02-17,California,family,beljames@example.com Jeff Bragg,2018-10-10,Texas,family,jb@texas.edu Sandy Allen,2002-03-09,Colorado,friend,sandya@mail.com Fred Kobo,1967-10-10,Colorado,friend,fkobo@example.net
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...
#Wren
Wren
var lcs // recursive lcs = Fn.new { |x, y| if (x.count == 0 || y.count == 0) return "" var x1 = x[0...-1] var y1 = y[0...-1] if (x[-1] == y[-1]) return lcs.call(x1, y1) + x[-1] var x2 = lcs.call(x, y1) var y2 = lcs.call(x1, y) return (x2.count > y2.count) ? x2 : y2 }   var scs = Fn.new { |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...
#Oforth
Oforth
import: date   0 asDateUTC println
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...
#PARI.2FGP
PARI/GP
system("date -ur 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...
#Pascal
Pascal
Program ShowEpoch;   uses SysUtils;   begin Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', Now)); Writeln(FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', 0)); end.
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: * * * * * * * * * * * * * * * ...
#Euphoria
Euphoria
procedure triangle(integer x, integer y, integer len, integer n) if n = 0 then position(y,x) puts(1,'*') else triangle (x, y+len, floor(len/2), n-1) triangle (x+len, y, floor(len/2), n-1) triangle (x+len*2, y+len, floor(len/2), n-1) end if end procedure   clear_sc...
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:
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic 'code' declarations def Order=7, Size=1<<Order; int X, Y; [SetVid($13); \set 320x200 graphics video mode for Y:= 0 to Size-1 do for X:= 0 to Size-1 do if (X&Y)=0 then Point(X, Y, 4\red\); X:= ChIn(1); \wait for keystroke SetVid(...
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:
#zkl
zkl
const Order=8, Size=(1).shiftLeft(Order); img:=PPM(300,300); foreach y,x in (Size,Size){ if(x.bitAnd(y)==0) img[x,y]=0xff0000 } img.write(File("sierpinskiTriangle.ppm","wb"));
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: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#AutoHotkey
AutoHotkey
Loop 4 MsgBox % Carpet(A_Index)   Carpet(n) { Loop % 3**n { x := A_Index-1 Loop % 3**n t .= Dot(x,A_Index-1) t .= "`n" } Return t }   Dot(x,y) { While x>0 && y>0 If (mod(x,3)=1 && mod(y,3)=1) Return " " Else x //= 3, y //= 3 Return "." }
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 ...
#C.2B.2B
C++
#include <iostream> #include <tuple> #include <vector>   using namespace std;   double shoelace(vector<pair<double, double>> points) { double leftSum = 0.0; double rightSum = 0.0;   for (int i = 0; i < points.size(); ++i) { int j = (i + 1) % points.size(); leftSum += points[i].first * points[j].second; rightS...
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#Arturo
Arturo
$ arturo -e:"print {Hello World!}"
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#AWK
AWK
$ awk 'BEGIN { print "Hello"; }'
http://rosettacode.org/wiki/Shell_one-liner
Shell one-liner
Task Show how to specify and execute a short program in the language from a command shell, where the input to the command shell is only one line in length. Avoid depending on the particular shell or operating system used as much as is reasonable; if the language has notable implementations which have different comman...
#BASIC
BASIC
echo 'print "foo"'|basic
http://rosettacode.org/wiki/Show_ASCII_table
Show ASCII table
Task Show  the ASCII character set  from values   32   to   127   (decimal)   in a table format. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting Word frequency Letter frequency Jewels and stones I before E except after C Bioin...
#6502_Assembly
6502 Assembly
========================================================================== ; task  : show ascii table ; language: 6502 Assembly ; for:  : rosettacode.org ; run  : on a Commodore 64 with command ; sys 49152 ; ; same logic of "Commodore BASIC" ; ; assembler win2c64 by Aart Bik ; http://www.aartbik.com/ ...
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...
#Kotlin
Kotlin
// version 1.2.31   import java.text.SimpleDateFormat import java.util.Date import java.io.File import java.io.IOException   val file = File("simdb.csv")   class Item( val name: String, val date: String, val category: String ) : Comparable<Item> {   override fun compareTo(other: Item) = date.compareTo(...
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...
#zkl
zkl
class Link{ var len,letter,next; fcn init(l=0,c="",lnk=Void){ len,letter,next=l,c,lnk; } } fcn scs(x,y,out){ lx,ly:=x.len(),y.len(); lnk:=(ly+1).pump(List,'wrap(_){ (lx+1).pump(List(),Link.create) });   foreach i in (ly){ lnk[i][lx]=Link(ly-i, y[i]) } foreach j in (lx){ lnk[ly][j]=Link(lx-j, x[j]) }   ...
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...
#Perl
Perl
print scalar gmtime 0, "\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...
#Phix
Phix
with javascript_semantics constant d0 = {0,1,1,0,0,0,1,1} include builtins\timedate.e ?format_timedate(d0,"YYYY-MM-DD") ?format_timedate(d0,"Dddd, Mmmm d, YYYY")
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...
#PHP
PHP
<?php echo gmdate('r', 0), "\n"; ?>
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: * * * * * * * * * * * * * * * ...
#Excel
Excel
sierpinskiTriangle =LAMBDA(c, LAMBDA(n, IF(0 = n, c, LET( prev, sierpinskiTriangle(c)(n - 1),   APPENDROWS( sierpCentered(prev) )( sierpDoubled(prev) ) ) ) ...
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: ########################### # ## ## ## ## ## ## ## ## # ########################### ### ###### ###### ### # # # ## # # ## # # # ### ###### ...
#AWK
AWK
# WSC.AWK - Waclaw Sierpinski's carpet contributed by Dan Nielsen # # syntax: GAWK -f WSC.AWK [-v o={a|A}{b|B}] [-v X=anychar] iterations # # -v o=ab default # a|A loose weave | tight weave # b|B don't show | show how the carpet is built # -v X=? Carpet is built with X's. The character assigned to X re...
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 ...
#Cowgol
Cowgol
include "cowgol.coh";   typedef Coord is uint16; # floating point types are not supported   record Point is x: Coord; y: Coord; end record;   sub shoelace(p: [Point], length: intptr): (area: Coord) is var left: Coord := 0; var right: Coord := 0;   var y0 := p.y; var x0 := p.x;   while length...
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 ...
#D
D
import std.stdio;   Point[] pnts = [{3,4}, {5,11}, {12,8}, {9,5}, {5,6}];   void main() { auto ans = shoelace(pnts); writeln(ans); }   struct Point { real x, y; }   real shoelace(Point[] pnts) { real leftSum = 0, rightSum = 0;   for (int i=0; i<pnts.length; ++i) { int j = (i+1) % pnts.length...