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_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... | #Scala | Scala | Stream from 0 foreach (i => println(i.toOctalString)) |
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... | #Scheme | Scheme | (do ((i 0 (+ i 1))) (#f) (display (number->string i 8)) (newline)) |
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... | #Scratch | Scratch | $ include "seed7_05.s7i";
const proc: main is func
local
var integer: i is 0;
begin
repeat
writeln(i radix 8);
incr(i);
until FALSE;
end func; |
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... | #REXX | REXX | /*REXX program lists the prime factors of a specified integer (or a range of integers).*/
@.=left('', 8); @.0="{unity} "; @.1='[prime] ' /*some tags and handy-dandy literals.*/
parse arg LO HI @ . /*get optional arguments from the C.L. */
if LO=='' | LO=="," then do; LO=1; HI=40; end... |
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... | #OCaml | OCaml | let () =
let buf = Buffer.create 1 in
let s = Buffer.add_string buf in
Random.self_init();
s "<table>";
s "<thead align='right'>";
s "<tr><th></th>";
List.iter (fun v ->
s ("<td>" ^ v ^ "</td>")
) ["X"; "Y"; "Z"];
s "</tr>";
s "</thead>";
s "<tbody align='right'>";
for i = 0 to pred 3 do
... |
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.
| #Run_BASIC | Run BASIC | open "output.txt" for output as #f
close #f
dirOk = mkdir( "f:\doc")
if not(dirOk) then print "Directory not created!": end
open "f:\doc\output.txt" for output as #f
close #f |
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.
| #Rust | Rust | use std::io::{self, Write};
use std::fs::{DirBuilder, File};
use std::path::Path;
use std::{process,fmt};
const FILE_NAME: &'static str = "output.txt";
const DIR_NAME : &'static str = "docs";
fn main() {
create(".").and(create("/"))
.unwrap_or_else(|e| error_handler(e,1));
}
fn create<P>(root... |
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... | #R | R | File <- "~/test.csv"
Opened <- readLines(con = File)
Size <- length(Opened)
HTML <- "~/test.html"
Table <- list()
for(i in 1:Size)
{
#i=1
Split <- unlist(strsplit(Opened[i],split = ","))
Table[i] <- paste0("<td>",Split,"</td>",collapse = "")
Table[i] <- paste0("<tr>",Table[i],"</tr>")
}
Table[1] <- past... |
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 ... | #Vim_Script | Vim Script | " Create a two-dimensional array with r rows and c columns.
" The optional third argument specifies the initial value
" (default is 0).
function MakeArray(r, c, ...)
if a:0
let init = a:1
else
let init = 0
endif
let temp = []
for c in range(a:c)
call add(temp, init)
en... |
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... | #Scala | Scala | import scala.math.sqrt
object StddevCalc extends App {
def calcAvgAndStddev[T](ts: Iterable[T])(implicit num: Fractional[T]): (T, Double) = {
def avg(ts: Iterable[T])(implicit num: Fractional[T]): T =
num.div(ts.sum, num.fromInt(ts.size)) // Leaving with type of function T
val mean: T = avg(ts) //... |
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... | #Visual_Basic | Visual Basic | Option Explicit
'----------------------------------------------------------------------
Private Function coin_count(coins As Variant, amount As Long) As Variant
'return type will be Decimal
Dim s() As Variant
Dim n As Long, c As Long
ReDim s(amount + 1)
s(1) = CDec(1)
For c = LBound(coins) To UBound(coins)
... |
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... | #Vlang | Vlang | fn main() {
amount := 100
println("amount, ways to make change: $amount ${count_change(amount)}"))
}
fn count_change(amount int) i64 {
return cc(amount, 4)
}
fn cc(amount int, kinds_of_coins int) i64 {
if amount == 0 {
return 1
} else if amount < 0 || kinds_of_coins == 0 {
return... |
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... | #Racket | Racket |
(define count-substring
(compose length regexp-match*))
|
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... | #Raku | Raku | sub count-substring($big, $little) { +$big.comb: / :r $little / }
say count-substring("the three truths", "th"); # 3
say count-substring("ababababab", "abab"); # 2
say count-substring(123123123, 12); # 3 |
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... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const proc: main is func
local
var integer: i is 0;
begin
repeat
writeln(i radix 8);
incr(i);
until FALSE;
end func; |
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... | #Sidef | Sidef | var i = 0;
loop { say i++.as_oct } |
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... | #Simula | Simula |
BEGIN
PROCEDURE OUTOCT(N); INTEGER N;
BEGIN
PROCEDURE OCT(N); INTEGER N;
BEGIN
IF N > 0 THEN BEGIN
OCT(N//8);
OUTCHAR(CHAR(RANK('0')+MOD(N,8)));
END;
END OCT;
IF N < 0 THEN BEGIN OUTCHAR('-'); OUTOCT(-N); END
ELS... |
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... | #Ring | Ring |
for i = 1 to 20
see "" + i + " = " + factors(i) + nl
next
func factors n
f = ""
if n = 1 return "1" ok
p = 2
while p <= n
if (n % p) = 0
f += string(p) + " x "
n = n/p
else p += 1 ok
end
return left(f, len(f) - 3)
|
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... | #Ruby | Ruby | require 'optparse'
require 'prime'
maximum = 10
OptionParser.new do |o|
o.banner = "Usage: #{File.basename $0} [-m MAXIMUM]"
o.on("-m MAXIMUM", Integer,
"Count up to MAXIMUM [#{maximum}]") { |m| maximum = m }
o.parse! rescue ($stderr.puts $!, o; exit 1)
($stderr.puts o; exit 1) unless ARGV.size == 0
en... |
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... | #Oz | Oz | declare
[Roads] = {Module.link ['x-ozlib://wmeyer/roads/Roads.ozf']}
fun {Table Session}
html(
head(title("Show a table with row and column headings")
style(type:"text/css"
css(td 'text-align':center)
))
body(
{TagFromList table
tr(th th("X") th("Y") th("Z"))
|
{CreateRows 3 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.
| #Scala | Scala | import java.io.File
object CreateFile extends App {
try { new File("output.txt").createNewFile() }
catch { case e: Exception => println(s"Exception caught: $e with creating output.txt") }
try { new File(s"${File.separator}output.txt").createNewFile() }
catch { case e: Exception => println(s"Exception caught: ... |
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... | #Racket | Racket | #lang racket
(define e.g.-CSV
(string-join
'("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 ... |
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 ... | #Wren | Wren | import "io" for Stdin, Stdout
var x
var y
System.print("Enter the dimensions of the array:")
while (true) {
System.write(" First dimension : ")
Stdout.flush()
x = Num.fromString(Stdin.readLine())
if (x && (x is Num) && (x.isInteger) && (x > 0) ) {
System.write(" Second dimension : ")
... |
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... | #Scheme | Scheme |
(define (standart-deviation-generator)
(let ((nums '()))
(lambda (x)
(set! nums (cons x nums))
(let* ((mean (/ (apply + nums) (length nums)))
(mean-sqr (lambda (y) (expt (- y mean) 2)))
(variance (/ (apply + (map mean-sqr nums)) (length nums))))
(sqrt variance)))))
(let loop ((f (... |
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... | #Wren | Wren | import "/big" for BigInt
import "/fmt" for Fmt
var countCoins = Fn.new { |c, m, n|
var table = List.filled(n + 1, null)
table[0] = BigInt.one
for (i in 1..n) table[i] = BigInt.zero
for (i in 0...m) {
for (j in c[i]..n) table[j] = table[j] + table[j-c[i]]
}
return table[n]
}
var c = [... |
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... | #Red | Red | Red []
count-occurrences: function [string substring] [
length? parse string [collect [some [keep substring to substring]]]
]
test-case-1: "the three truths"
test-case-2: "ababababab"
print [test-case-1 "-" count-occurrences test-case-1 "th"]
print [test-case-2 "-" count-occurrences test-case-2 "abab"]
|
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... | #REXX | REXX | /*REXX program counts the occurrences of a (non─overlapping) substring in a string. */
w=. /*max. width so far.*/
bag= 'the three truths' ; x= "th" ; call showResult
bag= 'ababababab' ; x= "abab" ; call sho... |
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... | #Smalltalk | Smalltalk | 0 to:Integer infinity do:[:n |
n printOn:Stdout radix:8.
Stdout cr.
] |
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... | #Sparkling | Sparkling | for (var i = 0; true; i++) {
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... | #Standard_ML | Standard ML | local
fun count n = (print (Int.fmt StringCvt.OCT n ^ "\n"); count (n+1))
in
val _ = count 0
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... | #Run_BASIC | Run BASIC | for i = 1000 to 1016
print i;" = "; factorial$(i)
next
wait
function factorial$(num)
if num = 1 then factorial$ = "1"
fct = 2
while fct <= num
if (num mod fct) = 0 then
factorial$ = factorial$ ; x$ ; fct
x$ = " x "
num = num / fct
else
fct = fct + 1
end if
wend
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... | #Rust | Rust | use std::env;
fn main() {
let args: Vec<_> = env::args().collect();
let n = if args.len() > 1 {
args[1].parse().expect("Not a valid number to count to")
}
else {
20
};
count_in_factors_to(n);
}
fn count_in_factors_to(n: u64) {
println!("1");
let mut primes = vec![];
... |
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... | #PARI.2FGP | PARI/GP | html(n=3)={
print("<table>\n<tr><th></th><th>X</th><th>Y</th><th>Z</th></tr>");
for(i=1,n,
print1("<tr><td>"i"</td>");
for(j=1,3,print1("<td>"random(9999)"</td>"));
print("</tr>")
);
print("</table>")
}; |
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.
| #Scheme | Scheme | (open-output-file "output.txt")
(open-output-file "/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.
| #Seed7 | Seed7 | $ include "seed7_05.s7i";
include "osfiles.s7i";
const proc: main is func
local
var file: aFile is STD_NULL;
begin
aFile := open("output.txt", "w");
close(aFile);
mkdir("docs");
aFile := open("/output.txt", "w");
close(aFile);
mkdir("/docs");
end func; |
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... | #Raku | Raku | my $str = "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!";
# comment... |
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 ... | #XPL0 | XPL0 | inc c:\cxpl\codes; \(command words can be abbreviated to first 3 letters)
def IntSize=4; \number of bytes in an integer (2 or 4 depending on version)
int X, Y, A, I;
[X:= IntIn(0); Y:= IntIn(0); \get 2 dimensions from user
A:= Reserve(X*IntSize);
for I:= 0 to X-1 do A(I):= Reserve(Y*IntSize... |
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 ... | #zkl | zkl | rows:=ask("Rows: ").toInt();
cols:=ask("columns: ").toInt();
array:=rows.pump(List.createLong(rows),List.createLong(cols,0).copy);
array[1][2]=123;
array.println();
array[1][2].println(); |
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... | #Scilab | Scilab | T=[2,4,4,4,5,5,7,9];
stdev(T)*sqrt((length(T)-1)/length(T)) |
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... | #zkl | zkl | fcn ways_to_make_change(x, coins=T(25,10,5,1)){
if(not coins) return(0);
if(x<0) return(0);
if(x==0) return(1);
ways_to_make_change(x, coins[1,*]) + ways_to_make_change(x - coins[0], coins)
}
ways_to_make_change(100).println(); |
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... | #ZX_Spectrum_Basic | ZX Spectrum Basic | 10 LET amount=100
20 GO SUB 1000
30 STOP
1000 LET nPennies=amount
1010 LET nNickles=INT (amount/5)
1020 LET nDimes=INT (amount/10)
1030 LET nQuarters=INT (amount/25)
1040 LET count=0
1050 FOR p=0 TO nPennies
1060 FOR n=0 TO nNickles
1070 FOR d=0 TO nDimes
1080 FOR q=0 TO nQuarters
1090 LET s=p+n*5+d*10+q*25
1100 IF s=... |
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... | #Ring | Ring |
aString = "Ring Welcome Ring to the Ring Ring Programming Ring Language Ring"
bString = "Ring"
see count(aString,bString)
func count cString,dString
sum = 0
while substr(cString,dString) > 0
sum++
cString = substr(cString,substr(cString,dString)+len(string(sum)))
end
return... |
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... | #Ruby | Ruby | def countSubstrings str, subStr
str.scan(subStr).length
end
p countSubstrings "the three truths", "th" #=> 3
p countSubstrings "ababababab", "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... | #Swift | Swift | import Foundation
func octalSuccessor(value: String) -> String {
if value.isEmpty {
return "1"
} else {
let i = value.startIndex, j = value.endIndex.predecessor()
switch (value[j]) {
case "0": return value[i..<j] + "1"
case "1": return value[i..<j] + "2"
case "2": return v... |
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... | #Tcl | Tcl | package require Tcl 8.5; # arbitrary precision integers; we can count until we run out of memory!
while 1 {
puts [format "%llo" [incr counter]]
} |
http://rosettacode.org/wiki/Count_in_octal | Count in octal | Task
Produce a sequential count in octal, starting at zero, and using an increment of a one for each consecutive number.
Each number should appear on a single line, and the program should count until terminated, or until the maximum value of the numeric type in use is reached.
Related task
Integer sequ... | #UNIX_Shell | UNIX Shell | #!/bin/sh
num=0
while true; do
echo $num
num=`echo "obase=8;ibase=8;$num+1"|bc`
done |
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... | #Sage | Sage | def count_in_factors(n):
if is_prime(n) or n == 1:
print(n,end="")
return
while n != 1:
p = next_prime(1)
while n % p != 0:
p = next_prime(p)
print(p,end="")
n = n / p
if n != 1: print(" x",end=" ")
for i in range(1, 101):
print(i,"=",en... |
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... | #Scala | Scala |
object CountInFactors extends App {
def primeFactors(n: Int): List[Int] = {
def primeStream(s: LazyList[Int]): LazyList[Int] = {
s.head #:: primeStream(s.tail filter {
_ % s.head != 0
})
}
val primes = primeStream(LazyList.from(2))
def factors(n: Int): List[Int] = primes.... |
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... | #Pascal | Pascal | <@ SDCLIT>
<@ DTBLIT>
<@ DTRLITLIT>
<@ DTDLITLIT>|[style]background-color:white</@>
<@ DTD>X</@>
<@ DTD>Y</@>
<@ DTD>Z</@>|[style]width:100%; background-color:brown;color:white; text-align:center</@>
<@ ITEFORLIT>10|
<@ DTRLITCAP>
<@ DTDPOSFORLIT>...|[style]background-color:Brown; color:white; te... |
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.
| #SenseTalk | SenseTalk | set the folder to "~/Desktop"
put "" into file "docs/output.txt"
set the folder to "/"
put empty into file "/docs/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.
| #Sidef | Sidef | # Here
%f'output.txt' -> create;
%d'docs' -> create;
# Root dir
Dir.root + %f'output.txt' -> create;
Dir.root + %d'docs' -> create; |
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... | #Red | Red | Red []
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 mother! Behold his mother!}
add2h... |
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 ... | #zonnon | zonnon |
module Main;
type
Matrix = array *,* of integer;
var
m: Matrix;
i,j: integer;
begin
write("first dim? ");readln(i);
write("second dim? ");readln(j);
m := new Matrix(i,j);
m[0,0] := 10;
writeln("m[0,0]:> ",m[0,0]);
writeln("m[0,1].> ",m[0,1])
end Main.
|
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... | #Sidef | Sidef | class StdDevAccumulator(n=0, sum=0, sumofsquares=0) {
method <<(num) {
n += 1
sum += num
sumofsquares += num**2
self
}
method stddev {
sqrt(sumofsquares/n - pow(sum/n, 2))
}
method to_s {
self.stddev.to_s
}
}
var i = 0
var sd = StdDevAccumulator()
[2,4,4,4,5,5,7,9].each {|n|
... |
http://rosettacode.org/wiki/Count_occurrences_of_a_substring | Count occurrences of a substring | Task
Create a function, or show a built-in function, to count the number of non-overlapping occurrences of a substring inside a string.
The function should take two arguments:
the first argument being the string to search, and
the second a substring to be searched for.
It should return an integer cou... | #Run_BASIC | Run BASIC | print countSubstring("the three truths","th")
print countSubstring("ababababab","abab")
FUNCTION countSubstring(s$,find$)
WHILE instr(s$,find$,i) <> 0
countSubstring = countSubstring + 1
i = instr(s$,find$,i) + len(find$)
WEND
END FUNCTION |
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... | #Rust | Rust |
fn main() {
println!("{}","the three truths".matches("th").count());
println!("{}","ababababab".matches("abab").count());
}
|
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... | #VBA | VBA |
Sub CountOctal()
Dim i As Integer
i = 0
On Error GoTo OctEnd
Do
Debug.Print Oct(i)
i = i + 1
Loop
OctEnd:
Debug.Print "Integer overflow - count terminated"
End Sub
|
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... | #VBScript | VBScript |
For i = 0 To 20
WScript.StdOut.WriteLine Oct(i)
Next
|
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... | #Vim_Script | Vim Script | let counter = 0
while counter >= 0
echon printf("%o\n", counter)
let counter += 1
endwhile |
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... | #Scheme | Scheme | (define (factors n)
(let facs ((l '()) (d 2) (x n))
(cond ((= x 1) (if (null? l) '(1) l))
((< x (* d d)) (cons x l))
(else (if (= 0 (modulo x d))
(facs (cons d l) d (/ x d))
(facs l (+ 1 d) x))))))
(define (show l)
(display (car l))
(if (not (null? (cdr l)))
(begin
(display " × ")
... |
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... | #Peloton | Peloton | <@ SDCLIT>
<@ DTBLIT>
<@ DTRLITLIT>
<@ DTDLITLIT>|[style]background-color:white</@>
<@ DTD>X</@>
<@ DTD>Y</@>
<@ DTD>Z</@>|[style]width:100%; background-color:brown;color:white; text-align:center</@>
<@ ITEFORLIT>10|
<@ DTRLITCAP>
<@ DTDPOSFORLIT>...|[style]background-color:Brown; color:white; te... |
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.
| #Slate | Slate | (File newNamed: 'output.txt') touch.
(Directory current / 'output.txt') touch. |
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.
| #Smalltalk | Smalltalk | (FileDirectory on: 'c:\') newFileNamed: 'output.txt'; 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... | #Retro | Retro | remapping off
"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!" remappin... |
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... | #Smalltalk | Smalltalk | Object subclass: SDAccum [
|sum sum2 num|
SDAccum class >> new [ |o|
o := super basicNew.
^ o init.
]
init [ sum := 0. sum2 := 0. num := 0 ]
value: aValue [
sum := sum + aValue.
sum2 := sum2 + ( aValue * aValue ).
num := num + 1.
^ self stddev
]
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... | #Scala | Scala | import scala.annotation.tailrec
def countSubstring(str1:String, str2:String):Int={
@tailrec def count(pos:Int, c:Int):Int={
val idx=str1 indexOf(str2, pos)
if(idx == -1) c else count(idx+str2.size, c+1)
}
count(0,0)
} |
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... | #Scheme | Scheme | gosh> (use gauche.lazy)
#<undef>
gosh> (length (lrxmatch "th" "the three truths"))
3
gosh> (length (lrxmatch "abab" "ababababab"))
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... | #Vlang | Vlang | import math
fn main() {
for i := i8(0); ; i++ {
println("${i:o}")
if i == math.max_i8 {
break
}
}
} |
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... | #VTL-2 | VTL-2 | 1000 N=0
1010 #=2000
1020 ?=""
1030 #=N=65535*9999
1040 N=N+1
1050 #=1010
2000 R=!
2010 O=N
2020 D=1
2030 O=O/8
2040 :D)=%
2050 D=D+1
2060 #=O>1*2030
2070 E=D-1
2080 $=48+:E)
2090 E=E-1
2100 #=E>1*2080
2110 #=R |
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... | #Whitespace | Whitespace | |
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... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const proc: writePrimeFactors (in var integer: number) is func
local
var boolean: laterElement is FALSE;
var integer: checker is 2;
begin
while checker * checker <= number do
if number rem checker = 0 then
if laterElement then
write(" * ");
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... | #Sidef | Sidef | class Counter {
method factors(n, p=2) {
var a = gather {
while (n >= p*p) {
while (p `divides` n) {
take(p)
n //= p
}
p = self.next_prime(p)
}
}
(n > 1 || a.is_empty) ? (a << n) :... |
http://rosettacode.org/wiki/Create_an_HTML_table | Create an HTML table | Create an HTML table.
The table body should have at least three rows of three columns.
Each of these three columns should be labelled "X", "Y", and "Z".
An extra column should be added at either the extreme left or the extreme right of the table that has no heading, but is filled with sequential row numbers.
The... | #Perl | Perl | my @heading = qw(X Y Z);
my $rows = 5;
print '<table><thead><td>',
(map { "<th>$_</th>" } @heading),
"</thead><tbody>";
for (1 .. $rows) {
print "<tr><th>$_</th>",
(map { "<td>".int(rand(10000))."</td>" } @heading),
"</tr>";
}
print "</tbody></table>"; |
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.
| #SNOBOL4 | SNOBOL4 | output(.file,1,'output.txt'); endfile(1) ;* Macro Spitbol
* output(.file,1,,'output.txt'); endfile(1) ;* CSnobol
host(1,'mkdir docs')
output(.file,1,'/output.txt'); endfile(1) ;* Macro Spitbol
* output(.file,1,,'/output.txt'); endfile(1) ;* CSnobol
host(1,'mkdir /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.
| #SQL_PL | SQL PL |
BEGIN
DECLARE UTL_FILE_HANDLER UTL_FILE.FILE_TYPE;
DECLARE DIR_ALIAS_CURRENT VARCHAR(128);
DECLARE DIR_ALIAS_ROOT VARCHAR(128);
DECLARE DIRECTORY VARCHAR(1024);
DECLARE FILENAME VARCHAR(255);
SET DIR_ALIAS_CURRENT = 'outputFileCurrent';
SET DIRECTORY = '/home/db2inst1/doc';
SET FILENAME = 'output.tx... |
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... | #REXX | REXX | /*REXX program converts CSV ───► HTML table representing the CSV data. */
arg header_ . /*obtain an uppercase version of args. */
wantsHdr= (header_=='HEADER') /*is the arg (low/upp/mix case)=HEADER?*/
... |
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... | #SQL | SQL | -- the minimal table
CREATE TABLE IF NOT EXISTS teststd (n DOUBLE PRECISION NOT NULL);
-- code modularity with view, we could have used a common table expression instead
CREATE VIEW vteststd AS
SELECT COUNT(n) AS cnt,
SUM(n) AS tsum,
SUM(POWER(n,2)) AS tsqr
FROM teststd;
-- you can of course put this code in... |
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... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const func integer: countSubstring (in string: stri, in string: searched) is func
result
var integer: count is 0;
local
var integer: offset is 0;
begin
offset := pos(stri, searched);
while offset <> 0 do
incr(count);
offset := pos(stri, searched, offset + le... |
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... | #SenseTalk | SenseTalk |
put the number of occurrences of "th" in "the three truths" --> 3
put the number of occurrences of "abab" in "ababababab" -- > 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... | #Wren | Wren | import "/fmt" for Conv
var i = 0
while (true) {
System.print(Conv.oct(i))
i = i + 1
} |
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... | #XPL0 | XPL0 | include c:\cxpl\codes; \intrinsic code declarations
proc OctOut(N); \Output N in octal
int N;
int R;
[R:= N&7;
N:= N>>3;
if N then OctOut(N);
ChOut(0, R+^0);
];
int I;
[I:= 0;
repeat OctOut(I); CrLf(0);
I:= I+1;
until KeyHit or I=0;
] |
http://rosettacode.org/wiki/Count_in_octal | Count in octal | Task
Produce a sequential count in octal, starting at zero, and using an increment of a one for each consecutive number.
Each number should appear on a single line, and the program should count until terminated, or until the maximum value of the numeric type in use is reached.
Related task
Integer sequ... | #zig | zig | const std = @import("std");
const fmt = std.fmt;
const warn = std.debug.warn;
pub fn main() void {
var i: u8 = 0;
var buf: [3]u8 = undefined;
while (i < 255) : (i += 1) {
_ = fmt.formatIntBuf(buf[0..], i, 8, false, 0); // buffer, value, base, uppercase, width
warn("{}\n", buf);
}
} |
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... | #Swift | Swift | extension BinaryInteger {
@inlinable
public func primeDecomposition() -> [Self] {
guard self > 1 else { return [] }
func step(_ x: Self) -> Self {
return 1 + (x << 2) - ((x >> 1) << 1)
}
let maxQ = Self(Double(self).squareRoot())
var d: Self = 1
var q: Self = self & 1 == 0 ? 2 : 3
... |
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... | #Tcl | Tcl | package require Tcl 8.5
namespace eval prime {
variable primes [list 2 3 5 7 11]
proc restart {} {
variable index -1
variable primes
variable current [lindex $primes end]
}
proc get_next_prime {} {
variable primes
variable index
if {$index < [llength $primes]-1} {
return [lindex $primes [... |
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... | #Phix | Phix | puts(1,"<table border=2>\n")
puts(1," <tr><th></th>")
for j=1 to 3 do
printf(1,"<th>%s</th>",'W'+j)
end for
puts(1,"</tr>\n")
for i=1 to 3 do
printf(1," <tr><td>%d</td>",i)
for j=1 to 3 do
printf(1,"<td>%d</td>",rand(10000))
end for
puts(1,"</tr>\n")
end for
puts(1,"</table>")
|
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.
| #SQLite | SQLite |
/*
*Use '/' for *nix. Use whatever your root directory is on Windows.
*Must be run as admin.
*/
.shell mkdir "docs";
.shell mkdir "/docs";
.output output.txt
.output /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.
| #Standard_ML | Standard ML | let val out = TextIO.openOut "output.txt" in
TextIO.closeOut out
end;
OS.FileSys.mkDir "docs"; |
http://rosettacode.org/wiki/CSV_to_HTML_translation | CSV to HTML translation | Consider a simplified CSV format where all rows are separated by a newline
and all columns are separated by commas.
No commas are allowed as field data, but the data may contain
other characters and character sequences that would
normally be escaped when converted to HTML
Task
Create a function that takes a st... | #Ruby | Ruby | ruby csv2html.rb header
|
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... | #Swift | Swift | import Darwin
class stdDev{
var n:Double = 0.0
var sum:Double = 0.0
var sum2:Double = 0.0
init(){
let testData:[Double] = [2,4,4,4,5,5,7,9];
for x in testData{
var a:Double = calcSd(x)
println("value \(Int(x)) SD = \(a)");
}
}
func calc... |
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... | #Sidef | Sidef | say "the three truths".count("th");
say "ababababab".count("abab"); |
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... | #Simula | Simula | BEGIN
INTEGER PROCEDURE COUNTSUBSTRING(T,TSUB); TEXT T,TSUB;
BEGIN
INTEGER N,I;
I := 1;
WHILE I+TSUB.LENGTH-1 <= T.LENGTH DO
IF T.SUB(I,TSUB.LENGTH) = TSUB THEN
BEGIN
N := N+1;
I := I+MAX(TSUB.LENGTH,1);
END ELSE I := I+1;
... |
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... | #Z80_Assembly | Z80 Assembly | xor a ;LD A,0
ld b,&40 ;how many numbers to print.
loop_showOctal:
push af
push af
call ShowOctal
ld a,' '
call PrintChar ;put a blank space after the value
pop af
;;;;;;;;;;;;;;;;;;;;; this code starts a new line after every 8th output.
ld a,b
and &07
dec a
call ... |
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... | #zkl | zkl | foreach n in ([0..]){println("%.8B".fmt(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... | #VBScript | VBScript | Function CountFactors(n)
If n = 1 Then
CountFactors = 1
Else
arrP = Split(ListPrimes(n)," ")
Set arrList = CreateObject("System.Collections.ArrayList")
divnum = n
Do Until divnum = 1
'The -1 is to account for the null element of arrP
For i = 0 To UBound(arrP)-1
If divnum = 1 Then
Exit For
... |
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... | #PHP | PHP | <?php
/**
* @author Elad Yosifon
* @desc HTML Table - normal style
*/
$cols = array('', 'X', 'Y', 'Z');
$rows = 3;
$html = '<html><body><table><colgroup>';
foreach($cols as $col)
{
$html .= '<col style="text-align: left;" />';
}
unset($col);
$html .= '</colgroup><thead><tr>';
foreach($cols as $col)
{
$html .= ... |
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.
| #Stata | Stata | file open f using output.txt, write replace
file close f
mkdir docs
file open f using \output.txt, write replace
file close f
mkdir \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.
| #Tcl | Tcl | close [open output.txt w]
close [open [file nativename /output.txt] w]
file mkdir docs
file mkdir [file nativename /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... | #Run_BASIC | Run BASIC | 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 mother! Behold his mother!"
k = instr(csv... |
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... | #Tcl | Tcl | oo::class create SDAccum {
variable sum sum2 num
constructor {} {
set sum 0.0
set sum2 0.0
set num 0
}
method value {x} {
set sum2 [expr {$sum2 + $x**2}]
set sum [expr {$sum + $x}]
incr num
return [my stddev]
}
method count {} {
ret... |
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... | #Smalltalk | Smalltalk | Transcript showCR:('the three truths' occurrencesOfString:'th').
Transcript showCR:('ababababab' occurrencesOfString:'abab') |
Subsets and Splits
Rosetta Code COBOL Python Hard Tasks
Identifies and retrieves challenging tasks that exist in both COBOL and Python, revealing cross-language programming patterns and difficulty levels for comparative analysis.
Rosetta Code Task Comparisons
Identifies tasks common to both COBOL and Python languages that are described as having difficulty levels, revealing cross-language task similarities and providing useful comparative programming examples.
SQL Code Examples from Training Data
Retrieves raw SQL code examples for the SQL language, which is basic data retrieval without meaningful analysis or patterns.
SQL Code Examples from Training Data
Retrieves raw SQL code examples for the SQL language, which is basic filtering that shows what data looks like but doesn't provide meaningful analysis or patterns.
Select Specific Languages Codes
Retrieves specific programming language names and codes from training data, providing basic filtering but limited analytical value beyond identifying these particular languages.