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/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #Action.21 | Action! | CARD FUNC Leonardo(BYTE n)
CARD curr,prev,tmp
IF n<=1 THEN
RETURN (1)
FI
prev=1
curr=1
DO
tmp=prev
prev=curr
curr==+tmp+1
n==-1
UNTIL n=1
OD
RETURN (curr)
PROC Main()
BYTE n
CARD l
Put(125) ;clear screen
FOR n=0 TO 22 ;limited to 22 because of CARD limitations
DO
... |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #Ada | Ada | with Ada.Text_IO; use Ada.Text_IO;
procedure Leonardo is
function Leo
(N : Natural;
Step : Natural := 1;
First : Natural := 1;
Second : Natural := 1) return Natural is
L : array (0..1) of Natural := (First, Second);
begin
for i in 1 .. N loop
L := (L(1), L(0)+L(1)+St... |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #Sidef | Sidef | [%w(a b c),%w(A B C),%w(1 2 3)].zip { |i,j,k|
say (i, j, k)
} |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #D | D | import std.stdio, std.meta, std.range;
TA[] select(TA, TI1, TC1, TI2, TC2, TI3, TC3, TP)
(lazy TA mapper,
ref TI1 iter1, TC1 items1,
ref TI2 iter2, lazy TC2 items2,
ref TI3 iter3, lazy TC3 items3,
lazy TP where) {
Appender!(TA[]) result;
auto iters = Alia... |
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #SETL | SETL | for i in {1..5} loop
for j in {1..i} loop
nprint( '*' );
end loop;
print; -- new line
end loop; |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #ALGOL_68 | ALGOL 68 | BEGIN
# leonardo number parameters #
MODE LEONARDO = STRUCT( INT l0, l1, add number );
# default leonardo number parameters #
LEONARDO leonardo numbers = LEONARDO( 1, 1, 1 );
# operators to allow us to specify non-default parameters #
PRIO WITHLZERO = 9, WITHLONE = 9, WITHADDNUMBER = 9;
OP ... |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #Smalltalk | Smalltalk | |a b c|
a := OrderedCollection new addAll: #('a' 'b' 'c').
b := OrderedCollection new addAll: #('A' 'B' 'C').
c := OrderedCollection new addAll: #(1 2 3).
1 to: (a size) do: [ :i |
(a at: i) display.
(b at: i) display.
(c at: i) displayNl.
]. |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #E | E | pragma.enable("accumulator") # considered experimental
accum [] for x in 1..n { for y in x..n { for z in y..n { if (x**2 + y**2 <=> z**2) { _.with([x,y,z]) } } } } |
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #Sidef | Sidef | for (var i = 1; i <= 5; i++) {
for (var j = 1; j <= i; j++) {
print '*'
}
print "\n"
} |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #AppleScript | AppleScript | ------------------------ GENERATOR -------------------------
-- leo :: Int -> Int -> Int -> Generator [Int]
on leo(L0, L1, delta)
script
property x : L0
property y : L1
on |λ|()
set n to x
set {x, y} to {y, x + y + delta}
return n
end |λ|
end... |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #Standard_ML | Standard ML |
(*
* val combine_lists : string list list -> string list
*)
fun combine_lists nil = nil
| combine_lists (l1::ls) = List.foldl (ListPair.map (fn (x,y) => y ^
x)) l1 ls;
(* ["a1Ax","b2By","c3Cz"] *)
combine_lists[["a","b","c"],["1","2","3"],["A","B","C"],["x","y","z"]];
|
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #EchoLisp | EchoLisp |
;; copied from Racket
(for*/list ([x (in-range 1 21)]
[y (in-range x 21)]
[z (in-range y 21)])
#:when (= (+ (* x x) (* y y)) (* z z))
(list x y z))
→ ((3 4 5) (5 12 13) (6 8 10) (8 15 17) (9 12 15) (12 16 20))
|
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #Simula | Simula | begin
integer i,j;
for i:=1 step 1 until 5 do
begin
for j:=1 step 1 until i do
outtext("*");
outimage
end
end
|
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #Arturo | Arturo | L: function [n l0 l1 ladd].memoize[
(n=0)? -> l0 [
(n=1)? -> l1
-> (L n-1 l0 l1 ladd) + (L n-2 l0 l1 ladd) + ladd
]
]
Leonardo: function [z]-> L z 1 1 1
print "The first 25 Leonardo numbers:"
print map 0..24 => Leonardo
print ""
print "The first 25 Leonardo numbers with L0=0, L1=1, LA... |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #Stata | Stata | local u a b c
local v A B C
matrix w=1,2,3
forv i=1/3 {
di "`: word `i' of `u''`: word `i' of `v''`=el("w",1,`i')'"
} |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #Efene | Efene | pythag = fn (N) {
[(A, B, C) for A in lists.seq(1, N) \
for B in lists.seq(A, N) \
for C in lists.seq(B, N) \
if A + B + C <= N and A * A + B * B == C * C]
}
@public
run = fn () {
io.format("~p~n", [pythag(20)])
}
|
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #Slate | Slate | 1 to: 5 do: [| :n | inform: ($* repeatedTimes: n)]. |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #AutoHotkey | AutoHotkey | Leonardo(n, L0:=1, L1:=1, step:=1){
if n=0
return L0
if n=1
return L1
return Leonardo(n-1, L0, L1, step) + Leonardo(n-2, L0, L1, step) + step
} |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #AWK | AWK |
# syntax: GAWK -f LEONARDO_NUMBERS.AWK
BEGIN {
leonardo(1,1,1,"Leonardo")
leonardo(0,1,0,"Fibonacci")
exit(0)
}
function leonardo(L0,L1,step,text, i,tmp) {
printf("%s numbers (%d,%d,%d):\n",text,L0,L1,step)
for (i=1; i<=25; i++) {
if (i == 1) {
printf("%d ",L0)
}
else if... |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #SuperCollider | SuperCollider |
#x, y, z = [["a", "b", "c"], ["A", "B", "C"], ["1", "2", "3"]];
3.collect { |i| x[i] ++ y[i] ++ z[i] }
|
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #Ela | Ela | pyth n = [(x,y,z) \\ x <- [1..n], y <- [x..n], z <- [y..n] | x**2 + y**2 == z**2] |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #Elixir | Elixir | iex(30)> pytha3 = fn(n) ->
...(30)> for x <- 1..n, y <- x..n, z <- y..n, x*x+y*y == z*z, do: {x,y,z}
...(30)> end
#Function<6.90072148/1 in :erl_eval.expr/5>
iex(31)> pytha3.(20)
[{3, 4, 5}, {5, 12, 13}, {6, 8, 10}, {8, 15, 17}, {9, 12, 15}, {12, 16, 20}]
|
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #Smalltalk | Smalltalk | 1 to: 5 do: [ :aNumber |
aNumber timesRepeat: [ '*' display ].
Character nl display.
] |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #Bash | Bash |
#!/bin/bash
function leonardo_number () {
L0_value=${2:-1}
L1_value=${3:-1}
Add=${4:-1}
leonardo_numbers=($L0_value $L1_value)
for (( i = 2; i < $1; ++i))
do
leonardo_numbers+=( $((leonardo_numbers[i-1] + leonardo_numbers[i-2] + Add)) )
done
echo "${leonardo_numbers[*]}"
}
|
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #Swift | Swift | let a1 = ["a", "b", "c"]
let a2 = ["A", "B", "C"]
let a3 = [1, 2, 3]
for i in 0 ..< a1.count {
println("\(a1[i])\(a2[i])\(a3[i])")
} |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #Erlang | Erlang | pythag(N) ->
[ {A,B,C} || A <- lists:seq(1,N),
B <- lists:seq(A,N),
C <- lists:seq(B,N),
A+B+C =< N,
A*A+B*B == C*C ]. |
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #SNOBOL4 | SNOBOL4 | ol outer = ?lt(outer,5) outer + 1 :f(end)
inner = outer; stars = ""
il stars = ?gt(inner,0) stars "*" :f(disp)
inner = inner - 1 :(il)
disp output = stars; :(ol)
end |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #BASIC | BASIC |
subroutine leonardo(L0, L1, suma, texto)
print "Numeros de " + texto + " (" + L0 + "," + L1 + "," + suma + "):"
for i = 1 to 25
if i = 1 then
print L0 + " ";
else
if i = 2 then
print L1 + " ";
else
print L0 + L1 + suma + " ";
tmp = L0
L0 = L1
L1 = tmp + L1 + suma
end if
end if
... |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #BBC_BASIC | BBC BASIC | REM >leonardo
:
PRINT "Enter values of L0, L1, and ADD, separated by commas:"
INPUT l0%, l1%, add%
PRINT l0% ' l1%
FOR i% = 3 TO 25
temp% = l1%
l1% += l0% + add%
l0% = temp%
PRINT l1%
NEXT
PRINT
END |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #Tailspin | Tailspin |
def x: ['a', 'b', 'c'];
def y: ['A', 'B', 'C'];
def z: [1, 2, 3];
1..$x::length -> '$x($);$y($);$z($);
' -> !OUT::write
|
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #F.23 | F# | let pyth n = [ for a in [1..n] do
for b in [a..n] do
for c in [b..n] do
if (a*a+b*b = c*c) then yield (a,b,c)] |
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #SNUSP | SNUSP | / \
<
< <
< /<<<<<.\
. ?
> \->>>>>/
> !
> >
! >
/>-\ />+>+\
? ?
\+</ \ -<</
< !
< +
- >
/ !\?/#
\+++++>+++++++++++++>\ ... |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #Burlesque | Burlesque | blsq ) 1 1 1{.+\/.+}\/+]23!CCLm]wdsh
1 1 3 5 9 15 25 41 67 109 177 287 465 753 1219 1973 3193 5167 8361 13529 21891 35421 57313 92735 150049
blsq ) 0 1 0{.+\/.+}\/+]23!CCLm]wdsh
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #C | C |
#include<stdio.h>
void leonardo(int a,int b,int step,int num){
int i,temp;
printf("First 25 Leonardo numbers : \n");
for(i=1;i<=num;i++){
if(i==1)
printf(" %d",a);
else if(i==2)
printf(" %d",b);
else{
printf(" %d",a+b+step);
temp = a;
a = b;
b = temp+b+step;
}
}
}
int main()
{
... |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #Tcl | Tcl | set list1 {a b c}
set list2 {A B C}
set list3 {1 2 3}
foreach i $list1 j $list2 k $list3 {
puts "$i$j$k"
} |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #Factor | Factor | USING: backtrack kernel locals math math.ranges ;
:: pythagorean-triples ( n -- seq )
[
n [1,b] amb-lazy :> a
a n [a,b] amb-lazy :> b
b n [a,b] amb-lazy :> c
a a * b b * + c c * = must-be-true { a b c }
] bag-of ; |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #Fortran | Fortran |
!-*- mode: compilation; default-directory: "/tmp/" -*-
!Compilation started at Fri Jun 7 23:39:20
!
!a=./f && make $a && $a
!gfortran -std=f2008 -Wall -fopenmp -ffree-form -fall-intrinsics -fimplicit-none f.f08 -o f
! 3 4 5
! 5 12 13
! 6 8 10
! 8 15 17
! 9 12 15
! 12 16 20
!
!Compilation fi... |
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #Sparkling | Sparkling | for (var row = 1; row <= 5; row++) {
for (var col = 1; col <= row; col++) {
printf("*");
}
print();
} |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #C.23 | C# | using System;
using System.Linq;
public class Program
{
public static void Main() {
Console.WriteLine(string.Join(" ", Leonardo().Take(25)));
Console.WriteLine(string.Join(" ", Leonardo(L0: 0, L1: 1, add: 0).Take(25)));
}
public static IEnumerable<int> Leonardo(int L0 = 1, int L1 = 1, in... |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #TorqueScript | TorqueScript |
$var[0] = "a b c"
$var[1] = "A B C";
$var[2] = "1 2 3";
for(%i=0;%i<3;%i++)
echo(getWord($var[0],%i) @ getWord($var[1],%i) @ getWord($var[2],%i));
|
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #FreeBASIC | FreeBASIC | Dim As Integer x, y, z, n = 25
For x = 1 To n
For y = x To n
For z = y To n
If x^2 + y^2 = z^2 Then Print Using "{##_, ##_, ##}"; x; y; z
Next z
Next y
Next x
Sleep |
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #Spin | Spin | con
_clkmode = xtal1 + pll16x
_clkfreq = 80_000_000
obj
ser : "FullDuplexSerial.spin"
pub main | m, n
ser.start(31, 30, 0, 115200)
repeat n from 1 to 5
repeat m from 1 to n
ser.tx("*")
ser.str(string(13,10))
waitcnt(_clkfreq + cnt)
ser.stop
cogstop(0) |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #C.2B.2B | C++ |
#include <iostream>
void leoN( int cnt, int l0 = 1, int l1 = 1, int add = 1 ) {
int t;
for( int i = 0; i < cnt; i++ ) {
std::cout << l0 << " ";
t = l0 + l1 + add; l0 = l1; l1 = t;
}
}
int main( int argc, char* argv[] ) {
std::cout << "Leonardo Numbers: "; leoN( 25 );
std::cout <<... |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #TUSCRIPT | TUSCRIPT |
$$ MODE TUSCRIPT
arr1="a'b'c"
arr2="a'b'C"
arr3="1'2'3"
LOOP a=arr1,b=arr2,c=arr3
PRINT a,b,c
ENDLOOP
|
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #FunL | FunL | def triples( n ) = [(a, b, c) | a <- 1..n-2, b <- a+1..n-1, c <- b+1..n if a^2 + b^2 == c^2]
println( triples(20) ) |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #GAP | GAP | # We keep only primitive pythagorean triples
pyth := n ->
Filtered(Cartesian([1 .. n], [1 .. n], [1 .. n]),
u -> u[3]^2 = u[1]^2 + u[2]^2 and u[1] < u[2]
and GcdInt(u[1], u[2]) = 1);
pyth(100);
# [ [ 3, 4, 5 ], [ 5, 12, 13 ], [ 7, 24, 25 ], [ 8, 15, 17 ], [ 9, 40, 41 ], [ 11, 60, 61 ], [ 12, 35, 37 ],
# [ 1... |
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #SPL | SPL | > i, 1..5
> j, 1..i
#.output("*",#.rs)
<
#.output()
< |
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
... | #11l | 11l | T LinearCongruentialGenerator
seed = 0
Int a, c, m
F (a, c, m)
.a = a
.c = c
.m = m
F ()()
.seed = (.a * .seed + .c) [&] .m
R .seed
V bsd_rnd = LinearCongruentialGenerator(1103515245, 12345, 7FFF'FFFF)
V ms_rnd = LinearCongruentialGenerator(214013, 2531011, 7FFF'FFFF)
... |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #Common_Lisp | Common Lisp |
;;;
;;; leo - calculates the first n number from a leo sequence.
;;; The first argument n is the number of values to return. The next three arguments a, b, add are optional.
;;; Default values provide the "original" leonardo numbers as defined in the task.
;;; a and b are the first and second element of the leonardo ... |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #TXR | TXR | $ txr -c '@(bind a ("a" "b" "c"))
@(bind b ("A" "B" "C"))
@(bind c ("1" "2" "3"))
@(output)
@ (repeat)
@a@b@c
@ (end)
@(end)'
aA1
bB2
cC3 |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #Go | Go | package main
import "fmt"
type (
seq []int
sofs []seq
)
func newSeq(start, end int) seq {
if end < start {
end = start
}
s := make(seq, end-start+1)
for i := 0; i < len(s); i++ {
s[i] = start + i
}
return s
}
func newSofs() sofs {
return sofs{seq{}}
}
func ... |
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #Stata | Stata | forvalues n=1/5 {
local s ""
forvalues i=1/`n' {
local s `s'*
}
display "`s'"
} |
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
... | #360_Assembly | 360 Assembly | * Linear congruential generator 07/03/2017
LINCONG CSECT
USING LINCONG,R12
LR R12,R15 set base register
BEGIN SR R5,R5 bsdseed=0
SR R7,R7 msseed=0
LA R8,1 i=1
L R9,=F'10' number of... |
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
... | #Ada | Ada | generic
type Base_Type is mod <>;
Multiplyer, Adder: Base_Type;
Output_Divisor: Base_Type := 1;
package LCG is
procedure Initialize(Seed: Base_Type);
function Random return Base_Type;
-- changes the state and outputs the result
end LCG; |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #Crystal | Crystal | def leonardo(l_zero, l_one, add, amount)
terms = [l_zero, l_one]
while terms.size < amount
new = terms[-1] + terms[-2]
new += add
terms << new
end
terms
end
puts "First 25 Leonardo numbers: \n#{ leonardo(1,1,1,25) }"
puts "Leonardo numbers with fibonacci parameters:\n#{ leonard... |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #D | D |
import std.stdio;
void main() {
write("Leonardo Numbers: ");
leonardoNumbers( 25 );
write("Fibonacci Numbers: ");
leonardoNumbers( 25, 0, 1, 0 );
}
void leonardoNumbers(int count, int l0=1, int l1=1, int add=1) {
int t;
for (int i=0; i<count; ++i) {
write(l0, " ");
t = l0... |
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 ... | #11l | 11l | F minimumEditDistance(=s1, =s2)
I s1.len > s2.len
(s1, s2) = (s2, s1)
V distances = Array(0 .. s1.len)
L(char2) s2
V newDistances = [L.index + 1]
L(char1) s1
I char1 == char2
newDistances.append(distances[L.index])
E
newDistances.append(1 + min((d... |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #TypeScript | TypeScript | // Loop over multiple arrays simultaneously
var arr1: string[] = ['a', 'b', 'c'];
var arr2: string[] = ['A', 'B', 'C'];
var arr3: number[] = [1, 2, 3];
for (var i = 0; i <= 2; i++)
console.log(`${arr1[i]}${arr2[i]}${arr3[i]}`);
|
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #Haskell | Haskell | pyth :: Int -> [(Int, Int, Int)]
pyth n =
[ (x, y, z)
| x <- [1 .. n]
, y <- [x .. n]
, z <- [y .. n]
, x ^ 2 + y ^ 2 == z ^ 2 ] |
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #Suneido | Suneido | for(i = 0; i < 5; ++i)
{
str = ''
for (j = 0; j <= i; ++j)
str $= '*'
Print(str)
} |
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #Swift | Swift | for i in 1...5 {
for _ in 1...i {
print("*", terminator: "")
}
print()
} |
http://rosettacode.org/wiki/Left_factorials | Left factorials | Left factorials, !n, may refer to either subfactorials or to factorial sums;
the same notation can be confusingly seen being used for the two different definitions.
Sometimes, subfactorials (also known as derangements) may use any of the notations:
!n`
!n
n¡
(It may not be vis... | #11l | 11l | F left_fact(n)
BigInt result = 0
BigInt factorial = 1
L(i) 1 .. n
result += factorial
factorial *= i
R result
print(‘First 11 left factorials:’)
print((0..10).map(i -> left_fact(i)))
print("\n20 through 110 (inclusive) by tens:")
L(i) (20..110).step(10)
print(left_fact(i))
print("\nDigits i... |
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
... | #ALGOL_68 | ALGOL 68 |
BEGIN
COMMENT
Algol 68 Genie checks for integer overflow whereas the reference
language leaves the result undefined so for portability we need to
see how wide a variable must be to hold the maximum possible value
before range reduction. This occurs in the BSD RNG when
rseed=2147483647 and is therefore ... |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #F.23 | F# | open System
let leo l0 l1 d =
Seq.unfold (fun (x, y) -> Some (x, (y, x + y + d))) (l0, l1)
let leonardo = leo 1 1 1
let fibonacci = leo 0 1 0
[<EntryPoint>]
let main _ =
let leoNums = Seq.take 25 leonardo |> Seq.chunkBySize 16
printfn "First 25 of the (1, 1, 1) Leonardo numbers:\n%A" leoNums
Cons... |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #Factor | Factor | USING: fry io kernel math prettyprint sequences ;
IN: rosetta-code.leonardo-numbers
: first25-leonardo ( vector add -- seq )
23 swap '[ dup 2 tail* sum _ + over push ] times ;
: print-leo ( seq -- ) [ pprint bl ] each nl ;
"First 25 Leonardo numbers:" print
V{ 1 1 } 1 first25-leonardo print-leo
"First 25 Le... |
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 ... | #360_Assembly | 360 Assembly | * Levenshtein distance - 22/04/2020
LEVENS CSECT
USING LEVENS,R13 base register
B 72(R15) skip savearea
DC 17F'0' savearea
SAVE (14,12) save previous context
ST R13,4(R15) link backward
... |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #UNIX_Shell | UNIX Shell | a=a:b:c
b=A:B:C
c=1:2:3
oldifs=$IFS
IFS=:
i=0
for wa in $a; do
set -- $b; shift $i; wb=$1
set -- $c; shift $i; wc=$1
printf '%s%s%s\n' $wa $wb $wc
i=`expr $i + 1`
done
IFS=$oldifs |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #Hy | Hy | (defn triples [n]
(list-comp (, a b c) [a (range 1 (inc n))
b (range a (inc n))
c (range b (inc n))]
(= (pow c 2)
(+ (pow a 2)
(pow b 2)))))
(print (triples 15))
; [(3, 4, 5), (5, 12, 13), (6, 8, 10), (9, 12, 15)] |
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #Tailspin | Tailspin |
1..5 -> '$:1..$ -> '*';
' -> !OUT::write
|
http://rosettacode.org/wiki/Left_factorials | Left factorials | Left factorials, !n, may refer to either subfactorials or to factorial sums;
the same notation can be confusingly seen being used for the two different definitions.
Sometimes, subfactorials (also known as derangements) may use any of the notations:
!n`
!n
n¡
(It may not be vis... | #ALGOL_68 | ALGOL 68 | # set the precision of LONG LONG INT - large enough for !n up to ! 10 000 #
PR precision 36000 PR
# stores left factorials in an array #
# we calculate the left factorials, storing their values in the "values" array #
# if step is <= 1, we store we store every left factorial, otherwise we store !x when x MOD step = 0 #... |
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
... | #AutoHotkey | AutoHotkey | a := 0, b:= [0]
Loop, 10
BSD .= "`t" (a := BSD(a)) "`n"
, b := MS(b[1])
, MS .= "`t" (b[2]) "`n"
MsgBox, % "BSD:`n" BSD "`nMS:`n" MS
BSD(Seed) {
return, Mod(1103515245 * Seed + 12345, 2147483648)
}
MS(Seed) {
Seed := Mod(214013 * Seed + 2531011, 2147483648)
return, [Seed, Seed // 65536]
} |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #Fermat | Fermat | Func Leonardo(size, l0, l1, add) =
Array leo[1,size]; {set up as a row rather than column vector; looks nicer to print}
leo[1,1]:=l0; leo[1,2]:=l1; {fermat arrays are 1-indexed}
for i=3 to size do
leo[1,i]:=leo[1,i-2]+leo[1,i-1]+add;
od;
.;
Leonardo(25, 1, 1, 1);
[leo];
L... |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #Fortran | Fortran | SUBROUTINE LEONARDO(LAST,L0,L1,AF) !Show the first LAST values of the sequence.
INTEGER LAST !Limit to show.
INTEGER L0,L1 !Starting values.
INTEGER AF !The "Add factor" to deviate from Fibonacci numbers.
OPTIONAL AF !Indicate that this parameter may be omitted.
INTEGER EMBOLISM... |
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 ... | #Action.21 | Action! |
DEFINE STRING="CHAR ARRAY" ; sys.act
DEFINE width="15" ; max characters 14
DEFINE MatrixSize="225" ; 15*15
PROC Set2Dm(INT ARRAY matrix, INT x,y, val)
matrix(x+y*width)=val
RETURN
INT FUNC Get2Dm(INT ARRAY matrix, INT x,y)
INT res
res=matrix(x+y*width)
RETURN(res)
INT FUNC DamerauLevenshteinDistance(STRIN... |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #Ursa | Ursa | > decl string<> a b c
> append (split "abc" "") a
> append (split "ABC" "") b
> append (split "123" "") c
> for (decl int i) (< i (size a)) (inc i)
.. out a<i> b<i> c<i> endl console
..end
aA1
bB2
cC3
> _ |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #Icon_and_Unicon | Icon and Unicon |
|(x := seq(), x^2 > 3, x*2)
|
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #Tcl | Tcl | for {set lines 1} {$lines <= 5} {incr lines} {
for {set i 1} {$i <= $lines} {incr i} {
puts -nonewline "*"
}
puts ""
} |
http://rosettacode.org/wiki/Left_factorials | Left factorials | Left factorials, !n, may refer to either subfactorials or to factorial sums;
the same notation can be confusingly seen being used for the two different definitions.
Sometimes, subfactorials (also known as derangements) may use any of the notations:
!n`
!n
n¡
(It may not be vis... | #AWK | AWK |
#!/usr/bin/gawk -Mf
function left_factorial(num) {
result=0
adder=1
if (num==0) return(0)
for (k = 1; k <=num; k++) {
result = result + adder
adder = adder * k
}
return(result)
}
BEGIN {
for (i = 0; i <= 10; i++) {
print "!" i " = " left_factorial(i)
}
for (i = 20; i<= 110; i+=10) {
print "!" i " =... |
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
... | #Batch | Batch |
@echo off & setlocal enabledelayedexpansion
echo BSD Rand
set /a a=0,cnt=1
:b
set /a "a=1103515245 *a+12345,a&=0x7fffffff, cnt+=1"
call:prettyprint !cnt! !a!
if !cnt! leq 10 goto :b
echo.
echo Microsoft Rand
set /a a=0,cnt=1
:c
set /a "a=214013 *a+2531011,a&=0x7fffffff, b=a>>16,cnt+=1"
call:prettyprint !cnt! !b!
... |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #FreeBASIC | FreeBASIC |
Sub leonardo(L0 As Integer, L1 As Integer, suma As Integer, texto As String)
Dim As Integer i, tmp
Print "Numeros de " &texto &" (" &L0 &"," &L1 &"," &suma &"):"
For i = 1 To 25
If i = 1 Then
Print L0;
Elseif i = 2 Then
Print L1;
Else
Print L0 + ... |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #Go | Go | package main
import "fmt"
func leonardo(n, l0, l1, add int) []int {
leo := make([]int, n)
leo[0] = l0
leo[1] = l1
for i := 2; i < n; i++ {
leo[i] = leo[i - 1] + leo[i - 2] + add
}
return leo
}
func main() {
fmt.Println("The first 25 Leonardo numbers with L[0] = 1, L[1] = 1 and ... |
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 ... | #Ada | Ada | with Ada.Text_IO;
procedure Main is
function Levenshtein_Distance (S, T : String) return Natural is
D : array (0 .. S'Length, 0 .. T'Length) of Natural;
begin
for I in D'Range (1) loop
D (I, 0) := I;
end loop;
for I in D'Range (2) loop
D (0, I) := I;
end loop;
... |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #Ursala | Ursala | #show+
main = ~&K7 <'abc','ABC','123'> |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #Ioke | Ioke | for(
x <- 1..20,
y <- x..20,
z <- y..20,
x * x + y * y == z * z,
[x, y, z]
) |
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #TI-83_BASIC | TI-83 BASIC | ClrHome
For(I,1,5
For(J,1,I
Output(I,J,"*
End
End
|
http://rosettacode.org/wiki/Left_factorials | Left factorials | Left factorials, !n, may refer to either subfactorials or to factorial sums;
the same notation can be confusingly seen being used for the two different definitions.
Sometimes, subfactorials (also known as derangements) may use any of the notations:
!n`
!n
n¡
(It may not be vis... | #BBC_BASIC | BBC BASIC | INSTALL @lib$+"BB4WMAPMLIB" : PROCMAPM_Init : MAPM_Dec%=200
Result$="0" : A$="1"
FOR I%=0 TO 10000
IF I% Result$=FNMAPM_Add(Result$,A$) : A$=FNMAPM_Multiply(A$,STR$I%)
IF I% < 111 IF I% MOD 10 = 0 OR I% < 11 PRINT "!";I% " = " FNMAPM_FormatDec(Result$,0)
IF I% > 999 IF I%... |
http://rosettacode.org/wiki/Left_factorials | Left factorials | Left factorials, !n, may refer to either subfactorials or to factorial sums;
the same notation can be confusingly seen being used for the two different definitions.
Sometimes, subfactorials (also known as derangements) may use any of the notations:
!n`
!n
n¡
(It may not be vis... | #Bracmat | Bracmat | ( ( leftFact
= result factorial i
. 0:?result
& 1:?factorial
& 0:?i
& whl
' ( !i+1:~>!arg:?i
& !factorial+!result:?result
& !factorial*!i:?factorial
)
& !result
)
& ( iterate
= from to step c fun
. !arg:(?from.?to.?step.?fun)
& ... |
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
... | #BBC_BASIC | BBC BASIC | @% = &D0D
PRINT "MS generator:"
dummy% = FNrandMS(0)
FOR i% = 1 TO 10
PRINT FNrandMS(-1)
NEXT
PRINT '"BSD generator:"
dummy% = FNrandBSD(0)
FOR i% = 1 TO 10
PRINT FNrandBSD(-1)
NEXT
END
DEF FNrandMS(seed%)
PRIVATE state%
IF ... |
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
... | #bc | bc | /* BSD rand */
define rand() {
randseed = (randseed * 1103515245 + 12345) % 2147483648
return randseed
}
randseed = 1
rand(); rand(); rand(); print "\n"
/* Microsoft rand */
define rand() {
randseed = (randseed * 214013 + 2531011) % 2147483648
return randseed / 65536
}
randseed = 1
rand(); rand(); rand();... |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #Haskell | Haskell | import Data.List (intercalate, unfoldr)
import Data.List.Split (chunksOf)
--------------------- LEONARDO NUMBERS ---------------------
-- L0 -> L1 -> Add number -> Series (infinite)
leo :: Integer -> Integer -> Integer -> [Integer]
leo l0 l1 d = unfoldr (\(x, y) -> Just (x, (y, x + y + d))) (l0, l1)
leonardo :: [In... |
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 ... | #Aime | Aime | integer
dist(data s, t, integer i, j, list d)
{
integer x;
x = d[i * (~t + 1) + j];
if (x == -1) {
if (i == ~s) {
x = ~t - j;
} elif (j == ~t) {
x = ~s - i;
} elif (s[i] == t[j]) {
x = dist(s, t, i + 1, j + 1, d);
} else {
x =... |
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... | #11l | 11l | F countletters(s)
DefaultDict[Char, Int] results
L(char) s
V c = char.lowercase()
I c C ‘a’..‘z’
results[c]++
R results
:start:
L(letter, count) countletters(File(:argv[1]).read())
print(letter‘=’count) |
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously | Loop over multiple arrays simultaneously | Task
Loop over multiple arrays (or lists or tuples or whatever they're called in
your language) and display the i th element of each.
Use your language's "for each" loop if it has one, otherwise iterate
through the collection in order with some other loop.
For this example, loop over the arrays:
... | #Vala | Vala | const char a1[] = {'a','b','c'};
const char a2[] = {'A','B','C'};
const int a3[] = {1, 2, 3};
void main() {
for (int i = 0; i < 3; i++)
stdout.printf("%c%c%i\n", a1[i], a2[i], a3[i]);
} |
http://rosettacode.org/wiki/List_comprehensions | List comprehensions | A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.
Some attributes of a list comprehension are:
They should be distinct from (nested) for loops and the use of map and filter functio... | #J | J | require'stats'
buildSet=:conjunction def '(#~ v) u y'
triples=: 1 + 3&comb
isPyth=: 2&{"1 = 1&{"1 +&.:*: 0&{"1
pythTr=: triples buildSet isPyth |
http://rosettacode.org/wiki/Loops/For | Loops/For | “For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
... | #TI-89_BASIC | TI-89 BASIC | Local i,j
ClrIO
For i, 1, 5
For j, 1, i
Output i*8, j*6, "*"
EndFor
EndFor |
http://rosettacode.org/wiki/Left_factorials | Left factorials | Left factorials, !n, may refer to either subfactorials or to factorial sums;
the same notation can be confusingly seen being used for the two different definitions.
Sometimes, subfactorials (also known as derangements) may use any of the notations:
!n`
!n
n¡
(It may not be vis... | #C | C |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gmp.h>
void mpz_left_fac_ui(mpz_t rop, unsigned long op)
{
mpz_t t1;
mpz_init_set_ui(t1, 1);
mpz_set_ui(rop, 0);
size_t i;
for (i = 1; i <= op; ++i) {
mpz_add(rop, rop, t1);
mpz_mul_ui(t1, t1, i);
}
... |
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
... | #Befunge | Befunge | >025*>\::0\`288*::*:****+.55+,"iQ"5982156*:v
v $$_^#!\-1:\%***:*::*882 ++*"yf"3***+***+*<
>025*>\:488**:*/:0\`6"~7"+:*+01-2/-*+."O?+"55v
@ $$_^#!\-1:\%***:*::*882 ++***" ''4C"*+2**,+< |
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #J | J |
leo =: (] , {.@[ + _2&{@] + {:@])^:(_2&+@{:@[)
|
http://rosettacode.org/wiki/Leonardo_numbers | Leonardo numbers |
Leonardo numbers are also known as the Leonardo series.
The Leonardo numbers are a sequence of numbers defined by:
L(0) = 1 [1st equation]
L(1) = 1 [2nd equation]
L(n) = L(n-1) + L(n-2) + 1 ... | #Java | Java | import java.util.Arrays;
import java.util.List;
@SuppressWarnings("SameParameterValue")
public class LeonardoNumbers {
private static List<Integer> leonardo(int n) {
return leonardo(n, 1, 1, 1);
}
private static List<Integer> leonardo(int n, int l0, int l1, int add) {
Integer[] leo = new... |
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 ... | #ALGOL_68 | ALGOL 68 | # Calculate Levenshtein distance between strings - translated from the Action! sample #
BEGIN
PROC damerau levenshtein distance = (STRING str1, str2)INT:
BEGIN
INT m=UPB str1;
INT n=UPB str2;
(0:m,0:n)INT matrix;
FOR i FROM 0 TO m DO FOR j FROM 0 TO n DO matrix(i,j):=0 OD OD;
FOR i TO m DO matrix(i,1)... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.