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/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... | #Perl | Perl | print substr("knight",1), "\n"; # strip first character
print substr("socks", 0, -1), "\n"; # strip last character
print substr("brooms", 1, -1), "\n"; # strip both 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.
| #Octave | Octave | a = [ 1, 2, 3, 4, 5, 6 ];
b = [ 10, 20, 30, 40, 50, 60 ];
vsum = a + b;
vprod = a .* b; |
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... | #Lasso | Lasso | define sum_of_a_series(n::integer,k::integer) => {
local(sum = 0)
loop(-from=#k,-to=#n) => {
#sum += 1.00/(math_pow(loop_count,2))
}
return #sum
}
sum_of_a_series(1000,1) |
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 |... | #PARI.2FGP | PARI/GP | GEN
string_interpolate(GEN n)
{
pari_printf("The value was: %Ps.\n", n);
GEN s = pari_sprintf("Storing %Ps in a string", n);
} |
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 |... | #Perl | Perl | $extra = "little";
print "Mary had a $extra lamb.\n";
printf "Mary had a %s lamb.\n", $extra; |
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... | #Nim | Nim | import strutils
echo "She was a soul stripper. She took my heart!".split({'a','e','i'}).join()
echo "She was a soul stripper. She took my heart!".multiReplace(
("a", ""),
("e", ""),
("i", "")
)
# And another way using module "sequtils".
import sequtils
echo "She was a soul stripper. She took my heart!".filt... |
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... | #Objective-C | Objective-C | @interface NSString (StripCharacters)
- (NSString *) stripCharactersInSet: (NSCharacterSet *) chars;
@end
@implementation NSString (StripCharacters)
- (NSString *) stripCharactersInSet: (NSCharacterSet *) chars {
return [[self componentsSeparatedByCharactersInSet:chars] componentsJoinedByString:@""];
}
@end |
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 |... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | compare[x_, y_] := Module[{},
If[x == y,
Print["Comparing for equality (case sensitive): " <> x <> " and " <> y <> " ARE equal"],
Print["Comparing for equality (case sensitive): " <> x <> " and " <> y <> " are NOT equal" ]] ;
If[x != y,
Print["Comparing for inequality (case sensitive): " <> x <> " and "... |
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 |... | #MATLAB_.2F_Octave | MATLAB / Octave |
a="BALL";
b="BELL";
if a==b, disp('The strings are equal'); end;
if strcmp(a,b), disp('The strings are equal'); end;
if a~=b, disp('The strings are not equal'); end;
if ~strcmp(a,b), disp('The strings are not equal'); end;
if a > b, disp('The first string is lexically after than the second'); end;... |
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... | #FutureBasic | FutureBasic | window 1
CFStringRef s = @"alphaBETA"
print s
print ucase(s)
print lcase(s)
HandleEvents |
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... | #Gambas | Gambas | Public Sub Main()
Dim sString As String = "alphaBETA "
Print UCase(sString)
Print LCase(sString)
End |
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 |... | #Gambas | Gambas | Public Sub Main()
Dim sString1 As String = "Hello world"
Dim sString2 As String = "Hello"
Print sString1 Begins Left(sString2, 5) 'Determine if the first string starts with second string
If InStr(sString1, sString2) Then Print "True" Else Print "False" 'Determine if the first string cont... |
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... | #Fantom | Fantom |
fansh> c := "møøse"
møøse
fansh> c.toBuf.size // find the byte length of the string in default (UTF8) encoding
7
fansh> c.toBuf.toHex // display UTF8 representation
6dc3b8c3b87365
fansh> c.toBuf(Charset.utf16LE).size // byte length in UTF16 little-endian
10
fansh> c.toBuf(Charset.utf16LE).toHex // display a... |
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... | #Forth | Forth | CREATE s ," Hello world" \ create string "s"
s C@ ( -- length=11 )
s COUNT ( addr len ) \ convert to a stack string, described below |
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 ... | #zkl | zkl | var ctlCodes=([1..31].pump(String,"toChar") +(127).toChar());
var extdChars=[127..255].pump(String,"toChar");
var test = "string of ☺☻♥♦⌂, control characters(\t\b\e) and other ilk.♫☼§►↔◄";
test.println("<< test string");
(test-ctlCodes).println("<< no control chars");
(test-extdChars).println("<< no extended chars");... |
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... | #Liberty_BASIC | Liberty BASIC | a = "Hello"
b = a & " world!"
put b
-- "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... | #Lingo | Lingo | a = "Hello"
b = a & " world!"
put b
-- "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... | #Lisaac | Lisaac | Section Header
+ name := STRING_CONCATENATION;
Section Public
- main <- (
+ sc : STRING_CONSTANT;
+ sv : STRING;
sc := "Hello";
(sc + " literal").println;
sv := sc + " literal";
sv.println;
); |
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.
| #PHP | PHP | $max = 1000;
$sum = 0;
for ($i = 1 ; $i < $max ; $i++) {
if (($i % 3 == 0) or ($i % 5 == 0)) {
$sum += $i;
}
}
echo $sum, PHP_EOL;
|
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
| #Prolog | Prolog | digit_sum(N, Base, Sum):-
digit_sum(N, Base, Sum, 0).
digit_sum(N, Base, Sum, S1):-
N < Base,
!,
Sum is S1 + N.
digit_sum(N, Base, Sum, S1):-
divmod(N, Base, M, Digit),
S2 is S1 + Digit,
digit_sum(M, Base, Sum, S2).
test_digit_sum(N, Base):-
digit_sum(N, Base, Sum),
writef('Sum o... |
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
| #Python | Python | sum(x * x for x in [1, 2, 3, 4, 5])
# or
sum(x ** 2 for x in [1, 2, 3, 4, 5])
# or
sum(pow(x, 2) for x in [1, 2, 3, 4, 5]) |
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
| #Q | Q | ssq:{sum x*x} |
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... | #PL.2FI | PL/I | put ( trim(text, ' ', '') ); /* trims leading blanks. */
put ( trim(text, '', ' ') ); /* trims trailing blanks. */
put ( trim(text) ); /* trims leading and trailing */
/* blanks. */ |
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... | #PowerShell | PowerShell |
$var = " Hello World "
$var.TrimStart() # String with leading whitespace removed
$var.TrimEnd() # String with trailing whitespace removed
$var.Trim() # String with both leading and trailing whitespace removed
|
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 |... | #Julia | Julia | julia> s = "abcdefg"
"abcdefg"
julia> n = 3
3
julia> s[n:end]
"cdefg"
julia> m=2
2
julia> s[n:n+m]
"cde"
julia> s[1:end-1]
"abcdef"
julia> s[search(s,'c')]
'c'
julia> s[search(s,'c'):search(s,'c')+m]
"cde" |
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.
| #Picat | Picat | import util.
import cp.
main => go.
go =>
sudokus(Sudokus),
foreach([Comment,SudokuS] in Sudokus)
println(SudokuS),
println(Comment),
% Convert string to numbers and "." to _ (unknown)
Sudoku = [ [cond(S == '.',_,S.to_integer()) :
S in slice(SudokuS,(I*9)+1,(I+1)*9)] : I in 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... | #Phix | Phix | constant s = "(test)"
?s[2..-1]
?s[1..-2]
?s[2..-2]
|
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... | #Phixmonti | Phixmonti | include ..\Utilitys.pmt
"(test)"
dup 1 del ?
dup -1 del ?
dup 1 del -1 del ? |
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.
| #Oforth | Oforth | [1, 2, 3, 4, 5 ] sum println
[1, 3, 5, 7, 9 ] prod println |
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.
| #Ol | Ol |
(print (fold + 0 '(1 2 3 4 5)))
(print (fold * 1 '(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... | #LFE | LFE |
(defun sum-series (nums)
(lists:foldl
#'+/2
0
(lists:map
(lambda (x) (/ 1 x x))
nums)))
|
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 |... | #Phix | Phix | string size = "little"
string s = sprintf("Mary had a %s lamb.",{size})
?s
|
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 |... | #PHP | PHP | <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?> |
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... | #OCaml | OCaml | let stripchars s cs =
let len = String.length s in
let res = Bytes.create len in
let rec aux i j =
if i >= len
then Bytes.to_string (Bytes.sub res 0 j)
else if String.contains cs s.[i] then
aux (succ i) (j)
else begin
Bytes.set res j s.[i];
aux (succ i) (succ j)
end
in
au... |
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 |... | #MiniScript | MiniScript | string1 = input("Please enter a string.")
string2 = input("Please enter a second string.")
//Comparing two strings for exact equality
if string1 == string2 then
print "Strings are equal."
end if
//Comparing two strings for inequality
if string1 != string2 then
print "Strings are NOT equal."
end if
//C... |
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 |... | #Nanoquery | Nanoquery | def compare(a, b)
println format("\n%s is of type %s and %s is of type %s", a, type(a), b, type(b))
if a < b
println format("%s is strictly less than %s", a, b)
end
if a <= b
println format("%s is less than or equal to %s", a, b)
end
if a > b
println format("%s is strictly greater than %s", a, b)
end
if a... |
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... | #GAP | GAP | LowercaseString("alphaBETA");
UppercaseString("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... | #GML | GML | #define cases
{
x = 'alphaBETA';
y = string_upper(x); // returns ALPHABETA
z = string_lower(x); // returns alphabeta
show_message(y);
show_message(z);
} |
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 |... | #GML | GML | #define charMatch
{
first = "qwertyuiop";
// Determining if the first string starts with second string
second = "qwerty";
if (string_pos(second, first) > 0) {
show_message("'" + first + "' starts with '" + second + "'");
} else {
show_message("'" + first + "' does not start with '... |
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... | #Fortran | Fortran | ' FB 1.05.0 Win64
Dim s As String = "moose" '' variable length ascii string
Dim f As String * 5 = "moose" '' fixed length ascii string (in practice a zero byte is appended)
Dim z As ZString * 6 = "moose" '' fixed length zero terminated ascii string
Dim w As WString * 6 = "møøse" '' fixed length zero termin... |
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... | #LiveCode | LiveCode | local str="live"
put str & "code" into str2
put str && str2 |
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... | #Logo | Logo | make "s "hello
print word :s "| there!| |
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... | #Lua | Lua | a = "hello "
print(a .. "world")
c = a .. "world"
print(c) |
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.
| #Picat | Picat |
sumdiv(N, D) = S =>
M = N div D,
S = (M*(M + 1) div 2) * D.
sum35big(N) = sumdiv(N, 3) + sumdiv(N, 5) - sumdiv(N, 15).
main =>
Upto1K = [N: N in 1..999, (N mod 3 = 0; N mod 5 = 0)].sum,
writef("The sum of all multiples of 3 and 5 below 1000 is %w%n", Upto1K),
writef("The sum of all multiples l... |
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
| #PureBasic | PureBasic |
EnableExplicit
Procedure.i SumDigits(Number.q, Base)
If Number < 0 : Number = -Number : EndIf; convert negative numbers to positive
If Base < 2 : Base = 2 : EndIf ; base can't be less than 2
Protected sum = 0
While Number > 0
sum + Number % Base
Number / Base
Wend
ProcedureReturn sum
EndProcedur... |
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
| #Quackery | Quackery | [ 0 swap witheach [ 2 ** + ] ] is sumofsquares ( [ --> 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
| #R | R | arr <- c(1,2,3,4,5)
result <- sum(arr^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... | #Prolog | Prolog | strip :-
In = " There are unwanted blanks here! ",
strip_left(In, OutLeft),
format('In : ~s__~n', [In]),
format('Strip left : ~s__~n', [OutLeft]),
strip_right(In, OutRight),
format('Strip right : ~s__~n', [OutRight]),
strip(In, Out),
format('Strip : ~s__~n', [Out]).
strip_left(In, Out)... |
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 |... | #Kotlin | Kotlin | // version 1.0.6
fun main(args: Array<String>) {
val s = "0123456789"
val n = 3
val m = 4
val c = '5'
val z = "12"
var i: Int
println(s.substring(n, n + m))
println(s.substring(n))
println(s.dropLast(1))
i = s.indexOf(c)
println(s.substring(i, i + m))
i = s.indexOf(z)
... |
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.
| #PicoLisp | PicoLisp | (load "lib/simul.l")
### Fields/Board ###
# val lst
(setq
*Board (grid 9 9)
*Fields (apply append *Board) )
# Init values to zero (empty)
(for L *Board
(for This L
(=: val 0) ) )
# Build lookup lists
(for (X . L) *Board
(for (Y . This) L
(=: lst
(make
(let A (* 3 (/ ... |
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... | #PHP | PHP | <?php
echo substr("knight", 1), "\n"; // strip first character
echo substr("socks", 0, -1), "\n"; // strip last character
echo substr("brooms", 1, -1), "\n"; // strip both 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.
| #ooRexx | ooRexx | a=.my_array~new(20)
do i=1 To 20
a[i]=i
End
s=a~makestring((LINE),',')
Say s
Say ' sum='a~sum
Say 'product='a~prod
::class my_array subclass array
::method sum
sum=0
Do i=1 To self~dimension(1)
sum+=self[i]
End
Return sum
::method prod
Numeric Digits 30
prod=1
Do i=1 To self~dimension(1)
prod*=self[i]
En... |
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... | #Liberty_BASIC | Liberty BASIC |
for i =1 to 1000
sum =sum +1 /( i^2)
next i
print sum
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 |... | #Picat | Picat | main =>
V = "little",
printf("Mary had a %w lamb\n", V),
% As a function
S = to_fstring("Mary had a %w lamb", V),
println(S). |
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 |... | #PicoLisp | PicoLisp | (let Extra "little"
(prinl (text "Mary had a @1 lamb." Extra)) ) |
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... | #Oforth | Oforth | String method: stripChars(str) #[ str include not ] self filter ;
"She was a soul stripper. She took my heart!" stripChars("aei") println |
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... | #PARI.2FGP | PARI/GP | stripchars(s, bad)={
bad=Set(Vec(Vecsmall(bad)));
s=Vecsmall(s);
my(v=[]);
for(i=1,#s,if(!setsearch(bad,s[i]),v=concat(v,s[i])));
Strchr(v)
};
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 |... | #NetRexx | NetRexx | animal = 'dog'
if animal = 'cat' then
say animal "is lexically equal to cat"
if animal \= 'cat' then
say animal "is not lexically equal cat"
if animal > 'cat' then
say animal "is lexically higher than cat"
if animal < 'cat' then
say animal "is lexically lower than cat"
if animal >= 'cat' then
say animal "is n... |
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... | #Go | Go | package main
import (
"fmt"
"strings"
"unicode"
"unicode/utf8"
)
func main() {
show("alphaBETA")
show("alpha BETA")
// Three digraphs that should render similar to DZ, Lj, and nj.
show("DŽLjnj")
// Unicode apostrophe in third word.
show("o'hare O'HARE o’hare don't")
}
func sho... |
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 |... | #Go | Go | package main
import (
"fmt"
"strings"
)
func match(first, second string) {
fmt.Printf("1. %s starts with %s: %t\n",
first, second, strings.HasPrefix(first, second))
i := strings.Index(first, second)
fmt.Printf("2. %s contains %s: %t,\n", first, second, i >= 0)
if i >= 0 {
fmt... |
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... | #FreeBASIC | FreeBASIC | ' FB 1.05.0 Win64
Dim s As String = "moose" '' variable length ascii string
Dim f As String * 5 = "moose" '' fixed length ascii string (in practice a zero byte is appended)
Dim z As ZString * 6 = "moose" '' fixed length zero terminated ascii string
Dim w As WString * 6 = "møøse" '' fixed length zero termin... |
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... | #M2000_Interpreter | M2000 Interpreter |
Module CheckString {
s$ = "hello"
PRINT s$;" literal" 'or s$ + " literal"
s2$ = s$ + " literal"
PRINT s2$
Print Len(s2$)=13
\\ get an ansi string
k$=Str$("Hello")
Print Len(k$)=2.5 ' 2.5 words or 5 bytes
Print Chr$(k$)
k2$=k$+Str$(" literal")
Print Le... |
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... | #M4 | M4 | define(`concat',`$1$2')dnl
define(`A',`any text value')dnl
concat(`A',` concatenated with string literal')
define(`B',`concat(`A',` and string literal')')dnl
B |
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.
| #PicoLisp | PicoLisp | (de sumMul (N F)
(let N1 (/ (dec N) F)
(*/ F N1 (inc N1) 2) ) )
(for I 20
(let N (** 10 I)
(println
(-
(+ (sumMul N 3) (sumMul N 5))
(sumMul N 15) ) ) ) ) |
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
| #Python | Python |
from numpy import base_repr
def sumDigits(num, base=10):
return sum(int(x, base) for x in list(base_repr(num, 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
| #Racket | Racket |
#lang racket
(for/sum ([x #(3 1 4 1 5 9)]) (* x x))
|
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... | #PureBasic | PureBasic | ;define the whitespace as desired
#whitespace$ = " " + Chr($9) + Chr($A) + Chr($B) + Chr($C) + Chr($D) + Chr($1C) + Chr($1D) + Chr($1E) + Chr($1F)
Procedure.s myLTrim(source.s)
Protected i, *ptrChar.Character, length = Len(source)
*ptrChar = @source
For i = 1 To length
If Not FindString(#whitespace$, Chr(*p... |
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 |... | #Ksh | Ksh |
#!/bin/ksh
# Display a substring:
# - starting from n characters in and of m length;
# - starting from n characters in, up to the end of the string;
# - whole string minus the last character;
# - starting from a known character within the string and of m length;
# - starting from a known substring within th... |
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.
| #PL.2FI | PL/I | sudoku: procedure options (main); /* 27 July 2014 */
declare grid (9,9) fixed (1) static initial (
0, 0, 3, 0, 2, 0, 6, 0, 0,
9, 0, 0, 3, 0, 5, 0, 0, 1,
0, 0, 1, 8, 0, 6, 4, 0, 0,
0, 0, 8, 1, 0, 2, 9, 0, 0,
7, 0, 0, 0, 0, 0, 0, 0, 8,
0, 0, 6, 7, 0, 8, 2, 0, 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... | #Picat | Picat | go =>
test("upraisers"),
test("Δημοτική"),
nl.
test(S) =>
println(s=S),
println(butfirst=S.slice(2)),
println(butfirst=S.tail),
println(butfirst=S[2..S.len]),
println(butlast=S.but_last()),
println(butfirst_butlast=S.tail.but_last),
println(butfirst_butlast=slice(S,2,S.length-1)),
println(... |
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.
| #Oz | Oz | declare
Xs = [1 2 3 4 5]
Sum = {FoldL Xs Number.'+' 0}
Product = {FoldL Xs Number.'*' 1}
in
{Show Sum}
{Show Product} |
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.
| #PARI.2FGP | PARI/GP | vecsum1(v)={
sum(i=1,#v,v[i])
};
vecprod(v)={
prod(i=1,#v,v[i])
}; |
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... | #Lingo | Lingo | the floatprecision = 8
sum = 0
repeat with i = 1 to 1000
sum = sum + 1/power(i, 2)
end repeat
put sum
-- 1.64393457 |
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 |... | #PL.2FI | PL/I | *process or(!) source xref attributes;
sit: Proc Options(main);
/*********************************************************************
* Test string replacement
* 02.08.2013 Walter Pachl
*********************************************************************/
Dcl s Char(50) Var Init('Mary had a &X lamb. It is &X');... |
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... | #Pascal | Pascal | sub stripchars {
my ($s, $chars) = @_;
$s =~ s/[$chars]//g;
return $s;
}
print stripchars("She was a soul stripper. She took my heart!", "aei"), "\n"; |
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... | #Perl | Perl | sub stripchars {
my ($s, $chars) = @_;
$s =~ s/[$chars]//g;
return $s;
}
print stripchars("She was a soul stripper. She took my heart!", "aei"), "\n"; |
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 |... | #Nim | Nim | import strutils
var s1: string = "The quick brown"
var s2: string = "The Quick Brown"
echo("== : ", s1 == s2)
echo("!= : ", s1 != s2)
echo("< : ", s1 < s2)
echo("<= : ", s1 <= s2)
echo("> : ", s1 > s2)
echo(">= : ", s1 >= s2)
# cmpIgnoreCase(a, b) => 0 if a == b; < 0 if a < b; > 0 if a > b
echo("cmpIgnoreCase :", s1.... |
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 |... | #Oforth | Oforth | "abcd" "abcd" ==
"abcd" "abce" <>
"abcd" "abceed" <=
"abce" "abcd" >
"abcEEE" toUpper "ABCeee" toUpper == |
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... | #Groovy | Groovy | def str = 'alphaBETA'
println str.toUpperCase()
println str.toLowerCase() |
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... | #Haskell | Haskell | import Data.Char
s = "alphaBETA"
lower = map toLower s
upper = map toUpper s |
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 |... | #Groovy | Groovy | assert "abcd".startsWith("ab")
assert ! "abcd".startsWith("zn")
assert "abcd".endsWith("cd")
assert ! "abcd".endsWith("zn")
assert "abab".contains("ba")
assert ! "abab".contains("bb")
assert "abab".indexOf("bb") == -1 // not found flag
assert "abab".indexOf("ab") == 0
def indicesOf = { string, substring ->
if... |
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... | #Frink | Frink |
b = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
length[stringToBytes[b, "UTF-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... | #GAP | GAP | Length("abc");
# or same result with
Size("abc"); |
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... | #Maple | Maple | str := "Hello":
newstr := cat(str,", world!"):
str;
newstr; |
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... | #Mathcad | Mathcad | Carpenter := "Gort. " (Carpenter = "Gort. ")
|
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.
| #PL.2FI | PL/I | threeor5: procedure options (main); /* 8 June 2014 */
declare (i, n) fixed(10), sum fixed (31) static initial (0);
get (n);
put ('The number of multiples of 3 or 5 below ' || trim(n) || ' is');
do i = 1 to n-1;
if mod(i, 3) = 0 | mod(i, 5) = 0 then sum = sum + i;
end;
put edit ( trim(... |
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
| #Quackery | Quackery | [ temp put 0
[ over while
swap temp share /mod
rot + again ]
nip temp release ] is digitsum ( n n --> n )
1 10 digitsum echo sp
1234 10 digitsum echo sp
hex FE 16 digitsum echo sp
hex F0E 16 digitsum echo |
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
| #Raku | Raku | say [+] map * ** 2, 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
| #Raven | Raven | define sumOfSqrs use $lst
0 $lst each dup * +
[ 1 2 3 4] sumOfSqrs "Sum of squares: %d\n" print |
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... | #Python | Python | >>> s = ' \t \r \n String with spaces \t \r \n '
>>> s
' \t \r \n String with spaces \t \r \n '
>>> s.lstrip()
'String with spaces \t \r \n '
>>> s.rstrip()
' \t \r \n String with spaces'
>>> s.strip()
'String with spaces'
>>> |
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... | #Quackery | Quackery | /O> [ reverse trim reverse ] is trim-trailing ( $ --> $ )
... [ trim trim-trailing ] is trim-both-ends ( $ --> $ )
... $ ' a quick quack ' echo$ say "!" cr
... $ ' a quick quack ' trim echo$ say "!" cr
... $ ' a quick quack ' trim-trailing echo$ say "!" cr
... $ ' a quick quack ' trim-both-ends echo... |
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 |... | #LabVIEW | LabVIEW |
{S.slice 1 2 hello brave new world}
-> brave new
{W.slice 4 11 www.rosetta.org}
-> rosetta
|
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.
| #Prolog | Prolog | :- use_module(library(clpfd)).
sudoku(Rows) :-
length(Rows, 9), maplist(length_(9), Rows),
append(Rows, Vs), Vs ins 1..9,
maplist(all_distinct, Rows),
transpose(Rows, Columns), maplist(all_distinct, Columns),
Rows = [A,B,C,D,E,F,G,H,I],
blocks(A, B, C), blocks(D, E, F),... |
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... | #PicoLisp | PicoLisp | : (pack (cdr (chop "knight"))) # Remove first character
-> "night"
: (pack (head -1 (chop "socks"))) # Remove last character
-> "sock"
: (pack (cddr (rot (chop "brooms")))) # Remove first and last characters
-> "room" |
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... | #PL.2FI | PL/I |
declare s character (100) varying;
s = 'now is the time to come to the aid of the party';
if length(s) <= 2 then stop;
put skip list ('First character removed=' || substr(s,2) );
put skip list ('Last character removed=' || substr(s, 1, length(s)-1) );
put skip list ('One character from each end removed=' ||
subst... |
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.
| #Pascal | Pascal | my @list = ( 1, 2, 3 );
my ( $sum, $prod ) = ( 0, 1 );
$sum += $_ foreach @list;
$prod *= $_ foreach @list; |
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... | #LiveCode | LiveCode | repeat with i = 1 to 1000
add 1/(i^2) to summ
end repeat
put summ //1.643935 |
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 |... | #PowerShell | PowerShell | $extra = "little"
"Mary had a {0} lamb." -f $extra |
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 |... | #Prolog | Prolog | Extra = little,
format('Mary had a ~w lamb.', [Extra]), % display result
format(atom(Atom), 'Mary had a ~w lamb.', [Extra]). % ... or store it a variable |
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... | #Phix | Phix | ?filter("She was a soul stripper. She took my heart!","out","aei")
|
Subsets and Splits
Rosetta Code COBOL Python Hard Tasks
Identifies and retrieves challenging tasks that exist in both COBOL and Python, revealing cross-language programming patterns and difficulty levels for comparative analysis.
Rosetta Code Task Comparisons
Identifies tasks common to both COBOL and Python languages that are described as having difficulty levels, revealing cross-language task similarities and providing useful comparative programming examples.
SQL Code Examples from Training Data
Retrieves raw SQL code examples for the SQL language, which is basic data retrieval without meaningful analysis or patterns.
SQL Code Examples from Training Data
Retrieves raw SQL code examples for the SQL language, which is basic filtering that shows what data looks like but doesn't provide meaningful analysis or patterns.
Select Specific Languages Codes
Retrieves specific programming language names and codes from training data, providing basic filtering but limited analytical value beyond identifying these particular languages.