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/String_prepend
String prepend
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 |...
#PowerShell
PowerShell
  $str = "World!" $str = "Hello, " + $str $str  
http://rosettacode.org/wiki/String_prepend
String prepend
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 |...
#Prolog
Prolog
  :- op(200, xfx, user:(=+)).   %% +Prepend =+ +Chars % % Will destructively update Chars % So that Chars = Prepend prefixed to Chars. % eazar001 in ##prolog helped refine this approach.   [X|Xs] =+ Chars :- append(Xs, Chars, Rest), nb_setarg(2, Chars, Rest), nb_setarg(1, Chars, X).  
http://rosettacode.org/wiki/String_prepend
String prepend
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 |...
#PureBasic
PureBasic
S$ = " World!" S$ = "Hello" + S$ If OpenConsole() PrintN(S$)   Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input() CloseConsole() EndIf
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 |...
#F.23
F#
open System   // self defined operators for case insensitive comparison let (<~) a b = String.Compare(a, b, StringComparison.OrdinalIgnoreCase) < 0 let (<=~) a b = String.Compare(a, b, StringComparison.OrdinalIgnoreCase) <= 0 let (>~) a b = String.Compare(a, b, StringComparison.OrdinalIgnoreCase) > 0 let (>=~) a b = ...
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...
#Component_Pascal
Component Pascal
  MODULE AlphaBeta; IMPORT StdLog,Strings;   PROCEDURE Do*; VAR str,res: ARRAY 128 OF CHAR; BEGIN str := "alphaBETA"; Strings.ToUpper(str,res); StdLog.String("Uppercase:> ");StdLog.String(res);StdLog.Ln; Strings.ToLower(str,res); StdLog.String("Lowercase:> ");StdLog.String(res);StdLog.Ln END Do;   END 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...
#D
D
void main() { import std.stdio, std.string;   immutable s = "alphaBETA"; s.toUpper.writeln; s.toLower.writeln; }
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 |...
#Delphi
Delphi
program CharacterMatching;   {$APPTYPE CONSOLE}   uses StrUtils;   begin WriteLn(AnsiStartsText('ab', 'abcd')); // True WriteLn(AnsiEndsText('zn', 'abcd')); // False WriteLn(AnsiContainsText('abcd', 'bb')); // False Writeln(AnsiContainsText('abcd', 'ab')); // True WriteLn(Pos('ab', 'abcd')); // 1 end.
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...
#COBOL
COBOL
FUNCTION BYTE-LENGTH(str)
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...
#ColdFusion
ColdFusion
  <cfoutput> <cfset str = "Hello World"> <cfset j = createObject("java","java.lang.String").init(str)> <cfset t = j.getBytes()> <p>#arrayLen(t)#</p> </cfoutput>  
