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/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #MATLAB_.2F_Octave | MATLAB / Octave | lcm(a,b) |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #Maxima | Maxima | lcm(a, b); /* a and b may be integers or polynomials */
/* In Maxima the gcd of two integers is always positive, and a * b = gcd(a, b) * lcm(a, b),
so the lcm may be negative. To get a positive lcm, simply do */
abs(lcm(a, b)) |
http://rosettacode.org/wiki/Levenshtein_distance | Levenshtein distance |
This page uses content from Wikipedia. The original article was at Levenshtein distance. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In information theory and computer science, the Levenshtein ... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | EditDistance["kitten","sitting"]
EditDistance["rosettacode","raisethysword"] |
http://rosettacode.org/wiki/Letter_frequency | Letter frequency | Task
Open a text file and count the occurrences of each letter.
Some of these programs count all characters (including punctuation),
but some only count letters A to Z.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequen... | #Kotlin | Kotlin | // version 1.1.2
import java.io.File
fun main(args: Array<String>) {
val text = File("input.txt").readText().toLowerCase()
val letterMap = text.filter { it in 'a'..'z' }.groupBy { it }.toSortedMap()
for (letter in letterMap) println("${letter.key} = ${letter.value.size}")
val sum = letterMap.values.... |
http://rosettacode.org/wiki/Linear_congruential_generator | Linear congruential generator | The linear congruential generator is a very simple example of a random number generator.
All linear congruential generators use this formula:
r
n
+
1
=
a
×
r
n
+
c
(
mod
m
)
{\displaystyle r_{n+1}=a\times r_{n}+c{\pmod {m}}}
Where:
r
0
{\displaystyle r_{0}}
is a seed.
r
1
... | #XPL0 | XPL0 | include c:\cxpl\codes;
int R;
func BSD;
[R:= (1103515245*R + 12345) & $7FFF_FFFF;
return R;
]; \BSD
func MSFT;
[R:= (214013*R + 2531011) & $7FFF_FFFF;
return R>>16;
]; \MSFT
int N;
[SetVid(4); \320x200x2 graphics
R:= 0; \initialize seed
for N:= 0 to 5000 do
Point(rem(BSD/1... |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #LLVM | LLVM | ; This is not strictly LLVM, as it uses the C library function "printf".
; LLVM does not provide a way to print values, so the alternative would be
; to just load the string into memory, and that would be boring.
$"EMPTY_STR" = comdat any
$"NOT_STR" = comdat any
$"IS_A_LEAP_YEAR" = comdat any
@main.test_case = priv... |
http://rosettacode.org/wiki/Langton%27s_ant | Langton's ant | Langton's ant is a cellular automaton that models an ant sitting on a plane of cells, all of which are white initially, the ant facing in one of four directions.
Each cell can either be black or white.
The ant moves according to the color of the cell it is currently sitting in, with the following rules:
If the ce... | #F.23 | F# |
// Langton's ant F# https://rosettacode.org/wiki/Langton%27s_ant
// A list of cells which are black is maintained and then printed out at the end
type Cell = { X : int; Y : int }
type Direction = | North | South | East| West // direction the ant is facing
let withinBounds (dim:int) (cell: Cell) = // ant's ... |
http://rosettacode.org/wiki/Kronecker_product | Kronecker product | Kronecker product
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Implement the Kronecker product of two matrices (arbitrary sized) resulting in a block matrix.
Test cases
Show results for each of the following two samples:
Sample 1 (from ... | #Rust | Rust | fn main() {
let mut a = vec![vec![1., 2.], vec![3., 4.]];
let mut b = vec![vec![0., 5.], vec![6., 7.]];
let mut a_ref = &mut a;
let a_rref = &mut a_ref;
let mut b_ref = &mut b;
let b_rref = &mut b_ref;
let ab = kronecker_product(a_rref, b_rref);
println!("Kronecker product of\n... |
http://rosettacode.org/wiki/Kronecker_product | Kronecker product | Kronecker product
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Implement the Kronecker product of two matrices (arbitrary sized) resulting in a block matrix.
Test cases
Show results for each of the following two samples:
Sample 1 (from ... | #Scala | Scala | object KroneckerProduct
{
/**Get the dimensions of the input matrix*/
def getDimensions(matrix : Array[Array[Int]]) : (Int,Int) = {
val dimensions = matrix.map(x => x.size)
(dimensions.size, dimensions(0))
}
/**Compute the Kronecker product between 2 input matrixes and return the result as a matrix*/... |
http://rosettacode.org/wiki/Last_Friday_of_each_month | Last Friday of each month | Task
Write a program or a script that returns the date of the last Fridays of each month of a given year.
The year may be given through any simple input method in your language (command line, std in, etc).
Example of an expected output:
./last_fridays 2012
2012-01-27
2012-02-24
2012-03-30
2012-04-27
2012-05-25
20... | #Julia | Julia | using Dates
const wday = Dates.Fri
const lo = 1
const hi = 12
print("\nThis script will print the last ", Dates.dayname(wday))
println("s of each month of the year given.")
println("(Leave input empty to quit.)")
while true
print("\nYear> ")
y = chomp(readline())
0 < length(y) || break
y = try
... |
http://rosettacode.org/wiki/Last_letter-first_letter | Last letter-first letter | A certain children's game involves starting with a word in a particular category. Each participant in turn says a word, but that word must begin with the final letter of the previous word. Once a word has been given, it cannot be repeated. If an opponent cannot give a word in the category, they fall out of the ga... | #zkl | zkl | pokemon:=("audino bagon baltoy banette bidoof braviary "
"bronzor carracosta charmeleon cresselia croagunk darmanitan deino "
...
"whismur wingull yamask").split();
tree:=pokemon.pump(Dictionary(),'wrap(name){ //--> Hash("aB":("Bc","Bd",,,) )
T( name, pokemon.filter('wrap(nm){ name[-1]==nm[0] }) )
});
... |
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #PowerShell | PowerShell | Function Get-LargestConcatenation ( [int[]]$Integers )
{
# Get the length of the largest integer
$Length = ( $Integers | Sort -Descending | Select -First 1 ).ToString().Length
# Convert to an array of strings,
# sort by each number repeated Length times and truncated to Length,
# and conca... |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #Microsoft_Small_Basic | Microsoft Small Basic |
Textwindow.Write("LCM(35, 21) = ")
mlcm = 35
nlcm = 21
CalculateLCM()
TextWindow.WriteLine(lcm)
Sub CalculateLCM
mgcd = mlcm
ngcd = nlcm
CalculateGCD()
lcm = mlcm / gcd * nlcm
EndSub
Sub CalculateGCD
While mgcd <> 0
tmp = mgcd
mgcd = Math.Remainder(ngcd, mgcd)
ngcd = tmp
EndWhile
gcd ... |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #MiniScript | MiniScript | gcd = function(a, b)
while b
temp = b
b = a % b
a = temp
end while
return abs(a)
end function
lcm = function(a,b)
if not a and not b then return 0
return abs(a * b) / gcd(a, b)
end function
print lcm(18,12)
|
http://rosettacode.org/wiki/Levenshtein_distance | Levenshtein distance |
This page uses content from Wikipedia. The original article was at Levenshtein distance. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In information theory and computer science, the Levenshtein ... | #MATLAB | MATLAB |
function score = levenshtein(s1, s2)
% score = levenshtein(s1, s2)
%
% Calculates the area under the ROC for a given set
% of posterior predictions and labels. Currently limited to two classes.
%
% s1: string
% s2: string
% score: levenshtein distance
%
% Author: Ben Hamner (ben@benhamner.com)
if length(s1) < length(... |
http://rosettacode.org/wiki/Letter_frequency | Letter frequency | Task
Open a text file and count the occurrences of each letter.
Some of these programs count all characters (including punctuation),
but some only count letters A to Z.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequen... | #Ksh | Ksh |
#!/bin/ksh
# Count the occurrences of each character
######
# main #
######
typeset -iA freqCnt
while read; do
for ((i=0; i<${#REPLY}; i++)); do
(( freqCnt[${REPLY:i:1}]++ ))
done
done < $0 ## Count chars of this code file
for ch in "${!freqCnt[@]}"; do
[[ ${ch} == ?(\S) ]] && print -- "${ch} ${freqC... |
http://rosettacode.org/wiki/Linear_congruential_generator | Linear congruential generator | The linear congruential generator is a very simple example of a random number generator.
All linear congruential generators use this formula:
r
n
+
1
=
a
×
r
n
+
c
(
mod
m
)
{\displaystyle r_{n+1}=a\times r_{n}+c{\pmod {m}}}
Where:
r
0
{\displaystyle r_{0}}
is a seed.
r
1
... | #zkl | zkl | var [private] seed = 0;
fcn srand(s){ seed = s }
const TWO31=(1).shiftLeft(31);
//#define BSD_RAND 1
#ifdef BSD_RAND
const A=1103515245, C=12345;
fcn rand{ seed = (seed * A + C) % TWO31 }
#else // MS rand
const A=214013, C=2531011, TWO16=(1).shiftLeft(16);
fcn rand{ (seed = (seed * A + C) % TWO31) / ... |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #Logo | Logo | to multiple? :n :d
output equal? 0 modulo :n :d
end
to leapyear? :y
output ifelse multiple? :y 100 [multiple? :y 400] [multiple? :y 4]
end |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #Logtalk | Logtalk | leap_year(Year) :-
( mod(Year, 4) =:= 0, mod(Year, 100) =\= 0 ->
true
; mod(Year, 400) =:= 0
). |
http://rosettacode.org/wiki/Langton%27s_ant | Langton's ant | Langton's ant is a cellular automaton that models an ant sitting on a plane of cells, all of which are white initially, the ant facing in one of four directions.
Each cell can either be black or white.
The ant moves according to the color of the cell it is currently sitting in, with the following rules:
If the ce... | #Fantom | Fantom |
class World
{
Int height
Int width
Bool[] state
new make (Int height, Int width)
{
this.height = height
this.width = width
state = List(Bool#, height * width)
(height*width).times { state.add (false) }
}
Bool inWorld (Int x, Int y)
{
x >= 0 && x < width && y >= 0 && y < height
... |
http://rosettacode.org/wiki/Kronecker_product | Kronecker product | Kronecker product
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Implement the Kronecker product of two matrices (arbitrary sized) resulting in a block matrix.
Test cases
Show results for each of the following two samples:
Sample 1 (from ... | #Sidef | Sidef | func kronecker_product(a, b) {
a ~X b -> map { _[0] ~X* _[1] }
}
kronecker_product([[1, 2], [3, 4]],
[[0, 5], [6, 7]]).each { .say }
say ''
kronecker_product([[0,1,0], [1,1,1], [0,1,0]],
[[1,1,1,1],[1,0,0,1], [1,1,1,1]]).each { .say } |
http://rosettacode.org/wiki/Last_Friday_of_each_month | Last Friday of each month | Task
Write a program or a script that returns the date of the last Fridays of each month of a given year.
The year may be given through any simple input method in your language (command line, std in, etc).
Example of an expected output:
./last_fridays 2012
2012-01-27
2012-02-24
2012-03-30
2012-04-27
2012-05-25
20... | #K | K |
/ List the dates of last Fridays of each month of
/ a given year
/ lastfridt.k
isleap: {(+/~x!' 4 100 400)!2}
wd: {(_jd x)!7}
dom: (31;28;31;30;31;30;31;31;30;31;30;31)
init: {:[isleap x;dom[1]::29;dom[1]::28]}
wdme: {[m;y]; init y; dt:(10000*y)+(100*m)+dom[m-1];jd::(_jd dt);mewd::(wd dt)}
lfd: {[m;y]; wdme[m;y];:[... |
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #Prolog | Prolog | largest_int_v1(In, Out) :-
maplist(name, In, LC),
aggregate(max(V), get_int(LC, V), Out).
get_int(LC, V) :-
permutation(LC, P),
append(P, LV),
name(V, LV).
|
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #MiniZinc | MiniZinc | function var int: lcm(int: a2,int:b2) =
let {
int:a1 = max(a2,b2);
int:b1 = min(a2,b2);
array[0..a1,0..b1] of var int: gcd;
constraint forall(a in 0..a1)(
forall(b in 0..b1)(
gcd[a,b] ==
if (b == 0) then
a
else
gcd[b, a mod b]
endif
)
... |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #min | min | ((0 <) (-1 *) when) :abs
((dup 0 ==) (pop abs) (swap over mod) () linrec) :gcd
(over over gcd '* dip div) :lcm |
http://rosettacode.org/wiki/Levenshtein_distance | Levenshtein distance |
This page uses content from Wikipedia. The original article was at Levenshtein distance. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In information theory and computer science, the Levenshtein ... | #MiniScript | MiniScript | import "stringUtil"
print "kitten".editDistance("sitting") |
http://rosettacode.org/wiki/Letter_frequency | Letter frequency | Task
Open a text file and count the occurrences of each letter.
Some of these programs count all characters (including punctuation),
but some only count letters A to Z.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequen... | #Lambdatalk | Lambdatalk |
{script
// W.frequency is added to the lambdatalk dictionary via the {script ...} special form
LAMBDATALK.DICT['W.frequency'] = function() {
// 1) simply copied from the rosetta.org #Javascript entry
var frequency = function(txt) {
var cs = txt.split(''),
i = cs.length,
dct = {},... |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #LOLCODE | LOLCODE | BTW Determine if a Gregorian calendar year is leap
HAI 1.3
HOW IZ I Leap YR Year
BOTH SAEM 0 AN MOD OF Year AN 4
O RLY?
YA RLY
BOTH SAEM 0 AN MOD OF Year AN 100
O RLY?
YA RLY
BOTH SAEM 0 AN MOD OF Year AN 400
O RLY?
YA RLY
FOUND YR WIN
... |
http://rosettacode.org/wiki/Langton%27s_ant | Langton's ant | Langton's ant is a cellular automaton that models an ant sitting on a plane of cells, all of which are white initially, the ant facing in one of four directions.
Each cell can either be black or white.
The ant moves according to the color of the cell it is currently sitting in, with the following rules:
If the ce... | #Forth | Forth |
1 0 0 0 \ pushes orientation of the ant to the stack.
100 CONSTANT border \ lenght of the side of the grid
border border * constant size \ size of the grid
variable antpos... |
http://rosettacode.org/wiki/Kronecker_product | Kronecker product | Kronecker product
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Implement the Kronecker product of two matrices (arbitrary sized) resulting in a block matrix.
Test cases
Show results for each of the following two samples:
Sample 1 (from ... | #Simula | Simula | BEGIN
PROCEDURE OUTMATRIX(A, W); INTEGER ARRAY A; INTEGER W;
BEGIN
INTEGER I, J;
INTEGER LA1, UA1;
INTEGER LA2, UA2;
LA1 := LOWERBOUND(A, 1); UA1 := UPPERBOUND(A, 1);
LA2 := LOWERBOUND(A, 2); UA2 := UPPERBOUND(A, 2);
FOR I := LA1 STEP 1 UNTIL UA1 DO
... |
http://rosettacode.org/wiki/Kronecker_product | Kronecker product | Kronecker product
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Implement the Kronecker product of two matrices (arbitrary sized) resulting in a block matrix.
Test cases
Show results for each of the following two samples:
Sample 1 (from ... | #Stata | Stata | . mata
------------------------------------------------- mata (type end to exit) ----------
: a=1,2\3,4
: b=0,5\6,7
: a#b
1 2 3 4
+---------------------+
1 | 0 5 0 10 |
2 | 6 7 12 14 |
3 | 0 15 0 20 |
4 | 18 21 24 28 |
+---------------------+
... |
http://rosettacode.org/wiki/Last_Friday_of_each_month | Last Friday of each month | Task
Write a program or a script that returns the date of the last Fridays of each month of a given year.
The year may be given through any simple input method in your language (command line, std in, etc).
Example of an expected output:
./last_fridays 2012
2012-01-27
2012-02-24
2012-03-30
2012-04-27
2012-05-25
20... | #Kotlin | Kotlin | // version 1.0.6
import java.util.*
fun main(args: Array<String>) {
print("Enter a year : ")
val year = readLine()!!.toInt()
println("The last Fridays of each month in $year are as follows:")
val calendar = GregorianCalendar(year, 0, 31)
for (month in 1..12) {
val daysInMonth = calenda... |
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #Python | Python | try:
cmp # Python 2 OK or NameError in Python 3
def maxnum(x):
return ''.join(sorted((str(n) for n in x),
cmp=lambda x,y:cmp(y+x, x+y)))
except NameError:
# Python 3
from functools import cmp_to_key
def cmp(x, y):
return -1 if x<y else ( 0 if x==y el... |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #.D0.9C.D0.9A-61.2F52 | МК-61/52 | ИПA ИПB * |x| ПC ИПA ИПB / [x] П9
ИПA ИПB ПA ИП9 * - ПB x=0 05 ИПC
ИПA / С/П |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #ML | ML | fun gcd (a, 0) = a
| (0, b) = b
| (a, b) where (a < b)
= gcd (a, b rem a)
| (a, b) = gcd (b, a rem b)
fun lcm (a, b) = let val d = gcd (a, b)
in a * b div d
end
|
http://rosettacode.org/wiki/Levenshtein_distance | Levenshtein distance |
This page uses content from Wikipedia. The original article was at Levenshtein distance. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In information theory and computer science, the Levenshtein ... | #Modula-2 | Modula-2 | MODULE LevenshteinDistance;
FROM InOut IMPORT WriteString, WriteCard, WriteLn;
FROM Strings IMPORT Length;
PROCEDURE levenshtein(s, t: ARRAY OF CHAR): CARDINAL;
CONST MaxLen = 15;
VAR d: ARRAY [0..MaxLen],[0..MaxLen] OF CARDINAL;
lenS, lenT, i, j: CARDINAL;
PROCEDURE min(a, b: CARDINAL): CARDINA... |
http://rosettacode.org/wiki/Letter_frequency | Letter frequency | Task
Open a text file and count the occurrences of each letter.
Some of these programs count all characters (including punctuation),
but some only count letters A to Z.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequen... | #langur | langur | val .countLetters = f(.s) {
for[=h{}] .s2 in split(replace(.s, RE/\P{L}/)) {
_for[.s2; 0] += 1
}
}
val .counts = .countLetters(readfile "./fuzz.txt")
writeln join "\n", map f(.k) $"\.k;: \.counts[.k];", keys .counts |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #Lua | Lua | function isLeapYear(year)
return year%4==0 and (year%100~=0 or year%400==0)
end |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #Maple | Maple | isLeapYear := proc(year)
if not year mod 4 = 0 or (year mod 100 = 0 and not year mod 400 = 0) then
return false;
else
return true;
end if;
end proc: |
http://rosettacode.org/wiki/Langton%27s_ant | Langton's ant | Langton's ant is a cellular automaton that models an ant sitting on a plane of cells, all of which are white initially, the ant facing in one of four directions.
Each cell can either be black or white.
The ant moves according to the color of the cell it is currently sitting in, with the following rules:
If the ce... | #Fortran | Fortran | program Langtons_Ant
implicit none
integer, parameter :: csize = 100
integer :: direction = 0, maxsteps = 20000
integer :: i, x, y
logical :: cells(csize,csize) = .true.
logical :: cflag
x = csize / 2; y = x
do i = 1, maxsteps
cflag = cells(x,y)
if(cflag) then
direction = directi... |
http://rosettacode.org/wiki/Kronecker_product | Kronecker product | Kronecker product
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Implement the Kronecker product of two matrices (arbitrary sized) resulting in a block matrix.
Test cases
Show results for each of the following two samples:
Sample 1 (from ... | #SuperCollider | SuperCollider | // the iterative version is derived from the javascript one here:
(
f = { |a, b|
var m = a.size;
var n = a[0].size;
var p = b.size;
var q = b[0].size;
var rtn = m * p;
var ctn = n * q;
var res = { 0.dup(ctn) }.dup(rtn);
m.do { |i|
n.do { |j|
p.do { |k|
q.do { |l|
res[p*i+k][q*j+l] = a[i][j] * b[k]... |
http://rosettacode.org/wiki/Kronecker_product | Kronecker product | Kronecker product
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Implement the Kronecker product of two matrices (arbitrary sized) resulting in a block matrix.
Test cases
Show results for each of the following two samples:
Sample 1 (from ... | #Swift | Swift | func kronecker(m1: [[Int]], m2: [[Int]]) -> [[Int]] {
let m = m1.count
let n = m1[0].count
let p = m2.count
let q = m2[0].count
let rtn = m * p
let ctn = n * q
var res = Array(repeating: Array(repeating: 0, count: ctn), count: rtn)
for i in 0..<m {
for j in 0..<n {
for k in 0..<p {
... |
http://rosettacode.org/wiki/Last_Friday_of_each_month | Last Friday of each month | Task
Write a program or a script that returns the date of the last Fridays of each month of a given year.
The year may be given through any simple input method in your language (command line, std in, etc).
Example of an expected output:
./last_fridays 2012
2012-01-27
2012-02-24
2012-03-30
2012-04-27
2012-05-25
20... | #Lasso | Lasso | define isLeapYear(y::integer) => {
#y % 400 == 0 ? return true
#y % 100 == 0 ? return false
#y % 4 == 0 ? return true
return false
}
define fridays(y::integer) => {
local(out = array)
loop(12) => {
local(last = 28)
loop_count == 2 && isLeapYear(#y) ? #last = 29
array(4,6,9,11) >> loop_count ? #last == 30
... |
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #Quackery | Quackery | [ sortwith
[ 2dup swap join
dip join $< ]
[] swap witheach join ] is largest-int ( [ --> $ )
$ '1 34 3 98 9 76 45 4' nest$ largest-int echo$ cr
$ '54 546 548 60' nest$ largest-int echo$ |
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #R | R | Largest_int_from_concat_ints <- function(vec){
#recursive function for computing all permutations
perm <- function(vec) {
n <- length(vec)
if (n == 1)
return(vec)
else {
x <- NULL
for (i in 1:n){
x <- rbind(x, cbind(vec[i], perm(vec[-i])))
}
return(x)
}
... |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #Modula-2 | Modula-2 |
MODULE LeastCommonMultiple;
FROM STextIO IMPORT
WriteString, WriteLn;
FROM SWholeIO IMPORT
WriteInt;
PROCEDURE GCD(M, N: INTEGER): INTEGER;
VAR
Tmp: INTEGER;
BEGIN
WHILE M <> 0 DO
Tmp := M;
M := N MOD M;
N := Tmp;
END;
RETURN N;
END GCD;
PROCEDURE LCM(M, N: INTEGER): INTEGER;
BEGIN
RET... |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #Nanoquery | Nanoquery | def gcd(a, b)
if (a < 1) or (b < 1)
throw new(InvalidNumberException, "gcd cannot be calculated on values < 1")
end
c = 0
while b != 0
c = a
a = b
b = c % b
end
return a
end
def lcm(m, n)
return (m * n) / gcd(m, n)
end
println lcm(12, 18)
println lcm(6, 14)
println lcm(1,2) = lcm(2,1) |
http://rosettacode.org/wiki/Levenshtein_distance | Levenshtein distance |
This page uses content from Wikipedia. The original article was at Levenshtein distance. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In information theory and computer science, the Levenshtein ... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref symbols nobinary
n = 0
w = ''
n = n + 1; w[0] = n; w[n] = "kitten sitting"
n = n + 1; w[0] = n; w[n] = "rosettacode raisethysword"
loop n = 1 to w[0]
say w[n].word(1) "->" w[n].word(2)":" levenshteinDistance(w[n].word(1), w[n].word(2))
end n
return
m... |
http://rosettacode.org/wiki/Letter_frequency | Letter frequency | Task
Open a text file and count the occurrences of each letter.
Some of these programs count all characters (including punctuation),
but some only count letters A to Z.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequen... | #Lasso | Lasso | local(
str = 'Hello world!',
freq = map
)
// as a loop. arguably quicker than query expression
loop(#str->size) => {
#freq->keys !>> #str->get(loop_count) ?
#freq->insert(#str->get(loop_count) = #str->values->find(#str->get(loop_count))->size)
}
// or
local(
str = 'Hello world!',
freq = map
)
// as query ex... |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | LeapYearQ[2002] |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #MATLAB_.2F_Octave | MATLAB / Octave | function TrueFalse = isLeapYear(year)
TrueFalse = (eomday(year,2) == 29);
end |
http://rosettacode.org/wiki/Langton%27s_ant | Langton's ant | Langton's ant is a cellular automaton that models an ant sitting on a plane of cells, all of which are white initially, the ant facing in one of four directions.
Each cell can either be black or white.
The ant moves according to the color of the cell it is currently sitting in, with the following rules:
If the ce... | #FreeBASIC | FreeBASIC | ' version 16-10-2016
' compile with: fbc -s gui
' a cell size of 4 x 4 pixels is used
' In FreeBASIC the 0,0 is the top left corner
ScreenRes 400,400,8 ' give a 100 by 100 field
Dim As UByte Ptr p = ScreenPtr
If p = 0 Then End ' p does not point to screen
Palette 0, 0, 0, 0 ' index 0 = black
Palett... |
http://rosettacode.org/wiki/Kronecker_product | Kronecker product | Kronecker product
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Implement the Kronecker product of two matrices (arbitrary sized) resulting in a block matrix.
Test cases
Show results for each of the following two samples:
Sample 1 (from ... | #Tcl | Tcl | # some helpers for matrices in nice string form:
proc parse_matrix {s} {
split [string trim $s] \n
}
proc print_matrix {m} {
foreach row $m {
puts [join [lmap x $row {format %3s $x}]]
}
}
# obvious imperative version using [foreach]
proc kroenecker {A B} {
foreach arow $A {
foreach b... |
http://rosettacode.org/wiki/Last_Friday_of_each_month | Last Friday of each month | Task
Write a program or a script that returns the date of the last Fridays of each month of a given year.
The year may be given through any simple input method in your language (command line, std in, etc).
Example of an expected output:
./last_fridays 2012
2012-01-27
2012-02-24
2012-03-30
2012-04-27
2012-05-25
20... | #LiveCode | LiveCode | function lastFriday yyyy
-- year,month num,day of month,hour in 24-hour time,minute,second,numeric day of week.
convert the long date to dateitems
put 1 into item 2 of it
put 1 into item 3 of it
put yyyy into item 1 of it
put it into startDate
convert startDate to dateItems
repeat with m... |
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #Racket | Racket |
#lang racket
(define (largest-int ns)
(string->number (apply ~a (sort ns (λ(x y) (string>? (~a x y) (~a y x)))))))
(map largest-int '((1 34 3 98 9 76 45 4) (54 546 548 60)))
;; -> '(998764543431 6054854654)
|
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #Raku | Raku | sub maxnum(*@x) {
[~] @x.sort: -> $a, $b { $b ~ $a leg $a ~ $b }
}
say maxnum <1 34 3 98 9 76 45 4>;
say maxnum <54 546 548 60>; |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref symbols nobinary
numeric digits 3000
runSample(arg)
return
-- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
method lcm(m_, n_) public static
L_ = m_ * n_ % gcd(m_, n_)
return L_
-- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~... |
http://rosettacode.org/wiki/Levenshtein_distance | Levenshtein distance |
This page uses content from Wikipedia. The original article was at Levenshtein distance. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In information theory and computer science, the Levenshtein ... | #Nim | Nim | import std/editdistance
echo editDistanceAscii("kitten", "sitting")
echo editDistanceAscii("rosettacode", "raisethysword") |
http://rosettacode.org/wiki/Letter_frequency | Letter frequency | Task
Open a text file and count the occurrences of each letter.
Some of these programs count all characters (including punctuation),
but some only count letters A to Z.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequen... | #Liberty_BASIC | Liberty BASIC |
open "text.txt" for input as #i
txt$ =input$( #i, lof( #i))
Le =len( txt$)
close #i
dim LetterFreqy( 255)
' txt$ =upper$( txt$)
for i =1 to Le
char =asc( mid$( txt$, i, 1))
if char >=32 then LetterFreqy( char) =LetterFreqy( char) +1
next i
for j =3... |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #Maxima | Maxima | leapyearp(year) := is(mod(year, 4) = 0 and
(mod(year, 100) # 0 or mod(year, 400) = 0))$ |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #Mercury | Mercury | :- pred is_leap_year(int::in) is semidet.
is_leap_year(Year) :-
( if Year mod 100 = 0 then Year mod 400 = 0 else Year mod 4 = 0 ). |
http://rosettacode.org/wiki/Langton%27s_ant | Langton's ant | Langton's ant is a cellular automaton that models an ant sitting on a plane of cells, all of which are white initially, the ant facing in one of four directions.
Each cell can either be black or white.
The ant moves according to the color of the cell it is currently sitting in, with the following rules:
If the ce... | #Furor | Furor |
###sysinclude X.uh
$ff0000 sto szin1
$ffffff sto szin2
2 sto pausetime
maxypixel 100 - sto YRES
maxxpixel sto XRES
zero ant
// Az ant iránykódjai:
// 0 : fel
// 1 : le
// 2 : jobbra
// 3 : balra
@XRES 2 / sto antx // Az ant kezdeti koordinátái
@YRES 2 / sto anty
myscreen "Furor monitor" @YRES @XRES graphic // C... |
http://rosettacode.org/wiki/Kronecker_product | Kronecker product | Kronecker product
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Implement the Kronecker product of two matrices (arbitrary sized) resulting in a block matrix.
Test cases
Show results for each of the following two samples:
Sample 1 (from ... | #VBScript | VBScript | ' Kronecker product - 05/04/2017
dim a(),b(),r()
sub kroneckerproduct '(a,b)
m=ubound(a,1): n=ubound(a,2)
p=ubound(b,1): q=ubound(b,2)
rtn=m*p
ctn=n*q
redim r(rtn,ctn)
for i=1 to m
for j=1 to n
for k=1 to p
for l=1 to q
r(p*(i-1)+k,q*(j-... |
http://rosettacode.org/wiki/Last_Friday_of_each_month | Last Friday of each month | Task
Write a program or a script that returns the date of the last Fridays of each month of a given year.
The year may be given through any simple input method in your language (command line, std in, etc).
Example of an expected output:
./last_fridays 2012
2012-01-27
2012-02-24
2012-03-30
2012-04-27
2012-05-25
20... | #Logo | Logo | ; Determine if a Gregorian calendar year is leap
to leap? :year
output (and
equal? 0 modulo :year 4
not member? modulo :year 400 [100 200 300]
)
end
; Convert Gregorian calendar date to a simple day count from
; RD 1 = January 1, 1 CE
to day_number :year :month :day
local "elapsed make "elapsed diff... |
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #Red | Red | Red []
foreach seq [[1 34 3 98 9 76 45 4] [54 546 548 60]] [
print rejoin sort/compare seq function [a b] [ (rejoin [a b]) > rejoin [b a] ]
]
|
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #REXX | REXX | /*REXX program constructs the largest integer from an integer list using concatenation.*/
@.=.; @.1 = 1 34 3 98 9 76 45 4 /*the 1st integer list to be used. */
@.2 = 54 546 548 60 /* " 2nd " " " " " */
@.3 = 4 45 54 5 ... |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #Nim | Nim | proc gcd(u, v: int): auto =
var
u = u
v = v
while v != 0:
u = u %% v
swap u, v
abs(u)
proc lcm(a, b: int): auto = abs(a * b) div gcd(a, b)
echo lcm(12, 18)
echo lcm(-6, 14) |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #Objeck | Objeck |
class LCM {
function : Main(args : String[]) ~ Nil {
IO.Console->Print("lcm(35, 21) = ")->PrintLine(lcm(21,35));
}
function : lcm(m : Int, n : Int) ~ Int {
return m / gcd(m, n) * n;
}
function : gcd(m : Int, n : Int) ~ Int {
tmp : Int;
while(m <> 0) { tmp := m; m := n % m; n := tmp; };
... |
http://rosettacode.org/wiki/Levenshtein_distance | Levenshtein distance |
This page uses content from Wikipedia. The original article was at Levenshtein distance. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In information theory and computer science, the Levenshtein ... | #Objeck | Objeck | class Levenshtein {
function : Main(args : String[]) ~ Nil {
if(args->Size() = 2) {
s := args[0]; t := args[1]; d := Distance(s,t);
"{$s} -> {$t} = {$d}"->PrintLine();
};
}
function : native : Distance(s : String,t : String) ~ Int {
d := Int->New[s->Size() + 1, t->Size() + 1];
for(i ... |
http://rosettacode.org/wiki/Letter_frequency | Letter frequency | Task
Open a text file and count the occurrences of each letter.
Some of these programs count all characters (including punctuation),
but some only count letters A to Z.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequen... | #Lua | Lua | -- Return entire contents of named file
function readFile (filename)
local file = assert(io.open(filename, "r"))
local contents = file:read("*all")
file:close()
return contents
end
-- Return a closure to keep track of letter counts
function tally ()
local t = {}
-- Add x to tally if supplied, return tal... |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #min | min | (mod 0 ==) :divisor?
(((400 divisor?) (4 divisor?) (100 divisor? not)) cleave and or) :leap-year? |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #MiniScript | MiniScript | isLeapYear = function(year)
return year%4==0 and (year % 100 or not year % 400)
end function |
http://rosettacode.org/wiki/Langton%27s_ant | Langton's ant | Langton's ant is a cellular automaton that models an ant sitting on a plane of cells, all of which are white initially, the ant facing in one of four directions.
Each cell can either be black or white.
The ant moves according to the color of the cell it is currently sitting in, with the following rules:
If the ce... | #Gambas | Gambas | 'This code will create a GUI Form to display the result
hGridView As GridView 'The display is on a GridView
iCol As Integer = 38 'Column start position
iRow As Integer = 30 'Row ... |
http://rosettacode.org/wiki/Kronecker_product | Kronecker product | Kronecker product
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Implement the Kronecker product of two matrices (arbitrary sized) resulting in a block matrix.
Test cases
Show results for each of the following two samples:
Sample 1 (from ... | #Wren | Wren | import "/fmt" for Fmt
import "/matrix" for Matrix
var a1 = [
[1, 2],
[3, 4]
]
var a2 = [
[0, 5],
[6, 7]
]
var a3 = [
[0, 1, 0],
[1, 1, 1],
[0, 1, 0]
]
var a4 = [
[1, 1, 1, 1],
[1, 0, 0, 1],
[1, 1, 1, 1]
]
var m1 = Matrix.new(a1)
var m2 = Matrix.new(a2)
Fmt.mprint(m1.kr... |
http://rosettacode.org/wiki/Last_Friday_of_each_month | Last Friday of each month | Task
Write a program or a script that returns the date of the last Fridays of each month of a given year.
The year may be given through any simple input method in your language (command line, std in, etc).
Example of an expected output:
./last_fridays 2012
2012-01-27
2012-02-24
2012-03-30
2012-04-27
2012-05-25
20... | #Lua | Lua | function isLeapYear (y)
return (y % 4 == 0 and y % 100 ~=0) or y % 400 == 0
end
function dayOfWeek (y, m, d)
local t = os.time({year = y, month = m, day = d})
return os.date("%A", t)
end
function lastWeekdays (wday, year)
local monthLength, day = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
... |
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #Ring | Ring |
nums=[1,34,3,98,9,76,45,4]
see largestInt(8) + nl
nums=[54,546,548,60]
see largestInt(4) + nl
func largestInt len
l = ""
sorted = false
while not sorted
sorted=true
for i=1 to len-1
a=string(nums[i])
b=string(nums[i+1])
if a+b<b+a
temp = nums[i]
n... |
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #Ruby | Ruby | def icsort nums
nums.sort { |x, y| "#{y}#{x}" <=> "#{x}#{y}" }
end
[[54, 546, 548, 60], [1, 34, 3, 98, 9, 76, 45, 4]].each do |c|
p c # prints nicer in Ruby 1.8
puts icsort(c).join
end |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #OCaml | OCaml | let rec gcd u v =
if v <> 0 then (gcd v (u mod v))
else (abs u)
let lcm m n =
match m, n with
| 0, _ | _, 0 -> 0
| m, n -> abs (m * n) / (gcd m n)
let () =
Printf.printf "lcm(35, 21) = %d\n" (lcm 21 35) |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #Oforth | Oforth | 12 18 lcm |
http://rosettacode.org/wiki/Levenshtein_distance | Levenshtein distance |
This page uses content from Wikipedia. The original article was at Levenshtein distance. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In information theory and computer science, the Levenshtein ... | #Objective-C | Objective-C | @interface NSString (levenshteinDistance)
- (NSUInteger)levenshteinDistanceToString:(NSString *)string;
@end
@implementation NSString (levenshteinDistance)
- (NSUInteger)levenshteinDistanceToString:(NSString *)string {
NSUInteger sl = [self length];
NSUInteger tl = [string length];
NSUInteger *d = calloc(... |
http://rosettacode.org/wiki/Letter_frequency | Letter frequency | Task
Open a text file and count the occurrences of each letter.
Some of these programs count all characters (including punctuation),
but some only count letters A to Z.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequen... | #M2000_Interpreter | M2000 Interpreter |
document file1$={Open a text file and count the occurrences of each letter.
Some of these programs count all characters (including punctuation), but some only count letters A to Z
}
const Ansi=3, nl$=chr$(13)+chr$(10), Console=-2
save.doc file1$, "checkdoc.txt", Ansi
open "checkdoc.txt" for input as F
buffer onec... |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #MIPS_Assembly | MIPS Assembly |
IsLeap: andi $a1, $a0, 3 #a0 is year to test
bnez $a1 NotLeap
li $a1, 100
div $a0, $a1
mfhi $a1
bnez $a1, Leap
mflo $a1
andi $a1, $a1, 3
bnez $a1, NotLeap
Leap: li $v0, 1
jr $ra
NotLeap:li $v0, 0
jr $ra
|
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #.D0.9C.D0.9A-61.2F52 | МК-61/52 | П0 1 0 0 / {x} x=0 14 ИП0 4
0 0 ПП 18 ИП0 4 ПП 18 / {x}
x=0 24 1 С/П 0 С/П |
http://rosettacode.org/wiki/Langton%27s_ant | Langton's ant | Langton's ant is a cellular automaton that models an ant sitting on a plane of cells, all of which are white initially, the ant facing in one of four directions.
Each cell can either be black or white.
The ant moves according to the color of the cell it is currently sitting in, with the following rules:
If the ce... | #GFA_Basic | GFA Basic |
'
' Langton's ant
'
' World is a global boolean array, 100x100 in size
width%=100
height%=100
DIM world!(width%,height%)
ARRAYFILL world!(),FALSE
' Time in world
time%=0
' Ant is represented by a global three-element array
' holding: x, y, direction [0=north,1=west,2=south,3=east]
DIM ant%(3)
'
@setup_ant
@run_ant
@d... |
http://rosettacode.org/wiki/Kronecker_product | Kronecker product | Kronecker product
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Implement the Kronecker product of two matrices (arbitrary sized) resulting in a block matrix.
Test cases
Show results for each of the following two samples:
Sample 1 (from ... | #zkl | zkl | var [const] GSL=Import.lib("zklGSL"); // libGSL (GNU Scientific Library)
fcn kronecker(A,B){
m,n, p,q := A.rows,A.cols, B.rows,B.cols;
r:=GSL.Matrix(m*p, n*q);
foreach i,j,k,l in (m,n,p,q){ r[p*i + k, q*j + l]=A[i,j]*B[k,l] }
r
} |
http://rosettacode.org/wiki/Last_Friday_of_each_month | Last Friday of each month | Task
Write a program or a script that returns the date of the last Fridays of each month of a given year.
The year may be given through any simple input method in your language (command line, std in, etc).
Example of an expected output:
./last_fridays 2012
2012-01-27
2012-02-24
2012-03-30
2012-04-27
2012-05-25
20... | #Maple | Maple | fridays := proc(year)
local i, dt, change, last_days;
last_days := [31,28,31,30,31,30,31,31,30,31,30,31];
if (Calendar:-IsLeapYear(year)) then
last_days[2] := 28;
end if;
for i to 12 do
dt := Date(year, i, last_days[i]);
change := 0;
if not(Calendar:-DayOfWeek(dt) = 6) then
change := -(Calendar:-DayOfW... |
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #Run_BASIC | Run BASIC | a1$ = "1, 34, 3, 98, 9, 76, 45, 4"
a2$ = "54,546,548,60"
print "Max Num ";a1$;" = ";maxNum$(a1$)
print "Max Num ";a2$;" = ";maxNum$(a2$)
function maxNum$(a1$)
while word$(a1$,i+1,",") <> ""
i = i + 1
a$(i) = trim$(word$(a1$,i,","))
wend
s = 1
while s = 1
s = 0
for j = 1 to i -1
if a$(j)+a$(j+1) < a$(j+1)+a$... |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #ooRexx | ooRexx |
say lcm(18, 12)
-- calculate the greatest common denominator of a numerator/denominator pair
::routine gcd private
use arg x, y
loop while y \= 0
-- check if they divide evenly
temp = x // y
x = y
y = temp
end
return x
-- calculate the least common multiple of a numerator/denomin... |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #Order | Order | #include <order/interpreter.h>
#define ORDER_PP_DEF_8gcd ORDER_PP_FN( \
8fn(8U, 8V, \
8if(8isnt_0(8V), 8gcd(8V, 8remainder(8U, 8V)), 8U)))
#define ORDER_PP_DEF_8lcm ORDER_PP_FN( \
8fn(8X, 8Y, \
8if(8or(8is_0(8X), 8is_0(8Y)), \
0, ... |
http://rosettacode.org/wiki/Levenshtein_distance | Levenshtein distance |
This page uses content from Wikipedia. The original article was at Levenshtein distance. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In information theory and computer science, the Levenshtein ... | #OCaml | OCaml | let minimum a b c =
min a (min b c)
let levenshtein_distance s t =
let m = String.length s
and n = String.length t in
(* for all i and j, d.(i).(j) will hold the Levenshtein distance between
the first i characters of s and the first j characters of t *)
let d = Array.make_matrix (m+1) (n+1) 0 in
fo... |
http://rosettacode.org/wiki/Letter_frequency | Letter frequency | Task
Open a text file and count the occurrences of each letter.
Some of these programs count all characters (including punctuation),
but some only count letters A to Z.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequen... | #Maple | Maple | StringTools:-CharacterFrequencies(readbytes("File.txt",infinity,TEXT)) |
http://rosettacode.org/wiki/Leap_year | Leap year | Task
Determine whether a given year is a leap year in the Gregorian calendar.
See also
Leap year (wiki)
| #Modula-2 | Modula-2 | MODULE LeapYear;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,ReadChar;
PROCEDURE IsLeapYear(year : INTEGER) : BOOLEAN;
BEGIN
IF year MOD 100 = 0 THEN
RETURN year MOD 400 = 0;
END;
RETURN year MOD 4 = 0
END IsLeapYear;
PROCEDURE Print(year : INTEGER);
VAR
buf : ARR... |
http://rosettacode.org/wiki/Langton%27s_ant | Langton's ant | Langton's ant is a cellular automaton that models an ant sitting on a plane of cells, all of which are white initially, the ant facing in one of four directions.
Each cell can either be black or white.
The ant moves according to the color of the cell it is currently sitting in, with the following rules:
If the ce... | #Go | Go | package main
import (
"fmt"
"image"
"image/color"
"image/draw"
"image/png"
"os"
)
const (
up = iota
rt
dn
lt
)
func main() {
bounds := image.Rect(0, 0, 100, 100)
im := image.NewGray(bounds)
gBlack := color.Gray{0}
gWhite := color.Gray{255}
draw.Draw(im, ... |
http://rosettacode.org/wiki/Last_Friday_of_each_month | Last Friday of each month | Task
Write a program or a script that returns the date of the last Fridays of each month of a given year.
The year may be given through any simple input method in your language (command line, std in, etc).
Example of an expected output:
./last_fridays 2012
2012-01-27
2012-02-24
2012-03-30
2012-04-27
2012-05-25
20... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | FridaysOfYear[Y_] :=
NestWhile[(DaysPlus[#, - 1]) &, #, (DateString[#, "DayName"] != "Friday") &] & /@
Most@Reverse@NestList [DaysPlus[# /. {x_, y_, X_} -> {x, y, 1}, - 1] &, {Y + 1, 1, 1}, 12]
Column@FridaysOfYear[2012] |
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #Rust | Rust | fn maxcat(a: &mut [u32]) {
a.sort_by(|x, y| {
let xy = format!("{}{}", x, y);
let yx = format!("{}{}", y, x);
xy.cmp(&yx).reverse()
});
for x in a {
print!("{}", x);
}
println!();
}
fn main() {
maxcat(&mut [1, 34, 3, 98, 9, 76, 45, 4]);
maxcat(&mut [54, 546,... |
http://rosettacode.org/wiki/Largest_int_from_concatenated_ints | Largest int from concatenated ints | Task
Given a set of positive integers, write a function to order the integers in such a way that the concatenation of the numbers forms the largest possible integer and return this integer.
Use the following two sets of integers as tests and show your program output here.
{1, 34, 3, 98, 9, 76, 45, 4}
{54,... | #S-lang | S-lang | define catcmp(a, b)
{
a = string(a);
b = string(b);
return strcmp(b+a, a+b);
}
define maxcat(arr)
{
arr = arr[array_sort(arr, &catcmp)];
variable result = "", elem;
foreach elem (arr)
result += string(elem);
return result;
}
print("max of series 1 is " + maxcat([1, 34, 3, 98, 9, 76, 45, 4]... |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #PARI.2FGP | PARI/GP | lcm |
http://rosettacode.org/wiki/Least_common_multiple | Least common multiple | Least common multiple
You are encouraged to solve this task according to the task description, using any language you may know.
Task
Compute the least common multiple (LCM) of two integers.
Given m and n, the least common multiple is the smallest positive integer that has both m and n as factor... | #Pascal | Pascal | Program LeastCommonMultiple(output);
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
function lcm(a, b: longint): longint;
begin
result := a;
while (result mod b) <> 0 do
inc(result, a);
end;
begin
writeln('The least common multiple of 12 and 18 is: ', lcm(12, 18));
end. |
http://rosettacode.org/wiki/Levenshtein_distance | Levenshtein distance |
This page uses content from Wikipedia. The original article was at Levenshtein distance. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
In information theory and computer science, the Levenshtein ... | #ooRexx | ooRexx |
say "kitten -> sitting:" levenshteinDistance("kitten", "sitting")
say "rosettacode -> raisethysword:" levenshteinDistance("rosettacode", "raisethysword")
::routine levenshteinDistance
use arg s, t
s = s~lower
t = t~lower
m = s~length
n = t~length
-- for all i and j, d[i,j] will hold the Levenshtein ... |
http://rosettacode.org/wiki/Letter_frequency | Letter frequency | Task
Open a text file and count the occurrences of each letter.
Some of these programs count all characters (including punctuation),
but some only count letters A to Z.
Other tasks related to string operations:
Metrics
Array length
String length
Copy a string
Empty string (assignment)
Counting
Word frequen... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | Tally[Characters[Import["file.txt","Text"]]] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.