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/Create_a_file
Create a file
In this task, the job is to create a new empty file called "output.txt" of size 0 bytes and an empty directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#Dc
Dc
! for d in . / ;do > "$d/output.txt" ; mkdir "$d/docs" ;done
http://rosettacode.org/wiki/Create_a_file
Create a file
In this task, the job is to create a new empty file called "output.txt" of size 0 bytes and an empty directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#DCL
DCL
open/write output_file output.txt open/write output_file [000000]output.txt create/directory [.docs] create/directory [000000.docs]
http://rosettacode.org/wiki/CSV_to_HTML_translation
CSV to HTML translation
Consider a simplified CSV format where all rows are separated by a newline and all columns are separated by commas. No commas are allowed as field data, but the data may contain other characters and character sequences that would normally be   escaped   when converted to HTML Task Create a function that takes a st...
#EchoLisp
EchoLisp
  ;; CSV -> LISTS (define (csv->row line) (string-split line ",")) (define (csv->table csv) (map csv->row (string-split csv "\n")))   ;; LISTS->HTML (define html 'html) (define (emit-tag tag html-proc content ) (if (style tag) (push html (format "<%s style='%a'>" tag (style tag))) (push html (format "<%s...
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#Kotlin
Kotlin
// version 1.1.3   import java.io.File   fun main(args: Array<String>) { val lines = File("example.csv").readLines().toMutableList() lines[0] += ",SUM" for (i in 1 until lines.size) { lines[i] += "," + lines[i].split(',').sumBy { it.toInt() } } val text = lines.joinToString("\n") File("e...
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#uBasic.2F4tH
uBasic/4tH
Push 0, 3, 1, 7, 5, 9, 8, 6, 4, 2: i = FUNC(_Data(0)) Push 7, 0, 9, 2, 1, 5, 4, 8, 6, 3: i = FUNC(_Data(i)) Push 4, 2, 0, 6, 8, 7, 1, 3, 5, 9: i = FUNC(_Data(i)) Push 1, 7, 5, 0, 9, 8, 3, 4, 2, 6: i = FUNC(_Data(i)) Push 6, 1, 2, 3, 0, 4, 5, 9, 7, 8: i = FUNC(_Data(i)) Push 3, 6, 7, 4, 2, 0, 9, 5, 8, 1: i = FUNC(_Data(...
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#Visual_Basic_.NET
Visual Basic .NET
Module Module1   ReadOnly table = { {0, 3, 1, 7, 5, 9, 8, 6, 4, 2}, {7, 0, 9, 2, 1, 5, 4, 8, 6, 3}, {4, 2, 0, 6, 8, 7, 1, 3, 5, 9}, {1, 7, 5, 0, 9, 8, 3, 4, 2, 6}, {6, 1, 2, 3, 0, 4, 5, 9, 7, 8}, {3, 6, 7, 4, 2, 0, 9, 5, 8, 1}, {5, ...
http://rosettacode.org/wiki/Cuban_primes
Cuban primes
The name   cuban   has nothing to do with   Cuba  (the country),   but has to do with the fact that cubes   (3rd powers)   play a role in its definition. Some definitions of cuban primes   primes which are the difference of two consecutive cubes.   primes of the form:   (n+1)3 - n3.   primes of the form:   n3 - ...
#Visual_Basic_.NET
Visual Basic .NET
Module Module1 Dim primes As List(Of Long) = {3L, 5L}.ToList()   Sub Main(args As String()) Const cutOff As Integer = 200, bigUn As Integer = 100000, tn As String = " cuban prime" Console.WriteLine("The first {0:n0}{1}s:", cutOff, tn) Dim c As Integer = 0, showEach As Boole...
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#Pascal
Pascal
<@ SAI> <@ ITEFORLI3>2121|2008| <@ LETVARCAP>Christmas Day|25-Dec-<@ SAYVALFOR>...</@></@> <@ TSTDOWVARLIT>Christmas Day|1</@> <@ IFF> <@ SAYCAP>Christmas Day <@ SAYVALFOR>...</@> is a Sunday</@><@ SAYKEY>__Newline</@> </@> </@> </@>
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#Peloton
Peloton
<@ SAI> <@ ITEFORLI3>2121|2008| <@ LETVARCAP>Christmas Day|25-Dec-<@ SAYVALFOR>...</@></@> <@ TSTDOWVARLIT>Christmas Day|1</@> <@ IFF> <@ SAYCAP>Christmas Day <@ SAYVALFOR>...</@> is a Sunday</@><@ SAYKEY>__Newline</@> </@> </@> </@>
http://rosettacode.org/wiki/Create_a_two-dimensional_array_at_runtime
Create a two-dimensional array at runtime
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed ...
#ERRE
ERRE
  PROGRAM DYNAMIC   !$DYNAMIC DIM A%[0,0]   BEGIN PRINT(CHR$(12);) !CLS INPUT("Subscripts",R%,C%)  !$DIM A%[R%,C%] A%[2,3]=6 PRINT("Value in row";2;"and col";3;"is";A%[2,3]) END PROGRAM  
http://rosettacode.org/wiki/Create_a_two-dimensional_array_at_runtime
Create a two-dimensional array at runtime
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed ...
#Euphoria
Euphoria
include get.e   sequence array integer height,width,i,j   height = floor(prompt_number("Enter height: ",{})) width = floor(prompt_number("Enter width: ",{}))   array = repeat(repeat(0,width),height)   i = floor(height/2+0.5) j = floor(width/2+0.5) array[i][j] = height + width   printf(1,"array[%d][%d] is %d\n", {i,j,ar...
http://rosettacode.org/wiki/Cumulative_standard_deviation
Cumulative standard deviation
Task[edit] Write a stateful function, class, generator or co-routine that takes a series of floating point numbers, one at a time, and returns the running standard deviation of the series. The task implementation should use the most natural programming style of those listed for the function in the implementation langu...
#Icon_and_Unicon
Icon and Unicon
procedure main()   stddev() # reset state / empty every s := stddev(![2,4,4,4,5,5,7,9]) do write("stddev (so far) := ",s)   end   procedure stddev(x) # running standard deviation static X,sumX,sum2X   if /x then { # reset state X := [] sumX := sum2X := 0. } else { # accumulate ...
http://rosettacode.org/wiki/CRC-32
CRC-32
Task Demonstrate a method of deriving the Cyclic Redundancy Check from within the language. The result should be in accordance with ISO 3309, ITU-T V.42, Gzip and PNG. Algorithms are described on Computation of CRC in Wikipedia. This variant of CRC-32 uses LSB-first order, sets the initial CRC to FFFFFFFF16, and...
#Lua
Lua
local compute=require"zlib".crc32() local sum=compute("The quick brown fox jumps over the lazy dog") print(string.format("0x%x", sum))  
http://rosettacode.org/wiki/CRC-32
CRC-32
Task Demonstrate a method of deriving the Cyclic Redundancy Check from within the language. The result should be in accordance with ISO 3309, ITU-T V.42, Gzip and PNG. Algorithms are described on Computation of CRC in Wikipedia. This variant of CRC-32 uses LSB-first order, sets the initial CRC to FFFFFFFF16, and...
#M2000_Interpreter
M2000 Interpreter
  Module CheckIt { Function PrepareTable { Dim Base 0, table(256) For i = 0 To 255 { k = i For j = 0 To 7 { If binary.and(k,1)=1 Then { k =binary.Xor(binary.shift(k, -1) , 0xEDB88320) ...
http://rosettacode.org/wiki/Count_the_coins
Count the coins
There are four types of common coins in   US   currency:   quarters   (25 cents)   dimes   (10 cents)   nickels   (5 cents),   and   pennies   (1 cent) There are six ways to make change for 15 cents:   A dime and a nickel   A dime and 5 pennies   3 nickels   2 nickels and 5 pennies   A nickel and 10 pen...
#Common_Lisp
Common Lisp
(defun count-change (amount coins &optional (length (1- (length coins))) (cache (make-array (list (1+ amount) (length coins)) :initial-element nil))) (cond ((< length 0) 0) ((< amount 0) 0) ((= amount ...
http://rosettacode.org/wiki/Count_occurrences_of_a_substring
Count occurrences of a substring
Task Create a function,   or show a built-in function,   to count the number of non-overlapping occurrences of a substring inside a string. The function should take two arguments:   the first argument being the string to search,   and   the second a substring to be searched for. It should return an integer cou...
#BCPL
BCPL
get "libhdr"   let countsubstr(str, match) = valof $( let i, count = 1, 0 while i <= str%0 do test valof $( for j = 1 to match%0 unless match%j = str%(i+j-1) resultis false resultis true $) then $( count := count + 1 ...
http://rosettacode.org/wiki/Count_occurrences_of_a_substring
Count occurrences of a substring
Task Create a function,   or show a built-in function,   to count the number of non-overlapping occurrences of a substring inside a string. The function should take two arguments:   the first argument being the string to search,   and   the second a substring to be searched for. It should return an integer cou...
#Bracmat
Bracmat
( count-substring = n S s p . 0:?n:?p & !arg:(?S.?s) & @( !S  :  ? ( [!p ? !s [?p ? & !n+1:?n & ~ ) ) | !n ) & out$(count-substring$("the three truths".th)) & out$(count-substring$(ababababab.abab)) &...
http://rosettacode.org/wiki/Count_in_octal
Count in octal
Task Produce a sequential count in octal,   starting at zero,   and using an increment of a one for each consecutive number. Each number should appear on a single line,   and the program should count until terminated,   or until the maximum value of the numeric type in use is reached. Related task   Integer sequ...
#bc
bc
obase = 8 /* Output base is octal. */ for (num = 0; 1; num++) num /* Loop forever, printing counter. */
http://rosettacode.org/wiki/Count_in_octal
Count in octal
Task Produce a sequential count in octal,   starting at zero,   and using an increment of a one for each consecutive number. Each number should appear on a single line,   and the program should count until terminated,   or until the maximum value of the numeric type in use is reached. Related task   Integer sequ...
#BCPL
BCPL
get "libhdr"   let start() be $( let x = 0 $( writeo(x) wrch('*N') x := x + 1 $) repeatuntil x = 0 $)
http://rosettacode.org/wiki/Count_in_factors
Count in factors
Task Write a program which counts up from   1,   displaying each number as the multiplication of its prime factors. For the purpose of this task,   1   (unity)   may be shown as itself. Example       2   is prime,   so it would be shown as itself.       6   is not prime;   it would be shown as   2 × 3 {\di...
#Befunge
Befunge
1>>>>:.48*"=",,::1-#v_.v $<<<^_@#-"e":+1,+55$2<<< v4_^#-1:/.:g00_00g1+>>0v >8*"x",,:00g%!^!%g00:p0<
http://rosettacode.org/wiki/Count_in_factors
Count in factors
Task Write a program which counts up from   1,   displaying each number as the multiplication of its prime factors. For the purpose of this task,   1   (unity)   may be shown as itself. Example       2   is prime,   so it would be shown as itself.       6   is not prime;   it would be shown as   2 × 3 {\di...
#C
C
#include <stdio.h> #include <stdlib.h>   typedef unsigned long long ULONG;   ULONG get_prime(int idx) { static long n_primes = 0, alloc = 0; static ULONG *primes = 0; ULONG last, p; int i;   if (idx >= n_primes) { if (n_primes >= alloc) { a...
http://rosettacode.org/wiki/Create_an_HTML_table
Create an HTML table
Create an HTML table. The table body should have at least three rows of three columns. Each of these three columns should be labelled "X", "Y", and "Z". An extra column should be added at either the extreme left or the extreme right of the table that has no heading, but is filled with sequential row numbers. The...
#C.2B.2B
C++
#include <fstream> #include <boost/array.hpp> #include <string> #include <cstdlib> #include <ctime> #include <sstream>   void makeGap( int gap , std::string & text ) { for ( int i = 0 ; i < gap ; i++ ) text.append( " " ) ; }   int main( ) { boost::array<char , 3> chars = { 'X' , 'Y' , 'Z' } ; int headga...
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#ooRexx
ooRexx
/* REXX */ dats='20071123' Say date('I',dats,'S') Say date('W',dats,'S')',' date('M',dats,'S') substr(dats,7,2)',' left(dats,4) Say date('W',dats,'S')',' date('M',dats,'S') translate('gh, abcd',dats,'abcdefgh') dati=date('I') Say dati Say date('W',dati,'I')',' date('M',dati,'I') translate('ij, abcd',dati,'abcdefghij')
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#OxygenBasic
OxygenBasic
  extern lib "kernel32.dll"   'http://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx   typedef struct _SYSTEMTIME { WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds; } SYSTEMTIME, *PSYSTEMTIME;   void GetSystemTime(S...
http://rosettacode.org/wiki/Cramer%27s_rule
Cramer's rule
linear algebra Cramer's rule system of linear equations Given { a 1 x + b 1 y + c 1 z = d 1 a 2 x + b 2 y + c 2 z = d 2 a 3 x + b 3 y + c 3 z = d 3 {\displaystyle \left\{{\begin{matrix}a_{1}x+b_{1}y+c_{1}z&={\color {red}d_{1...
#JavaScript
JavaScript
  var matrix = [ [2, -1, 5, 1], [3, 2, 2, -6], [1, 3, 3, -1], [5, -2, -3, 3] ]; var freeTerms = [-3, -32, -47, 49];   var result = cramersRule(matrix,freeTerms); console.log(result);   /** * Compute Cramer's Rule * @param {array} matrix x,y,z, etc. terms * @param {array} freeTerms * @return {array} ...
http://rosettacode.org/wiki/Create_a_file
Create a file
In this task, the job is to create a new empty file called "output.txt" of size 0 bytes and an empty directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#Delphi
Delphi
  program createFile;   {$APPTYPE CONSOLE}   uses Classes, SysUtils;   const filename = 'output.txt';   var cwdPath, fsPath: string;     // Create empty file in current working directory function CreateEmptyFile1: Boolean; var f: textfile; begin // Make path to the file to be created cwdPath := ExtractF...
http://rosettacode.org/wiki/CSV_to_HTML_translation
CSV to HTML translation
Consider a simplified CSV format where all rows are separated by a newline and all columns are separated by commas. No commas are allowed as field data, but the data may contain other characters and character sequences that would normally be   escaped   when converted to HTML Task Create a function that takes a st...
#Erlang
Erlang
  -module( csv_to_html ).   -export( [table_translation/1, task/0] ).   table_translation( CSV ) -> [Headers | Contents] = [string:tokens(X, ",") || X <- string:tokens( CSV, "\n")], Table = create_html_table:html_table( [{border, "1"}, {cellpadding, "10"}], Headers, Contents ), create_html_table:external_format( Tab...
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#Lingo
Lingo
---------------------------------------- -- Simplified CSV parser (without escape character support etc.). -- First line is interrepted as header with column names. -- @param {string} csvStr -- @param {string} [sep=","] - single char as string -- @param {string} [eol=RETURN] -- @return {propList} ----------------------...
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#Lua
Lua
local csv={} for line in io.lines('file.csv') do table.insert(csv, {}) local i=1 for j=1,#line do if line:sub(j,j) == ',' then table.insert(csv[#csv], line:sub(i,j-1)) i=j+1 end end table.insert(csv[#csv], line:sub(i,j)) end   table.insert(csv[1], 'SUM') for i...
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#Vlang
Vlang
const table = [ [u8(0), 3, 1, 7, 5, 9, 8, 6, 4, 2], [u8(7), 0, 9, 2, 1, 5, 4, 8, 6, 3], [u8(4), 2, 0, 6, 8, 7, 1, 3, 5, 9], [u8(1), 7, 5, 0, 9, 8, 3, 4, 2, 6], [u8(6), 1, 2, 3, 0, 4, 5, 9, 7, 8], [u8(3), 6, 7, 4, 2, 0, 9, 5, 8, 1], [u8(5), 8, 6, 9, 7, 2, 0, 1, 3, 4], [u8(8), 9, 4, 5, 3, ...
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#Wren
Wren
import "/fmt" for Fmt   var table = [ [0, 3, 1, 7, 5, 9, 8, 6, 4, 2], [7, 0, 9, 2, 1, 5, 4, 8, 6, 3], [4, 2, 0, 6, 8, 7, 1, 3, 5, 9], [1, 7, 5, 0, 9, 8, 3, 4, 2, 6], [6, 1, 2, 3, 0, 4, 5, 9, 7, 8], [3, 6, 7, 4, 2, 0, 9, 5, 8, 1], [5, 8, 6, 9, 7, 2, 0, 1, 3, 4], [8, 9, 4, 5, 3, 6, 2, 0, 1...
http://rosettacode.org/wiki/Cuban_primes
Cuban primes
The name   cuban   has nothing to do with   Cuba  (the country),   but has to do with the fact that cubes   (3rd powers)   play a role in its definition. Some definitions of cuban primes   primes which are the difference of two consecutive cubes.   primes of the form:   (n+1)3 - n3.   primes of the form:   n3 - ...
#Wren
Wren
import "/fmt" for Fmt   var start = System.clock var primes = [3, 5] var cutOff = 200 var bigOne = 100000 var cubans = [] var bigCuban = "" var c = 0 var showEach = true var u = 0 var v = 1   for (i in 1...(1<<20)) { var found = false u = u + 6 v = v + u var mx = v.sqrt.floor for (item in primes) {...
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#Perl
Perl
#! /usr/bin/perl -w   use Time::Local; use strict;   foreach my $i (2008 .. 2121) { my $time = timelocal(0,0,0,25,11,$i); my ($s,$m,$h,$md,$mon,$y,$wd,$yd,$is) = localtime($time); if ( $wd == 0 ) { print "25 Dec $i is Sunday\n"; } }   exit 0;
http://rosettacode.org/wiki/Create_a_two-dimensional_array_at_runtime
Create a two-dimensional array at runtime
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed ...
#F.23
F#
open System   let width = int( Console.ReadLine() ) let height = int( Console.ReadLine() ) let arr = Array2D.create width height 0 arr.[0,0] <- 42 printfn "%d" arr.[0,0]
http://rosettacode.org/wiki/Cumulative_standard_deviation
Cumulative standard deviation
Task[edit] Write a stateful function, class, generator or co-routine that takes a series of floating point numbers, one at a time, and returns the running standard deviation of the series. The task implementation should use the most natural programming style of those listed for the function in the implementation langu...
#IS-BASIC
IS-BASIC
100 PROGRAM "StDev.bas" 110 LET N=8 120 NUMERIC ARR(1 TO N) 130 FOR I=1 TO N 140 READ ARR(I) 150 NEXT 160 DEF STDEV(N) 170 LET S1,S2=0 180 FOR I=1 TO N 190 LET S1=S1+ARR(I)^2:LET S2=S2+ARR(I) 200 NEXT 210 LET STDEV=SQR((N*S1-S2^2)/N^2) 220 END DEF 230 FOR J=1 TO N 240 PRINT J;"item =";ARR(J),"standar...
http://rosettacode.org/wiki/CRC-32
CRC-32
Task Demonstrate a method of deriving the Cyclic Redundancy Check from within the language. The result should be in accordance with ISO 3309, ITU-T V.42, Gzip and PNG. Algorithms are described on Computation of CRC in Wikipedia. This variant of CRC-32 uses LSB-first order, sets the initial CRC to FFFFFFFF16, and...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
type="CRC32"; (*pick one out of 13 predefined hash types*) StringForm[ "The "<>type<>" hash code of \"``\" is ``.", s="The quick brown fox jumps over the lazy dog", Hash[s,type,"HexString"] ]  
http://rosettacode.org/wiki/CRC-32
CRC-32
Task Demonstrate a method of deriving the Cyclic Redundancy Check from within the language. The result should be in accordance with ISO 3309, ITU-T V.42, Gzip and PNG. Algorithms are described on Computation of CRC in Wikipedia. This variant of CRC-32 uses LSB-first order, sets the initial CRC to FFFFFFFF16, and...
#Neko
Neko
/** <doc>CRC32 in Neko</doc> **/   var int32_new = $loader.loadprim("std@int32_new", 1) var update_crc32 = $loader.loadprim("zlib@update_crc32", 4)   var crc = int32_new(0) var txt = "The quick brown fox jumps over the lazy dog"   crc = update_crc32(crc, txt, 0, $ssize(txt)) $print(crc, "\n")
http://rosettacode.org/wiki/Count_the_coins
Count the coins
There are four types of common coins in   US   currency:   quarters   (25 cents)   dimes   (10 cents)   nickels   (5 cents),   and   pennies   (1 cent) There are six ways to make change for 15 cents:   A dime and a nickel   A dime and 5 pennies   3 nickels   2 nickels and 5 pennies   A nickel and 10 pen...
#D
D
import std.stdio, std.bigint;   auto changes(int amount, int[] coins) { auto ways = new BigInt[amount + 1]; ways[0] = 1; foreach (coin; coins) foreach (j; coin .. amount + 1) ways[j] += ways[j - coin]; return ways[$ - 1]; }   void main() { changes( 1_00, [25, 10, 5, 1]).writeln...
http://rosettacode.org/wiki/Count_occurrences_of_a_substring
Count occurrences of a substring
Task Create a function,   or show a built-in function,   to count the number of non-overlapping occurrences of a substring inside a string. The function should take two arguments:   the first argument being the string to search,   and   the second a substring to be searched for. It should return an integer cou...
#C
C
#include <stdio.h> #include <string.h>   int match(const char *s, const char *p, int overlap) { int c = 0, l = strlen(p);   while (*s != '\0') { if (strncmp(s++, p, l)) continue; if (!overlap) s += l - 1; c++; } return c; }   int main() { ...
http://rosettacode.org/wiki/Count_in_octal
Count in octal
Task Produce a sequential count in octal,   starting at zero,   and using an increment of a one for each consecutive number. Each number should appear on a single line,   and the program should count until terminated,   or until the maximum value of the numeric type in use is reached. Related task   Integer sequ...
#Befunge
Befunge
:0\55+\:8%68>*#<+#8\#68#%/#8:_$>:#,_$1+:0`!#@_
http://rosettacode.org/wiki/Count_in_octal
Count in octal
Task Produce a sequential count in octal,   starting at zero,   and using an increment of a one for each consecutive number. Each number should appear on a single line,   and the program should count until terminated,   or until the maximum value of the numeric type in use is reached. Related task   Integer sequ...
#Bracmat
Bracmat
  ( oct = .  !arg:<8 & (!arg:~<0|ERROR) | str$(oct$(div$(!arg.8)) mod$(!arg.8)) ) & -1:?n & whl'(1+!n:?n&out$(!n oct$!n));  
http://rosettacode.org/wiki/Count_in_octal
Count in octal
Task Produce a sequential count in octal,   starting at zero,   and using an increment of a one for each consecutive number. Each number should appear on a single line,   and the program should count until terminated,   or until the maximum value of the numeric type in use is reached. Related task   Integer sequ...
#Brainf.2A.2A.2A
Brainf***
+[ Start with n=1 to kick off the loop [>>++++++++<< Set up {n 0 8} for divmod magic [->+>- Then [>+>>]> do [+[-<+>]>+>>] the <<<<<<] magic >>>+ Increment n % 8 so that 0s don't break things >] Move into n / 8 and divmod that unless it's 0 -< Set up sentinel ...
http://rosettacode.org/wiki/Count_in_factors
Count in factors
Task Write a program which counts up from   1,   displaying each number as the multiplication of its prime factors. For the purpose of this task,   1   (unity)   may be shown as itself. Example       2   is prime,   so it would be shown as itself.       6   is not prime;   it would be shown as   2 × 3 {\di...
#C.23
C#
using System; using System.Collections.Generic;   namespace prog { class MainClass { public static void Main (string[] args) { for( int i=1; i<=22; i++ ) { List<int> f = Factorize(i); Console.Write( i + ": " + f[0] ); for( int j=1; j<f.Count; j++ ) { Console.Write( " * " + f[j] ); ...
http://rosettacode.org/wiki/Create_an_HTML_table
Create an HTML table
Create an HTML table. The table body should have at least three rows of three columns. Each of these three columns should be labelled "X", "Y", and "Z". An extra column should be added at either the extreme left or the extreme right of the table that has no heading, but is filled with sequential row numbers. The...
#Clojure
Clojure
(ns rosettacode.html-table (:use 'hiccup.core))   (defn <tr> [el sq] [:tr (map vector (cycle [el]) sq)])   (html [:table (<tr> :th ["" \X \Y \Z]) (for [n (range 1 4)] (->> #(rand-int 10000) (repeatedly 3) (cons n) (<tr> :td)))])
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#Oz
Oz
declare WeekDays = unit(0:"Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday") Months = unit(0:"January" "February" "March" "April" "May" "June" "July" "August" "September" "October" "November" "December")   fun {DateISO Time} Year = 1900 +...
http://rosettacode.org/wiki/Cramer%27s_rule
Cramer's rule
linear algebra Cramer's rule system of linear equations Given { a 1 x + b 1 y + c 1 z = d 1 a 2 x + b 2 y + c 2 z = d 2 a 3 x + b 3 y + c 3 z = d 3 {\displaystyle \left\{{\begin{matrix}a_{1}x+b_{1}y+c_{1}z&={\color {red}d_{1...
#jq
jq
# The minor of the input matrix after removing the specified row and column. # Assumptions: the input is square and the indices are hunky dory. def minor(rowNum; colNum): . as $in | (length - 1) as $len | reduce range(0; $len) as $i (null; reduce range(0; $len) as $j (.; if $i < rowNum and $j < colN...
http://rosettacode.org/wiki/Cramer%27s_rule
Cramer's rule
linear algebra Cramer's rule system of linear equations Given { a 1 x + b 1 y + c 1 z = d 1 a 2 x + b 2 y + c 2 z = d 2 a 3 x + b 3 y + c 3 z = d 3 {\displaystyle \left\{{\begin{matrix}a_{1}x+b_{1}y+c_{1}z&={\color {red}d_{1...
#Julia
Julia
function cramersolve(A::Matrix, b::Vector) return collect(begin B = copy(A); B[:, i] = b; det(B) end for i in eachindex(b)) ./ det(A) end   A = [2 -1 5 1 3 2 2 -6 1 3 3 -1 5 -2 -3 3]   b = [-3, -32, -47, 49]   @show cramersolve(A, b)
http://rosettacode.org/wiki/Create_a_file
Create a file
In this task, the job is to create a new empty file called "output.txt" of size 0 bytes and an empty directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#E
E
<file:output.txt>.setBytes([]) <file:docs>.mkdir(null) <file:///output.txt>.setBytes([]) <file:///docs>.mkdir(null)
http://rosettacode.org/wiki/Create_a_file
Create a file
In this task, the job is to create a new empty file called "output.txt" of size 0 bytes and an empty directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#EchoLisp
EchoLisp
  ;; The file system is the browser local storage ;; It is divided into named stores (directories) ;; "user" is the default (home) store   ; before : list of stores (local-stores) → ("system" "user" "words" "reader" "info" "root")   (local-put-value "output.txt" "") → "output.txt" ; into "user" (local-make-store "user...
http://rosettacode.org/wiki/CSV_to_HTML_translation
CSV to HTML translation
Consider a simplified CSV format where all rows are separated by a newline and all columns are separated by commas. No commas are allowed as field data, but the data may contain other characters and character sequences that would normally be   escaped   when converted to HTML Task Create a function that takes a st...
#Euphoria
Euphoria
constant input = "Character,Speech\n" & "The multitude,The messiah! Show us the messiah!\n" & "Brians mother,<angry>Now you listen here! He's not the messiah; " & "he's a very naughty boy! Now go away!</angry>\n" & "The multitude,Who are you?\n" & "Brians mother,I'm his mother; that's who!\n" & ...
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { Function Sum { Long c=0 while not empty { c+=number } =c } Document CSV$ = {C1,C2,C3,C4,C5 1,5,9,13,17 2,6,10,14,18 3,7,11,15,19 4,8,12,16,20 } \\ export enc...
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#Maple
Maple
M := ImportMatrix("data.csv",source=csv); M(..,6) := < "Total", seq( add(M[i,j], j=1..5), i=2..5 ) >; ExportMatrix("data_out.csv",M,target=csv);  
http://rosettacode.org/wiki/Damm_algorithm
Damm algorithm
The Damm algorithm is a checksum algorithm which detects all single digit errors and adjacent transposition errors. The algorithm is named after H. Michael Damm. Task Verify the checksum, stored as last digit of an input.
#zkl
zkl
fcn damm(digits){ // digits is something that supports an iterator of integers var [const] tbl=Data(0,Int, // 10x10 byte bucket 0, 3, 1, 7, 5, 9, 8, 6, 4, 2, 7, 0, 9, 2, 1, 5, 4, 8, 6, 3, 4, 2, 0, 6, 8, 7, 1, 3, 5, 9, 1, 7, 5, 0, 9, 8, 3, 4, 2, 6, 6, 1, 2, 3, 0, 4, 5, 9, 7, 8, ...
http://rosettacode.org/wiki/Cuban_primes
Cuban primes
The name   cuban   has nothing to do with   Cuba  (the country),   but has to do with the fact that cubes   (3rd powers)   play a role in its definition. Some definitions of cuban primes   primes which are the difference of two consecutive cubes.   primes of the form:   (n+1)3 - n3.   primes of the form:   n3 - ...
#zkl
zkl
var [const] BI=Import("zklBigNum"); // libGMP cubans:=(1).walker(*).tweak('wrap(n){ // lazy iterator p:=3*n*(n + 1) + 1; BI(p).probablyPrime() and p or Void.Skip }); println("First 200 cuban primes:"); do(20){ (10).pump(String, cubans.next, "%10,d".fmt).println() }   cubans.drop(100_000 - cubans.n).value : p...
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#Phix
Phix
-- demo\rosetta\Day_of_the_week.exw sequence res = {} for y=2008 to 2121 do if day_of_week(y,12,25,true)="Sunday" then res = append(res,y) end if end for ?res
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#PHP
PHP
<?php for($i=2008; $i<2121; $i++) { $datetime = new DateTime("$i-12-25 00:00:00"); if ( $datetime->format("w") == 0 ) { echo "25 Dec $i is Sunday\n"; } } ?>
http://rosettacode.org/wiki/Create_a_two-dimensional_array_at_runtime
Create a two-dimensional array at runtime
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed ...
#Factor
Factor
USING: io kernel math.matrices math.parser prettyprint sequences ; IN: rosettacode.runtime2darray   : set-Mi,j ( elt {i,j} matrix -- ) [ first2 swap ] dip nth set-nth ; : Mi,j ( {i,j} matrix -- elt ) [ first2 swap ] dip nth nth ;   : example ( -- ) readln readln [ string>number ] bi@ zero-matrix ! create the array [ ...
http://rosettacode.org/wiki/Create_a_two-dimensional_array_at_runtime
Create a two-dimensional array at runtime
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed ...
#Fermat
Fermat
?m; {imput the dimensions of the array} ?n; Array a[m,n]; {generate an array of m rows and n columns} a[m\2, n\2] := m+n-1; {put some value in one of the cells} !!a[m\2, n\2]; {display that entry} @[a]; {delete the array}
http://rosettacode.org/wiki/Cumulative_standard_deviation
Cumulative standard deviation
Task[edit] Write a stateful function, class, generator or co-routine that takes a series of floating point numbers, one at a time, and returns the running standard deviation of the series. The task implementation should use the most natural programming style of those listed for the function in the implementation langu...
#J
J
mean=: +/ % # dev=: - mean stddevP=: [: %:@mean *:@dev NB. A) 3 equivalent defs for stddevP stddevP=: [: mean&.:*: dev NB. B) uses Under (&.:) to apply inverse of *: after mean stddevP=: %:@(mean@:*: - *:@mean) NB. C) sqrt of ((mean of squares) - (square of mean))     stddevP\ 2 ...
http://rosettacode.org/wiki/CRC-32
CRC-32
Task Demonstrate a method of deriving the Cyclic Redundancy Check from within the language. The result should be in accordance with ISO 3309, ITU-T V.42, Gzip and PNG. Algorithms are described on Computation of CRC in Wikipedia. This variant of CRC-32 uses LSB-first order, sets the initial CRC to FFFFFFFF16, and...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols binary   import java.util.zip.CRC32   toBeEncoded = String("The quick brown fox jumps over the lazy dog") myCRC = CRC32() myCRC.update(toBeEncoded.getBytes()) say "The CRC-32 value is :" Long.toHexString(myCRC.getValue()) "!"   return  
http://rosettacode.org/wiki/CRC-32
CRC-32
Task Demonstrate a method of deriving the Cyclic Redundancy Check from within the language. The result should be in accordance with ISO 3309, ITU-T V.42, Gzip and PNG. Algorithms are described on Computation of CRC in Wikipedia. This variant of CRC-32 uses LSB-first order, sets the initial CRC to FFFFFFFF16, and...
#Nim
Nim
import strutils   type TCrc32* = uint32 const InitCrc32* = TCrc32(0xffffffff)   proc createCrcTable(): array[0..255, TCrc32] = for i in 0..255: var rem = TCrc32(i) for j in 0..7: if (rem and 1) > 0: rem = (rem shr 1) xor TCrc32(0xedb88320) else: rem = rem shr 1 result[i] = rem   # Table create...
http://rosettacode.org/wiki/Count_the_coins
Count the coins
There are four types of common coins in   US   currency:   quarters   (25 cents)   dimes   (10 cents)   nickels   (5 cents),   and   pennies   (1 cent) There are six ways to make change for 15 cents:   A dime and a nickel   A dime and 5 pennies   3 nickels   2 nickels and 5 pennies   A nickel and 10 pen...
#Dart
Dart
  var cache = new Map();   main() { var stopwatch = new Stopwatch()..start();   // use the brute-force recursion for the small problem int amount = 100; list coinTypes = [25,10,5,1]; print (coins(amount,coinTypes).toString() + " ways for $amount using $coinTypes coins.");   // use the cache vers...
http://rosettacode.org/wiki/Count_the_coins
Count the coins
There are four types of common coins in   US   currency:   quarters   (25 cents)   dimes   (10 cents)   nickels   (5 cents),   and   pennies   (1 cent) There are six ways to make change for 15 cents:   A dime and a nickel   A dime and 5 pennies   3 nickels   2 nickels and 5 pennies   A nickel and 10 pen...
#Delphi
Delphi
  program Count_the_coins;   {$APPTYPE CONSOLE}   function Count(c: array of Integer; m, n: Integer): Integer; var table: array of Integer; i, j: Integer; begin SetLength(table, n + 1); table[0] := 1; for i := 0 to m - 1 do for j := c[i] to n do table[j] := table[j] + table[j - c[i]]; Exit(table[n...
http://rosettacode.org/wiki/Count_occurrences_of_a_substring
Count occurrences of a substring
Task Create a function,   or show a built-in function,   to count the number of non-overlapping occurrences of a substring inside a string. The function should take two arguments:   the first argument being the string to search,   and   the second a substring to be searched for. It should return an integer cou...
#C.23
C#
using System;   class SubStringTestClass { public static int CountSubStrings(this string testString, string testSubstring) { int count = 0;   if (testString.Contains(testSubstring)) { for (int i = 0; i < testString.Length; i++) { if (testString.Subst...
http://rosettacode.org/wiki/Count_occurrences_of_a_substring
Count occurrences of a substring
Task Create a function,   or show a built-in function,   to count the number of non-overlapping occurrences of a substring inside a string. The function should take two arguments:   the first argument being the string to search,   and   the second a substring to be searched for. It should return an integer cou...
#C.2B.2B
C++
#include <iostream> #include <string>   // returns count of non-overlapping occurrences of 'sub' in 'str' int countSubstring(const std::string& str, const std::string& sub) { if (sub.length() == 0) return 0; int count = 0; for (size_t offset = str.find(sub); offset != std::string::npos; offset = str.find(...
http://rosettacode.org/wiki/Count_in_octal
Count in octal
Task Produce a sequential count in octal,   starting at zero,   and using an increment of a one for each consecutive number. Each number should appear on a single line,   and the program should count until terminated,   or until the maximum value of the numeric type in use is reached. Related task   Integer sequ...
#C
C
#include <stdio.h>   int main() { unsigned int i = 0; do { printf("%o\n", i++); } while(i); return 0; }
http://rosettacode.org/wiki/Count_in_octal
Count in octal
Task Produce a sequential count in octal,   starting at zero,   and using an increment of a one for each consecutive number. Each number should appear on a single line,   and the program should count until terminated,   or until the maximum value of the numeric type in use is reached. Related task   Integer sequ...
#C.23
C#
using System;   class Program { static void Main() { var number = 0; do { Console.WriteLine(Convert.ToString(number, 8)); } while (++number > 0); } }
http://rosettacode.org/wiki/Count_in_factors
Count in factors
Task Write a program which counts up from   1,   displaying each number as the multiplication of its prime factors. For the purpose of this task,   1   (unity)   may be shown as itself. Example       2   is prime,   so it would be shown as itself.       6   is not prime;   it would be shown as   2 × 3 {\di...
#C.2B.2B
C++
#include <iostream> #include <iomanip> using namespace std;   void getPrimeFactors( int li ) { int f = 2; string res; if ( li == 1 ) res = "1"; else { while ( true ) { if( !( li % f ) ) { res += to_string(f); li /= f; if( li == 1 ) break; res += " x "; } else f++; } } ...
http://rosettacode.org/wiki/Create_an_HTML_table
Create an HTML table
Create an HTML table. The table body should have at least three rows of three columns. Each of these three columns should be labelled "X", "Y", and "Z". An extra column should be added at either the extreme left or the extreme right of the table that has no heading, but is filled with sequential row numbers. The...
#CoffeeScript
CoffeeScript
  # This is one of many ways to create a table. CoffeeScript plays nice # with any templating solution built for JavaScript, and of course you # can build tables in the browser using DOM APIs. This approach is just # brute force string manipulation.   table = (header_row, rows) -> """ <table> #{header_row} #{...
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#Pascal
Pascal
program dateform; uses DOS;   { Format digit with leading zero } function lz(w: word): string; var s: string; begin str(w,s); if length(s) = 1 then s := '0' + s; lz := s end;   function m2s(mon: integer): string; begin case mon of 1: m2s := 'January'; 2: m2s := 'February'; 3: m2s := 'March'...
http://rosettacode.org/wiki/Cramer%27s_rule
Cramer's rule
linear algebra Cramer's rule system of linear equations Given { a 1 x + b 1 y + c 1 z = d 1 a 2 x + b 2 y + c 2 z = d 2 a 3 x + b 3 y + c 3 z = d 3 {\displaystyle \left\{{\begin{matrix}a_{1}x+b_{1}y+c_{1}z&={\color {red}d_{1...
#Kotlin
Kotlin
// version 1.1.3   typealias Vector = DoubleArray typealias Matrix = Array<Vector>   fun johnsonTrotter(n: Int): Pair<List<IntArray>, List<Int>> { val p = IntArray(n) { it } // permutation val q = IntArray(n) { it } // inverse permutation val d = IntArray(n) { -1 } // direction = 1 or -1 var sign = 1...
http://rosettacode.org/wiki/Create_a_file
Create a file
In this task, the job is to create a new empty file called "output.txt" of size 0 bytes and an empty directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#Elena
Elena
import system'io;   public program() { File.assign("output.txt").textwriter().close();   File.assign("\output.txt").textwriter().close();   Directory.assign("docs").create();   Directory.assign("\docs").create(); }
http://rosettacode.org/wiki/Create_a_file
Create a file
In this task, the job is to create a new empty file called "output.txt" of size 0 bytes and an empty directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#Elixir
Elixir
File.open("output.txt", [:write]) File.open("/output.txt", [:write])   File.mkdir!("docs") File.mkdir!("/docs")
http://rosettacode.org/wiki/CSV_to_HTML_translation
CSV to HTML translation
Consider a simplified CSV format where all rows are separated by a newline and all columns are separated by commas. No commas are allowed as field data, but the data may contain other characters and character sequences that would normally be   escaped   when converted to HTML Task Create a function that takes a st...
#F.23
F#
open System open System.Text open System.Xml   let data = """ Character,Speech The multitude,The messiah! Show us the messiah! Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> The multitude,Who are you? Brians mother,I'm his mother; that's who! The multitude,...
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
iCSV=Import["test.csv"] ->{{"C1","C2","C3","C4","C5"},{1,5,9,13,17},{2,6,10,14,18},{3,7,11,15,19},{4,8,12,16,20}} iCSV = Transpose@ Append[Transpose[iCSV], Join[{"Sum"}, Total /@ Drop[iCSV, 1]]]; iCSV // MatrixForm Export["test.csv",iCSV];
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#MATLAB_.2F_Octave
MATLAB / Octave
filename='data.csv'; fid = fopen(filename); header = fgetl(fid); fclose(fid); X = dlmread(filename,',',1,0);   fid = fopen('data.out.csv','w+'); fprintf(fid,'%s,sum\n',header); for k=1:size(X,1), fprintf(fid,"%i,",X(k,:)); fprintf(fid,"%i\n",sum(X(k,:))); end; fclose(fid);
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#Picat
Picat
go => L = [Year : Year in 2008..2121, dow(Year, 12, 25) == 0], println(L), println(len=L.length), nl.   % Day of week, Sakamoto's method dow(Y, M, D) = R => T = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4], if M < 3 then Y := Y - 1 end, R = (Y + Y // 4 - Y // 100 + Y // 400 + T[M] + D) mod 7.  
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#PicoLisp
PicoLisp
(for (Y 2008 (>= 2121 Y) (inc Y)) (when (= "Sunday" (day (date Y 12 25))) (printsp Y) ) )
http://rosettacode.org/wiki/Create_a_two-dimensional_array_at_runtime
Create a two-dimensional array at runtime
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed ...
#Forth
Forth
: cell-matrix create ( width height "name" ) over , * cells allot does> ( x y -- addr ) dup cell+ >r @ * + cells r> + ;   5 5 cell-matrix test   36 0 0 test ! 0 0 test @ . \ 36
http://rosettacode.org/wiki/Create_a_two-dimensional_array_at_runtime
Create a two-dimensional array at runtime
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed ...
#Fortran
Fortran
PROGRAM Example   IMPLICIT NONE INTEGER :: rows, columns, errcheck INTEGER, ALLOCATABLE :: array(:,:)   WRITE(*,*) "Enter number of rows" READ(*,*) rows WRITE(*,*) "Enter number of columns" READ(*,*) columns   ALLOCATE (array(rows,columns), STAT=errcheck) ! STAT is optional and is used for error checkin...
http://rosettacode.org/wiki/Cumulative_standard_deviation
Cumulative standard deviation
Task[edit] Write a stateful function, class, generator or co-routine that takes a series of floating point numbers, one at a time, and returns the running standard deviation of the series. The task implementation should use the most natural programming style of those listed for the function in the implementation langu...
#Java
Java
public class StdDev { int n = 0; double sum = 0; double sum2 = 0;   public double sd(double x) { n++; sum += x; sum2 += x*x;   return Math.sqrt(sum2/n - sum*sum/n/n); }   public static void main(String[] args) { double[] testData = {2,4,4,4,5,5,7,9}; StdDev sd = new StdDev();...
http://rosettacode.org/wiki/CRC-32
CRC-32
Task Demonstrate a method of deriving the Cyclic Redundancy Check from within the language. The result should be in accordance with ISO 3309, ITU-T V.42, Gzip and PNG. Algorithms are described on Computation of CRC in Wikipedia. This variant of CRC-32 uses LSB-first order, sets the initial CRC to FFFFFFFF16, and...
#NOWUT
NOWUT
; link with PIOxxx.OBJ   sectionbss   crctable.d: resd 256   sectiondata   havetable.b: db 0 string: db "The quick brown fox jumps over the lazy dog" stringend: db 13,10,0  ; carriage return and null terminator   sectioncode   start! gosub initp...
http://rosettacode.org/wiki/CRC-32
CRC-32
Task Demonstrate a method of deriving the Cyclic Redundancy Check from within the language. The result should be in accordance with ISO 3309, ITU-T V.42, Gzip and PNG. Algorithms are described on Computation of CRC in Wikipedia. This variant of CRC-32 uses LSB-first order, sets the initial CRC to FFFFFFFF16, and...
#Oberon-2
Oberon-2
  MODULE CRC32; IMPORT NPCT:Zlib, Strings, Out; VAR s: ARRAY 128 OF CHAR; BEGIN COPY("The quick brown fox jumps over the lazy dog",s); Out.Hex(Zlib.CRC32(0,s,0,Strings.Length(s)),0);Out.Ln END CRC32.  
http://rosettacode.org/wiki/Count_the_coins
Count the coins
There are four types of common coins in   US   currency:   quarters   (25 cents)   dimes   (10 cents)   nickels   (5 cents),   and   pennies   (1 cent) There are six ways to make change for 15 cents:   A dime and a nickel   A dime and 5 pennies   3 nickels   2 nickels and 5 pennies   A nickel and 10 pen...
#Dyalect
Dyalect
func countCoins(coins, n) { var xs = Array.Empty(n + 1, 0) xs[0] = 1 for c in coins { var cj = c while cj <= n { xs[cj] += xs[cj - c] cj += 1 } } return xs[n] }   var coins = [1, 5, 10, 25] print(countCoins(coins, 100))
http://rosettacode.org/wiki/Count_the_coins
Count the coins
There are four types of common coins in   US   currency:   quarters   (25 cents)   dimes   (10 cents)   nickels   (5 cents),   and   pennies   (1 cent) There are six ways to make change for 15 cents:   A dime and a nickel   A dime and 5 pennies   3 nickels   2 nickels and 5 pennies   A nickel and 10 pen...
#EchoLisp
EchoLisp
  (lib 'compile) ;; for (compile) (lib 'bigint) ;; integer results > 32 bits (lib 'hash) ;; hash table   ;; h-table (define Hcoins (make-hash))   ;; the function to memoize (define (sumways cents coins) (+ (ways cents (cdr coins)) (ways (- cents (car coins)) coins)))   ;; accelerator : ways (cents, coins) = ways (...
http://rosettacode.org/wiki/Count_occurrences_of_a_substring
Count occurrences of a substring
Task Create a function,   or show a built-in function,   to count the number of non-overlapping occurrences of a substring inside a string. The function should take two arguments:   the first argument being the string to search,   and   the second a substring to be searched for. It should return an integer cou...
#Clojure
Clojure
  (defn re-quote "Produces a string that can be used to create a Pattern that would match the string text as if it were a literal pattern. Metacharacters or escape sequences in text will be given no special meaning" [text] (java.util.regex.Pattern/quote text))   (defn count-substring [txt sub] (count (...
http://rosettacode.org/wiki/Count_occurrences_of_a_substring
Count occurrences of a substring
Task Create a function,   or show a built-in function,   to count the number of non-overlapping occurrences of a substring inside a string. The function should take two arguments:   the first argument being the string to search,   and   the second a substring to be searched for. It should return an integer cou...
#COBOL
COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. testing.   DATA DIVISION. WORKING-STORAGE SECTION. 01 occurrences PIC 99.   PROCEDURE DIVISION. INSPECT "the three truths" TALLYING occurrences FOR ALL "th" DISPLAY occurrences   MOVE 0 TO occurr...
http://rosettacode.org/wiki/Count_in_octal
Count in octal
Task Produce a sequential count in octal,   starting at zero,   and using an increment of a one for each consecutive number. Each number should appear on a single line,   and the program should count until terminated,   or until the maximum value of the numeric type in use is reached. Related task   Integer sequ...
#C.2B.2B
C++
#include <iostream>   int main() { unsigned i = 0; do { std::cout << std::oct << i << std::endl; ++i; } while(i != 0); return 0; }
http://rosettacode.org/wiki/Count_in_octal
Count in octal
Task Produce a sequential count in octal,   starting at zero,   and using an increment of a one for each consecutive number. Each number should appear on a single line,   and the program should count until terminated,   or until the maximum value of the numeric type in use is reached. Related task   Integer sequ...
#Clojure
Clojure
(doseq [i (range)] (println (format "%o" i)))
http://rosettacode.org/wiki/Count_in_factors
Count in factors
Task Write a program which counts up from   1,   displaying each number as the multiplication of its prime factors. For the purpose of this task,   1   (unity)   may be shown as itself. Example       2   is prime,   so it would be shown as itself.       6   is not prime;   it would be shown as   2 × 3 {\di...
#Clojure
Clojure
(ns listfactors (:gen-class))   (defn factors "Return a list of factors of N." ([n] (factors n 2 ())) ([n k acc] (cond (= n 1) (if (empty? acc) [n] (sort acc)) (>= k n) (if (empty? acc) [n] (sort (cons n acc))) (= 0 (rem n...
http://rosettacode.org/wiki/Create_an_HTML_table
Create an HTML table
Create an HTML table. The table body should have at least three rows of three columns. Each of these three columns should be labelled "X", "Y", and "Z". An extra column should be added at either the extreme left or the extreme right of the table that has no heading, but is filled with sequential row numbers. The...
#COBOL
COBOL
  IDENTIFICATION DIVISION. PROGRAM-ID. Table. AUTHOR. Bill Gunshannon. INSTALLATION. Home. DATE-WRITTEN. 1 January 2022. ************************************************************ ** Program Abstract: ** Data values are hardcoded in this example but they ...
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#Perl
Perl
use POSIX;   print strftime('%Y-%m-%d', 0, 0, 0, 10, 10, 107), "\n"; print strftime('%A, %B %d, %Y', 0, 0, 0, 10, 10, 107), "\n";
http://rosettacode.org/wiki/Date_format
Date format
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Task Display the   current date   in the formats of:   2007-11-23     and   Friday, November 23, 2007
#Phix
Phix
with javascript_semantics include builtins\timedate.e ?format_timedate(date(),"YYYY-MM-DD") ?format_timedate(date(),"Dddd, Mmmm d, YYYY")
http://rosettacode.org/wiki/Cramer%27s_rule
Cramer's rule
linear algebra Cramer's rule system of linear equations Given { a 1 x + b 1 y + c 1 z = d 1 a 2 x + b 2 y + c 2 z = d 2 a 3 x + b 3 y + c 3 z = d 3 {\displaystyle \left\{{\begin{matrix}a_{1}x+b_{1}y+c_{1}z&={\color {red}d_{1...
#Lua
Lua
local matrix = require "matrix" -- https://github.com/davidm/lua-matrix   local function cramer(mat, vec) -- Check if matrix is quadratic assert(#mat == #mat[1], "Matrix is not square!") -- Check if vector has the same size of the matrix assert(#mat == #vec, "Vector has not the same size of the matrix!")   lo...
http://rosettacode.org/wiki/Create_a_file
Create a file
In this task, the job is to create a new empty file called "output.txt" of size 0 bytes and an empty directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#Emacs_Lisp
Emacs Lisp
(make-empty-file "output.txt") (make-directory "docs") (make-empty-file "/output.txt") (make-directory "/docs")
http://rosettacode.org/wiki/Create_a_file
Create a file
In this task, the job is to create a new empty file called "output.txt" of size 0 bytes and an empty directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#Erlang
Erlang
  -module(new_file). -export([main/0]).   main() -> ok = file:write_file( "output.txt", <<>> ), ok = file:make_dir( "docs" ), ok = file:write_file( filename:join(["/", "output.txt"]), <<>> ), ok = file:make_dir( filename:join(["/", "docs"]) ).  
http://rosettacode.org/wiki/CSV_to_HTML_translation
CSV to HTML translation
Consider a simplified CSV format where all rows are separated by a newline and all columns are separated by commas. No commas are allowed as field data, but the data may contain other characters and character sequences that would normally be   escaped   when converted to HTML Task Create a function that takes a st...
#Factor
Factor
USING: csv html.streams prettyprint xml.writer ;   "Character,Speech The multitude,The messiah! Show us the messiah! Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> The multitude,Who are you? Brians mother,I'm his mother; that's who! The multitude,Behold his...
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#Nanoquery
Nanoquery
def sum(record) sum = 0   for i in range(1, len(record) - 1) sum = sum + int(record ~ i) end for   return sum end def   open "file.csv" add "SUM"   for i in range($dbsize, 1) (i ~ @"SUM") = sum(#i) end for   write
http://rosettacode.org/wiki/CSV_data_manipulation
CSV data manipulation
CSV spreadsheet files are suitable for storing tabular data in a relatively portable way. The CSV format is flexible but somewhat ill-defined. For present purposes, authors may assume that the data fields contain no commas, backslashes, or quotation marks. Task Read a CSV file, change some values and save the cha...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols   import org.apache.commons.csv.   -- ============================================================================= class RCsv public final   properties private constant NL = String System.getProperty("line.separator") COL_NAME_SUM = Stri...
http://rosettacode.org/wiki/Day_of_the_week
Day of the week
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January). Task In what years between 2008 and 2121 will the 25th of ...
#Pike
Pike
filter(Calendar.Year(2008)->range(Calendar.Year(2121))->years()->month(12)->day(25), lambda(object day){ return day->week_day()==7; })->year()->format_nice();