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/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Robotic
Robotic
def logic(a, b) print 'a and b: ', a && b, "\n" print 'a or b: ' , a || b, "\n" print 'not a: ' , !a , "\n" print 'a xor b: ' , a ^ b, "\n" end
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Ruby
Ruby
def logic(a, b) print 'a and b: ', a && b, "\n" print 'a or b: ' , a || b, "\n" print 'not a: ' , !a , "\n" print 'a xor b: ' , a ^ b, "\n" 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: ...
#Oforth
Oforth
[ "a", "b", "c" ] [ "A", "B", "C" ] [ 1, 2, 3 ] zipAll(3) apply(#[ apply(#print) printcr ])
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#TorqueScript
TorqueScript
for(%a = 0; %a > -1; %a++) {  %number = getRandom(0, 19); if(%number == 10) break; }
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#Transact-SQL
Transact-SQL
  DECLARE @i INT; WHILE 1=1 BEGIN SET @i = ABS(CHECKSUM(NewId())) % 20; PRINT @i; IF @i=10 BREAK; PRINT ABS(CHECKSUM(NewId())) % 20; END;  
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Q
Q
las:{{raze string[count@'x],'@'[;0]x:where[differ x]_x}\[x;1#"1"]} las 8
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. ...
#Phix
Phix
for i=1 to 5 do for j=1 to i do puts(1,"*") end for puts(1,"\n") end for
http://rosettacode.org/wiki/Long_multiplication
Long multiplication
Task Explicitly implement   long multiplication. This is one possible approach to arbitrary-precision integer algebra. For output, display the result of   264 * 264. Optionally, verify your result against builtin arbitrary precision support. The decimal representation of   264   is: 18,446,744,073,709,551,61...
#XPL0
XPL0
include c:\cxpl\stdlib; char Two64, Product(40); [Two64:= "18446744073709551616"; StrNMul(Two64, Two64, Product, 20); Product(39):= Product(39)!$80; \terminate string Text(0, Product+1); \skip leading zero ]
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Rust
Rust
  fn boolean_ops(a: bool, b: bool) { println!("{} and {} -> {}", a, b, a && b); println!("{} or {} -> {}", a, b, a || b); println!("{} xor {} -> {}", a, b, a ^ b); println!("not {} -> {}\n", a, !a); }   fn main() { boolean_ops(true, true); boolean_ops(true, false); boolean_ops(false, true); ...
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Scala
Scala
def logical(a: Boolean, b: Boolean): Unit = { println("and: " + (a && b)) println("or: " + (a || b)) println("not: " + !a) }   logical(true, false)
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: ...
#ooRexx
ooRexx
  x = .array~of("a", "b", "c") y = .array~of("A", "B", "C") z = .array~of(1, 2, 3)   loop i = 1 to x~size say x[i]y[i]z[i] end  
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT LOOP a=RANDOM_NUMBERS (0,19,1) IF (10==a) THEN PRINT "a=",a STOP ELSE b=RANDOM_NUMBERS (0,19,1) PRINT "a=",a," b=",b ENDIF IF (10==a,b) STOP ENDLOOP  
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#uBasic.2F4tH
uBasic/4tH
Do n = RND(20) Print n Until n = 10 Print RND(20) Loop
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Quackery
Quackery
[ stack ] is instances   [ 1 instances put $ "" swap behead swap space join witheach [ 2dup != iff [ rot instances share number$ join rot join swap 1 instances replace ] else [ drop 1 instances tally ] ] drop instances rel...
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#R
R
look.and.say <- function(x, return.an.int=FALSE) { #convert number to character vector xstr <- unlist(strsplit(as.character(x), "")) #get run length encoding rlex <- rle(xstr) #form new string odds <- as.character(rlex$lengths) evens <- rlex$values newstr <- as.vector(rbind(odds, evens)) #...
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. ...
#PHP
PHP
for ($i = 1; $i <= 5; $i++) { for ($j = 1; $j <= $i; $j++) { echo '*'; } echo "\n"; }
http://rosettacode.org/wiki/Long_multiplication
Long multiplication
Task Explicitly implement   long multiplication. This is one possible approach to arbitrary-precision integer algebra. For output, display the result of   264 * 264. Optionally, verify your result against builtin arbitrary precision support. The decimal representation of   264   is: 18,446,744,073,709,551,61...
#zkl
zkl
var BN=Import("zklBigNum"); BN(2).pow(64) * BN(2).pow(64) 340282366920938463463374607431768211456   BN(2).pow(128) : "%,d".fmt(_) 340,282,366,920,938,463,463,374,607,431,768,211,456   //42!, also BN(42).factorial() [2..42].reduce(fcn(p,n){p*n},BN(1)) : "%,d".fmt(_) 1,405,006,117,752,879,898,543,142,606,244,511,569,9...
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Scheme
Scheme
(define (logic a b) (display "a and b is ") (display (and a b)) (newline) (display "a or b is ") (display (or a b)) (newline) (display "not a is ") (display (not a)) (newline))
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Seed7
Seed7
const proc: writeLogic (in boolean: a, in boolean: b) is func begin writeln("a and b is " <& a and b); writeln("a or b is " <& a or b); writeln("not a is " <& not a); end func;
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: ...
#Oz
Oz
for I in [a b c] J in ['A' 'B' 'C'] K in [1 2 3] do {System.showInfo I#J#K} end
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#UNIX_Shell
UNIX Shell
while true; do a=`jot -w %d -r 1 0 20` || exit $? echo $a test 10 -eq $a && break b=`jot -w %d -r 1 0 20` || exit $? echo $b done
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Racket
Racket
  #lang racket   (define (encode str) (regexp-replace* #px"(.)\\1*" str (lambda (m c) (~a (string-length m) c))))   (define (look-and-say-sequence n) (reverse (for/fold ([r '("1")]) ([n n]) (cons (encode (car r)) r))))   (for-each displayln (look-and-say-sequence 10))  
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Raku
Raku
.say for ('1', *.subst(/(.)$0*/, { .chars ~ .[0] }, :g) ... *)[^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. ...
#Picat
Picat
go => N = 5, foreach(I in 1..N) foreach(_J in 1..I) print("*") end, nl end.
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Self
Self
true not = false. ( true && false ) = false. ( true ^^ false ) = true. "xor" ( true || false ) = true. "or"  
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Sidef
Sidef
func logic(a, b) { say ("a and b: ", a && b); say ("a or b: ", a || b); say ("a xor b: ", a ^ b); say (" not a: ", !a); }   logic(false, true);
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: ...
#PARI.2FGP
PARI/GP
loopMultiple(V)={ my(l=#V[1]); for(i=2,#V,l=min(l,#V[i])); for(i=1,#V[1], for(j=1,#V, print1(V[j][i]) ); print() ) };
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#Ursa
Ursa
decl ursa.util.random r decl int a b while true set a (r.getint 19) out a endl console if (= a 10) break end while set b (r.getint 19) out b endl console end while
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#VBA
VBA
Public Sub LoopsBreak() Dim value As Integer Randomize Do While True value = Int(20 * Rnd) Debug.Print value If value = 10 Then Exit Do Debug.Print Int(20 * Rnd) Loop End Sub
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#REXX
REXX
/*REXX program displays the sequence (and/or lengths) for the look and say series.*/ parse arg N ! . /*obtain optional arguments from the CL*/ if N=='' | N=="," then N= 20 /*Not specified? Then use the default.*/ if !=='' | !=="," then != 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. ...
#PicoLisp
PicoLisp
(for N 5 (do N (prin "*")) (prinl) )
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#SkookumScript
SkookumScript
!logic: (a? b?) [ println("a and b: " a and b) println("a or b: " a or b) println("not a: " not a) println("a xor b: " a xor b) println("a nand b: " a nand b) println("a nor b: " a nor b) println("a not xor b: " a nxor b) ]  
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Slate
Slate
{#/\. #\/. #not} do: [ |:func| func arity = 1 ifTrue: [inform: 'True ' ; (func as: String) ; ' = ' ; (func sendTo: {True}) printString. inform: 'False ' ; (func as: String) ; ' = ' ; (func sendTo: {False}) printString.].   func arity = 2 ifTrue: [{{True. True}. {True. False}. {False. ...
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: ...
#Pascal
Pascal
sub zip (&@) { my $code = shift; my $min; $min = $min && $#$_ > $min ? $min : $#$_ for @_;   for my $i(0..$min){ $code->(map $_->[$i] ,@_) } } my @a1 = qw( a b c ); my @a2 = qw( A B C ); my @a3 = qw( 1 2 3 );   zip { print @_,"\n" }\(@a1, @a2, @a3);
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#VBScript
VBScript
Dim a, b, i   Do a = Int(Rnd * 20) WScript.StdOut.Write a If a = 10 Then Exit Do b = Int(Rnd * 20) WScript.Echo vbNullString, b Loop   For i = 1 To 100000 a = Int(Rnd * 20) WScript.StdOut.Write a If a = 10 Then Exit For b = Int(Rnd * 20) WScript.Echo vbNullString, b Next
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Ring
Ring
  number = "1" for nr = 1 to 10 number = lookSay(number) see number + nl next   func lookSay n i = 0 j = 0 c="" o="" i = 1 while i <= len(n) c = substr(n,i,1) j = i + 1 while substr(n,j,1) = c j += 1 end o += string(j-i) + 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. ...
#Pike
Pike
int main(){ for(int i = 1; i <= 5; i++){ for(int j=1; j <= i; j++){ write("*"); } write("\n"); } }
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Smalltalk
Smalltalk
|test| test := [ :a :b | ('%1 %2 %3 = %4' % { a. 'and'. b. (a & b) }) displayNl. ('%1 %2 %3 = %4' % { a. 'or'. b. (a | b) }) displayNl. ('%1 %2 = %3' % {'not'. a. (a not) }) displayNl ].   test value: true value: true. test value: false value: false. test value: true value: false. test value: false value: true.
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Standard_ML
Standard ML
fun print_logic (a, b) = ( print ("a and b is " ^ Bool.toString (a andalso b) ^ "\n"); print ("a or b is " ^ Bool.toString (a orelse b) ^ "\n"); print ("not a is " ^ Bool.toString (not a) ^ "\n") )
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: ...
#Perl
Perl
sub zip (&@) { my $code = shift; my $min; $min = $min && $#$_ > $min ? $min : $#$_ for @_;   for my $i(0..$min){ $code->(map $_->[$i] ,@_) } } my @a1 = qw( a b c ); my @a2 = qw( A B C ); my @a3 = qw( 1 2 3 );   zip { print @_,"\n" }\(@a1, @a2, @a3);
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#Visual_Basic_.NET
Visual Basic .NET
Module Program Sub Main() ' Initialize with seed 0 to get deterministic output (may vary across .NET versions, though). Dim rand As New Random(0)   Do Dim first = rand.Next(20) ' Upper bound is exclusive. Console.Write(first & " ")   If first = 10 Then Exi...
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#Vlang
Vlang
import rand import rand.seed   fn main() { rand.seed(seed.time_seed_array(2)) for { a := rand.intn(20)? println(a) if a == 10 { break } b := rand.intn(20)? println(b) } }
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Ruby
Ruby
  class String def look_and_say gsub(/(.)\1*/){|s| s.size.to_s + s[0]} end end   ss = '1' 12.times {puts ss; ss = ss.look_and_say}  
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. ...
#PILOT
PILOT
C  :i = 1 *OuterLoop C  :j = 0 C  :$stars = *InnerLoop C  :j = j + 1 C  :$stars =*$stars J ( j < i )  :*InnerLoop T  :$stars C  :i = i + 1 J ( i < 6 )  :*OuterLoop END:
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Stata
Stata
prog def bool args a b di `a'&`b' di `a'|`b' di !`a' end
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Swift
Swift
func logic(a: Bool, b: Bool) { println("a AND b: \(a && b)"); println("a OR b: \(a || b)"); println("NOT a: \(!a)"); }
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: ...
#Phix
Phix
procedure print3(sequence a, b, c) for i=1 to min({length(a),length(b),length(c)}) do printf(1, "%s%s%g\n", {a[i], b[i], c[i]}) end for end procedure print3("abc","ABC",{1, 2, 3}) ?columnize({"abc","ABC","1234"},{},' ')
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#Wren
Wren
import "random" for Random   var r = Random.new() while (true) { var n = r.int(20) System.print(n) if (n == 10) break System.print(r.int(20)) }
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#XBasic
XBasic
  PROGRAM "loopbreak"   IMPORT "xst" ' for XstGetSystemTime   DECLARE FUNCTION Entry()   ' Pseudo-random number generator ' Based on the rand, srand functions from Kernighan & Ritchie's book ' 'The C Programming Language' DECLARE FUNCTION Rand() DECLARE FUNCTION SRand(seed%%)   FUNCTION Entry() XstGetSystemTime (@mse...
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Rust
Rust
fn next_sequence(in_seq: &[i8]) -> Vec<i8> { assert!(!in_seq.is_empty());   let mut result = Vec::new(); let mut current_number = in_seq[0]; let mut current_runlength = 1;   for i in &in_seq[1..] { if current_number == *i { current_runlength += 1; } else { res...
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. ...
#PL.2FI
PL/I
do i = 1 to 5; do j = 1 to i; put edit ('*') (a); end; put skip; end;
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Tcl
Tcl
proc logic {a b} { puts "a and b: [expr {$a && $b}]" puts "a or b: [expr {$a || $b}]" puts "not a: [expr {!$a}]" }
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Toka
Toka
[ 0 <> [ ." true" ] [ ." false"] ifTrueFalse ] is .bool [ ( a b -- ) cr ." a = " over .bool ." b = " dup .bool cr ." a and b = " 2dup and .bool cr ." a or b = " over or .bool cr ." not a = " 0 = .bool ] is logic
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: ...
#Phixmonti
Phixmonti
include ..\Utilitys.pmt   ( "abc" "ABC" "123" )   len var dim1 1 get len var dim2 drop   dim1 for var i dim2 for var j ( j i ) sget tochar print endfor nl endfor  
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#XBS
XBS
while(true){ set n:number = math.random(0,19); log(`first: {n}`); if(n==10){stop} n = math.random(0,19); log(`second: {n}`); }
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#XPL0
XPL0
include c:\cxpl\codes; int N; loop [N:= Ran(20); IntOut(0, N); if N=10 then quit; ChOut(0, 9\tab\); IntOut(0, Ran(20)); CrLf(0); ]
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Sather
Sather
class MAIN is look_and_say!: STR is current ::= "1"; loop yield current; buf ::= #FSTR; last ::= current[0]; count ::= 0; loop ch ::= current.elt!; if ch /= last then buf := buf + count + last; last := ch; ...
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. ...
#Plain_English
Plain English
To run: Start up. Write a triangle of asterisks on the console given 5. Wait for the escape key. Shut down.   To write a row of asterisks on the console given a number: If a counter is past the number, write "" on the console; exit. Write "*" on the console without advancing. Repeat.   To write a triangle of asterisks ...
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#uBasic.2F4tH
uBasic/4tH
Proc _Boolean(4, 2) Proc _Boolean(0, 2) Proc _Boolean(2, 0)   End     _Boolean Param(2) a@ = a@ # 0 ' Transform to true booleans b@ = b@ # 0   print "A and B is "; a@ * b@ ' Multiplication will now do AND print "A or B is "; a@ + b@ ' Addition will now do OR print "no...
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: ...
#PHP
PHP
$a = array('a', 'b', 'c'); $b = array('A', 'B', 'C'); $c = array('1', '2', '3'); //These don't *have* to be strings, but it saves PHP from casting them later   if ((sizeOf($a) !== sizeOf($b)) || (sizeOf($b) !== sizeOf($c))){ throw new Exception('All three arrays must be the same length'); } foreach ($a as $key => $v...
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#Yabasic
Yabasic
do i = int(ran(19)) print i using "##"; print " "; if i = 10 then break : fi i = int(ran(19)) print i using "##", " "; loop print end
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#Zig
Zig
const std = @import("std");   pub fn main() !void { const RndGen = std.rand.DefaultPrng; var rnd = RndGen.init(42); // possible improvement: make rng fair var rand_num1: u5 = undefined; var rand_num2: u5 = undefined; while (true) { rand_num1 = rnd.random().int(u5) % 20; try std.i...
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Scala
Scala
import scala.annotation.tailrec   object LookAndSay extends App {   loop(10, "1")   @tailrec private def loop(n: Int, num: String): Unit = { println(num) if (n <= 0) () else loop(n - 1, lookandsay(num)) }   private def lookandsay(number: String): String = { val result = new StringBuilder   @ta...
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. ...
#Pop11
Pop11
lvars i, j; for i from 1 to 5 do for j from 1 to i do printf('*','%p'); endfor; printf('\n') endfor;
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#V
V
[mylogic [get2 [dup] dip swap [dup] dip]. get2 and puts get2 or puts swap not puts pop ].
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Vala
Vala
public class Program { private static void print_logic (bool a, bool b) { print ("a and b is %s\n", (a && b).to_string ()); print ("a or b is %s\n", (a || b).to_string ()); print ("not a %s\n", (!a).to_string ()); } public static int main (string[] args) { if (args.length < 3...
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: ...
#Picat
Picat
import util.   go =>   L1 = ["a","b","c"], L2 = ["A","B","C"], L3 = ["1","2","3"],   println("foreach loop:"), foreach({A,B,C} in zip(L1,L2,L3)) println([A,B,C].join('')) end, nl,   println("list comprehension/n:"), println( [[A,B,C].join('') : {A,B,C} in zip(L1,L2,L3)].join("\n")), nl,    % W...
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#zkl
zkl
while(1){n:=(0).random(20); n.print(" "); if (n==10){ println(); break; } (0).random().println(); }
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Seed7
Seed7
$ include "seed7_05.s7i";   const func string: lookAndSay (in integer: level, in string: stri) is func result var string: lookAndSay is ""; local var integer: index is 2; begin if level = 1 then if stri <> "" then while index <= length(stri) and stri[index] = stri[1] do incr(in...
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. ...
#PowerShell
PowerShell
for ($i = 1; $i -le 5; $i++) { for ($j = 1; $j -le $i; $j++) { Write-Host -NoNewline * } Write-Host }
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Verilog
Verilog
module main; integer a, b;   initial begin a = 1; //true b = 0; //false $display(a && b); //AND $display(a || b); //OR $display(!a); //NOT $finish ; end endmodule
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Visual_Basic_.NET
Visual Basic .NET
Function Test(ByVal a As Boolean, ByVal b As Boolean) Console.WriteLine("And " & a And b) Console.WriteLine("Or " & a Or b) Console.WriteLine("Not " & Not a) Console.WriteLine("Xor " & a Xor b) Console.WriteLine("And, short-circuited " & a AndAlso b) Console.WriteLine("Or, short-circuited " & a ...
http://rosettacode.org/wiki/Levenshtein_distance/Alignment
Levenshtein distance/Alignment
The Levenshtein distance algorithm returns the number of atomic operations (insertion, deletion or edition) that must be performed on a string in order to obtain an other one, but it does not say anything about the actual operations used or their order. An alignment is a notation used to describe the operations used t...
#11l
11l
F levenshteinAlign(aa, bb) V a = aa.lowercase() V b = bb.lowercase() V costs = [[0] * (b.len + 1)] * (a.len + 1) L(j) 0 .. b.len costs[0][j] = j L(i) 1 .. a.len costs[i][0] = i L(j) 1 .. b.len V tmp = costs[i - 1][j - 1] + Int(a[i - 1] != b[j - 1]) costs[i][j] = min(1 ...
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: ...
#PicoLisp
PicoLisp
(mapc prinl '(a b c) '(A B C) (1 2 3) )
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Sidef
Sidef
func lookandsay(str) { str.gsub(/((.)\2*)/, {|a,b| a.len.to_s + b }); }   var num = "1"; { say num; num = lookandsay(num); } * 10;
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. ...
#Processing
Processing
size( 105,120 );   for ( int i=20; i<=100; i+=20 ) for ( int j=10; j<=i; j+=20 ) text( "*", j,i );
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Wren
Wren
var f = Fn.new { |a, b| System.print("a = %(a)") System.print("b = %(b)") System.print("!a = %(!a)") System.print("a && b = %(a && b)") System.print("a || b = %(a || b)") System.print() }   var tests = [ [true, true], [true, false], [false, true], [false, false] ] for (test in test...
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#XLISP
XLISP
(defun logical-functions (a b) (print `(a and b = ,(and a b))) (print `(a or b = ,(or a b))) (print `(not a = ,(not a))) )
http://rosettacode.org/wiki/Levenshtein_distance/Alignment
Levenshtein distance/Alignment
The Levenshtein distance algorithm returns the number of atomic operations (insertion, deletion or edition) that must be performed on a string in order to obtain an other one, but it does not say anything about the actual operations used or their order. An alignment is a notation used to describe the operations used t...
#Arturo
Arturo
print join.with:"\n" levenshtein.align "place" "palace" print join.with:"\n" levenshtein.align "rosettacode" "raisethysword"
http://rosettacode.org/wiki/Levenshtein_distance/Alignment
Levenshtein distance/Alignment
The Levenshtein distance algorithm returns the number of atomic operations (insertion, deletion or edition) that must be performed on a string in order to obtain an other one, but it does not say anything about the actual operations used or their order. An alignment is a notation used to describe the operations used t...
#C
C
#include <stdio.h> #include <stdlib.h> #include <string.h>   typedef struct edit_s edit_t, *edit; struct edit_s { char c1, c2; int n; edit next; };   void leven(char *a, char *b) { int i, j, la = strlen(a), lb = strlen(b); edit *tbl = malloc(sizeof(edit) * (1 + la)); tbl[0] = calloc((1 + la) * (1 + lb), sizeof(ed...
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: ...
#Pike
Pike
  array a1 = ({ "a", "b", "c" }); array a2 = ({ "A", "B", "C" }); array a3 = ({ "1", "2", "3" });   foreach(a1; int index; string char_dummy) write("%s%s%s\n", a1[index], a2[index], a3[index]);  
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Smalltalk
Smalltalk
String extend [ lookAndSay [ |anElement nextElement counter coll newColl| coll := (self asOrderedCollection). newColl := OrderedCollection new. counter := 0. anElement := (coll first). [ coll size > 0 ] whileTrue: [ nextElement := coll removeFirst. ( anElement == nextElement ) i...
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. ...
#Prolog
Prolog
example :- between(1,5,I), nl, between(1,I,_J), write('*'), fail. example.
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic 'code' declarations   func Logic(A, B); int A, B; [HexOut(0, A and B); ChOut(0, ^ ); HexOut(0, A or B); ChOut(0, ^ ); HexOut(0, not A); ChOut(0, ^ ); HexOut(0, A xor B); ]; \Logic   [Logic(false, false); CrLf(0); Logic(true, false); CrLf(0); Logic(true, true); C...
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#XSLT
XSLT
<xsl:template name="logic"> <xsl:param name="a" select="true()"/> <xsl:param name="b" select="false()"/> <fo:block>a and b = <xsl:value-of select="$a and $b"/></fo:block> <fo:block>a or b = <xsl:value-of select="$a or $b"/></fo:block> <fo:block>not a = <xsl:value-of select="not($a)"/></fo:block> </xsl:templa...
http://rosettacode.org/wiki/Legendre_prime_counting_function
Legendre prime counting function
The prime-counting function π(n) computes the number of primes not greater than n. Legendre was the first mathematician to create a formula to compute π(n) based on the inclusion/exclusion principle. To calculate: Define φ(x, 0) = x φ(x, a) = φ(x, a−1) − φ(⌊x/pa⌋, a−1), where pa is the ath prime number. then π(n) ...
#C.2B.2B
C++
#include <cmath> #include <iostream> #include <unordered_map> #include <vector>   std::vector<int> generate_primes(int limit) { std::vector<bool> sieve(limit >> 1, true); for (int p = 3, s = 9; s < limit; p += 2) { if (sieve[p >> 1]) { for (int q = s; q < limit; q += p << 1) ...
http://rosettacode.org/wiki/Levenshtein_distance/Alignment
Levenshtein distance/Alignment
The Levenshtein distance algorithm returns the number of atomic operations (insertion, deletion or edition) that must be performed on a string in order to obtain an other one, but it does not say anything about the actual operations used or their order. An alignment is a notation used to describe the operations used t...
#D
D
void main() { import std.stdio, std.algorithm;   immutable s1 = "rosettacode"; immutable s2 = "raisethysword";   string s1b, s2b; size_t pos1, pos2;   foreach (immutable c; levenshteinDistanceAndPath(s1, s2)[1]) { final switch (c) with (EditOp) { case none, substitute: ...
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: ...
#PL.2FI
PL/I
  declare P(3) character (1) initial ('a', 'b', 'c'), Q(3) character (1) initial ('A', 'B', 'C'), R(3) fixed decimal (1) initial (1, 2, 3);   do i = lbound(P,1) to hbound(P,1); put skip edit (P(i), Q(i), R(i)) (2 A, F(1)); end;  
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#SNOBOL4
SNOBOL4
* # Encode RLE define('rle(str)c,n') :(rle_end) rle str len(1) . c :f(return) str span(c) @n = rle = rle n c :(rle) rle_end   * # First m members of sequence with seed n define('looksay(n,m)') :(looksay_end) looksay output = n; m = gt(m,1) m - 1 :f(return) n = rl...
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. ...
#Python
Python
import sys for i in xrange(5): for j in xrange(i+1): sys.stdout.write("*") print
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#zkl
zkl
fcn f(a,b){a and b} fcn g(a,b){a or b} fcn h(a){(not a)}
http://rosettacode.org/wiki/Legendre_prime_counting_function
Legendre prime counting function
The prime-counting function π(n) computes the number of primes not greater than n. Legendre was the first mathematician to create a formula to compute π(n) based on the inclusion/exclusion principle. To calculate: Define φ(x, 0) = x φ(x, a) = φ(x, a−1) − φ(⌊x/pa⌋, a−1), where pa is the ath prime number. then π(n) ...
#CoffeeScript
CoffeeScript
  sorenson = require('sieve').primes # Sorenson's extensible sieve from task: Extensible Prime Generator   # put in outer scope to avoid recomputing the cache memoPhi = {} primes = []   isqrt = (x) -> Math.floor Math.sqrt x   pi = (n) -> phi = (x, a) -> y = memoPhi[[x,a]] return y unless y is undef...
http://rosettacode.org/wiki/Levenshtein_distance/Alignment
Levenshtein distance/Alignment
The Levenshtein distance algorithm returns the number of atomic operations (insertion, deletion or edition) that must be performed on a string in order to obtain an other one, but it does not say anything about the actual operations used or their order. An alignment is a notation used to describe the operations used t...
#Eiffel
Eiffel
  distance (source, target: STRING): INTEGER -- Minimum number of operations to turn `source' into `target'. local l_distance: ARRAY2 [INTEGER] del, ins, subst: INTEGER do create l_distance.make (source.count, target.count) ⟳ ic:(1 |..| source.count) ¦ l_distance [ic, 1] := ic - 1 ⟲ ⟳ ij:(1 |..| target.co...
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: ...
#PostScript
PostScript
  % transpose is defined in initlib like this. /transpose { [ exch { { {empty? exch pop} map all?} {pop exit} ift [ exch {} {uncons {exch cons} dip exch} fold counttomark 1 roll] uncons } loop ] {reverse} map }.   % using it. [[/a /b /c] [/A /B /C] [1 2 3]] transpose  
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#SQL
SQL
DROP VIEW delta; CREATE VIEW delta AS SELECT sequence1.v AS x, (sequence1.v<>sequence2.v)*sequence1.c AS v, sequence1.c AS c FROM SEQUENCE AS sequence1, SEQUENCE AS sequence2 WHERE sequence1.c = sequence2.c+1;   DROP VIEW rle0; CREATE VIEW rle0 AS SELECT delta2.x AS x...
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. ...
#QB64
QB64
FOR c = 1 TO 5 FOR n = 1 TO c PRINT "*"; NEXT PRINT NEXT
http://rosettacode.org/wiki/Legendre_prime_counting_function
Legendre prime counting function
The prime-counting function π(n) computes the number of primes not greater than n. Legendre was the first mathematician to create a formula to compute π(n) based on the inclusion/exclusion principle. To calculate: Define φ(x, 0) = x φ(x, a) = φ(x, a−1) − φ(⌊x/pa⌋, a−1), where pa is the ath prime number. then π(n) ...
#Erlang
Erlang
  -mode(native).   -define(LIMIT, 1000000000).   main(_) -> put(primes, array:from_list(primality:sieve(floor(math:sqrt(?LIMIT))))), ets:new(memphi, [set, named_table, protected]), output(0, 9).   nthprime(N) -> array:get(N - 1, get(primes)).   output(A, B) -> output(A, B, 1). output(A, B, _) when A > B -> ...
http://rosettacode.org/wiki/Levenshtein_distance/Alignment
Levenshtein distance/Alignment
The Levenshtein distance algorithm returns the number of atomic operations (insertion, deletion or edition) that must be performed on a string in order to obtain an other one, but it does not say anything about the actual operations used or their order. An alignment is a notation used to describe the operations used t...
#Go
Go
package main   import ( "fmt"   "github.com/biogo/biogo/align" ab "github.com/biogo/biogo/alphabet" "github.com/biogo/biogo/feat" "github.com/biogo/biogo/seq/linear" )   func main() { // Alphabets for things like DNA are predefined in biogo, but we // define our own here. lc := ab.Must(a...
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: ...
#PowerBASIC
PowerBASIC
FUNCTION PBMAIN () AS LONG DIM x(2), y(2) AS STRING * 1 DIM z(2) AS LONG   'data ARRAY ASSIGN x() = ("a", "b", "c") ARRAY ASSIGN y() = ("A", "B", "C") ARRAY ASSIGN z() = (1, 2, 3)   'set upper bound C& = UBOUND(x) IF UBOUND(y) > C& THEN C& = UBOUND(y) IF UBOUND(z) > C& THEN C& = ...
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#SQL_PL
SQL PL
  SET SERVEROUTPUT ON @   BEGIN DECLARE NMBR VARCHAR(100) DEFAULT '1'; DECLARE J SMALLINT DEFAULT 1;   CALL DBMS_OUTPUT.PUT_LINE(NMBR); WHILE (J < 10) DO BEGIN DECLARE I SMALLINT; DECLARE SIZE SMALLINT; DECLARE ACTUAL CHAR(1); DECLARE REPEAT CHAR(1); DECLARE RESULT VARCHAR(100); DECLARE TIMES SMALLINT...