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/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#JavaScript
JavaScript
var jortSort = function( array ) {   // sort the array var originalArray = array.slice(0); array.sort( function(a,b){return a - b} );   // compare to see if it was originally sorted for (var i = 0; i < originalArray.length; ++i) { if (originalArray[i] !== array[i]) return false; }   return true; };
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#jq
jq
def jortsort: . == sort;
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#F.23
F#
  let fN jewels stones=stones|>Seq.filter(fun n->Seq.contains n jewels)|>Seq.length printfn "%d" (fN "aA" "aAAbbbb")  
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Factor
Factor
USING: kernel prettyprint sequences ;   : count-jewels ( stones jewels -- n ) [ member? ] curry count ;   "aAAbbbb" "aA" "ZZ" "z" [ count-jewels . ] 2bi@
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#FreeBASIC
FreeBASIC
function gcdp( a as uinteger, b as uinteger ) as uinteger if b = 0 then return a return gcdp( b, a mod b ) end function   function gcd(a as integer, b as integer) as uinteger return gcdp( abs(a), abs(b) ) end function   function jacobi( a as uinteger, n as uinteger ) as integer if gcd(a, n)<>1 then retu...
http://rosettacode.org/wiki/Knuth_shuffle
Knuth shuffle
The   Knuth shuffle   (a.k.a. the Fisher-Yates shuffle)   is an algorithm for randomly shuffling the elements of an array. Task Implement the Knuth shuffle for an integer array (or, if possible, an array of any type). Specification Given an array items with indices ranging from 0 to last, the algorithm can be d...
#Scala
Scala
def shuffle[T](a: Array[T]) = { for (i <- 1 until a.size reverse) { val j = util.Random nextInt (i + 1) val t = a(i) a(i) = a(j) a(j) = t } a }
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#FreeBASIC
FreeBASIC
Sub Evaluation Dim As Integer i, lo = 1, hi = 100 Dim As Double temp = 0 For i = lo To hi temp += (1/i) ''r(i) Next i Print temp End Sub   Evaluation Sleep
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Go
Go
package main   import "fmt"   var i int   func sum(i *int, lo, hi int, term func() float64) float64 { temp := 0.0 for *i = lo; *i <= hi; (*i)++ { temp += term() } return temp }   func main() { fmt.Printf("%f\n", sum(&i, 1, 100, func() float64 { return 1.0 / float64(i) })) }
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Jsish
Jsish
/* jortSort in Jsish, based on the original satire, modified for jsish */ var jortSort = function(arr:array):boolean { // make a copy var originalArray = arr.slice(0); // sort arr.sort( function(a,b) { return a - b; } ); // compare to see if it was originally sorted for (var i = 0; i < originalA...
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Euphoria
Euphoria
  function number_of(object jewels, object stones) -- why limit ourselves to strings? integer ct = 0 for i = 1 to length(stones) do ct += find(stones[i],jewels) != 0 end for return ct end function   ? number_of("aA","aAAbbbb") ? number_of("z","ZZ") ? number_of({1,"Boo",3},{1,2,3,'A',"Boo",3}) -- mig...
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#FreeBASIC
FreeBASIC
  function contar_joyas(piedras as string, joyas as string) as integer dim as integer bc, cont: cont = 0 for i as integer = 1 to len(piedras) bc = instr(1, joyas, mid(piedras, i, 1)) if bc <> 0 then cont += 1 next i contar_joyas = cont end function   print contar_joyas("aAAbbbb", "aA") p...
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#Go
Go
package main   import ( "fmt" "log" "math/big" )   func jacobi(a, n uint64) int { if n%2 == 0 { log.Fatal("'n' must be a positive odd integer") } a %= n result := 1 for a != 0 { for a%2 == 0 { a /= 2 nn := n % 8 if nn == 3 || nn == 5 { ...
http://rosettacode.org/wiki/Knuth_shuffle
Knuth shuffle
The   Knuth shuffle   (a.k.a. the Fisher-Yates shuffle)   is an algorithm for randomly shuffling the elements of an array. Task Implement the Knuth shuffle for an integer array (or, if possible, an array of any type). Specification Given an array items with indices ranging from 0 to last, the algorithm can be d...
#Scheme
Scheme
#!r6rs (import (rnrs base (6)) (srfi :27 random-bits))   (define (semireverse li n) (define (continue front back n) (cond ((null? back) front) ((zero? n) (cons (car back) (append front (cdr back)))) (else (continue (cons (car back) front) (cdr back) (- n 1))))) (continue '() li n))   (...
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Groovy
Groovy
def sum = { i, lo, hi, term -> (lo..hi).sum { i.value = it; term() } } def obj = [:] println (sum(obj, 1, 100, { 1 / obj.value }))
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Haskell
Haskell
import Control.Monad.ST import Data.STRef   sum_ :: STRef s Double -> Double -> Double -> ST s Double -> ST s Double sum_ ref_i lo hi term = sum <$> mapM ((>> term) . writeSTRef ref_i) [lo .. hi]   foo :: Double foo = runST $ do i <- newSTRef undefined -- initial value doesn't matter sum_ i 1 100 $ recip <$> r...
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Julia
Julia
  jortsort(A) = sort(A) == A  
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#K
K
jortsort:{x~x@<x}
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Go
Go
package main   import ( "fmt" "strings" )   func js(stones, jewels string) (n int) { for _, b := range []byte(stones) { if strings.IndexByte(jewels, b) >= 0 { n++ } } return }   func main() { fmt.Println(js("aAAbbbb", "aA")) }
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Haskell
Haskell
jewelCount :: Eq a => [a] -> [a] -> Int jewelCount jewels = foldr go 0 where go c | c `elem` jewels = succ | otherwise = id   --------------------------- TEST ------------------------- main :: IO () main = mapM_ print $ uncurry jewelCount <$> [("aA", "aAAbbbb"), ("z", "ZZ")]  
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#Haskell
Haskell
jacobi :: Integer -> Integer -> Integer jacobi 0 1 = 1 jacobi 0 _ = 0 jacobi a n = let a_mod_n = rem a n in if even a_mod_n then case rem n 8 of 1 -> jacobi (div a_mod_n 2) n 3 -> negate $ jacobi (div a_mod_n 2) n 5 -> negate $ jacobi (div a_mod_n 2) n ...
http://rosettacode.org/wiki/Knuth_shuffle
Knuth shuffle
The   Knuth shuffle   (a.k.a. the Fisher-Yates shuffle)   is an algorithm for randomly shuffling the elements of an array. Task Implement the Knuth shuffle for an integer array (or, if possible, an array of any type). Specification Given an array items with indices ranging from 0 to last, the algorithm can be d...
#Scratch
Scratch
$ include "seed7_05.s7i";   const type: intArray is array integer;   const proc: shuffle (inout intArray: a) is func local var integer: i is 0; var integer: k is 0; var integer: tmp is 0; begin for i range maxIdx(a) downto 2 do k := rand(1, i); tmp := a[i]; a[i] := a[k]; a[k]...
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Huginn
Huginn
harmonic_sum( i, lo, hi, term ) { temp = 0.0; i *= 0.0; i += lo; while ( i <= hi ) { temp += term(); i += 1.0; } return ( temp ); }   main() { i = 0.0; print( "{}\n".format( harmonic_sum( i, 1.0, 100.0, @[i](){ 1.0 / i; } ) ...
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Icon_and_Unicon
Icon and Unicon
record mutable(value) # record wrapper to provide mutable access to immutable types   procedure main() A := mutable() write( sum(A, 1, 100, create 1.0/A.value) ) end   procedure sum(A, lo, hi, term) temp := 0 every A.value := lo to hi do temp +:= @^term return temp end
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Kotlin
Kotlin
// version 1.0.6   fun <T> jortSort(a: Array<T>): Boolean { val b = a.copyOf() b.sort() for (i in 0 until a.size) if (a[i] != b[i]) return false return true }   fun <T> printResults(a: Array<T>) { println(a.joinToString(" ") + " => " + if (jortSort(a)) "sorted" else "not sorted") }   fun mai...
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#J
J
  NB. jewels sums a raveled equality table NB. use: x jewels y x are the stones, y are the jewels. intersect =: -.^:2 jewels =: ([: +/ [: , =/~) ~.@:intersect&Alpha_j_   'aAAbbbb ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz' jewels&>&;: 'aA ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'...
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Java
Java
import java.util.HashSet; import java.util.Set;   public class App { private static int countJewels(String stones, String jewels) { Set<Character> bag = new HashSet<>(); for (char c : jewels.toCharArray()) { bag.add(c); }   int count = 0; for (char c : stones.toCh...
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#J
J
  NB. direct translation of the Lua program found NB. at the wikipedia entry incorporated here in comments.   NB.function jacobi(n, k) jacobi=: dyad define every   k=. x NB. k is the left argument n=. y NB. n is the right hand argument   NB.assert(k > 0 and k % 2 == 1) assert. (k > 0) *. 1 = 2 | k   NB.n = n % ...
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#Java
Java
    public class JacobiSymbol {   public static void main(String[] args) { int max = 30; System.out.printf("n\\k "); for ( int k = 1 ; k <= max ; k++ ) { System.out.printf("%2d ", k); } System.out.printf("%n"); for ( int n = 1 ; n <= max ; n += 2 ) { ...
http://rosettacode.org/wiki/Knuth_shuffle
Knuth shuffle
The   Knuth shuffle   (a.k.a. the Fisher-Yates shuffle)   is an algorithm for randomly shuffling the elements of an array. Task Implement the Knuth shuffle for an integer array (or, if possible, an array of any type). Specification Given an array items with indices ranging from 0 to last, the algorithm can be d...
#Seed7
Seed7
$ include "seed7_05.s7i";   const type: intArray is array integer;   const proc: shuffle (inout intArray: a) is func local var integer: i is 0; var integer: k is 0; var integer: tmp is 0; begin for i range maxIdx(a) downto 2 do k := rand(1, i); tmp := a[i]; a[i] := a[k]; a[k]...
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#J
J
jensen=: monad define 'name lo hi expression'=. y temp=. 0 for_n. lo+i.1+hi-lo do. (name)=. n temp=. temp + ".expression end. )
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Java
Java
import java.util.function.*; import java.util.stream.*;   public class Jensen { static double sum(int lo, int hi, IntToDoubleFunction f) { return IntStream.rangeClosed(lo, hi).mapToDouble(f).sum(); }   public static void main(String args[]) { System.out.println(sum(1, 100, (i -> 1.0/i))); ...
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Lua
Lua
function copy (t) local new = {} for k, v in pairs(t) do new[k] = v end return new end   function jortSort (array) local originalArray = copy(array) table.sort(array) for i = 1, #originalArray do if originalArray[i] ~= array[i] then return false end end return true end
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Maple
Maple
jortSort := proc(arr) local copy: copy := sort(Array([seq(arr[i], i=1..numelems(arr))])): return ArrayTools:-IsEqual(copy,arr): end proc: #Examples jortSort(Array([5,6,7,2,1])); jortSort(Array([-5,0,7,12,21])); jortSort(Array(StringTools:-Explode("abcdefg")));
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#JavaScript
JavaScript
(() => {   // jewelCount :: String -> String -> Int const jewelCount = (j, s) => { const js = j.split(''); return s.split('') .reduce((a, c) => js.includes(c) ? a + 1 : a, 0) };   // TEST ----------------------------------------------- return [ ['aA', 'aAAbbbb...
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#jq
jq
$ jq -n --arg stones aAAbbbb --arg jewels aA ' [$stones|split("") as $s|$jewels|split("") as $j|$s[]| select(. as $c|$j|contains([$c]))]|length'
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#jq
jq
  def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .; def rpad($len): tostring | ($len - length) as $l | . + (" " * $l)[:$l];   def jacobi(a; n): {a: (a % n), n: n, result: 1} | until(.a == 0; until( .a % 2 != 0; .a /= 2 | if (.n % 8) | IN(3, 5) then ....
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#Julia
Julia
function jacobi(a, n) a %= n result = 1 while a != 0 while iseven(a) a ÷= 2 ((n % 8) in [3, 5]) && (result *= -1) end a, n = n, a (a % 4 == n % 4 == 3) && (result *= -1) a %= n end return n == 1 ? result : 0 end   print(" Table of jacob...
http://rosettacode.org/wiki/Knuth_shuffle
Knuth shuffle
The   Knuth shuffle   (a.k.a. the Fisher-Yates shuffle)   is an algorithm for randomly shuffling the elements of an array. Task Implement the Knuth shuffle for an integer array (or, if possible, an array of any type). Specification Given an array items with indices ranging from 0 to last, the algorithm can be d...
#SenseTalk
SenseTalk
set list to 1..9 -- a range, will become a list as needed set last to the number of items in list   repeat with i = last down to 2 -- in SenseTalk, the first index in a list is 1 set j = random (1,i-1) set [item i of list, item j of list] to [item j of list, item i of list] -- swap items end repeat   put list
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#JavaScript
JavaScript
var obj;   function sum(o, lo, hi, term) { var tmp = 0; for (o.val = lo; o.val <= hi; o.val++) tmp += term(); return tmp; }   obj = {val: 0}; alert(sum(obj, 1, 100, function() {return 1 / obj.val}));
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Joy
Joy
100 [0] [[1.0 swap /] dip +] primrec.
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
jortSort[list_] := list == Sort[list]; Print[jortSort[Range[100]]]; Print[jortSort[RandomSample[Range[100]]]];
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Nim
Nim
import algorithm   func jortSort[T](a: openArray[T]): bool = a == a.sorted()   proc test[T](a: openArray[T]) = echo a, " is ", if a.jortSort(): "" else: "not ", "sorted"   test([1, 2, 3]) test([2, 3, 1]) echo "" test(['a', 'b', 'c']) test(['c', 'a', 'b'])
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Julia
Julia
module Jewels   count(s, j) = Base.count(x ∈ j for x in s)   end # module Jewels
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Kotlin
Kotlin
// Version 1.2.40   fun countJewels(s: String, j: String) = s.count { it in j }   fun main(args: Array<String>) { println(countJewels("aAAbbbb", "aA")) println(countJewels("ZZ", "z")) }
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#Kotlin
Kotlin
fun jacobi(A: Int, N: Int): Int { assert(N > 0 && N and 1 == 1) var a = A % N var n = N var result = 1 while (a != 0) { var aMod4 = a and 3 while (aMod4 == 0) { // remove factors of four a = a shr 2 aMod4 = a and 3 } if (aMod4 == 2) { ...
http://rosettacode.org/wiki/Knuth_shuffle
Knuth shuffle
The   Knuth shuffle   (a.k.a. the Fisher-Yates shuffle)   is an algorithm for randomly shuffling the elements of an array. Task Implement the Knuth shuffle for an integer array (or, if possible, an array of any type). Specification Given an array items with indices ranging from 0 to last, the algorithm can be d...
#Sidef
Sidef
func knuth_shuffle(a) { for i (a.len ^.. 1) { var j = i.irand a[i, j] = a[j, i] } return a }   say knuth_shuffle(@(1..10))
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#jq
jq
def sum(lo; hi; term): reduce range(lo; hi+1) as $i (0; . + ($i|term));   # The task: sum(1;100;1/.)
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Julia
Julia
macro sum(i, loname, hiname, term) return quote lo = $loname hi = $hiname tmp = 0.0 for i in lo:hi tmp += $term end return tmp end end   i = 0 @sum(i, 1, 100, 1.0 / i)
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Objeck
Objeck
function : JortSort(elems : CompareVector) ~ Bool { sorted := CompareVector->New(elems); sorted->Sort();   each(i : sorted) { if(sorted->Get(i)->Compare(elems->Get(i)) <> 0) { return false; }; };   return true; }
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#OCaml
OCaml
let jortSortList lst = lst = List.sort compare lst
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Lambdatalk
Lambdatalk
  {def countjewels {def countjewels.r {lambda {:a :b :c} {if {A.empty? :a} then :c else {countjewels.r {A.rest :a}  :b {if {= {A.in? {A.first :a} :b} -1} then :c else {+ :c 1}}}}}} {lambda {:a :b} {countjew...
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Lua
Lua
function count_jewels(s, j) local count = 0 for i=1,#s do local c = s:sub(i,i) if string.match(j, c) then count = count + 1 end end return count end   print(count_jewels("aAAbbbb", "aA")) print(count_jewels("ZZ", "z"))
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
TableForm[Table[JacobiSymbol[n, k], {n, 1, 17, 2}, {k, 16}], TableHeadings -> {ReplacePart[Range[1, 17, 2], 1 -> "n=1"], ReplacePart[Range[16], 1 -> "k=1"]}]
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#Nim
Nim
template isOdd(n: int): bool = (n and 1) != 0 template isEven(n: int): bool = (n and 1) == 0     func jacobi(n, k: int): range[-1..1] = assert k > 0 and k.isOdd var n = n mod k var k = k result = 1 while n != 0: while n.isEven: n = n shr 1 if (k and 7) in [3, 5]: result = -result s...
http://rosettacode.org/wiki/Knuth_shuffle
Knuth shuffle
The   Knuth shuffle   (a.k.a. the Fisher-Yates shuffle)   is an algorithm for randomly shuffling the elements of an array. Task Implement the Knuth shuffle for an integer array (or, if possible, an array of any type). Specification Given an array items with indices ranging from 0 to last, the algorithm can be d...
#Smalltalk
Smalltalk
"The selector swap:with: is documented, but it seems not implemented (GNU Smalltalk version 3.0.4); so here it is an implementation" SequenceableCollection extend [ swap: i with: j [ |t| t := self at: i. self at: i put: (self at: j). self at: j put: t. ] ].   Object subclass: Shuffler [ Shuffler ...
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Kotlin
Kotlin
fun sum(lo: Int, hi: Int, f: (Int) -> Double) = (lo..hi).sumByDouble(f)   fun main(args: Array<String>) = println(sum(1, 100, { 1.0 / it }))
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Lua
Lua
  function sum(var, a, b, str) local ret = 0 for i = a, b do ret = ret + setfenv(loadstring("return "..str), {[var] = i})() end return ret end print(sum("i", 1, 100, "1/i"))  
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Oforth
Oforth
: jortSort dup sort == ;
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#ooRexx
ooRexx
jortSort: Parse Arg list /*--------------------------------------------------------------------- * Determine if list is sorted * << is used to avoid numeric comparison * 3 4e-1 is sorted *--------------------------------------------------------------------*/ Do i=2 To words(list) If word(list,i)<<word(list,i-1) Then ...
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Maple
Maple
count_jewel := proc(stones, jewels) local count, j, letter: j := convert(jewels,set): count := 0: for letter in stones do if (member(letter, j)) then count++: end if: end do: return count: end proc: count_jewel("aAAbbbb", "aA")
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
JewelsStones[j_String, s_String] := Count[MemberQ[Characters[j], #] & /@ Characters[s], True] JewelsStones["aA", "aAAbbbb"] JewelsStones["ZZ", "z"]
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#Perl
Perl
use strict; use warnings;   sub J { my($k,$n) = @_;   $k %= $n; my $jacobi = 1; while ($k) { while (0 == $k % 2) { $k = int $k / 2; $jacobi *= -1 if $n%8 == 3 or $n%8 == 5; } ($k, $n) = ($n, $k); $jacobi *= -1 if $n%4 == 3 and $k%4 == 3; $k...
http://rosettacode.org/wiki/Knuth_shuffle
Knuth shuffle
The   Knuth shuffle   (a.k.a. the Fisher-Yates shuffle)   is an algorithm for randomly shuffling the elements of an array. Task Implement the Knuth shuffle for an integer array (or, if possible, an array of any type). Specification Given an array items with indices ranging from 0 to last, the algorithm can be d...
#SNOBOL4
SNOBOL4
* Library for random() -include 'Random.sno'   * # String -> array define('s2a(str,n)i') :(s2a_end) s2a s2a = array(n); str = str ' ' sa1 str break(' ') . s2a<i = i + 1> span(' ') = :s(sa1)f(return) s2a_end   * # Array -> string define('a2s(a)i') :(a2s_end) a2s a2s = a2s a<i = i ...
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#M2000_Interpreter
M2000 Interpreter
  Module Jensen`s_Device { Def double i Report Lazy$(1/i) ' display the definition of the lazy function Function Sum (&i, lo, hi, &f()) { def double temp For i= lo to hi { temp+=f() } =temp } Print Sum(&i, 1, 100, Lazy$(1/i...
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#M4
M4
define(`for', `ifelse($#,0,``$0'', `ifelse(eval($2<=$3),1, `pushdef(`$1',$2)$4`'popdef(`$1')$0(`$1',incr($2),$3,`$4')')')') define(`sum', `pushdef(`temp',0)`'for(`$1',$2,$3, `define(`temp',eval(temp+$4))')`'temp`'popdef(`temp')') sum(`i',1,100,`1000/i')
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#PARI.2FGP
PARI/GP
jortSort(v)=vecsort(v)==v
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Perl
Perl
sub jortsort { my @s=sort @_; # Default standard string comparison for (0..$#s) { return 0 unless $_[$_] eq $s[$_]; } 1; }
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#MATLAB_.2F_Octave
MATLAB / Octave
  function s = count_jewels(stones,jewels) s=0; for c=jewels s=s+sum(c==stones); end %!test %! assert(count_jewels('aAAbbbb','aA'),3) %!test %! assert(count_jewels('ZZ','z'),0)  
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#min
min
(('' '' '') => spread if) :if?   ((1 0 if?) concat map sum) :count   (swap indexof -1 !=) :member?   (("" split) dip 'member? cons count) :count-jewels   "aAAbbbb" "aA" count-jewels puts! "ZZ" "z" count-jewels puts!
http://rosettacode.org/wiki/Jaro-Winkler_distance
Jaro-Winkler distance
The Jaro-Winkler distance is a metric for measuring the edit distance between words. It is similar to the more basic Levenstein distance but the Jaro distance also accounts for transpositions between letters in the words. With the Winkler modification to the Jaro metric, the Jaro-Winkler distance also adds an increase ...
#11l
11l
V WORDS = File(‘linuxwords.txt’).read_lines() V MISSPELLINGS = [‘accomodate’, ‘definately’, ‘goverment’]   F jaro_winkler_distance(=st1, =st2) I st1.len < st2.len (st1, st2) = (st2, st1) V len1 = st1.len V len2 = st2.len I len2 == 0 R 0.0 V delta = max(0, l...
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#Phix
Phix
with javascript_semantics function jacobi(integer a, n) atom result = 1 a = remainder(a,n) while a!=0 do while remainder(a,2)==0 do a /= 2 if find(remainder(n,8),{3,5}) then result *= -1 end if end while {a, n} = {n, a} if remainder(a,4)==3 and remaind...
http://rosettacode.org/wiki/Knuth_shuffle
Knuth shuffle
The   Knuth shuffle   (a.k.a. the Fisher-Yates shuffle)   is an algorithm for randomly shuffling the elements of an array. Task Implement the Knuth shuffle for an integer array (or, if possible, an array of any type). Specification Given an array items with indices ranging from 0 to last, the algorithm can be d...
#Stata
Stata
mata function shuffle(a) { n = length(a) r = runiformint(1,1,1,1..n) for (i=n; i>=2; i--) { j = r[i] x = a[i] a[i] = a[j] a[j] = x } return(a) }   shuffle(1..10) end
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
sum[term_, i_, lo_, hi_] := Block[{temp = 0}, Do[temp = temp + term, {i, lo, hi}]; temp]; SetAttributes[sum, HoldFirst];
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Maxima
Maxima
mysum(e, v, lo, hi) := block([s: 0], for i from lo thru hi do s: s + subst(v=i, e), s)$   mysum(1/n, n, 1, 10); 7381/2520   /* compare with builtin sum */ sum(1/n, n, 1, 10); 7381/2520   /* what if n is assigned a value ? */ n: 200$   /* still works */ mysum(1/n, n, 1, 10); 7381/2520
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Phix
Phix
type JortSort(sequence s) return s=sort(s) end type
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Picat
Picat
go => List = [ [1,2,3,4,5], [2,3,4,5,1], [2], "jortsort", "jortsort".sort() ], foreach(L in List) printf("%w: ", L), if not jortsort(L) then print("not ") end, println("sorted") end, nl.   jortsort(X) => X == X.sort().
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Modula-2
Modula-2
MODULE Jewels; FROM FormatString IMPORT FormatString; FROM Terminal IMPORT WriteString,WriteLn,ReadChar;   PROCEDURE WriteInt(n : INTEGER); VAR buf : ARRAY[0..15] OF CHAR; BEGIN FormatString("%i", buf, n); WriteString(buf) END WriteInt;   PROCEDURE CountJewels(s,j : ARRAY OF CHAR) : INTEGER; VAR c,i,k : CARDINA...
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Nim
Nim
import sequtils   func countJewels(stones, jewels: string): Natural = stones.countIt(it in jewels)   echo countJewels("aAAbbbb", "aA") echo countJewels("ZZ", "z")
http://rosettacode.org/wiki/Jaro-Winkler_distance
Jaro-Winkler distance
The Jaro-Winkler distance is a metric for measuring the edit distance between words. It is similar to the more basic Levenstein distance but the Jaro distance also accounts for transpositions between letters in the words. With the Winkler modification to the Jaro metric, the Jaro-Winkler distance also adds an increase ...
#Elm
Elm
module JaroWinkler exposing (similarity)     commonPrefixLength : List a -> List a -> Int -> Int commonPrefixLength xs ys counter = case ( xs, ys ) of ( x :: xs_, y :: ys_ ) -> if x == y then commonPrefixLength xs_ ys_ (counter + 1)   else counter   ...
http://rosettacode.org/wiki/Jaro-Winkler_distance
Jaro-Winkler distance
The Jaro-Winkler distance is a metric for measuring the edit distance between words. It is similar to the more basic Levenstein distance but the Jaro distance also accounts for transpositions between letters in the words. With the Winkler modification to the Jaro metric, the Jaro-Winkler distance also adds an increase ...
#ALGOL_68
ALGOL 68
PROC jaro sim = ( STRING sp1, sp2 )REAL: IF STRING s1 = sp1[ AT 0 ]; STRING s2 = sp2[ AT 0 ]; INT le1 = ( UPB s1 - LWB s1 ) + 1; INT le2 = ( UPB s2 - LWB s2 ) + 1; le1 < 1 AND le2 < 1 THEN # both strings are empty # 1 ELIF le1 < 1 OR le2 < 1 THE...
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#Python
Python
def jacobi(a, n): if n <= 0: raise ValueError("'n' must be a positive integer.") if n % 2 == 0: raise ValueError("'n' must be odd.") a %= n result = 1 while a != 0: while a % 2 == 0: a /= 2 n_mod_8 = n % 8 if n_mod_8 in (3, 5): ...
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#Raku
Raku
# Jacobi function sub infix:<J> (Int $k is copy, Int $n is copy where * % 2) { $k %= $n; my $jacobi = 1; while $k { while $k %% 2 { $k div= 2; $jacobi *= -1 if $n % 8 == 3 | 5; } ($k, $n) = $n, $k; $jacobi *= -1 if 3 == $n%4 & $k%4; $k %= $n; ...
http://rosettacode.org/wiki/Knuth_shuffle
Knuth shuffle
The   Knuth shuffle   (a.k.a. the Fisher-Yates shuffle)   is an algorithm for randomly shuffling the elements of an array. Task Implement the Knuth shuffle for an integer array (or, if possible, an array of any type). Specification Given an array items with indices ranging from 0 to last, the algorithm can be d...
#Swift
Swift
import func Darwin.arc4random_uniform   extension Array {   func shuffle() -> Array {   var result = self; result.shuffleInPlace(); return result }   mutating func shuffleInPlace() {   for i in 1 ..< count { swap(&self[i], &self[Int(arc4random_uniform(UInt32(i+1)))]) } }   }   // Swift 2...
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#NetRexx
NetRexx
  import COM.ibm.netrexx.process.   class JensensDevice   properties static interpreter=NetRexxA exp=Rexx "" termMethod=Method   method main(x=String[]) static say sum('i',1,100,'1/i')   method sum(i,lo,hi,term) static SIGNALS IOException,NoSuchMethodException,IllegalAccessException,InvocationTarget...
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#PicoLisp
PicoLisp
  (de jortSort (L) (= L (sort L))) (jortSort (1 2 3))  
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#PowerShell
PowerShell
  function jortsort($a) { -not (Compare-Object $a ($a | sort) -SyncWindow 0)} jortsort @(1,2,3) jortsort @(2,3,1)  
http://rosettacode.org/wiki/Jacobsthal_numbers
Jacobsthal numbers
Jacobsthal numbers are an integer sequence related to Fibonacci numbers. Similar to Fibonacci, where each term is the sum of the previous two terms, each term is the sum of the previous, plus twice the one before that. Traditionally the sequence starts with the given terms 0, 1. J0 = 0 J1 = 1 Jn = Jn-1 + 2 ×...
#ALGOL_68
ALGOL 68
BEGIN # find some Jacobsthal and related Numbers # INT max jacobsthal = 29; # highest Jacobsthal number we will find # INT max oblong = 20; # highest Jacobsthal oblong number we will find # INT max j prime = 20; # number of Jacobsthal prinmes we will find # ...
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Objeck
Objeck
use Collection.Generic;   class JewelsStones { function : Main(args : String[]) ~ Nil { Count("aAAbbbb", "aA")->PrintLine(); Count("ZZ", "z")->PrintLine(); }   function : Count(stones : String, jewels : String) ~ Int { bag := Set->New()<CharHolder>;   each(i : jewels) { bag->Insert(jewels->G...
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Perl
Perl
sub count_jewels { my( $j, $s ) = @_; my($c,%S);   $S{$_}++ for split //, $s; $c += $S{$_} for split //, $j; return "$c\n"; }   print count_jewels 'aA' , 'aAAbbbb'; print count_jewels 'z' , 'ZZ';
http://rosettacode.org/wiki/Jaro-Winkler_distance
Jaro-Winkler distance
The Jaro-Winkler distance is a metric for measuring the edit distance between words. It is similar to the more basic Levenstein distance but the Jaro distance also accounts for transpositions between letters in the words. With the Winkler modification to the Jaro metric, the Jaro-Winkler distance also adds an increase ...
#C.2B.2B
C++
#include <algorithm> #include <cstdlib> #include <fstream> #include <iomanip> #include <iostream> #include <string> #include <vector>   auto load_dictionary(const std::string& path) { std::ifstream in(path); if (!in) throw std::runtime_error("Cannot open file " + path); std::string line; std::ve...
http://rosettacode.org/wiki/Jacobi_symbol
Jacobi symbol
The Jacobi symbol is a multiplicative function that generalizes the Legendre symbol. Specifically, the Jacobi symbol (a | n) equals the product of the Legendre symbols (a | p_i)^(k_i), where n = p_1^(k_1)*p_2^(k_2)*...*p_i^(k_i) and the Legendre symbol (a | p) denotes the value of a ^ ((p-1)/2) (mod p) (a | p) ≡   1 ...
#REXX
REXX
/*REXX pgm computes/displays the Jacobi symbol, the # of rows & columns can be specified*/ parse arg rows cols . /*obtain optional arguments from the CL*/ if rows='' | rows=="," then rows= 17 /*Not specified? Then use the default.*/ if cols='' | cols=="," then cols= 16 ...
http://rosettacode.org/wiki/Knuth_shuffle
Knuth shuffle
The   Knuth shuffle   (a.k.a. the Fisher-Yates shuffle)   is an algorithm for randomly shuffling the elements of an array. Task Implement the Knuth shuffle for an integer array (or, if possible, an array of any type). Specification Given an array items with indices ranging from 0 to last, the algorithm can be d...
#Tcl
Tcl
proc knuth_shuffle lst { set j [llength $lst] for {set i 0} {$j > 1} {incr i;incr j -1} { set r [expr {$i+int(rand()*$j)}] set t [lindex $lst $i] lset lst $i [lindex $lst $r] lset lst $r $t } return $lst }   % knuth_shuffle {1 2 3 4 5} 2 1 3 5 4 % knuth_shuffle {1 2 3 4 5} 5 2 1 ...
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Nim
Nim
var i: int   proc harmonicSum(i: var int; lo, hi: int; term: proc: float): float = i = lo while i <= hi: result += term() inc i   echo harmonicSum(i, 1, 100, proc: float = 1 / i)
http://rosettacode.org/wiki/Jensen%27s_Device
Jensen's Device
Jensen's Device You are encouraged to solve this task according to the task description, using any language you may know. This task is an exercise in call by name. Jensen's Device is a computer programming technique devised by Danish computer scientist Jørn Jensen after studying the ALGOL 60 Report. The following pr...
#Objeck
Objeck
  bundle Default { class Jensens { i : static : Int;   function : Sum(lo : Int, hi : Int, term : () ~ Float) ~ Float { temp := 0.0;   for(i := lo; i <= hi; i += 1;) { temp += term(); };   return temp; }   function : term() ~ Float { return 1.0 / i; }   fun...
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#PureBasic
PureBasic
Macro isSort(liste) If OpenConsole() Print("[ ") : ForEach liste : Print(liste+Space(1)) : Next : Print("] = ") If jortSort(liste) : PrintN("True") : Else : PrintN("False") : EndIf EndIf EndMacro   Procedure.b jortSort(List jortS.s()) NewList cpy.s() : CopyList(jortS(),cpy()) : SortList(cpy(),#PB_So...
http://rosettacode.org/wiki/JortSort
JortSort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Python
Python
>>> def jortsort(sequence): return list(sequence) == sorted(sequence) >>> for data in [(1,2,4,3), (14,6,8), ['a', 'c'], ['s', 'u', 'x'], 'CVGH', 'PQRST']: print(f'jortsort({repr(data)}) is {jortsort(data)}') jortsort((1, 2, 4, 3)) is False jortsort((14, 6, 8)) is False jortsort(['a', 'c']) is True jortsort(['s', 'u',...
http://rosettacode.org/wiki/Jacobsthal_numbers
Jacobsthal numbers
Jacobsthal numbers are an integer sequence related to Fibonacci numbers. Similar to Fibonacci, where each term is the sum of the previous two terms, each term is the sum of the previous, plus twice the one before that. Traditionally the sequence starts with the given terms 0, 1. J0 = 0 J1 = 1 Jn = Jn-1 + 2 ×...
#AppleScript
AppleScript
on jacobsthalNumbers(variant, n) -- variant: text containing "Lucas", "oblong", or "prime" — or none of these. -- n: length of output sequence required.   -- The two Jacobsthal numbers preceding the current 'j'. Initially the first two in the sequence. set {anteprev, prev} to {0, 1} -- Default plug-...
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Phix
Phix
function count_jewels(string stones, jewels) integer res = 0 for i=1 to length(stones) do res += find(stones[i],jewels)!=0 end for return res end function ?count_jewels("aAAbbbb","aA") ?count_jewels("ZZ","z")
http://rosettacode.org/wiki/Jewels_and_stones
Jewels and stones
Jewels and stones You are encouraged to solve this task according to the task description, using any language you may know. Task Create a function which takes two string parameters: 'stones' and 'jewels' and returns an integer. Both strings can contain any number of upper or lower case letters. However, in the case ...
#Picat
Picat
jewels_and_stones1(Jewels,Stones) = sum([1 : S in Stones, J in Jewels, S == J]).
http://rosettacode.org/wiki/Jaro-Winkler_distance
Jaro-Winkler distance
The Jaro-Winkler distance is a metric for measuring the edit distance between words. It is similar to the more basic Levenstein distance but the Jaro distance also accounts for transpositions between letters in the words. With the Winkler modification to the Jaro metric, the Jaro-Winkler distance also adds an increase ...
#F.23
F#
  // Calculate Jaro-Winkler Similarity of 2 Strings. Nigel Galloway: August 7th., 2020 let Jw P n g=let L=float(let i=Seq.map2(fun n g->n=g) n g in (if Seq.length i>4 then i|>Seq.take 4 else i)|>Seq.takeWhile id|>Seq.length) let J=J n g in J+P*L*(1.0-J)   let dict=System.IO.File.ReadAllLines("linuxwords.tx...