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/Image_noise
Image noise
Generate a random black and white   320x240   image continuously, showing FPS (frames per second). A sample image
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic 'code' declarations int CpuReg, \address of CPU register array (from GetReg) FPS, \frames per second, the display's update rate Sec, \current second of time (from real-time clock) SecOld, ...
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
#Z80_Assembly
Z80 Assembly
forever: ld hl,frametimer ld a,(hl) rrca rrca rrca xor (hl) ;crude xorshift rng used to select a "random" location to draw to.   ld h,0 ld L,a ;this random value becomes the low byte of HL   rlc L rl h ;reduce the RNG's bias towards the top of the screen by shifting one bit into ...
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...
#Nanoquery
Nanoquery
i = 1 while true println i i += 1 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...
#Necromantus
Necromantus
  let i = 0; while true { write(i); i = i + 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.
#Smalltalk
Smalltalk
|f| f := FileStream open: 'afile.txt' mode: FileStream read. [ f atEnd ] whileFalse: [ (f nextLine) displayNl ] .
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.
#SNOBOL4
SNOBOL4
loop output = input :s(loop) 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.
#Sparkling
Sparkling
var line; while (line = getline()) != nil { print(line); }
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...
#Vedit_macro_language
Vedit macro language
#1 = 41 // number of prisoners #2 = 3 // step size #3 = 1 // number of survivors   Buf_Switch(Buf_Free) for (#5=0; #5<#1; #5++) { Ins_Text("prisoner ") Num_Ins(#5, LEFT) }   BOF #4=1 while (#1 > #3) { if (#4++ % #2 == 0) { Del_Line(1) #1-- } else { Line(1) } if (At_EOF) { BOF } }
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...
#Haskell
Haskell
import Network.HTTP import Text.Regex.TDFA import Text.Printf   getWordList :: IO String getWordList = do response <- simpleHTTP.getRequest$ url getResponseBody response where url = "http://wiki.puzzlers.org/pub/wordlists/unixdict.txt"   main = do words <- getWordList putStrLn "Checking Rule...
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#GAP
GAP
# Using built-in functions Incr := s -> String(Int(s) + 1);   # Implementing addition # (but here 9...9 + 1 = 0...0 since the string length is fixed) Increment := function(s) local c, n, carry, digits; digits := "0123456789"; n := Length(s); carry := true; while n > 0 and carry do c := Position(digits, s[...
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#Go
Go
package main import "fmt" import "strconv" func main() { i, _ := strconv.Atoi("1234") fmt.Println(strconv.Itoa(i + 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 |...
#Euphoria
Euphoria
include get.e   integer a,b a = floor(prompt_number("a = ",{})) b = floor(prompt_number("b = ",{}))   puts(1,"a is ") if a < b then puts(1,"less then") elsif a = b then puts(1,"equal to") elsif a > b then puts(1,"grater then") end if puts(1," 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
#Prolog
Prolog
consult('filename').
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
#PureBasic
PureBasic
IncludeFile "Filename"
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
#Python
Python
import mymodule
http://rosettacode.org/wiki/IBAN
IBAN
This page uses content from Wikipedia. The original article was at IBAN. 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) The   International Bank Account Number (IBAN)   is an internationally agree...
#Groovy
Groovy
def validateIBAN(String iban) { def iso = [AL: 28, AD: 24, AT: 20, AZ: 28, BE: 16, BH: 22, BA: 20, BR: 29, BG: 22, HR: 21, CY: 28, CZ: 24, DK: 18, DO: 28, EE: 20, FO: 18, FI: 18, FR: 27, GE: 22, DE: 22, GI: 23, GL: 18, GT: 28, HU: 28, IS: 26, IE: 22, IL: 23, IT: 27, KZ: 20, KW: 30, LV: 21, L...
http://rosettacode.org/wiki/Humble_numbers
Humble numbers
Humble numbers are positive integers which have   no   prime factors   >   7. Humble numbers are also called   7-smooth numbers,   and sometimes called   highly composite, although this conflicts with another meaning of   highly composite numbers. Another way to express the above is: humble = 2i × 3j × 5k...
#Python
Python
'''Humble numbers'''   from itertools import groupby, islice from functools import reduce     # humbles :: () -> [Int] def humbles(): '''A non-finite stream of Humble numbers. OEIS A002473 ''' hs = set([1]) while True: nxt = min(hs) yield nxt hs.remove(nxt) hs.upda...
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 ⋮ ⋮ ⋮ ⋱ ...
#Elena
Elena
import extensions; import system'routines; import system'collections;   public program() { var n := console.write:"Enter the matrix size:".readLine().toInt();   var identity := new Range(0, n).selectBy:(i => new Range(0,n).selectBy:(j => (i == j).iif(1,0) ).summarize(new ArrayList())) ...
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...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols binary   k_ = Rexx bigDigits = 999999999 -- Maximum setting for digits allowed by NetRexx numeric digits bigDigits   loop k_ = 1 say k_ end k_  
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...
#NewLISP
NewLISP
(while (println (++ i)))
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.
#Standard_ML
Standard ML
fun foldLines f init strm = case TextIO.inputLine strm of SOME line => foldLines f (f (line, init)) strm | NONE => init
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.
#Tcl
Tcl
set fh [open $filename] while {[gets $fh line] != -1} { # process $line } close $fh
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.
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT file="a.txt" ERROR/STOP OPEN (file,READ,-std-) ACCESS source: READ/RECORDS/UTF8 $file s,text LOOP READ/NEXT/EXIT source PRINT text ENDLOOP ENDACCESS source  
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...
#Visual_Basic_.NET
Visual Basic .NET
Module Module1   'Determines the killing order numbering prisoners 1 to n Sub Josephus(n As Integer, k As Integer, m As Integer) Dim p = Enumerable.Range(1, n).ToList() Dim i = 0   Console.Write("Prisoner killing order:") While p.Count > 1 i = (i + k - 1) Mod p.Count ...
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...
#Icon_and_Unicon
Icon and Unicon
import Utils # To get the FindFirst class   procedure main(a) showCounts := "--showcounts" == !a totals := table(0) phrases := ["cei","cie","ei","ie"] # Longer phrases first ff := FindFirst(phrases)   every map(!&input) ? while totals[2(tab(ff.locate()), ff.moveMatch(), move(-1))] +:= 1   ...
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#Golfscript
Golfscript
~)`
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#Groovy
Groovy
println ((("23455" as BigDecimal) + 1) as String) println ((("23455.78" as BigDecimal) + 1) as String)
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 |...
#Excel
Excel
  =IF($A1>$B1;concatenate($A1;" is greater than ";$B1);IF($A1<$B1;concatenate($A1;" is smaller than ";$B1);concatenate($A1;" is equal to ";$B1)))  
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 |...
#F.23
F#
let compare_ints a b = let r = match a with | x when x < b -> -1, printfn "%d is less than %d" x b | x when x = b -> 0, printfn "%d is equal to %d" x b | x when x > b -> 1, printfn "%d is greater than %d" x b | x -> 0, printf "default condition (not reached)" fst r
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
#QB64
QB64
'$INCLUDE:'filename.bas'
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
#Quackery
Quackery
$ "myfile.qky" loadfile
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
#R
R
source("filename.R")
http://rosettacode.org/wiki/IBAN
IBAN
This page uses content from Wikipedia. The original article was at IBAN. 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) The   International Bank Account Number (IBAN)   is an internationally agree...
#Haskell
Haskell
import Data.Char (toUpper) import Data.Maybe (fromJust)   validateIBAN :: String -> Either String String validateIBAN [] = Left "No IBAN number." validateIBAN xs = case lookupCountry of Nothing -> invalidBecause "Country does not exist." Just l -> if length normalized /= l t...
http://rosettacode.org/wiki/Humble_numbers
Humble numbers
Humble numbers are positive integers which have   no   prime factors   >   7. Humble numbers are also called   7-smooth numbers,   and sometimes called   highly composite, although this conflicts with another meaning of   highly composite numbers. Another way to express the above is: humble = 2i × 3j × 5k...
#Quackery
Quackery
' [ 2 3 5 7 ] smoothwith [ -1 peek [ 10 12 ** ] constant = ] -1 split drop dup 50 split drop echo cr cr 12 times [ dup 0 over size rot 10 i^ 1+ ** searchwith < drop split swap size echo sp i^ 1+ echo say "-digit humble numbers" cr ] drop  
http://rosettacode.org/wiki/Humble_numbers
Humble numbers
Humble numbers are positive integers which have   no   prime factors   >   7. Humble numbers are also called   7-smooth numbers,   and sometimes called   highly composite, although this conflicts with another meaning of   highly composite numbers. Another way to express the above is: humble = 2i × 3j × 5k...
#Racket
Racket
#lang racket   (define (gen-humble-numbers N (kons #f) (k0 (void))) (define rv (make-vector N 1))   (define (loop n 2-idx 3-idx 5-idx 7-idx next-2 next-3 next-5 next-7 k) (if (= n N) rv (let ((mn (min next-2 next-3 next-5 next-7))) (vector-set! rv n mn) (define (add-1-if-min ...
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 ⋮ ⋮ ⋮ ⋱ ...
#Elixir
Elixir
defmodule Matrix do def identity(n) do Enum.map(0..n-1, fn i -> for j <- 0..n-1, do: (if i==j, do: 1, else: 0) end) end end   IO.inspect Matrix.identity(5)
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...
#Nim
Nim
var i:int64 = 0 while true: inc i echo i
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...
#Oberon-2
Oberon-2
  MODULE IntegerSeq; IMPORT Out, Object:BigInt;   PROCEDURE IntegerSequence*; VAR i: LONGINT; BEGIN FOR i := 0 TO MAX(LONGINT) DO Out.LongInt(i,0);Out.String(", ") END; Out.Ln END IntegerSequence;   PROCEDURE BigIntSequence*; VAR i: BigInt.BigInt; BEGIN i := BigInt.zero; ...
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.
#UNIX_Shell
UNIX Shell
while read line ; do # examine or do something to the text in the "line" variable echo "$line" done
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.
#UnixPipes
UnixPipes
yes 'A B C D ' | while read x ; do echo -$x- ; done
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...
#Vlang
Vlang
// basic task fntion fn final_survivor(n int, kk int) int { // argument validation omitted mut circle := []int{len: n, init: it} k := kk-1 mut ex_pos := 0 for circle.len > 1 { ex_pos = (ex_pos + k) % circle.len circle.delete(ex_pos) } return circle[0] }   // extra fn position(n int...
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...
#J
J
dict=:tolower fread '/tmp/unixdict.txt'
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#Haskell
Haskell
(show . (+1) . read) "1234"
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#HicEst
HicEst
CHARACTER string = "123 -4567.89"   READ( Text=string) a, b WRITE(Text=string) a+1, b+1 ! 124 -4566.89
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 |...
#Factor
Factor
: example ( -- ) readln readln [ string>number ] bi@ [ > [ "A > B" print ] when ] [ < [ "A < B" print ] when ] [ = [ "A = B" print ] when ] 2tri ;  
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
#Racket
Racket
  #lang racket (include "other-file.rkt")  
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
#Raku
Raku
use MyModule;
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
#RapidQ
RapidQ
  $INCLUDE "RAPIDQ.INC"  
http://rosettacode.org/wiki/IBAN
IBAN
This page uses content from Wikipedia. The original article was at IBAN. 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) The   International Bank Account Number (IBAN)   is an internationally agree...
#IS-BASIC
IS-BASIC
100 PROGRAM "IBAN.bas" 110 STRING CO$(1 TO 93)*2 120 NUMERIC LG(1 TO 93) 130 FOR I=1 TO 93 140 READ CO$(I),LG(I) 150 NEXT 160 DO 170 PRINT :PRINT "IBAN code: ":INPUT PROMPT ">":IB$ 180 IF IB$="" THEN EXIT DO 190 IF IBAN(IB$) THEN 200 PRINT "CRC ok." 210 ELSE 220 SET #102:INK 3:PRINT "CRC error.":SE...
http://rosettacode.org/wiki/Humble_numbers
Humble numbers
Humble numbers are positive integers which have   no   prime factors   >   7. Humble numbers are also called   7-smooth numbers,   and sometimes called   highly composite, although this conflicts with another meaning of   highly composite numbers. Another way to express the above is: humble = 2i × 3j × 5k...
#Raku
Raku
sub smooth-numbers (*@list) { cache my \Smooth := gather { my %i = (flat @list) Z=> (Smooth.iterator for ^@list); my %n = (flat @list) Z=> 1 xx *;   loop { take my $n := %n{*}.min;   for @list -> \k { %n{k} = %i{k}.pull-one * k if %n{k} == $n; ...
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 ⋮ ⋮ ⋮ ⋱ ...
#Erlang
Erlang
%% Identity Matrix in Erlang for the Rosetta Code Wiki. %% Implemented by Arjun Sunel   -module(identity_matrix). -export([square_matrix/2 , identity/1]).   square_matrix(Size, Elements) -> [[Elements(Column, Row) || Column <- lists:seq(1, Size)] || Row <- lists:seq(1, Size)].   identity(Size) -> square_matrix(...
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...
#Objeck
Objeck
  bundle Default { class Count { function : Main(args : String[]) ~ Nil { i := 0; do { i->PrintLine(); i += 1; } while(i <> 0); } } }  
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...
#OCaml
OCaml
let () = let i = ref 0 in while true do print_int !i; print_newline (); incr i; done
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.
#Ursa
Ursa
decl file f f.open "filename.txt" while (f.hasnext) out (in string f) endl console end while
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.
#Vala
Vala
int main() { string? s; while((s = stdin.read_line()) != null) { stdout.printf("%s\n", s); } return 0; }
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.
#VBA
VBA
Public Sub test() Dim filesystem As Object, stream As Object, line As String Set filesystem = CreateObject("Scripting.FileSystemObject") Set stream = filesystem.OpenTextFile("D:\test.txt") Do While stream.AtEndOfStream <> True line = stream.ReadLine Debug.Print line Loop stream.C...
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...
#Wren
Wren
var josephus = Fn.new { |n, k, m| if (k <= 0 || m <= 0 || n <= k || n <= m) Fiber.abort("One or more parameters are invalid.") var killed = [] var survived = List.filled(n, 0) for (i in 0...n) survived[i] = i var start = k - 1 while (true) { var end = survived.count - 1 var i = s...
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...
#Java
Java
  import java.io.BufferedReader; import java.io.FileReader;   public class IbeforeE { public static void main(String[] args) { IbeforeE now=new IbeforeE(); String wordlist="unixdict.txt"; if(now.isPlausibleRule(wordlist)) System.out.println("Rule is plausible."); else System.out.println("Rule is not pl...
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#HolyC
HolyC
I8 *s;   s = "10"; s = Str2I64(s) + 1; Print("%d\n", s);   s = "-10"; s = Str2I64(s) + 1; Print("%d\n", s);
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#Hy
Hy
(str (inc (int "123")))
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 |...
#FALSE
FALSE
^^ \$@$@$@$@\ >[\$," is greater than "\$,]? \>[\$," is less than "\$,]? =["characters are equal"]?
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 |...
#Fantom
Fantom
class Main { public static Void main () { try { Env.cur.out.print ("Enter number 1: ").flush num1 := Env.cur.in.readLine.toInt Env.cur.out.print ("Enter number 2: ").flush num2 := Env.cur.in.readLine.toInt   if (num1 < num2) echo ("$num1 is smaller than $num2") ...
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
#Retro
Retro
'filename include
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
#REXX
REXX
/*%INCLUDE member */
http://rosettacode.org/wiki/IBAN
IBAN
This page uses content from Wikipedia. The original article was at IBAN. 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) The   International Bank Account Number (IBAN)   is an internationally agree...
#J
J
NB. delete any blank characters delblk =. #~ ' '&~: NB. rearrange rot =. '00' ,~ 2&}. @: (2&|.) NB. characters -> "digits" dig =. a. {~ (a.i.'0')+i.10 dig =. dig,a. {~ (a.i.'A')+i.26 todig =. dig&i. coded =. [: ". 'x' ,~ delblk @: ": @: todig   NB. calculate check sum cs =: 98 - 97 | coded @: rot @: delblk f.   NB. che...
http://rosettacode.org/wiki/Humble_numbers
Humble numbers
Humble numbers are positive integers which have   no   prime factors   >   7. Humble numbers are also called   7-smooth numbers,   and sometimes called   highly composite, although this conflicts with another meaning of   highly composite numbers. Another way to express the above is: humble = 2i × 3j × 5k...
#REXX
REXX
/*REXX program computes and displays humble numbers, also will display counts of sizes.*/ parse arg n m . /*obtain optional arguments from the CL*/ if n=='' | n=="," then n= 50 /*Not specified? Then use the default.*/ if m=='' | m=="," then m= 60 ...
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 ⋮ ⋮ ⋮ ⋱ ...
#ERRE
ERRE
  PROGRAM IDENTITY   !$DYNAMIC DIM A[0,0]   BEGIN PRINT(CHR$(12);) ! CLS INPUT("Matrix size",N%)  !$DIM A[N%,N%] FOR I%=1 TO N% DO A[I%,I%]=1 END FOR ! print matrix FOR I%=1 TO N% DO FOR J%=1 TO N% DO WRITE("###";A[I%,J%];) END FOR PRINT END FOR END PROGRAM  
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...
#Oforth
Oforth
: integers 1 while( true ) [ dup . 1+ ] ;
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...
#Ol
Ol
  (let loop ((n 1)) (print n) (loop (+ 1 n)))  
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.
#VBScript
VBScript
  filepath = "SPECIFY PATH TO TEXT FILE HERE"   Set objFSO = CreateObject("Scripting.FileSystemObject") Set objInFile = objFSO.OpenTextFile(filepath,1,False,0)   Do Until objInFile.AtEndOfStream line = objInFile.ReadLine WScript.StdOut.WriteLine line Loop   objInFile.Close Set objFSO = Nothing  
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.
#Visual_Basic_.NET
Visual Basic .NET
Sub Consume(ByVal stream As IO.StreamReader) Dim line = stream.ReadLine Do Until line Is Nothing Console.WriteLine(line) line = stream.ReadLine Loop End Sub
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...
#XPL0
XPL0
include c:\cxpl\codes;   func Prisoner(N, K); \Return final surviving prisoner int N, K; \number of prisoners, number to skip int I, J; char A; [A:= Reserve(N); for I:= 0 to N-1 do A(I):= I; I:= 0; repeat I:= I+K-1; \skip to next prisoner I:= rem(I...
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...
#jq
jq
def plausibility_ratio: 2;   # scan/2 produces a stream of matches but the first match of a segment (e.g. cie) # blocks further matches with that segment, and therefore if scan produces "ie", # it was NOT preceded by "c". def dictionary: reduce .[] as $word ( {}; reduce ($word | scan("ie|ei|cie|cei")) as $f...
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#HyperTalk
HyperTalk
put 0 into someVar add 1 to someVar -- without "into [field reference]" the value will appear -- in the message box put someVar -- into cd fld 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 |...
#Fermat
Fermat
Func Compare =  ?a;  ?b; if a=b then !'Equal' fi; if a<b then !'Less than' fi; if a>b then !'Greater than' fi; .;
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
#Ring
Ring
Load 'file.ring'
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
#RPG
RPG
// fully qualified syntax: /include library/file,member   // most sensible; file found on *libl: /include file,member   // shortest one, the same library and file: /include member   // and alternative: /copy library/file,member   //... farther like "include"
http://rosettacode.org/wiki/IBAN
IBAN
This page uses content from Wikipedia. The original article was at IBAN. 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) The   International Bank Account Number (IBAN)   is an internationally agree...
#Java
Java
import java.math.BigInteger; import java.util.*;   public class IBAN { private static final String DEFSTRS = "" + "AL28 AD24 AT20 AZ28 BE16 BH22 BA20 BR29 BG22 " + "HR21 CY28 CZ24 DK18 DO28 EE20 FO18 FI18 FR27 GE22 DE22 GI23 " + "GL18 GT28 HU28 IS26 IE22 IL23 IT27 KZ20 KW30 LV21 ...
http://rosettacode.org/wiki/Humble_numbers
Humble numbers
Humble numbers are positive integers which have   no   prime factors   >   7. Humble numbers are also called   7-smooth numbers,   and sometimes called   highly composite, although this conflicts with another meaning of   highly composite numbers. Another way to express the above is: humble = 2i × 3j × 5k...
#Ring
Ring
  load "stdlib.ring"   limit = 10 numList = []   for n2 = 0 to limit for n3 = 0 to limit for n5 = 0 to limit for n7 = 0 to limit num = pow(2,n2) * pow(3,n3) * pow(5,n5) * pow(7,n7) add(numList,num) next next next next   numList = sort(numLi...
http://rosettacode.org/wiki/Humble_numbers
Humble numbers
Humble numbers are positive integers which have   no   prime factors   >   7. Humble numbers are also called   7-smooth numbers,   and sometimes called   highly composite, although this conflicts with another meaning of   highly composite numbers. Another way to express the above is: humble = 2i × 3j × 5k...
#Ruby
Ruby
def humble?(i) while i % 2 == 0; i /= 2 end while i % 3 == 0; i /= 3 end while i % 5 == 0; i /= 5 end while i % 7 == 0; i /= 7 end i == 1 end   count, num = 0, 0 digits = 10 # max digits for humble numbers limit = 10 ** digits # max numbers to search through humble = Array...
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 ⋮ ⋮ ⋮ ⋱ ...
#Euler_Math_Toolbox
Euler Math Toolbox
  function IdentityMatrix(n) $ X:=zeros(n,n); $ for i=1 to n $ X[i,i]:=1; $ end; $ return X; $endfunction  
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...
#OpenEdge.2FProgress
OpenEdge/Progress
#include <order/interpreter.h>   #define ORDER_PP_DEF_8printloop ORDER_PP_FN( \ 8fn(8N, \ 8do(8print(8to_lit(8N) 8comma 8space), \ 8printloop(8inc(8N)))) )   ORDER_PP( 8printloop(1) )
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...
#Order
Order
#include <order/interpreter.h>   #define ORDER_PP_DEF_8printloop ORDER_PP_FN( \ 8fn(8N, \ 8do(8print(8to_lit(8N) 8comma 8space), \ 8printloop(8inc(8N)))) )   ORDER_PP( 8printloop(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.
#Wren
Wren
import "io" for File   File.open("input.txt") { |file| var offset = 0 var line = "" while(true) { var b = file.readBytes(1, offset) offset = offset + 1 if (b == "\n") { // process 'line' line = "" // reset line variable } else if (b == "\r") { // Windo...
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.
#x86_Assembly
x86 Assembly
#define SYS_WRITE $1 #define SYS_OPEN $2 #define SYS_CLOSE $3 #define SYS_FSTAT $5 #define SYS_MMAP $9 #define SYS_MUNMAP $11 #define SYS_EXIT $60   // From experiments: #define FSIZEOFF 48 #define STATSIZE 144   // From Linux source: #define RDONLY $00 #define PROT_READ $0x1 #define M...
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...
#zkl
zkl
fcn j(n,k){ reg p=[0..n-1].walk().copy(), i=0, seq=L(); while(p){ i=(i+k-1)%p.len(); seq.append(p.pop(i)); } "Prisoner killing order: %s.\nSurvivor: %d" .fmt(seq[0,-1].concat(","),seq[-1]); }
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...
#Julia
Julia
# v0.0.6   open("unixdict.txt") do txtfile rule1, notrule1, rule2, notrule2 = 0, 0, 0, 0 for word in eachline(txtfile) # "I before E when not preceded by C" if ismatch(r"ie"i, word) if ismatch(r"cie"i, word) notrule1 += 1 else rule1 += 1 ...
http://rosettacode.org/wiki/Increment_a_numerical_string
Increment a numerical string
Task Increment a numerical string.
#i
i
software { string = "1" string += 1 print(string) }
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 |...
#Fish
Fish
l2=?vv ~< v o< v <>l?^"Please pre-populate the stack with the two integers."ar>l?^; \$:@@:@)?v v  ;oanv!!!?< >$n" is greater than "{r>ol1=^ / < \$:@@:@=?v v  ;oanv!!!?< >$n" is equal to "{r>ol1=^ / ...
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 |...
#Forth
Forth
: compare-integers ( a b -- ) 2dup < if ." a is less than b" then 2dup > if ." a is greater than b" then = if ." a is equal to b" then ;
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
#Ruby
Ruby
require '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
#Run_BASIC
Run BASIC
run SomeProgram.bas",#include ' this gives it a handle of #include render #include ' render will RUN the program with handle #include
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
#Rust
Rust
mod test;   fn main() { test::some_function(); }
http://rosettacode.org/wiki/IBAN
IBAN
This page uses content from Wikipedia. The original article was at IBAN. 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) The   International Bank Account Number (IBAN)   is an internationally agree...
#JavaScript
JavaScript
var ibanLen = { NO:15, BE:16, DK:18, FI:18, FO:18, GL:18, NL:18, MK:19, SI:19, AT:20, BA:20, EE:20, KZ:20, LT:20, LU:20, CR:21, CH:21, HR:21, LI:21, LV:21, BG:22, BH:22, DE:22, GB:22, GE:22, IE:22, ME:22, RS:22, AE:23, GI:23, IL:23, AD:24, CZ:24, ES:24, MD:24, PK:24, RO:24, SA:24, SE:24, SK:24, VG:24, TN:24, PT:...
http://rosettacode.org/wiki/Humble_numbers
Humble numbers
Humble numbers are positive integers which have   no   prime factors   >   7. Humble numbers are also called   7-smooth numbers,   and sometimes called   highly composite, although this conflicts with another meaning of   highly composite numbers. Another way to express the above is: humble = 2i × 3j × 5k...
#Sidef
Sidef
func smooth_generator(primes) {   var s = primes.len.of { [1] }   { var n = s.map { .first }.min { |i| s[i].shift if (s[i][0] == n) s[i] << (n * primes[i]) } * primes.len n } }   with (smooth_generator([2,3,5,7])) {|g| say 50.of { g.run }.join(' ')...
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 ⋮ ⋮ ⋮ ⋱ ...
#Excel
Excel
IDMATRIX =LAMBDA(n, LET( ixs, SEQUENCE(n, n, 0, 1), x, MOD(ixs, n), y, QUOTIENT(ixs, n),   IF(x = y, 1, 0 ) ) )
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...
#PARI.2FGP
PARI/GP
n=0; while(1,print(++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...
#Pascal
Pascal
Program IntegerSequenceLimited; var Number: QWord = 0; // 8 bytes, unsigned: 0 .. 18446744073709551615 begin repeat writeln(Number); inc(Number); until false; 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.
#XPL0
XPL0
int C; [repeat \read file repeat \read line repeat C:= ChIn(1); \read word ChOut(0, C); until (C<^A ! C>^z) & (C<^0 ! C>^9); \non-alphanumeric until C < $20; \CR, LF, ...
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.
#zkl
zkl
foreach line in (File("foo.txt")){...} List(1,2,3).readln() // here, a "line" is a list element Utils.Helpers.zipWith(False, // enumerate a file fcn(n,line){"%3d: %s".fmt(n,line).print()},[1..],File("cmp.zkl"))