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/Taxicab_numbers
Taxicab numbers
A   taxicab number   (the definition that is being used here)   is a positive integer that can be expressed as the sum of two positive cubes in more than one way. The first taxicab number is   1729,   which is: 13   +   123       and also 93   +   103. Taxicab numbers are also known as:   taxi numbers   tax...
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 DIM f(1625): REM populating a cube table at the start will be faster than computing the cubes on the fly 20 FOR x=1 TO 1625 30 LET f(x)=x*x*x: REM x*x*x rather than x^3 as the ZX Spectrum's exponentiation function is legendarily slow 40 NEXT x 50 LET c=0 60 FOR x=1 TO 4294967295: REM the highest number the ZX Spectr...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Go
Go
package main   import ( "fmt" "os" "strconv" )   func main() { if len(os.Args) != 2 { fmt.Println("Usage: k <Kelvin>") return } k, err := strconv.ParseFloat(os.Args[1], 64) if err != nil { fmt.Println(err) return } if k < 0 { fmt.Println("Kelvi...
http://rosettacode.org/wiki/Ternary_logic
Ternary logic
This page uses content from Wikipedia. The original article was at Ternary logic. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) In logic, a three-valued logic (also trivalent, ternary, or trinary...
#Yabasic
Yabasic
  tFalse = 0 tDontKnow = 1 tTrue = 2   sub not3(b) return 2-b end sub   sub and3(a,b) return min(a,b) end sub   sub or3(a,b) return max(a,b) end sub   sub eq3(a,b) if a = tDontKnow or b = tDontKnow then return tDontKnow elsif a = b then return tTrue else return tFalse end if end ...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Scala
Scala
val gifts = Array( "A partridge in a pear tree.", "Two turtle doves and", "Three French hens,", "Four calling birds,", "Five gold rings,", "Six geese a-laying,", "Seven swans a-swimming,", "Eight maids a-milking,", "Nine ladies dancing,", "Ten lords a-leaping,", "Eleven piper...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Scheme
Scheme
; Racket has this built in, but it's not standard (define (take lst n) (if (or (null? lst) (<= n 0)) '() (cons (car lst) (take (cdr lst) (- n 1)))))   (let ((days '("first" "second" "third" "fourth" "fifth" "sixth" "seventh" "eighth" "ninth" "tenth" "eleventh" "twelfth"))   (gifts '("A p...
http://rosettacode.org/wiki/Synchronous_concurrency
Synchronous concurrency
The goal of this task is to create two concurrent activities ("Threads" or "Tasks", not processes.) that share data synchronously. Your language may provide syntax or libraries to perform concurrency. Different languages provide different implementations of concurrency, often with different names. Some languages use th...
#UnixPipes
UnixPipes
rm -f node ; mkfifo node cat file | tee >(wc -l > node ) | cat - node
http://rosettacode.org/wiki/Synchronous_concurrency
Synchronous concurrency
The goal of this task is to create two concurrent activities ("Threads" or "Tasks", not processes.) that share data synchronously. Your language may provide syntax or libraries to perform concurrency. Different languages provide different implementations of concurrency, often with different names. Some languages use th...
#Visual_Basic_.NET
Visual Basic .NET
Imports System.Threading   Module Module1   Sub Main() Dim t1 As New Thread(AddressOf Reader) Dim t2 As New Thread(AddressOf Writer) t1.Start() t2.Start() t1.Join() t2.Join() End Sub   Sub Reader() For Each line In IO.File.ReadAllLines("input.txt") m_...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Excel
Excel
=NOW()
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#F.23
F#
printfn "%s" (System.DateTime.Now.ToString("u"))
http://rosettacode.org/wiki/Summarize_and_say_sequence
Summarize and say sequence
There are several ways to generate a self-referential sequence. One very common one (the Look-and-say sequence) is to start with a positive integer, then generate the next term by concatenating enumerated groups of adjacent alike digits: 0, 10, 1110, 3110, 132110, 1113122110, 311311222110 ... The terms generat...
#JavaScript
JavaScript
  function selfReferential(n) { n = n.toString(); let res = [n]; const makeNext = (n) => { let matchs = { '9':0,'8':0,'7':0,'6':0,'5':0,'4':0,'3':0,'2':0,'1':0,'0':0}, res = []; for(let index=0;index<n.length;index++) matchs[n[index].toString()]++; for(let ind...
http://rosettacode.org/wiki/Sutherland-Hodgman_polygon_clipping
Sutherland-Hodgman polygon clipping
The   Sutherland-Hodgman clipping algorithm   finds the polygon that is the intersection between an arbitrary polygon (the “subject polygon”) and a convex polygon (the “clip polygon”). It is used in computer graphics (especially 2D graphics) to reduce the complexity of a scene being displayed by eliminating parts of a...
#TypeScript
TypeScript
interface XYCoords { x : number; y : number; }   const inside = ( cp1 : XYCoords, cp2 : XYCoords, p : XYCoords) : boolean => { return (cp2.x-cp1.x)*(p.y-cp1.y) > (cp2.y-cp1.y)*(p.x-cp1.x); };   const intersection = ( cp1 : XYCoords ,cp2 : XYCoords ,s : XYCoords, e : XYCoords ) : XYCoords => { const dc ...
http://rosettacode.org/wiki/Sutherland-Hodgman_polygon_clipping
Sutherland-Hodgman polygon clipping
The   Sutherland-Hodgman clipping algorithm   finds the polygon that is the intersection between an arbitrary polygon (the “subject polygon”) and a convex polygon (the “clip polygon”). It is used in computer graphics (especially 2D graphics) to reduce the complexity of a scene being displayed by eliminating parts of a...
#Sidef
Sidef
class Point(x, y) { method to_s { "(#{'%.2f' % x}, #{'%.2f' % y})" } }   func sutherland_hodgman(subjectPolygon, clipPolygon) { var inside = { |cp1, cp2, p| ((cp2.x-cp1.x)*(p.y-cp1.y)) > ((cp2.y-cp1.y)*(p.x-cp1.x)) }   var intersection = { |cp1, cp2, s, e| var (dcx, dcy) = (cp1.x-cp2.x, cp...
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#Java
Java
import java.util.Arrays; import java.util.HashSet; import java.util.Set;   public class SymmetricDifference { public static void main(String[] args) { Set<String> setA = new HashSet<String>(Arrays.asList("John", "Serena", "Bob", "Mary", "Serena")); Set<String> setB = new HashSet<String>(Arrays.asLis...
http://rosettacode.org/wiki/Take_notes_on_the_command_line
Take notes on the command line
Take notes on the command line is part of Short Circuit's Console Program Basics selection. Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then al...
#Scala
Scala
import java.io.{ FileNotFoundException, FileOutputStream, PrintStream } import java.time.LocalDateTime   object TakeNotes extends App { val notesFileName = "notes.txt" if (args.length > 0) { val ps = new PrintStream(new FileOutputStream(notesFileName, true)) ps.println(LocalDateTime.now() + args.mkString("\...
http://rosettacode.org/wiki/Take_notes_on_the_command_line
Take notes on the command line
Take notes on the command line is part of Short Circuit's Console Program Basics selection. Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then al...
#Scheme
Scheme
#lang racket (require racket/date) (define *notes* "NOTES.TXT")   (let ([a (vector->list (current-command-line-arguments))]) (cond [(empty? a) (with-handlers ([exn:fail? void]) (call-with-input-file *notes* (lambda (fi) (copy-port fi (current-output-port))))) ] [else ...
http://rosettacode.org/wiki/Superellipse
Superellipse
A superellipse is a geometric figure defined as the set of all points (x, y) with | x a | n + | y b | n = 1 , {\displaystyle \left|{\frac {x}{a}}\right|^{n}\!+\left|{\frac {y}{b}}\right|^{n}\!=1,} where n, a, and b are positive numbers. Task Draw a superellipse with n = 2.5, and a...
#zkl
zkl
fcn superEllipse(plot,n,color=0xff0000){ // we'll assume width <= height a,p:=(plot.w/2).toFloat(), 1.0/n; // just calculate upper right quadrant foreach x in ([0.0 .. a]){ y:=(a.pow(n) - x.pow(n)).pow(p); // a==b>0 --> y=(a^n - x^n)^(1/n) //println( (x/a).abs().pow(n) + (y/b).abs().pow(n) ); // s...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Groovy
Groovy
  class Convert{ static void main(String[] args){ def c=21.0; println("K "+c) println("C "+k_to_c(c)); println("F "+k_to_f(k_to_c(c))); println("R "+k_to_r(c)); } static def k_to_c(def k=21.0){return k-273.15;} static def k_to_f(def k=21.0){return ((k*9)/5)+32;} static def k_to_r(def k=21.0){return k*1.8;} }  
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Seed7
Seed7
$ include "seed7_05.s7i";   const proc: main is func local const array string: gifts is [] ( "A partridge in a pear tree.", "Two turtle doves and", "Three french hens", "Four calling birds", "Five golden rings", "Six geese a-laying", "Seven swans a-swimming", "Eight maids a-milking...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Self
Self
(| parent* = traits oddball.   gifts = ( 'And a partridge in a pear tree' & 'Two turtle doves' & 'Three french hens' & 'Four calling birds' & 'FIVE GO-OLD RINGS' & 'Six geese a-laying' & 'Seven swans a-swimming' & 'Eight maids a-milking' & 'Nine ladies dancing' & 'Ten lords a-leaping' & ...
http://rosettacode.org/wiki/Synchronous_concurrency
Synchronous concurrency
The goal of this task is to create two concurrent activities ("Threads" or "Tasks", not processes.) that share data synchronously. Your language may provide syntax or libraries to perform concurrency. Different languages provide different implementations of concurrency, often with different names. Some languages use th...
#Wren
Wren
import "io" for File   var EOT = "\x04"   var readLines = Fiber.new { |fileName| var file = File.open(fileName) var offset = 0 var line = "" while (true) { var b = file.readBytes(1, offset) offset = offset + 1 if (b == "\n") { Fiber.yield(line) line = "" /...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Factor
Factor
USE: calendar   now .
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Falcon
Falcon
  /* Added by Aykayayciti Earl Lamont Montgomery April 10th, 2018 */   > CurrentTime().toString()  
http://rosettacode.org/wiki/Summarize_and_say_sequence
Summarize and say sequence
There are several ways to generate a self-referential sequence. One very common one (the Look-and-say sequence) is to start with a positive integer, then generate the next term by concatenating enumerated groups of adjacent alike digits: 0, 10, 1110, 3110, 132110, 1113122110, 311311222110 ... The terms generat...
#jq
jq
# Given any array, produce an array of [item, count] pairs for each run. def runs: reduce .[] as $item ( []; if . == [] then [ [ $item, 1] ] else .[length-1] as $last | if $last[0] == $item then (.[0:length-1] + [ [$item, $last[1] + 1] ] ) else . + [[$item, 1]...
http://rosettacode.org/wiki/Sutherland-Hodgman_polygon_clipping
Sutherland-Hodgman polygon clipping
The   Sutherland-Hodgman clipping algorithm   finds the polygon that is the intersection between an arbitrary polygon (the “subject polygon”) and a convex polygon (the “clip polygon”). It is used in computer graphics (especially 2D graphics) to reduce the complexity of a scene being displayed by eliminating parts of a...
#Swift
Swift
struct Point { var x: Double var y: Double }   struct Polygon { var points: [Point]   init(points: [Point]) { self.points = points }   init(points: [(Double, Double)]) { self.init(points: points.map({ Point(x: $0.0, y: $0.1) })) } }   func isInside(_ p1: Point, _ p2: Point, _ p3: Point) -> Bool { ...
http://rosettacode.org/wiki/Sutherland-Hodgman_polygon_clipping
Sutherland-Hodgman polygon clipping
The   Sutherland-Hodgman clipping algorithm   finds the polygon that is the intersection between an arbitrary polygon (the “subject polygon”) and a convex polygon (the “clip polygon”). It is used in computer graphics (especially 2D graphics) to reduce the complexity of a scene being displayed by eliminating parts of a...
#Tcl
Tcl
# Find intersection of an arbitrary polygon with a convex one. package require Tcl 8.6   # Does the path (x0,y0)->(x1,y1)->(x2,y2) turn clockwise # or counterclockwise? proc cw {x0 y0 x1 y1 x2 y2} { set dx1 [expr {$x1 - $x0}]; set dy1 [expr {$y1 - $y0}] set dx2 [expr {$x2 - $x0}]; set dy2 [expr {$y2 - $y0}] ...
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#JavaScript
JavaScript
// in A but not in B function relative_complement(A, B) { return A.filter(function(elem) {return B.indexOf(elem) == -1}); }   // in A or in B but not in both function symmetric_difference(A,B) { return relative_complement(A,B).concat(relative_complement(B,A)); }   var a = ["John", "Serena", "Bob", "Mary", "Sere...
http://rosettacode.org/wiki/Take_notes_on_the_command_line
Take notes on the command line
Take notes on the command line is part of Short Circuit's Console Program Basics selection. Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then al...
#Seed7
Seed7
$ include "seed7_05.s7i"; $ include "getf.s7i"; $ include "time.s7i";   const string: noteFileName is "NOTES.TXT";   const proc: main is func local var file: note is STD_NULL; begin if length(argv(PROGRAM)) = 0 then # write NOTES.TXT write(getf(noteFileName)); else # Write date & time ...
http://rosettacode.org/wiki/Take_notes_on_the_command_line
Take notes on the command line
Take notes on the command line is part of Short Circuit's Console Program Basics selection. Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then al...
#Sidef
Sidef
var file = %f'notes.txt'   if (ARGV.len > 0) { var fh = file.open_a fh.say(Time.local.ctime + "\n\t" + ARGV.join(" ")) fh.close } else { var fh = file.open_r fh && fh.each { .say } }
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Haskell
Haskell
import System.Exit (die) import Control.Monad (mapM_)   main = do putStrLn "Please enter temperature in kelvin: " input <- getLine let kelvin = read input if kelvin < 0.0 then die "Temp cannot be negative" else mapM_ putStrLn $ convert kelvin   convert :: Double -> [String] convert n = zipWith (++) ...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#SenseTalk
SenseTalk
put [ "partridge in a pear tree.", "turtle doves and", "french hens", "calling birds", "golden rings", "geese a-laying", "swans a-swimming", "maids a-milking", "ladies dancing", "lords a-leaping", "pipers piping", "drummers drumming" ] into gifts   repeat with each item d1 of 1 .. 12 put "On the" && ordina...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Sidef
Sidef
var days = <first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth>;   var gifts = <<'EOT'.lines; And a partridge in a pear tree. Two turtle doves, Three french hens, Four calling birds, Five golden rings, Six geese a-laying, Seven swans a-swimming, Eight maids a-milking, Ni...
http://rosettacode.org/wiki/Synchronous_concurrency
Synchronous concurrency
The goal of this task is to create two concurrent activities ("Threads" or "Tasks", not processes.) that share data synchronously. Your language may provide syntax or libraries to perform concurrency. Different languages provide different implementations of concurrency, often with different names. Some languages use th...
#zkl
zkl
fcn reader(fileName,out){ n:=0; foreach line in (File(fileName)) { out.write(line); n+=1; } out.close(); // signal done Atomic.waitFor(out.Property("isOpen")); // wait for other thread to reopen Pipe out.write(n); } fcn writer(in){ Utils.zipWith(fcn(n,line){ "%3d: %s".fmt(n,line).print() },[1..],in); ...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Fantom
Fantom
fansh> DateTime.nowTicks 351823905158000000 fansh> DateTime.now 2011-02-24T00:51:47.066Z London fansh> DateTime.now.toJava 1298508885979
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Forth
Forth
[UNDEFINED] MS@ [IF] \ Win32Forth (rolls over daily) [DEFINED] ?MS [IF] ( -- ms )  : ms@ ?MS ; \ iForth [ELSE] [DEFINED] cputime [IF] ( -- Dusec )  : ms@ cputime d+ 1000 um/mod nip ; \ gforth: Anton Ertl [ELSE] [DEFINED] t...
http://rosettacode.org/wiki/Summarize_and_say_sequence
Summarize and say sequence
There are several ways to generate a self-referential sequence. One very common one (the Look-and-say sequence) is to start with a positive integer, then generate the next term by concatenating enumerated groups of adjacent alike digits: 0, 10, 1110, 3110, 132110, 1113122110, 311311222110 ... The terms generat...
#Julia
Julia
const seen = Dict{Vector{Char}, Vector{Char}}()   function findnextterm(prevterm) counts = Dict{Char, Int}() reversed = Vector{Char}() for c in prevterm if !haskey(counts, c) counts[c] = 0 end counts[c] += 1 end for c in sort(collect(keys(counts))) if coun...
http://rosettacode.org/wiki/Sutherland-Hodgman_polygon_clipping
Sutherland-Hodgman polygon clipping
The   Sutherland-Hodgman clipping algorithm   finds the polygon that is the intersection between an arbitrary polygon (the “subject polygon”) and a convex polygon (the “clip polygon”). It is used in computer graphics (especially 2D graphics) to reduce the complexity of a scene being displayed by eliminating parts of a...
#Wren
Wren
import "graphics" for Canvas, Color import "dome" for Window import "./polygon" for Polygon   class SutherlandHodgman { construct new(width, height, subject, clipper) { Window.title = "Sutherland-Hodgman" Window.resize(width, height) Canvas.resize(width, height) _subject = subject ...
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#jq
jq
# The following implementation of intersection (but not symmetric_difference) assumes that the # elements of a (and of b) are unique and do not include null: def intersection(a; b): reduce ((a + b) | sort)[] as $i ([null, []]; if .[0] == $i then [null, .[1] + [$i]] else [$i, .[1]] end) | .[1] ;   def symmetric...
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#Julia
Julia
A = ["John", "Bob", "Mary", "Serena"] B = ["Jim", "Mary", "John", "Bob"] @show A B symdiff(A, B)
http://rosettacode.org/wiki/Take_notes_on_the_command_line
Take notes on the command line
Take notes on the command line is part of Short Circuit's Console Program Basics selection. Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then al...
#SNOBOL4
SNOBOL4
#! /usr/local/bin/snobol4 -b a = 2 ;* skip '-b' parameter notefile = "notes.txt" while args = args host(2,a = a + 1) " " :s(while) ident(args) :f(append) noparms input(.notes,io_findunit(),,notefile) :s(display)f(end) display output = notes :s(display) endfile(notes) :(end) append output(.notes,io_findun...
http://rosettacode.org/wiki/Take_notes_on_the_command_line
Take notes on the command line
Take notes on the command line is part of Short Circuit's Console Program Basics selection. Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then al...
#Swift
Swift
import Foundation   let args = Process.arguments let manager = NSFileManager() let currentPath = manager.currentDirectoryPath var err:NSError?   // Create file if it doesn't exist if !manager.fileExistsAtPath(currentPath + "/notes.txt") { println("notes.txt doesn't exist") manager.createFileAtPath(currentPath +...
http://rosettacode.org/wiki/Take_notes_on_the_command_line
Take notes on the command line
Take notes on the command line is part of Short Circuit's Console Program Basics selection. Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then al...
#Tcl
Tcl
# Make it easier to change the name of the notes file set notefile notes.txt   if {$argc} { # Write a message to the file set msg [clock format [clock seconds]]\n\t[join $argv " "] set f [open $notefile a] puts $f $msg close $f } else { # Print the contents of the file catch { set f [open $...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Icon_and_Unicon
Icon and Unicon
procedure main(A) k := A[1] | 21.00 write("K ",k) write("C ",k-273.15) write("R ",r := k*(9.0/5.0)) write("F ",r - 459.67) end
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Simula
Simula
Begin Text Array days(1:12), gifts(1:12); Integer day, gift;   days(1)  :- "first"; days(2)  :- "second"; days(3)  :- "third"; days(4)  :- "fourth"; days(5)  :- "fifth"; days(6)  :- "sixth"; days(7)  :- "seventh"; days(8)  :- "eighth"; days(9)  :- "ninth"; days(10) :- "tenth"; days(11) :- "ele...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Smalltalk
Smalltalk
Object subclass: TwelveDays [ Ordinals := #('first' 'second' 'third' 'fourth' 'fifth' 'sixth' 'seventh' 'eighth' 'ninth' 'tenth' 'eleventh' 'twelfth').   Gifts := #( 'A partridge in a pear tree.' 'Two turtle doves and' 'Three French hens,' 'Four calling birds,' ...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Fortran
Fortran
integer :: start, stop, rate real :: result   ! optional 1st integer argument (COUNT) is current raw system clock counter value (not UNIX epoch millis!!) ! optional 2nd integer argument (COUNT_RATE) is clock cycles per second ! optional 3rd integer argument (COUNT_MAX) is maximum clock counter value call system_clock( ...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   Print Date + " " + Time '' returns system date/time in format : mm-dd-yyyy hh:mm:ss Sleep
http://rosettacode.org/wiki/Summarize_and_say_sequence
Summarize and say sequence
There are several ways to generate a self-referential sequence. One very common one (the Look-and-say sequence) is to start with a positive integer, then generate the next term by concatenating enumerated groups of adjacent alike digits: 0, 10, 1110, 3110, 132110, 1113122110, 311311222110 ... The terms generat...
#Kotlin
Kotlin
// version 1.1.2   const val LIMIT = 1_000_000   val sb = StringBuilder()   fun selfRefSeq(s: String): String { sb.setLength(0) // faster than using a local StringBuilder object for (d in '9' downTo '0') { if (d !in s) continue val count = s.count { it == d } sb.append("$count$d")...
http://rosettacode.org/wiki/Sutherland-Hodgman_polygon_clipping
Sutherland-Hodgman polygon clipping
The   Sutherland-Hodgman clipping algorithm   finds the polygon that is the intersection between an arbitrary polygon (the “subject polygon”) and a convex polygon (the “clip polygon”). It is used in computer graphics (especially 2D graphics) to reduce the complexity of a scene being displayed by eliminating parts of a...
#Yabasic
Yabasic
  open window 400, 400 backcolor 0,0,0 clear window   DPOL = 8 DREC = 3 CX = 1 : CY = 2   dim poligono(DPOL, 2) dim rectang(DREC, 2) dim clipped(DPOL + DREC, 2)   for n = 0 to DPOL : read poligono(n, CX), poligono(n, CY) : next n DATA 50,150, 200,50, 350,150, 350,300, 250,300, 200,250, 150,350, 100,250, 100,200 for n =...
http://rosettacode.org/wiki/Sutherland-Hodgman_polygon_clipping
Sutherland-Hodgman polygon clipping
The   Sutherland-Hodgman clipping algorithm   finds the polygon that is the intersection between an arbitrary polygon (the “subject polygon”) and a convex polygon (the “clip polygon”). It is used in computer graphics (especially 2D graphics) to reduce the complexity of a scene being displayed by eliminating parts of a...
#zkl
zkl
class P{ // point fcn init(_x,_y){ var [const] x=_x.toFloat(), y=_y.toFloat() } fcn __opSub(p) { self(x - p.x, y - p.y) } fcn cross(p) { x*p.y - y*p.x } fcn toString { "(%7.2f,%7.2f)".fmt(x,y) } var [const,proxy] ps=fcn{ T(x.toInt(),y.toInt()) }; // property } fcn shClipping(clip,polygon)...
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#K
K
A: ?("John";"Bob";"Mary";"Serena") B: ?("Jim";"Mary";"John";"Bob")   A _dvl B / in A but not in B "Serena" B _dvl A / in B but not in A "Jim" (A _dvl B;B _dvl A) / Symmetric difference ("Serena" "Jim")
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#Kotlin
Kotlin
// version 1.1.2   fun main(args: Array<String>) { val a = setOf("John", "Bob", "Mary", "Serena") val b = setOf("Jim", "Mary", "John", "Bob") println("A = $a") println("B = $b") val c = a - b println("A \\ B = $c") val d = b - a println("B \\ A = $d") val e = c.union(d) ...
http://rosettacode.org/wiki/Take_notes_on_the_command_line
Take notes on the command line
Take notes on the command line is part of Short Circuit's Console Program Basics selection. Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then al...
#uBasic.2F4tH
uBasic/4tH
If Cmd (0) > 1 Then ' if there are commandline arguments If Set (a, Open ("notes.txt", "a")) < 0 Then Print "Cannot write \qnotes.txt\q" ' open the file in "append" mode End ' on error, issue message and exit EndIf ' wr...
http://rosettacode.org/wiki/Take_notes_on_the_command_line
Take notes on the command line
Take notes on the command line is part of Short Circuit's Console Program Basics selection. Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then al...
#UNIX_Shell
UNIX Shell
# NOTES=$HOME/notes.txt if [[ $# -eq 0 ]] ; then [[ -r $NOTES ]] && more $NOTES else date >> $NOTES echo " $*" >> $NOTES fi
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#J
J
NB. Temp conversions are all linear polynomials K2K =: 0 1 NB. K = (1 *k) + 0 K2C =: _273 1 NB. C = (1 *k) - 273 K2F =: _459.67 1.8 NB. F = (1.8*k) - 459.67 K2R =: 0 1.8 NB. R = (1.8*k) + 0   NB. Do all conversions at once (eval NB. polynomials in pa...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Smart_BASIC
Smart BASIC
' by rbytes dim d$(12),x$(15)!s=15 for t=0 to 11!read d$(t)!next t for t=0 to 14!read x$(t)!next t for u=0 to 11!s-=1 print x$(0)&d$(u)&x$(1)&chr$(10)&x$(2) for t=s to 14!print x$(t)!next t print!next u!data "first","second","third","fourth","fifth","sixth","seventh","eight","ninth","tenth","eleventh","Twelfth","On the...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Snobol
Snobol
DAYS = ARRAY('12') DAYS<1> = 'first' DAYS<2> = 'second' DAYS<3> = 'third' DAYS<4> = 'fourth' DAYS<5> = 'fifth' DAYS<6> = 'sixth' DAYS<7> = 'seventh' DAYS<8> = 'eighth' DAYS<9> = 'ninth' DAYS<10> = 'tenth' DAYS<11> = 'eleventh' DAYS<12> = 'twelfth'   GIFTS = ARRAY('12') GIFTS<1> = 'A partridge in a pear t...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Frink
Frink
println[now[]]
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#FutureBasic
FutureBasic
window 1 print time print time(@"hh:mm:ss" ) print time(@"h:mm a" ) print time(@"h:mm a zzz") HandleEvents
http://rosettacode.org/wiki/Summarize_and_say_sequence
Summarize and say sequence
There are several ways to generate a self-referential sequence. One very common one (the Look-and-say sequence) is to start with a positive integer, then generate the next term by concatenating enumerated groups of adjacent alike digits: 0, 10, 1110, 3110, 132110, 1113122110, 311311222110 ... The terms generat...
#Lua
Lua
-- Return the next term in the self-referential sequence function findNext (nStr) local nTab, outStr, pos, count = {}, "", 1, 1 for i = 1, #nStr do nTab[i] = nStr:sub(i, i) end table.sort(nTab, function (a, b) return a > b end) while pos <= #nTab do if nTab[pos] == nTab[pos + 1] then ...
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#Ksh
Ksh
  #!/bin/ksh   # Symmetric difference - enumerate the items that are in A or B but not both.   # # Variables: # typeset -a A=( John Bob Mary Serena ) typeset -a B=( Jim Mary John Bob )   # # Functions: # # # Function _flattenarr(arr, sep) - flatten arr into string by separator sep # function _flattenarr { typeset _arr...
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#Lasso
Lasso
  [ var( 'a' = array( 'John' ,'Bob' ,'Mary' ,'Serena' )   ,'b' = array   );   $b->insert( 'Jim' ); // Alternate method of populating array $b->insert( 'Mary' ); $b->insert( 'John' ); $b->insert( 'Bob' );   $a->sort( true ); // arrays must be sorted (true = ascending) for difference...
http://rosettacode.org/wiki/Take_notes_on_the_command_line
Take notes on the command line
Take notes on the command line is part of Short Circuit's Console Program Basics selection. Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then al...
#Visual_Basic_.NET
Visual Basic .NET
Imports System.IO   Module Notes Function Main(ByVal cmdArgs() As String) As Integer Try If cmdArgs.Length = 0 Then Using sr As New StreamReader("NOTES.TXT") Console.WriteLine(sr.ReadToEnd) End Using Else Using sw As...
http://rosettacode.org/wiki/Take_notes_on_the_command_line
Take notes on the command line
Take notes on the command line is part of Short Circuit's Console Program Basics selection. Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then al...
#Wren
Wren
import "os" for Process import "/ioutil" for File, FileUtil import "/date" for Date   var dateFormatIn = "yyyy|-|mm|-|dd|+|hh|:|MM" var dateFormatOut = "yyyy|-|mm|-|dd| |hh|:|MM" var args = Process.arguments if (args.count == 0) { if (File.exists("NOTES.TXT")) System.print(File.read("NOTES.TXT")) } else if (args.c...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Java
Java
public class TemperatureConversion { public static void main(String args[]) { if (args.length == 1) { try { double kelvin = Double.parseDouble(args[0]); if (kelvin >= 0) { System.out.printf("K  %2.2f\n", kelvin); System.out....
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#SQL
SQL
  WITH FUNCTION nl ( s IN varchar2 ) RETURN varchar2 IS BEGIN RETURN chr(10) || s; END nl; FUNCTION v ( d NUMBER, x NUMBER, g IN varchar2 ) RETURN varchar2 IS BEGIN RETURN CASE WHEN d >= x THEN nl (g) END; END v; SELECT 'On the ' || to_char(to_date(level,'j'),'jspth' ) || ' day o...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Gambas
Gambas
Public Sub Main()   Print Format(Now, "dddd dd mmmm yyyy hh:nn:ss")   End
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Genie
Genie
[indent=4]   init var now = new DateTime.now_local() print now.to_string()
http://rosettacode.org/wiki/Summarize_and_say_sequence
Summarize and say sequence
There are several ways to generate a self-referential sequence. One very common one (the Look-and-say sequence) is to start with a positive integer, then generate the next term by concatenating enumerated groups of adjacent alike digits: 0, 10, 1110, 3110, 132110, 1113122110, 311311222110 ... The terms generat...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
selfRefSequence[ x_ ] := FromDigits@Flatten@Reverse@Cases[Transpose@{RotateRight[DigitCount@x,1], Range[0,9]},Except[{0,_}]] DisplaySequence[ x_ ] := NestWhileList[selfRefSequence,x,UnsameQ[##]&,4] data= {#, Length@DisplaySequence[#]}&/@Range[1000000]; Print["Values: ", Select[data ,#[[2]] == Max@data[[;;,2]]&][[1,;;...
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#Logo
Logo
to diff :a :b [:acc []] if empty? :a [output sentence :acc :b] ifelse member? first :a :b ~ [output (diff butfirst :a remove first :a :b  :acc)] ~ [output (diff butfirst :a  :b lput first :a :acc)] end   make "a [John Bob Mary Serena] make "b [Jim Mary John Bob]   show diff :a :b  ; [Serena Jim]
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#Lua
Lua
A = { ["John"] = true, ["Bob"] = true, ["Mary"] = true, ["Serena"] = true } B = { ["Jim"] = true, ["Mary"] = true, ["John"] = true, ["Bob"] = true }   A_B = {} for a in pairs(A) do if not B[a] then A_B[a] = true end end   B_A = {} for b in pairs(B) do if not A[b] then B_A[b] = true end end   for a_b in pairs(A_...
http://rosettacode.org/wiki/Take_notes_on_the_command_line
Take notes on the command line
Take notes on the command line is part of Short Circuit's Console Program Basics selection. Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then al...
#XPL0
XPL0
include xpllib; \Date and Time routines int I, NotesSize, Ch, CmdArgSize; char Notes(1_000_000), CmdArg(1000); [\Read in notes.txt, if it exists Trap(false); \disable abort on errors FSet(FOpen("notes.txt", 0), ^i); OpenI(3); if GetErr = 0 then \file exists [I:= 0;...
http://rosettacode.org/wiki/Take_notes_on_the_command_line
Take notes on the command line
Take notes on the command line is part of Short Circuit's Console Program Basics selection. Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then al...
#zkl
zkl
const notesName="NOTES.TXT"; args:=vm.arglist; if (not args) { try{ File(notesName).read(*).text.print(); } catch{println("no file")} } else{ f:=File(notesName,"a+"); f.writeln(Time.Date.ctime(),"\n\t",args.concat(" ")); f.close(); }
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#JavaScript
JavaScript
var k2c = k => k - 273.15 var k2r = k => k * 1.8 var k2f = k => k2r(k) - 459.67   Number.prototype.toMaxDecimal = function (d) { return +this.toFixed(d) + '' }   function kCnv(k) { document.write( k,'K° = ', k2c(k).toMaxDecimal(2),'C° = ', k2r(k).toMaxDecimal(2),'R° = ', k2f(k).toMaxDecimal(2),'F°<br>' ) }   k...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Swift
Swift
let gifts = [ "partridge in a pear tree", "Two turtle doves", "Three French hens", "Four calling birds", "Five gold rings", "Six geese a-laying", "Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing", "Ten lords a...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Tailspin
Tailspin
  def ordinal: ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth']; def gift: [ 'a partridge in a pear tree', 'two turtle-doves', 'three French hens', 'four calling birds', 'five golden rings', 'six geese a-laying', 'seven swans a-swimming...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Go
Go
package main   import "time" import "fmt"   func main() { t := time.Now() fmt.Println(t) // default format fmt.Println(t.Format("Mon Jan 2 15:04:05 2006")) // some custom format }
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Groovy
Groovy
def nowMillis = new Date().time println 'Milliseconds since the start of the UNIX Epoch (Jan 1, 1970) == ' + nowMillis
http://rosettacode.org/wiki/Summarize_and_say_sequence
Summarize and say sequence
There are several ways to generate a self-referential sequence. One very common one (the Look-and-say sequence) is to start with a positive integer, then generate the next term by concatenating enumerated groups of adjacent alike digits: 0, 10, 1110, 3110, 132110, 1113122110, 311311222110 ... The terms generat...
#Nim
Nim
import algorithm, sequtils, sets, strutils, tables   var cache: Table[seq[char], int] # Maps key -> number of iterations.     iterator sequence(seed: string): string = ## Yield the successive strings of a sequence.   var history: HashSet[string] history.incl seed var current = seed yield current   while t...
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#Maple
Maple
A := {John, Bob, Mary, Serena}; B := {Jim, Mary, John, Bob};
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
SymmetricDifference[x_List,y_List] := Join[Complement[x,Intersection[x,y]],Complement[y,Intersection[x,y]]]
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#jq
jq
  # round(keep) takes as input any jq (i.e. JSON) number and emits a string. # "keep" is the desired maximum number of numerals after the decimal point, # e.g. 9.999|round(2) => 10.00 def round(keep): tostring | (index("e") | if . then . else index("E") end) as $e | if $e then (.[0:$e] | round(keep)) + .[$e+1:] ...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Terraform
Terraform
locals { days = [ "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth" ] gifts = [ "A partridge in a pear tree.", "Two turtle doves, and", "Three French hens,", "Four calling birds,", "Five gold rings,", "Six ge...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#Tcl
Tcl
set days { first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth } set gifts [lreverse { "A partridge in a pear tree." "Two turtle doves, and" "Three french hens," "Four calling birds," "Five golden rings," "Six geese a-laying," "Seven swans a-swimming," ...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#GUISS
GUISS
Taskbar
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Haskell
Haskell
import System.Time (getClockTime, toCalendarTime, formatCalendarTime)   import System.Locale (defaultTimeLocale)   main :: IO () main = do ct <- getClockTime print ct -- print default format, or cal <- toCalendarTime ct putStrLn $ formatCalendarTime defaultTimeLocale "%a %b %e %H:%M:%S %Y" cal
http://rosettacode.org/wiki/Summarize_and_say_sequence
Summarize and say sequence
There are several ways to generate a self-referential sequence. One very common one (the Look-and-say sequence) is to start with a positive integer, then generate the next term by concatenating enumerated groups of adjacent alike digits: 0, 10, 1110, 3110, 132110, 1113122110, 311311222110 ... The terms generat...
#Perl
Perl
sub next_num { my @a; $a[$_]++ for split '', shift; join('', map(exists $a[$_] ? $a[$_].$_ : "", reverse 0 .. 9)); }   my %cache; sub seq { my $a = shift; my (%seen, @s); until ($seen{$a}) { $seen{$a} = 1; push(@s, $a); last if !wantarray && $cache{$a}; $a = next_num($a); } return (@s) if wantarray;   ...
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#MATLAB
MATLAB
>> [setdiff([1 2 3],[2 3 4]) setdiff([2 3 4],[1 2 3])]   ans =   1 4
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Julia
Julia
cfr(k) = print("Kelvin: $k, ", "Celsius: $(round(k-273.15,2)), ", "Fahrenheit: $(round(k*1.8-459.67,2)), ", "Rankine: $(round(k*1.8,2))")
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Kotlin
Kotlin
// version 1.1.2   class Kelvin(val degrees: Double) { fun toCelsius() = degrees - 273.15   fun toFahreneit() = (degrees - 273.15) * 1.8 + 32.0   fun toRankine() = (degrees - 273.15) * 1.8 + 32.0 + 459.67 }   fun main(args: Array<String>) { print("Enter the temperature in degrees Kelvin : ") val deg...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#True_BASIC
True BASIC
DATA "first","second","third","fourth","fifth","sixth" DATA "seventh","eighth","ninth","tenth","eleventh","twelfth" DATA "A partridge in a pear tree." DATA "Two turtle doves and" DATA "Three french hens" DATA "Four calling birds" DATA "Five golden rings" DATA "Six geese a-laying" DATA "Seven swans a-swimming" DATA "Eig...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#HicEst
HicEst
seconds_since_midnight = TIME() ! msec as fraction   seconds_since_midnight = TIME(Year=yr, Day=day, WeekDay=wday, Gregorian=gday) ! other options e.g. Excel, YYYYMMDD (num or text)
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#HolyC
HolyC
CDateStruct ds; Date2Struct(&ds, Now + local_time_offset);   Print("%04d-%02d-%02d %02d:%02d:%02d\n", ds.year, ds.mon, ds.day_of_mon, ds.hour, ds.min, ds.sec);  
http://rosettacode.org/wiki/Summarize_and_say_sequence
Summarize and say sequence
There are several ways to generate a self-referential sequence. One very common one (the Look-and-say sequence) is to start with a positive integer, then generate the next term by concatenating enumerated groups of adjacent alike digits: 0, 10, 1110, 3110, 132110, 1113122110, 311311222110 ... The terms generat...
#Phix
Phix
with javascript_semantics string n = "000000" function incn() for i=length(n) to 1 by -1 do if n[i]='9' then if i=1 then return false end if n[i]='0' else n[i] += 1 exit end if end for return true end function sequence res = {}, bes...
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#Maxima
Maxima
/* builtin */ symmdifference({"John", "Bob", "Mary", "Serena"}, {"Jim", "Mary", "John", "Bob"}); {"Jim", "Serena"}
http://rosettacode.org/wiki/Symmetric_difference
Symmetric difference
Task Given two sets A and B, compute ( A ∖ B ) ∪ ( B ∖ A ) . {\displaystyle (A\setminus B)\cup (B\setminus A).} That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: ( A ∪ B ) ∖ ( A ∩ B ) {\displaystyle (A\cup B)\setminus (A...
#Mercury
Mercury
:- module symdiff. :- interface.   :- import_module io. :- pred main(io::di, io::uo) is det.   :- implementation. :- import_module list, set, string.   main(!IO) :- A = set(["John", "Bob", "Mary", "Serena"]), B = set(["Jim", "Mary", "John", "Bob"]), print_set("A\\B", DiffAB @ (A `difference` B), !IO), p...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#Lambdatalk
Lambdatalk
  {def to-celsius {lambda {:k} {- :k 273.15}}} -> to-celsius   {def to-farenheit {lambda {:k} {- {* :k 1.8} 459.67}}} -> to-farenheit   {def to-rankine {lambda {:k} {* :k 1.8}}} -> to-rankine   {def format {lambda {:n} {/ {round {* :n 100}} 100}}} -> format   {def kelvinConversion {lambda {:k} kelvin is equivalent t...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#uBasic.2F4tH
uBasic/4tH
Dim @n(12) : Dim @v(12) ' define both arrays   Proc _DataDays ' put data on the stack   For i=11 To 0 Step -1 ' read them in @n(i) = Pop() Next   Proc _DataGifts ' put data on the stack   For i=11 To 0 Step -1 ' read them ...
http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas
The Twelve Days of Christmas
Task Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.) Other tasks related to string operations: Metrics Array length Stri...
#UNIX_Shell
UNIX Shell
#!/usr/bin/env bash ordinals=(first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth)   gifts=( "A partridge in a pear tree." "Two turtle doves and" "Three French hens," "Four calling birds," "Five gold rings," "Six geese a-laying," ...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Hoon
Hoon
now
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Icon_and_Unicon
Icon and Unicon
procedure main()   write("&time - milliseconds of CPU time = ",&time) write("&clock - Time of day as hh:mm:ss (24-hour format) = ",&clock) write("&date - current date in yyyy/mm/dd format = ",&date) write("&dateline - timestamp with day of the week, date, and current time to the minute = ",&dateline)   ...