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/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#Common_Lisp
Common Lisp
(if (= val 42) "That is the answer to life, the universe and everything" "Try again") ; the else clause here is optional
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Phix
Phix
with javascript_semantics function allsame(sequence s) for i=2 to length(s) do if s[i]!=s[1] then return false end if end for return true end function function strict_order(sequence s) for i=2 to length(s) do if s[i]<=s[i-1] then return false end if end for return true end func...
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#Gambas
Gambas
Public Sub Main() Dim sInput As String[] = ["", "ABC", "ABC DEF", "ABC DEF G H"] Dim sTemp As String   For Each sTemp In sInput Print sTemp & " = "; sTemp = Replace(sTemp, " ", ",") If RInStr(sTemp, ",") > 0 Then sTemp = Mid(sTemp, 1, RInStr(sTemp, ",") - 1) & " and " & Mid(sTemp, RInStr(sTemp, ",") + 1) E...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#Mercury
Mercury
:- module comb. :- interface. :- import_module list, int, bag.   :- pred choose(list(T)::in, int::in, bag(T)::out) is nondet. :- pred choose_all(list(T)::in, int::in, list(list(T))::out) is det. :- pred count_choices(list(T)::in, int::in, int::out) is det.   :- implementation. :- import_module solutions.   choose(L, N,...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#Nim
Nim
import sugar, sequtils   proc combsReps[T](lst: seq[T], k: int): seq[seq[T]] = if k == 0: @[newSeq[T]()] elif lst.len == 0: @[] else: lst.combsReps(k - 1).map((x: seq[T]) => lst[0] & x) & lst[1 .. ^1].combsReps(k)   echo(@["iced", "jam", "plain"].combsReps(2)) echo toSeq(1..10).combsReps(3).len
http://rosettacode.org/wiki/Combinations_and_permutations
Combinations and permutations
This page uses content from Wikipedia. The original article was at Combination. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) This page uses content from Wikipedia. The original article was at P...
#Stata
Stata
real scalar comb1(n, k) { return(exp(lnfactorial(n)-lnfactorial(k)-lnfactorial(n-k))) }   real scalar perm(n, k) { return(exp(lnfactorial(n)-lnfactorial(n-k))) }
http://rosettacode.org/wiki/Combinations_and_permutations
Combinations and permutations
This page uses content from Wikipedia. The original article was at Combination. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) This page uses content from Wikipedia. The original article was at P...
#Swift
Swift
import BigInt   func permutations(n: Int, k: Int) -> BigInt { let l = n - k + 1   guard l <= n else { return 1 }   return (l...n).reduce(BigInt(1), { $0 * BigInt($1) }) }   func combinations(n: Int, k: Int) -> BigInt { let fact = {() -> BigInt in guard k > 1 else { return 1 }   return (2...
http://rosettacode.org/wiki/Compiler/lexical_analyzer
Compiler/lexical analyzer
Definition from Wikipedia: Lexical analysis is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of tokens (strings with an identified "meaning"). A program that performs lexical analysis may be called a lexer, tokenizer, or scanner (though "scanner" is als...
#Nim
Nim
  import re, strformat, strutils   type TokenKind = enum tkUnknown = "UNKNOWN_TOKEN", tkMul = "Op_multiply", tkDiv = "Op_divide", tkMod = "Op_mod", tkAdd = "Op_add", tkSub = "Op_subtract", tkNeg = "Op_negate", tkLt = "Op_less", tkLte = "Op_lessequal", tkGt = "Op_greater", t...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#jq
jq
$ARGS.positional contains an array of the positional arguments as JSON strings
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Jsish
Jsish
#!/usr/local/bin/jsish puts(Info.argv0()); puts(console.args);
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Julia
Julia
using Printf   prog = Base.basename(Base.source_path())   println(prog, "'s command-line arguments are:") for s in ARGS println(" ", s) end  
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#Deluge
Deluge
// single line comment
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#Dragon
Dragon
// This is a comment
http://rosettacode.org/wiki/Conway%27s_Game_of_Life
Conway's Game of Life
The Game of Life is a   cellular automaton   devised by the British mathematician   John Horton Conway   in 1970.   It is the best-known example of a cellular automaton. Conway's game of life is described   here: A cell   C   is represented by a   1   when alive,   or   0   when dead,   in an   m-by-m   (or m×m)   sq...
#INTERCAL
INTERCAL
pad=: 0,0,~0,.0,.~] life=: (3 3 (+/ e. 3+0,4&{)@,;._3 ])@pad NB. the above could also be a one-line solution: life=: (3 3 (+/ e. 3+0,4&{)@,;._3 ])@(0,0,~0,.0,.~])  
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#Computer.2Fzero_Assembly
Computer/zero Assembly
if (condition) { // Some Task }   if (condition) { // Some Task } else if (condition2) { // Some Task } else { // Some Task }
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Phixmonti
Phixmonti
include ..\Utilitys.pmt   ( "alpha" "beta" "gamma" "delta" "epsilon" "zeta" "eta" "theta" "iota" "kappa" "lambda" "mu" )   dup dup sort == /# put 0 (false) in the pile, indicating that they are not in ascending order #/   drop /# discard the result #/   dup len swap 1 get rot repeat == /# put 0 (false) in the pil...
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Picat
Picat
main => Lists = [["AA","BB","CC"], ["AA","AA","AA"], ["AA","CC","BB"], ["AA","ACB","BB","CC"], ["single_element"], []], foreach(L in Lists) Same = all_same(L).cond(true,false), Sorted = sorted(L).cond(true,false), printf("%-18w all_same:%-5w sor...
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#Go
Go
package main   import ( "fmt" "strings" )   func q(s []string) string { switch len(s) { case 0: return "{}" case 1: return "{" + s[0] + "}" case 2: return "{" + s[0] + " and " + s[1] + "}" default: return "{" + strings.Join(s[:len(s)-1], ", ") + ...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#OCaml
OCaml
let rec combs_with_rep k xxs = match k, xxs with | 0, _ -> [[]] | _, [] -> [] | k, x::xs -> List.map (fun ys -> x::ys) (combs_with_rep (k-1) xxs) @ combs_with_rep k xs
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#PARI.2FGP
PARI/GP
ways(k,v,s=[])={ if(k==0,return([])); if(k==1,return(vector(#v,i,concat(s,[v[i]])))); if(#v==1,return(ways(k-1,v,concat(s,v)))); my(u=vecextract(v,2^#v-2)); concat(ways(k-1,v,concat(s,[v[1]])),ways(k,u,s)) }; xc(k,v)=binomial(#v+k-1,k); ways(2, ["iced","jam","plain"])
http://rosettacode.org/wiki/Combinations_and_permutations
Combinations and permutations
This page uses content from Wikipedia. The original article was at Combination. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) This page uses content from Wikipedia. The original article was at P...
#Tcl
Tcl
# Exact integer versions proc tcl::mathfunc::P {n k} { set t 1 for {set i $n} {$i > $n-$k} {incr i -1} { set t [expr {$t * $i}] } return $t } proc tcl::mathfunc::C {n k} { set t [P $n $k] for {set i $k} {$i > 1} {incr i -1} { set t [expr {$t / $i}] } return $t }   # Floating point vers...
http://rosettacode.org/wiki/Compiler/lexical_analyzer
Compiler/lexical analyzer
Definition from Wikipedia: Lexical analysis is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of tokens (strings with an identified "meaning"). A program that performs lexical analysis may be called a lexer, tokenizer, or scanner (though "scanner" is als...
#ObjectIcon
ObjectIcon
# -*- ObjectIcon -*- # # The Rosetta Code lexical analyzer in Object Icon. Based upon the ATS # implementation. # # Usage: lex [INPUTFILE [OUTPUTFILE]] # If INPUTFILE or OUTPUTFILE is "-" or missing, then standard input # or standard output is used, respectively. *) #   import io   $define EOF -1   $define TOKEN_EL...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Klong
Klong
  .p'.a  
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Kotlin
Kotlin
fun main(args: Array<String>) { println("There are " + args.size + " arguments given.") args.forEachIndexed { i, a -> println("The argument #${i+1} is $a and is at index $i") } }
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Lasso
Lasso
#!/usr/bin/lasso9   iterate($argv) => { stdoutnl("Argument " + loop_count + ": " + loop_value) }
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#DWScript
DWScript
(* This is a comment. It may extend across multiple lines. *)   { Alternatively curly braces can be used. }   /* C-style multi-line comments are supported */   // and single-line C++ style comments too
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#Dyalect
Dyalect
/* This is a multi-line comment */   //This is a single-line comment
http://rosettacode.org/wiki/Conway%27s_Game_of_Life
Conway's Game of Life
The Game of Life is a   cellular automaton   devised by the British mathematician   John Horton Conway   in 1970.   It is the best-known example of a cellular automaton. Conway's game of life is described   here: A cell   C   is represented by a   1   when alive,   or   0   when dead,   in an   m-by-m   (or m×m)   sq...
#J
J
pad=: 0,0,~0,.0,.~] life=: (3 3 (+/ e. 3+0,4&{)@,;._3 ])@pad NB. the above could also be a one-line solution: life=: (3 3 (+/ e. 3+0,4&{)@,;._3 ])@(0,0,~0,.0,.~])  
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#Crack
Crack
if (condition) { // Some Task }   if (condition) { // Some Task } else if (condition2) { // Some Task } else { // Some Task }
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#PicoLisp
PicoLisp
(= "AA" "AA" "AA") -> T (= "AA" "AA" "Aa") -> NIL (< "AA" "AA") -> NIL (< "AA" "Aa") -> T (< "1" "A" "B" "Z" "c" ) -> T (> "A" "B" "Z" "C") -> NIL
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#PL.2FI
PL/I
*process source xref attributes or(!); /*-------------------------------------------------------------------- * 01.07.2014 Walter Pachl *-------------------------------------------------------------------*/ clist: Proc Options(main); Dcl (hbound) Builtin; Dcl sysprint Print; Dcl abc(3) Char(2) Init('AA','BB','CC...
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#Groovy
Groovy
def commaQuibbling = { it.size() < 2 ? "{${it.join(', ')}}" : "{${it[0..-2].join(', ')} and ${it[-1]}}" }
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#Haskell
Haskell
quibble ws = "{" ++ quibbles ws ++ "}" where quibbles [] = "" quibbles [a] = a quibbles [a,b] = a ++ " and " ++ b quibbles (a:bs) = a ++ ", " ++ quibbles bs   main = mapM_ (putStrLn . quibble) $ [[], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H"]] ++ (map words ["One two three four", "...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#Pascal
Pascal
program CombWithRep; //combinations with repetitions //Limit = count of elements //Maxval = value of top , lowest is always 0 //so 0..Maxvalue => maxValue+1 elements {$IFDEF FPC} // {$R+,O+} {$MODE DELPHI}{$OPTIMIZATION ON,ALL}{$COPERATORS ON} {$ELSE}{$APPTYPE CONSOLE}{$ENDIF} uses SysUtils;//GetTickCount64   var ...
http://rosettacode.org/wiki/Combinations_and_permutations
Combinations and permutations
This page uses content from Wikipedia. The original article was at Combination. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) This page uses content from Wikipedia. The original article was at P...
#VBScript
VBScript
' Combinations and permutations - vbs - 10/04/2017 dim i,j Wscript.StdOut.WriteLine "-- Long Integer - Permutations - from 1 to 12" for i=1 to 12 for j=1 to i Wscript.StdOut.Write "P(" & i & "," & j & ")=" & perm(i,j) & " " next 'j Wscript.StdOut.WriteLine "" next 'i Wscript.StdOut.WriteLine "-- Float integer -...
http://rosettacode.org/wiki/Combinations_and_permutations
Combinations and permutations
This page uses content from Wikipedia. The original article was at Combination. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) This page uses content from Wikipedia. The original article was at P...
#Visual_Basic_.NET
Visual Basic .NET
' Combinations and permutations - 10/04/2017 Imports System.Numerics 'BigInteger Module CombPermRc   Sub Main() Dim i, j As Long For i = 1 To 12 For j = 1 To i Console.Write("P(" & i & "," & j & ")=" & PermBig(i, j).ToString & " ") Next j Console...
http://rosettacode.org/wiki/Compiler/lexical_analyzer
Compiler/lexical analyzer
Definition from Wikipedia: Lexical analysis is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of tokens (strings with an identified "meaning"). A program that performs lexical analysis may be called a lexer, tokenizer, or scanner (though "scanner" is als...
#OCaml
OCaml
(*------------------------------------------------------------------*) (* The Rosetta Code lexical analyzer, in OCaml. Based on the ATS. *)   (* When you compare this code to the ATS code, please keep in mind that, although ATS has an ML-like syntax:   * The type system is not the same at all.   * Most ATS...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#LFE
LFE
  $ ./bin/lfe -pa ebin/ -c "alpha beta" -h "gamma"  
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Liberty_BASIC
Liberty BASIC
print CommandLine$
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Lingo
Lingo
put the commandline -- "-c alpha beta -h gamma"
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#Dylan
Dylan
// This is a comment   /* This is a comment that spans multiple lines */
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#D.C3.A9j.C3.A0_Vu
Déjà Vu
#this is a comment !print "this is not a comment, obviously" #this is a comment as well
http://rosettacode.org/wiki/Conway%27s_Game_of_Life
Conway's Game of Life
The Game of Life is a   cellular automaton   devised by the British mathematician   John Horton Conway   in 1970.   It is the best-known example of a cellular automaton. Conway's game of life is described   here: A cell   C   is represented by a   1   when alive,   or   0   when dead,   in an   m-by-m   (or m×m)   sq...
#JAMES_II.2FRule-based_Cellular_Automata
JAMES II/Rule-based Cellular Automata
@caversion 1;   dimensions 2;   //using Moore neighborhood neighborhood moore;   //available states state DEAD, ALIVE;   /* if current state is ALIVE and the neighborhood does not contain 2 or 3 ALIVE states the cell changes to DEAD */ rule{ALIVE}:!ALIVE{2,3}->DEAD;   /* if current state is DEAD and there are...
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#D
D
void main() { enum int i = 5;   // "static if" for various static checks: static if (i == 7) { // ... } else { //... }   // is(T == U) checks if type T is U. static if (is(typeof(i) == int)) { // ... } else { // ... }   // D switch is improved over...
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Plain_English
Plain English
To decide if some string things are lexically equal: If the string things are empty, say yes. Get a string thing from the string things. Put the string thing's string into a canonical string. Loop. If the string thing is nil, say yes. If the string thing's string is not the canonical string, say no. Put the string thin...
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#PowerShell
PowerShell
  function IsAscending ( [string[]]$Array ) { ( 0..( $Array.Count - 2 ) ).Where{ $Array[$_] -le $Array[$_+1] }.Count -eq $Array.Count - 1 } function IsEqual ( [string[]]$Array ) { ( 0..( $Array.Count - 2 ) ).Where{ $Array[$_] -eq $Array[$_+1] }.Count -eq $Array.Count - 1 }   IsAscending 'A', 'B', 'B', 'C' IsAscendi...
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#Icon_and_Unicon
Icon and Unicon
procedure main() every write(quibble([] | ["ABC"] | ["ABC","DEF"] | ["ABC","DEF","G","H"])) end   procedure quibble(A) join := s := "" while s := pull(A)||join||s do join := if *join = 0 then " and " else ", " return "{"||s||"}" end
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#J
J
quibLast2=: ' and ' joinstring (2 -@<. #) {. ] withoutLast2=: ([: # _2&}.) {. ] quibble=: '{', '}' ,~ ', ' joinstring withoutLast2 , <@quibLast2
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#Perl
Perl
sub p { $_[0] ? map p($_[0] - 1, [@{$_[1]}, $_[$_]], @_[$_ .. $#_]), 2 .. $#_ : $_[1] } sub f { $_[0] ? $_[0] * f($_[0] - 1) : 1 } sub pn{ f($_[0] + $_[1] - 1) / f($_[0]) / f($_[1] - 1) }   for (p(2, [], qw(iced jam plain))) { print "@$_\n"; }   printf "\nThere are %d ways to pick 7 out of 10\n", pn(7,10);  
http://rosettacode.org/wiki/Combinations_and_permutations
Combinations and permutations
This page uses content from Wikipedia. The original article was at Combination. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) This page uses content from Wikipedia. The original article was at P...
#Wren
Wren
import "/big" for BigInt import "/fmt" for Fmt import "/trait" for Stepped   var perm = Fn.new { |n, k| if (n <= 0 || k < 0) Fiber.abort("Invalid argument(s).") if (k == 0) return BigInt.one return (n-k+1..n).reduce(BigInt.one) { |acc, i| acc * BigInt.new(i) } }   var comb = Fn.new { |n, k| if (n <= 0 |...
http://rosettacode.org/wiki/Compiler/lexical_analyzer
Compiler/lexical analyzer
Definition from Wikipedia: Lexical analysis is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of tokens (strings with an identified "meaning"). A program that performs lexical analysis may be called a lexer, tokenizer, or scanner (though "scanner" is als...
#Ol
Ol
  (import (owl parse))   (define (get-comment) (get-either (let-parses ( (_ (get-imm #\*)) (_ (get-imm #\/))) #true) (let-parses ( (_ get-byte) (_ (get-comment))) #true)))   (define get-whitespace (get-any-of (get-byte-if (lambda ...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Logo
Logo
logo file.logo - arg1 arg2 arg3
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#E
E
# This is a regular comment.   ? "This is an Updoc comment, which > is an executable example or test case.".split(" ") # value: ["This", "is", "an", "Updoc", "comment,", "which # is", "an", "executable", "example", "or", "test", "case."]
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#EasyLang
EasyLang
# This is a comment
http://rosettacode.org/wiki/Conway%27s_Game_of_Life
Conway's Game of Life
The Game of Life is a   cellular automaton   devised by the British mathematician   John Horton Conway   in 1970.   It is the best-known example of a cellular automaton. Conway's game of life is described   here: A cell   C   is represented by a   1   when alive,   or   0   when dead,   in an   m-by-m   (or m×m)   sq...
#Java
Java
public class GameOfLife{ public static void main(String[] args){ String[] dish= { "_#_", "_#_", "_#_",}; int gens= 3; for(int i= 0;i < gens;i++){ System.out.println("Generation " + i + ":"); print(dish); dish= life(dish); } }   public static String[] life(String[] dish){ String[] newGe...
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#Dao
Dao
a = 3 if( a == 1 ){ io.writeln( 'a == 1' ) }else if( a== 3 ){ io.writeln( 'a == 3' ) }else{ io.writeln( 'a is neither 1 nor 3' ) }
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Prolog
Prolog
los(["AA","BB","CC"]). los(["AA","AA","AA"]). los(["AA","CC","BB"]). los(["AA","ACB","BB","CC"]). los(["single_element"]).   lexically_equal(S,S,S). in_order(G,L,G) :- compare(<,L,G).   test_list(List) :- List = [L|T], write('for list '), write(List), nl, (foldl(lexically_equal, T, L, _) -> writel...
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#Java
Java
public class Quibbler {   public static String quibble(String[] words) { String qText = "{"; for(int wIndex = 0; wIndex < words.length; wIndex++) { qText += words[wIndex] + (wIndex == words.length-1 ? "" : wIndex == words.length-2 ? " and " : ", "; } qText += "}"; return qText; }   publ...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#Phix
Phix
with javascript_semantics procedure show_choices(sequence set, integer n, at=1, sequence res={}) if length(res)=n then ?res else for i=at to length(set) do show_choices(set,n,i,append(deep_copy(res),set[i])) end for end if end procedure show_choices({"iced","jam","plain...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#PHP
PHP
<?php function combos($arr, $k) { if ($k == 0) { return array(array()); }   if (count($arr) == 0) { return array(); }   $head = $arr[0];   $combos = array(); $subcombos = combos($arr, $k-1); foreach ($subcombos as $subcombo) { array_unshift($subcombo, $head); $c...
http://rosettacode.org/wiki/Compiler/lexical_analyzer
Compiler/lexical analyzer
Definition from Wikipedia: Lexical analysis is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of tokens (strings with an identified "meaning"). A program that performs lexical analysis may be called a lexer, tokenizer, or scanner (though "scanner" is als...
#Perl
Perl
#!/usr/bin/env perl   use strict; use warnings; no warnings 'once';     #----- Definition of the language to be lexed -----#   my @tokens = ( # Name | Format | Value # # -------------- |----------------------|-------------# ['Op_multiply' , '*' , ...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#LSE64
LSE64
argc , nl # number of arguments (including command itself) 0 # argument dup arg dup 0 = || ,t 1 + repeat drop
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Lua
Lua
print( "Program name:", arg[0] )   print "Arguments:" for i = 1, #arg do print( i," ", arg[i] ) end
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { Document a$ = { Module Global A { Show Read a$="nothing", x=0 Print a$, x A$=Key$ } A: End } Dir temporary$ Save.doc a$, "program.gsb" \\ open if gsb extension is register to m2000.exe Win quote$(di...
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#EchoLisp
EchoLisp
  666 ; this is an end-of-line comment   #| This is a multi-line comment Nesting is not allowed |#   ;; The (info <name> [<string>)] function associates a symbol and a comment ;; These info strings are saved in permanent memory (local storage) ;; Unicode characters may be used, as everywhere in the language   (defin...
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#ECL
ECL
// this is a one-line comment
http://rosettacode.org/wiki/Conway%27s_Game_of_Life
Conway's Game of Life
The Game of Life is a   cellular automaton   devised by the British mathematician   John Horton Conway   in 1970.   It is the best-known example of a cellular automaton. Conway's game of life is described   here: A cell   C   is represented by a   1   when alive,   or   0   when dead,   in an   m-by-m   (or m×m)   sq...
#JavaScript
JavaScript
function GameOfLife () {   this.init = function (turns,width,height) { this.board = new Array(height); for (var x = 0; x < height; x++) { this.board[x] = new Array(width); for (var y = 0; y < width; y++) { this.board[x][y] = Math.round(Math.random()); } } this.turns = turns; }   this.nextGen = f...
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#Delphi
Delphi
if (input.Field == "Hello World") { sVar = "good"; } else if (input.Field == "Bye World") { sVar = "bad"; } else { sVar = "neutral"; }
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#PureBasic
PureBasic
EnableExplicit DataSection Data.s ~"AA\tAA\tAA\nAA\tBB\tCC\nAA\tCC\tBB\nAA\tACB\tBB\tCC\nsingel_element" EndDataSection   Macro PassFail(PF) If PF : PrintN("Pass") : Else : PrintN("Fail") : EndIf EndMacro   Macro ProcRec(Proc) Define tf1$,tf2$ : Static chk.b : chk=#True tf1$=StringField(s$,c,tz$) : tf2$=StringF...
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#JavaScript
JavaScript
function quibble(words) { return "{" + words.slice(0, words.length-1).join(",") + (words.length > 1 ? " and " : "") + (words[words.length-1] || '') + "}"; }   [[], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H"]].forEach( function(s) { console.log(quibble(s)); } );
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#PicoLisp
PicoLisp
(de combrep (N Lst) (cond ((=0 N) '(NIL)) ((not Lst)) (T (conc (mapcar '((X) (cons (car Lst) X)) (combrep (dec N) Lst) ) (combrep N (cdr Lst)) ) ) ) )
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#Prolog
Prolog
  combinations_of_length(_,[]). combinations_of_length([X|T],[X|Combinations]):- combinations_of_length([X|T],Combinations). combinations_of_length([_|T],[X|Combinations]):- combinations_of_length(T,[X|Combinations]).  
http://rosettacode.org/wiki/Compiler/lexical_analyzer
Compiler/lexical analyzer
Definition from Wikipedia: Lexical analysis is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of tokens (strings with an identified "meaning"). A program that performs lexical analysis may be called a lexer, tokenizer, or scanner (though "scanner" is als...
#Phix
Phix
-- -- demo\rosetta\Compiler\core.e -- ============================ -- -- Standard declarations and routines used by lex.exw, parse.exw, cgen.exw, and interp.exw -- (included in distribution as above, which contains some additional sanity checks) -- with javascript_semantics global constant EOF = -1, STDIN = 0, STDOUT...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
#!/usr/local/bin/MathematicaScript -script $CommandLine
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Mercury
Mercury
  :- module cmd_line_args. :- interface.   :- import_module io. :- pred main(io::di, io::uo) is det.   :- implementation. :- import_module int, list, string.   main(!IO) :- io.progname("", ProgName, !IO), io.format("This program is named %s.\n", [s(ProgName)], !IO), io.command_line_arguments(Args, !IO), ...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#min
min
args
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#EDSAC_order_code
EDSAC order code
[This is a comment] [ And so is this ] [But in 1949 they wouldn't have been]
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#EGL
EGL
-- inline comment, continues until new line
http://rosettacode.org/wiki/Conway%27s_Game_of_Life
Conway's Game of Life
The Game of Life is a   cellular automaton   devised by the British mathematician   John Horton Conway   in 1970.   It is the best-known example of a cellular automaton. Conway's game of life is described   here: A cell   C   is represented by a   1   when alive,   or   0   when dead,   in an   m-by-m   (or m×m)   sq...
#jq
jq
# Notes on the implementation:   # 1. For efficiency, the implementation requires that the world # has boundaries, as illustrated in the examples. # 2. For speed, the simulation uses the exploded string. # 3. The ASCII values of the "alive" and "empty" symbols are # hardcoded: "." => 46; " " => 32 # 4. To adjust...
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#Deluge
Deluge
if (input.Field == "Hello World") { sVar = "good"; } else if (input.Field == "Bye World") { sVar = "bad"; } else { sVar = "neutral"; }
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Python
Python
all(a == nexta for a, nexta in zip(strings, strings[1:])) # All equal all(a < nexta for a, nexta in zip(strings, strings[1:])) # Strictly ascending   len(set(strings)) == 1 # Concise all equal sorted(strings, reverse=True) == strings # Concise (but not particularly efficient) ascending  
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Quackery
Quackery
[ [ true swap dup size 1 > while behead swap witheach [ over != if [ dip not conclude ] ] ] drop ] is allthesame ( [ --> b )   [ [ true swap dup size 1 > while behead swap witheach [ tuck $> if [ dip not co...
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#jq
jq
def quibble: if length == 0 then "" elif length == 1 then .[0] else (.[0:length-1] | join(", ")) + " and " + .[length-1] end | "{" + . + "}";
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#Julia
Julia
function quibble(arr::Array) if isempty(arr) rst = "" else rst = "$(arr[end])" end if length(arr) > 1 rst = join(arr[1:end-1], ", ") * " and " * rst end return "{" * rst * "}" end   @show quibble([]) @show quibble(["ABC"]) @show quibble(["ABC", "DEF"]) @show quibble(["ABC", "DEF", "G", "H"])
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#PureBasic
PureBasic
Procedure nextCombination(Array combIndex(1), elementCount) ;combIndex() must be dimensioned to 'k' - 1, elementCount equals 'n' - 1 ;combination produced includes repetition of elements and is represented by the array combIndex() Protected i, indexValue, combSize = ArraySize(combIndex()), curIndex   ;update in...
http://rosettacode.org/wiki/Compiler/lexical_analyzer
Compiler/lexical analyzer
Definition from Wikipedia: Lexical analysis is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of tokens (strings with an identified "meaning"). A program that performs lexical analysis may be called a lexer, tokenizer, or scanner (though "scanner" is als...
#Prolog
Prolog
/* Test harness for the analyzer, not needed if we are actually using the output. */ load_file(File, Input) :- read_file_to_codes(File, Codes, []), maplist(char_code, Chars, Codes), atom_chars(Input,Chars).   test_file(File) :- load_file(File, Input), tester(Input).   tester(S) :- atom_chars(S,Chars), token...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#MMIX
MMIX
argv IS $1 argc IS $0 i IS $2   LOC #100 Main LOC @ SETL i,1 % i = 1 Loop CMP $3,argc,2 % argc < 2 ? BN $3,1F % then jump to end XOR $255,$255,$255 % clear $255 8ADDU $255,i,argv % i*8 + argv LDOU $25...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Modula-2
Modula-2
MODULE try;   FROM Arguments IMPORT GetArgs, ArgTable, GetEnv; FROM InOut IMPORT WriteCard, WriteLn, WriteString;   VAR count, item : SHORTCARD; storage : ArgTable;   BEGIN GetArgs (count, storage); WriteString ('Count ='); WriteCard (count, 4); WriteLn; item := 0; ...
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#Eiffel
Eiffel
-- inline comment, continues until new line
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#Ela
Ela
//single line comment   /*multiple line comment*/
http://rosettacode.org/wiki/Conway%27s_Game_of_Life
Conway's Game of Life
The Game of Life is a   cellular automaton   devised by the British mathematician   John Horton Conway   in 1970.   It is the best-known example of a cellular automaton. Conway's game of life is described   here: A cell   C   is represented by a   1   when alive,   or   0   when dead,   in an   m-by-m   (or m×m)   sq...
#Jsish
Jsish
/* Conway's game of life, in Jsish */ function GameOfLife () { this.title = "Conway's Game of Life"; this.cls = "\u001B[H\u001B[2J";   this.init = function (turns, width, height) { this.board = new Array(height); for (var x = 0; x < height; x++) { this.board[x] = new Array(width)...
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#DM
DM
if (condition) // Do thing, DM uses indentation for control flow.   if (condition) // Do thing   else if (condition) // Do thing   else // Do thing  
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#R
R
  chunks <- function (compare, xs) { starts = which(c(T, !compare(head(xs, -1), xs[-1]), T)) lapply(seq(1,length(starts)-1), function(i) xs[starts[i]:(starts[i+1]-1)] ) }  
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Racket
Racket
#lang racket/base (define ((list-stringX? stringX?) strs) (or (null? strs) (null? (cdr strs)) (apply stringX? strs))) (define list-string=? (list-stringX? string=?)) (define list-string<? (list-stringX? string<?))   (module+ test (require tests/eli-tester) (test (list-string=? '()) => #t (list-string=? '("a...
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#Kotlin
Kotlin
// version 1.0.6   fun commaQuibble(s: String): String { val t = s.trim('[', ']').replace(" ", "").replace("\"", "") val words = t.split(',') val sb = StringBuilder("{") for (i in 0 until words.size) { sb.append(when (i) { 0 -> "" words.lastIndex -> " and...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#Python
Python
>>> from itertools import combinations_with_replacement >>> n, k = 'iced jam plain'.split(), 2 >>> list(combinations_with_replacement(n,k)) [('iced', 'iced'), ('iced', 'jam'), ('iced', 'plain'), ('jam', 'jam'), ('jam', 'plain'), ('plain', 'plain')] >>> # Extra credit >>> len(list(combinations_with_replacement(range(10)...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#Quackery
Quackery
( nextplain generates the next plaindrome in the current base by adding one to a given plaindrome, then replacing each trailing zero with the least significant non-zero digit of the number   See: https://oeis.org/search?q=plaindromes   4 base put -1 10 times [ nextplain ...
http://rosettacode.org/wiki/Compiler/lexical_analyzer
Compiler/lexical analyzer
Definition from Wikipedia: Lexical analysis is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of tokens (strings with an identified "meaning"). A program that performs lexical analysis may be called a lexer, tokenizer, or scanner (though "scanner" is als...
#Python
Python
from __future__ import print_function import sys   # following two must remain in the same order   tk_EOI, tk_Mul, tk_Div, tk_Mod, tk_Add, tk_Sub, tk_Negate, tk_Not, tk_Lss, tk_Leq, tk_Gtr, \ tk_Geq, tk_Eq, tk_Neq, tk_Assign, tk_And, tk_Or, tk_If, tk_Else, tk_While, tk_Print, \ tk_Putc, tk_Lparen, tk_Rparen, tk_L...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Modula-3
Modula-3
MODULE Args EXPORTS Main;   IMPORT IO, Params;   BEGIN IO.Put(Params.Get(0) & "\n"); IF Params.Count > 1 THEN FOR i := 1 TO Params.Count - 1 DO IO.Put(Params.Get(i) & "\n"); END; END; END Args.
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Nanoquery
Nanoquery
// // command-line arguments //   // output all arguments for i in range(0, len(args) - 1) println args[i] end