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.
#LFE
LFE
  (: file write_file '"output.txt" '"Some data") (: file make_dir '"docs") (: file write_file '"/output.txt" '"Some data") (: file make_dir '"/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...
#Kotlin
Kotlin
// version 1.1.3   val csv = "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...
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...
#Racket
Racket
#lang racket (require (planet neil/csv:1:=7) net/url)   (define make-reader (make-csv-reader-maker '((separator-chars #\,) (strip-leading-whitespace? . #t) (strip-trailing-whitespace? . #t))))   (define (all-rows port) (define read-row (make-reader port)) (define head (append (read-row)...
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...
#Raku
Raku
my $csvfile = './whatever.csv'; my $fh = open($csvfile, :r); my @header = $fh.get.split(','); my @csv = map {[.split(',')]>>.Num}, $fh.lines; close $fh;   my $out = open($csvfile, :w); $out.say((@header,'SUM').join(',')); $out.say((@$_, [+] @$_).join(',')) for @csv; close $out;
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 ...
#Standard_ML
Standard ML
(* Call: yearsOfSundayXmas(2008, 2121) *) fun yearsOfSundayXmas(fromYear, toYear) = if fromYear>toYear then () else let val d = Date.date {year=fromYear, month=Date.Dec, day=25, hour=0, minute=0, second=0, offset=SOME Time.zeroTime} val wd = Date.weekDay d...
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 ...
#Stata
Stata
clear sca n=2121-2008+1 set obs `=n' gen year=2007+_n list if dow(mdy(12,25,year))==0, noobs sep(0)   +------+ | year | |------| | 2011 | | 2016 | | 2022 | | 2033 | | 2039 | | 2044 | | 2050 | | 2061 | | 2067 | | 2072 | | 2078 | | 2089 | | 2095 | | 2101 | | 2107 | | 2112 | | 2118 ...
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 ...
#Nim
Nim
import strutils, rdstdin   let w = readLineFromStdin("Width: ").parseInt() h = readLineFromStdin("Height: ").parseInt()   # Create the rows. var s = newSeq[seq[int]](h)   # Create the columns. for i in 0 ..< h: s[i].newSeq(w)   # Store a value in an element. s[0][0] = 5   # Retrieve and print it. echo s[0][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 ...
#Objeck
Objeck
  use IO;   bundle Default { class TwoDee { function : Main(args : System.String[]) ~ Nil { DoIt(); }   function : native : DoIt() ~ Nil { Console->GetInstance()->Print("Enter x: "); x := Console->GetInstance()->ReadString()->ToInt();   Console->GetInstance()->Print("Enter y: "); ...
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...
#Objective-C
Objective-C
#import <Foundation/Foundation.h>   @interface SDAccum : NSObject { double sum, sum2; unsigned int num; } -(double)value: (double)v; -(unsigned int)count; -(double)mean; -(double)variance; -(double)stddev; @end   @implementation SDAccum -(double)value: (double)v { sum += v; sum2 += v*v; num++; return [self ...
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...
#Smalltalk
Smalltalk
CRC32Stream hashValueOf:'The quick brown fox jumps over the lazy dog'
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...
#Swift
Swift
import Foundation   let strData = "The quick brown fox jumps over the lazy dog".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) let crc = crc32(uLong(0), UnsafePointer<Bytef>(strData!.bytes), uInt(strData!.length))   println(NSString(format:"%2X", crc))
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...
#Lasso
Lasso
define cointcoins( target::integer, operands::array ) => {   local( targetlength = #target + 1, operandlength = #operands -> size, output = staticarray_join(#targetlength,0), outerloopcount )   #output -> get(1) = 1   loop(#operandlength) => { #outerloopcount = loop_count loop(#targetlength) => {   ...
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...
#Lua
Lua
function countSums (amount, values) local t = {} for i = 1, amount do t[i] = 0 end t[0] = 1 for k, val in pairs(values) do for i = val, amount do t[i] = t[i] + t[i - val] end end return t[amount] end   print(countSums(100, {1, 5, 10, 25})) print(countSums(100000, {1, 5, 10, 25, 50, 100})...
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...
#jq
jq
  def countSubstring(sub): [match(sub; "g")] | length;
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...
#Julia
Julia
matchall(r::Regex, s::String[, overlap::Bool=false]) -> Vector{String} Return a vector of the matching substrings from eachmatch.
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...
#JavaScript
JavaScript
for (var n = 0; n < 1e14; n++) { // arbitrary limit that's not too big document.writeln(n.toString(8)); // not sure what's the best way to output it in JavaScript }
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...
#jq
jq
# generate octals as strings, beginning with "0" def octals: # input and output: array of octal digits in reverse order def octal_add1: [foreach (.[], null) as $d ({carry: 1}; if $d then ($d + .carry ) as $r | if $r > 7 then {carry: 1, emit: ($r - 8)} else {carry: 0, emit: $r } en...
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...
#Julia
Julia
  for i in one(Int64):typemax(Int64) print(oct(i), " ") sleep(0.1) end  
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...
#Groovy
Groovy
def factors(number) { if (number == 1) { return [1] } def factors = [] BigInteger value = number BigInteger possibleFactor = 2 while (possibleFactor <= value) { if (value % possibleFactor == 0) { factors << possibleFactor value /= possibleFactor } ...
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...
#Haskell
Haskell
import Data.List (unfoldr) import Control.Monad (forM_)   import qualified Text.Blaze.Html5 as B import Text.Blaze.Html.Renderer.Pretty (renderHtml)   import System.Random (RandomGen, getStdGen, randomRs, split)   makeTable :: RandomGen g => [String] -> Int -> g -> B.Html makeTable headings nRows gen = B.table $ ...
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
#Standard_ML
Standard ML
print (Date.fmt "%Y-%m-%d" (Date.fromTimeLocal (Time.now ())) ^ "\n"); print (Date.fmt "%A, %B %d, %Y" (Date.fromTimeLocal (Time.now ())) ^ "\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
#Stata
Stata
display %tdCCYY-NN-DD td($S_DATE) display %tdDayname,_Month_dd,_CCYY td($S_DATE)
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.
#Liberty_BASIC
Liberty BASIC
  nomainwin   open "output.txt" for output as #f close #f   result = mkdir( "F:\RC") if result <>0 then notice "Directory not created!": end   open "F:\RC\output.txt" for output as #f close #f   end  
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.
#Lingo
Lingo
-- note: fileIO xtra is shipped with Director, i.e. an "internal" fp = xtra("fileIO").new() fp.createFile("output.txt")
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...
#Lambdatalk
Lambdatalk
  {def CSV Character,Speech\n The multitude,The messiah! Show us the messiah!\n Brians mother,Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!\n The multitude,Who are you\n Brians mother,I'm his mother; that's who!\n The multitude,Behold his mother! Behold his mother!\n } -> CSV   {de...
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...
#Red
Red
>>filein: read/lines %file.csv >>data: copy [] >>foreach item filein [append/only data split item ","] ; [["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"]]
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...
#REXX
REXX
/* REXX *************************************************************** * extend in.csv to add a column containing the sum of the lines' elems * 21.06.2013 Walter Pachl **********************************************************************/ csv='in.csv' Do i=1 By 1 While lines(csv)>0 l=linein(csv) If i=1 Then l...
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 ...
#Suneido
Suneido
year = 2008 while (year <= 2121) { if Date('#' $ year $ '1225').WeekDay() is 0 Print(year) ++year }
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 ...
#Swift
Swift
import Cocoa   var year=2008 let formatter=NSDateFormatter() formatter.dateFormat = "yyyy-MM-dd"   let gregorian:NSCalendar! = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) while (year<2122){ var date:NSDate!=formatter.dateFromString(String(year)+"-12-25") var components=gregorian.components(NSC...
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 ...
#Objective-C
Objective-C
#import <Foundation/Foundation.h>   int main() { @autoreleasepool { int num1, num2; scanf("%d %d", &num1, &num2);   NSLog(@"%d %d", num1, num2);   NSMutableArray *arr = [NSMutableArray arrayWithCapacity: (num1*num2)]; // initialize it with 0s for(int i=0; i < (num1*num2); i++) [arr addObject: ...
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...
#OCaml
OCaml
let sqr x = x *. x   let stddev l = let n, sx, sx2 = List.fold_left (fun (n, sx, sx2) x -> succ n, sx +. x, sx2 +. sqr x) (0, 0., 0.) l in sqrt ((sx2 -. sqr sx /. float n) /. float n)   let _ = let l = [ 2.;4.;4.;4.;5.;5.;7.;9. ] in Printf.printf "List: "; List.iter (Printf.printf "%g ") l;...
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...
#Tcl
Tcl
package require Tcl 8.6   set data "The quick brown fox jumps over the lazy dog" puts [format "%x" [zlib crc32 $data]]
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...
#TXR
TXR
(crc32 "The quick brown fox jumps over the lazy dog")
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...
#M2000_Interpreter
M2000 Interpreter
  Module FindCoins { Function count(c(), n) { dim table(n+1)=0@ : table(0)=1@ for c=0 to len(c())-1 { if c(c)>n then exit } if c else exit for i=0 to c-1 {for j=c(i) to n {table(j)+=table(j-c(i))}} =table(n) } P...
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...
#Maple
Maple
assume(p::posint,abs(x)<1): coin:=unapply(sum(x^(p*n),n=0..infinity),p): ways:=(amount,purse)->coeff(series(mul(coin(k),k in purse),x,amount+1),x,amount):   ways(100,[1,5,10,25]); # 242   ways(1000,[1,5,10,25,50,100]); # 2103596   ways(10000,[1,5,10,25,50,100]); # 139946140451   ways(100000,[1,5,10,25,50,100]); # 13398...
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...
#K
K
"the three truths" _ss "th" 0 4 13   #"the three truths" _ss "th" 3   "ababababab" _ss "abab" 0 4   #"ababababab" _ss "abab" 2  
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...
#Klingphix
Klingphix
include ..\Utilitys.tlhy   :count %s !s 0 >ps [ps> 1 + >ps $s len nip + snip nip] [$s find dup] while drop drop ps> ;   "the three truths" "th" count ? "ababababab" "abab" count ?   " " input
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...
#Klingphix
Klingphix
include ..\Utilitys.tlhy   :octal "" >ps [dup 7 band tostr ps> chain >ps 8 / int] [dup abs 0 >] while ps> tonum bor ;   ( 0 10 ) sequence @octal map pstack   " " input
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...
#Kotlin
Kotlin
// version 1.1   // counts up to 177 octal i.e. 127 decimal fun main(args: Array<String>) { (0..Byte.MAX_VALUE).forEach { println("%03o".format(it)) } }
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...
#LabVIEW
LabVIEW
'%4o '__number_format set 0 do dup 1 compress . "\n" . 1 + loop
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...
#Haskell
Haskell
import Data.List (intercalate)   showFactors n = show n ++ " = " ++ (intercalate " * " . map show . factorize) n -- Pointfree form showFactors = ((++) . show) <*> ((" = " ++) . intercalate " * " . map show . factorize)
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...
#Icon_and_Unicon
Icon and Unicon
procedure main() write("Press ^C to terminate") every f := [i:= 1] | factors(i := seq(2)) do { writes(i," : [") every writes(" ",!f|"]\n") } end   link factors
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...
#Icon_and_Unicon
Icon and Unicon
procedure main() printf("<table>\n <tr><th></th><th>X</th><th>Y</th><th>Z</th>") every r := 1 to 4 do { printf("</tr>\n <tr><td>%d</td>",r) every 1 to 3 do printf("<td>%d</td>",?9999) # random 4 digit numbers per cell } printf("</tr>\n</table>\n") end   link printf
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
#Suneido
Suneido
Date().Format('yyyy-MM-dd') --> "2010-03-16" Date().LongDate() --> "Tuesday, March 16, 2010"
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
#Swift
Swift
import Foundation extension String { func toStandardDateWithDateFormat(format: String) -> String { let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = format dateFormatter.dateStyle = .LongStyle return dateFormatter.stringFromDate(dateFormatter.dateFromString(self)!) ...
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.
#Little
Little
void create_file(string path) { FILE f; unless (exists(path)) { unless (f = fopen(path, "w")){ die(path); } else { puts("file ${path} created"); fclose(f); } } else { puts("File ${path} already exists"); } }   void create_dir(string pat...
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...
#Liberty_BASIC
Liberty BASIC
  newline$ ="|" ' No escape behaviour, so can't refer to '/n'. ' Generally imported csv would have separator CR LF; easily converted first if needed   csv$ ="Character,Speech" +newline$+_ "The multitude,The me...
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...
#Ring
Ring
  # Project : CSV data manipulation   load "stdlib.ring" fnin = "input.csv" fnout = "output.csv" fpin = fopen(fnin,"r") fpout = fopen(fnout,"r") csv = read(fnin) nr = 0 csvstr = ""   while not feof(fpin) sum = 0 nr = nr + 1 line = readline(fpin) if nr = 1 line = substr(line,nl...
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...
#Ruby
Ruby
require 'csv' # read: ar = CSV.table("test.csv").to_a #table method assumes headers and converts numbers if possible.   # manipulate: ar.first << "SUM" ar[1..-1].each{|row| row << row.sum}   # write: CSV.open("out.csv", 'w') do |csv| ar.each{|line| csv << line} end
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 ...
#Tcl
Tcl
package require Tcl 8.5   for {set y 2008} {$y <= 2121} {incr y} { if {[clock format [clock scan "$y-12-25" -format {%Y-%m-%d}] -format %w] == 0} { puts "xmas $y is a sunday" } }
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 ...
#TI-83_BASIC
TI-83 BASIC
  :For(A,2008,2121 :If dayofWk(A,12,25)=1 :Disp A :End  
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 ...
#OCaml
OCaml
let nbr1 = read_int ();; let nbr2 = read_int ();; let array = Array.make_matrix nbr1 nbr2 0.0;; array.(0).(0) <- 3.5;; print_float array.(0).(0); print_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 ...
#ooRexx
ooRexx
Say "enter first dimension" pull d1 say "enter the second dimension" pull d2 a = .array~new(d1, d2) a[1, 1] = "Abc" say a[1, 1] say d1 d2 a[d1,d2] say a[10,10] max=1000000000 b = .array~new(max,max)
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...
#Oforth
Oforth
Channel new [ ] over send drop const: StdValues   : stddev(x) | l | StdValues receive x + dup ->l StdValues send drop #qs l map sum l size asFloat / l avg sq - sqrt ;
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...
#Vala
Vala
using ZLib.Utility;   void main() { var str = (uint8[])"The quick brown fox jumps over the lazy dog".to_utf8(); stdout.printf("%lx\n", crc32(0, str)); }
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...
#VAX_Assembly
VAX Assembly
EDB88320 0000 1 poly: .long ^xedb88320  ;crc32 00000044 0004 2 table: .blkl 16 0044 3 4C 58 21 0000004C'010E0000' 0044 4 fmt: .ascid "!XL"  ;resu...
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...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
CountCoins[amount_, coinlist_] := ( ways = ConstantArray[1, amount]; Do[For[j = coin, j <= amount, j++, If[ j - coin == 0, ways[[j]] ++, ways[[j]] += ways[[j - coin]] ]] , {coin, coinlist}]; ways[[amount]])
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...
#MATLAB_.2F_Octave
MATLAB / Octave
  %% Count_The_Coins clear;close all;clc; tic   for i = 1:2 % 1st loop is main challenge 2nd loop is optional challenge if (i == 1) amount = 100; % Matlab indexes from 1 not 0, so we need to add 1 to our target value amount = amount + 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...
#Kotlin
Kotlin
// version 1.0.6   fun countSubstring(s: String, sub: String): Int = s.split(sub).size - 1   fun main(args: Array<String>) { println(countSubstring("the three truths","th")) println(countSubstring("ababababab","abab")) println(countSubstring("","")) }
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...
#Lambdatalk
Lambdatalk
  {def countSubstring {def countSubstring.r {lambda {:n :i :acc :s} {if {>= :i :n} then :acc else {countSubstring.r :n {+ :i 1} {if {W.equal? {W.get :i :s} ⫖} then {+ :acc 1} else :acc} ...
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...
#Lang5
Lang5
'%4o '__number_format set 0 do dup 1 compress . "\n" . 1 + loop
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...
#langur
langur
val .limit = 70000   for .i = 0; .i <= .limit; .i += 1 { writeln $"10x\.i; == 8x\.i:8x;" }
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...
#LFE
LFE
(: lists foreach (lambda (x) (: io format '"~p~n" (list (: erlang integer_to_list x 8)))) (: lists seq 0 2000))  
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...
#IS-BASIC
IS-BASIC
100 PROGRAM "Factors.bas" 110 FOR I=1 TO 30 120 PRINT I;"= ";FACTORS$(I) 130 NEXT 140 DEF FACTORS$(N) 150 LET F$="" 160 IF N=1 THEN 170 LET FACTORS$="1" 180 ELSE 190 LET P=2 200 DO WHILE P<=N 210 IF MOD(N,P)=0 THEN 220 LET F$=F$&STR$(P)&"*" 230 LET N=INT(N/P) 240 ELSE 250...
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...
#J
J
q:
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...
#J
J
ele=:4 :0 nm=. x-.LF lf=. x-.nm  ;('<',nm,'>') ,L:0 y ,L:0 '</',nm,'>',lf )   hTbl=:4 :0 rows=. 'td' <@ele"1 ":&.>y 'table' ele ('tr',LF) <@ele ('th' ele x); rows )
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
#Tcl
Tcl
set now [clock seconds] puts [clock format $now -format "%Y-%m-%d"] puts [clock format $now -format "%A, %B %d, %Y"]
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
#Terraform
Terraform
locals { today = timestamp() }   output "iso" { value = formatdate("YYYY-MM-DD", local.today) }   output "us-long" { value = formatdate("EEEE, MMMM D, YYYY", local.today) }
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.
#Lua
Lua
io.open("output.txt", "w"):close() io.open("\\output.txt", "w"):close()
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.
#M2000_Interpreter
M2000 Interpreter
  Module MakeDirAndFile { Def WorkingDir$, RootDir$ If Drive$(Dir$)="Drive Fixed" Then WorkingDir$=Dir$ If Drive$("C:\")="Drive Fixed" Then RootDir$="C:\"   if WorkingDir$<>"" Then task(WorkingDir$) If RootDir$<>"" then task(RootDir$) Dir User ' return to user directory   Sub t...
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...
#Lua
Lua
FS = "," -- field separator   csv = [[ 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 m...
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...
#Run_BASIC
Run BASIC
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 "   print csv$ dim csvData$(5,5)   for r = 1 to 5 a$ = word$(csv$,r,chr$(13)) for c = 1 to 5 csvData$(r,c) = word$(a$,c,",") next c next r   [loop] input "Row to change:";r input "Col to change;";c if r > 5 or c > 5 then print "Row ";...
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...
#Rust
Rust
use std::error::Error; use std::num::ParseIntError; use csv::{Reader, Writer};   fn main() -> Result<(), Box<dyn Error>> { let mut reader = Reader::from_path("data.csv")?; let mut writer = Writer::from_path("output.csv")?;   // headers() returns an immutable reference, so clone() before appending let mu...
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 ...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT PRINT "25th of December will be a Sunday in the following years: " LOOP year=2008,2121 SET dayofweek = DATE (number,25,12,year,nummer) IF (dayofweek==7) PRINT year ENDLOOP  
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 ...
#TypeScript
TypeScript
  // Find years with Sunday Christmas var f = 2008; var t = 2121; console.log(`Sunday Christmases ${f} - ${t}`); for (y = f; y <= t; y++) { var x = (y * 365) + Math.floor(y / 4) - Math.floor(y / 100) + Math.floor(y / 400) - 6; if (x % 7 == 0) process.stdout.write(`${y}\t`); } process.stdout.write("\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 ...
#Oz
Oz
declare %% Read width and height from stdin class TextFile from Open.file Open.text end StdIn = {New TextFile init(name:stdin)} Width = {String.toInt {StdIn getS($)}} Height = {String.toInt {StdIn getS($)}} %% create array Arr = {Array.new 1 Width unit} in for X in 1..Width do Arr.X := {Array.new 1...
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 ...
#PARI.2FGP
PARI/GP
tmp(m,n)={ my(M=matrix(m,n,i,j,0)); M[1,1]=1; M[1,1] };
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...
#ooRexx
ooRexx
sdacc = .SDAccum~new x = .array~of(2,4,4,4,5,5,7,9) sd = 0 do i = 1 to x~size sd = sdacc~value(x[i]) Say '#'i 'value =' x[i] 'stdev =' sd end   ::class SDAccum ::method sum attribute ::method sum2 attribute ::method count attribute ::method init self~sum = 0.0 self~sum2 = 0.0 self~count = 0 ::method value ...
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...
#VBScript
VBScript
  dim crctbl(255) const crcc =&hEDB88320   sub gencrctable for i= 0 to 255 k=i for j=1 to 8 if k and 1 then k=(k and &h7fffffff)\2 or (&h40000000 and ((k and &h80000000)<>0)) k=k xor crcc else k=(k and &h7fffffff)\2 or (&h40000000 and ((k and &h80000000)<>0)) end if next ' j ...
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...
#Visual_Basic
Visual Basic
Option Explicit Declare Function RtlComputeCrc32 Lib "ntdll.dll" _ (ByVal dwInitial As Long, pData As Any, ByVal iLen As Long) As Long '-------------------------------------------------------------------- Sub Main() Dim s As String Dim b() As Byte Dim l As Long   s = "The quick brown fox jumps over the lazy dog" ...
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...
#Mercury
Mercury
:- module coins. :- interface. :- import_module int, io. :- type coin ---> quarter; dime; nickel; penny. :- type purse ---> purse(int, int, int, int).   :- pred sum_to(int::in, purse::out) is nondet.   :- pred main(io::di, io::uo) is det. :- implementation. :- import_module solutions, list, string.   :- func value(coin...
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...
#Nim
Nim
proc changes(amount: int, coins: openArray[int]): int = var ways = @[1] ways.setLen(amount+1) for coin in coins: for j in coin..amount: ways[j] += ways[j-coin] ways[amount]   echo changes(100, [1, 5, 10, 25]) echo changes(100000, [1, 5, 10, 25, 50, 100])
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...
#langur
langur
writeln len indices q(th), q(the three truths) writeln len indices q(abab), q(ababababab)
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...
#Lasso
Lasso
define countSubstring(str::string, substr::string)::integer => { local(i = 1, foundpos = -1, found = 0) while(#i < #str->size && #foundpos != 0) => { protect => { handle_error => { #foundpos = 0 } #foundpos = #str->find(#substr, -offset=#i) } if(#foundpos > 0) => { #found += 1 #i = #foundpos + #subs...
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...
#Liberty_BASIC
Liberty BASIC
  'the method used here uses the base-conversion from RC Non-decimal radices/Convert 'to terminate hit <CTRL<BRK>   global alphanum$ alphanum$ ="01234567"   i =0   while 1 print toBase$( 8, i) i =i +1 wend   end   function toBase$( base, number) ' Convert dec...
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...
#Logo
Logo
to increment_octal :n ifelse [empty? :n] [ output 1 ] [ local "last make "last last :n local "butlast make "butlast butlast :n make "last sum :last 1 ifelse [:last < 8] [ output word :butlast :last ] [ output word (increment_octal :butlast) 0 ] ] end   make "oct 0 w...
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...
#Java
Java
public class CountingInFactors{ public static void main(String[] args){ for(int i = 1; i<= 10; i++){ System.out.println(i + " = "+ countInFactors(i)); }   for(int i = 9991; i <= 10000; i++){ System.out.println(i + " = "+ countInFactors(i)); } }   private...
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...
#Java
Java
public class HTML {   public static String array2HTML(Object[][] array){ StringBuilder html = new StringBuilder( "<table>"); for(Object elem:array[0]){ html.append("<th>" + elem.toString() + "</th>"); } for(int i = 1; i < array.length; i++){ Object[] row = array[i]; html.append("<tr>"); for(Obj...
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
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT SET dayofweek = DATE (today,day,month,year,number)   SET months=* DATA January DATA Februari DATA March DATA April DATA Mai DATA June DATA July DATA August DATA September DATA October DATA November DATA December   SET days="Monday'Tuesday'Wendsday'Thursday'Fryday'Saturday'Sonday"   SET nameofday =SE...
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
#UNIX_Shell
UNIX Shell
date +"%Y-%m-%d" date +"%A, %B %d, %Y"
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.
#Maple
Maple
  FileTools:-Text:-WriteFile("output.txt", ""); # make empty file in current dir FileTools:-MakeDirectory("docs"); # make empty dir in current dir FileTools:-Text:-WriteFile("/output.txt", ""); # make empty file in root dir FileTools:-MakeDirectory("/docs"); # make empty dir in root dir  
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.
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
  SetDirectory@NotebookDirectory[]; t = OpenWrite["output.txt"] Close[t] s = OpenWrite[First@FileNameSplit[$InstallationDirectory] <> "\\output.txt"] Close[s]   (*In root directory*) CreateDirectory["\\docs"] (*In current operating directory*) CreateDirectory[Directory[]<>"\\docs"] (*"left<>right" is shorthand for "Str...
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...
#Maple
Maple
#A translation of the C code posted html_table := proc(str) local char; printf("<table>\n<tr><td>"); for char in str do if char = "\n" then printf("</td></tr>\n<tr><td>") elif char = "," then printf("</td><td>") elif char = "<" then printf("&lt;") ...
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...
#SAS
SAS
data _null_; infile datalines dlm="," firstobs=2; file "output.csv" dlm=","; input c1-c5; if _n_=1 then put "C1,C2,C3,C4,C5,Sum"; s=sum(of c1-c5); put c1-c5 s; datalines; 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 ; run;
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...
#Scala
Scala
import scala.io.Source   object parseCSV extends App {   val rawData = """|C1,C2,C3,C4,C5 |1,5,9,13,17 |2,6,10,14,18 |3,7,11,15,19 |20,21,22,23,24""".stripMargin   val data = Seq((Source.fromString(rawData).getLines()).map(_.split(",")).toSeq: _*)   val output = ((data.take(1)....
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 ...
#UNIX_Shell
UNIX Shell
#! /bin/bash   for (( i=2008; i<=2121; ++i )) do date -d "$i-12-25" done |grep Sun   exit 0
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 ...
#Ursala
Ursala
#import std #import nat #import stt   christmases = time_to_string* string_to_time*TS 'Dec 25 0:0:0 '-*@hS %nP* nrange/2008 2121   #show+   sunday_years = ~&zS sep` * =]'Sun'*~ christmases
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 ...
#Pascal
Pascal
program array2d(input, output);   type tArray2d(dim1, dim2: integer) = array[1 .. dim1, 1 .. dim2] of real; pArray2D = ^tArray2D;   var d1, d2: integer; data: pArray2D;   begin { read values } readln(d1, d2);   { create array } new(data, d1, d2);   { write element } data^[1,1] := 3.5;   { output element } w...
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...
#PARI.2FGP
PARI/GP
newpoint(x)={ myT=x; myS=0; myN=1; [myT,myS]/myN }; addpoint(x)={ myT+=x; myN++; myS+=(myN*x-myT)^2/myN/(myN-1); [myT,myS]/myN }; addpoints(v)={ print(newpoint(v[1])); for(i=2,#v,print(addpoint(v[i]))); print("Mean: ",myT/myN); print("Standard deviation: ",sqrt(myS/myN)) }; addpoints([2,4,4,4,5,...
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...
#Visual_Basic_.NET
Visual Basic .NET
Public Class Crc32   ' Table for pre-calculated values. Shared table(255) As UInteger   ' Initialize table Shared Sub New() For i As UInteger = 0 To table.Length - 1 Dim te As UInteger = i ' table entry For j As Integer = 0 To 7 If (te And 1) = 1 Then te =...