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/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#Rust
Rust
  fn sedol(input: &str) -> Option<String> { let weights = vec![1, 3, 1, 7, 3, 9, 1]; let valid_chars = "0123456789BCDFGHJKLMNPQRSTVWXYZ";   if input.len() != 6 { return None; }   // could be done by regex if needed for c in input.chars() { if !valid_chars.contains(c) { ...
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#Scala
Scala
class SEDOL(s: String) { require(s.size == 6 || s.size == 7, "SEDOL length must be 6 or 7 characters") require(s.size == 6 || s(6).asDigit == chksum, "Incorrect SEDOL checksum") require(s forall (c => !("aeiou" contains c.toLower)), "Vowels not allowed in SEDOL") def chksum = 10 - ((s zip List(1, 3, 1, 7, 3, 9)...
http://rosettacode.org/wiki/Sequence_of_non-squares
Sequence of non-squares
Task Show that the following remarkable formula gives the sequence of non-square natural numbers: n + floor(1/2 + sqrt(n)) Print out the values for   n   in the range   1   to   22 Show that no squares occur for   n   less than one million This is sequence   A000037   in the OEIS database.
#XLISP
XLISP
(defun non-square (n) (+ n (floor (+ 0.5 (sqrt n)))))   (defun range (x y) (if (< x y) (cons x (range (+ x 1) y))))   (defun squarep (x) (= x (expt (floor (sqrt x)) 2)))   (defun count-squares (x y) (define squares 0) (if (squarep (non-square x)) (define squares (+ squares 1))) (...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Python
Python
>>> s1, s2 = {1, 2, 3, 4}, {3, 4, 5, 6} >>> s1 | s2 # Union {1, 2, 3, 4, 5, 6} >>> s1 & s2 # Intersection {3, 4} >>> s1 - s2 # Difference {1, 2} >>> s1 < s1 # True subset False >>> {3, 1} < s1 # True subset True >>> s1 <= s1 # Subset True >>> {3, 1} <= s1 # Subset True >>> {3, 2, 4, 1} == s1 # Equality True >>> s1 == s...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Furor
Furor
  tick sto startingtick #g 100000 sto MAX @MAX mem !maximize sto primeNumbers one count @primeNumbers 0 2 [^] 2 @MAX külső: {|| @count {| {}§külső {} []@primeNumbers !/ else{<}§külső |} // @count vége @primeNumbers @count++ {} [^] |} // @MAX vége @primeNumbers free ."Time : " tick @startingtick - print ." tick\n" ."Prí...
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#Seed7
Seed7
$ include "seed7_05.s7i";   const func char: sedolCheckDigit (in string: sedol) is func result var char: checkDigit is ' '; local const array integer: weight is [] (1, 3, 1, 7, 3, 9); var char: ch is ' '; var integer: index is 0; var integer: item is 0; var integer: sum is 0; begin f...
http://rosettacode.org/wiki/Sequence_of_non-squares
Sequence of non-squares
Task Show that the following remarkable formula gives the sequence of non-square natural numbers: n + floor(1/2 + sqrt(n)) Print out the values for   n   in the range   1   to   22 Show that no squares occur for   n   less than one million This is sequence   A000037   in the OEIS database.
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic 'code' declarations   func real Floor(X); \Truncate X toward - infinity real X; return float(fix(X-0.5));   func PerfectSq(N); \Return 'true' if N is a perfect square int N; return sqrt(N)*sqrt(N) = N;   int N, M, M0; [for N:= 1 to 22 do [IntOu...
http://rosettacode.org/wiki/Sequence_of_non-squares
Sequence of non-squares
Task Show that the following remarkable formula gives the sequence of non-square natural numbers: n + floor(1/2 + sqrt(n)) Print out the values for   n   in the range   1   to   22 Show that no squares occur for   n   less than one million This is sequence   A000037   in the OEIS database.
#Yabasic
Yabasic
// Display first 22 values print "The first 22 numbers generated by the sequence are : " for i = 1 to 22 print nonSquare(i), " "; next i print   // Check for squares up to one million found = false for i = 1 to 1e6 j = sqrt(nonSquare(i)) if j = int(j) then found = true print i, " square num...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Quackery
Quackery
[ [] $ "" rot sort$ witheach [ tuck != if [ dup dip [ nested join ] ] ] drop ] is -duplicates ( { --> { )   [ [] $ "" rot sort$ witheach [ tuck = if [ nested join $ "" ] ] drop -duplicates ] is duplica...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#FutureBasic
FutureBasic
window 1, @"Sieve of Eratosthenes", (0,0,720,300)   begin globals dynamic gPrimes(1) as Boolean end globals   local fn SieveOfEratosthenes( n as long ) long i, j   for i = 2 to n for j = i * i to n step i gPrimes(j) = _true next if gPrimes(i) = 0 then print i, next i kill gPrimes end fn   fn ...
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#Sidef
Sidef
func sedol(s) {   die 'No vowels allowed' if (s ~~ /[AEIOU]/); die 'Invalid format' if (s !~ /^[0-9B-DF-HJ-NP-TV-Z]{6}$/);   const base36 = ((@(0..9) + @('A'..'Z')) ~Z @(0..35) -> flatten.to_h); const weights = [1, 3, 1, 7, 3, 9];   var vs = [base36{ s.chars... }]; var checksum = (vs ~Z* weig...
http://rosettacode.org/wiki/Sequence_of_non-squares
Sequence of non-squares
Task Show that the following remarkable formula gives the sequence of non-square natural numbers: n + floor(1/2 + sqrt(n)) Print out the values for   n   in the range   1   to   22 Show that no squares occur for   n   less than one million This is sequence   A000037   in the OEIS database.
#zkl
zkl
fcn seq(n){n + (0.5+n.toFloat().sqrt()).floor()} [1..22].apply(seq).toString(*).println();   fcn isSquare(n){n.toFloat().sqrt().modf()[1]==0.0} isSquare(25) //-->True isSquare(26) //-->False [2..0d1_000_000].filter(fcn(n){isSquare(seq(n))}).println();
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Racket
Racket
  #lang racket   (define A (set 1 2 3 4)) (define B (set 3 4 5 6)) (define C (set 4 5))   (set-union A B)  ; gives (set 1 2 3 4 5 6) (set-intersect A B) ; gives (set 3 4) (set-subtract A B)  ; gives (set 1 2) (set=? A B)  ; gives #f (subset? C A)  ; gives #f (subset? C B)  ; gives #t  
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#F.C5.8Drmul.C3.A6
Fōrmulæ
Eratosthenes := function(n) local a, i, j; a := ListWithIdenticalEntries(n, true); if n < 2 then return []; else for i in [2 .. n] do if a[i] then j := i*i; if j > n then return Filtered([2 .. n], i -> a[i]); ...
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#Smalltalk
Smalltalk
String extend [ includesAnyOf: aSet [ aSet do: [ :e | (self includes: e) ifTrue: [ ^true ] ]. ^false ] ].
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#SQL_PL
SQL PL
  --#SET TERMINATOR @   SET SERVEROUTPUT ON@   CREATE OR REPLACE FUNCTION CHECK_SEDOL ( IN TEXT VARCHAR(6) ) RETURNS VARCHAR(7) BEGIN DECLARE TYPE SEDOL AS CHAR(1) ARRAY [6]; --declare text varchar(6) default 'B12345'; DECLARE WEIGHT SEDOL; DECLARE I SMALLINT; DECLARE SENTENCE VARCHAR(256); DECLARE CHAR...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Raku
Raku
use Test;   my $a = set <a b c>; my $b = set <b c d>; my $c = set <a b c d e>;   ok 'c' ∈ $a, "c is an element in set A"; nok 'd' ∈ $a, "d is not an element in set A";   is-deeply $a ∪ $b, set(<a b c d>), "union; a set of all elements either in set A or in set B"; is-deeply $a ∩ $b, set(<b c>), "intersection; a set of ...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#GAP
GAP
Eratosthenes := function(n) local a, i, j; a := ListWithIdenticalEntries(n, true); if n < 2 then return []; else for i in [2 .. n] do if a[i] then j := i*i; if j > n then return Filtered([2 .. n], i -> a[i]); ...
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#Standard_ML
Standard ML
fun char2value c = if List.exists (fn x => x = c) (explode "AEIOU") then raise Fail "no vowels" else if Char.isDigit c then ord c - ord #"0" else if Char.isUpper c then ord c - ord #"A" + 10 else raise Match   val sedolweight = [1,3,1,7,3,9]   fun checksum sedol = let val tmp = ListPair.foldlEq (fn (ch, weigh...
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#Tcl
Tcl
namespace eval sedol { variable chars {0 1 2 3 4 5 6 7 8 9 "" B C D "" F G H "" J K L M N "" P Q R S T "" V W X Y Z} variable weight {1 3 1 7 3 9 1}   proc checksum {alnum6} { variable chars variable weight set sum 0 set col 0 foreach char [split [string toupper [stri...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#REXX
REXX
/*REXX program demonstrates some common SET functions. */ truth.0= 'false'; truth.1= "true" /*two common names for a truth table. */ set.= /*the order of sets isn't important. */   call setAdd 'prime',2 3 2 5 7 11 13 17 19 23 ...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#GLBasic
GLBasic
// Sieve of Eratosthenes (find primes) // GLBasic implementation     GLOBAL n%, k%, limit%, flags%[]   limit = 100 // search primes up to this number   DIM flags[limit+1] // GLBasic arrays start at 0   FOR n = 2 TO SQR(limit) IF flags[n] = 0 FOR k = n*n TO limit STEP n flags[k] = 1 NE...
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#Transact-SQL
Transact-SQL
CREATE FUNCTION [dbo].[fn_CheckSEDOL] ( @SEDOL varchar(50) ) RETURNS varchar(7) AS BEGIN declare @true bit = 1, @false bit = 0, @isSEDOL bit, @sedol_weights varchar(6) ='131739', @sedol_len int = LEN(@SEDOL), @sum int = 0     if ((@sedol_len = 6)) begin select @SEDOL = UPPER(@SEDOL) Declare @vowels ...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Ring
Ring
  # Project : Set   arr = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape"] for n = 1 to 25 add(arr,"") next seta = "1010101" see "Set A: " + arrset(arr,seta) + nl setb = "0111110" see "Set B: " + arrset(arr,setb) + nl elementm = "0000010" see "Element M: " + arrset(arr,elementm) + nl   temp = a...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Go
Go
package main import "fmt"   func main() { const limit = 201 // means sieve numbers < 201   // sieve c := make([]bool, limit) // c for composite. false means prime candidate c[1] = true // 1 not considered prime p := 2 for { // first allowed optimization: outer loop only go...
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT check="1'3'1'7'3'9" values="123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" value=STRINGS (values,":<%:") BUILD r_TABLE/or illegal=":A:E:I:O:U:" LOOP input="710889'B0YBKJ'406566'B0YBLH'228276'B0YBKL'557910'B0YBKR'585284'B0YBKT'BOYAKT'B00030",sum="" IF (input.ma.illegal) THEN PRINT/ERROR input, " illegal" ...
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#Ursala
Ursala
#import std #import nat   alphabet = digits-- ~=`A-~r letters weights = <1,3,1,7,3,9> charval = -:@rlXS num alphabet iprod = sum:-0+ product*p/weights+ charval* checksum = difference/10+ remainder\10+ iprod
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Ruby
Ruby
>> require 'set' => true >> s1, s2 = Set[1, 2, 3, 4], [3, 4, 5, 6].to_set # different ways of creating a set => [#<Set: {1, 2, 3, 4}>, #<Set: {5, 6, 3, 4}>] >> s1 | s2 # Union => #<Set: {5, 6, 1, 2, 3, 4}> >> s1 & s2 # Intersection => #<Set: {3, 4}> >> s1 - s2 # Difference => #<Set: {1, 2}> >> s1.proper_subset?(s1) # P...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Groovy
Groovy
def sievePrimes = { bound -> def isPrime = new BitSet(bound) isPrime[0..1] = false isPrime[2..bound] = true (2..(Math.sqrt(bound))).each { pc -> if (isPrime[pc]) { ((pc**2)..bound).step(pc) { isPrime[it] = false } } } (0..bound).findAll { isPrime[it] } }
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#VBA
VBA
Function getSedolCheckDigit(Input1) Dim mult(6) As Integer mult(1) = 1: mult(2) = 3: mult(3) = 1 mult(4) = 7: mult(5) = 3: mult(6) = 9 If Len(Input1) <> 6 Then getSedolCheckDigit = "Six chars only please" Exit Function End If Input1 = UCase(Input1) Total = 0 For i = 1 To ...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Run_BASIC
Run BASIC
  A$ = "apple cherry elderberry grape" B$ = "banana cherry date elderberry fig" C$ = "apple cherry elderberry grape orange" D$ = "apple cherry elderberry grape" E$ = "apple cherry elderberry" M$ = "banana"   print "A = ";A$ print "B = ";B$ print "C = ";C$ print "D = ";D$ print "E = ";E$ print "M = ";M$   if instr(A$,M...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#GW-BASIC
GW-BASIC
10 INPUT "ENTER NUMBER TO SEARCH TO: ";LIMIT 20 DIM FLAGS(LIMIT) 30 FOR N = 2 TO SQR (LIMIT) 40 IF FLAGS(N) < > 0 GOTO 80 50 FOR K = N * N TO LIMIT STEP N 60 FLAGS(K) = 1 70 NEXT K 80 NEXT N 90 REM DISPLAY THE PRIMES 100 FOR N = 2 TO LIMIT 110 IF FLAGS(N) = 0 THEN PRINT N;", "; 120 NEXT N
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#VBScript
VBScript
  arr = Array("710889",_ "B0YBKJ",_ "406566",_ "B0YBLH",_ "228276",_ "B0YBKL",_ "557910",_ "B0YBKR",_ "585284",_ "B0YBKT",_ "12345",_ "A12345",_ "B00030")   For j = 0 To UBound(arr) WScript.StdOut.Write arr(j) & getSEDOLCheckDigit(arr(j)) WScri...
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#Visual_FoxPro
Visual FoxPro
  #DEFINE ALPHABET "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #DEFINE VOWELS "AEIOU" #DEFINE VALIDCHARS "0123456789" + ALPHABET LOCAL cMsg As String, cCode As String LOCAL ARRAY codes[12] codes[1] = "710889" codes[2] = "B0YBKJ" codes[3] = "406566" codes[4] = "B0YBLH" codes[5] = "228276" codes[6] = "B0YBKL" codes[7] = "557910" codes...
http://rosettacode.org/wiki/Search_in_paragraph%27s_text
Search in paragraph's text
The goal is to verify the presence of a word or regular expression within several paragraphs of text (structured or not) and to format the output of the relevant paragraphs before putting them on the standard output. So here, let’s imagine that we are trying to verify the presence of a keyword "SystemError" within wha...
#AWK
AWK
  awk 'BEGIN { RS = "" ; ORS = "\n----------------\n" } /Traceback/ && /SystemError/ { print substr($0,index($0,"Traceback")) }' Traceback.txt  
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Rust
Rust
use std::collections::HashSet;   fn main() { let a = vec![1, 3, 4].into_iter().collect::<HashSet<i32>>(); let b = vec![3, 5, 6].into_iter().collect::<HashSet<i32>>();   println!("Set A: {:?}", a.iter().collect::<Vec<_>>()); println!("Set B: {:?}", b.iter().collect::<Vec<_>>()); println!("Does A contain 4? {}"...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Haskell
Haskell
{-# LANGUAGE FlexibleContexts #-} -- too lazy to write contexts... {-# OPTIONS_GHC -O2 #-}   import Control.Monad.ST ( runST, ST ) import Data.Array.Base ( MArray(newArray, unsafeRead, unsafeWrite), IArray(unsafeAt), STUArray, unsafeFreezeSTUArray, assocs ) import Data....
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#Wren
Wren
import "/str" for Char import "/fmt" for Conv   var sedol = Fn.new { |s| if (!(s is String && s.count == 6)) return false var weights = [1, 3, 1, 7, 3, 9] var sum = 0 for (i in 0..5) { var c = s[i] if (!Char.isUpper(c) && !Char.isDigit(c)) return null if ("AEIOU".contains(c)) ret...
http://rosettacode.org/wiki/Search_in_paragraph%27s_text
Search in paragraph's text
The goal is to verify the presence of a word or regular expression within several paragraphs of text (structured or not) and to format the output of the relevant paragraphs before putting them on the standard output. So here, let’s imagine that we are trying to verify the presence of a keyword "SystemError" within wha...
#J
J
NB. read file, separate on blank lines paragraphs=: ((LF,LF)&E. <;.2 ])fread 'traceback.txt'   NB. ignore text preceding 'Traceback (most recent call last)' cleaned=: {{y}.~{.I.'Traceback (most recent call last)'&E.y}}each paragraphs   NB. limit to paragraphs containing 'SystemError' searched=: (#~ (1 e.'SystemError'&...
http://rosettacode.org/wiki/Search_in_paragraph%27s_text
Search in paragraph's text
The goal is to verify the presence of a word or regular expression within several paragraphs of text (structured or not) and to format the output of the relevant paragraphs before putting them on the standard output. So here, let’s imagine that we are trying to verify the presence of a keyword "SystemError" within wha...
#jq
jq
def p1: "Traceback (most recent call last):"; def p2: "SystemError"; def sep: "----------------";   split("\n\n")[] | index(p1) as $ix | select( $ix and index(p2) ) | .[$ix:], sep
http://rosettacode.org/wiki/Search_in_paragraph%27s_text
Search in paragraph's text
The goal is to verify the presence of a word or regular expression within several paragraphs of text (structured or not) and to format the output of the relevant paragraphs before putting them on the standard output. So here, let’s imagine that we are trying to verify the presence of a keyword "SystemError" within wha...
#Julia
Julia
const filename = "traceback.txt" const pmarker, target = "Traceback (most recent call last):", "SystemError"   foreach( p -> println(p, p[end] == '\n' ? "" : "\n", "-"^16), [ p[findfirst(pmarker, p).start:end] for p in split(read(filename, String), r"\r?\n\r?\n") if contains(p, pmarker) ...
http://rosettacode.org/wiki/Search_in_paragraph%27s_text
Search in paragraph's text
The goal is to verify the presence of a word or regular expression within several paragraphs of text (structured or not) and to format the output of the relevant paragraphs before putting them on the standard output. So here, let’s imagine that we are trying to verify the presence of a keyword "SystemError" within wha...
#Phix
Phix
with javascript_semantics --constant text = get_text("Traceback.txt") -- (not js!) constant text = """ 2018-06-19 23:19:34,877 ERROR Processes plugin raised an exception. <snip> }""", paras = split(text,"\n\n"), tmrcl = "Traceback (most recent call last)" for i=1 to length(paras) do string para = paras[i] i...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Scala
Scala
  object sets { val set1 = Set(1,2,3,4,5) val set2 = Set(3,5,7,9) println(set1 contains 3) println(set1 | set2) println(set1 & set2) println(set1 diff set2) println(set1 subsetOf set2) println(set1 == set2) }  
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#HicEst
HicEst
REAL :: N=100, sieve(N)   sieve = $ > 1 ! = 0 1 1 1 1 ... DO i = 1, N^0.5 IF( sieve(i) ) THEN DO j = i^2, N, i sieve(j) = 0 ENDDO ENDIF ENDDO   DO i = 1, N IF( sieve(i) ) WRITE() i ENDDO
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#XPL0
XPL0
string 0; \use zero-terminated strings   func CheckDigit(Str); \Return the check digit for a SEDOL char Str; int Sum, I, C, V; [Sum:= 0; for I:= 0 to 6-1 do [C:= Str(I); case of C>=^0 & C<=^9: V:= C-^0; C>=^A & C<=^Z: V:= C-^A+10 other V:= -1; case I of 1, 4: V:= V*3;...
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#Yabasic
Yabasic
data "710889", "B0YBKJ", "406566", "B0YBLH", "228276", "B0YBKL", "557910", "B0YBKR", "585284", "B0YBKT", "B00030", "AB", "B00A03", ""   do read d$ if d$ = "" break print sedol$(d$) loop   sub sedol$(d$) LOCAL a, i, s, weights$(1)   a = len(d$) if a < 6 or a > 6 return d$ + ": Error in length"   ...
http://rosettacode.org/wiki/Search_in_paragraph%27s_text
Search in paragraph's text
The goal is to verify the presence of a word or regular expression within several paragraphs of text (structured or not) and to format the output of the relevant paragraphs before putting them on the standard output. So here, let’s imagine that we are trying to verify the presence of a keyword "SystemError" within wha...
#Python
Python
  with open('Traceback.txt', 'r' ) as f: rawText = f.read()   paragraphs = rawText.split( "\n\n" )   for p in paragraphs: if "SystemError" in p:   index = p.find( "Traceback (most recent call last):" )   if -1 != index: print( p[index:] ) print( "----------------" )  
http://rosettacode.org/wiki/Search_in_paragraph%27s_text
Search in paragraph's text
The goal is to verify the presence of a word or regular expression within several paragraphs of text (structured or not) and to format the output of the relevant paragraphs before putting them on the standard output. So here, let’s imagine that we are trying to verify the presence of a keyword "SystemError" within wha...
#Raku
Raku
unit sub MAIN ( :$for, :$at = 0 );   put slurp.split( /\n\n+/ ).grep( { .contains: $for } ) .map( { .substr: .index: $at } ) .join: "\n----------------\n"
http://rosettacode.org/wiki/Search_in_paragraph%27s_text
Search in paragraph's text
The goal is to verify the presence of a word or regular expression within several paragraphs of text (structured or not) and to format the output of the relevant paragraphs before putting them on the standard output. So here, let’s imagine that we are trying to verify the presence of a keyword "SystemError" within wha...
#Wren
Wren
import "io" for File import "./pattern" for Pattern   var fileName = "Traceback.txt" var p1 = Pattern.new("Traceback (most recent call last):") var p2 = Pattern.new("SystemError") var sep = "----------------"   File.read(fileName) .split("\n\n") .where { |para| p1.isMatch(para) && p2.isMatch(para) } .each {...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Scheme
Scheme
(define (element? a lst) (and (not (null? lst)) (or (eq? a (car lst)) (element? a (cdr lst)))))   ; util, not strictly needed (define (uniq lst) (if (null? lst) lst (let ((a (car lst)) (b (cdr lst))) (if (element? a b) (uniq b) (cons a (uniq b))))))   (define (intersection a b) (cond ((null...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Hoon
Hoon
:: Find primes by the sieve of Eratosthenes !: |= end=@ud =/ index 2 =/ primes `(list @ud)`(gulf 1 end) |- ^- (list @ud) ?: (gte index (lent primes)) primes $(index +(index), primes +:(skid primes |=([a=@ud] &((gth a index) =(0 (mod a index))))))  
http://rosettacode.org/wiki/SEDOLs
SEDOLs
Task For each number list of 6-digit SEDOLs, calculate and append the checksum digit. That is, given this input: 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT B00030 Produce this output: 7108899 B0YBKJ7 4065663 B0YBLH2 2282765 B0YBKL9 5579107 B0YBKR5 5852842 B0YBKT7 B000300 Extra credit ...
#zkl
zkl
fcn checksum(text){ ( text.len()!=6 or (text..matches("*[AEIOUaeioua-z]*")) ) and throw(Exception.ValueError("Invalid SEDOL text: "+text));   text + (10 - text.pump(List,'wrap(c){ if("0"<=c<="9") c.toAsc()-0x30; else c.toAsc()-55; }).zipWith('*,T(1,3,1,7,3,9)).sum() % 1...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Seed7
Seed7
$ include "seed7_05.s7i";   const type: charSet is set of char; enable_output(charSet);   const proc: main is func local const charSet: A is {'A', 'B', 'C', 'D', 'E', 'F'}; var charSet: B is charSet.value; var char: m is 'A'; begin B := {'E', 'F', 'G', 'H', 'I', 'K'}; incl(B, 'J'); # Add ...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Icon_and_Unicon
Icon and Unicon
procedure main() sieve(100) end   procedure sieve(n) local p,i,j p:=list(n, 1) every i:=2 to sqrt(n) & j:= i+i to n by i & p[i] == 1 do p[j] := 0 every write(i:=2 to n & p[i] == 1 & i) end
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#SETL
SETL
  A := {1, 2, 3, 4}; B := {3, 4, 5, 6}; C := {4, 5};   -- Union, Intersection, Difference, Subset, Equality print(A + B); -- {1, 2, 3, 4, 5, 6} print(A * B); -- {3, 4} print(A - B); -- {1, 2} print(C subset B); -- #T print(C = B); -- #F  
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#J
J
10|13 3
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Sidef
Sidef
class MySet(*set) {   method init { var elems = set set = Hash() elems.each { |e| self += e } }   method +(elem) { set{elem} = elem self }   method del(elem) { set.delete(elem) }   method has(elem) { set.has_key(elem) }   method...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Janet
Janet
(defn primes-before "Gives all the primes < limit" [limit] (assert (int? limit)) # Janet has a buffer type (mutable string) which has easy methods for use as bitset (def buf-size (math/ceil (/ limit 8))) (def is-prime (buffer/new-filled buf-size (bnot 0))) (print "Size" buf-size "is-prime: " is-prime) (...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Simula
Simula
SIMSET BEGIN    ! WE DON'T SUBCLASS HEAD BUT USE COMPOSITION FOR CLASS SET ; CLASS SET; BEGIN PROCEDURE ADD(E); REF(ELEMENT) E; BEGIN IF NOT ISIN(E, THIS SET) THEN E.CLONE.INTO(H); END**OF**ADD;   BOOLEAN PROCEDURE EMPTY; EMPTY := H.EMPTY; REF(LINK) PROCEDU...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Java
Java
import java.util.LinkedList;   public class Sieve{ public static LinkedList<Integer> sieve(int n){ if(n < 2) return new LinkedList<Integer>(); LinkedList<Integer> primes = new LinkedList<Integer>(); LinkedList<Integer> nums = new LinkedList<Integer>();   ...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Smalltalk
Smalltalk
  #(1 2 3) asSet union: #(2 3 4) asSet. "a Set(1 2 3 4)"   #(1 2 3) asSet intersection: #(2 3 4) asSet. "a Set(2 3)"   #(1 2 3) asSet difference: #(2 3 4) asSet. "a Set(1)"   #(1 2 3) asSet includesAllOf: #(1 3) asSet. "true"   #(1 2 3) asSet includesAllOf: #(1 3 4) asSet. "false"   #(1 2 3) asSet = #(2 1 3) ...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#JavaScript
JavaScript
function eratosthenes(limit) { var primes = []; if (limit >= 2) { var sqrtlmt = Math.sqrt(limit) - 2; var nums = new Array(); // start with an empty Array... for (var i = 2; i <= limit; i++) // and nums.push(i); // only initialize the Array once... for (var i = 0; i <...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#SQL
SQL
  -- set of numbers is a table -- create one set with 3 elements   CREATE TABLE myset1 (element NUMBER);   INSERT INTO myset1 VALUES (1); INSERT INTO myset1 VALUES (2); INSERT INTO myset1 VALUES (3);   commit;   -- check if 1 is an element   SELECT 'TRUE' BOOL FROM dual WHERE 1 IN (SELECT element FROM myset1);   -- cr...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#JOVIAL
JOVIAL
  START FILE MYOUTPUT ... $ ''Insufficient information to complete this declaration'' PROC SIEVEE $ '' define the sieve data structure '' ARRAY CANDIDATES 1000 B $ FOR I =0,1,999 $ BEGIN '' everything is potentially prime until proven otherwise '' CANDIDATES($I$) = 1$ END '' Neit...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Swift
Swift
var s1 : Set<Int> = [1, 2, 3, 4] let s2 : Set<Int> = [3, 4, 5, 6] println(s1.union(s2)) // union; prints "[5, 6, 2, 3, 1, 4]" println(s1.intersect(s2)) // intersection; prints "[3, 4]" println(s1.subtract(s2)) // difference; prints "[2, 1]" println(s1.isSubsetOf(s1)) // subset; prints "true" println(Set<Int>([3, 1]).is...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#11l
11l
V x = ‘From global scope’   F outerfunc() V x = ‘From scope at outerfunc’   F scoped_local() V x = ‘scope local’ R ‘scoped_local scope gives x = ’x print(scoped_local())   F scoped_nonlocal() R ‘scoped_nonlocal scope gives x = ’@x print(scoped_nonlocal())   F scoped_global() R ...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#jq
jq
# Denoting the input by $n, which is assumed to be a positive integer, # eratosthenes/0 produces an array of primes less than or equal to $n: def eratosthenes:   # erase(i) sets .[i*j] to false for integral j > 1 def erase(i): if .[i] then reduce range(2; (1 + length) / i) as $j (.; .[i * $j] = false) else ...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Tcl
Tcl
package require struct::set   # Many ways to build sets set s1 [list 1 2 3 4] set s2 {3 4 5 6} struct::set add s3 {2 3 4 3 2}; # $s3 will be proper set... set item 5   puts "union: [struct::set union $s1 $s2]" puts "intersection: [struct::set intersect $s1 $s2]" puts "difference: [struct::set difference $s1 $s2]" put...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#6502_Assembly
6502 Assembly
macro LDIR,source,dest,count ;LoaD, Increment, Repeat lda #<source sta $00 lda #>source sta $01   lda #<dest sta $02 lda #>dest sta $03   ldx count ldy #0 \@:  ;this is a local label   lda ($00),y ;load a byte from the source address sta ($02),y ;store in destination address iny  ;increment dex bne \@ ...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Ada
Ada
package P is ... -- Declarations placed here are publicly visible private ... -- These declarations are visible only to the children of P end P;
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#ALGOL_60
ALGOL 60
singleton = "global variable"   assume_global() { Global ; assume all variables declared in this function are global in scope Static callcount := 0 ; except this one declared static, initialized once only MsgBox % singleton ; usefull to initialize a bunch of singletons callcount++ }   assume_global2() { ...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Ada
Ada
with Ada.Text_Io; use Ada.Text_Io;   procedure Temp_File is Temp : File_Type; Contents : String(1..80); Length : Natural; begin -- Create a temporary file Create(File => Temp); Put_Line(File => Temp, Item => "Hello World"); Reset(File => Temp, Mode => In_File); Get_Line(File => Temp, Item => Con...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Julia
Julia
# Returns an array of positive prime numbers less than or equal to lim function sieve(lim :: Int) if lim < 2 return [] end limi :: Int = (lim - 1) ÷ 2 # calculate the required array size isprime :: Array{Bool} = trues(limi) llimi :: Int = (isqrt(lim) - 1) ÷ 2 # and calculate maximum root prime index ...
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#VBA
VBA
'Implementation of "set" using the built in Collection datatype. 'A collection can hold any object as item. The examples here are only strings. 'A collection stores item, key pairs. With the key you can retrieve the item. 'The keys are hidden and cannot be changed. No duplicate keys are allowed. 'For the "set" implemen...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#ALGOL_68
ALGOL 68
singleton = "global variable"   assume_global() { Global ; assume all variables declared in this function are global in scope Static callcount := 0 ; except this one declared static, initialized once only MsgBox % singleton ; usefull to initialize a bunch of singletons callcount++ }   assume_global2() { ...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#ALGOL_W
ALGOL W
singleton = "global variable"   assume_global() { Global ; assume all variables declared in this function are global in scope Static callcount := 0 ; except this one declared static, initialized once only MsgBox % singleton ; usefull to initialize a bunch of singletons callcount++ }   assume_global2() { ...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#BBC_BASIC
BBC BASIC
file% = FNopentempfile IF file% = 0 ERROR 100, "Failed to open temp file" PRINT #file%, "Hello world!" PTR#file% = 0 INPUT #file%, message$ CLOSE #file% PRINT message$ END   DEF FNopentempfile LOCAL pname%, hfile%, chan% OPEN_EXISTING = 3 FILE_FLAG...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#C
C
#include <stdlib.h> #include <stdio.h>   int main(void) { FILE *fh = tmpfile(); /* file is automatically deleted when program exits */ /* do stuff with stream "fh" */ fclose(fh); /* The C standard library also has a tmpnam() function to create a file for you to open later. But you should not use it because ...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#C.23
C#
using System; using System.IO;   Console.WriteLine(Path.GetTempFileName());
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Klingphix
Klingphix
include ..\Utilitys.tlhy   %limit %i 1000 !limit ( 1 $limit ) sequence   ( 2 $limit sqrt int ) [ !i $i get [ ( 2 $limit 1 - $i / int ) [ $i * false swap set ] for ] if ] for ( 1 $limit false ) remove pstack   "Press ENTER to end " input
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#Wren
Wren
import "/set" for Set   var fruits = Set.new(["apple", "pear", "orange", "banana"]) System.print("fruits  : %(fruits)") var fruits2 = Set.new(["melon", "orange", "lemon", "gooseberry"]) System.print("fruits2 : %(fruits2)\n")   System.print("fruits contains 'banana'  : %(fruits.contains("banana"))") System.print("fr...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#AutoHotkey
AutoHotkey
singleton = "global variable"   assume_global() { Global ; assume all variables declared in this function are global in scope Static callcount := 0 ; except this one declared static, initialized once only MsgBox % singleton ; usefull to initialize a bunch of singletons callcount++ }   assume_global2() { ...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Axe
Axe
10 X = 1 20 DEF FN F(X) = X 30 DEF FN G(N) = X 40 PRINT FN F(2) 50 PRINT FN G(3)
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Clojure
Clojure
(let [temp-file (java.io.File/createTempFile "pre" ".suff")] ; insert logic here that would use temp-file (.delete temp-file))
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#D
D
module tempfile ; import tango.io.TempFile, tango.io.Stdout ;   void main(char[][] args) {   // create a temporary file that will be deleted automatically when out of scope auto tempTransient = new TempFile(TempFile.Transient) ; Stdout(tempTransient.path()).newline ;   // create a temporary file, still persist ...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Delphi
Delphi
  program Secure_temporary_file;   {$APPTYPE CONSOLE}   uses System.SysUtils, System.IOUtils;   var FileName, buf: string;   begin FileName := TPath.GetTempFileName; with TFile.Open(FileName, TFileMode.fmCreate, TFileAccess.faReadWrite, Tfileshare.fsNone) do begin buf := 'This is a exclusive temp fi...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Kotlin
Kotlin
import kotlin.math.sqrt   fun sieve(max: Int): List<Int> { val xs = (2..max).toMutableList() val limit = sqrt(max.toDouble()).toInt() for (x in 2..limit) xs -= x * x..max step x return xs }   fun main(args: Array<String>) { println(sieve(100)) }
http://rosettacode.org/wiki/Set
Set
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A   set  is a collection of elements, without duplicates and without order. Task Show each of these set operations: Set creation Test m ∈ S -- "m is an...
#zkl
zkl
var [const] unique = Utils.Helpers.listUnique; class Set { fcn init { var [const] set = (vm.arglist.copy() : unique(_)) } fcn holds(x) { set.holds(x) } fcn union(setB) { self(set.xplode(),setB.set.xplode()) } fcn intersection(setB){ sb:=setB.set; C:=self(); sc:=C.set; foreach x in (set){ if (sb....
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#BASIC
BASIC
10 X = 1 20 DEF FN F(X) = X 30 DEF FN G(N) = X 40 PRINT FN F(2) 50 PRINT FN G(3)
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#bc
bc
define g(a) { auto b   b = 3   "Inside g: a = "; a "Inside g: b = "; b "Inside g: c = "; c "Inside g: d = "; d   a = 3; b = 3; c = 3; d = 3 }   define f(a) { auto b, c   b = 2; c = 2 "Inside f (before call): a = "; a "Inside f (before call): b = "; b "Inside f (before cal...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Emacs_Lisp
Emacs Lisp
(make-temp-file "prefix") ;; => "/tmp/prefix25452LPe"
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Fortran
Fortran
OPEN (F,STATUS = 'SCRATCH') !Temporary disc storage.
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Go
Go
package main   import ( "fmt" "io/ioutil" "log" "os" )   func main() { f, err := ioutil.TempFile("", "foo") if err != nil { log.Fatal(err) } defer f.Close()   // We need to make sure we remove the file // once it is no longer needed. defer os.Remove(f.Name())   // … use the file via 'f' … fmt.Fprintln(f,...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Lambdatalk
Lambdatalk
  {def sieve   {def sieve.rec2 {lambda {:a :n :i :k} {if {< :k :n} then {sieve.rec2 {A.set! :k 0 :a} :n :i {+ :k :i}} else :a}}}   {def sieve.rec1 {lambda {:a :n :i} {if {< :i {sqrt :n}} then {sieve.rec1 {if {= {A.get :i :a} 1} then {sieve.rec2 :a :n :i {* :i :i}} ...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Bracmat
Bracmat
67:?x {x has global scope} & 77:?y { y has global scope } & ( double = .  !y+!y { y refers to the variable declared in myFunc, which shadows the global variable with the same name } ) & ( myFunc = y,z { y and z have dynamic scope. z is never used. } ...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#C
C
int a; // a is global static int p; // p is "locale" and can be seen only from file1.c   extern float v; // a global declared somewhere else   // a "global" function int code(int arg) { int myp; // 1) this can be seen only from inside code // 2) In recursive code this variable will...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#C.23
C#
public //visible to anything. protected //visible to current class and to derived classes. internal //visible to anything inside the same assembly (.dll/.exe). protected internal //visible to anything inside the same assembly and also to derived classes outside the assembly. private //visible only to the current class....
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Groovy
Groovy
def file = File.createTempFile( "xxx", ".txt" )   // There is no requirement in the instructions to delete the file. //file.deleteOnExit()   println file
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Haskell
Haskell
import System.IO   main = do (pathOfTempFile, h) <- openTempFile "." "prefix.suffix" -- first argument is path to directory where you want to put it -- do stuff with it here; "h" is the Handle to the opened file return ()
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#HicEst
HicEst
! The "scratch" option opens a file exclusively for the current process. ! A scratch file is automatically deleted upon process termination.   OPEN( FIle='TemporaryAndExclusive', SCRatch, IOStat=ErrNr) WRITE(FIle='TemporaryAndExclusive') "something" WRITE(FIle='TemporaryAndExclusive', CLoSe=1) ! explicit "close" delete...