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/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Retro
Retro
$c 'hello,_world! 'This_is_'a_string'  
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#REXX
REXX
char1 = "A" char2 = 'A' str = "this is a string" another = 'this is also a string' escape1 = "that's it!" escape2 = 'that''s it!'
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Retro
Retro
#100 ( decimal ) %100 ( binary ) $100 ( hex ) 'c ( ascii character ) 100 ( number in current base )
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#REXX
REXX
/*REXX pgm displays an integer (expressed in the pgm as a literal) in different bases*/ /*────────── expressing decimal numbers ──────────*/ ddd = 123 /*a decimal number (expressed as a literal). */ ddd = '123' /*this is...
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 |...
#Maxima
Maxima
f(a, b) := [not a, a or b, a and b];   /* to use multiple arguments, use any of these */ a and b and c and d; a or b or c or d; "and"(a, b, c, d); "or"(a, b, c, d); apply("and", [a, b, c, d]); apply("or", [a, b, c, d]);
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 |...
#MAXScript
MAXScript
fn printLogic a b = ( format "a and b is %\n" (a and b) format "a or b is %\n" (a or b) format "not a is %\n" (not 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: ...
#Jsish
Jsish
/* Loop over multiple arrays, in Jsish */ var a1 = ['a', 'b', 'c']; var a2 = ['A', 'B', 'C']; var a3 = [1, 2, 3];   puts('Equal sizes'); var arr = [a1, a2, a3]; var m = arr[0].length; for (var a of arr) if (a.length > m) m = a.length; for (var i = 0; i < m; i++) printf("%q%q%q\n", a1[i], a2[i], a3[i]);   puts('\nUnequ...
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...
#Oz
Oz
for break:Break do R = {OS.rand} mod 20 in {Show R} if R == 10 then {Break} else {Show {OS.rand} mod 20} end 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...
#PARI.2FGP
PARI/GP
while(1, t=random(20); print(t); if(t==10, break); print(random(20)) )
http://rosettacode.org/wiki/Longest_common_subsequence
Longest common subsequence
Introduction Define a subsequence to be any output string obtained by deleting zero or more symbols from an input string. The Longest Common Subsequence (LCS) is a subsequence of maximum length common to two or more strings. Let A ≡ A[0]… A[m - 1] and B ≡ B[0]… B[n - 1], m < n be strings drawn from an alphabet Σ of ...
#Scheme
Scheme
  ;; using srfi-69 (define (memoize proc) (let ((results (make-hash-table))) (lambda args (or (hash-table-ref results args (lambda () #f)) (let ((r (apply proc args))) (hash-table-set! results args r) r)))))   (define (longest xs ys) (if (> (length xs) (length ys...
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...
#Maxima
Maxima
collect(a) := block( [n: length(a), b: [ ], x: a[1], m: 1], for i from 2 thru n do (if a[i] = x then m: m + 1 else (b: endcons([x, m], b), x: a[i], m: 1)), b: endcons([x, m], b) )$   look_and_say(s) := apply(sconcat, map(lambda([p], sconcat(string(p[2]), p[1])), collect(charlist(s))))$   block([s: "1"], ...
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#SPL
SPL
> n, 1..10 s += n  ? n%5, s += ", " >> n%5 #.output(s) s = "" <
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#SQL_PL
SQL PL
  --#SET TERMINATOR @   SET SERVEROUTPUT ON @   BEGIN DECLARE I SMALLINT DEFAULT 1;   Loop: WHILE (I <= 10) DO CALL DBMS_OUTPUT.PUT(I); SET I = I + 1; IF (MOD(I - 1, 5) = 0) THEN CALL DBMS_OUTPUT.PUT_LINE(' '); ITERATE Loop; END IF; CALL DBMS_OUTPUT.PUT(', '); END WHILE Loop; END @  
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#Vlang
Vlang
const ( input = '49927398716 49927398717 1234567812345678 1234567812345670'   t = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9] )   fn luhn(s string) bool { odd := s.len & 1 mut sum := 0 for i, c in s.split('') { if c < '0' || c > '9' { return false } if i&1 == odd { ...
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. ...
#Mercury
Mercury
:- module loops_for. :- interface.   :- import_module io. :- pred main(io::di, io::uo) is det.   :- implementation. :- import_module int.   main(!IO) :- int.fold_up(outer_loop_body, 1, 5, !IO).   :- pred outer_loop_body(int::in, io::di, io::uo) is det.   outer_loop_body(I, !IO) :- int.fold_up(inner_loop_body, 1, ...
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
Task Demonstrate a   for-loop   where the step-value is greater than one. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For with a specified step   Loops/Foreach   Loops/Increment loop index within loop b...
#Vala
Vala
for (int i = 1; i < 10; i += 2) stdout.printf("%d\n", i);
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
Task Demonstrate a   for-loop   where the step-value is greater than one. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For with a specified step   Loops/Foreach   Loops/Increment loop index within loop b...
#VAX_Assembly
VAX Assembly
0000 0000 1 .entry main,0 50 D4 0002 2 clrf r0 ;init to 0.0 0004 3 loop: 01 0004 4 nop ;do nothing FFF9 50 0A 3E 4F 0005 5 acbf #112.0, ...
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...
#PL.2FI
PL/I
/* Multiply a by b, giving c. */ multiply: procedure (a, b, c); declare (a, b, c) (*) fixed decimal (1); declare (d, e, f) (hbound(a,1)) fixed decimal (1); declare pr (-hbound(a,1) : hbound(a,1)) fixed decimal (1); declare p fixed decimal (2), (carry, s) fixed decimal (1); declare neg bit (1) aligned; ...
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Ring
Ring
  see 'This is a "quoted string"'  
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Ruby
Ruby
'single quotes with \'embedded quote\' and \\backslash' %q(not interpolating with (nested) parentheses and newline)
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#S-lang
S-lang
% String literals variable c, ch, s, b, r, v;   c = 'A'; ch = '\x{1d7bc}';   printf("Double quotes\n"); s = "this is a single line string with\t\tbackslash substitutions"; () = fputs(s, stdout); () = fputs("\n", stdout);   s = "this is a single line string without\t\tbackslash substitutions"R; () = fputs(s, stdout); ()...
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Ring
Ring
  see "Decimal literal = " + 1234 + nl see "Hexadecimal literal = " + dec("4D2") + nl see "Octal Literal = " + octal(668) + nl see "Binary literal = " + bintodec("10011010010")   func bintodec(bin) binsum = 0 for n=1 to len(bin) binsum = binsum + number(bin[n]) *pow(2, len(bin)-n) next ret...
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Ruby
Ruby
727 == 0b1011010111 # => true, binary 727 == 0x2d7 # => true, hex 727 == 0o1327 # => true, octal 727 == 01327 # => true, octal   12345 == 12_345 # => true underscores are ignored; useful for keeping track of places  
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 |...
#Metafont
Metafont
def tf(expr a) = if a: "true" else: "false" fi enddef; def test(expr a, b) = for o = "and", "or": message tf(a) & " " & o & " " & tf(b); show a scantokens(o) b; endfor message "not " & tf(a); show not a enddef;
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 |...
#min
min
(  :b :a "xor is: " print! a b xor puts! "and is: " print! a b and puts! "or is: " print! a b or puts! "not is: " print! a not puts! ) :logical-operators
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: ...
#Julia
Julia
foreach(println, ('a', 'b', 'c'), ('A', 'B', 'C'), (1, 2, 3))
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...
#Pascal
Pascal
while (1) { my $a = int(rand(20)); print "$a\n"; if ($a == 10) { last; } my $b = int(rand(20)); print "$b\n"; }
http://rosettacode.org/wiki/Longest_common_subsequence
Longest common subsequence
Introduction Define a subsequence to be any output string obtained by deleting zero or more symbols from an input string. The Longest Common Subsequence (LCS) is a subsequence of maximum length common to two or more strings. Let A ≡ A[0]… A[m - 1] and B ≡ B[0]… B[n - 1], m < n be strings drawn from an alphabet Σ of ...
#Seed7
Seed7
$ include "seed7_05.s7i";   const func string: lcs (in string: a, in string: b) is func result var string: lcs is ""; local var string: x is ""; var string: y is ""; begin if a <> "" and b <> "" then if a[length(a)] = b[length(b)] then lcs := lcs(a[.. pred(length(a))], b[.. pred(leng...
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...
#MAXScript
MAXScript
fn lookAndSay num = ( local result = "" num += " " local current = num[1] local numReps = 1   for digit in 2 to num.count do ( if num[digit] != current then ( result += (numReps as string) + current numReps = 1 current = num[digit] ) ...
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#Stata
Stata
forvalues n=1/10 { display `n' _continue if mod(`n',5)==0 { display continue } display ", " _continue }
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#Suneido
Suneido
ob = Object() for (i = 1; i <= 10; ++i) { ob.Add(i) if i is 5 { Print(ob.Join(',')) ob = Object() } } Print(ob.Join(','))
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#Wren
Wren
import "/fmt" for Fmt import "/trait" for Stepped   var luhn = Fn.new { |s| // reverse digits s = s[-1..0] // sum the odd digits var s1 = Stepped.new(s, 2).reduce(0) { |sum, d| sum + d.bytes[0] - 48 } // sum two times the even digits var s2 = Stepped.new(s[1..-1], 2).reduce(0) { |sum, d| ...
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. ...
#MiniScript
MiniScript
for i in range(1,5) s = "" for j in range(1, i) s = s + "*" end for print s end for
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
Task Demonstrate a   for-loop   where the step-value is greater than one. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For with a specified step   Loops/Foreach   Loops/Increment loop index within loop b...
#VBA
VBA
Sub MyLoop() For i = 2 To 8 Step 2 Debug.Print i; Next i Debug.Print End Sub
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...
#PL.2FM
PL/M
100H: /* LONG MULTIPLICATION OF LARGE INTEGERS */ /* LARGE INTEGERS ARE REPRESENTED BY ARRAYS OF BYTES WHOSE VALUES ARE */ /* A SINGLE DECIMAL DIGIT OF THE NUMBER */ /* THE LEAST SIGNIFICANT DIGIT OF THE LARGE INTEGER IS IN ELEMENT 1 */ ...
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Scala
Scala
val c = 'c'
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Scheme
Scheme
#\a #\A #\? #\space #\newline
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Seed7
Seed7
var char: ch is 'z';
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Rust
Rust
10 // Decimal 0b10 // Binary 0x10 // Hexadecimal 0o10 // Octal 1_000 // Underscores may appear anywhere in the numeric literal for clarity 10_i32 // The type (in this case i32, a 32-bit signed integer) may also be appended. 10i32 // With or without underscores
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Scala
Scala
scala> 16 res10: Int = 16 scala> 020L res11: Long = 16 scala> 0x10 : Byte res12: Byte = 16 scala> 16 : Short res13: Short = 16 scala> 020 : Int res14: Int = 16 scala> 0x10 : Long res15: Long = 16
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 |...
#Modula-2
Modula-2
MODULE LogicalOps; FROM FormatString IMPORT FormatString; FROM Terminal IMPORT WriteString,WriteLn,ReadChar;   PROCEDURE Print(a,b : BOOLEAN); VAR buf : ARRAY[0..31] OF CHAR; BEGIN FormatString("a and b is %b\n", buf, a AND b); WriteString(buf); FormatString("a or b is %b\n", buf, a OR b); WriteString(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 |...
#Modula-3
Modula-3
MODULE Logical EXPORTS Main;   FROM IO IMPORT Put; FROM Fmt IMPORT Bool;   PROCEDURE Test(a, b: BOOLEAN) = BEGIN Put("a AND b is " & Bool(a AND b) & "\n"); Put("a OR b is " & Bool(a OR b) & "\n"); Put("NOT a is " & Bool(NOT a) & "\n"); END Test;   BEGIN Test(TRUE, FALSE); END Logical.
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: ...
#K
K
{,/$x}'+("abc";"ABC";1 2 3)
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...
#Perl
Perl
while (1) { my $a = int(rand(20)); print "$a\n"; if ($a == 10) { last; } my $b = int(rand(20)); print "$b\n"; }
http://rosettacode.org/wiki/Longest_common_subsequence
Longest common subsequence
Introduction Define a subsequence to be any output string obtained by deleting zero or more symbols from an input string. The Longest Common Subsequence (LCS) is a subsequence of maximum length common to two or more strings. Let A ≡ A[0]… A[m - 1] and B ≡ B[0]… B[n - 1], m < n be strings drawn from an alphabet Σ of ...
#SequenceL
SequenceL
import <Utilities/Sequence.sl>;   lcsBack(a(1), b(1)) := let aSub := allButLast(a); bSub := allButLast(b);   x := lcsBack(a, bSub); y := lcsBack(aSub, b); in [] when size(a) = 0 or size(b) = 0 else lcsBack(aSub, bSub) ++ [last(a)] when last(a) = last(b) el...
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...
#Metafont
Metafont
vardef lookandsay(expr s) = string r; r := ""; if string s: i := 0; forever: exitif not (i < length(s)); c := i+1; forever: exitif ( (substring(c,c+1) of s) <> (substring(i,i+1) of s) ); c := c + 1; endfor r := r & decimal (c-i) & substring(i,i+1) of s; i := c; endfor fi r enddef;   stri...
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#Swift
Swift
for i in 1...10 { print(i, terminator: "") if i % 5 == 0 { print() continue } print(", ", terminator: "") }
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#Tcl
Tcl
for {set i 1} {$i <= 10} {incr i} { puts -nonewline $i if {$i % 5 == 0} { puts "" continue } puts -nonewline ", " }
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#Xojo
Xojo
Public Function Modulus10(digits As String) as String // // Confirm the digits are really, well, digits //   dim validator as new RegEx validator.SearchPattern = "\A\d+\z" if validator.Search( digits ) is nil then // // Raise an exception or something // end if   static doublingTable() as st...
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. ...
#Modula-2
Modula-2
MODULE For; IMPORT InOut;   VAR i, j: INTEGER;   BEGIN FOR i := 1 TO 5 DO FOR j := 1 TO i DO InOut.Write('*'); END; InOut.WriteLn END END For.
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
Task Demonstrate a   for-loop   where the step-value is greater than one. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For with a specified step   Loops/Foreach   Loops/Increment loop index within loop b...
#VBScript
VBScript
buffer = "" For i = 2 To 8 Step 2 buffer = buffer & i & " " Next WScript.Echo buffer
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...
#PowerShell
PowerShell
  # LongAddition only supports Unsigned Integers represented as Strings/Character Arrays Function LongAddition ( [Char[]] $lhs, [Char[]] $rhs ) { $lhsl = $lhs.length $rhsl = $rhs.length if(($lhsl -gt 0) -and ($rhsl -gt 0)) { $maxplace = [Math]::Max($rhsl,$lhsl)+1 1..$maxplace | ForEach-Object { $carry = 0 ...
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Sidef
Sidef
'single quotes with \'embedded quote\' and \\backslash'; ‚unicode single quoted’; %q(not interpolating with (nested) parentheses and newline);
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Slate
Slate
$a $D $8 $, $\s $\n
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#SQL
SQL
SELECT 'The boy said ''hello''.';
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Scheme
Scheme
> (= 727 #b1011010111) #t > (= 727 #o1327) #t > (= 727 #d727) #t > (= 727 #x2d7) #t
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Seed7
Seed7
$ include "seed7_05.s7i";   const proc: main is func begin writeln(727); writeln(32#MN); writeln(16#2D7); writeln(10#727); writeln(8#1327); writeln(2#1011010111); end func;  
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 |...
#MUMPS
MUMPS
  LOGIC(A,B) WRITE !,A," AND ",B," IS ",A&B WRITE !,A," OR ",B," IS ",A!B WRITE !,"NOT ",A," AND ",B," IS ",'(A)&B WRITE !,"NOT ",A," OR ",B," IS ",'(A)!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 |...
#Nanoquery
Nanoquery
def logic(a, b) println "a and b: " + (a && b) println "a or b: " + (a && b) println "not a: " + !a 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: ...
#Kotlin
Kotlin
// version 1.0.6   fun main(args: Array<String>) { val a1 = charArrayOf('a', 'b', 'c') val a2 = charArrayOf('A', 'B', 'C') val a3 = intArrayOf(1, 2, 3) for(i in 0 .. 2) println("${a1[i]}${a2[i]}${a3[i]}") println() // For arrays of different sizes we would need to iterate up to the mimimm size ...
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...
#Phix
Phix
integer i while 1 do i = rand(20)-1 printf(1, "%g ", {i}) if i=10 then exit end if printf(1, "%g\n", {rand(20)-1}) 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...
#PHP
PHP
while (true) { $a = rand(0,19); echo "$a\n"; if ($a == 10) break; $b = rand(0,19); echo "$b\n"; }
http://rosettacode.org/wiki/Longest_common_subsequence
Longest common subsequence
Introduction Define a subsequence to be any output string obtained by deleting zero or more symbols from an input string. The Longest Common Subsequence (LCS) is a subsequence of maximum length common to two or more strings. Let A ≡ A[0]… A[m - 1] and B ≡ B[0]… B[n - 1], m < n be strings drawn from an alphabet Σ of ...
#SETL
SETL
op .longest(a, b); return if #a > #b then a else b end; end .longest;   procedure lcs(a, b); if exists empty in {a, b} | #empty = 0 then return empty; elseif a(1) = b(1) then return a(1) + lcs(a(2..), b(2..)); else return lcs(a(2..), b) .longest lcs(a, b(2..))...
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...
#MiniScript
MiniScript
// Look and Say Sequence repeats = function(digit, string) count = 0 for c in string if c != digit then break count = count + 1 end for return str(count) end function   numbers = "1" print numbers for i in range(1,10) // warning, loop size > 15 gets long numbers very quickly number = "" position = 0 while po...
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#Transact-SQL
Transact-SQL
  DECLARE @i INT = 0; DECLARE @str VarChar(40) = ''; WHILE @i<10 BEGIN SET @i = @i + 1; SET @str = @str + CONVERT(varchar(2),@i); IF @i % 5 = 0 BEGIN PRINT @str; SET @str ='' CONTINUE; END SET @str = @str +', '; END;  
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT numbers="" LOOP n=1,10 numbers=APPEND (numbers,", ",n) rest=n%5 IF (rest!=0) CYCLE PRINT numbers numbers="" ENDLOOP  
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#XPL0
XPL0
string 0; \use zero-terminated strings   func Valid(Str); \Return 'true' if digits in Str pass Luhn test char Str; int Len, Sum, I, Dig; [Len:= 0; \find length of Str while Str(Len) do Len:= Len+1; Sum:= 0; \sum even and odd digits for I:= 0 to Len-1 do \(no ne...
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. ...
#Modula-3
Modula-3
MODULE Stars EXPORTS Main;   IMPORT IO;   BEGIN FOR i := 1 TO 5 DO FOR j := 1 TO i DO IO.Put("*"); END; IO.Put("\n"); END; END Stars.
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
Task Demonstrate a   for-loop   where the step-value is greater than one. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For with a specified step   Loops/Foreach   Loops/Increment loop index within loop b...
#Vedit_macro_language
Vedit macro language
for (#1 = 1; #1 < 10; #1 += 2) { Num_Type(#1) }
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
Task Demonstrate a   for-loop   where the step-value is greater than one. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For with a specified step   Loops/Foreach   Loops/Increment loop index within loop b...
#Verilog
Verilog
  module main; integer i;   initial begin   for(i = 1; i <= 21; i = i + 2) $write(i); $finish ; end endmodule  
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...
#Prolog
Prolog
?- X is 2**64 * 2**64. X = 340282366920938463463374607431768211456.
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Standard_ML
Standard ML
- #"a"; val it = #"a" : char
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Swift
Swift
let you = "You" let str1 = "\(you) can insert variables into strings." let str2 = "Swift also supports unicode in strings ı∫ƒ∂ß´™¡à" let str3 = "Swift also supports control characters \n\tLike this" let str4 = "'" // ' let str5 = "\"" // " println(str3)
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Tcl
Tcl
set str "This is Tcl $::tcl_version\tIt is [clock format [clock seconds]]" puts $str ;# ==> This is Tcl 8.5 It is Mon Apr 06 16:49:46 EDT 2009
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Sidef
Sidef
say 255; say 0xff; say 0377; say 0b1111_1111;
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Slate
Slate
2r1011010111 + 8r1327 + 10r727 + 16r2d7 / 4
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 |...
#Neko
Neko
/** Logical operations, in Neko */   /* For logical operations, values need to be explicitly treated as boolean */ /* Only null, false and 0 evaluate as false with $istrue() */   var logical = 1 if logical $print("literal 1 tests true\n") else $print("literal 1 tests false\n") if $istrue(logical) $print("$istrue(1) te...
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: ...
#Lambdatalk
Lambdatalk
  1) loop over 3 sentences of equal length and returning 3 sentences   {def A a b c} -> A {def B A B C} -> B {def C 1 2 3} -> C   {S.map {lambda {:i} {br}{S.get :i {A}} {S.get :i {B}} {S.get :i {C}} } {S.serie 0 {- {S.length {A}} 1}}} -> a A 1 b B 2 c C 3   2) ...
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...
#PicoLisp
PicoLisp
(use R (loop (println (setq R (rand 1 19))) (T (= 10 R)) (println (rand 1 19)) ) )
http://rosettacode.org/wiki/Longest_common_subsequence
Longest common subsequence
Introduction Define a subsequence to be any output string obtained by deleting zero or more symbols from an input string. The Longest Common Subsequence (LCS) is a subsequence of maximum length common to two or more strings. Let A ≡ A[0]… A[m - 1] and B ≡ B[0]… B[n - 1], m < n be strings drawn from an alphabet Σ of ...
#Sidef
Sidef
func lcs(xstr, ystr) is cached {   xstr.is_empty && return xstr; ystr.is_empty && return ystr;   var(x, xs, y, ys) = (xstr.ft(0,0), xstr.ft(1), ystr.ft(0,0), ystr.ft(1));   if (x == y) { x + lcs(xs, ys) } else { [lcs(xstr, ys), lcs(xs, ystr)].max_by { .len };...
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...
#Modula-2
Modula-2
MODULE LookAndSay; FROM InOut IMPORT WriteString, WriteLn; FROM Strings IMPORT Assign, Length;   CONST MaxSize = 128; Steps = 14;   VAR buf1, buf2: ARRAY [0..MaxSize-1] OF CHAR; step: CARDINAL;   PROCEDURE LookSay(in: ARRAY OF CHAR; VAR out: ARRAY OF CHAR); VAR count, inIdx, outIdx: CARDINAL; ...
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#UNIX_Shell
UNIX Shell
Z=1 while (( Z<=10 )); do echo -e "$Z\c" if (( Z % 5 != 0 )); then echo -e ", \c" else echo -e "" fi (( Z++ )) done
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#zkl
zkl
fcn luhnTest(n){ 0 == (n.split().reverse().reduce(fcn(s,n,clk){ s + if(clk.next()) n else 2*n%10 + n/5 },0,Walker.cycle(1,0)) %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. ...
#MOO
MOO
for i in [1..5] s = ""; for j in [1..i] s += "*"; endfor player:tell(s); endfor
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
Task Demonstrate a   for-loop   where the step-value is greater than one. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For with a specified step   Loops/Foreach   Loops/Increment loop index within loop b...
#Vim_Script
Vim Script
for i in range(2, 10, 2) echo i endfor
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...
#PureBasic
PureBasic
Structure decDigitFmt ;decimal digit format Array Digit.b(0) ;contains each digit of number, right-most digit is index 0 digitCount.i ;zero based sign.i ; {x < 0} = -1, {x = 0} = 0, {x > 0} = 1 EndStructure   Global zero_decDigitFmt.decDigitFmt ;represents zero in the decimal digit format   ;converts string repr...
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#TI-89_BASIC
TI-89 BASIC
str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF."
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#TOML
TOML
str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF."
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT,{} s1=* DATA "string" s2=* DATA + "double" quotes s3=* DATA + 'single' quotes s4=* DATA + "double" + 'single' quotes show=JOIN(s1," ",s2,s3,s4) show=JOIN(show) PRINT show  
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Smalltalk
Smalltalk
2r1011010111 + 5r100 + 8r1327 + 10r727 + 16r2d7 / 4
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Standard_ML
Standard ML
- 727 = 0x2d7; val it = true : bool - 727 = Word.toInt 0w727; val it = true : bool - 0w727 = 0wx2d7; val it = true : bool - ~727; (* negative number; * ~ is the unary negation operator for all numbers, including reals and ints; * worth mentioning because it's unusual *) val it = ~727 : int
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 |...
#Nemerle
Nemerle
using System; using System.Console;   module Logical { WriteLogical(a : bool, b : bool) : void { WriteLine("{0} and {1} is {2}", a, b, a && b); WriteLine("{0} or {1} is {2}", a, b, a || b); WriteLine("not {0} is {1}", a, !a); }   Main() : void {WriteLogical(true, false)} }
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 |...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols binary   runSample(arg) return   -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method logicalOperation(xL = boolean, xR = boolean) public static say showBool(xL) 'AND' showBool(xR) '=' showBool(xL & xR) -- AND sa...
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: ...
#LFE
LFE
  (lists:zipwith3 (lambda (i j k) (io:format "~s~s~p~n" `(,i ,j ,k))) '(a b c) '(A B C) '(1 2 3))  
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...
#Pike
Pike
int main(){ while(1){ int a = random(20); write(a + "\n"); if(a == 10){ break; } int b = random(20); write(b + "\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...
#PL.2FI
PL/I
  do forever; k = trunc(random()*20); put (k); if k = 10 then leave; k = trunc(random()*20); put skip list (k); end;  
http://rosettacode.org/wiki/Longest_common_subsequence
Longest common subsequence
Introduction Define a subsequence to be any output string obtained by deleting zero or more symbols from an input string. The Longest Common Subsequence (LCS) is a subsequence of maximum length common to two or more strings. Let A ≡ A[0]… A[m - 1] and B ≡ B[0]… B[n - 1], m < n be strings drawn from an alphabet Σ of ...
#Slate
Slate
s1@(Sequence traits) longestCommonSubsequenceWith: s2@(Sequence traits) [ s1 isEmpty \/ s2 isEmpty ifTrue: [^ {}]. s1 last = s2 last ifTrue: [(s1 allButLast longestCommonSubsequenceWith: s2 allButLast) copyWith: s1 last] ifFalse: [| x y | x: (s1 longestCommonSubsequenceWith: s2 allButLast). ...
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...
#NewLisp
NewLisp
  ;;; Compute the following number in the sequence (define (next-number s) (let (n 0 c (first s) res "") (dostring (x s) (if (= (char x) c) ; the iteration variable is the ASCII code (++ n) (begin (setq res (string res n c)) (setq n 1 c (char x))))) (setq res (string res n c)) res)) ; ;;; Pr...
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#UnixPipes
UnixPipes
yes \ | cat -n | head -n 10 | xargs -n 5 echo | tr ' ' ,
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#Ursa
Ursa
decl int i for (set i 1) (< i 11) (inc i) if (= (mod i 5) 0) out i endl console continue end if out i ", " console end for