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/Inheritance/Multiple
Inheritance/Multiple
Multiple inheritance allows to specify that one class is a subclass of several other classes. Some languages allow multiple inheritance for arbitrary classes,   others restrict it to interfaces,   some don't allow it at all. Task Write two classes (or interfaces) Camera and MobilePhone,   then write a class Camer...
#zkl
zkl
class Camera{} class MobilePhone{} class CameraPhone(Camera,MobilePhone){} CameraPhone.linearizeParents
http://rosettacode.org/wiki/Increasing_gaps_between_consecutive_Niven_numbers
Increasing gaps between consecutive Niven numbers
Note:   Niven   numbers are also called   Harshad   numbers.   They are also called    multidigital   numbers. Niven numbers are positive integers which are evenly divisible by the sum of its digits   (expressed in base ten). Evenly divisible   means   divisible with no remainder. Task   find the gap (differen...
#x86-64_Assembly
x86-64 Assembly
bits 64 section .data ;;; Header header: db 'Gap no Gap Niven index Niven number',10 db '------ --- ------------- --------------',10 .len: equ $-header ;;; Placeholder for line output line: db 'XXXXXX' .gapno: db ' XXX' .gap: db ' XXXXXXXXXXXXX' .nivno: db ' XXXXXXXXXXXXXX' .niv: db 10 .len: equ $-line...
http://rosettacode.org/wiki/Integer_overflow
Integer overflow
Some languages support one or more integer types of the underlying processor. This integer types have fixed size;   usually   8-bit,   16-bit,   32-bit,   or   64-bit. The integers supported by such a type can be   signed   or   unsigned. Arithmetic for machine level integers can often be done by single CPU instruct...
#PL.2FM
PL/M
100H: /* SHOW INTEGER OVERFLOW */   /* CP/M SYSTEM CALL */ BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END; /* CONSOLE I/O ROUTINES */ PRCHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END; PRSTRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END; ...
http://rosettacode.org/wiki/Input_loop
Input loop
Input loop is part of Short Circuit's Console Program Basics selection. Task Read from a text stream either word-by-word or line-by-line until the stream runs out of data. The stream will have an unknown amount of data on it.
#Go
Go
package main   import ( "bufio" "io" "log" "os" )   func main() { in := bufio.NewReader(os.Stdin) for { s, err := in.ReadString('\n') if err != nil { // io.EOF is expected, anything else // should be handled/reported if err != io.EOF { log.Fatal(err) } break } // Do something with the l...
http://rosettacode.org/wiki/Input_loop
Input loop
Input loop is part of Short Circuit's Console Program Basics selection. Task Read from a text stream either word-by-word or line-by-line until the stream runs out of data. The stream will have an unknown amount of data on it.
#Groovy
Groovy
def lineMap = [:] System.in.eachLine { line, i -> lineMap[i] = line } lineMap.each { println it }
http://rosettacode.org/wiki/Isqrt_(integer_square_root)_of_X
Isqrt (integer square root) of X
Sometimes a function is needed to find the integer square root of   X,   where   X   can be a real non─negative number. Often   X   is actually a non─negative integer. For the purposes of this task,   X   can be an integer or a real number,   but if it simplifies things in your computer programming language,   assume...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "bigint.s7i";   const func string: commatize (in bigInteger: bigNum) is func result var string: stri is ""; local var integer: index is 0; begin stri := str(bigNum); for index range length(stri) - 3 downto 1 step 3 do stri := stri[.. index] & "," & stri[su...
http://rosettacode.org/wiki/Isqrt_(integer_square_root)_of_X
Isqrt (integer square root) of X
Sometimes a function is needed to find the integer square root of   X,   where   X   can be a real non─negative number. Often   X   is actually a non─negative integer. For the purposes of this task,   X   can be an integer or a real number,   but if it simplifies things in your computer programming language,   assume...
#Sidef
Sidef
var n = 1234 say n.isqrt say n.iroot(2)
http://rosettacode.org/wiki/Inverted_index
Inverted index
An Inverted Index is a data structure used to create full text search. Task Given a set of text files, implement a program to create an inverted index. Also create a user interface to do a search using that inverted index which returns a list of files that contain the query term / terms. The search index can be i...
#PHP
PHP
<?php   function buildInvertedIndex($filenames) { $invertedIndex = [];   foreach($filenames as $filename) { $data = file_get_contents($filename);   if($data === false) die('Unable to read file: ' . $filename);   preg_match_all('/(\w+)/', $data, $matches, PREG_SET_ORDER);   fo...
http://rosettacode.org/wiki/Introspection
Introspection
Task verify the version/revision of your currently running (compiler/interpreter/byte-compiler/runtime environment/whatever your language uses) and exit if it is too old. check whether the variable "bloop" exists and whether the math-function "abs()" is available and if yes compute abs(bloop). Extra credit Repor...
#PARI.2FGP
PARI/GP
if(lex(version(), [2,4,3]) < 0, quit()); \\ Compare the version to 2.4.3 lexicographically   if(bloop!='bloop && type(abs) == "t_CLOSURE", abs(bloop))
http://rosettacode.org/wiki/Introspection
Introspection
Task verify the version/revision of your currently running (compiler/interpreter/byte-compiler/runtime environment/whatever your language uses) and exit if it is too old. check whether the variable "bloop" exists and whether the math-function "abs()" is available and if yes compute abs(bloop). Extra credit Repor...
#Perl
Perl
require v5.6.1; # run time version check require 5.6.1; # ditto require 5.006_001; # ditto; preferred for backwards compatibility
http://rosettacode.org/wiki/Josephus_problem
Josephus problem
Josephus problem is a math puzzle with a grim description: n {\displaystyle n} prisoners are standing on a circle, sequentially numbered from 0 {\displaystyle 0} to n − 1 {\displaystyle n-1} . An executioner walks along the circle, starting from prisoner 0 {\displaystyle 0} , removing eve...
#Oz
Oz
declare fun {Pipe Xs L H F} if L=<H then {Pipe {F Xs L} L+1 H F} else Xs end end fun {Josephus N K} fun {Victim Xs I} case Xs of kill(X S)|Xr then if S==1 then Last=I nil elseif X mod K==0 then Killed:=I-1|@Killed kill(X+1 S-1)|Xr else kill(X+1 S)|{Victim Xr I} end [] nil then n...
http://rosettacode.org/wiki/Interactive_programming_(repl)
Interactive programming (repl)
Many language implementations come with an interactive mode. This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions. An interactive mode may also be known as a command mode,   a read-eval-print loop (REPL),   or a shell. Task Show how to start this...
#Retro
Retro
:f (sss-s) [ s:prepend ] sip s:prepend s:append ; 'Rosetta 'Code ': f
http://rosettacode.org/wiki/Interactive_programming_(repl)
Interactive programming (repl)
Many language implementations come with an interactive mode. This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions. An interactive mode may also be known as a command mode,   a read-eval-print loop (REPL),   or a shell. Task Show how to start this...
#REXX
REXX
/*REXX*/ parse arg a b c say f(a,b,c) exit f:return arg(1)arg(3)arg(3)arg(2)
http://rosettacode.org/wiki/ISBN13_check_digit
ISBN13 check digit
Task Validate the check digit of an ISBN-13 code:   Multiply every other digit by  3.   Add these numbers and the other digits.   Take the remainder of this number after division by  10.   If it is  0,   the ISBN-13 check digit is correct. Use the following codes for testing:   978-1734314502       (good)   ...
#Swift
Swift
func checkISBN(isbn: String) -> Bool { guard !isbn.isEmpty else { return false }   let sum = isbn .compactMap({ $0.wholeNumberValue }) .enumerated() .map({ $0.offset & 1 == 1 ? 3 * $0.element : $0.element }) .reduce(0, +)   return sum % 10 == 0 }   let cases = [ "978-1734314502", "978-17...
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#Arturo
Arturo
num: "12349"   print ["The next number is:" (to :integer num)+1]
http://rosettacode.org/wiki/Integer_comparison
Integer comparison
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 |...
#BASIC
BASIC
  INPUT "Enter first number " ,a INPUT "Enter second number " ,b IF a < b THEN PRINT a ," is less than ", b IF a = b THEN PRINT a, " is equal to ", b IF a > b THEN PRINT a, " is greater than ", b
http://rosettacode.org/wiki/Include_a_file
Include a file
Task Demonstrate the language's ability to include source code from other files. See Also Compiler/Simple file inclusion pre processor
#ChucK
ChucK
Machine.add(me.dir() + "/MyOwnClassesDefinitions.ck");
http://rosettacode.org/wiki/Include_a_file
Include a file
Task Demonstrate the language's ability to include source code from other files. See Also Compiler/Simple file inclusion pre processor
#Clipper
Clipper
#include "inkey.ch"
http://rosettacode.org/wiki/Inheritance/Single
Inheritance/Single
This task is about derived types;   for implementation inheritance, see Polymorphism. Inheritance is an operation of type algebra that creates a new type from one or several parent types. The obtained type is called derived type. It inherits some of the properties of its parent types. Usually inherited properties...
#Lasso
Lasso
define animal => type { data public gender::string }   define dog => type { parent animal }   define cat => type { parent animal }   define collie => type { parent dog }   define lab => type { parent dog }   local(myanimal = lab)   #myanimal -> gender = 'Male' #myanimal -> gender
http://rosettacode.org/wiki/Inheritance/Single
Inheritance/Single
This task is about derived types;   for implementation inheritance, see Polymorphism. Inheritance is an operation of type algebra that creates a new type from one or several parent types. The obtained type is called derived type. It inherits some of the properties of its parent types. Usually inherited properties...
#Latitude
Latitude
  Animal ::= Object clone tap {  ;; Methods go here... }.   Dog ::= Animal clone tap {  ;; Methods go here... }.   Cat ::= Animal clone tap {  ;; Methods go here... }.   Lab ::= Dog clone tap {  ;; Methods go here... }.   Collie ::= Dog clone tap {  ;; Methods go here... }.
http://rosettacode.org/wiki/Inheritance/Single
Inheritance/Single
This task is about derived types;   for implementation inheritance, see Polymorphism. Inheritance is an operation of type algebra that creates a new type from one or several parent types. The obtained type is called derived type. It inherits some of the properties of its parent types. Usually inherited properties...
#Lingo
Lingo
-- parent script "Animal" -- ...
http://rosettacode.org/wiki/Identity_matrix
Identity matrix
Task Build an   identity matrix   of a size known at run-time. An identity matrix is a square matrix of size n × n, where the diagonal elements are all 1s (ones), and all the other elements are all 0s (zeroes). I n = [ 1 0 0 ⋯ 0 0 1 0 ⋯ 0 0 0 1 ⋯ 0 ⋮ ⋮ ⋮ ⋱ ...
#11l
11l
F identity_matrix(size) V matrix = [[0] * size] * size L(i) 0 .< size matrix[i][i] = 1 R matrix   L(row) identity_matrix(3) print(row)
http://rosettacode.org/wiki/Hunt_the_Wumpus
Hunt the Wumpus
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. Create a simple implementation of the classic textual game Hunt The Wumpus. The rules are: The game is set in a cave that consists ...
#AutoHotkey
AutoHotkey
  // constant value 2d array to represent the dodecahedron // room structure const static int adjacentRooms[20][3] = { {1, 4, 7}, {0, 2, 9}, {1, 3, 11}, {2, 4, 13}, {0, 3, 5}, {4, 6, 14}, {5, 7, 16}, {0, 6, 8}, {7, 9, 17}, {1, 8, 10}, {9, 11, 18}, {2, 10, 12}, {11, 13, 19}, {3, 12, 14}, {5, 13,...
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters
Idiomatically determine all the lowercase and uppercase letters
Idiomatically determine all the lowercase and uppercase letters   (of the Latin [English] alphabet)   being used currently by a computer programming language. The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other). Task requirements Display the set of...
#Haskell
Haskell
main = do putStrLn $ "Lower: " ++ ['a'..'z'] putStrLn $ "Upper: " ++ ['A'..'Z']
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters
Idiomatically determine all the lowercase and uppercase letters
Idiomatically determine all the lowercase and uppercase letters   (of the Latin [English] alphabet)   being used currently by a computer programming language. The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other). Task requirements Display the set of...
#J
J
(#~ tolower ~: toupper) a. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters
Idiomatically determine all the lowercase and uppercase letters
Idiomatically determine all the lowercase and uppercase letters   (of the Latin [English] alphabet)   being used currently by a computer programming language. The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other). Task requirements Display the set of...
#Java
Java
import java.util.stream.IntStream;   public class Letters { public static void main(String[] args) throws Exception { System.out.print("Upper case: "); IntStream.rangeClosed(0, 0x10FFFF) .filter(Character::isUpperCase) .limit(72) .forEach(n -> Syste...
http://rosettacode.org/wiki/Imaginary_base_numbers
Imaginary base numbers
Imaginary base numbers are a non-standard positional numeral system which uses an imaginary number as its radix. The most common is quater-imaginary with radix 2i. The quater-imaginary numeral system was first proposed by Donald Knuth in 1955 as a submission for a high school science talent search. [Ref.] Other imagi...
#Haskell
Haskell
import Data.Char (chr, digitToInt, intToDigit, isDigit, ord) import Data.Complex (Complex (..), imagPart, realPart) import Data.List (delete, elemIndex) import Data.Maybe (fromMaybe)   base :: Complex Float base = 0 :+ 2   quotRemPositive :: Int -> Int -> (Int, Int) quotRemPositive a b | r < 0 = (1 + q, floor (realPa...
http://rosettacode.org/wiki/Image_noise
Image noise
Generate a random black and white   320x240   image continuously, showing FPS (frames per second). A sample image
#Common_Lisp
Common Lisp
;; (require :lispbuilder-sdl)   (defun draw-noise (surface) "draws noise on the surface. Returns the surface" (let ((width (sdl:width surface)) (height (sdl:height surface)) (i-white (sdl:map-color sdl:*white* surface)) (i-black (sdl:map-color sdl:*black* surface))) (sdl-base::with-pixel (s (sdl:fp surface))...
http://rosettacode.org/wiki/Image_convolution
Image convolution
One class of image digital filters is described by a rectangular matrix of real coefficients called kernel convoluted in a sliding window of image pixels. Usually the kernel is square K k l {\displaystyle K_{kl}} , where k, l are in the range -R,-R+1,..,R-1,R. W=2R+1 is the kernel width. The filter determine...
#J
J
NB. pad the edges of an array with border pixels NB. (increasing the first two dimensions by 1 less than the kernel size) pad=: adverb define 'a b'=. (<. ,. >.) 0.5 0.5 p. $m a"_`(0 , ] - 1:)`(# 1:)}~&# # b"_`(0 , ] - 1:)`(# 1:)}~&(1 { $) #"1 ] )   kernel_filter=: adverb define ($m)+/ .*&(,m)&(,/);._3 m pad )
http://rosettacode.org/wiki/Image_convolution
Image convolution
One class of image digital filters is described by a rectangular matrix of real coefficients called kernel convoluted in a sliding window of image pixels. Usually the kernel is square K k l {\displaystyle K_{kl}} , where k, l are in the range -R,-R+1,..,R-1,R. W=2R+1 is the kernel width. The filter determine...
#Java
Java
import java.awt.image.*; import java.io.File; import java.io.IOException; import javax.imageio.*;   public class ImageConvolution { public static class ArrayData { public final int[] dataArray; public final int width; public final int height;   public ArrayData(int width, int height) { thi...
http://rosettacode.org/wiki/Index_finite_lists_of_positive_integers
Index finite lists of positive integers
It is known that the set of finite lists of positive integers is   countable. This means that there exists a subset of natural integers which can be mapped to the set of finite lists of positive integers. Task Implement such a mapping:   write a function     rank     which assigns an integer to any finite, arbi...
#Ruby
Ruby
def rank(arr) arr.join('a').to_i(11) end   def unrank(n) n.to_s(11).split('a').map(&:to_i) end   l = [1, 2, 3, 10, 100, 987654321] p l n = rank(l) p n l = unrank(n) p l
http://rosettacode.org/wiki/Index_finite_lists_of_positive_integers
Index finite lists of positive integers
It is known that the set of finite lists of positive integers is   countable. This means that there exists a subset of natural integers which can be mapped to the set of finite lists of positive integers. Task Implement such a mapping:   write a function     rank     which assigns an integer to any finite, arbi...
#Scala
Scala
object IndexFiniteList extends App { val (defBase, s) = (10, Seq(1, 2, 3, 10, 100, 987654321))   def rank(x: Seq[Int], base: Int = defBase) = BigInt(x.map(Integer.toString(_, base)).mkString(base.toHexString), base + 1)   def unrank(n: BigInt, base: Int = defBase): List[BigInt] = n.toString(base + 1).spli...
http://rosettacode.org/wiki/Integer_sequence
Integer sequence
Task Create a program that, when run, would display all integers from   1   to   ∞   (or any relevant implementation limit),   in sequence   (i.e.   1, 2, 3, 4, etc)   if given enough time. An example may not be able to reach arbitrarily-large numbers based on implementations limits.   For example, if integer...
#EchoLisp
EchoLisp
  (lib 'bigint) ;; arbitrary length integers (for ((n (in-naturals))) (writeln n))  
http://rosettacode.org/wiki/Integer_sequence
Integer sequence
Task Create a program that, when run, would display all integers from   1   to   ∞   (or any relevant implementation limit),   in sequence   (i.e.   1, 2, 3, 4, etc)   if given enough time. An example may not be able to reach arbitrarily-large numbers based on implementations limits.   For example, if integer...
#EDSAC_order_code
EDSAC order code
[ Integer sequence ================   A program for the EDSAC   Displays integers 1,2,3... in binary form in the first word of storage tank 2 until stopped   Works with Initial Orders 2 ]   T56K [ set load point ] GK [ set base address ]   A3@ [ increment accumulator ] U64F [ copy a...
http://rosettacode.org/wiki/Infinity
Infinity
Task Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding IEEE numbers), and if so, returns positive infinity.   Otherwise, return the largest possible po...
#Groovy
Groovy
def biggest = { Double.POSITIVE_INFINITY }
http://rosettacode.org/wiki/Infinity
Infinity
Task Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding IEEE numbers), and if so, returns positive infinity.   Otherwise, return the largest possible po...
#Haskell
Haskell
maxRealFloat :: RealFloat a => a -> a maxRealFloat x = encodeFloat b (e-1) `asTypeOf` x where b = floatRadix x - 1 (_,e) = floatRange x   infinity :: RealFloat a => a infinity = if isInfinite inf then inf else maxRealFloat 1.0 where inf = 1/0
http://rosettacode.org/wiki/Increasing_gaps_between_consecutive_Niven_numbers
Increasing gaps between consecutive Niven numbers
Note:   Niven   numbers are also called   Harshad   numbers.   They are also called    multidigital   numbers. Niven numbers are positive integers which are evenly divisible by the sum of its digits   (expressed in base ten). Evenly divisible   means   divisible with no remainder. Task   find the gap (differen...
#Yabasic
Yabasic
  sub digit_sum(n, sum) // devuelve la suma de los dígitos de n dada la suma de los dígitos de n - 1 sum = sum + 1 while n > 0 and (mod(n, 10) = 0) sum = sum - 9 n = int(n / 10) end while return sum end sub   sub divisible(n, d) if mod(d, 1) = 0 and mod(n, 1) = 1 then return 0 el...
http://rosettacode.org/wiki/Increasing_gaps_between_consecutive_Niven_numbers
Increasing gaps between consecutive Niven numbers
Note:   Niven   numbers are also called   Harshad   numbers.   They are also called    multidigital   numbers. Niven numbers are positive integers which are evenly divisible by the sum of its digits   (expressed in base ten). Evenly divisible   means   divisible with no remainder. Task   find the gap (differen...
#zkl
zkl
harshadW:=[1..].tweak(fcn(n){ if(n%(n.split().sum(0))) Void.Skip else n }); harshadW:=Walker.zero().tweak(fcn(go){ // faster than one liner, fewer calls foreach h in ([go.value..]){ // spin s,t := 0,h; while(t){ s+=t%10; t/=10 } // sum of digits if(0 == h%s){ go.set(h+1); return(h) } } }.fp(Ref(1)...
http://rosettacode.org/wiki/Integer_overflow
Integer overflow
Some languages support one or more integer types of the underlying processor. This integer types have fixed size;   usually   8-bit,   16-bit,   32-bit,   or   64-bit. The integers supported by such a type can be   signed   or   unsigned. Arithmetic for machine level integers can often be done by single CPU instruct...
#PowerShell
PowerShell
  try { # All of these raise an exception, which is caught below. # The try block is aborted after the first exception, # so the subsequent lines are never executed.   [int32] (-(-2147483647-1)) [int32] (2000000000 + 2000000000) [int32] (-2147483647 - 2147483647) [int32] (46341 * 46341) [int32] ((-2147483647-1)...
http://rosettacode.org/wiki/Input_loop
Input loop
Input loop is part of Short Circuit's Console Program Basics selection. Task Read from a text stream either word-by-word or line-by-line until the stream runs out of data. The stream will have an unknown amount of data on it.
#Haskell
Haskell
import System.IO   readLines :: Handle -> IO [String] readLines h = do s <- hGetContents h return $ lines s   readWords :: Handle -> IO [String] readWords h = do s <- hGetContents h return $ words s
http://rosettacode.org/wiki/Input_loop
Input loop
Input loop is part of Short Circuit's Console Program Basics selection. Task Read from a text stream either word-by-word or line-by-line until the stream runs out of data. The stream will have an unknown amount of data on it.
#HicEst
HicEst
CHARACTER name='myfile.txt', string*1000   OPEN(FIle=name, OLD, LENgth=bytes, IOStat=errorcode, ERror=9)   DO line = 1, bytes ! loop terminates with end-of-file error at the latest READ(FIle=name, IOStat=errorcode, ERror=9) string WRITE(StatusBar) string ENDDO   9 WRITE(Messagebox, Name) line, er...
http://rosettacode.org/wiki/Isqrt_(integer_square_root)_of_X
Isqrt (integer square root) of X
Sometimes a function is needed to find the integer square root of   X,   where   X   can be a real non─negative number. Often   X   is actually a non─negative integer. For the purposes of this task,   X   can be an integer or a real number,   but if it simplifies things in your computer programming language,   assume...
#Standard_ML
Standard ML
(*   The Rosetta Code integer square root task, in Standard ML.   Compile with, for example:   mlton isqrt.sml   *)   val zero = IntInf.fromInt (0) val one = IntInf.fromInt (1) val seven = IntInf.fromInt (7) val word1 = Word.fromInt (1) val word2 = Word.fromInt (2)   fun find_a_power_of_4_greater_than_x (x) = ...
http://rosettacode.org/wiki/Isqrt_(integer_square_root)_of_X
Isqrt (integer square root) of X
Sometimes a function is needed to find the integer square root of   X,   where   X   can be a real non─negative number. Often   X   is actually a non─negative integer. For the purposes of this task,   X   can be an integer or a real number,   but if it simplifies things in your computer programming language,   assume...
#Swift
Swift
import BigInt   func integerSquareRoot<T: BinaryInteger>(_ num: T) -> T { var x: T = num var q: T = 1 while q <= x { q <<= 2 } var r: T = 0 while q > 1 { q >>= 2 let t: T = x - r - q r >>= 1 if t >= 0 { x = t r += q } } ...
http://rosettacode.org/wiki/Inverted_index
Inverted index
An Inverted Index is a data structure used to create full text search. Task Given a set of text files, implement a program to create an inverted index. Also create a user interface to do a search using that inverted index which returns a list of files that contain the query term / terms. The search index can be i...
#PicoLisp
PicoLisp
$ cat file1 it is what it is $ cat file2 what is it $ cat file3 it is a banana
http://rosettacode.org/wiki/Introspection
Introspection
Task verify the version/revision of your currently running (compiler/interpreter/byte-compiler/runtime environment/whatever your language uses) and exit if it is too old. check whether the variable "bloop" exists and whether the math-function "abs()" is available and if yes compute abs(bloop). Extra credit Repor...
#Phix
Phix
requires("0.8.2") -- crashes on 0.8.1 and earlier requires(WINDOWS) -- crashes on Linux requires(64) -- crashes on 32-bit
http://rosettacode.org/wiki/Introspection
Introspection
Task verify the version/revision of your currently running (compiler/interpreter/byte-compiler/runtime environment/whatever your language uses) and exit if it is too old. check whether the variable "bloop" exists and whether the math-function "abs()" is available and if yes compute abs(bloop). Extra credit Repor...
#Phixmonti
Phixmonti
_version 1.0 < if "Interpreter version is old" else "Last version" endif print
http://rosettacode.org/wiki/Josephus_problem
Josephus problem
Josephus problem is a math puzzle with a grim description: n {\displaystyle n} prisoners are standing on a circle, sequentially numbered from 0 {\displaystyle 0} to n − 1 {\displaystyle n-1} . An executioner walks along the circle, starting from prisoner 0 {\displaystyle 0} , removing eve...
#PARI.2FGP
PARI/GP
Josephus(n, k)=if(n<2, n>0, my(t=(Josephus(n-1, k)+k)%n); if(t, t, n))
http://rosettacode.org/wiki/Interactive_programming_(repl)
Interactive programming (repl)
Many language implementations come with an interactive mode. This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions. An interactive mode may also be known as a command mode,   a read-eval-print loop (REPL),   or a shell. Task Show how to start this...
#Ring
Ring
  r = "Rosetta" c = "Code" s = ":" see r+s+s+c  
http://rosettacode.org/wiki/Interactive_programming_(repl)
Interactive programming (repl)
Many language implementations come with an interactive mode. This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions. An interactive mode may also be known as a command mode,   a read-eval-print loop (REPL),   or a shell. Task Show how to start this...
#Ruby
Ruby
$ irb irb(main):001:0> def f(string1, string2, separator) irb(main):002:1> [string1, '', string2].join(separator) irb(main):003:1> end => :f irb(main):004:0> f('Rosetta', 'Code', ':') => "Rosetta::Code" irb(main):005:0> exit $
http://rosettacode.org/wiki/ISBN13_check_digit
ISBN13 check digit
Task Validate the check digit of an ISBN-13 code:   Multiply every other digit by  3.   Add these numbers and the other digits.   Take the remainder of this number after division by  10.   If it is  0,   the ISBN-13 check digit is correct. Use the following codes for testing:   978-1734314502       (good)   ...
#Tcl
Tcl
  proc validISBN13 code { regsub -all {\D} $code "" code ;# remove non-digits if {[string length $code] == 13} { set sum 0 set fac 1 foreach digit [split $code ""] { set sum [expr {$sum + $digit * $fac}] set fac [expr {$fac == 1? 3: 1}] } if {$sum % 10 == 0} {return...
http://rosettacode.org/wiki/I_before_E_except_after_C
I before E except after C
The phrase     "I before E, except after C"     is a widely known mnemonic which is supposed to help when spelling English words. Task Using the word list from   http://wiki.puzzlers.org/pub/wordlists/unixdict.txt, check if the two sub-clauses of the phrase are plausible individually:   "I before E when not pre...
#11l
11l
V PLAUSIBILITY_RATIO = 2   F plausibility_check(comment, x, y) print("\n Checking plausibility of: #.".format(comment)) I x > :PLAUSIBILITY_RATIO * y print(‘ PLAUSIBLE. As we have counts of #. vs #., a ratio of #2.1 times’.format(x, y, Float(x) / y)) E I x > y print(‘ IMPLAUSIBLE. A...
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#Asymptote
Asymptote
string cadena = "12345.78"; cadena = string((real)cadena + 1); write(cadena);
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#AutoHotkey
AutoHotkey
str = 12345 MsgBox % str += 1
http://rosettacode.org/wiki/Integer_comparison
Integer comparison
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 |...
#Batch_File
Batch File
@echo off setlocal EnableDelayedExpansion set /p a="A: " set /p b="B: " if %a% LSS %b% ( echo %a% is less than %b% ) else ( if %a% GTR %b% ( echo %a% is greater than %b% ) else ( if %a% EQU %b% ( echo %a% is equal to %b% )))
http://rosettacode.org/wiki/Include_a_file
Include a file
Task Demonstrate the language's ability to include source code from other files. See Also Compiler/Simple file inclusion pre processor
#Clojure
Clojure
(load "path/to/file")
http://rosettacode.org/wiki/Include_a_file
Include a file
Task Demonstrate the language's ability to include source code from other files. See Also Compiler/Simple file inclusion pre processor
#COBOL
COBOL
COPY "copy.cpy". *> The full stop is mandatory, wherever the COPY is. COPY "another-copy.cpy" REPLACING foo BY bar SPACE BY ZERO ==text to replace== BY ==replacement text==.
http://rosettacode.org/wiki/Inheritance/Single
Inheritance/Single
This task is about derived types;   for implementation inheritance, see Polymorphism. Inheritance is an operation of type algebra that creates a new type from one or several parent types. The obtained type is called derived type. It inherits some of the properties of its parent types. Usually inherited properties...
#Lisaac
Lisaac
Section Header + name := ANIMAL; // ...
http://rosettacode.org/wiki/Inheritance/Single
Inheritance/Single
This task is about derived types;   for implementation inheritance, see Polymorphism. Inheritance is an operation of type algebra that creates a new type from one or several parent types. The obtained type is called derived type. It inherits some of the properties of its parent types. Usually inherited properties...
#Logtalk
Logtalk
  :- object(thing, instantiates(thing)). :- end_object.   :- object(animal, specializes(thing)). ... :- end_object.   :- object(dog, specializes(animal)). ... :- end_object.   :- object(cat, specializes(animal)). ... :- end_object.   :- object(lab, specializes(dog)). ... :- end_objec...
http://rosettacode.org/wiki/Inheritance/Single
Inheritance/Single
This task is about derived types;   for implementation inheritance, see Polymorphism. Inheritance is an operation of type algebra that creates a new type from one or several parent types. The obtained type is called derived type. It inherits some of the properties of its parent types. Usually inherited properties...
#Lua
Lua
Class = { classname = "Class aka Object aka Root-Of-Tree", new = function(s,t) s.__index = s local instance = setmetatable(t or {}, s) instance.parent = s return instance end }   Animal = Class:new{classname="Animal", speak=function(s) return s.voice or "("..s.classname.." has no voice)" end } Cat...
http://rosettacode.org/wiki/Identity_matrix
Identity matrix
Task Build an   identity matrix   of a size known at run-time. An identity matrix is a square matrix of size n × n, where the diagonal elements are all 1s (ones), and all the other elements are all 0s (zeroes). I n = [ 1 0 0 ⋯ 0 0 1 0 ⋯ 0 0 0 1 ⋯ 0 ⋮ ⋮ ⋮ ⋱ ...
#360_Assembly
360 Assembly
* Identity matrix 31/03/2017 INDENMAT CSECT USING INDENMAT,R13 base register B 72(R15) skip savearea DC 17F'0' savearea STM R14,R12,12(R13) save previous context ST R13,4(R15) link backward ST...
http://rosettacode.org/wiki/Hunt_the_Wumpus
Hunt the Wumpus
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified. See this page's Talk page for discussion. Create a simple implementation of the classic textual game Hunt The Wumpus. The rules are: The game is set in a cave that consists ...
#C.23
C#
  // constant value 2d array to represent the dodecahedron // room structure const static int adjacentRooms[20][3] = { {1, 4, 7}, {0, 2, 9}, {1, 3, 11}, {2, 4, 13}, {0, 3, 5}, {4, 6, 14}, {5, 7, 16}, {0, 6, 8}, {7, 9, 17}, {1, 8, 10}, {9, 11, 18}, {2, 10, 12}, {11, 13, 19}, {3, 12, 14}, {5, 13,...
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters
Idiomatically determine all the lowercase and uppercase letters
Idiomatically determine all the lowercase and uppercase letters   (of the Latin [English] alphabet)   being used currently by a computer programming language. The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other). Task requirements Display the set of...
#jq
jq
# The range of codepoints is from m up to but excluding n; # "class" should be a character class, e.g. Ll or Lu for lower/upper case respectively. def generate(class; m; n): reduce (range(m;n) | [.] | implode | select( test( "\\p{" + class + "}" ))) as $c (""; . + $c);
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters
Idiomatically determine all the lowercase and uppercase letters
Idiomatically determine all the lowercase and uppercase letters   (of the Latin [English] alphabet)   being used currently by a computer programming language. The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other). Task requirements Display the set of...
#Julia
Julia
  function countunicode() englishlettercodes = [Int(c) for c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"] count = 0 az = "" AZ = "" for i in 0:0xffffff if is_assigned_char(i) count += 1 end if i in englishlettercodes c = Char(i) ...
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters
Idiomatically determine all the lowercase and uppercase letters
Idiomatically determine all the lowercase and uppercase letters   (of the Latin [English] alphabet)   being used currently by a computer programming language. The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other). Task requirements Display the set of...
#Kotlin
Kotlin
// version 1.0.6   fun main(args: Array<String>) { print("Lower case : ") for (ch in 'a'..'z') print(ch) print("\nUpper case : ") for (ch in 'A'..'Z') print(ch) println() }
http://rosettacode.org/wiki/Idiomatically_determine_all_the_lowercase_and_uppercase_letters
Idiomatically determine all the lowercase and uppercase letters
Idiomatically determine all the lowercase and uppercase letters   (of the Latin [English] alphabet)   being used currently by a computer programming language. The method should find the letters regardless of the hardware architecture that is being used (ASCII, EBCDIC, or other). Task requirements Display the set of...
#Lua
Lua
function ASCIIstring (pattern) local matchString, ch = "" for charNum = 0, 255 do ch = string.char(charNum) if string.match(ch, pattern) then matchString = matchString .. ch end end return matchString end   print(ASCIIstring("%l")) print(ASCIIstring("%u"))  
http://rosettacode.org/wiki/Imaginary_base_numbers
Imaginary base numbers
Imaginary base numbers are a non-standard positional numeral system which uses an imaginary number as its radix. The most common is quater-imaginary with radix 2i. The quater-imaginary numeral system was first proposed by Donald Knuth in 1955 as a submission for a high school science talent search. [Ref.] Other imagi...
#J
J
  ibdec=: {{ 0j2 ibdec y : digits=. 0,".,~&'36b'@> tolower y -.'. ' (x #. digits) % x^#(}.~ 1+i.&'.')y-.' ' }}"1   ibenc=: {{ 0j2 ibenc y : if.0=y do.,'0' return.end. sq=.*:x assert. 17 > sq step=. }.,~(1,|sq) +^:(0>{:@]) (0,sq) #: {. seq=. step^:(0~:{.)^:_"0 're im0'=.+.y 'im imf'=.(sign,1)*(0,|x)#...
http://rosettacode.org/wiki/Image_noise
Image noise
Generate a random black and white   320x240   image continuously, showing FPS (frames per second). A sample image
#D
D
import std.stdio, std.random, sdl.SDL;   void main() { SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO); auto surface = SDL_SetVideoMode(320,240,8, SDL_DOUBLEBUF|SDL_HWSURFACE);   uint frameNumber, totalTime, lastTime; while (true) { SDL_LockSurface(surface); foreach (i; 0 .. surface.w * surface.h) (cast...
http://rosettacode.org/wiki/Image_convolution
Image convolution
One class of image digital filters is described by a rectangular matrix of real coefficients called kernel convoluted in a sliding window of image pixels. Usually the kernel is square K k l {\displaystyle K_{kl}} , where k, l are in the range -R,-R+1,..,R-1,R. W=2R+1 is the kernel width. The filter determine...
#JavaScript
JavaScript
// Image imageIn, Array kernel, function (Error error, Image imageOut) // precondition: Image is loaded // returns loaded Image to asynchronous callback function function convolve(imageIn, kernel, callback) { var dim = Math.sqrt(kernel.length), pad = Math.floor(dim / 2);   if (dim % 2 !== 1) { r...
http://rosettacode.org/wiki/Index_finite_lists_of_positive_integers
Index finite lists of positive integers
It is known that the set of finite lists of positive integers is   countable. This means that there exists a subset of natural integers which can be mapped to the set of finite lists of positive integers. Task Implement such a mapping:   write a function     rank     which assigns an integer to any finite, arbi...
#Sidef
Sidef
func rank(Array arr) { Number(arr.join('a'), 11) }   func unrank(Number n) { n.base(11).split('a').map { Num(_) } }   var l = [1, 2, 3, 10, 100, 987654321] say l var n = rank(l) say n var l = unrank(n) say l
http://rosettacode.org/wiki/Index_finite_lists_of_positive_integers
Index finite lists of positive integers
It is known that the set of finite lists of positive integers is   countable. This means that there exists a subset of natural integers which can be mapped to the set of finite lists of positive integers. Task Implement such a mapping:   write a function     rank     which assigns an integer to any finite, arbi...
#Tcl
Tcl
package require Tcl 8.6   proc rank {integers} { join [lmap i $integers {format %llo $i}] 8 }   proc unrank {codedValue} { lmap i [split $codedValue 8] {scan $i %llo} }
http://rosettacode.org/wiki/Index_finite_lists_of_positive_integers
Index finite lists of positive integers
It is known that the set of finite lists of positive integers is   countable. This means that there exists a subset of natural integers which can be mapped to the set of finite lists of positive integers. Task Implement such a mapping:   write a function     rank     which assigns an integer to any finite, arbi...
#Wren
Wren
import "/big" for BigInt   // Separates each integer in the list with an 'a' then encodes in base 11. // Empty list mapped to '-1'. var rank = Fn.new { |li| if (li.count == 0) return BigInt.minusOne return BigInt.fromBaseString(li.join("a"), 11) }   var unrank = Fn.new { |r| if (r == BigInt.minusOne) return...
http://rosettacode.org/wiki/Integer_sequence
Integer sequence
Task Create a program that, when run, would display all integers from   1   to   ∞   (or any relevant implementation limit),   in sequence   (i.e.   1, 2, 3, 4, etc)   if given enough time. An example may not be able to reach arbitrarily-large numbers based on implementations limits.   For example, if integer...
#Eiffel
Eiffel
  class APPLICATION inherit ARGUMENTS create make feature {NONE} -- Initialization make -- Run application. do from number := 0 until number = number.max_value loop print(number) print(", ") number := number + 1 end end number:INTEGER_64 end  
http://rosettacode.org/wiki/Integer_sequence
Integer sequence
Task Create a program that, when run, would display all integers from   1   to   ∞   (or any relevant implementation limit),   in sequence   (i.e.   1, 2, 3, 4, etc)   if given enough time. An example may not be able to reach arbitrarily-large numbers based on implementations limits.   For example, if integer...
#Elena
Elena
import extensions;   public program() { var i := 0u; while (true) { console.printLine(i);   i += 1u } }
http://rosettacode.org/wiki/Infinity
Infinity
Task Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding IEEE numbers), and if so, returns positive infinity.   Otherwise, return the largest possible po...
#Icon_and_Unicon
Icon and Unicon
print, !Values.f_infinity ;; for normal floats or print, !Values.D_infinity ;; for doubles
http://rosettacode.org/wiki/Infinity
Infinity
Task Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding IEEE numbers), and if so, returns positive infinity.   Otherwise, return the largest possible po...
#IDL
IDL
print, !Values.f_infinity ;; for normal floats or print, !Values.D_infinity ;; for doubles
http://rosettacode.org/wiki/Infinity
Infinity
Task Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding IEEE numbers), and if so, returns positive infinity.   Otherwise, return the largest possible po...
#Io
Io
inf := 1/0
http://rosettacode.org/wiki/Infinity
Infinity
Task Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding IEEE numbers), and if so, returns positive infinity.   Otherwise, return the largest possible po...
#IS-BASIC
IS-BASIC
PRINT INF
http://rosettacode.org/wiki/Integer_overflow
Integer overflow
Some languages support one or more integer types of the underlying processor. This integer types have fixed size;   usually   8-bit,   16-bit,   32-bit,   or   64-bit. The integers supported by such a type can be   signed   or   unsigned. Arithmetic for machine level integers can often be done by single CPU instruct...
#PureBasic
PureBasic
#MAX_BYTE =127   #MAX_ASCII=255 ;=MAX_CHAR Ascii-Mode   CompilerIf #PB_Compiler_Unicode=1 #MAX_CHAR =65535 ;Unicode-Mode CompilerElse #MAX_CHAR =255 CompilerEndIf   #MAX_WORD =32767   #MAX_UNIC =65535   #MAX_LONG =2147483647   CompilerIf #PB_Compiler_Processor=#PB_Processor_x86 #MAX_INT ...
http://rosettacode.org/wiki/Input_loop
Input loop
Input loop is part of Short Circuit's Console Program Basics selection. Task Read from a text stream either word-by-word or line-by-line until the stream runs out of data. The stream will have an unknown amount of data on it.
#i
i
software { loop { read() errors { exit } } }
http://rosettacode.org/wiki/Input_loop
Input loop
Input loop is part of Short Circuit's Console Program Basics selection. Task Read from a text stream either word-by-word or line-by-line until the stream runs out of data. The stream will have an unknown amount of data on it.
#Icon_and_Unicon
Icon and Unicon
link str2toks # call either words or lines depending on what you want to do. procedure main() words() end   procedure lines() while write(read()) end   procedure words() local line while line := read() do line ? every write(str2toks()) end
http://rosettacode.org/wiki/Isqrt_(integer_square_root)_of_X
Isqrt (integer square root) of X
Sometimes a function is needed to find the integer square root of   X,   where   X   can be a real non─negative number. Often   X   is actually a non─negative integer. For the purposes of this task,   X   can be an integer or a real number,   but if it simplifies things in your computer programming language,   assume...
#Tiny_BASIC
Tiny BASIC
10 LET X = 0 20 GOSUB 100 30 PRINT R 40 LET X = X + 1 50 IF X < 66 THEN GOTO 20 70 PRINT "---" 71 LET X = 7 72 GOSUB 100 73 PRINT R 77 LET X = 343 78 GOSUB 100 79 PRINT R 90 END 100 REM integer square root function 110 LET Q = 1 120 IF Q > X THEN GOTO 150 130 LET Q = Q * 4 140 GOTO 120 150 LET Z = X 160 LET R = 0 170 I...
http://rosettacode.org/wiki/Isqrt_(integer_square_root)_of_X
Isqrt (integer square root) of X
Sometimes a function is needed to find the integer square root of   X,   where   X   can be a real non─negative number. Often   X   is actually a non─negative integer. For the purposes of this task,   X   can be an integer or a real number,   but if it simplifies things in your computer programming language,   assume...
#UNIX_Shell
UNIX Shell
function isqrt { typeset -i x for x; do typeset -i q=1 while (( q <= x )); do (( q <<= 2 )) if (( q <= 0 )); then return 1 fi done typeset -i z=x typeset -i r=0 typeset -i t while (( q > 1 )); do (( q >>= 2 )) (( t = z - r - q )) (( r >>= 1 )) ...
http://rosettacode.org/wiki/Inverted_index
Inverted index
An Inverted Index is a data structure used to create full text search. Task Given a set of text files, implement a program to create an inverted index. Also create a user interface to do a search using that inverted index which returns a list of files that contain the query term / terms. The search index can be i...
#PowerShell
PowerShell
function Index-File ( [string[]]$FileList ) { # Create index hashtable, as needed If ( -not $Script:WordIndex ) { $Script:WordIndex = @{} }   # For each file to be indexed... ForEach ( $File in $FileList ) { # Find any previously existing entries for this file $ExistingEnt...
http://rosettacode.org/wiki/Introspection
Introspection
Task verify the version/revision of your currently running (compiler/interpreter/byte-compiler/runtime environment/whatever your language uses) and exit if it is too old. check whether the variable "bloop" exists and whether the math-function "abs()" is available and if yes compute abs(bloop). Extra credit Repor...
#PHP
PHP
<?php   if (version_compare(PHP_VERSION, '5.3.0', '<' )) { echo("You are using PHP Version " . PHP_VERSION . ". Please upgrade to Version 5.3.0\n"); exit(); } $bloop = -3; if (isset($bloop) && function_exists('abs')) { echo(abs($bloop)); } echo(count($GLOBALS) . " variables in global scope.\n"); echo(array_sum($GLOB...
http://rosettacode.org/wiki/Introspection
Introspection
Task verify the version/revision of your currently running (compiler/interpreter/byte-compiler/runtime environment/whatever your language uses) and exit if it is too old. check whether the variable "bloop" exists and whether the math-function "abs()" is available and if yes compute abs(bloop). Extra credit Repor...
#PicoLisp
PicoLisp
(unless (>= (version T) (3 0 1)) # Check version (only in the 64-bit version) (bye) )   # (setq bloop -7) # Uncomment this to get the output '7'   (and (num? bloop) # When 'bloop' is bound to a number (getd 'abs) # and 'abs' defined as a...
http://rosettacode.org/wiki/Josephus_problem
Josephus problem
Josephus problem is a math puzzle with a grim description: n {\displaystyle n} prisoners are standing on a circle, sequentially numbered from 0 {\displaystyle 0} to n − 1 {\displaystyle n-1} . An executioner walks along the circle, starting from prisoner 0 {\displaystyle 0} , removing eve...
#Perl
Perl
my @prisoner = 0 .. 40; my $k = 3; until (@prisoner == 1) { push @prisoner, shift @prisoner for 1 .. $k-1; shift @prisoner; }   print "Prisoner @prisoner survived.\n"
http://rosettacode.org/wiki/Interactive_programming_(repl)
Interactive programming (repl)
Many language implementations come with an interactive mode. This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions. An interactive mode may also be known as a command mode,   a read-eval-print loop (REPL),   or a shell. Task Show how to start this...
#Rust
Rust
name: myapp version: "1.0" author: A Rust Developer <rustme@home.com> about: Does awesome things args: - STRING1: about: First string to use required: true index: 1 - STRING2: about: Second string to use required: true index: 2 - SEPARATOR: about: Separtor to use r...
http://rosettacode.org/wiki/Interactive_programming_(repl)
Interactive programming (repl)
Many language implementations come with an interactive mode. This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions. An interactive mode may also be known as a command mode,   a read-eval-print loop (REPL),   or a shell. Task Show how to start this...
#S-lang
S-lang
slsh --help
http://rosettacode.org/wiki/Interactive_programming_(repl)
Interactive programming (repl)
Many language implementations come with an interactive mode. This is a command-line interpreter that reads lines from the user and evaluates these lines as statements or expressions. An interactive mode may also be known as a command mode,   a read-eval-print loop (REPL),   or a shell. Task Show how to start this...
#Scala
Scala
C:\>scala Welcome to Scala version 2.8.0.r21356-b20100407020120 (Java HotSpot(TM) Client V M, Java 1.6.0_05). Type in expressions to have them evaluated. Type :help for more information.   scala> "rosetta" res0: java.lang.String = rosetta
http://rosettacode.org/wiki/ISBN13_check_digit
ISBN13 check digit
Task Validate the check digit of an ISBN-13 code:   Multiply every other digit by  3.   Add these numbers and the other digits.   Take the remainder of this number after division by  10.   If it is  0,   the ISBN-13 check digit is correct. Use the following codes for testing:   978-1734314502       (good)   ...
#uBasic.2F4tH
uBasic/4tH
a := "978-1734314502" Print Show(a), Show (Iif (Func(_IsISBN (a)), "good", "bad"))   a := "978-1734314509" Print Show(a), Show (Iif (Func(_IsISBN (a)), "good", "bad"))   a := "978-1788399081" Print Show(a), Show (Iif (Func(_IsISBN (a)), "good", "bad"))   a := "978-1788399083" Print Show(a), Show (Iif (Func(_IsISBN (a)...
http://rosettacode.org/wiki/ISBN13_check_digit
ISBN13 check digit
Task Validate the check digit of an ISBN-13 code:   Multiply every other digit by  3.   Add these numbers and the other digits.   Take the remainder of this number after division by  10.   If it is  0,   the ISBN-13 check digit is correct. Use the following codes for testing:   978-1734314502       (good)   ...
#UNIX_Shell
UNIX Shell
check_isbn13 () { local i n t n=${1//[^0-9]/} t=0 for ((i=0; i<${#n}; ++i )); do (( t += ${n:i:1}*(1 + ((i&1)<<1)) )) done (( 0 == t % 10 )) }   for isbn in 978-1734314502 978-1734314509 978-1788399081 978-1788399083; do printf '%s: ' "$isbn" if check_isbn13 "$isbn"; then printf '%...
http://rosettacode.org/wiki/I_before_E_except_after_C
I before E except after C
The phrase     "I before E, except after C"     is a widely known mnemonic which is supposed to help when spelling English words. Task Using the word list from   http://wiki.puzzlers.org/pub/wordlists/unixdict.txt, check if the two sub-clauses of the phrase are plausible individually:   "I before E when not pre...
#8080_Assembly
8080 Assembly
;;; I before E, except after C fcb1: equ 5Ch ; FCB 1 (populated by file on command line) dma: equ 80h ; Standard DMA location bdos: equ 5 ; CP/M entry point puts: equ 9 ; CP/M call to write a string to the console fopen: equ 0Fh ; CP/M call to open a file fread: equ 14h ; CP/M call to read from a file CR: equ 13 LF: e...
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#AutoIt
AutoIt
Global $x = "12345" $x += 1 MsgBox(0,"",$x)
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#Avail
Avail
numberString ::= "1080"; incremented ::= numberString (base 10) + 1;
http://rosettacode.org/wiki/Integer_comparison
Integer comparison
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 |...
#BBC_BASIC
BBC BASIC
INPUT "Enter two numbers separated by a comma: " a, b CASE TRUE OF WHEN a < b: PRINT ;a " is less than "; b WHEN a = b: PRINT ;a " is equal to "; b WHEN a > b: PRINT ;a " is greater than "; b ENDCASE
http://rosettacode.org/wiki/Integer_comparison
Integer comparison
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 |...
#bc
bc
a = read() b = read() if (a < b) print "a is smaller than b\n" if (a > b) print "a is greater than b\n" if (a == b) print "a is equal to b\n" quit
http://rosettacode.org/wiki/Include_a_file
Include a file
Task Demonstrate the language's ability to include source code from other files. See Also Compiler/Simple file inclusion pre processor
#Common_Lisp
Common Lisp
(load "path/to/file")
http://rosettacode.org/wiki/Include_a_file
Include a file
Task Demonstrate the language's ability to include source code from other files. See Also Compiler/Simple file inclusion pre processor
#Crystal
Crystal
require "socket" # includes a file from standard library or /lib relative to current directory require "./myfile" # includes a file relative to current directory
http://rosettacode.org/wiki/Inheritance/Single
Inheritance/Single
This task is about derived types;   for implementation inheritance, see Polymorphism. Inheritance is an operation of type algebra that creates a new type from one or several parent types. The obtained type is called derived type. It inherits some of the properties of its parent types. Usually inherited properties...
#M2000_Interpreter
M2000 Interpreter
  Module CheckIt { Class Animal { } Class Dog as Animal { } Class Cat as Animal{ } Class Labrador As Dog { } Class Collie As Dog{ } \\ a is a pointer to a group made from class Labrador a->Labrador() Print a is type Animal = True Print ...
http://rosettacode.org/wiki/Inheritance/Single
Inheritance/Single
This task is about derived types;   for implementation inheritance, see Polymorphism. Inheritance is an operation of type algebra that creates a new type from one or several parent types. The obtained type is called derived type. It inherits some of the properties of its parent types. Usually inherited properties...
#Neko
Neko
var Animal = $new(null);   var Dog = $new(null); $objsetproto(Dog, Animal);   var Cat = $new(null); $objsetproto(Cat, Animal);   var Lab = $new(null); $objsetproto(Lab, Dog);   var Collie = $new(null); $objsetproto(Collie, Dog);