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/Stirling_numbers_of_the_second_kind
Stirling numbers of the second kind
Stirling numbers of the second kind, or Stirling partition numbers, are the number of ways to partition a set of n objects into k non-empty subsets. They are closely related to Bell numbers, and may be derived from them. Stirling numbers of the second kind obey the recurrence relation: S2(n, 0) and S2(0, k) = 0 ...
#zkl
zkl
fcn stirling2(n,k){ var seen=Dictionary(); // cache for recursion if(n==k) return(1); // (0.0)==1 if(n<1 or k<1) return(0); z1,z2 := "%d,%d".fmt(n-1,k), "%d,%d".fmt(n-1,k-1); if(Void==(s1 := seen.find(z1))){ s1 = seen[z1] = stirling2(n-1,k) } if(Void==(s2 := seen.find(z2))){ s2 = seen[z2] = st...
http://rosettacode.org/wiki/Straddling_checkerboard
Straddling checkerboard
Task Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits. Num...
#Go
Go
package main   import ( "fmt" "strings" )   func main() { key := ` 8752390146 ET AON RIS 5BC/FGHJKLM 0PQD.VWXYZU` p := "you have put on 7.5 pounds since I saw you." fmt.Println(p) c := enc(key, p) fmt.Println(c) fmt.Println(dec(key, c)) }   func enc(bd, pt string) (ct string) { enc...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#F.C5.8Drmul.C3.A6
Fōrmulæ
package main   import ( "fmt" "math/big" )   func main() { limit := 100 last := 12 unsigned := true s1 := make([][]*big.Int, limit+1) for n := 0; n <= limit; n++ { s1[n] = make([]*big.Int, limit+1) for k := 0; k <= limit; k++ { s1[n][k] = new(big.Int) } ...
http://rosettacode.org/wiki/String_append
String append
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 str = "foo" str += str print(str)
http://rosettacode.org/wiki/String_append
String append
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 |...
#EasyLang
EasyLang
a$ = "hello" a$ &= " world" print a$
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#C.23
C#
  using System; using System.Collections.Generic; using System.Linq;   namespace RosettaCode { static class StreamMerge { static IEnumerable<T> Merge2<T>(IEnumerable<T> source1, IEnumerable<T> source2) where T : IComparable { var q1 = new Queue<T>(source1); var q2 = new Q...
http://rosettacode.org/wiki/Straddling_checkerboard
Straddling checkerboard
Task Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits. Num...
#Haskell
Haskell
import Data.Char import Data.Map   charToInt :: Char -> Int charToInt c = ord c - ord '0'   -- Given a string, decode a single character from the string. -- Return the decoded char and the remaining undecoded string. decodeChar :: String -> (Char,String) decodeChar ('7':'9':r:rs) = (r,rs) decodeChar ('7':r:rs) = ("...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#Go
Go
package main   import ( "fmt" "math/big" )   func main() { limit := 100 last := 12 unsigned := true s1 := make([][]*big.Int, limit+1) for n := 0; n <= limit; n++ { s1[n] = make([]*big.Int, limit+1) for k := 0; k <= limit; k++ { s1[n][k] = new(big.Int) } ...
http://rosettacode.org/wiki/String_append
String append
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
  ;; Solution from Common Lisp and Racket (define-syntax-rule (set-append! str tail) (set! str (string-append str tail)))   (define name "Albert") → name   (set-append! name " de Jeumont-Schneidre") name → "Albert de Jeumont-Schneidre"  
http://rosettacode.org/wiki/String_append
String append
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 |...
#Elena
Elena
import extensions; import extensions'text;   public program() { var s := StringWriter.load("Hello"); s.append:" World";   console.printLine:s.readChar() }
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#C.2B.2B
C++
//#include <functional> #include <iostream> #include <vector>   template <typename C, typename A> void merge2(const C& c1, const C& c2, const A& action) { auto i1 = std::cbegin(c1); auto i2 = std::cbegin(c2);   while (i1 != std::cend(c1) && i2 != std::cend(c2)) { if (*i1 <= *i2) { action...
http://rosettacode.org/wiki/Straddling_checkerboard
Straddling checkerboard
Task Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits. Num...
#Icon_and_Unicon
Icon and Unicon
procedure main() StraddlingCheckerBoard("setup","HOLMESRTABCDFGIJKNPQUVWXYZ./", 3,7)   text := "One night. it was on the twentieth of March, 1888. I was returning" write("text = ",image(text)) write("encode = ",image(en := StraddlingCheckerBoard("encode",text))) write("decode = ",image(StraddlingCheckerBoard("decode"...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#Haskell
Haskell
import Text.Printf (printf) import Data.List (groupBy) import qualified Data.MemoCombinators as Memo   stirling1 :: Integral a => (a, a) -> a stirling1 = Memo.pair Memo.integral Memo.integral f where f (n, k) | n == 0 && k == 0 = 1 | n > 0 && k == 0 = 0 | k > n = 0 | otherwise ...
http://rosettacode.org/wiki/String_append
String append
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 |...
#Elixir
Elixir
iex(60)> s = "Hello" "Hello" iex(61)> s <> " World!" "Hello World!"
http://rosettacode.org/wiki/String_append
String append
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 |...
#Emacs_Lisp
Emacs Lisp
(defvar str "foo") (setq str (concat str "bar")) str ;=> "foobar"
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#11l
11l
F stern_brocot(predicate = series -> series.len < 20) V sb = [1, 1] V i = 0 L predicate(sb) sb [+]= [sum(sb[i .< i + 2]), sb[i + 1]] i++ R sb   V n_first = 15 print(("The first #. values:\n ".format(n_first))‘ ’stern_brocot(series -> series.len < :n_first)[0 .< n_first]) print()   V n_max = 10 ...
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#D
D
import std.range.primitives; import std.stdio;   // An output range for writing the elements of the example ranges struct OutputWriter { void put(E)(E e) if (!isInputRange!E) { stdout.write(e); } }   void main() { import std.range : only; merge2(OutputWriter(), only(1,3,5,7), only(2,4,6,8)); ...
http://rosettacode.org/wiki/Straddling_checkerboard
Straddling checkerboard
Task Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits. Num...
#J
J
'Esc Stop'=: '/.' 'Nums Alpha'=: '0123456789';'ABCDEFGHIJKLMNOPQRSTUVWXYZ' Charset=: Nums,Alpha,Stop   escapenum=: (,@:((; Esc&,)&>) Nums) rplc~ ] NB. escape numbers unescapenum=: ((, ; ' '&,@])"1 0 Nums"_) rplc~ ] NB. unescape coded numbers (x is escape code, y is cipher) expandKeyatUV=: 0:`[`(1...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#J
J
NB. agenda set by the test according to the definition test=: 1 i.~ (0 0&-: , 1 0&-:)@:*@:, , < s1=: 1:`0:`0:`($:&<: + (($: * [)~ <:)~)@.test s1&> table i. 13 +----+------------------------------------------------------------------------------------------+ |s1&>|0 1 2 3 4 ...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#Java
Java
  import java.math.BigInteger; import java.util.HashMap; import java.util.Map;   public class SterlingNumbersFirstKind {   public static void main(String[] args) { System.out.println("Unsigned Stirling numbers of the first kind:"); int max = 12; System.out.printf("n/k"); for ( int n ...
http://rosettacode.org/wiki/String_append
String append
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 |...
#Erlang
Erlang
1> S = "Hello". "Hello" 2> S ++ " world". "Hello world"
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Euphoria
Euphoria
  sequence string = "String"   printf(1,"%s\n",{string})   string &= " is now longer\n"   printf(1,"%s",{string})  
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#360_Assembly
360 Assembly
* Stern-Brocot sequence - 12/03/2019 STERNBR CSECT USING STERNBR,R13 base register B 72(R15) skip savearea DC 17F'0' savearea SAVE (14,12) save previous context ST R13,4(R15) link backward ...
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#Elixir
Elixir
defmodule StreamMerge do def merge2(file1, file2), do: mergeN([file1, file2])   def mergeN(files) do Enum.map(files, fn fname -> File.open!(fname) end) |> Enum.map(fn fd -> {fd, IO.read(fd, :line)} end) |> merge_loop end   defp merge_loop([]), do: :ok defp merge_loop(fdata) do {fd, min} = Enum...
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#Fortran
Fortran
SUBROUTINE FILEMERGE(N,INF,OUTF) !Merge multiple inputs into one output. INTEGER N !The number of input files. INTEGER INF(*) !Their unit numbers. INTEGER OUTF !The output file. INTEGER L(N) !The length of each current record. INTEGER LIST(0:N)!In sorted order. LOGICAL LI...
http://rosettacode.org/wiki/Straddling_checkerboard
Straddling checkerboard
Task Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits. Num...
#Java
Java
import java.util.HashMap; import java.util.Map; import java.util.regex.*;   public class StraddlingCheckerboard {   final static String[] keyvals = {"H:0", "O:1", "L:2", "M:4", "E:5", "S:6", "R:8", "T:9", "A:30", "B:31", "C:32", "D:33", "F:34", "G:35", "I:36", "J:37", "K:38", "N:39", "P:70", "Q:71",...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#jq
jq
# For efficiency, define the helper function for `stirling1/2` as a # top-level function so we can use it directly for constructing the table: # input: [m,j,cache] # output: [s, cache] def stirling1: . as [$m, $j, $cache] | "\($m),\($j)" as $key | $cache | if has($key) then [.[$key], .] e...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#Julia
Julia
using Combinatorics   const s1cache = Dict()   function stirlings1(n, k, signed::Bool=false) if signed == true && isodd(n - k) return -stirlings1(n, k) elseif haskey(s1cache, Pair(n, k)) return s1cache[Pair(n, k)] elseif n < 0 throw(DomainError(n, "n must be nonnegative")) elseif...
http://rosettacode.org/wiki/String_append
String append
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#F.23
F#
let mutable x = "foo" x <- x + "bar" printfn "%s" x
http://rosettacode.org/wiki/String_append
String append
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
"Hello, " "world!" append
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#11l
11l
F leaf_plot(&x) x.sort() V i = x[0] I/ 10 - 1 L(j) 0 .< x.len V d = x[j] I/ 10 L d > i i++ print(‘#.#3 |’.format((j != 0) * "\n", i), end' ‘’) print(‘ ’(x[j] % 10), end' ‘’) print()   V data = [ 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, ...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#8080_Assembly
8080 Assembly
puts: equ 9 ; CP/M syscall to print a string org 100h ;;; Generate the first 1200 elements of the Stern-Brocot sequence lxi b,600 ; 2 elements generated per loop lxi h,seq mov e,m ; Initialization inx h push h ; Save considered member pointer inx h ; Insertion pointer genseq: xthl ; Load considered member poin...
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#Go
Go
package main   import ( "container/heap" "fmt" "io" "log" "os" "strings" )   var s1 = "3 14 15" var s2 = "2 17 18" var s3 = "" var s4 = "2 3 5 7"   func main() { fmt.Print("merge2: ") merge2( os.Stdout, strings.NewReader(s1), strings.NewReader(s2)) fmt.Println...
http://rosettacode.org/wiki/Straddling_checkerboard
Straddling checkerboard
Task Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits. Num...
#JavaScript
JavaScript
<script> var alphabet=new Array("ESTONIA R","BCDFGHJKLM","PQUVWXYZ./") // scramble alphabet as you wish var prefixes=new Array("",alphabet[0].indexOf(" "),alphabet[0].lastIndexOf(" "))   function straddle(message){ var out="" message=message.toUpperCase() message=message.replace(/([0-9])/g,"/$1") // dumb way to...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#Kotlin
Kotlin
import java.math.BigInteger   fun main() { println("Unsigned Stirling numbers of the first kind:") val max = 12 print("n/k") for (n in 0..max) { print("%10d".format(n)) } println() for (n in 0..max) { print("%-3d".format(n)) for (k in 0..n) { print("%10s"....
http://rosettacode.org/wiki/String_append
String append
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
  /* Added by Aykayayciti Earl Lamont Montgomery April 10th, 2018 */   s1, s2 = "Hello", "Foo" > s1 + " World" printl(s2 + " bar")  
http://rosettacode.org/wiki/String_append
String append
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
\ Strings in Forth are simply named memory locations   create astring 256 allot \ create a "string"   s" Hello " astring PLACE \ initialize the string   s" World!" astring +PLACE \ append with "+place"
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#ACL2
ACL2
(defun insert (x xs) (cond ((endp xs) (list x)) ((> x (first xs)) (cons (first xs) (insert x (rest xs)))) (t (cons x xs))))   (defun isort (xs) (if (endp xs) nil (insert (first xs) (isort (rest xs)))))   (defun stem-and-leaf-bins (xs bin curr) (cond ((endp xs) (list cu...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#8086_Assembly
8086 Assembly
puts: equ 9 cpu 8086 bits 16 org 100h section .text ;;; Generate the first 1200 elemets of the Stern-Brocot sequence mov cx,600 ; 2 elements generated per loop mov si,seq mov di,seq+2 lodsb mov ah,al ; AH = predecessor genseq: lodsb ; AL = considered member add ah,al ; AH = sum xchg ah,al ; Swap them (AL = ...
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#Haskell
Haskell
-- stack runhaskell --package=conduit-extra --package=conduit-merge   import Control.Monad.Trans.Resource (runResourceT) import qualified Data.ByteString.Char8 as BS import Data.Conduit (($$), (=$=)) import Data.Conduit.Binary (sinkHandle, sourceFile) import...
http://rosettacode.org/wiki/Straddling_checkerboard
Straddling checkerboard
Task Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits. Num...
#Julia
Julia
  function straddlingcheckerboard(board, msg, doencode) lookup = Dict() reverselookup = Dict() row2 = row3 = slash = -1 function encode(x) s = "" for ch in replace(replace(uppercase(x), r"([01-9])", s";=;\1"), r";=;", slash) c = string(ch) if haskey(lookup, c) ...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
TableForm[Array[StirlingS1, {n = 12, k = 12} + 1, {0, 0}], TableHeadings -> {"n=" <> ToString[#] & /@ Range[0, n], "k=" <> ToString[#] & /@ Range[0, k]}] Max[Abs[StirlingS1[100, #]] & /@ Range[0, 100]]
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#Nim
Nim
import sequtils, strutils   proc s1(n, k: Natural): Natural = if k == 0: return ord(n == 0) if k > n: return 0 s1(n - 1, k - 1) + (n - 1) * s1(n - 1, k)   echo " k ", toSeq(0..12).mapIt(($it).align(2)).join(" ") echo " n" for n in 0..12: stdout.write ($n).align(2) for k in 0..n: stdout.write...
http://rosettacode.org/wiki/String_append
String append
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 main   character(len=:),allocatable :: str   str = 'hello' str = str//' world'   write(*,*) str   end program main  
http://rosettacode.org/wiki/String_append
String append
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   Var s = "String" s += " append" Print s Sleep
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#C
C
/* * RosettaCode example: Statistics/Normal distribution in C * * The random number generator rand() of the standard C library is obsolete * and should not be used in more demanding applications. There are plenty * libraries with advanced features (eg. GSL) with functions to calculate * the mean, the standard de...
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#Action.21
Action!
INCLUDE "D2:SORT.ACT" ;from the Action! Tool Kit   PROC Main() DEFINE len="121" BYTE ARRAY a(len)=[ 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 ...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#Action.21
Action!
PROC Generate(BYTE ARRAY seq INT POINTER count INT minCount,maxVal) INT i   seq(0)=1 seq(1)=1 count^=2 i=1 WHILE count^<minCount OR seq(count^-1)#maxVal AND seq(count^-2)#maxVal DO seq(count^)=seq(i-1)+seq(i) seq(count^+1)=seq(i) count^==+2 i==+1 OD RETURN   PROC PrintSeq(BYTE ARRAY seq INT count)...
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#Java
Java
import java.util.Iterator; import java.util.List; import java.util.Objects;   public class StreamMerge { private static <T extends Comparable<T>> void merge2(Iterator<T> i1, Iterator<T> i2) { T a = null, b = null;   while (i1.hasNext() || i2.hasNext()) { if (null == a && i1.hasNext()) { ...
http://rosettacode.org/wiki/Straddling_checkerboard
Straddling checkerboard
Task Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits. Num...
#Kotlin
Kotlin
// version 1.2.0   val board = "ET AON RISBCDFGHJKLMPQ/UVWXYZ." val digits = "0123456789" val rows = " 26" val escape = "62" val key = "0452"   fun encrypt(message: String): String { val msg = message.toUpperCase() .filter { (it in board || it in digits) && it !in " /" } val sb = StringBuil...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#Perl
Perl
use strict; use warnings; use bigint; use feature 'say'; use feature 'state'; no warnings 'recursion'; use List::Util qw(max);   sub Stirling1 { my($n, $k) = @_; return 1 unless $n || $k; return 0 unless $n && $k; state %seen; return ($seen{"{$n-1}|{$k-1}"} //= Stirling1($n-1, $k-1)) + ($...
http://rosettacode.org/wiki/String_append
String append
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 sString As String = "Hello "   sString &= "World!" Print sString   End
http://rosettacode.org/wiki/String_append
String append
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 |...
#Genie
Genie
[indent=4] /* String append, in Genie */ init str:string = "Hello" str += ", world"   print str
http://rosettacode.org/wiki/String_append
String append
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 |...
#GlovePIE
GlovePIE
var.string="This is " var.string+="Sparta!" debug=var.string
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#C.23
C#
using System; using MathNet.Numerics.Distributions; using MathNet.Numerics.Statistics;   class Program { static void RunNormal(int sampleSize) { double[] X = new double[sampleSize]; var norm = new Normal(new Random()); norm.Samples(X);   const int numBuckets = 10; var his...
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#Ada
Ada
  with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Gnat.Heap_Sort_G; procedure stemleaf is data : array(Natural Range <>) of Integer := ( 0,12,127,28,42,39,113, 42,18,44,118,44,37,113,124,37,48,127,36,29,31, 125,139,131,115,105,132,104,123,35,113,122,42,117,119,58,109,23,105...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#Ada
Ada
with Ada.Text_IO, Ada.Containers.Vectors;   procedure Sequence is   package Vectors is new Ada.Containers.Vectors(Index_Type => Positive, Element_Type => Positive); use type Vectors.Vector;   type Sequence is record List: Vectors.Vector; Index: Positive; -- This implements some form of ...
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#Julia
Julia
  function merge(stream1, stream2, T=Char) if !eof(stream1) && !eof(stream2) b1 = read(stream1, T) b2 = read(stream2, T) while !eof(stream1) && !eof(stream2) if b1 <= b2 print(b1) if !eof(stream1) b1 = read(stream1, T) ...
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#Kotlin
Kotlin
// version 1.2.21   import java.io.File   fun merge2(inputFile1: String, inputFile2: String, outputFile: String) { val file1 = File(inputFile1) val file2 = File(inputFile2) require(file1.exists() && file2.exists()) { "Both input files must exist" } val reader1 = file1.bufferedReader() val reader2 = ...
http://rosettacode.org/wiki/Straddling_checkerboard
Straddling checkerboard
Task Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits. Num...
#Lua
Lua
  local brd = { "HOL MES RT", "ABCDFGIJKN", "PQUVWXYZ./" } local dicE, dicD, s1, s2 = {}, {}, 0, 0   function dec( txt ) local i, numb, s, t, c = 1, false while( i < #txt ) do c = txt:sub( i, i ) if not numb then if tonumber( c ) == s1 then i = i + 1; s = string.forma...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#Phix
Phix
with javascript_semantics include mpfr.e constant lim = 100, lim1 = lim+1, last = 12 bool unsigned = true sequence s1 = repeat(0,lim1) for n=1 to lim1 do s1[n] = mpz_inits(lim1) end for mpz_set_si(s1[1][1],1) mpz {t, m100} = mpz_inits(2) for n=1 to lim do for k=1 to n do mpz_set_si(...
http://rosettacode.org/wiki/String_append
String append
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
s := "foo" s += "bar"
http://rosettacode.org/wiki/String_append
String append
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 |...
#Gosu
Gosu
// Example 1 var s = "a" s += "b" s += "c" print(s)   // Example 2 print("a" + "b" + "c")   // Example 3 var a = "a" var b = "b" var c = "c" print("${a}${b}${c}")
http://rosettacode.org/wiki/String_append
String append
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
  class Append{ static void main(String[] args){ def c="Hello "; def d="world"; def e=c+d; println(e); } }  
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#C.2B.2B
C++
#include <random> #include <map> #include <string> #include <iostream> #include <cmath> #include <iomanip>   int main( ) { std::random_device myseed ; std::mt19937 engine ( myseed( ) ) ; std::normal_distribution<> normDistri ( 2 , 3 ) ; std::map<int , int> normalFreq ; int sum = 0 ; //holds the sum of th...
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#AutoHotkey
AutoHotkey
SetWorkingDir %A_ScriptDir% #NoEnv Data := "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 ...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#ALGOL_68
ALGOL 68
BEGIN # find members of the Stern-Brocot sequence: starting from 1, 1 the # # subsequent members are the previous two members summed followed by # # the previous # # iterative Greatest Common Divisor routine, returns the gcd of m and n # ...
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#Nim
Nim
import streams,strutils let stream1 = newFileStream("file1") stream2 = newFileStream("file2") while not stream1.atEnd and not stream2.atEnd: echo (if stream1.peekLine.parseInt > stream2.peekLine.parseInt: stream2.readLine else: stream1.readLine)   for line in stream1.lines: echo line for line in stream2.lines: ...
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#Perl
Perl
use strict; use warnings; use English; use String::Tokenizer; use Heap::Simple;   my $stream1 = <<"END_STREAM_1"; Integer vel neque ligula. Etiam a ipsum a leo eleifend viverra sit amet ac arcu. Suspendisse odio libero, ullamcorper eu sem vitae, gravida dignissim ipsum. Aenean tincidunt commodo feugiat. Nunc viverra do...
http://rosettacode.org/wiki/Straddling_checkerboard
Straddling checkerboard
Task Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits. Num...
#M2000_Interpreter
M2000 Interpreter
  module Straddling_checkerboard { function encrypt$(message$, alphabet) { message$=filter$(ucase$(message$),"-/,. ") def num1, num2 num1=instr(alphabet#val$(0)," ") num2=instr(alphabet#val$(0)," ", num1+1)-1 num1-- escapenum=instr(alphabet#val$(2),"/")-1 escapenum1=instr(alphabet#val$(2),".")-1 num0=-...
http://rosettacode.org/wiki/Straddling_checkerboard
Straddling checkerboard
Task Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits. Num...
#Nim
Nim
import strutils, tables   const FullStop = '.' Escape = '/'   type Checkerboard = object encryptTable: Table[char, string] decryptTable: Table[string, char]     proc initCheckerboard(digits: string; row1, row2, row3: string): Checkerboard = ## Initialize a checkerboard with given digits in row 0 and the follo...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#Prolog
Prolog
:- dynamic stirling1_cache/3.   stirling1(N, N, 1):-!. stirling1(_, 0, 0):-!. stirling1(N, K, 0):- K > N, !. stirling1(N, K, L):- stirling1_cache(N, K, L), !. stirling1(N, K, L):- N1 is N - 1, K1 is K - 1, stirling1(N1, K, L1), stirling1(N1, K1, L2), !, L is L2 + (N - 1) * L1, assertz(stirling1_cache(N, K, L...
http://rosettacode.org/wiki/String_append
String append
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
  main = putStrLn ("Hello" ++ "World")  
http://rosettacode.org/wiki/String_append
String append
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 |...
#Icon_and_Unicon
Icon and Unicon
  procedure main() s := "foo" s ||:= "bar" write(s) end  
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#D
D
import std.stdio, std.random, std.math, std.range, std.algorithm, statistics_basic;   struct Normals { double mu, sigma; double[2] state; size_t index = state.length; enum empty = false;   void popFront() pure nothrow { index++; }   @property double front() { if (index >= state.le...
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#AWK
AWK
  # syntax: GAWK -f STEM-AND-LEAF_PLOT.AWK # # sorting: # PROCINFO["sorted_in"] is used by GAWK # SORTTYPE is used by Thompson Automation's TAWK # BEGIN { data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " \ "125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 ...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#ALGOL-M
ALGOL-M
begin integer array S[1:1200]; integer i,ok;   integer function gcd(a,b); integer a,b; gcd := if a>b then gcd(a-b,b) else if a<b then gcd(a,b-a) else a;   integer function first(n); integer n; begin integer i; i := 1; while S[i]<>n do i := i + 1; first := i; end;   S[1] := S[2] := 1; for i ...
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#Phix
Phix
without js -- file i/o include builtins/pqueue.e procedure add(integer fn, pq) object line = gets(fn) if line=-1 then close(fn) else pq_add({fn,line}, pq) end if end procedure -- setup (optional/remove if files already exist) constant data = {"Line 001\nLine 008\nLine 017\n", ...
http://rosettacode.org/wiki/Straddling_checkerboard
Straddling checkerboard
Task Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits. Num...
#Perl
Perl
use strict; use warnings; use feature 'say'; use List::Util <min max>;   my(%encode,%decode,@table);   sub build { my($u,$v,$alphabet) = @_; my(@flat_board,%p2c,%c2p); my $numeric_escape = '/';   @flat_board = split '', uc $alphabet; splice @flat_board, min($u,$v), 0, undef; splice @flat_board, ...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#PureBasic
PureBasic
EnableExplicit #MAX=12 #LZ=10 #SP$=" " Dim s1.i(#MAX,#MAX) Define n.i,k.i,x.i,s$,esc$   s1(0,0)=1 esc$=#ESC$+"[8;24;170t" ; Enlarges the console window   For n=0 To #MAX For k=1 To n s1(n,k)=s1(n-1,k-1)-(n-1)*s1(n-1,k) Next Next   If OpenConsole() Print(esc$) PrintN(~"Signed Stirling numbers of the first...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#Python
Python
  computed = {}   def sterling1(n, k): key = str(n) + "," + str(k)   if key in computed.keys(): return computed[key] if n == k == 0: return 1 if n > 0 and k == 0: return 0 if k > n: return 0 result = sterling1(n - 1, k - 1) + (n - 1) * sterling1(n - 1, k) computed[key] = result return result   print("Un...
http://rosettacode.org/wiki/String_append
String append
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 |...
#J
J
s=: 'new' s new s=: s,' value' NB. append is in-place s new value
http://rosettacode.org/wiki/String_append
String append
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 |...
#Java
Java
String sa = "Hello"; sa += ", World!"; System.out.println(sa);   StringBuilder ba = new StringBuilder(); ba.append("Hello"); ba.append(", World!"); System.out.println(ba.toString());
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#Elixir
Elixir
defmodule Statistics do def normal_distribution(n, w\\5) do {sum, sum2, hist} = generate(n, w) mean = sum / n stddev = :math.sqrt(sum2 / n - mean*mean)   IO.puts "size: #{n}" IO.puts "mean: #{mean}" IO.puts "stddev: #{stddev}" {min, max} = Map.to_list(hist) |> Enum.fil...
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#Factor
Factor
USING: assocs formatting kernel math math.functions math.statistics random sequences sorting ;   2,000,000 [ 0 1 normal-random-float ] replicate  ! make data set dup [ mean ] [ population-std ] bi  ! calculate and show "Mean: %f\nStdev: %f\n\n" printf  ! mean and stddev   [ 10 * floor 10 ...
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#BBC_BASIC
BBC BASIC
INSTALL @lib$+"SORTLIB" Sort% = FN_sortinit(0, 0)   DIM Data%(120) Data%() = \ \ 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, \ \ 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, \ \ 35, 113, 122, 42, 117, 119, 58, 109, 23, 105,...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#Amazing_Hopper
Amazing Hopper
  #include <flow.h> #include <flow-flow.h>   DEF-MAIN(argv,argc) CLR-SCR SET( amount, 1200 ) DIM(amount) AS-ONES( Stern )   /* Generate Stern-Brocot sequence: */ GOSUB( Generate Sequence ) PRNL( "Find 15 first: ", [1:19] CGET(Stern) )   /* show Stern-Brocot sequence: */ SET( i, 1 ), ITERATE( ++i, ...
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#PicoLisp
PicoLisp
(de streamMerge @ (let Heap (make (while (args) (let? Fd (next) (if (in Fd (read)) (link (cons @ Fd)) (close Fd) ) ) ) ) (make (while Heap (link (caar (setq Heap (sort Heap)))) (if (in (cdar Heap) (re...
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#Python
Python
import heapq import sys   sources = sys.argv[1:] for item in heapq.merge(open(source) for source in sources): print(item)
http://rosettacode.org/wiki/State_name_puzzle
State name puzzle
Background This task is inspired by Mark Nelson's DDJ Column "Wordplay" and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition [1] and originally attributed to David Edelheit. The challenge was to take the names of two U.S. States, mix them all together, then rearrange the letters to form the...
#11l
11l
V states = [‘Alabama’, ‘Alaska’, ‘Arizona’, ‘Arkansas’, ‘California’, ‘Colorado’, ‘Connecticut’, ‘Delaware’, ‘Florida’, ‘Georgia’, ‘Hawaii’, ‘Idaho’, ‘Illinois’, ‘Indiana’, ‘Iowa’, ‘Kansas’, ‘Kentucky’, ‘Louisiana’, ‘Maine’, ‘Maryland’, ‘Massachusetts’, ‘Michigan’, ‘Minnesota’, ‘Mississippi’, ‘Missouri’, ‘Montana’, ‘Ne...
http://rosettacode.org/wiki/Start_from_a_main_routine
Start from a main routine
Some languages (like Gambas and Visual Basic) support two startup modes.   Applications written in these languages start with an open window that waits for events, and it is necessary to do some trickery to cause a main procedure to run instead.   Data driven or event driven languages may also require similar tricker...
#6502_Assembly
6502 Assembly
with Ada.Text_IO; procedure Foo is begin Ada.Text_IO.Put_Line("Bar"); end Foo;
http://rosettacode.org/wiki/Straddling_checkerboard
Straddling checkerboard
Task Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The checkerboard should take a 28 character alphabet (A-Z plus a full stop and an escape character) and two different numbers representing the blanks in the first row. The output will be a series of decimal digits. Num...
#Phix
Phix
with javascript_semantics function read_table(string cb) sequence encode = repeat("",128), decode = repeat(0,128), row = {0} if length(cb)!=30 then crash("table wrong length") end if for i=1 to 30 do integer c = cb[i] if c=' ' then row &= i-1 els...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#Quackery
Quackery
[ dip number$ over size - space swap of swap join echo$ ] is justify ( n n --> )   [ table ] is s1table ( n --> n )   [ swap 101 * + s1table ] is s1 ( n n --> n )   101 times [ i^ 101 times [ dup i^ [ over 0 = over 0 = and iff ...
http://rosettacode.org/wiki/Stirling_numbers_of_the_first_kind
Stirling numbers of the first kind
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coeffici...
#Raku
Raku
sub Stirling1 (Int \n, Int \k) { return 1 unless n || k; return 0 unless n && k; state %seen; (%seen{"{n - 1}|{k - 1}"} //= Stirling1(n - 1, k - 1)) + (n - 1) * (%seen{"{n - 1}|{k}"} //= Stirling1(n - 1, k)) }   my $upto = 12;   my $mx = (1..^$upto).map( { Stirling1($upto, $_) } ).max.chars;   put '...
http://rosettacode.org/wiki/String_append
String append
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 |...
#JavaScript
JavaScript
var s1 = "Hello"; s1 += ", World!"; print(s1);   var s2 = "Goodbye"; // concat() returns the strings together, but doesn't edit existing string // concat can also have multiple parameters print(s2.concat(", World!"));
http://rosettacode.org/wiki/String_append
String append
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 |...
#jq
jq
"Hello" | . += ", world!"   ["Hello"] | .[0] += ", world!" | .[0]   { "greeting": "Hello"} | .greeting += ", world!" | .greeting
http://rosettacode.org/wiki/Statistics/Normal_distribution
Statistics/Normal distribution
The Normal (or Gaussian) distribution is a frequently used distribution in statistics. While most programming languages provide a uniformly distributed random number generator, one can derive normally distributed random numbers from a uniform generator. The task Take a uniform random number generator and create a ...
#Fortran
Fortran
program Normal_Distribution implicit none   integer, parameter :: i64 = selected_int_kind(18) integer, parameter :: r64 = selected_real_kind(15) integer(i64), parameter :: samples = 1000000_i64 real(r64) :: mean, stddev real(r64) :: sumn = 0, sumnsq = 0 integer(i64) :: n = 0 integer(i64) :: bin(-50:50)...
http://rosettacode.org/wiki/Stem-and-leaf_plot
Stem-and-leaf plot
Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 11...
#C
C
#include <stdio.h> #include <stdlib.h>   int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; }   void leaf_plot(int *x, int len) { int i, j, d;   qsort(x, len, sizeof(int), icmp);   i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; ...
http://rosettacode.org/wiki/Stern-Brocot_sequence
Stern-Brocot sequence
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence. The first and second members of the sequence are both 1:     1, 1 Start by considering the second member of the sequence Sum the considered member of the sequence and its prece...
#APL
APL
task←{ stern←{⍵{ ⍺←0 ⋄ ⍺⍺≤⍴⍵:⍺⍺↑⍵ (⍺+1)∇⍵,(+/,2⊃⊣)2↑⍺↓⍵ }1 1} seq←stern 1200 ⍝ Cache 1200 elements ⎕←'First 15 elements:',15↑seq ⎕←'Locations of 1..10:',seq⍳⍳10 ⎕←'Location of 100:',seq⍳100 ⎕←'All GCDs 1:','no' 'yes'[1+1∧.=2∨/1000↑seq] }
http://rosettacode.org/wiki/Stream_merge
Stream merge
2-stream merge Read two sorted streams of items from external source (e.g. disk, or network), and write one stream of sorted items to external sink. Common algorithm: keep 1 buffered item from each source, select minimal of them, write it, fetch another item from that stream from which the written item was. N-strea...
#Racket
Racket
;; This module produces a sequence that merges streams in order (by <) #lang racket/base (require racket/stream)   (define-values (tl-first tl-rest tl-empty?) (values stream-first stream-rest stream-empty?))   (define-struct merged-stream (< ss v ss′) #:mutable ; sadly, so we don't have to redo potentially expensiv...