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/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Wren
Wren
var sumSquares = Fn.new { |v| v.reduce(0) { |sum, n| sum + n * n } }   var v = [1, 2, 3, -1, -2, -3] System.print("Vector  : %(v)") System.print("Sum of squares : %(sumSquares.call(v))")
http://rosettacode.org/wiki/Substring
Substring
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 |...
#newLISP
newLISP
> (set 'str "alphabet" 'n 2 'm 4) 4 > ; starting from n characters in and of m length > (slice str n m) "phab" > ; starting from n characters in, up to the end of the string > (slice str n) "phabet" > ; whole string minus last character > (chop str) "alphabe" > ; starting from a known character within the string and of...
http://rosettacode.org/wiki/Sudoku
Sudoku
Task Solve a partially filled-in normal   9x9   Sudoku grid   and display the result in a human-readable format. references Algorithmics of Sudoku   may help implement this. Python Sudoku Solver Computerphile video.
#Swift
Swift
import Foundation   typealias SodukuPuzzle = [[Int]]   class Soduku { let mBoardSize:Int! let mBoxSize:Int! var mBoard:SodukuPuzzle! var mRowSubset:[[Bool]]! var mColSubset:[[Bool]]! var mBoxSubset:[[Bool]]!   init(board:SodukuPuzzle) { mBoard = board mBoardSize = board.count...
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#TorqueScript
TorqueScript
 %string = "Moo";  %string = getSubStr(%string, 1, strLen(%string) - 1); echo(%string);
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT str="upraisers" str1=EXTRACT (str,2,0) str2=EXTRACT (str,0,-1) str3=EXTRACT (str,2,-1) PRINT str PRINT str1 PRINT str2 PRINT str3  
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Ruby
Ruby
arr = [1,2,3,4,5] # or ary = *1..5, or ary = (1..5).to_a p sum = arr.inject(0) { |sum, item| sum + item } # => 15 p product = arr.inject(1) { |prod, element| prod * element } # => 120
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Run_BASIC
Run BASIC
dim array(100) for i = 1 To 100 array(i) = rnd(0) * 100 next i   product = 1 for i = 0 To 19 sum = (sum + array(i)) product = (product * array(i)) next i   Print " Sum is ";sum Print "Product is ";product
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#OCaml
OCaml
let sum a b fn = let result = ref 0. in for i = a to b do result := !result +. fn i done; !result
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Octave
Octave
sum(1 ./ [1:1000] .^ 2)
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#Tcl
Tcl
proc stripchars {str chars} { foreach c [split $chars ""] {set str [string map [list $c ""] $str]} return $str }   set s "She was a soul stripper. She took my heart!" puts [stripchars $s "aei"]
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#TorqueScript
TorqueScript
$string = "She was a soul stripper. She took my heart!"; $chars = "aei"; $newString = stripChars($string, $chars); echo($string); echo($newString);
http://rosettacode.org/wiki/String_comparison
String 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 |...
#SNOBOL4
SNOBOL4
s1 = 'mnopqrs' s2 = 'mnopqrs' s3 = 'mnopqr' s4 = 'nop' s5 = 'nOp'   OUTPUT = 'Case sensitive comparisons:' OUTPUT = LEQ(s1, s2) s1 ' and ' s2 ' are equal (LEQ).' OUTPUT = IDENT(s1, s2) s1 ' and ' s2 ' are equal (IDENT).'   OUTPUT = OUTPUT = LNE(s1, s3) s1 ' an...
http://rosettacode.org/wiki/String_comparison
String 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 |...
#Standard_ML
Standard ML
map String.compare [ ("one","one"), ("one","two"), ("one","Two"), ("one",String.map Char.toLower "Two") ] ;   val it = [EQUAL, LESS, GREATER, LESS]: order list   "one" <> "two" ; val it = true: bool  
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#NewLISP
NewLISP
  (upper-case "alphaBETA") (lower-case "alphaBETA")  
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#Nial
Nial
toupper 'alphaBETA' =ALPHABETA tolower 'alphaBETA' =alphabeta
http://rosettacode.org/wiki/String_matching
String matching
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 |...
#MATLAB_.2F_Octave
MATLAB / Octave
  % 1. Determining if the first string starts with second string strcmp(str1,str2,length(str2)) % 2. Determining if the first string contains the second string at any location ~isempty(strfind(s1,s2)) % 3. Determining if the first string ends with the second string ( (length(str1)>=length(str2)) && strcmp(...
http://rosettacode.org/wiki/String_length
String length
Task Find the character and byte length of a string. This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters. F...
#Liberty_BASIC
Liberty BASIC
utf8Str = "Hello world äöü" put utf8Str.length -- 15
http://rosettacode.org/wiki/String_length
String length
Task Find the character and byte length of a string. This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters. F...
#Lingo
Lingo
utf8Str = "Hello world äöü" put utf8Str.length -- 15
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal. To illustrate the operat...
#Python
Python
s1 = "hello" print s1 + " world"   s2 = s1 + " world" print s2
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal. To illustrate the operat...
#QB64
QB64
s1$ = "String" s2$ = s1$ + " concatenation" PRINT s1$ PRINT s2$
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#Simula
Simula
! Find the sum of multiples of two factors below a limit - ! Project Euler problem 1: multiples of 3 or 5 below 1000 & 10**20; BEGIN INTEGER PROCEDURE GCD(a, b); INTEGER a, b; GCD := IF b = 0 THEN a ELSE GCD(b, MOD(a, b));   ! sum of multiples of n up to limit; INTEGER PROCEDURE multiples(n, limit);...
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#Transd
Transd
#lang transd   MainModule : { v10: [1, 1234, 10000000], vvar: ["fe:16", "f0e:16", "2022:3", "Transd:30"],   sumDigits: (λ s String() (with snum (substr s 0 ":") base (first (substr s after: ":") "10") n 0 (textout "sum of " :left width: 10 (+ snum ":" base " : " )) (t...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#XLISP
XLISP
(defun sum-of-squares (vec) (defun sumsq (xs) (if (null xs) 0 (+ (expt (car xs) 2) (sumsq (cdr xs))))) (sumsq (vector->list vec)))   (define first-seven-primes #(2 3 5 7 11 13 17))   (define zero-length-vector #())   (print `(the sum of the squares of the first seven prime number...
http://rosettacode.org/wiki/Substring
Substring
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 |...
#Nim
Nim
import strformat, strutils, unicode   let s1 = "abcdefgh" # ASCII string. s2 = "àbĉdéfgĥ" # UTF-8 string. n = 2 m = 3 c = 'd' cs1 = "de" cs2 = "dé"   var pos: int   # ASCII strings. # We can take a substring using "s.substr(first, last)" or "s[first..last]". # The latter form can also be used as lvalu...
http://rosettacode.org/wiki/Substring
Substring
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 |...
#Niue
Niue
( based on the JavaScript code ) 'abcdefgh 's ; s str-len 'len ; 2 'n ; 3 'm ;   ( starting from n characters in and of m length ) s n n m + substring . ( => cde ) newline   ( starting from n characters in, up to the end of the string ) s n len substring . ( => cdefgh ) newline   ( whole string minus last character ) s...
http://rosettacode.org/wiki/Sudoku
Sudoku
Task Solve a partially filled-in normal   9x9   Sudoku grid   and display the result in a human-readable format. references Algorithmics of Sudoku   may help implement this. Python Sudoku Solver Computerphile video.
#SystemVerilog
SystemVerilog
    ////////////////////////////////////////////////////////////////////////////// /// SudokuSolver /// /// A class that fills up a sudoku board, the initial board is given /// /// as an array preset_rows, the positions where preset_rows is zero /// ...
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#UNIX_Shell
UNIX Shell
str='abcdefg' echo "${str#?}" # Remove first char echo "${str%?}" # Remove last char
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#Vala
Vala
  // declare test string string s = "Hello, world!"; // remove first letter string s_first = s[1:s.length]; //remove last letter string s_last = s[0:s.length - 1]; // remove first and last letters string s_first_last = s[1:s.length - 1];  
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Rust
Rust
    fn main() { let arr = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];   // using fold let sum = arr.iter().fold(0i32, |a, &b| a + b); let product = arr.iter().fold(1i32, |a, &b| a * b); println!("the sum is {} and the product is {}", sum, product);   // or using sum and product let sum = arr.iter().sum...
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#S-lang
S-lang
variable a = [5, -2, 3, 4, 666, 7];
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Oforth
Oforth
: sumSerie(s, n) 0 n seq apply(#[ s perform + ]) ;
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#OpenEdge.2FProgress
OpenEdge/Progress
DEF VAR dcResult AS DECIMAL NO-UNDO. DEF VAR n AS INT NO-UNDO.   DO n = 1 TO 1000 : dcResult = dcResult + 1 / (n * n) . END.   DISPLAY dcResult .
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#Transd
Transd
#lang transd   MainModule: { _start: (λ (with s "She was a soul stripper. She took my heart!" (textout (replace s "(a|e|i)" ""))) ) }
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#True_BASIC
True BASIC
FUNCTION stripchars$(text$, remove$) LET s$ = text$ FOR i = 1 TO LEN(remove$) DO LET t = POS(s$, (remove$)[i:i]) IF t <> 0 THEN LET s$ = (s$)[1:t-1] & (s$)[t+1:maxnum] ELSE EXIT DO LOOP NEXT i LET stripchars$ = s$ END FUNCTION   PRINT stripchars$("She was a soul str...
http://rosettacode.org/wiki/String_comparison
String 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 |...
#Swift
Swift
func compare (a: String, b: String) { if a == b { println("'\(a)' and '\(b)' are lexically equal.") } if a != b { println("'\(a)' and '\(b)' are not lexically equal.") }   if a < b { println("'\(a)' is lexically before '\(b)'.") } if a > b { println("'\(a)' is lexically after '\(b)'.") }...
http://rosettacode.org/wiki/String_comparison
String 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 |...
#Tailspin
Tailspin
  $a -> \(when <=$b> do '$a; equals $b;' ! \) -> !OUT::write   $a -> \(when <~=$b> do '$a; not equal to $b;' ! \) -> !OUT::write   $a -> \(when <..$b> do '$a; lexically less or equal to $b;' ! \) -> !OUT::write   $a -> \(when <$b..> do '$a; lexically greater or equal to $b;' ! \) -> !OUT::write   $a -> \(when <..~$b> d...
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#Nim
Nim
import strutils   var s: string = "alphaBETA_123" echo s, " as upper case: ", toUpperAscii(s) echo s, " as lower case: ", toLowerAscii(s) echo s, " as capitalized: ", capitalizeAscii(s) echo s, " as normal case: ", normalize(s) # to lower case without underscores.
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#Objeck
Objeck
  string := "alphaBETA"; string->ToUpper()->PrintLine(); string->ToLower()->PrintLine();  
http://rosettacode.org/wiki/String_matching
String matching
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 |...
#min
min
(indexof 0 ==) :starts-with? (indexof -1 !=) :contains? ((/ $/) swap 1 insert "" join regex ("") !=) :ends-with?   "minimalistic" "min" starts-with? puts! "minimalistic" "list" contains? puts! "minimalistic" "list" ends-with? puts!
http://rosettacode.org/wiki/String_matching
String matching
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 |...
#MiniScript
MiniScript
string.startsWith = function(s) return self.len >= s.len and s[:s.len] == s end function   string.endsWith = function(s) return self.len >= s.len and s[-s.len:] == s end function   string.findAll = function(s) result = [] after = null while true foundPos = self.indexOf(s, after) if f...
http://rosettacode.org/wiki/String_length
String length
Task Find the character and byte length of a string. This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters. F...
#LiveCode
LiveCode
put the length of "Hello World"
http://rosettacode.org/wiki/String_length
String length
Task Find the character and byte length of a string. This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters. F...
#Logo
Logo
print count "|Hello World|  ; 11 print count "møøse  ; 5 print char 248  ; ø - implies ISO-Latin character set
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal. To illustrate the operat...
#Quackery
Quackery
$ "A duck's quack" $ " has no echo." join echo$
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal. To illustrate the operat...
#R
R
hello <- "hello" paste(hello, "literal") # "hello literal" hl <- paste(hello, "literal") #saves concatenates string to a new variable paste("no", "spaces", "between", "words", sep="") # "nospacesbetweenwords"
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal. To illustrate the operat...
#Racket
Racket
#lang racket (define hello "hello") (displayln hello)   (define world (string-append hello " " "world" "!")) (displayln world)   ;outputs: ; hello ; hello world!
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#Stata
Stata
clear all set obs 999 gen a=_n tabstat a if mod(a,3)==0 | mod(a,5)==0, statistic(sum)
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#Swift
Swift
      var n:Int=1000   func sum(x:Int)->Int{   var s:Int=0 for i in 0...x{ if i%3==0 || i%5==0 { s=s+i }   } return s }   var sumofmult:Int=sum(x:n) print(sumofmult)    
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#TypeScript
TypeScript
// Sum digits of an integer   function sumOfDigitBase(n: number, bas: number): number { var digit = 0, sum = 0; while (n > 0) { var tmp = Math.floor(n / bas); digit = n - bas * tmp; n = tmp; sum += digit; } return sum; }   console.log(` 1 sums to ${sumOfDigitBase(1, 10)}`); console.log(` 1...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic 'code' declarations   func SumSq(V, L); int V, L; int S, I; [S:= 0; for I:= 0 to L-1 do S:= S+sq(V(I)); return S; ]; \SumSq   [IntOut(0, SumSq([1,2,3,4,5,6,7,8,9,10], 10)); CrLf(0); IntOut(0, SumSq([0], 0)); CrLf(0); \zero-length vector "[]" doesn't compile ]
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#zkl
zkl
T().reduce(fcn(p,n){ p + n*n },0) //-->0 T(3,1,4,1,5,9).reduce(fcn(p,n){ p + n*n },0.0) //-->133.0 [1..5].reduce(fcn(p,n){ p + n*n },0) //-->55
http://rosettacode.org/wiki/Substring
Substring
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 |...
#Objeck
Objeck
  bundle Default { class SubString { function : Main(args : String[]) ~ Nil { s := "0123456789";   n := 3; m := 4; c := '2'; sub := "456";   s->SubString(n, m)->PrintLine(); s->SubString(n)->PrintLine(); s->SubString(0, s->Size())->PrintLine(); s->SubString(s-...
http://rosettacode.org/wiki/Sudoku
Sudoku
Task Solve a partially filled-in normal   9x9   Sudoku grid   and display the result in a human-readable format. references Algorithmics of Sudoku   may help implement this. Python Sudoku Solver Computerphile video.
#Tailspin
Tailspin
  templates deduceRemainingDigits data row <"1">, col <"1"> local templates findOpenPosition @:{options: 10}; $ -> \[i;j](when <[](..~$@findOpenPosition.options)> do @findOpenPosition: {row: $i, col: $j, options: $::length}; \) -> !VOID $@ ! end findOpenPosition   templates selectFirst&{pos:} de...
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#VBScript
VBScript
Function TopNTail(s,mode) Select Case mode Case "top" TopNTail = Mid(s,2,Len(s)-1) Case "tail" TopNTail = Mid(s,1,Len(s)-1) Case "both" TopNTail = Mid(s,2,Len(s)-2) End Select End Function   WScript.Echo "Top: UPRAISERS = " & TopNTail("UPRAISERS","top"...
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#SAS
SAS
data _null_; array a{*} a1-a100; do i=1 to 100; a{i}=i*i; end; b=sum(of a{*}); put b c; run;
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Sather
Sather
class MAIN is main is a :ARRAY{INT} := |10, 5, 5, 20, 60, 100|; sum, prod :INT; loop sum := sum + a.elt!; end; prod := 1; loop prod := prod * a.elt!; end; #OUT + sum + " " + prod + "\n"; end; end;
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Oz
Oz
declare fun {SumSeries S N} {FoldL {Map {List.number 1 N 1} S} Number.'+' 0.} end   fun {S X} 1. / {Int.toFloat X*X} end in {Show {SumSeries S 1000}}
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT,{} string="She was a soul stripper. She took my heart!" stringstrip=EXCHANGE (string,"_[aei]__") print string print stringstrip  
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#TXR
TXR
(defun strip-chars (str set) (let* ((regex-ast ^(set ,*(list-str set))) (regex-obj (regex-compile regex-ast))) (regsub regex-obj "" str)))   (defun usage () (pprinl `usage: @{(ldiff *full-args* *args*) " "} <string> <set>`) (exit 1))   (tree-case *args* ((str set extra) (usage)) ((str set . junk)...
http://rosettacode.org/wiki/String_comparison
String 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 |...
#Tcl
Tcl
if {$a eq $b} { puts "the strings are equal" } if {$a ne $b} { puts "the strings are not equal" }
http://rosettacode.org/wiki/String_comparison
String 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 |...
#UNIX_Shell
UNIX Shell
#!/bin/sh   A=Bell B=Ball   # Traditional test command implementations test for equality and inequality # but do not have a lexical comparison facility if [ $A = $B ] ; then echo 'The strings are equal' fi if [ $A != $B ] ; then echo 'The strings are not equal' fi   # All variables in the shell are strings, so nume...
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#Objective-C
Objective-C
NSLog(@"%@", @"alphaBETA".uppercaseString); NSLog(@"%@", @"alphaBETA".lowercaseString);   NSLog(@"%@", @"foO BAr".capitalizedString); // "Foo Bar"
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#OCaml
OCaml
let () = let str = "alphaBETA" in print_endline (String.uppercase_ascii str); (* ALPHABETA *) print_endline (String.lowercase_ascii str); (* alphabeta *)   print_endline (String.capitalize_ascii str); (* AlphaBETA *) ;;
http://rosettacode.org/wiki/String_matching
String matching
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 |...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref savelog symbols   lipsum = '' x_ = 0 x_ = x_ + 1; lipsum[0] = x_; lipsum[x_] = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' x_ = x_ + 1; lipsum[0] = x_; lipsum[x_] = lipsum[1].re...
http://rosettacode.org/wiki/String_length
String length
Task Find the character and byte length of a string. This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters. F...
#LSE64
LSE64
" Hello world" @ 1 + 8 * , # 96 = (11+1)*(size of a cell) = 12*8
http://rosettacode.org/wiki/String_length
String length
Task Find the character and byte length of a string. This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters. F...
#Lua
Lua
str = "Hello world" length = #str
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal. To illustrate the operat...
#Raku
Raku
my $s = 'hello'; say $s ~ ' literal'; my $s1 = $s ~ ' literal'; say $s1;   # or, using mutating concatenation:   $s ~= ' literal'; say $s;
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal. To illustrate the operat...
#Raven
Raven
# Cat strings "First string and " "second string" cat print   # Join [ "First string" "second string" "third string" ] " and " join print   # print [ "First string" "second string" "third string" ] each print   # Formatted print "\n" "Third string" "Second string" "First string" "%s %s %s %s" print   # Heredoc " - NOT!...
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#Tcl
Tcl
# Fairly simple version; only counts by 3 and 5, skipping intermediates proc mul35sum {n} { for {set total [set threes [set fives 0]]} {$threes<$n||$fives<$n} {} { if {$threes<$fives} { incr total $threes incr threes 3 } elseif {$threes>$fives} { incr total $fives incr fives 5 } else { i...
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#Ursa
Ursa
def sumDigits (string val, int base) decl int ret for (decl int i) (< i (size val)) (inc i) set ret (+ ret (int val<i> base)) end for return ret end sumDigits
http://rosettacode.org/wiki/Substring
Substring
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 |...
#OCaml
OCaml
$ ocaml # let s = "ABCDEFGH" ;; val s : string = "ABCDEFGH"   # let n, m = 2, 3 ;; val n : int = 2 val m : int = 3   # String.sub s n m ;; - : string = "CDE"   # String.sub s n (String.length s - n) ;; - : string = "CDEFGH"   # String.sub s 0 (String.length s - 1) ;; - : string = "ABCDEFG"   # String.sub s (String.inde...
http://rosettacode.org/wiki/Sudoku
Sudoku
Task Solve a partially filled-in normal   9x9   Sudoku grid   and display the result in a human-readable format. references Algorithmics of Sudoku   may help implement this. Python Sudoku Solver Computerphile video.
#Tcl
Tcl
package require Tcl 8.6 oo::class create Sudoku { variable idata   method clear {} { for {set y 0} {$y < 9} {incr y} { for {set x 0} {$x < 9} {incr x} { my set $x $y {} } } } method load {data} { set error "data must be a 9-element list, each element also being a\ list of 9 numbers from...
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#Wren
Wren
import "/str" for Str   var a = "Beyoncé" var b = Str.delete(a, 0) var len = a.codePoints.count var c = Str.delete(a, len-1) var d = Str.delete(c, 0) for (e in [a, b, c, d]) System.print(e)
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#XPL0
XPL0
include c:\cxpl\stdlib; char S, P; [S:= "Smiles"; Text(0, S+1); \first character removed CrLf(0); P:= S + StrLen(S) - 2; \point to last character in string P(0):= P(0) ! $80; \set the MSb on the last character Text(0, S); \last character removed CrLf(0); Text(0, S+1); \first and la...
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Scala
Scala
val seq = Seq(1, 2, 3, 4, 5) val sum = seq.foldLeft(0)(_ + _) val product = seq.foldLeft(1)(_ * _)
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Scheme
Scheme
(apply + '(1 2 3 4 5)) (apply * '(1 2 3 4 5))
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Panda
Panda
sum{{1.0.divide(1..1000.sqr)}}
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#PARI.2FGP
PARI/GP
sum(n=1,1000,1/n^2)
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#UNIX_Shell
UNIX Shell
strip_chars() { echo "$1" | tr -d "$2" }
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#Ursala
Ursala
strip = ~&j   #cast %s   test = strip('she was a soul stripper. she took my heart','aei')
http://rosettacode.org/wiki/String_comparison
String 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 |...
#Vala
Vala
void main() { var s1 = "The quick brown"; var s2 = "The Quick Brown"; stdout.printf("== : %s\n", s1 == s2 ? "true" : "false"); stdout.printf("!= : %s\n", s1 != s2 ? "true" : "false"); stdout.printf("<  : %s\n", s1 < s2 ? "true" : "false"); stdout.printf("<= : %s\n", s1 <= s2 ? "true" : "false"); stdout.p...
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#Octave
Octave
s = "alphaBETA"; slc = tolower(s); suc = toupper(s); disp(slc); disp(suc);
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#Oforth
Oforth
"alphaBETA" toUpper "alphaBETA" toLower
http://rosettacode.org/wiki/String_matching
String matching
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 |...
#NewLISP
NewLISP
(setq str "abcdefbcghi")   ;; test if str starts with "ab" (starts-with str "ab")   ;; find "bc" inside str (find "bc" str)   ;; test if str ends with "ghi" (ends-with str "ghi")   ;; find all positions of pattern inside str (define (find-all-pos pattern str) (let ((idx -1) (pos '())) (while (setq idx (find patte...
http://rosettacode.org/wiki/String_length
String length
Task Find the character and byte length of a string. This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters. F...
#M2000_Interpreter
M2000 Interpreter
  A$=format$("J\u0332o\u0332s\u0332e\u0301\u0332") Print Len(A$) = 9 ' true Utf-16LE Print Len.Disp(A$) = 4 \\ display length Buffer Clear Mem as Byte*100 \\ Write at memory at offset 0 or address Mem(0) Return Mem, 0:=A$ Print Eval$(Mem, 0, 18) For i=0 to 17 step 2 \\ print hex value and character Hex Eva...
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal. To illustrate the operat...
#REBOL
REBOL
s: "hello" print s1: rejoin [s " literal"] print s1
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal. To illustrate the operat...
#Red
Red
>>str1: "Hello" >>str2: append str1 " World" >> print str2 Hello World >> print str1 Hello World
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal. To illustrate the operat...
#ReScript
ReScript
let s1 = "hello" let s2 = s1 ++ " literal"   Js.log(s1) Js.log(s2)  
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#UNIX_Shell
UNIX Shell
function sum_multiples { typeset -i n=$1 limit=$2 typeset -i max=limit-1 (( max -= max % n )) printf '%d\n' $(( max / n * (n+max)/2 )) }   function sum35 { typeset -i limit=$1 printf '%d\n' $(( $(sum_multiples 3 $limit) + $(sum_multiples 5 $limit) - $(sum_multiples 1...
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#Visual_Basic
Visual Basic
Function sumDigits(num As Variant, base As Long) As Long 'can handle up to base 36 Dim outp As Long Dim validNums As String, tmp As Variant, x As Long, lennum As Long 'ensure num contains only valid characters validNums = Left$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", base) lennum = Len(num) ...
http://rosettacode.org/wiki/Substring
Substring
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 |...
#Oforth
Oforth
: substrings(s, n, m) s sub(n, m) println s right(s size n - 1 +) println s left(s size 1 - ) println s sub(s indexOf('d'), m) println s sub(s indexOfAll("de"), m) println ;
http://rosettacode.org/wiki/Sudoku
Sudoku
Task Solve a partially filled-in normal   9x9   Sudoku grid   and display the result in a human-readable format. references Algorithmics of Sudoku   may help implement this. Python Sudoku Solver Computerphile video.
#Ursala
Ursala
#import std #import nat   sudoku =   @FL mat0+ block3+ mat` *+ block3*+ block9+ -+ ~&rSL+ (psort (nleq+)* <~&blrl,~&blrr>)+ ~&arg^& -+ ~&al?\~&ar ~&aa^&~&afahPRPfafatPJPRY+ ~&farlthlriNCSPDPDrlCS2DlrTS2J, ^|J/~& ~&rt!=+ ^= ~&s+ ~&H( -+.|=&lrr;,|=&lrl;,|=&ll;+-, ~&rgg&& ~&irtPFXlrjrXPS; ...
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#zkl
zkl
"Smiles"[1,*] //-->miles "Smiles"[0,-1] //-->Smile "Smiles"[1,-1] //-->mile
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 PRINT FN f$("knight"): REM strip the first letter. You can also write PRINT "knight"(2 TO) 20 PRINT FN l$("socks"): REM strip the last letter 30 PRINT FN b$("brooms"): REM strip both the first and last letter 100 STOP   9000 DEF FN f$(a$)=a$(2 TO LEN(a$)) 9010 DEF FN l$(a$)=a$(1 TO LEN(a$)-(1 AND (LEN(a$)>=1))) 9020...
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Seed7
Seed7
const func integer: sumArray (in array integer: valueArray) is func result var integer: sum is 0; local var integer: value is 0; begin for value range valueArray do sum +:= value; end for; end func;   const func integer: prodArray (in array integer: valueArray) is func result var int...
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#SETL
SETL
numbers := [1 2 3 4 5 6 7 8 9]; print(+/ numbers, */ numbers);
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Pascal
Pascal
Program SumSeries; type tOutput = double;//extended; tmyFunc = function(number: LongInt): tOutput;   function f(number: LongInt): tOutput; begin f := 1/sqr(tOutput(number)); end;   function Sum(from,upto: LongInt;func:tmyFunc):tOutput; var res: tOutput; begin res := 0.0; // for from:= from to upto do res := ...
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#VBA
VBA
Function StripChars(stString As String, stStripChars As String, Optional bSpace As Boolean) Dim i As Integer, stReplace As String If bSpace = True Then stReplace = " " Else stReplace = "" End If For i = 1 To Len(stStripChars) stString = Replace(stString, Mid(stStripChars, i, 1), ...
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#VBScript
VBScript
  Function stripchars(s1,s2) For i = 1 To Len(s1) If InStr(s2,Mid(s1,i,1)) Then s1 = Replace(s1,Mid(s1,i,1),"") End If Next stripchars = s1 End Function   WScript.StdOut.Write stripchars("She was a soul stripper. She took my heart!","aei")  
http://rosettacode.org/wiki/String_comparison
String 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 |...
#Vlang
Vlang
fn main() { c := "cat" d := "dog" if c == d { println('$c is bytewise identical to $d') } if c != d { println('$c is bytewise different from $d') } if c > d { println('$c is lexically bytewise greater than $d') } if c < d { println('$c is lexically byt...
http://rosettacode.org/wiki/String_comparison
String 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 |...
#WDTE
WDTE
== 'example1' 'example2' -- io.writeln io.stdout; # Test for exact equality. == 'example1' 'example2' -> ! -- io.writeln io.stdout; # Test for inequality. < 'example1' 'example2' -- io.writeln io.stdout; # Test for lexical before. > 'example1' 'example2' -- io.writeln io.stdout; # Test for lexical after.   # Case insen...