http://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string
Strip control codes and extended characters from a string
Task Strip control codes and extended characters from a string. The solution should demonstrate how to achieve each of the following results:   a string with control codes stripped (but extended characters not stripped)   a string with control codes and extended characters stripped In ASCII, the control codes ...
#Phix
Phix
with javascript_semantics requires("1.0.2") -- (param default fixes in pwa/p2js) function filter_it(string s, integer fromch=' ', toch=#7E, abovech=#7F) string res = "" for i=1 to length(s) do integer ch = s[i] if ch>=fromch and (ch<=toch or ch>abovech) then res &= ch end if ...
http://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string
Strip control codes and extended characters from a string
Task Strip control codes and extended characters from a string. The solution should demonstrate how to achieve each of the following results:   a string with control codes stripped (but extended characters not stripped)   a string with control codes and extended characters stripped In ASCII, the control codes ...
#PicoLisp
PicoLisp
(de stripCtrl (Str) (pack (filter '((C) (nor (= "^?" C) (> " " C "^A")) ) (chop Str) ) ) )   (de stripCtrlExt (Str) (pack (filter '((C) (> "^?" C "^_")) (chop 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...
#F.23
F#
open System   [<EntryPoint>] let main args = let s = "hello" Console.Write(s) Console.WriteLine(" literal") let s2 = s + " literal" Console.WriteLine(s2) 0
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...
#Factor
Factor
"wake up" [ " sheeple" append print ] [ ", you sheep" append ] bi print
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.
#.D0.9C.D0.9A-61.2F52
МК-61/52
П1 0 П0 3 П4 ИП4 3 / {x} x#0 17 ИП4 5 / {x} x=0 21 ИП0 ИП4 + П0 КИП4 ИП1 ИП4 - x=0 05 ИП0 С/П
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
#Objeck
Objeck
class SumDigits { function : Main(args : String[]) ~ Nil { SumDigit(1)->PrintLine(); SumDigit(12345)->PrintLine(); SumDigit(0xfe, 16)->PrintLine(); SumDigit(0xf0e, 16)->PrintLine(); }   function : SumDigit(value : Int, base : Int := 10) ~ Int { sum := 0; do { sum += value % base; ...
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
#OCaml
OCaml
List.fold_left (fun sum a -> sum + a * a) 0 ints
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
#Octave
Octave
a = [1:10]; sumsq = sum(a .^ 2);
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#Liberty_BASIC
Liberty BASIC
a$=" This is a test "   'LB TRIM$ removes characters with codes 0..31 as well as a space(code 32) 'So these versions of ltrim rtrim remove them too 'a$=" "+chr$(31)+"This is a test"+chr$(31)+" "   print "Source line" print ">";a$;"<" print "Strip left" print ">";ltrim$(a$);"<" print "Strip right" print ">";rtri...
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#Logtalk
Logtalk
  :- object(whitespace).   :- public(trim/4).   trim(String, TrimLeft, TrimRight, TrimBoth) :- trim_left(String, TrimLeft), trim_right(String, TrimRight), trim_right(TrimLeft, TrimBoth).   trim_left(String, TrimLeft) :- atom_codes(String, Codes), trim(Codes, TrimCodes...
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 |...
#Forth
Forth
2 constant Pos 3 constant Len : Str ( -- c-addr u ) s" abcdefgh" ;   Str Pos /string drop Len type \ cde Str Pos /string type \ cdefgh Str 1- type \ abcdefg Str char d scan drop Len type \ def Str s" de" search 2drop Len type \ def
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 |...
#Fortran
Fortran
program test_substring   character (*), parameter :: string = 'The quick brown fox jumps over the lazy dog.' character (*), parameter :: substring = 'brown' character , parameter :: c = 'q' integer , parameter :: n = 5 integer , parameter :: m = 15 integer :: i   ! Display the ...
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.
#Kotlin
Kotlin
// version 1.2.10   class Sudoku(rows: List<String>) { private val grid = IntArray(81) private var solved = false   init { require(rows.size == 9 && rows.all { it.length == 9 }) { "Grid must be 9 x 9" } for (i in 0..8) { for (j in 0..8 ) grid[9 * i + j] = rows...
http://rosettacode.org/wiki/Subleq
Subleq
Subleq is an example of a One-Instruction Set Computer (OISC). It is named after its only instruction, which is SUbtract and Branch if Less than or EQual to zero. Task Your task is to create an interpreter which emulates a SUBLEQ machine. The machine's memory consists of an array of signed integers.   These integers...
#PicoLisp
PicoLisp
(de mem (N) (nth (quote 15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72 101 108 108 111 44 32 119 111 114 108 100 33 10 0 ) (inc N) ) )   (for (IP (mem 0) IP) (let (A (pop 'IP) B (pop 'IP) C (pop 'IP)) (cond ((lt0 A) (set (mem B) (char))) ((lt0 B) (prin (...
http://rosettacode.org/wiki/Subleq
Subleq
Subleq is an example of a One-Instruction Set Computer (OISC). It is named after its only instruction, which is SUbtract and Branch if Less than or EQual to zero. Task Your task is to create an interpreter which emulates a SUBLEQ machine. The machine's memory consists of an array of signed integers.   These integers...
#PowerShell
PowerShell
  function Invoke-Subleq ([int[]]$Program) { [int]$ip, [string]$output = $null   try { while ($ip -ge 0) { if ($Program[$ip] -eq -1) { $Program[$Program[$ip + 1]] = [int](Read-Host -Prompt SUBLEQ)[0] } elseif ($Program[$ip + 1] ...
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...
#Logo
Logo
make "s "|My string| print butfirst :s print butlast :s print butfirst butlast :s
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...
#Logtalk
Logtalk
  :- object(top_and_tail).   :- public(test/1). test(String) :- sub_atom(String, 1, _, 0, MinusTop), write('String with first character cut: '), write(MinusTop), nl, sub_atom(String, 0, _, 1, MinusTail), write('String with last character cut: '), write(MinusTail), nl, sub...
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.
#Lucid
Lucid
[%sum,product%] where x = 1 fby x + 1; sum = 0 fby sum + x; product = 1 fby product * x end
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.
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { a = (1,2,3,4,5,6,7,8,9,10) print a#sum() = 55 sum = lambda->{push number+number} product = lambda->{Push number*number} print a#fold(lambda->{Push number*number}, 1), a#fold(lambda->{push number+number},0) dim a(2,2) = 5 Print a()#sum() = 20 } checkit  
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...
#Icon_and_Unicon
Icon and Unicon
procedure main() local i, sum sum := 0 & i := 0 every sum +:= 1.0/((| i +:= 1 ) ^ 2) \1000 write(sum) end
http://rosettacode.org/wiki/Strip_comments_from_a_string
Strip comments from a string
Strip comments from a string You are encouraged to solve this task according to the task description, using any language you may know. The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a semicolon) from a string or input line. Whitespace debacle:   There is s...
#R
R
strip_comments <- function(str) { if(!require(stringr)) stop("you need to install the stringr package") str_trim(str_split_fixed(str, "#|;", 2)[, 1]) }
http://rosettacode.org/wiki/Strip_comments_from_a_string
Strip comments from a string
Strip comments from a string You are encouraged to solve this task according to the task description, using any language you may know. The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a semicolon) from a string or input line. Whitespace debacle:   There is s...
#Racket
Racket
  #lang at-exp racket   (define comment-start-rx "[;#]")   (define text @~a{apples, pears # and bananas apples, pears ; and bananas })   (define (strip-comments text [rx comment-start-rx]) (string-join (for/list ([line (string-split text "\n")]) (string-trim line (pregexp (~a "\\s*" rx ".*")) #:...
http://rosettacode.org/wiki/Strip_comments_from_a_string
Strip comments from a string
Strip comments from a string You are encouraged to solve this task according to the task description, using any language you may know. The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a semicolon) from a string or input line. Whitespace debacle:   There is s...
#Raku
Raku
$*IN.slurp.subst(/ \h* <[ # ; ]> \N* /, '', :g).print
http://rosettacode.org/wiki/Strip_block_comments
Strip block comments
A block comment begins with a   beginning delimiter   and ends with a   ending delimiter,   including the delimiters.   These delimiters are often multi-character sequences. Task Strip block comments from program text (of a programming language much like classic C). Your demos should at least handle simple, non-ne...
#Tcl
Tcl
proc stripBlockComment {string {openDelimiter "/*"} {closeDelimiter "*/"}} { # Convert the delimiters to REs by backslashing all non-alnum characters set openAsRE [regsub -all {\W} $openDelimiter {\\&}] set closeAsRE [regsub -all {\W} $closeDelimiter {\\&}]   # Now remove the blocks using a dynamic non-...
http://rosettacode.org/wiki/Strip_block_comments
Strip block comments
A block comment begins with a   beginning delimiter   and ends with a   ending delimiter,   including the delimiters.   These delimiters are often multi-character sequences. Task Strip block comments from program text (of a programming language much like classic C). Your demos should at least handle simple, non-ne...
#TUSCRIPT
TUSCRIPT
  $$ MODE DATA $$ script=* /** * Some comments * longer comments here that we can parse. * * Rahoo */ function subroutine() { a = /* inline comment */ b + c ; } /*/ <-- tricky comments */   /** * Another comment. */ function something() { } $$ MODE TUSCRIPT ERROR/STOP C...
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
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 |...
#FunL
FunL
X = 'little' println( "Mary had a $X lamb." )
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
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 |...
#Gambas
Gambas
Public Sub Main()   Print Subst("Mary had a &1 lamb", "little")   End
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
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 |...
#Gastona
Gastona
#listix#   <how> //little <what> //has a @<how> lamb   <main> //Mary @<what>  
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...
#Groovy
Groovy
def stripChars = { string, stripChars -> def list = string as List list.removeAll(stripChars as List) list.join() }
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...
#Haskell
Haskell
stripChars :: String -> String -> String stripChars = filter . flip notElem
http://rosettacode.org/wiki/String_prepend
String prepend
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 |...
#Python
Python
#!/usr/bin/env python # -*- coding: utf-8 -*-   s = "12345678" s = "0" + s # by concatenation print(s)
http://rosettacode.org/wiki/String_prepend
String prepend
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 |...
#QB64
QB64
s$ = "prepend" s$ = "String " + s$ PRINT s$
http://rosettacode.org/wiki/String_prepend
String prepend
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 |...
#Quackery
Quackery
$ "with a rubber duck." $ "One is never alone " swap join echo$
http://rosettacode.org/wiki/String_prepend
String prepend
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 |...
#Racket
Racket
;there is no built-in way to set! prepend in racket (define str "foo") (set! str (string-append "bar " str)) (displayln str)   ;but you can create a quick macro to solve that problem (define-syntax-rule (set-prepend! str value) (set! str (string-append value str)))   (define macrostr " bar") (set-prepend! macrostr "f...
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 |...
#Factor
Factor
USING: ascii math.order sorting.human ;   IN: scratchpad "foo" "bar" = . ! compare for equality f IN: scratchpad "foo" "bar" = not . ! compare for inequality t IN: scratchpad "foo" "bar" before? . ! lexically ordered before? f IN: scratchpad "foo" "bar" after? . ! lexically ordered after? t IN: scratchpad "Foo" "foo" <...
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 |...
#Falcon
Falcon
  /* created by Aykayayciti Earl Lamont Montgomery April 9th, 2018 */   e = "early" l = "toast" g = "cheese" b = "cheese" e2 = "early" num1 = 123 num2 = 456   > e == e2 ? @ "$e equals $e2" : @ "$e does not equal $e2" > e != e2 ? @ "$e does not equal $e2": @ "$e equals $e2" // produces -1 for less than > b.cmpi(l) == 1 ...
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...
#DBL
DBL
  OPEN (1,O,'TT:')  ;open video   STR="alphaBETA"   LOCASE STR DISPLAY (1,STR,10)  ;alphabeta   UPCASE STR DISPLAY (1,STR,10)  ;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...
#Delphi
Delphi
writeln(uppercase('alphaBETA')); writeln(lowercase('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 |...
#Dyalect
Dyalect
var value = "abcd".StartsWith("ab") value = "abcd".EndsWith("zn") //returns false value = "abab".Contains("bb") //returns false value = "abab".Contains("ab") //returns true var loc = "abab".IndexOf("bb") //returns -1 loc = "abab".IndexOf("ab") //returns 0
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 |...
#E
E
def f(string1, string2) { println(string1.startsWith(string2))   var index := 0 while ((index := string1.startOf(string2, index)) != -1) { println(`at $index`) index += 1 }   println(string1.endsWith(string2)) }
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...
#Common_Lisp
Common Lisp
(length (sb-ext:string-to-octets "Hello Wørld"))
http://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string
Strip control codes and extended characters from a string
Task Strip control codes and extended characters from a string. The solution should demonstrate how to achieve each of the following results:   a string with control codes stripped (but extended characters not stripped)   a string with control codes and extended characters stripped In ASCII, the control codes ...
#Pike
Pike
> string input = random_string(100); > (string)((array)input-enumerate(32)-enumerate(255-126,1,127)); Result: "p_xx08M]cK<FHgR3\\I.x>)Tm<VgakYddy&P7"
http://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string
Strip control codes and extended characters from a string
Task Strip control codes and extended characters from a string. The solution should demonstrate how to achieve each of the following results:   a string with control codes stripped (but extended characters not stripped)   a string with control codes and extended characters stripped In ASCII, the control codes ...
#PL.2FI
PL/I
  stripper: proc options (main); declare s character (100) varying; declare i fixed binary;   s = 'the quick brown fox jumped'; /* A loop to replace blanks with control characters */ do i = 1 to length(s); if substr(s, i, 1) = ' ' then substr(s, i, 1) = '01'x; end; put skip list (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...
#Falcon
Falcon
  /* created by Aykayayciti Earl Lamont Montgomery April 9th, 2018 */   s = "critical" > s + " literal" s2 = s + " literal" > 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...
#Fantom
Fantom
fansh> a := "abc" abc fansh> b := a + "def" abcdef fansh> a abc fansh> b abcdef
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.
#Nanoquery
Nanoquery
def getSum(n) sum = 0 for i in range(3, n - 1) if (i % 3 = 0) or (i % 5 = 0) sum += i end end return sum end   println getSum(1000)
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
#OCaml
OCaml
let sum_digits ~digits ~base = let rec aux sum x = if x <= 0 then sum else aux (sum + x mod base) (x / base) in aux 0 digits   let () = Printf.printf "%d %d %d %d %d\n" (sum_digits 1 10) (sum_digits 12345 10) (sum_digits 123045 10) (sum_digits 0xfe 16) (sum_digits 0xf0e 16)
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
#Oforth
Oforth
#sq [1, 1.2, 3, 4.5 ] map sum
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
#Ol
Ol
  (define (sum-of-squares l) (fold + 0 (map * l l)))   (print (sum-of-squares '(1 2 3 4 5 6 7 8 9 10))) ; ==> 385  
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#Lua
Lua
str = " \t \r \n String with spaces \t \r \n "   print( string.format( "Leading whitespace removed: %s", str:match( "^%s*(.+)" ) ) ) print( string.format( "Trailing whitespace removed: %s", str:match( "(.-)%s*$" ) ) ) print( string.format( "Leading and trailing whitespace removed: %s", str:match( "^%s*(.-)%s*$" ) )...
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#M2000_Interpreter
M2000 Interpreter
  Module CheckIt { filter$=chr$(0) for i=1 to 31:filter$+=chr$(i):next a$=chr$(9)+" There are unwanted blanks here! "+chr$(9) a$=filter$(a$,filter$) ' exclude non printable characters   \\ string encoded as UTF16LE Print Len(a$)=39 Print(ltrim$(a$)) Print(rtrim$(a$)) Print(trim$(a$)) \\ string encoded a...
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 |...
#Free_Pascal
Free Pascal
s[n..n+m] s[n..high(nativeUInt)] s[1..length(s)-1] s[pos(c, s)..pos(c, s)+m] s[pos(p, s)..pos(p, s)+m]
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.
#Lua
Lua
--9x9 sudoku solver in lua --based on a branch and bound solution --fields are not tried in plain order --but in a way to detect dead ends earlier concat=table.concat insert=table.insert constraints = { } --contains a table with 3 constraints for every field -- a contraint "cons" is a table containing all fields whic...
http://rosettacode.org/wiki/Subleq
Subleq
Subleq is an example of a One-Instruction Set Computer (OISC). It is named after its only instruction, which is SUbtract and Branch if Less than or EQual to zero. Task Your task is to create an interpreter which emulates a SUBLEQ machine. The machine's memory consists of an array of signed integers.   These integers...
#PureBasic
PureBasic
DataSection StartData: Data.i 15,17,-1,17,-1,-1,16,1,-1,16,3,-1,15,15,0,0,-1,72,101,108,108,111,44,32,119,111,114,108,100,33,10,0 StopData: EndDataSection   If OpenConsole("Subleq")=0 : End 1 : EndIf Dim code.i((?StopData-?StartData)/SizeOf(Integer)-1) CopyMemory(?StartData,@code(0),?StopData-?StartData) Define.i...
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...
#Lua
Lua
print (string.sub("knights",2)) -- remove the first character print (string.sub("knights",1,-2)) -- remove the last character print (string.sub("knights",2,-2)) -- remove the first and last characters
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.
#Maple
Maple
a := Array([1, 2, 3, 4, 5, 6]); add(a); mul(a);
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...
#IDL
IDL
print,total( 1/(1+findgen(1000))^2)
http://rosettacode.org/wiki/Strip_comments_from_a_string
Strip comments from a string
Strip comments from a string You are encouraged to solve this task according to the task description, using any language you may know. The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a semicolon) from a string or input line. Whitespace debacle:   There is s...
#Red
Red
  >> parse s: "apples, pears ; and bananas" [to [any space ";"] remove thru end] == true >> s == "apples, pears"  
http://rosettacode.org/wiki/Strip_comments_from_a_string
Strip comments from a string
Strip comments from a string You are encouraged to solve this task according to the task description, using any language you may know. The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a semicolon) from a string or input line. Whitespace debacle:   There is s...
#REXX
REXX
/*REXX program strips a string delineated by a hash (#) or a semicolon (;). */ old1= ' apples, pears # and bananas'  ; say ' old ───►'old1"◄───" new1= stripCom1(old1)  ; say ' 1st version new ───►'new1"◄───" new2= stripCom2(old1)  ; ...
http://rosettacode.org/wiki/Strip_block_comments
Strip block comments
A block comment begins with a   beginning delimiter   and ends with a   ending delimiter,   including the delimiters.   These delimiters are often multi-character sequences. Task Strip block comments from program text (of a programming language much like classic C). Your demos should at least handle simple, non-ne...
#VBA
VBA
'strip block comment NESTED comments 'multi line comments 'and what if there are string literals with these delimeters? '------------------------ 'delimeters for Block Comment can be specified, exactly two characters each 'Three states: Block_Comment, String_Literal, Other_Text 'Globals: Dim t As String 'target string ...
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
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 |...
#Go
Go
  package main   import ( "fmt" )   func main() { str := "Mary had a %s lamb" txt := "little" out := fmt.Sprintf(str, txt) fmt.Println(out) }  
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
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 |...
#Groovy
Groovy
def adj = 'little' assert 'Mary had a little lamb.' == "Mary had a ${adj} lamb."
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
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 |...
#Haskell
Haskell
import Text.Printf   main = printf "Mary had a %s lamb\n" "little"
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...
#Icon_and_Unicon
Icon and Unicon
procedure main(A) cs := \A[1] | 'aei' # argument is set of characters to strip every write(stripChars(!&input, cs)) # strip all input lines end   procedure stripChars(s,cs) ns := "" s ? while ns ||:= (not pos(0), tab(upto(cs)|0)) do tab(many(cs)) return ns end
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...
#J
J
'She was a soul stripper. She took my heart!' -. 'aei' Sh ws soul strppr. Sh took my hrt!
http://rosettacode.org/wiki/String_prepend
String prepend
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 |...
#Raku
Raku
# explicit concatentation $_ = 'byte'; $_ = 'kilo' ~ $_; .say;   # interpolation as concatenation $_ = 'buck'; $_ = "mega$_"; .say;   # lvalue substr $_ = 'bit'; substr-rw($_,0,0) = 'nano'; .say;   # regex substitution $_ = 'fortnight'; s[^] = 'micro'; .say;   # reversed append assignment $_ = 'cooper'; $_ [R~]= 'mini...
http://rosettacode.org/wiki/String_prepend
String prepend
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 |...
#Red
Red
Red [] s: "world" insert s "hello " print s  
http://rosettacode.org/wiki/String_prepend
String prepend
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 |...
#REXX
REXX
zz= 'llo world!' /*─────────────── using literal abuttal.────────────*/ zz= 'he'zz /*This won't work if the variable name is X or B */ say zz     gg = "llo world!" /*─────────────── using literal concatenation.──────*/ gg = 'he' || gg say gg     aString= 'llo world!' /*───────────...
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 |...
#Forth
Forth
: str-eq ( str len str len -- ? ) compare 0= ; : str-neq ( str len str len -- ? ) compare 0<> ; : str-lt ( str len str len -- ? ) compare 0< ; : str-gt ( str len str len -- ? ) compare 0> ; : str-le ( str len str len -- ? ) compare 0<= ; : str-ge ( str len str len -- ? ) compare 0>= ;
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 |...
#Fortran
Fortran
PRINT 42,N 42 FORMAT (14HThe answer is ,I9)
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...
#DWScript
DWScript
PrintLn(UpperCase('alphaBETA')); PrintLn(LowerCase('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...
#Dyalect
Dyalect
let str = "alphaBETA"   print("Lower case: ", str.Lower(), separator: "") print("Upper case: ", str.Upper(), separator: "") print("Capitalize: ", str.Capitalize(), separator: "")
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 |...
#EchoLisp
EchoLisp
  (string-suffix? "nette" "Antoinette") → #t (string-prefix? "Simon" "Simon & Garfunkel") → #t   (string-match "Antoinette" "net") → #t ;; contains (string-index "net" "Antoinette") → 5 ;; substring location  
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...
#Component_Pascal
Component Pascal
  MODULE TestLen;   IMPORT Out;   PROCEDURE DoCharLength*; VAR s: ARRAY 16 OF CHAR; len: INTEGER; BEGIN s := "møøse"; len := LEN(s$); Out.String("s: "); Out.String(s); Out.Ln; Out.String("Length of characters: "); Out.Int(len, 0); Out.Ln END DoCharLength;   END TestLen.  
http://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string
Strip control codes and extended characters from a string
Task Strip control codes and extended characters from a string. The solution should demonstrate how to achieve each of the following results:   a string with control codes stripped (but extended characters not stripped)   a string with control codes and extended characters stripped In ASCII, the control codes ...
#PowerShell
PowerShell
  function Remove-Character { [CmdletBinding(DefaultParameterSetName="Control and Extended")] [OutputType([string])] Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [...
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...
#Forth
Forth
s" hello" pad place pad count type s" there!" pad +place \ +place is called "append" on some Forths pad count type
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...
#Fortran
Fortran
program StringConcatenation   integer, parameter :: maxstringlength = 64 character (maxstringlength) :: s1, s = "hello"   print *,s // " literal" s1 = trim(s) // " literal" print *,s1   end program
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.
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary numeric digits 40   runSample(arg) return   -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method summing(maxLimit = 1000) public static mult = 0 loop mv = 0 while mv < maxLimit if mv // 3 = 0 | mv // ...
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
#Oforth
Oforth
: sumDigits(n, base) 0 while( n ) [ n base /mod ->n + ] ;
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
#Order
Order
#include <order/interpreter.h>   ORDER_PP(8to_lit( 8seq_fold(8plus, 0, 8seq_map(8fn(8X, 8times(8X, 8X)), 8seq(3, 1, 4, 1, 5, 9))) ))
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
#Oz
Oz
declare fun {SumOfSquares Xs} for X in Xs sum:S do {S X*X} end end in {Show {SumOfSquares [3 1 4 1 5 9]}}
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#Maple
Maple
str := " \t \r \n String with spaces \t \r \n ";   with(StringTools):   TrimLeft(str); TrimRight(str); Trim(str);
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
StringTrim[" \n\t string with spaces \n \t "]
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 |...
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   Dim s As String = "123456789" Dim As Integer n = 3, m = 4 Print Mid(s, n, m) Print Mid(s, n) Print Left(s, Len(s) - 1) 'start from "5" say Print Mid(s, Instr(s, "5"), m) ' start from "12" say Print Mid(s, Instr(s, "12"), m) Sleep
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.
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
solve[sudoku_] := NestWhile[ Join @@ Table[ Table[ReplacePart[s, #1 -> n], {n, #2}] & @@ First@SortBy[{#, Complement[Range@9, s[[First@#]], s[[;; , Last@#]], Catenate@ Extract[Partition[s, {3, 3}], Quotient[#, 3, -2]]]} & /@ Position[s, 0, {2}], L...
http://rosettacode.org/wiki/Subleq
Subleq
Subleq is an example of a One-Instruction Set Computer (OISC). It is named after its only instruction, which is SUbtract and Branch if Less than or EQual to zero. Task Your task is to create an interpreter which emulates a SUBLEQ machine. The machine's memory consists of an array of signed integers.   These integers...
#Python
Python
import sys   def subleq(a): i = 0 try: while i >= 0: if a[i] == -1: a[a[i + 1]] = ord(sys.stdin.read(1)) elif a[i + 1] == -1: print(chr(a[a[i]]), end="") else: a[a[i + 1]] -= a[a[i]] if a[a[i + 1]] <= 0: ...
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...
#Maple
Maple
> s := "some string": > s[2..-1]; "ome string"   > s[1..-2]; "some strin"   > s[2..-2]; "ome strin"
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...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
StringDrop["input string",1] StringDrop["input string",-1] StringTake["input string",{2,-2}]  
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.
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
a = {1, 2, 3, 4, 5} Plus @@ a Apply[Plus, a] Total[a] Total@a a // Total Sum[a[[i]], {i, 1, Length[a]}] Sum[i, {i, a}]
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.
#MATLAB
MATLAB
>> array = [1 2 3;4 5 6;7 8 9]   array =   1 2 3 4 5 6 7 8 9   >> sum(array,1)   ans =   12 15 18   >> sum(array,2)   ans =   6 15 24   >> prod(array,1)   ans =   28 80 162   >> prod(array,2)   ans =   6 120 504
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...
#Io
Io
Io 20110905 Io> sum := 0 ; Range 1 to(1000) foreach(k, sum = sum + 1/(k*k)) ==> 1.6439345666815615 Io> 1 to(1000) map(k, 1/(k*k)) sum ==> 1.6439345666815615 Io>