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/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...
#Emacs_Lisp
Emacs Lisp
123 ;; decimal all Emacs #b101 ;; binary Emacs 21 up, XEmacs 21 #o77 ;; octal Emacs 21 up, XEmacs 21 #xFF ;; hex Emacs 21 up, XEmacs 21 #3r210 ;; any radix 2-36 Emacs 21 up (but not XEmacs 21.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...
#Erlang
Erlang
  > 2#101. 5 > 101. 101 > 16#F. 15 > 36#3z. 143  
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 |...
#ColdFusion
ColdFusion
<cffunction name = "logic" hint = "Performs basic logical operations"> <cfargument name = "a" required = "yes" type = "boolean" /> <cfargument name = "a" required = "yes" type = "boolean" /> <cfoutput> 'A' AND 'B' is #a AND b#< br /> 'A' OR 'B' is #a OR b#< br /> NOT 'A' is #!a# </cfoutput> </...
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 |...
#Common_Lisp
Common Lisp
(defun logic (a b) (print "a and b is") (write (and a b)) (print "a or b is" ) (write (or a b)) (print "not a is" ) (write (not a)))
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#Perl
Perl
# Standard notations: .5; 0.5; 1.23345e10; 1.23445e-10; # The numbers can be grouped: 100_000_000; # equals to 100000000  
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#Phix
Phix
?1e+12 -- (same as 1e12) ?1e-12 ?5 -- (same as 5.0) --?1. -- (illegal, use 1 or 1.0) ?.1 -- (same as 0.1) ?1/3 -- 0.333333 printf(1,"%g %G\n",1e-30)
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#PHP
PHP
.12 0.1234 1.2e3 7E-10  
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#Scheme
Scheme
(define (dec31wd year) (remainder (apply + (map (lambda (d) (quotient year d)) '(1 4 -100 400))) 7))   (define (long? year) (or (= 4 (dec31wd year)) (= 3 (dec31wd (- year 1)))))   (display "Long years between 1800 and 2100:") (newline) (display (filter long? (iota 300 1800)))
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#Sidef
Sidef
func is_long_year(year) { Date.parse("#{year}-12-28", "%Y-%m-%d").week == 53 }   say ( "Long years in the 20th century:\n", (1900..^2000).grep(is_long_year)) say ("\nLong years in the 21st century:\n", (2000..^2100).grep(is_long_year)) say ("\nLong years in the 22nd century:\n", (2100..^2200).grep(is_long_year))
http://rosettacode.org/wiki/Long_primes
Long primes
A   long prime   (as defined here)   is a prime number whose reciprocal   (in decimal)   has a   period length   of one less than the prime number. Long primes   are also known as:   base ten cyclic numbers   full reptend primes   golden primes   long period primes   maximal period primes   proper primes A...
#Python
Python
def sieve(limit): primes = [] c = [False] * (limit + 1) # composite = true # no need to process even numbers p = 3 while True: p2 = p * p if p2 > limit: break for i in range(p2, limit, 2 * p): c[i] = True while True: p += 2 if not c[p]: break  ...
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: ...
#DWScript
DWScript
const a1 = ['a', 'b', 'c']; const a2 = ['A', 'B', 'C']; const a3 = [1, 2, 3];   var i : Integer; for i := 0 to 2 do PrintLn(Format('%s%s%d', [a1[i], a2[i], a3[i]]));
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...
#Forth
Forth
include random.fs   : main begin 20 random dup . 10 <> while 20 random . repeat ;   \ use LEAVE to break out of a counted loop : main 100 0 do i random dup . 10 = if leave then i random . loop ;
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...
#Fortran
Fortran
program Example implicit none   real :: r integer :: a, b   do call random_number(r) a = int(r * 20) write(*,*) a if (a == 10) exit call random_number(r) b = int(r * 20) write(*,*) b end do   end program Example
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 ...
#J
J
lcs=: dyad define |.x{~ 0{"1 cullOne^:_ (\: +/"1)(\:{."1) 4$.$. x =/ y )   cullOne=: ({~[: <@<@< [: (i. 0:)1,[: *./[: |: 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...
#Draco
Draco
\util.g   proc nonrec look_and_say(*char inp, outp) void: char cur; byte count; channel output text outch; open(outch, outp); while cur := inp*; cur ~= '\e' do count := 1; while inp := inp + 1; inp* = cur do count := count + 1 od...
http://rosettacode.org/wiki/Longest_increasing_subsequence
Longest increasing subsequence
Calculate and show here a longest increasing subsequence of the list: { 3 , 2 , 6 , 4 , 5 , 1 } {\displaystyle \{3,2,6,4,5,1\}} And of the list: { 0 , 8 , 4 , 12 , 2 , 10 , 6 , 14 , 1 , 9 , 5 , 13 , 3 , 11 , 7 , 15 } {\displaystyle \{0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15\}} Note that a list may have m...
#Python
Python
def longest_increasing_subsequence(X): """Returns the Longest Increasing Subsequence in the Given List/Array""" N = len(X) P = [0] * N M = [0] * (N+1) L = 0 for i in range(N): lo = 1 hi = L while lo <= hi: mid = (lo+hi)//2 if (X[M[mid]] < X[i]): ...
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...
#Julia
Julia
  for i in 1:10 print(i) if i%5 == 0 println() continue end print(", ") 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...
#Kotlin
Kotlin
// version 1.1.2   fun main(args: Array<String>) { for(i in 1 .. 10) { if (i % 5 == 0) { println(i) continue } print("$i, ") } }
http://rosettacode.org/wiki/Longest_common_substring
Longest common substring
Task Write a function that returns the longest common substring of two strings. Use it within a program that demonstrates sample output from the function, which will consist of the longest common substring between "thisisatest" and "testing123testing". Note that substrings are consecutive characters within a string....
#REXX
REXX
/*REXX program determines the LCSUBSTR (Longest Common Substring) via a function. */ parse arg a b . /*obtain optional arguments from the CL*/ if a=='' then a= "thisisatest" /*Not specified? Then use the default.*/ if b=='' then b= "testing123testing" ...
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...
#R
R
  is.luhn <- function(cc){ numbers <- as.numeric(rev(unlist(strsplit(cc,"")))) (sum(numbers[seq(1,length(numbers),by=2)]) + sum({numbers[seq(2,length(numbers),by=2)]*2 ->.; .%%10 +.%/%10})) %% 10 == 0 }   sapply(c("49927398716","49927398717","1234567812345678","1234567812345670"),is.luhn)    
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite loop. 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 l...
#TorqueScript
TorqueScript
While(1) echo("SPAM");
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite loop. 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 l...
#Transact-SQL
Transact-SQL
WHILE 1=1 BEGIN PRINT "SPAM" END
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite loop. 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 l...
#Trith
Trith
["SPAM" print] loop
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#Scala
Scala
var i = 1024 while (i > 0) { println(i) i /= 2 }
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#Scheme
Scheme
(do ((n 1024 (quotient n 2))) ((<= n 0)) (display n) (newline))
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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 body...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT LOOP n=10,0,-1 PRINT n ENDLOOP  
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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 body...
#UNIX_Shell
UNIX Shell
i=10 while test $i -ge 0; do echo $i i=`expr $i - 1` done   # or   jot - 10 0 -1   # or   seq 10 -1 0
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#PicoLisp
PicoLisp
(let Val 0 (loop (println (inc 'Val)) (T (=0 (% Val 6))) ) )
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#Pike
Pike
int main(){ int value = 0; do { value++; write(value + "\n"); } while (value % 6); }
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. ...
#HicEst
HicEst
DO i = 1, 5 DO j = 1, i WRITE(APPend) "*" ENDDO WRITE() ' ' ENDDO
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...
#Oberon-2
Oberon-2
  MODULE LoopForStep; IMPORT Out; VAR i: INTEGER;   BEGIN FOR i := 0 TO 10 BY 3 DO Out.LongInt(i,0);Out.Ln END; FOR i := 10 TO 0 BY -3 DO Out.LongInt(i,0);Out.Ln END END LoopForStep.  
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...
#D
D
void main() { import std.stdio, std.bigint;   writeln(2.BigInt ^^ 64 * 2.BigInt ^^ 64); }
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...
#Forth
Forth
char c emit s" string" type
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...
#Fortran
Fortran
DIMENSION ATWT(12) PRINT 1 1 FORMAT (12HElement Name,F9.4) DO 10 I = 1,12 READ 1,ATWT(I) 10 PRINT 1,ATWT(I) END
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...
#ERRE
ERRE
  PRINT(17) PRINT(&21) PRINT($11) PRINT(%1001)  
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...
#Euphoria
Euphoria
  printf(1,"Decimal:\t%d, %d, %d, %d\n",{-10,10,16,64}) printf(1,"Hex:\t%x, %x, %x, %x\n",{-10,10,16,64}) printf(1,"Octal:\t%o, %o, %o, %o\n",{-10,10,16,64}) printf(1,"Exponential:\t%e, %e, %e, %e\n",{-10,10,16,64.12}) printf(1,"Floating Point\t%3.3f, %3.3f, %+3.3f\n",{-10,10.2,16.25,64.12625}) printf(1,"Floating Point...
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 |...
#D
D
import std.stdio;   void logic(T, U)(T lhs, U rhs) { writefln("'%s' is of type '%s', '%s' is of type '%s';", lhs, typeid(typeof(lhs)), rhs,typeid(typeof(rhs))); writefln("\t'%s' AND '%s' is %s, ", lhs, rhs, lhs && rhs); writefln("\t'%s' OR '%s' is %s, ", lhs, rhs, lhs || rhs); writefln("\t...
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#Picat
Picat
2.0  % normal float. Must have a decimal after the decimal point -2.1 2.01E3  % exponent can be E of e 2.01e3 2.01E-3 2.01e-3 1_000_123.123_456  % underscores can be used for clarity
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#PicoLisp
PicoLisp
  1.2345e-4 decimal floating-point 7e5 decimal floating-point 1.234_567_89e0 decimal floating-point. 1.0s0 decimal floating-point (single precision) 1.0d0 decimal floating-point (double precision) 1.34q0 decimal floating-point (quadruple/extended precision)   111.0101e7b bin...
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#PL.2FI
PL/I
  1.2345e-4 decimal floating-point 7e5 decimal floating-point 1.234_567_89e0 decimal floating-point. 1.0s0 decimal floating-point (single precision) 1.0d0 decimal floating-point (double precision) 1.34q0 decimal floating-point (quadruple/extended precision)   111.0101e7b bin...
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#Snobol
Snobol
DEFINE('DEC31WD(Year)')  :(END_DEC31WD) DEC31WD DEC31WD = REMDR(Year + (Year / 4) - (Year / 100) + (Year / 400), 7) :(RETURN) END_DEC31WD   DEFINE('ISOLONG(Year)')  :(END_ISOLONG) ISOLONG EQ(DEC31WD(Year), 4)  :S(RETURN) EQ(DEC31WD(Year - 1), ...
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#Swift
Swift
func isLongYear(_ year: Int) -> Bool { let year1 = year - 1 let p = (year + (year / 4) - (year / 100) + (year / 400)) % 7 let p1 = (year1 + (year1 / 4) - (year1 / 100) + (year1 / 400)) % 7   return p == 4 || p1 == 3 }   for range in [1900...1999, 2000...2099, 2100...2199] { print("\(range): \(range.filter(isL...
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#Tcl
Tcl
  ## Reference: https://en.wikipedia.org/wiki/ISO_week_date#Weeks_per_year   proc p {year} { return [expr {($year + ($year/4) - ($year/100) + ($year/400)) % 7}] }   proc is_long_year {year} { return [expr {[p $year] == 4 || [p [expr {$year - 1}]] == 3}] }   proc print_long_years {from to} { for {set year $f...
http://rosettacode.org/wiki/Long_primes
Long primes
A   long prime   (as defined here)   is a prime number whose reciprocal   (in decimal)   has a   period length   of one less than the prime number. Long primes   are also known as:   base ten cyclic numbers   full reptend primes   golden primes   long period primes   maximal period primes   proper primes A...
#Quackery
Quackery
[ over size 0 swap 2swap bsearchwith < drop ] is search ( [ --> n )   [ 1 over 1 - times [ 10 * over mod ] tuck 0 temp put [ 10 * over mod 1 temp tally rot 2dup != while unrot again ] 2drop drop temp take ] is period ( n --> n )   [ dup ...
http://rosettacode.org/wiki/Long_primes
Long primes
A   long prime   (as defined here)   is a prime number whose reciprocal   (in decimal)   has a   period length   of one less than the prime number. Long primes   are also known as:   base ten cyclic numbers   full reptend primes   golden primes   long period primes   maximal period primes   proper primes A...
#Racket
Racket
#lang racket (require math/number-theory)   (define (find-period n) (let ((rr (for/fold ((r 1)) ((i (in-range 1 (+ n 2)))) (modulo (* 10 r) n)))) (let period-loop ((r rr) (p 1)) (let ((r′ (modulo (* 10 r) n))) (if (= r′ rr) p (period-loop r′ (add1 p)))))))   (defi...
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: ...
#E
E
def a1 := ["a","b","c"] def a2 := ["A","B","C"] def a3 := ["1","2","3"]   for i => v1 in a1 { println(v1, a2[i], a3[i]) }
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...
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   Dim i As Integer Randomize Do i = Int(Rnd * 20) Print Using "##"; i; Print " "; If i = 10 Then Exit Do i = Int(Rnd * 20) Print Using "##"; i; Print" "; Loop   Print Sleep
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...
#FutureBasic
FutureBasic
include "NSLog.incl"   long num do num = rnd(20) - 1 NSLog(@"%ld",num) until ( num == 10 )   HandleEvents
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 ...
#Java
Java
public static String lcs(String a, String b){ int aLen = a.length(); int bLen = b.length(); if(aLen == 0 || bLen == 0){ return ""; }else if(a.charAt(aLen-1) == b.charAt(bLen-1)){ return lcs(a.substring(0,aLen-1),b.substring(0,bLen-1)) + a.charAt(aLen-1); }else{ St...
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...
#E
E
def lookAndSayNext(number :int) { var seen := null var count := 0 var result := "" def put() { if (seen != null) { result += count.toString(10) + E.toString(seen) } } for ch in number.toString(10) { if (ch != seen) { put() seen := ch count := 0 } count += 1 } ...
http://rosettacode.org/wiki/Longest_increasing_subsequence
Longest increasing subsequence
Calculate and show here a longest increasing subsequence of the list: { 3 , 2 , 6 , 4 , 5 , 1 } {\displaystyle \{3,2,6,4,5,1\}} And of the list: { 0 , 8 , 4 , 12 , 2 , 10 , 6 , 14 , 1 , 9 , 5 , 13 , 3 , 11 , 7 , 15 } {\displaystyle \{0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15\}} Note that a list may have m...
#Racket
Racket
#lang racket/base (require data/gvector)   (define (gvector-last gv) (gvector-ref gv (sub1 (gvector-count gv))))   (define (lis-patience-sort input-list) (let ([piles (gvector)]) (for ([item (in-list input-list)]) (insert-item! piles item)) (reverse (gvector-last piles))))   (define (insert-item! pile...
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...
#Lambdatalk
Lambdatalk
  {def loops_continue {lambda {:i} {if {> :i 10} then (end of loop) else {if {= :i 6} then {br}:i else :i} {if {= :i 10} then . else ,} {loops_continue {+ :i 1}}}}} -> loops_continue   {loops_continue 0} -> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. (end of loop)  
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...
#langur
langur
for .i of 10 { write .i if .i div 5 { writeln(); next } write ", " }
http://rosettacode.org/wiki/Longest_common_substring
Longest common substring
Task Write a function that returns the longest common substring of two strings. Use it within a program that demonstrates sample output from the function, which will consist of the longest common substring between "thisisatest" and "testing123testing". Note that substrings are consecutive characters within a string....
#Ring
Ring
  # Project : Longest Common Substring   str1 = "testing123testing" str2 = "tsitest" see longest(str1, str2)   func longest(str1, str2) subarr = [] for n=1 to len(str1) for m=1 to len(str1) sub = substr(str1, n, m) if substr(str2, sub) > 0 add(subarr, sub) ok next next   tem...
http://rosettacode.org/wiki/Longest_common_substring
Longest common substring
Task Write a function that returns the longest common substring of two strings. Use it within a program that demonstrates sample output from the function, which will consist of the longest common substring between "thisisatest" and "testing123testing". Note that substrings are consecutive characters within a string....
#Ruby
Ruby
def longest_common_substring(a,b) lengths = Array.new(a.length){Array.new(b.length, 0)} greatestLength = 0 output = "" a.each_char.with_index do |x,i| b.each_char.with_index do |y,j| next if x != y lengths[i][j] = (i.zero? || j.zero?) ? 1 : lengths[i-1][j-1] + 1 if lengths[i][j] > greatest...
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...
#Racket
Racket
  #lang racket   (define (luhn-test n) (let loop ([n n] [odd? #t] [s 0]) (if (zero? n) (zero? (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? 1 2) r) 10)]) (loop q (not odd?) (+ s rq rr))))))   (map luhn-test '(49927...
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite loop. 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 l...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT LOOP/999999999 print "spam" ENDLOOP  
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite loop. 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 l...
#UNIX_Shell
UNIX Shell
while :; do echo SPAM; done
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite loop. 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 l...
#UnixPipes
UnixPipes
yes SPAM
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#Scilab
Scilab
i=1024 while i>0 printf("%4d\n",i) i=int(i/2) end
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#Seed7
Seed7
$ include "seed7_05.s7i";   const proc: main is func local var integer: i is 1024; begin while i > 0 do writeln(i); i := i div 2 end while; end func;
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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 body...
#UnixPipes
UnixPipes
yes '' | cat -n | head -n 11 | while read n; do expr $n - 1 done | tail -r
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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 body...
#Ursa
Ursa
decl int i for (set i 10) (> i -1) (dec i) out i endl console end for
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#PL.2FI
PL/I
  dcl value fixed bin (31) init (0); do forever; value = value + 1;   if mod(value, 6) = 0 then leave;   put list (value); end;  
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#Plain_English
Plain English
To run: Start up. Demonstrate do-while. Wait for the escape key. Shut down.   To demonstrate do-while: Bump a counter. Convert the counter to a string. Write the string on the console. If the counter is evenly divisible by 6, exit. Repeat.
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. ...
#HolyC
HolyC
U8 i, j; for (i = 1; i <= 5; i++) { for (j = 1; j <= i; j++) Print("*"); Print("\n"); }
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...
#Objeck
Objeck
  for(i := 0; i < 10; i += 2;) { i->PrintLine(); };  
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...
#Dc
Dc
2 64^ 2 64^ *p
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...
#FreeBASIC
FreeBASIC
  Print "Hello, World." Print Chr(34); "Hello, World." & Chr(34)   Print "Tom said, ""The fox ran away.""" Print "Tom said," + "'The fox ran away.'"  
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...
#friendly_interactive_shell
friendly interactive shell
echo Quotes are optional in most cases. echo echo 'But they are when using either of these characters (or whitespace):' echo '# $ % ^ & * ( ) { } ; \' " \\ < > ?' echo echo Single quotes only interpolate \\ and \' sequences. echo '\In \other \cases, \backslashes \are \preserved \literally.' echo set something variable ...
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...
#F.23
F#
0b101 // = 5 0o12 // = 10 0xF // = 16
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...
#Factor
Factor
10 . ! decimal 0b10 . ! binary -0o10 . ! octal 0x10 . ! hexadecimal
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 |...
#Dc
Dc
[ 1 q ] sT   [ 0=T 0 ] s! [ l! x S@ l! x L@ + l! x ] s& [ l! x S@ l! x L@ * l! x ] s|   [ 48 + P ] s.   [ Sb Sa la l. x [ ] P lb l. x [ ] P la lb l& x l. x [ ] P la Lb l| x l. x [ ] P La l! x l. x A P ] sF   [a b a&b a|b !a] P A P 0 0 lF x 0 1 lF x 1 0 lF x 1 1 lF x
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 |...
#Delphi
Delphi
program LogicalOperations;   {$APPTYPE CONSOLE}   const a = True; b = False; begin Write('a = '); Writeln(a); Write('b = '); Writeln(b); Writeln;   Write('a AND b: '); Writeln(a AND b);   Write('a OR b: '); Writeln(a OR b);   Write('NOT a: '); Writeln(NOT a);   Write('a XOR b: '); Writeln(...
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#PureBasic
PureBasic
-1.0 1.0 1.0E2 1.0E+2 1.0E-2 -1E2
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#Python
Python
FLOAT  : '.' DIGITS (Exponent)? | DIGITS '.' Exponent | DIGITS ('.' (DIGITS (Exponent)?)? | Exponent)  ;   DIGITS : ( '0' .. '9' )+ ;   Exponent  : ('e' | 'E') ( '+' | '-' )? DIGITS  ;
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#Racket
Racket
  #lang racket .2 2. 2.+0i  ; zero imaginary part 2e0 #x10.8 ; hex float #o1e2  ; oct float 2.0f0  ; single float 1.0t0  ; extended 80-bit float (when available on platform)  
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#Terraform
Terraform
module "iso-long-years" { source = "./iso-long-years" start_year = 1995 end_year = 2045 }   output "long-years" { value = module.iso-long-years.long-years }
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#TypeScript
TypeScript
const isLongYear = (year: number): boolean => { const jan1: Date = new Date(year, 0, 1); const dec31: Date = new Date(year, 11, 31); return (4 == jan1.getDay() || 4 == dec31.getDay()) }   for (let y: number = 1995; y <= 2045; y++) { if (isLongYear(y)) { console.log(y) } }
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#UNIX_Shell
UNIX Shell
long_year() { cal 1 $1 | grep -q ' 3 *$' && return 0 cal 12 $1 | grep -q ' 26 *$' }
http://rosettacode.org/wiki/Long_primes
Long primes
A   long prime   (as defined here)   is a prime number whose reciprocal   (in decimal)   has a   period length   of one less than the prime number. Long primes   are also known as:   base ten cyclic numbers   full reptend primes   golden primes   long period primes   maximal period primes   proper primes A...
#Raku
Raku
use Math::Primesieve; my $sieve = Math::Primesieve.new;   sub is-long (Int $p) { my $r = 1; my $rr = $r = (10 * $r) % $p for ^$p; my $period; loop { $r = (10 * $r) % $p; ++$period; last if $period >= $p or $r == $rr; } $period == $p - 1 and $p > 2; }   my @primes = $sieve...
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: ...
#EchoLisp
EchoLisp
  ;; looping over different sequences : infinite stream, string, list and vector ;; loop stops as soon a one sequence ends. ;; the (iota 6) = ( 0 1 2 3 4 5) sequence will stop first.     (for ((i (in-naturals 1000)) (j "ABCDEFGHIJK") (k (iota 6)) (m #(o p q r s t u v w))) (writeln i j k m))   1000 "A" 0 ...
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...
#Gambas
Gambas
Public Sub Form_Open() Dim iRand As Integer   Repeat iRand = Rnd * 20 Print iRand Until iRand = 10   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...
#GAP
GAP
while true do a := Random(0, 19); Print(a); if a = 10 then Print("\n"); break; fi; a := Random(0, 19); Print("\t", a, "\n"); od;   # 11 6 # 5 8 # 1 4 # 5 10 # 1 16 # 10
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 ...
#JavaScript
JavaScript
function lcs(a, b) { var aSub = a.substr(0, a.length - 1); var bSub = b.substr(0, b.length - 1);   if (a.length === 0 || b.length === 0) { return ''; } else if (a.charAt(a.length - 1) === b.charAt(b.length - 1)) { return lcs(aSub, bSub) + a.charAt(a.length - 1); } else { var x = lcs(a, bSub); ...
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...
#EchoLisp
EchoLisp
  (lib 'math) ;; for (number->list) = explode function (lib 'list) ;; (group)   (define (next L) (for/fold (acc null) ((g (group L))) (append acc (list (length g) (first g)))))     (define (task n starter) (for/fold (L (number->list starter)) ((i n)) (writeln (list->string L)) (next L)))    
http://rosettacode.org/wiki/Longest_increasing_subsequence
Longest increasing subsequence
Calculate and show here a longest increasing subsequence of the list: { 3 , 2 , 6 , 4 , 5 , 1 } {\displaystyle \{3,2,6,4,5,1\}} And of the list: { 0 , 8 , 4 , 12 , 2 , 10 , 6 , 14 , 1 , 9 , 5 , 13 , 3 , 11 , 7 , 15 } {\displaystyle \{0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15\}} Note that a list may have m...
#Raku
Raku
sub lis(@d) { my @l = [].item xx @d; @l[0].push: @d[0]; for 1 ..^ @d -> $i { for ^$i -> $j { if @d[$j] < @d[$i] && @l[$i] < @l[$j] + 1 { @l[$i] = [ @l[$j][] ] } } @l[$i].push: @d[$i]; } return max :by(*.elems), @l; }   say lis([3,2,6,4,...
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...
#Lasso
Lasso
loop(10) => {^ loop_count loop_count % 5 ? ', ' | '\r' loop_count < 100 ? loop_continue 'Hello, World!' // never gets executed ^}
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...
#Lingo
Lingo
str = "" repeat with i = 1 to 10 put i after str if i mod 5 = 0 then put RETURN after str next repeat end if put ", " after str end repeat put str
http://rosettacode.org/wiki/Longest_common_substring
Longest common substring
Task Write a function that returns the longest common substring of two strings. Use it within a program that demonstrates sample output from the function, which will consist of the longest common substring between "thisisatest" and "testing123testing". Note that substrings are consecutive characters within a string....
#Rust
Rust
fn longest_common_substring(s1: &str, s2: &str) -> String { let s1_chars: Vec<char> = s1.chars().collect(); let s2_chars: Vec<char> = s2.chars().collect(); let mut lcs = "".to_string();   for i in 0..s1_chars.len() { for j in 0..s2_chars.len() { if s1_chars[i] == s2_chars[j] { ...
http://rosettacode.org/wiki/Longest_common_substring
Longest common substring
Task Write a function that returns the longest common substring of two strings. Use it within a program that demonstrates sample output from the function, which will consist of the longest common substring between "thisisatest" and "testing123testing". Note that substrings are consecutive characters within a string....
#Scala
Scala
def longestCommonSubstringsOptimizedPureFP(left: String, right: String): Option[Set[String]] = if (left.nonEmpty && right.nonEmpty) { val (shorter, longer) = if (left.length < right.length) (left, right) else (right, left)   @scala.annotation.tailrec def recursive( indexLonger: Int = 0, ...
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...
#Raku
Raku
sub luhn-test ($number --> Bool) { my @digits = $number.comb.reverse; my $sum = @digits[0,2...*].sum + @digits[1,3...*].map({ |($_ * 2).comb }).sum; return $sum %% 10; }   # And we can test it like this:   use Test;   my @cc-numbers = '49927398716' => True, '49927398717' => F...
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite loop. 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 l...
#Unlambda
Unlambda
``ci``s``s`kr``s``s``s``s`k.S`k.P`k.A`k.Mii
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite loop. 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 l...
#Ursa
Ursa
while true out "SPAM" endl console end while
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite loop. 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 l...
#V
V
true [ 'SPAM' puts ] while
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#SenseTalk
SenseTalk
put 1024 into x log x Repeat until x = 1 divide x by 2 log x End repeat
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#SETL
SETL
n := 1024; while n > 0 loop print( n ); n := n div 2; end loop;
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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 body...
#V
V
10 [0 >] [dup puts pred] while
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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 body...
#Vala
Vala
for (int i = 10; i >= 0; --i) stdout.printf("%d\n", i);
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#Pop11
Pop11
lvars val = 0; while true do val + 1 -> val; printf(val, '%p\n'); quitif(val rem 6 = 0); endwhile;