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/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 ...
#PureBasic
PureBasic
Procedure LevenshteinDistance(A_string$, B_String$) Protected m, n, i, j, min, k, l m = Len(A_string$) n = Len(B_String$) Dim D(m, n)   For i=0 To m: D(i,0)=i: Next For j=0 To n: D(0,j)=j: Next   For j=1 To n For i=1 To m If Mid(A_string$,i,1) = Mid(B_String$,j,1) D(i,j) = D(i-1, j-1); n...
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...
#Phix
Phix
with javascript_semantics sequence lc = repeat(0,#7E) --string text = get_text(command_line()[$]) string text = join(unix_dict(17)) for i=1 to length(text) do integer ch = text[i] if ch=-1 then exit end if if ch>=' ' and ch<#7F then lc[ch] += 1 end if end for integer count = 0 for i=' ' to #7E...
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)
#Picat
Picat
go => foreach(Y in [1600,1700,1899,1900,2000,2006,2012]) println(Y=cond(leap_year(Y),leap_year,not_leap_year)) end, nl.   leap_year(Year) => (Year mod 4 == 0, Year mod 100 != 0)  ; Year mod 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)
#PicoLisp
PicoLisp
(de isLeapYear (Y) (bool (date Y 2 29)) )
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...
#Lua
Lua
local socket = require 'socket' -- needed for socket.sleep local curses = require 'curses' -- used for graphics   local naptime = 0.02 -- seconds local world_x, world_y = 100, 100   local world = (function (x, y) local wrl = {} for i = 1, y do wrl[i] = {} for j = 1, x do wrl[i][j] = 0 end end return wrl en...
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...
#PicoLisp
PicoLisp
(de lastFridays (Y) (for M 12 (prinl (dat$ (find '((D) (= "Friday" (day D))) (mapcar '((D) (date Y M D)) `(range 31 22)) ) "-" ) ) ) )
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...
#Scala
Scala
def gcd(a: Int, b: Int):Int=if (b==0) a.abs else gcd(b, a%b) def lcm(a: Int, b: Int)=(a*b).abs/gcd(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...
#Scheme
Scheme
  >(define gcd (lambda (a b) (if (zero? b) a (gcd b (remainder a b))))) >(define lcm (lambda (a b) (if (or (zero? a) (zero? b)) 0 (abs (* b (floor (/ a (gcd a b)))))))) >(lcm 12 18) 36
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 ...
#Python
Python
def levenshteinDistance(str1, str2): m = len(str1) n = len(str2) d = [[i] for i in range(1, m + 1)] # d matrix rows d.insert(0, list(range(0, n + 1))) # d matrix columns for j in range(1, n + 1): for i in range(1, m + 1): if str1[i - 1] == str2[j - 1]: # Python (string) is ...
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...
#Phixmonti
Phixmonti
0 255 repeat var ascCodes   "unixdict.txt" "r" fopen var file   file 0 < not if true while file fgets dup 0 < not if len 1 swap 2 tolist for var i i get ascCodes over get 1 + rot set var ascCodes endfor drop true else drop false endif endwhile   ascCodes len for var i i...
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)
#PL.2FI
PL/I
dcl mod builtin; dcl year fixed bin (31);   do year = 1900, 1996 to 2001; if mod(year, 4) = 0 & (mod(year, 100) ^= 0 | mod(year, 400) = 0) then put skip edit(year, 'is a leap year') (p'9999b', a); else put skip edit(year, 'is not a leap year') (p'9999b', a); 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...
#M2000_Interpreter
M2000 Interpreter
  Module Ant { Form 120,102 N=100 Enum CellColor {black=0,white=#FFFFFF} Enum Direction{North=90, West=180, South=270, East=0} Function Rotate(cd as Direction, clockwise=true) { cd=(cd+if(clockwise->270,90)) mod 360 =cd ' return a Direction Enum type }   dim rect(1 to N, 1 to N)=white cx=N div 2 cy=N di...
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...
#Pike
Pike
int(0..1) last_friday(object day) { return day->week_day() == 5 && day->month_day() > day->month()->number_of_days()-7; }   int main(int argc, array argv) { array days = filter(Calendar.Year((int)argv[1])->months()->days()[*], last_friday); write("%{%s\n%}", days->format_ymd()); return 0; }
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...
#Seed7
Seed7
$ include "seed7_05.s7i";   const func integer: gcd (in var integer: a, in var integer: b) is func result var integer: gcd is 0; local var integer: help is 0; begin while a <> 0 do help := b rem a; b := a; a := help; end while; gcd := b; end func;   const func integer: 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...
#SenseTalk
SenseTalk
function gcd m, n repeat while m is greater than 0 put m into temp put n modulo m into m put temp into n end repeat return n end gcd   function lcm m, n return m divided by gcd(m, n) times n end 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 ...
#Racket
Racket
#lang racket   (define (levenshtein a b) (define (ls0 a-index b-index) (cond [(or (= a-index -1) (= b-index -1)) (abs (- a-index b-index))] [else (define a-char (string-ref a a-index)) (define b-char (string-ref b b-index)) (if (equal? a-char b-char) (ls ...
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...
#PHP
PHP
<?php print_r(array_count_values(str_split(file_get_contents($argv[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)
#PL.2FM
PL/M
100H: /* DETERMINE WHETHER SOME YEARS ARE LEAP YEARS OR NOT */   /* CP/M BDOS SYSTEM CALL */ BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5;END; /* CONSOLE OUTPUT ROUTINES */ PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END; PR$STRING: PROCEDURE( S ); DECLARE S ADDRE...
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...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
direction = 1; data = SparseArray[{{50, 50} -> -1}, {100, 100}, 1]; NestWhile[ {Re@#, Im@#} &@(direction *= (data[[Sequence @@ #]] *= -1) I) + # &, {50, 50}, 1 <= Min@# <= Max@# <= 100 &]; Image@data
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...
#PL.2FI
PL/I
  Fridays: procedure (year) options (main); /* 8 January 2013 */ declare year character (4) varying; declare start fixed binary (31); declare months fixed decimal (2) initial (0); declare (current_month, month_one_week_hence) character (2);   put list ('Last Fridays in each month for the year ' || year |...
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...
#Sidef
Sidef
say Math.lcm(1001, 221)
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...
#Smalltalk
Smalltalk
12 lcm: 18
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 ...
#Raku
Raku
sub levenshtein-distance ( Str $s, Str $t --> Int ) { my @s = *, |$s.comb; my @t = *, |$t.comb;   my @d; @d[$_; 0] = $_ for ^@s.end; @d[ 0; $_] = $_ for ^@t.end;   for 1..@s.end X 1..@t.end -> ($i, $j) { @d[$i; $j] = @s[$i] eq @t[$j] ?? @d[$i-1; $j-1] # No operation req...
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...
#Picat
Picat
go =>  % removing '\n' first Chars = delete_all(read_file_chars("unixdict.txt"),'\n'), M = letter_freq(Chars), println(M.sort_map(values).reverse).   % Get the letter frequency letter_freq(S) = Map => Map = new_map(), foreach(C in S) Map.put(C,Map.get(C,0)+1) end.   % Different sorting function on maps...
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)
#PostScript
PostScript
/isleapyear { dup dup 4 mod 0 eq  % needs to be divisible by 4 exch 100 mod 0 ne  % but not by 100 and exch 400 mod 0 eq  % or by 400 or } def
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)
#PowerShell
PowerShell
$Year = 2016 [System.DateTime]::IsLeapYear( $Year )
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...
#MATLAB_.2F_Octave
MATLAB / Octave
function u = langton_ant(n) if nargin<1, n=100; end; A = sparse(n,n); % white P = [n/2;n/2]; % Positon D = 3; % index of direction 0-3 T = [1,0,-1,0;0,1,0,-1]; % 4 directions k = 0; while (1) k = k+1; a = A(P(1),P(2)); A(P(1),P(2)) = ~a; if ( a ) D = mod(D+1,4); else D = mod(D-1,4); ...
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...
#PowerShell
PowerShell
  function last-dayofweek { param( [Int][ValidatePattern("[1-9][0-9][0-9][0-9]")]$year, [String][validateset('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')]$dayofweek ) $date = (Get-Date -Year $year -Month 1 -Day 1) while($date.DayOfWeek -ne $dayofweek) {$date = $date....
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...
#Sparkling
Sparkling
function factors(n) { var f = {};   for var i = 2; n > 1; i++ { while n % i == 0 { n /= i; f[i] = f[i] != nil ? f[i] + 1 : 1; } }   return f; }   function GCD(n, k) { let f1 = factors(n); let f2 = factors(k);   let fs = map(f1, function(factor, multiplicity) { let m = f2[factor]; return m == nil ? ...
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...
#Standard_ML
Standard ML
val rec gcd = fn (x, 0) => abs x | p as (_, y) => gcd (y, Int.rem p)   val lcm = fn p as (x, y) => Int.quot (abs (x * y), gcd p)
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 ...
#REXX
REXX
/*REXX program calculates and displays the Levenshtein distance between two strings. */ call Levenshtein 'kitten' , "sitting" call Levenshtein 'rosettacode' , "raisethysword" call Levenshtein 'Sunday' , "Saturday" call Levenshtein 'V...
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...
#PicoLisp
PicoLisp
(let Freq NIL (in "file.txt" (while (char) (accu 'Freq @ 1)) ) (sort Freq) )
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)
#Prolog
Prolog
leap_year(L) :- partition(is_leap_year, L, LIn, LOut), format('leap years : ~w~n', [LIn]), format('not leap years : ~w~n', [LOut]).   is_leap_year(Year) :- R4 is Year mod 4, R100 is Year mod 100, R400 is Year mod 400, ( (R4 = 0, R100 \= 0); R400 = 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)
#PureBasic
PureBasic
Procedure isLeapYear(Year) If (Year%4=0 And Year%100) Or Year%400=0 ProcedureReturn #True Else ProcedureReturn #False EndIf EndProcedure
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...
#Nim
Nim
import strutils, sequtils   type Direction = enum up, right, down, left Color = enum white, black   const width = 75 height = 52 maxSteps = 12_000   var m: array[height, array[width, Color]] dir = up x = width div 2 y = height div 2   var i = 0 while i < maxSteps and x in 0 ..< width and y in 0 ..< he...
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...
#PureBasic
PureBasic
Procedure LastFridayOfEachMonth(yyyy.i,List lfem.i()) Define dv.i=ParseDate("%yyyy",Str(yyyy)), mv.i=1 NewList d.i() For d=1 To 365 dv=AddDate(dv,#PB_Date_Day,1) If DayOfWeek(dv)=5 AddElement(d()) : d()=dv EndIf Next dv=0 For mv=1 To 12 ForEach d() If dv<d() And Month(d())=...
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...
#Swift
Swift
func lcm(a:Int, b:Int) -> Int { return abs(a * b) / gcd_rec(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...
#Tcl
Tcl
proc lcm {p q} { set m [expr {$p * $q}] if {!$m} {return 0} while 1 { set p [expr {$p % $q}] if {!$p} {return [expr {$m / $q}]} set q [expr {$q % $p}] if {!$q} {return [expr {$m / $p}]} } }
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 ...
#Ring
Ring
  # Project : Levenshtein distance   load "stdlib.ring" see "" + "distance(kitten, sitting) = " + levenshteindistance("kitten", "sitting") + nl see "" + "distance(saturday, sunday) = " + levenshteindistance("saturday", "sunday") + nl see "" + "distance(rosettacode, raisethysword) = " + levenshteindistance("rosettacode"...
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...
#Pike
Pike
  string all = Stdio.read_file("README.md"); mapping res = ([]); foreach(all/1, string char) res[char]++; write("%O\n", res);  
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)
#Python
Python
import calendar calendar.isleap(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)
#Q
Q
ly:{((0<>x mod 100) | 0=x mod 400) & 0=x mod 4} / Return 1b if x is a leap year; 0b otherwise
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...
#OCaml
OCaml
open Graphics   type dir = North | East | South | West   let turn_left = function | North -> West | East -> North | South -> East | West -> South   let turn_right = function | North -> East | East -> South | South -> West | West -> North   let move (x, y) = function | North -> x, y + 1 | East -...
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...
#Python
Python
import calendar   def last_fridays(year): for month in range(1, 13): last_friday = max(week[calendar.FRIDAY] for week in calendar.monthcalendar(year, month)) print('{:4d}-{:02d}-{:02d}'.format(year, month, last_friday))
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...
#TI-83_BASIC
TI-83 BASIC
lcm(12,18 36
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...
#TSE_SAL
TSE SAL
// library: math: get: least: common: multiple <description></description> <version control></version control> <version>1.0.0.0.2</version> <version control></version control> (filenamemacro=getmacmu.s) [<Program>] [<Research>] [kn, ri, su, 20-01-2013 14:36:11] INTEGER PROC FNMathGetLeastCommonMultipleI( INTEGER x1I, I...
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 ...
#Ruby
Ruby
module Levenshtein   def self.distance(a, b) a, b = a.downcase, b.downcase costs = Array(0..b.length) # i == 0 (1..a.length).each do |i| costs[0], nw = i, i - 1 # j == 0; nw is lev(i-1, j) (1..b.length).each do |j| costs[j], nw = [costs[j] + 1, costs[j-1] + 1, a[i-1] == b[j-1] ? nw : ...
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...
#PL.2FI
PL/I
  frequencies: procedure options (main); declare tallies(26) fixed binary static initial ((26) 0); declare alphabet character (26) static initial ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'); declare c character (1), i fixed binary; declare in file;   open file (in) title ('/LETTER.DAT,type(text),recsize(200)') ...
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)
#Quackery
Quackery
[ dup 400 mod 0 = iff [ drop true ] done dup 100 mod 0 = iff [ drop false ] done 4 mod 0 = ] is leap? ( n --> b )
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)
#R
R
isLeapYear <- function(year) { ifelse(year%%100==0, year%%400==0, year%%4==0) }   for (y in c(1900, 1994, 1996, 1997, 2000)) { cat(y, ifelse(isLeapYear(y), "is", "isn't"), "a leap year.\n") }
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...
#Octave
Octave
clear E=100 % Size of lattice. N=11200 % Number of iterations. z(1:1:E^2)=-1; % Init lattice rotations (-1=right, 1=left) k(1:1:E^2)=0; k(1)=(E^2+E)/2; % Init the Ant @ 50,50 for t=1:1:N; k(t+1)=mod(k(t)+real(round((0.5*(E+1)*exp(i*pi/4*(trace(diag(z))-E^2)))-(0.5*(E-1)*exp(-i*pi/4*(trace(diag(z))-E^...
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...
#Quackery
Quackery
[ over 3 < if [ 1 - ] dup 4 / over + over 100 / - swap 400 / + swap 1 - [ table 0 3 2 5 0 3 5 1 4 6 2 4 ] + + 7 mod ] is dayofweek ( day month year --> weekday )   [ dup 400 mod 0 = iff [ drop true ] done dup 100 mod 0 = iff [ drop false ] ...
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...
#TXR
TXR
$ txr -p '(lcm (expt 2 123) (expt 6 49) 17)' 43259338018880832376582582128138484281161556655442781051813888
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...
#TypeScript
TypeScript
// Least common multiple   function gcd(m: number, n: number): number { var tmp: number; while (m != 0) { tmp = m; m = n % m; n = tmp; } return n; }   function lcm(m: number, n: number): number { return Math.floor(m / gcd(m, n)) * n; }   console.log(`LCM(35, 21) = ${lcm(35, 21)}`);  
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 ...
#Run_BASIC
Run BASIC
print levenshteinDistance("kitten", "sitting") print levenshteinDistance("rosettacode", "raisethysword") end function levenshteinDistance(s1$, s2$) n = len(s1$) m = len(s2$) if n = 0 then levenshteinDistance = m goto [ex] end if if m = 0 then levenshteinDistance = n g...
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...
#PowerShell
PowerShell
  function frequency ($string) { $arr = $string.ToUpper().ToCharArray() |where{$_ -match '[A-KL-Z]'} $n = $arr.count $arr | group | foreach{ [pscustomobject]@{letter = "$($_.name)"; frequency = "$([math]::round($($_.Count/$n),5))"; count = "$($_.count)"} } | sort letter } $file = "$($MyInvocat...
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)
#Racket
Racket
(define (leap-year? y) (and (zero? (modulo y 4)) (or (positive? (modulo y 100)) (zero? (modulo y 400)))))
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)
#Raku
Raku
say "$year is a {Date.is-leap-year($year) ?? 'leap' !! 'common'} year."
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...
#Ol
Ol
  #!/usr/bin/ol (import (otus random!))   (define MAX 65536) ; should be power of two ; size of game board (should be less than MAX) (define WIDTH 170) (define HEIGHT 96)   ; helper function (define (hash x y) (let ((x (mod (+ x WIDTH) WIDTH)) (y (mod (+ y HEIGHT) HEIGHT))) (+ (* y MAX) x)))   ;; ; help...
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...
#R
R
year = commandArgs(T) d = as.Date(paste0(year, "-01-01")) fridays = d + seq(by = 7, (5 - as.POSIXlt(d)$wday) %% 7, 364 + (months(d + 30 + 29) == "February")) message(paste(collapse = "\n", fridays[tapply( seq_along(fridays), as.POSIXlt(fridays)$mon, max)]))
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...
#uBasic.2F4tH
uBasic/4tH
Print "LCM of 12 : 18 = "; FUNC(_LCM(12,18))   End     _GCD_Iterative_Euclid Param(2) Local (1) Do While b@ c@ = a@ a@ = b@ b@ = c@ % b@ Loop Return (ABS(a@))     _LCM Param(2) If a@*b@ Return (ABS(a@*b@)/FUNC(_GCD_Iterative_Euclid(a@,b@))) Else Return (0) 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...
#UNIX_Shell
UNIX Shell
gcd() { # Calculate $1 % $2 until $2 becomes zero. until test 0 -eq "$2"; do # Parallel assignment: set -- 1 2 set -- "$2" "`expr "$1" % "$2"`" done   # Echo absolute value of $1. test 0 -gt "$1" && set -- "`expr 0 - "$1"`" echo "$1" }   lcm() { set -- "$1" "$2" "`gcd "$1" "$2"`" set -- "`expr "$1" \* "$2" ...
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 ...
#Rust
Rust
fn main() { println!("{}", levenshtein_distance("kitten", "sitting")); println!("{}", levenshtein_distance("saturday", "sunday")); println!("{}", levenshtein_distance("rosettacode", "raisethysword")); }   fn levenshtein_distance(word1: &str, word2: &str) -> usize { let w1 = word1.chars().collect::<Vec<_...
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...
#Prolog
Prolog
frequency(File) :- read_file_to_codes(File, Code, []),   % we only keep alphabetic codes include(my_code_type, Code, LstCharCode),   % we translate char_codes into uppercase atoms. maplist(my_upcase, LstCharCode, LstChar),   % sort and pack the list msort(LstChar, SortLstChar), packList(SortLstChar, Freq), map...
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)
#Raven
Raven
define is_leap_year use $year $year 100 % 0 = if $year 400 % 0 = $year 4 % 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)
#REBOL
REBOL
leap-year?: func [ {Returns true if the specified year is a leap year; false otherwise.} year [date! integer!] /local div? ][ either date? year [year: year/year] [ if negative? year [throw make error! join [script invalid-arg] year] ] ; The key numbers are 4, 100, and 400, combined as f...
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...
#PARI.2FGP
PARI/GP
langton()={ my(M=matrix(100,100),x=50,y=50,d=0); while(x && y && x<=100 && y<=100, d=(d+if(M[x,y],1,-1))%4; M[x,y]=!M[x,y]; if(d%2,x+=d-2,y+=d-1); ); M }; show(M)={ my(d=sum(i=1,#M[,1],sum(j=1,#M,M[i,j])),u=vector(d),v=u,t); for(i=1,#M[,1],for(j=1,#M,if(M[i,j],v[t++]=i;u[t]=j))); plothraw(u,v)...
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...
#Racket
Racket
  #lang racket (require srfi/19 math)   (define (days-in-month m y) (define lengths #(0 31 #f 31 30 31 30 31 31 30 31 30 31)) (define d (vector-ref lengths m)) (or d (days-in-feb y)))   (define (leap-year? y) (and (divides? 4 y) (or (not (divides? 100 y)) (divides? 400 y))))   (define (days-in...
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...
#Ursa
Ursa
import "math" out (lcm 12 18) endl console
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...
#Vala
Vala
  int lcm(int a, int b){ /*Return least common multiple of two ints*/ // check for 0's if (a == 0 || b == 0) return 0;   // Math.abs(x) only works for doubles, Math.absf(x) for floats if (a < 0) a *= -1; if (b < 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 ...
#Scala
Scala
object Levenshtein0 extends App {   def distance(s1: String, s2: String): Int = { val dist = Array.tabulate(s2.length + 1, s1.length + 1) { (j, i) => if (j == 0) i else if (i == 0) j else 0 }   @inline def minimum(i: Int*): Int = i.min   for {j <- dist.indices.tail i <- dist(0).indices.tail} ...
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...
#PureBasic
PureBasic
Procedure countLetters(Array letterCounts(1), textLine.s) ;counts only letters A -> Z, uses index 0 of letterCounts() to keep a total of all counts Protected i, lineLength = Len(textLine), letter   textLine = UCase(textLine) For i = 1 To lineLength letter = Asc(Mid(textLine, i, 1)) - 'A' + 1 If letter >...
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)
#Retro
Retro
:isLeapYear? (y-f) dup #400 mod n:zero? [ drop #-1 #0 ] [ #1 ] choose 0; drop dup #100 mod n:zero? [ drop #0 #0 ] [ #1 ] choose 0; drop #4 mod n:zero? ;
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)
#REXX
REXX
leapyear: procedure; parse arg yr return yr//400==0 | (yr//100\==0 & yr//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...
#Pascal
Pascal
  {$B- Early and safe resolution of If x <> 0 and 1/x...} Program LangtonsAnt; Uses CRT; {Perpetrated by R.N.McLean (whom God preserve), Victoria University, December MMXV.} Var AsItWas: record mode: word; ta: word; end; Var LastLine,LastCol: byte;   Procedure Swap(var a,b: integer); {Oh for a compiler-recognised s...
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...
#Raku
Raku
sub MAIN (Int $year = Date.today.year) { my @fri; for Date.new("$year-01-01") .. Date.new("$year-12-31") { @fri[.month] = .Str if .day-of-week == 5; } .say for @fri[1..12]; }
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...
#VBA
VBA
Function gcd(u As Long, v As Long) As Long Dim t As Long Do While v t = u u = v v = t Mod v Loop gcd = u End Function Function lcm(m As Long, n As Long) As Long lcm = Abs(m * n) / gcd(m, n) End Function
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...
#VBScript
VBScript
Function LCM(a,b) LCM = POS((a * b)/GCD(a,b)) End Function   Function GCD(a,b) Do If a Mod b > 0 Then c = a Mod b a = b b = c Else GCD = b Exit Do End If Loop End Function   Function POS(n) If n < 0 Then POS = n * -1 Else POS = n End If End Function   i = WScript.Arguments(0) j = WScript....
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 ...
#Scheme
Scheme
  (define (levenshtein s t) (define (%levenshtein s sl t tl) (cond ((zero? sl) tl) ((zero? tl) sl) (else (min (+ (%levenshtein (cdr s) (- sl 1) t tl) 1) (+ (%levenshtein s sl (cdr t) (- tl 1)) 1) (+ (%levenshtein (cdr s) (- sl 1) (cdr t) (- tl 1)) (...
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...
#Python
Python
import collections, sys   def filecharcount(openfile): return sorted(collections.Counter(c for l in openfile for c in l).items())   f = open(sys.argv[1]) print(filecharcount(f))
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)
#Ring
Ring
  give year leap = isLeapYear(year) if leap true see year + " is leap year." else see year + " is not leap year." ok   Func isLeapYear year if (year % 400) = 0 return true but (year % 100) = 0 return false but (year % 4) = 0 return true else return false ok  
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)
#RPG
RPG
C*0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments+++++++ C *ENTRY PLIST C PARM YEAR 40 input (year) C PARM ISLEAP 1 output (Y/N) C* C MOVE 'N' ISLEAP C ...
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...
#Perl
Perl
#!/usr/bin/perl use strict; # Perl 5 implementation of Langton's Ant   # Using screen coordinates - 0,0 in upper-left, +X right, +Y down - # these directions (right, up, left, down) are counterclockwise # so advance through the array to turn left, retreat to turn right my @dirs = ( [1,0], [0,-1], [-1,0], [0,1] ); my $s...
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...
#REBOL
REBOL
leap-year?: function [year] [to-logic attempt [to-date reduce [29 2 year]]]   days-in-feb: function [year] [either leap-year? year [29] [28]]   days-in-month: function [month year] [ do pick [31 (days-in-feb year) 31 30 31 30 31 31 30 31 30 31] month ]   last-day-of-month: function [month year] [ to-date reduc...
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...
#Wortel
Wortel
@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...
#Wren
Wren
var gcd = Fn.new { |x, y| while (y != 0) { var t = y y = x % y x = t } return x.abs }   var lcm = Fn.new { |x, y| if (x == 0 && y == 0) return 0 return (x*y).abs / gcd.call(x, y) }   var xys = [[12, 18], [-6, 14], [35, 0]] for (xy in xys) { System.print("lcm(%(xy[0]), %(x...
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 ...
#Seed7
Seed7
$ include "seed7_05.s7i";   const func integer: levenshteinDistance (in string: s, in string: t) is func result var integer: distance is 0; local var array array integer: d is 0 times 0 times 0; var integer: i is 0; var integer: j is 0; begin d := [0 .. length(s)] times [0 .. length(t)] times ...
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...
#Quackery
Quackery
[ [] 26 times [ 0 join ] ] is makecountnest ( --> [ )   [ char A char Z 1+ within ] is ischar ( c --> b )   [ char A - 2dup peek 1+ unrot poke ] is tallychar ( [ c --> [ )   [ makecountnest swap witheach [ upper dup ischar iff tallychar else drop ] ] is ...
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)
#Ruby
Ruby
require 'date'   Date.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)
#Run_BASIC
Run BASIC
if date$("02/29/" + mid$(date$("mm/dd/yyyy"),7,4)) then print "leap year" else print "not"
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...
#Phix
Phix
sequence grid = repeat(repeat(' ',100),100) integer aX = 50, aY = 50, gXY, angle = 1 -- ' '/'#'; 0,1,2,3 = NESW constant dX = {0,-1,0,1} -- (dY = reverse(dX)) while aX>=1 and aX<=100 and aY>=1 and aY<=100 do gXY = grid[aX][aY] grid[aX][aY] = 67-gXY ...
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...
#REXX
REXX
╔════════════════════════════════════════════════════════════════════════════════════════════════╗ ║ lastDOW: procedure to return the date of the last day─of─week of any particular month of any ║ ║ particular year. ║ ║ ...
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...
#XBasic
XBasic
' Least common multiple PROGRAM "leastcommonmultiple" VERSION "0.0001"   DECLARE FUNCTION Entry() INTERNAL FUNCTION Gcd(m&, n&) INTERNAL FUNCTION Lcm(m&, n&)   FUNCTION Entry() PRINT "LCM(35, 21) ="; Lcm(35, 21) END FUNCTION   FUNCTION Gcd(m&, n&) DO WHILE m& <> 0 tmp& = m& m& = n& MOD m& n& = tmp& LO...
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...
#XPL0
XPL0
include c:\cxpl\codes;   func GCD(M,N); \Return the greatest common divisor of M and N int M, N; int T; [while N do \Euclid's method [T:= M; M:= N; N:= rem(T/N)]; return M; ];   func LCM(M,N); \Return least common multiple int M, N; return abs(M*N) / GCD(M,N);   \Display the LCM of two integers entered o...
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 ...
#SenseTalk
SenseTalk
  put textDifference("kitten", "sitting") // --> 3 put textDifference("rosettacode", "raisethysword") // --> 8    
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...
#Quick_Basic.2FQBASIC.2FPDS_7.1.2FVB-DOS
Quick Basic/QBASIC/PDS 7.1/VB-DOS
  ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' Program CountCar ' ' ' ' This program counts how many distinct characters ' ' have a text file specified by the user. ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ...
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)
#Rust
Rust
fn is_leap(year: i32) -> bool { let factor = |x| year % x == 0; factor(4) && (!factor(100) || factor(400)) }
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)
#S-BASIC
S-BASIC
  rem - compute p mod q function mod(p, q = integer) = integer end = p - q * (p/q)   rem - return true (-1) if y is a leap year, otherwise 0 function isleapyear(y = integer) = integer end = mod(y,4)=0 and mod(y,100)<>0 or mod(y,400)=0   rem - exercise the function var y = integer   print "Test of century years" for y ...
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...
#PHP
PHP
  // INIT AND DEFINITION define('dest_name', 'output.png'); // destination image define('width', 100); define('height', 100);   $x = 50; $y = 70; $dir = 0; // 0-up, 1-left, 2-down, 3-right $field = array(); $step_count = 0;   // LANGTON´S ANT PROCEDURE while(0 <= $x && $x <= width && 0 <= $y && $y <= height){ if(isse...
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...
#Ring
Ring
  see "What year to calculate (yyyy) : " give year see "Last Friday in " + year + " are on :" + nl month = list(12) mo = [4,0,0,3,5,1,3,6,2,4,0,2] mon = [31,28,31,30,31,30,31,31,30,31,30,31] if year < 2100 leap = year - 1900 else leap = year - 1904 ok m = ((year-1900)%7) + floor(leap/4) % 7 for n = 1 to 12 month[n...