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/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...
#Perl
Perl
sub countSubstring { my $str = shift; my $sub = quotemeta(shift); my $count = () = $str =~ /$sub/g; return $count; # or return scalar( () = $str =~ /$sub/g ); }   print countSubstring("the three truths","th"), "\n"; # prints "3" print countSubstring("ababababab","abab"), "\n"; # prints "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...
#Phix
Phix
sequence tests = {{"the three truths","th"}, {"ababababab","abab"}, {"ababababab","aba"}, {"ababababab","ab"}, {"ababababab","a"}, {"ababababab",""}} integer start, count string test, substring for i=1 to length(tests) do star...
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...
#PL.2FM
PL/M
100H: /* PRINT INTEGERS IN OCTAL */ BDOS: PROCEDURE( FN, ARG ); /* CP/M BDOS SYSTEM CALL */ DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END BDOS; PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END; PR$NL: PROCEDURE; CALL PR$CHAR( 0DH ); CALL PR$CHAR( 0AH ); END; PR$OCTAL: PROCEDURE...
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...
#Perl
Perl
use ntheory qw/factor/; print "$_ = ", join(" x ", factor($_)), "\n" for 1000000000000000000 .. 1000000000000000010;
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...
#Phix
Phix
with javascript_semantics procedure factorise(integer n) sequence res = prime_factors(n,true) res = join(apply(res,sprint)," x ") printf(1,"%2d: %s\n",{n,res}) end procedure papply(tagset(10)&{2144,1000000000},factorise)
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...
#MATLAB_.2F_Octave
MATLAB / Octave
function htmltable(fid,table,Label) fprintf(fid,'<table>\n <thead align = "right">\n'); if nargin<3, fprintf(fid,' <tr><th></th><td>X</td><td>Y</td><td>Z</td></tr>\n </thead>\n <tbody align = "right">\n'); else fprintf(fid,' <tr><th></th>'); fprintf(fid,'<td>%s</td>',Label{:}); ...
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.
#PL.2FI
PL/I
  open file (output) title ('/OUTPUT.TXT,type(text),recsize(100)' ); close file (output);  
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.
#PowerShell
PowerShell
New-Item output.txt -ItemType File New-Item \output.txt -ItemType File New-Item docs -ItemType Directory New-Item \docs -ItemType Directory
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...
#Perl
Perl
use HTML::Entities;   sub row { my $elem = shift; my @cells = map {"<$elem>$_</$elem>"} split ',', shift; print '<tr>', @cells, "</tr>\n"; }   my ($first, @rest) = map {my $x = $_; chomp $x; encode_entities $x} <STDIN>; print "<table>\n"; row @ARGV ? 'th' : 'td', $first; row 'td', $_ foreach @rest; ...
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 ...
#Scheme
Scheme
  (import (scheme base) (scheme read) (scheme write))   ;; Read x/y from user (define x (begin (display "X: ") (flush-output-port) (read))) (define y (begin (display "Y: ") (flush-output-port) (read)))   ;; Create a vector, and fill it with a vector for each row (define arr (make-vector x)) (do ((i 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...
#Raku
Raku
sub sd (@a) { my $mean = @a R/ [+] @a; sqrt @a R/ [+] map (* - $mean)**2, @a; }   sub sdaccum { my @a; return { push @a, $^x; sd @a; }; }   my &f = sdaccum; say f $_ for 2, 4, 4, 4, 5, 5, 7, 9;
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...
#Scheme
Scheme
(define ways-to-make-change (lambda (x coins) (cond [(null? coins) 0] [(< x 0) 0] [(zero? x) 1] [else (+ (ways-to-make-change x (cdr coins)) (ways-to-make-change (- x (car coins)) coins))])))   (ways-to-make-change 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...
#PHP
PHP
<?php echo substr_count("the three truths", "th"), PHP_EOL; // prints "3" echo substr_count("ababababab", "abab"), PHP_EOL; // prints "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...
#Picat
Picat
count_substrings_rec(S, SB) = C => count_rec(S,SB,0,C).   count_rec([],_SB,Count,Count). count_rec(SBRest,SB,Count0,Count) :- SBRest = SB ++ Rest, % "split" into substring and the rest of the string count_rec(Rest,SB,Count0+1,Count). count_rec([T|Rest],SB,Count0,Count) :- T != SB, % this character is not a s...
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...
#PowerShell
PowerShell
[int64]$i = 0 While ( $True ) { [Convert]::ToString( ++$i, 8 ) }
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...
#Prolog
Prolog
o(O) :- member(O, [0,1,2,3,4,5,6,7]).   octal([O]) :- o(O). octal([A|B]) :- octal(O), o(T), append(O, [T], [A|B]), dif(A, 0).   octalize :- forall( octal(X), (maplist(write, X), nl) ).
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...
#PicoLisp
PicoLisp
(de factor (N) (make (let (D 2 L (1 2 2 . (4 2 4 2 4 6 2 6 .)) M (sqrt N)) (while (>= M D) (if (=0 (% N D)) (setq M (sqrt (setq N (/ N (link D))))) (inc 'D (pop 'L)) ) ) (link N) ) ) )   (for N 20 (prinl N ": " (glue " * " (factor N))) )
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...
#PL.2FI
PL/I
  cnt: procedure options (main); declare (i, k, n) fixed binary; declare first bit (1) aligned;   do n = 1 to 40; put skip list (n || ' ='); k = n; first = '1'b; repeat: do i = 2 to k-1; if mod(k, i) = 0 then do; k = k/i; if ^first then put edit (' x ')(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...
#Modula-2
Modula-2
MODULE testCGI;   FROM InOut IMPORT WriteCard, WriteLn, WriteString, WriteBf; FROM Arguments IMPORT ArgTable, GetEnv; FROM Strings IMPORT Assign, Length, String;   VAR EnvVars : ArgTable;   PROCEDURE ReadEnvVar;   VAR Value : String; i : CARDINAL;   BEGIN ...
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.
#ProDOS
ProDOS
makedirectory docs changedirectory docs makenewfile output.txt
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.
#PureBasic
PureBasic
CreateFile(0,"output.txt"):CloseFile(0) CreateDirectory("docs") CreateFile(0,"/output.txt"):CloseFile(0) CreateDirectory("/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...
#Phix
Phix
with javascript_semantics constant input = """ 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 moth...
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 ...
#Seed7
Seed7
$ include "seed7_05.s7i";   const proc: main is func local var integer: numRows is 0; var integer: numCols is 0; var array array integer: anArray is 0 times 0 times 0; begin write("Give me the numer of rows: "); readln(numRows); write("Give me the numer of columns: "); readln(numCols); ...
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 ...
#Sidef
Sidef
func make_matrix(x, y) { y.of { x.of(0) }; }   var y = Sys.scanln("rows: ").to_i; var x = Sys.scanln("cols: ").to_i;   var matrix = make_matrix(x, y); # create the matrix matrix[y/2][x/2] = 1; # write something inside it say matrix; # display the matrix
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...
#REXX
REXX
/*REXX program calculates and displays the standard deviation of a given set of numbers.*/ parse arg # /*obtain optional arguments from the CL*/ if #='' then #= 2 4 4 4 5 5 7 9 /*None specified? Then use the default*/ n= words(#); $= 0; $$= 0; L= length(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...
#Scilab
Scilab
amount=100; coins=[25 10 5 1]; n_coins=zeros(coins); ways=0;   for a=0:4 for b=0:10 for c=0:20 for d=0:100 n_coins=[a b c d]; change=sum(n_coins.*coins); if change==amount then ways=ways+1; elseif change>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...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "bigint.s7i";   const func bigInteger: changeCount (in integer: amountCents, in array integer: coins) is func result var bigInteger: waysToChange is 0_; local var array bigInteger: t is 0 times 0_; var integer: pos is 0; var integer: s is 0; var integer: i is ...
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...
#PicoLisp
PicoLisp
(de countSubstring (Str Sub) (let (Cnt 0 H (chop Sub)) (for (S (chop Str) S (cdr S)) (when (head H S) (inc 'Cnt) (setq S (map prog2 H S)) ) ) Cnt ) )
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...
#Pike
Pike
  write("%d %d\n", String.count("the three truths", "th"), String.count("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...
#PureBasic
PureBasic
Procedure.s octal(n.q) Static Dim digits(20) Protected i, j, result.s For i = 0 To 20 digits(i) = n % 8 n / 8 If n < 1 For j = i To 0 Step -1 result + Str(digits(j)) Next Break EndIf Next   ProcedureReturn result EndProcedure   Define n.q If OpenConsole() While ...
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...
#Python
Python
import sys for n in xrange(sys.maxint): print oct(n)
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...
#PowerShell
PowerShell
  function eratosthenes ($n) { if($n -ge 1){ $prime = @(1..($n+1) | foreach{$true}) $prime[1] = $false $m = [Math]::Floor([Math]::Sqrt($n)) for($i = 2; $i -le $m; $i++) { if($prime[$i]) { for($j = $i*$i; $j -le $n; $j += $i) { $prime[$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...
#Nanoquery
Nanoquery
import Nanoquery.Util   random = new(Random)   println "<table>"   // generate header println "<tr><th></th><th>X</th><th>Y</th><th>Z</th></tr>"   // generate five rows for i in range(1, 5) println "<tr><td style=\"font-weight: bold;\">" + i + "</td>" println "<td>" + int($random.getInt(8999) + 1000) + "</td>" print...
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.
#Python
Python
import os for directory in ['/', './']: open(directory + 'output.txt', 'w').close() # create /output.txt, then ./output.txt os.mkdir(directory + 'docs') # create directory /docs, then ./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.
#R
R
f <- file("output.txt", "w") close(f)   # it may fails and the exact syntax to achieve the root # changes according to the operating system f <- file("/output.txt", "w") close(f)   success <- dir.create("docs") success <- dir.create("/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...
#PHP
PHP
  <?php $csv = <<<EOT 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 mother! Behold his mother! EO...
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 ...
#Simula
Simula
BEGIN INTEGER N,M; M := ININT; N := ININT; BEGIN INTEGER ARRAY A(1:M,1:N); A(M,N) := 99; OUTINT(A(M,N),0); OUTIMAGE; END;  ! ARRAY A OUT OF SCOPE ; 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 ...
#Smalltalk
Smalltalk
  m := (FillInTheBlankMorph request: 'Number of rows?') asNumber. n := (FillInTheBlankMorph request: 'Number of columns?') asNumber. aMatrix := Matrix rows: m columns: n. aMatrix at: (aMatrix rowCount // 2) at: (aMatrix columnCount // 2) put: 3.4. e := aMatrix at: (aMatrix rowCount // 2) at: (aMatrix columnCo...
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...
#Ring
Ring
  # Project : Cumulative standard deviation   decimals(6) sdsave = list(100) sd = "2,4,4,4,5,5,7,9" sumval = 0 sumsqs = 0   for num = 1 to 8 sd = substr(sd, ",", "") stddata = number(sd[num]) sumval = sumval + stddata sumsqs = sumsqs + pow(stddata,2) standdev = pow(((sumsqs / num) - pow((sumv...
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...
#Sidef
Sidef
func cc(_) { 0 } func cc({ .is_neg }, *_) { 0 } func cc({ .is_zero }, *_) { 1 }   func cc(amount, first, *rest) is cached { cc(amount, rest...) + cc(amount - first, first, rest...); }   func cc_optimized(amount, *rest) { cc(amount, rest.sort_by{|v| -v }...); }   var x = cc_optimized(100, 1, 5, 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...
#PL.2FI
PL/I
cnt: procedure options (main); declare (i, tally) fixed binary; declare (text, key) character (100) varying;   get edit (text) (L); put skip data (text); get edit (key) (L); put skip data (key);   tally = 0; i = 1; do until (i = 0); i = index(text, key, i); if i > 0 then do; tally = tally...
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...
#Quackery
Quackery
8 base put 0 [ dup echo cr 1+ again ]
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...
#Racket
Racket
  #lang racket (for ([i (in-naturals)]) (displayln (number->string i 8)))  
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...
#Raku
Raku
say .base(8) for ^Inf;
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...
#PureBasic
PureBasic
Procedure Factorize(Number, List Factors()) Protected I = 3, Max ClearList(Factors()) While Number % 2 = 0 AddElement(Factors()) Factors() = 2 Number / 2 Wend Max = Number While I <= Max And Number > 1 While Number % I = 0 AddElement(Factors()) Factors() = I Number / I ...
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...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   -- create some test data. Put the data in a Rexx indexed string maxI = 1000 rng = Random() xyz = '' xyz[0] = 1; xyz[1] = '. X Y Z' -- use a dot to indicate an empty cell loop r_ = 1 for 5 ra = r_ rng.nextInt(maxI) rng.nextInt(maxI) rng.ne...
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.
#Racket
Racket
#lang racket   (display-to-file "" "output.txt") (make-directory "docs") (display-to-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.
#Raku
Raku
  for '.', '' -> $prefix { mkdir "$prefix/docs"; open "$prefix/output.txt", :w; }  
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...
#PicoLisp
PicoLisp
(load "@lib/http.l")   (in "text.csv" (<table> 'myStyle NIL NIL (prinl) (while (split (line) ",") (<row> NIL (ht:Prin (pack (car @))) (ht:Prin (pack (cadr @)))) (prinl) ) ) )
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 ...
#SNOBOL4
SNOBOL4
* # Get user X,Y dimensions output = 'Enter X,Y:'; xy = trim(input) xy break(',') . x ',' rem . y   * # Define and create array, 1-based arr = array(x ',' y) ;* Or arr = array(xy)   * # Display array prototype output = 'Prototype: ' prototype(arr)   * # Assign ele...
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 ...
#Standard_ML
Standard ML
val nbr1 = valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn); val nbr2 = valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn); val array = Array2.array (nbr1, nbr2, 0.0); Array2.update (array, 0, 0, 3.5); print (Real.toString (Array2.sub (array, 0, 0)) ^ "\n");
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...
#Ruby
Ruby
class StdDevAccumulator def initialize @n, @sum, @sumofsquares = 0, 0.0, 0.0 end   def <<(num) # return self to make this possible: sd << 1 << 2 << 3 # => 0.816496580927726 @n += 1 @sum += num @sumofsquares += num**2 self end   def stddev Math.sqrt( (@sumofsquares / @n) - (@sum / ...
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...
#Swift
Swift
import BigInt   func countCoins(amountCents cents: Int, coins: [Int]) -> BigInt { let cycle = coins.filter({ $0 <= cents }).map({ $0 + 1 }).max()! * coins.count var table = [BigInt](repeating: 0, count: cycle)   for x in 0..<coins.count { table[x] = 1 }   var pos = coins.count   for s in 1..<cents+1 { ...
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...
#Tailspin
Tailspin
  templates makeChange&{coins:} def paid: $; @: [1..$paid -> 0]; $coins... -> \(def coin: $; @makeChange($coin): $@makeChange($coin) + 1; $coin+1..$paid -> @makeChange($): $@makeChange($) + $@makeChange($-$coin); \) -> !VOID $@($paid)! end makeChange   100 -> makeChange&{coins: [1,5,10,25]} -> '$; way...
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...
#PL.2FM
PL/M
100H: /* CP/M CALLS */ BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS; EXIT: PROCEDURE; CALL BDOS(0, 0); END EXIT; PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9, S); END PRINT;   /* PRINT A NUMBER */ PRINT$NUMBER: PROCEDURE (N); DECLARE S (8) BYTE INITIAL ('.....',13,10,'$'); ...
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...
#PowerBASIC
PowerBASIC
FUNCTION PBMAIN () AS LONG PRINT "the three truths, th:", TALLY("the three truths", "th") PRINT "ababababab, abab:", TALLY("ababababab", "abab") END FUNCTION
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...
#REXX
REXX
/*REXX program counts in octal until the number exceeds the number of program statements*/   /*┌────────────────────────────────────────────────────────────────────┐ │ Count all the protons (and electrons!) in the universe. │ │ ...
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...
#Ring
Ring
  size = 30 for n = 1 to size see octal(n) + nl next   func octal m output = "" w = m while fabs(w) > 0 oct = w & 7 w = floor(w / 8) output = string(oct) + output end return output  
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...
#Python
Python
from functools import lru_cache   primes = [2, 3, 5, 7, 11, 13, 17] # Will be extended   @lru_cache(maxsize=2000) def pfactor(n): if n == 1: return [1] n2 = n // 2 + 1 for p in primes: if p <= n2: d, m = divmod(n, p) if m == 0: if d > 1: ...
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...
#NewLISP
NewLISP
; file: html-table.lsp ; url: http://rosettacode.org/wiki/Create_an_HTML_table ; author: oofoe 2012-01-29   (seed (time-of-day)) ; Initialize random number generator.   ; The "tab" variable tracks the HTML indent. "pad" composes a line ; with the appropriate indent and a terminal newline.   (setq tab 0) (define (p...
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.
#Raven
Raven
"" as str str 'output.txt' write str '/output.txt' write 'docs' mkdir '/docs' mkdir
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.
#REBOL
REBOL
; Creating in current directory:   write %output.txt "" make-dir %docs/   ; Creating in root directory:   write %/output.txt "" 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...
#PowerShell
PowerShell
  Import-Csv -Path .\csv_html_test.csv | ConvertTo-Html -Fragment | Out-File .\csv_html_test.html  
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 ...
#Stata
Stata
display "Number of rows?" _request(nr) display "Number of columns?" _request(nc) matrix define a=J($nr,$nc,0) matrix a[1,2]=1.5 matrix list a matrix drop a
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 ...
#Swift
Swift
import Foundation   print("Enter the dimensions of the array seperated by a space (width height): ")   let fileHandle = NSFileHandle.fileHandleWithStandardInput() let dims = NSString(data: fileHandle.availableData, encoding: NSUTF8StringEncoding)?.componentsSeparatedByString(" ")   if let dims = dims where dims.count =...
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...
#Run_BASIC
Run BASIC
dim sdSave$(100) 'can call up to 100 versions 'holds (space-separated) number of data , sum of values and sum of squares sd$ = "2,4,4,4,5,5,7,9"   for num = 1 to 8 stdData = val(word$(sd$,num,",")) sumVal = sumVal + stdData sumSqs = sumSqs + stdData^2   ' standard deviation = square root of (th...
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...
#Tcl
Tcl
package require Tcl 8.5   proc makeChange {amount coins} { set table [lrepeat [expr {$amount+1}] [lrepeat [llength $coins] {}]] lset table 0 [lrepeat [llength $coins] 1] for {set i 1} {$i <= $amount} {incr i} { for {set j 0} {$j < [llength $coins]} {incr j} { set k [expr {$i - [lindex $coins $j]}] ...
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...
#PowerShell
PowerShell
  [regex]::Matches("the three truths", "th").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...
#Prolog
Prolog
    count_substring(String, Sub, Total) :- count_substring(String, Sub, 0, Total).   count_substring(String, Sub, Count, Total) :- ( substring_rest(String, Sub, Rest) -> succ(Count, NextCount), count_substring(Rest, Sub, NextCount, Total) ; Total = Count ).   substring_rest(S...
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...
#Ruby
Ruby
n = 0 loop do puts "%o" % n n += 1 end   # or for n in 0..Float::INFINITY puts n.to_s(8) end   # or 0.upto(1/0.0) do |n| printf "%o\n", n end   # version 2.1 later 0.step do |n| puts format("%o", n) end
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...
#Run_BASIC
Run BASIC
input "Begin number:";b input " End number:";e   for i = b to e print i;" ";toBase$(8,i) next i end   function toBase$(base,base10) for i = 10 to 1 step -1 toBase$ = str$(base10 mod base) +toBase$ base10 = int(base10 / base) if base10 < 1 then exit for next i end function
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...
#Quackery
Quackery
[ [] swap dup times [ [ dup i^ 2 + /mod 0 = while nip dip [ i^ 2 + join ] again ] drop dup 1 = if conclude ] drop ] is primefactors ( n --> [ )   [ 1 dup echo cr [ 1+ dup primefactors witheach [ echo i if...
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...
#R
R
  #initially I created a function which returns prime factors then I have created another function counts in the factors and #prints the values.   findfactors <- function(num) { x <- c() p1<- 2 p2 <- 3 everyprime <- num while( everyprime != 1 ) { while( everyprime%%p1 == 0 ) { x <- c(x, p1) e...
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...
#Nim
Nim
import random, htmlgen randomize()   template randTD(): string = td($rand(1000..9999)) proc randTR(x: int): string = tr(td($x, style="font-weight: bold"), randTD, randTD, randTD)   echo table( tr(th"", th"X", th"Y", th"Z"), randTR 1, randTR 2, randTR 3, randTR 4, randTR 5)
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.
#Retro
Retro
  'output.txt file:W file:open file:close '/output.txt file:W file:open file: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.
#REXX
REXX
/*REXX pgm creates a new empty file and directory; in curr dir and root.*/ do 2 /*perform three statements twice.*/ 'COPY NUL output.txt' /*copy a "null" (empty) file. */ 'MKDIR DOCS' /*make a directory (aka: folder).*/ 'CD \' ...
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...
#Prolog
Prolog
csv_html :- L = "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 mother! Behold his mother!",   c...
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 ...
#Tcl
Tcl
  puts "Enter width:" set width [gets stdin] puts "Enter height:" set height [gets stdin] # Initialize array for {set i 0} {$i < $width} {incr i} { for {set j 0} {$j < $height} {incr j} { set arr($i,$j) "" } } # Store value set arr(0,0) "abc" # Print value puts "Element (0/0): $arr(0,0)" # Cleanup array unset arr  
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 ...
#Toka
Toka
[ ( x y -- address ) cells malloc >r dup cells >r [ r> r> r> 2dup >r >r swap malloc swap i swap array.put >r ] iterate r> r> nip ] is 2D-array   [ ( a b address -- value ) array.get array.get ] is 2D-get-element   [ ( value a b address -- ) array.get array.put ] is 2D-put-element
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...
#Rust
Rust
pub struct CumulativeStandardDeviation { n: f64, sum: f64, sum_sq: f64 }   impl CumulativeStandardDeviation { pub fn new() -> Self { CumulativeStandardDeviation { n: 0., sum: 0., sum_sq: 0. } }   fn push(&mut self, x: f64) -> f64 { self...
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...
#uBasic.2F4tH
uBasic/4tH
c = 0 for p = 0 to 100 for n = 0 to 20 for d = 0 to 10 for q = 0 to 4 if p + n * 5 + d * 10 + q * 25 = 100 then print p;" pennies ";n;" nickels "; d;" dimes ";q;" quarters" c = c + 1 endif next q next d next n next p print c;" ways to make a buck"
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...
#UNIX_Shell
UNIX Shell
function count_change { local -i amount=$1 coin j local ways=(1) shift for coin; do for (( j=coin; j <= amount; j++ )); do let ways[j]=${ways[j]:-0}+${ways[j-coin]:-0} done done echo "${ways[amount]}" } count_change 100 25 10 5 1 count_change 100000 100 50 25 10 5 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...
#PureBasic
PureBasic
a = CountString("the three truths","th") b = CountString("ababababab","abab") ; a = 3 ; b = 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...
#Python
Python
>>> "the three truths".count("th") 3 >>> "ababababab".count("abab") 2
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...
#Rust
Rust
fn main() { for i in 0..std::usize::MAX { println!("{:o}", i); } }
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...
#Salmon
Salmon
iterate (i; [0...+oo]) printf("%o%\n", i);;
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...
#S-BASIC
S-BASIC
  rem - return p mod q function mod(p, q = integer) = integer end = p - q * (p / q)   rem - return octal representation of n function oct$(n = integer) = string var s = string s = "" while n > 0 do begin s = chr(mod(n,8) + '0') + s n = n / 8 end end = s   rem - count in octal until overflow var i = intege...
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...
#Racket
Racket
#lang typed/racket   (require math/number-theory)   (define (factorise-as-primes [n : Natural]) (if (= n 1) '(1) (let ((F (factorize n))) (append* (for/list : (Listof (Listof Natural)) ((f (in-list F))) (make-list (second f) (first f)))))))   (define (factor-count [start-inc : Natu...
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...
#Raku
Raku
constant @primes = 2, |(3, 5, 7 ... *).grep: *.is-prime;   multi factors(1) { 1 } multi factors(Int $remainder is copy) { gather for @primes -> $factor {   # if remainder < factor², we're done if $factor * $factor > $remainder { take $remainder if $remainder > 1; last; }   # How many times...
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...
#Objeck
Objeck
  class CreateTable { function : Main(args : String[]) ~ Nil { s := String->New();   s->Append("<table>"); s->Append("<thead align = \"right\">"); s->Append("<tr><th></th>"); td := "XYZ"; for(i:=0; i<3; i+=1;) { s->Append("<td>"); s->Append(td->Get(i)); s->Append("</td>"); ...
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.
#Ring
Ring
  system("mkdir C:\Ring\docs") fopen("C:\Ring\docs\output.txt", "w+") system("mkdir docs") fopen("output.txt", "w+")  
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.
#Ruby
Ruby
['/', './'].each{|dir| Dir.mkdir(dir + 'docs') # create '/docs', then './docs' File.open(dir + 'output.txt', 'w') {} # create empty file /output.txt, then ./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...
#Python
Python
csvtxt = '''\ 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 mother! Behold his mother!\ '''   fro...
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 ...
#Ursa
Ursa
decl int width height out "width: " console set width (in int console) out "height: " console set height (in int console)   decl int<><> twodstream for (decl int i) (< i height) (inc i) append (new int<>) twodstream end for for (set i 0) (< i height) (inc i) decl int j for (set j 0) (< j width)...
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 ...
#VBA
VBA
  Option Explicit   Sub Main_Create_Array() Dim NbColumns As Integer, NbRows As Integer   'Get two integers from the user, Do NbColumns = Application.InputBox("Enter number of columns : ", "Numeric only", 3, Type:=1) NbRows = Application.InputBox("Enter number of rows : ", "Numeric only", 5, Typ...
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...
#SAS
SAS
  *--Load the test data; data test1; input x @@; obs=_n_; datalines; 2 4 4 4 5 5 7 9 ; run;   *--Create a dataset with the cummulative data for each set of data for which the SD should be calculated; data test2 (drop=i obs); set test1; y=x; do i=1 to n; set test1 (rename=(obs=setid)) nobs=n point=i...
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...
#VBA
VBA
Private Function coin_count(coins As Variant, amount As Long) As Variant 'return type will be Decimal 'sequence s = Repeat(0, amount + 1) Dim s As Variant ReDim s(amount + 1) Dim c As Integer s(1) = CDec(1) For c = 1 To UBound(coins) For n = coins(c) To amount s(n + 1) = CDec...
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...
#VBScript
VBScript
  Function count(coins,m,n) ReDim table(n+1) table(0) = 1 i = 0 Do While i < m j = coins(i) Do While j <= n table(j) = table(j) + table(j - coins(i)) j = j + 1 Loop i = i + 1 Loop count = table(n) End Function   'testing arr = Array(1,5,10,25) m = UBound(arr) + 1 n = 100 WScript.StdOut.WriteLine cou...
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...
#Quackery
Quackery
[ [] 95 times [ i^ space + join ] ] constant is alphabet ( --> $ )   [ [ 2dup != while -1 split drop swap 1 split unrot drop again ] drop size ] is overlap ( [ [ --> n )   [ temp put [] swap alphabet witheach [ over...
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...
#R
R
count = function(haystack, needle) {v = attr(gregexpr(needle, haystack, fixed = T)[[1]], "match.length") if (identical(v, -1L)) 0 else length(v)}   print(count("hello", "l"))