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 ...
#Action.21
Action!
PROC PrintArray(INT ARRAY a INT size) INT i   Put('[) FOR i=0 TO size-1 DO IF i>0 THEN Put(' ) FI PrintI(a(i)) OD Put(']) RETURN   PROC InsertionSort(INT ARRAY a INT size) INT i,j,value   FOR i=1 TO size-1 DO value=a(i) j=i-1 WHILE j>=0 AND a(j)>value DO a(j+1)=a(j) ...
http://rosettacode.org/wiki/Knapsack_problem/0-1
Knapsack problem/0-1
A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. He has a good knapsack for carrying things, but knows that he can carry a maximum of only 4kg in it,   and it will have to last the whole day. He cre...
#VBA
VBA
'Knapsack problem/0-1 - 12/02/2017 Option Explicit Const maxWeight = 400 Dim DataList As Variant Dim xList(64, 3) As Variant Dim nItems As Integer Dim s As String, xss As String Dim xwei As Integer, xval As Integer, nn As Integer   Sub Main() Dim i As Integer, j As Integer DataList = Array("map", 9, 150, "compa...
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...
#PowerShell
PowerShell
$A = 1, 2, 3, 4, 5 Get-Random $A -Count $A.Count
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...
#ALGOL_68
ALGOL 68
BEGIN INT i; PROC sum = (REF INT i, INT lo, hi, PROC REAL term)REAL: COMMENT term is passed by-name, and so is i COMMENT BEGIN REAL temp := 0; i := lo; WHILE i <= hi DO # ALGOL 68 has a "for" loop but it creates a distinct # temp +:= term; # variable which w...
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...
#ALGOL_W
ALGOL W
begin integer i; real procedure sum ( integer %name% i; integer value lo, hi; real procedure term );  % i is passed by-name, term is passed as a procedure which makes it effectively passed by-name % begin real temp; temp := 0; i := lo; while i <= hi do begin  % The Algol W...
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 ...
#Ada
Ada
with Ada.Text_IO, Ada.Containers.Generic_Array_Sort;   procedure Jortsort is   function Jort_Sort(List: String) return Boolean is procedure Sort is new Ada.Containers.Generic_Array_Sort (Positive, Character, Array_Type => String); Second_List: String := List; begin Sort(Second_List); retu...
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 ...
#AppleScript
AppleScript
use AppleScript version "2.4" use framework "Foundation" use scripting additions     ------------------------- JORTSORT -------------------------     -- jortSort :: Ord a => [a] -> Bool on jortSort(xs) xs = sort(xs) end jortSort     --------------------------- TEST --------------------------- on run map(jortSor...
http://rosettacode.org/wiki/Knapsack_problem/0-1
Knapsack problem/0-1
A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. He has a good knapsack for carrying things, but knows that he can carry a maximum of only 4kg in it,   and it will have to last the whole day. He cre...
#VBScript
VBScript
' Knapsack problem/0-1 - 13/02/2017 dim w(22),v(22),m(22) data=array( "map", 9, 150, "compass", 13, 35, "water", 153, 200, _ "sandwich", 50, 160 , "glucose", 15, 60, "tin", 68, 45, _ "banana", 27, 60, "apple", 39, 40 , "cheese", 23, 30, "beer", 52, 10, _ "suntan cream", 11, 70, "camera", 32, 30 , "T-shirt", 24, 15, ...
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 ...
#11l
11l
F count_jewels(s, j) R sum(s.map(x -> Int(x C @j)))   print(count_jewels(‘aAAbbbb’, ‘aA’)) print(count_jewels(‘ZZ’, ‘z’))
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...
#PureBasic
PureBasic
EnableExplicit   Procedure KnuthShuffle(Array a(1)) Protected i, last = ArraySize(a())   For i = last To 1 Step -1 Swap a(i), a(Random(i)) Next EndProcedure   Procedure.s ArrayToString(Array a(1)) Protected ret$, i, last = ArraySize(a())   ret$ = Str(a(0)) For i = 1 To last ret$ + "," + ...
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...
#AppleScript
AppleScript
set i to 0   on jsum(i, lo, hi, term) set {temp, i's contents} to {0, lo} repeat while i's contents ≤ hi set {temp, i's contents} to {temp + (term's f(i)), (i's contents) + 1} end repeat return temp end jsum   script term_func on f(i) return 1 / i end f end script   return jsum(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...
#ARM_Assembly
ARM Assembly
    /* ARM assembly Raspberry PI */ /* program jensen.s */ /* compil as with option -mcpu=<processor> -mfpu=vfpv4 -mfloat-abi=hard */ /* link with gcc */   /* Constantes */ .equ EXIT, 1 @ Linux syscall /* Initialized data */ .data   szFormat: .asciz "Result = %.8f \n" .ali...
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 ...
#Arturo
Arturo
jortSort?: function [a]-> a = sort a   test: function [a]-> print [a "is" (jortSort? a)? -> "sorted" -> "not sorted"]   test [1 2 3] test [2 3 1]   print ""   test ["a" "b" "c"] test ["c" "a" "b"]
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 ...
#AutoHotkey
AutoHotkey
JortSort(Array){ sorted:=[] for index, val in Array sorted[val]:=1 for key, val in sorted if (key<>Array[A_Index]) return 0 return 1 }
http://rosettacode.org/wiki/Knapsack_problem/0-1
Knapsack problem/0-1
A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. He has a good knapsack for carrying things, but knows that he can carry a maximum of only 4kg in it,   and it will have to last the whole day. He cre...
#Visual_Basic
Visual Basic
'Knapsack problem/0-1 - 12/02/2017 Option Explicit Const maxWeight = 400 Dim DataList As Variant Dim xList(64, 3) As Variant Dim nItems As Integer Dim s As String, xss As String Dim xwei As Integer, xval As Integer, nn As Integer   Private Sub Form_Load() Dim i As Integer, j As Integer DataList = Array("map", ...
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 ...
#8080_Assembly
8080 Assembly
org 100h jmp demo ;;; Count jewels. ;;; Input: BC = jewels, DE = stones. ;;; Output: BC = count ;;; Destroyed: A, DE, HL jewel: lxi h,jarr ; Zero out the page of memory xra a jzero: mov m,a inr l jnz jzero jrjwl: ldax b ; Get jewel inx b mov l,a ; Mark the corresponding byte in the array inr m ana a ; If '...
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 ...
#8086_Assembly
8086 Assembly
cpu 8086 bits 16 org 100h section .text jmp demo ;;; Count jewels. ;;; Input: DS:SI = jewels, DS:DX = stones ;;; Output: CX = how many stones are jewels ;;; Destroyed: AX, BX, SI, DI jewel: xor ax,ax mov cx,128 ; Allocate 256 bytes (128 words) on stack .zloop: push ax ; Set them all to zero loop .zloop mov...
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...
#Python
Python
from random import randrange   def knuth_shuffle(x): for i in range(len(x)-1, 0, -1): j = randrange(i + 1) x[i], x[j] = x[j], x[i]   x = list(range(10)) knuth_shuffle(x) print("shuffled:", x)
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...
#Arturo
Arturo
harmonicSum: function [variable, lo, hi, term][ result: new 0.0 loop lo..hi 'n -> 'result + do ~"|variable|: |n| |term|" result ] print ["harmonicSum 1->100:" harmonicSum 'i 1 100 {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...
#AWK
AWK
  # syntax: GAWK -f JENSENS_DEVICE.AWK # converted from FreeBASIC BEGIN { evaluation() exit(0) } function evaluation( hi,i,lo,tmp) { lo = 1 hi = 100 for (i=lo; i<=hi; i++) { tmp += (1/i) } printf("%.15f\n",tmp) }  
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 ...
#BQN
BQN
JSort ← ≡⟜∧ JSort 3‿2‿1 0
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 ...
#C
C
  #include <stdio.h> #include <stdlib.h>       int number_of_digits(int x){ int NumberOfDigits; for(NumberOfDigits=0;x!=0;NumberOfDigits++){ x=x/10; } return NumberOfDigits; }   int* convert_array(char array[], int NumberOfElements) //converts integer arguments from char to int { int *conve...
http://rosettacode.org/wiki/Knapsack_problem/0-1
Knapsack problem/0-1
A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. He has a good knapsack for carrying things, but knows that he can carry a maximum of only 4kg in it,   and it will have to last the whole day. He cre...
#Visual_Basic_.NET
Visual Basic .NET
'Knapsack problem/0-1 - 12/02/2017 Public Class KnapsackBin Const knam = 0, kwei = 1, kval = 2 Const maxWeight = 400 Dim xList(,) As Object = { _ {"map", 9, 150}, _ {"compass", 13, 35}, _ {"water", 153, 200}, _ {"sandwich", 50, 160}, _ {"glucose", ...
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 ...
#Ada
Ada
with Ada.Text_IO;   procedure Jewels_And_Stones is   function Count (Jewels, Stones : in String) return Natural is Sum : Natural := 0; begin for J of Jewels loop for S of Stones loop if J = S then Sum := Sum + 1; exit; end if; end...
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 ...
#ALGOL_68
ALGOL 68
BEGIN # procedure that counts the number of times the letters in jewels occur in stones # PROC count jewels = ( STRING stones, jewels )INT: BEGIN # count the occurences of each letter in stones # INT upper a pos = 0; INT lower a pos = 1 + ( ABS "Z" - ABS "A" ); ...
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...
#Quackery
Quackery
[ [] swap dup size times [ dup size random pluck nested rot join swap ] drop ] is shuffle ( [ --> [ )   [ temp put 2dup swap temp share swap peek temp share rot peek dip [ swap temp take swap poke temp put ] swap ...
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...
#BASIC256
BASIC256
subroutine Evaluation() lo = 1 : hi = 100 : temp = 0 for i = lo to hi temp += (1/i) ##r(i) next i print temp end subroutine   call Evaluation() 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...
#BBC_BASIC
BBC BASIC
PRINT FNsum(j, 1, 100, FNreciprocal) END   DEF FNsum(RETURN i, lo, hi, RETURN func) LOCAL temp FOR i = lo TO hi temp += FN(^func) NEXT = temp   DEF FNreciprocal = 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 ...
#C.23
C#
using System;   class Program { public static bool JortSort<T>(T[] array) where T : IComparable, IEquatable<T> { // sort the array T[] originalArray = (T[]) array.Clone(); Array.Sort(array);   // compare to see if it was originally sorted for (var i = 0; i < originalArray.Length; 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 ...
#C.2B.2B
C++
  #include <algorithm> #include <string> #include <iostream> #include <iterator>   class jortSort { public: template<class T> bool jort_sort( T* o, size_t s ) { T* n = copy_array( o, s ); sort_array( n, s ); bool r = false;   if( n ) { r = check( o, n, s ); ...
http://rosettacode.org/wiki/Knapsack_problem/0-1
Knapsack problem/0-1
A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. He has a good knapsack for carrying things, but knows that he can carry a maximum of only 4kg in it,   and it will have to last the whole day. He cre...
#Vlang
Vlang
struct Item { name string w int v int }   const wants = [ Item{'map', 9, 150}, Item{'compass', 13, 35}, Item{'water', 153, 200}, Item{'sandwich', 50, 60}, Item{'glucose', 15, 60}, Item{'tin', 68, 45}, Item{'banana', 27, 60}, Item{'apple', 39, 4...
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 ...
#APL
APL
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 ...
#AppleScript
AppleScript
-- jewelCount :: String -> String -> Int on jewelCount(jewels, stones) set js to chars(jewels) script on |λ|(a, c) if elem(c, jewels) then a + 1 else a end if end |λ| end script foldl(result, 0, chars(stones)) end jewelC...
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...
#R
R
fisheryatesshuffle <- function(n) { pool <- seq_len(n) a <- c() while(length(pool) > 0) { k <- sample.int(length(pool), 1) a <- c(a, pool[k]) pool <- pool[-k] } 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...
#Bracmat
Bracmat
( ( sum = I lo hi Term temp .  !arg:((=?I),?lo,?hi,(=?Term)) & 0:?temp & !lo:?!I & whl ' ( !!I:~>!hi & !temp+!Term:?temp & 1+!!I:?!I ) & !temp ) & sum$((=i),1,100,(=!i^-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...
#C
C
#include <stdio.h>   int i; double sum(int *i, int lo, int hi, double (*term)()) { double temp = 0; for (*i = lo; *i <= hi; (*i)++) temp += term(); return temp; }   double term_func() { return 1.0 / i; }   int main () { printf("%f\n", sum(&i, 1, 100, term_func)); return 0; }
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 ...
#Clojure
Clojure
(defn jort-sort [x] (= x (sort x)))
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 ...
#Common_Lisp
Common Lisp
  (defun jort-sort (x) (equalp x (sort (copy-seq x) #'<)))  
http://rosettacode.org/wiki/Knapsack_problem/0-1
Knapsack problem/0-1
A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. He has a good knapsack for carrying things, but knows that he can carry a maximum of only 4kg in it,   and it will have to last the whole day. He cre...
#Wren
Wren
import "/fmt" for Fmt   var wants = [ ["map", 9, 150], ["compass", 13, 35], ["water", 153, 200], ["sandwich", 50, 160], ["glucose", 15, 60], ["tin", 68, 45], ["banana", 27, 60], ["apple", 39, 40], ["cheese", 23, 30], ["beer", 52, 10], ["suntan cream", 11, 70], ["camera", ...
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 ...
#Arturo
Arturo
count: function [jewels,stones][ size select split stones => [in? & jewels] ]   print count "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 ...
#AutoHotkey
AutoHotkey
JewelsandStones(ss, jj){ for each, jewel in StrSplit(jj) for each, stone in StrSplit(ss) if (stone == jewel) num++ return num }
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...
#Racket
Racket
#lang racket   (define (swap! vec i j) (let ([tmp (vector-ref vec i)]) (vector-set! vec i (vector-ref vec j)) (vector-set! vec j tmp)))   (define (knuth-shuffle x) (if (list? x) (vector->list (knuth-shuffle (list->vector x))) (begin (for ([i (in-range (sub1 (vector-length x)) 0 -1)]) (d...
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...
#C.23
C#
using System;   class JensensDevice { public static double Sum(ref int i, int lo, int hi, Func<double> term) { double temp = 0.0; for (i = lo; i <= hi; i++) { temp += term(); } return temp; }   static void Main() { int i = 0; Co...
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 ...
#Crystal
Crystal
def jort_sort(array) array == array.sort 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 ...
#D
D
  module jortsort;   import std.algorithm : sort, SwapStrategy;   bool jortSort(T)(T[] array) { auto originalArray = array.dup; sort!("a < b", SwapStrategy.stable)(array); return originalArray == array; }   unittest { assert(jortSort([1, 2, 3])); assert(!jortSort([1, 6, 3])); assert(jortSort(["apple", "banana", "...
http://rosettacode.org/wiki/Knapsack_problem/0-1
Knapsack problem/0-1
A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. He has a good knapsack for carrying things, but knows that he can carry a maximum of only 4kg in it,   and it will have to last the whole day. He cre...
#XPL0
XPL0
include c:\cxpl\codes; \include 'code' declarations   int Item, Items, Weights, Values, BestItems, BestValues, I, W, V, N; def Tab=9; def Name, Weight, Value; [Item:= [["map ", 9, 150], ["compass ", 13, 35], ["water ...
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 ...
#AWK
AWK
# syntax: GAWK -f JEWELS_AND_STONES.AWK BEGIN { printf("%d\n",count("aAAbbbb","aA")) printf("%d\n",count("ZZ","z")) exit(0) } function count(stone,jewel, i,total) { for (i=1; i<length(stone); i++) { if (jewel ~ substr(stone,i,1)) { total++ } } return(total) }  
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 ...
#BASIC
BASIC
10 READ N% 20 FOR A%=1 TO N% 30 READ J$,S$ 40 GOSUB 100 50 PRINT S$;" in ";J$;":";J% 60 NEXT 70 END   100 REM Count how many stones (S$) are jewels (J$). 110 DIM J%(127) 120 J%=0 130 FOR I%=1 TO LEN(J$): J%(ASC(MID$(J$,I%,1)))=1: NEXT 140 FOR I%=1 TO LEN(S$): J%=J%+J%(ASC(MID$(S$,I%,1))): NEXT 150 ERASE J% 160 RETURN ...
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 ...
#11l
11l
F jacobi(=a, =n) I n <= 0 X ValueError(‘'n' must be a positive integer.’) I n % 2 == 0 X ValueError(‘'n' must be odd.’) a %= n V result = 1 L a != 0 L a % 2 == 0 a /= 2 V n_mod_8 = n % 8 I n_mod_8 C (3, 5) result = -result (a, n) = (n, a) ...
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...
#Raku
Raku
sub shuffle (@a is copy) { for 1 ..^ @a -> $n { my $k = (0 .. $n).pick; $k == $n or @a[$k, $n] = @a[$n, $k]; } return @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...
#C.2B.2B
C++
  #include <iostream>   #define SUM(i,lo,hi,term)\ [&](const int _lo,const int _hi){\ decltype(+(term)) sum{};\ for (i = _lo; i <= _hi; ++i) sum += (term);\ return sum;\ }((lo),(hi))   int i; double sum(int &i, int lo, int hi, double (*term)()) { double temp = 0; for (i = lo; i <= hi; i++) temp +=...
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 ...
#Delphi
Delphi
  program JortSort;   {$APPTYPE CONSOLE} {$R *.res}   uses System.SysUtils, System.Generics.Collections, System.Generics.Defaults;   type TArrayHelper = class helper for TArray public class function JortSort<T>(const original: TArray<T>): Boolean; static; end;   { TArrayHelper }   class function TArrayH...
http://rosettacode.org/wiki/Knapsack_problem/0-1
Knapsack problem/0-1
A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack well for the trip. He has a good knapsack for carrying things, but knows that he can carry a maximum of only 4kg in it,   and it will have to last the whole day. He cre...
#zkl
zkl
fcn addItem(pairs,it){ // pairs is list of (cost of:,names), it is (name,w,v) w,left,right:=it[1],pairs[0,w],pairs[w,*]; left.extend(right.zipWith( fcn([(t1,_)]a,[(t2,_)]b){ t1>t2 and a or b }, pairs.apply('wrap([(tot,names)]){ T(tot + it[2], names + it[0]) }))) }//--> new list of pairs
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 ...
#BASIC256
BASIC256
  function contar_joyas(piedras, joyas) cont = 0 for i = 1 to length(piedras) bc = instr(joyas, mid(piedras, i, 1), 1) if bc <> 0 then cont += 1 next i return cont end function   print contar_joyas("aAAbbbb", "aA") print contar_joyas("ZZ", "z") print contar_joyas("ABCDEFGHIJKLMNOPQRSTUVWXYZ@abcdefghijklmnopqrst...
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 ...
#BCPL
BCPL
get "libhdr"   let jewels(j, s) = valof $( let jewel = vec 255 let count = 0 for i = 0 to 255 do jewel!i := false for i = 1 to j%0 do jewel!(j%i) := true for i = 1 to s%0 do if jewel!(s%i) then count := count + 1 resultis count $)   let show(j, s) be writef("*"%S*" in *"%S*...
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 ...
#Action.21
Action!
INCLUDE "D2:PRINTF.ACT" ;from the Action! Tool Kit   INT FUNC Jacobi(INT a,n) INT res,tmp   IF a>=n THEN a=a MOD n FI res=1 WHILE a DO WHILE (a&1)=0 DO a=a RSH 1 tmp=n&7 IF tmp=3 OR tmp=5 THEN res=-res FI OD tmp=a a=n n=tmp IF (a%3)=3 AND (n%3)=3 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 ...
#Arturo
Arturo
jacobi: function [n,k][ N: n % k K: k   result: 1 while [N <> 0][ while [even? N][ N: shr N 1 if contains? [3 5] and K 7 -> result: neg result ] [N,K]: @[K,N] if and? 3=and N 3 3=and K 3 -> result: neg result 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...
#REBOL
REBOL
rebol [ Title: "Fisher-Yates" Purpose: {Fisher-Yates shuffling algorithm} ]   fisher-yates: func [b [block!] /local n i j k] [ n: length? b: copy b i: n while [i > 1] [ if i <> j: random i [ error? set/any 'k pick b j change/only at b j pick b i change/onl...
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...
#Clipper
Clipper
// Jensen's device in Clipper (or Harbour) // A fairly direct translation of the Algol 60 // John M Skelton 11-Feb-2012   function main() local i ? transform(sum(@i, 1, 100, {|| 1 / i}), "##.###############") // @ is the quite rarely used pass by ref, {|| ...} is a // code block (an anonymous function, here wi...
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...
#Common_Lisp
Common Lisp
(declaim (inline %sum))   (defun %sum (lo hi func) (loop for i from lo to hi sum (funcall func i)))   (defmacro sum (i lo hi term) `(%sum ,lo ,hi (lambda (,i) ,term)))
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 ...
#Elixir
Elixir
iex(1)> jortsort = fn list -> list == Enum.sort(list) end #Function<6.90072148/1 in :erl_eval.expr/5> iex(2)> jortsort.([1,2,3,4]) true iex(3)> jortsort.([1,2,5,4]) false
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 ...
#F.23
F#
  let jortSort n=n=Array.sort n printfn "%A %A" (jortSort [|1;23;42|]) (jortSort [|23;42;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 ...
#Bracmat
Bracmat
( f = stones jewels N .  !arg:(?stones.?jewels) & 0:?N & ( @( !stones  :  ? (  %@  : [%( @(!jewels:? !sjt ?) & 1+!N:?N | ) & ~ )  ? ...
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 ...
#C
C
#include <stdio.h> #include <string.h>   int count_jewels(const char *s, const char *j) { int count = 0; for ( ; *s; ++s) if (strchr(j, *s)) ++count; return count; }   int main() { printf("%d\n", count_jewels("aAAbbbb", "aA")); printf("%d\n", count_jewels("ZZ", "z")); return 0; }
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 ...
#AWK
AWK
  # syntax: GAWK -f JACOBI_SYMBOL.AWK BEGIN { max_n = 29 max_a = max_n + 1 printf("n\\a") for (i=1; i<=max_a; i++) { printf("%3d",i) underline = underline " --" } printf("\n---%s\n",underline) for (n=1; n<=max_n; n+=2) { printf("%3d",n) for (a=1; a<=max_a; a++) { ...
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...
#REXX
REXX
/*REXX program shuffles a deck of playing cards (with jokers) using the Knuth shuffle.*/ rank= 'A 2 3 4 5 6 7 8 9 10 J Q K' /*pips of the various playing cards. */ suit= '♣♠♦♥' /*suit " " " " " */ parse arg seed . ...
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...
#D
D
double sum(ref int i, in int lo, in int hi, lazy double term) pure @safe /*nothrow @nogc*/ { double result = 0.0; for (i = lo; i <= hi; i++) result += term(); return result; }   void main() { import std.stdio;   int i; sum(i, 1, 100, 1.0/i).writeln; }
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...
#DWScript
DWScript
function sum(var i : Integer; lo, hi : Integer; lazy term : Float) : Float; begin i:=lo; while i<=hi do begin Result += term; Inc(i); end; end;   var i : Integer;   PrintLn(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 ...
#Factor
Factor
USING: kernel sorting ; : jortsort ( seq -- ? ) dup natural-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 ...
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   ' Although it's possible to create generic sorting routines using macros in FreeBASIC ' here we will just use Integer arrays.   Sub quicksort(a() As Integer, first As Integer, last As Integer) Dim As Integer length = last - first + 1 If length < 2 Then Return Dim pivot As Integer = a(first + ...
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 ...
#C.23
C#
using System; using System.Linq;   public class Program { public static void Main() { Console.WriteLine(Count("aAAbbbb", "Aa")); Console.WriteLine(Count("ZZ", "z")); }   private static int Count(string stones, string jewels) { var bag = jewels.ToHashSet(); return stones.Count...
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 ...
#C.2B.2B
C++
#include <algorithm> #include <iostream>   int countJewels(const std::string& s, const std::string& j) { int count = 0; for (char c : s) { if (j.find(c) != std::string::npos) { count++; } } return count; }   int main() { using namespace std;   cout << countJewels("aAA...
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 ...
#C
C
#include <stdlib.h> #include <stdio.h>   #define SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b)))   int jacobi(unsigned long a, unsigned long n) { if (a >= n) a %= n; int result = 1; while (a) { while ((a & 1) == 0) { a >>= 1; if ((n & 7) == 3 || (n & 7) == 5) result = -result; } SWAP(a, n); if ((...
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...
#Ring
Ring
  # Project : Knuth shuffle   items = list(52) for n = 1 to len(items) items[n] = n next knuth(items) showarray(items)   func knuth(items) for i = len(items) to 1 step -1 j = random(i-1) + 1 if i != j temp = items[i] items[i] = items[j] ...
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...
#E
E
pragma.enable("one-method-object") # "def _.get" is experimental shorthand def sum(&i, lo, hi, &term) { # bind i and term to passed slots var temp := 0 i := lo while (i <= hi) { # E has numeric-range iteration but it creates a distinct temp += term # variable which would not be ...
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...
#Elixir
Elixir
defmodule JensenDevice do def task, do: sum( 1, 100, fn i -> 1 / i end )   defp sum( i, high, _term ) when i > high, do: 0 defp sum( i, high, term ) do temp = term.( i ) temp + sum( i + 1, high, term ) end end   IO.puts JensenDevice.task
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 ...
#Go
Go
  package main   import ( "log" "sort" )   func main() { log.Println(jortSort([]int{1, 2, 1, 11, 213, 2, 4})) //false log.Println(jortSort([]int{0, 1, 0, 0, 0, 0})) //false log.Println(jortSort([]int{1, 2, 4, 11, 22, 22})) //true log.Println(jortSort([]int{0, 0, 0, 1, 2, 2})) //true }   func...
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 ...
#CLU
CLU
count_jewels = proc (jewels, stones: string) returns (int) is_jewel: array[bool] := array[bool]$fill(0, 256, false) for c: char in string$chars(jewels) do is_jewel[char$c2i(c)] := true end   n_jewels: int := 0 for c: char in string$chars(stones) do if is_jewel[char$c2i(c)] then n_jew...
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 ...
#Cowgol
Cowgol
include "cowgol.coh";   sub count_jewels(stones: [uint8], jewels: [uint8]): (count: uint16) is var jewel_mark: uint8[256]; MemZero(&jewel_mark as [uint8], 256);   while [jewels] != 0 loop jewel_mark[[jewels]] := 1; jewels := @next jewels; end loop;   count := 0; while [stones] !=...
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 ...
#C.2B.2B
C++
#include <algorithm> #include <cassert> #include <iomanip> #include <iostream>   int jacobi(int n, int k) { assert(k > 0 && k % 2 == 1); n %= k; int t = 1; while (n != 0) { while (n % 2 == 0) { n /= 2; int r = k % 8; if (r == 3 || r == 5) t = -...
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...
#Ruby
Ruby
class Array def knuth_shuffle! j = length i = 0 while j > 1 r = i + rand(j) self[i], self[r] = self[r], self[i] i += 1 j -= 1 end self end end   r = Hash.new(0) 100_000.times do |i| a = [1,2,3].knuth_shuffle! r[a] += 1 end   r.keys.sort.each {|a| puts "#{a.inspect} =>...
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...
#Erlang
Erlang
  -module( jensens_device ).   -export( [task/0] ).   task() -> sum( 1, 100, fun (I) -> 1 / I end ).   sum( I, High, _Term ) when I > High -> 0; sum( I, High, Term ) -> Temp = Term( I ), Temp + sum( I + 1, High, Term ).  
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 ...
#Haskell
Haskell
import Data.List (sort)   jortSort :: (Ord a) => [a] -> Bool jortSort list = list == sort list
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 ...
#J
J
jortsort=: -: /:~
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 ...
#Crystal
Crystal
stones, jewels = "aAAbbbb", "aA" stones.count(jewels) # => 3   # The above solution works for that case, but fails with certain other "jewels": stones, jewels = "aA^Bb", "^b" stones.count(jewels) # => 4 # '^b' in the "jewels" is read as "characters other than 'b'".   # This works as intended though: stones.count { |c| ...
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 ...
#D
D
import std.algorithm; import std.stdio;   int countJewels(string s, string j) { int count; foreach (c; s) { if (j.canFind(c)) { count++; } } return count; }   void main() { countJewels("aAAbbbb", "aA").writeln; countJewels("ZZ", "z").writeln; }
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 ...
#Crystal
Crystal
def jacobi(a, n) raise ArgumentError.new "n must b positive and odd" if n < 1 || n.even? res = 1 until (a %= n) == 0 while a.even? a >>= 1 res = -res if [3, 5].includes? n % 8 end a, n = n, a res = -res if a % 4 == n % 4 == 3 end n == 1 ? res : 0 end   puts "Jacobian symbols for ja...
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 ...
#Erlang
Erlang
  jacobi(_, N) when N =< 0 -> jacobi_domain_error; jacobi(_, N) when (N band 1) =:= 0 -> jacobi_domain_error; jacobi(A, N) when A < 0 -> J2 = ja(-A, N), case N band 3 of 1 -> J2; 3 -> -J2 end; jacobi(A, N) -> ja(A, N).   ja(0, _) -> 0; ja(1, _) -> 1; ja(A, N) when A >= N -> ja(A rem N, N); j...
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...
#Run_BASIC
Run BASIC
dim cards(52) for i = 1 to 52 ' make deck cards(i) = i next   for i = 52 to 1 step -1 ' shuffle deck r = int((rnd(1)*i) + 1) if r <> i then hold = cards(r) cards(r) = cards(i) cards(i) = hold end if next   print "== Shuffled Cards ==" ' print shuffled cards for 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...
#F.23
F#
  printfn "%.14f" (List.fold(fun n g->n+1.0/g) 0.0 [1.0..100.0]);;  
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...
#Factor
Factor
: sum ( lo hi term -- x ) [ [a,b] ] dip map-sum ; inline   1 100 [ recip ] sum .
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 ...
#Janet
Janet
(defn jortsort [xs] (deep= xs (sorted xs)))   (print (jortsort @[1 2 3 4 5])) # true (print (jortsort @[2 1 3 4 5])) # false
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 ...
#Java
Java
public class JortSort { public static void main(String[] args) { System.out.println(jortSort(new int[]{1, 2, 3})); }   static boolean jortSort(int[] arr) { return true; } }
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 ...
#Draco
Draco
proc nonrec count_jewels(*char jewels, stones) word: [256] bool jewel; word count; byte i; char c;   for i from 0 upto 255 do jewel[i] := false od; while c := jewels*; c ~= '\e' do jewel[c] := true; jewels := jewels + 1; od;   count := 0; while c := stones*; c ~= '\e'...
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 ...
#Dyalect
Dyalect
func countJewels(stones, jewels) { stones.Iterate().Map(x => jewels.Contains(x) ? 1 : 0).Reduce((x,y) => x + y, 0) }   print(countJewels("aAAbbbb", "aA")) print(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 ...
#F.23
F#
  //Jacobi Symbol. Nigel Galloway: July 14th., 2020 let J n m=let rec J n m g=match n with 0->if m=1 then g else 0 |n when n%2=0->J(n/2) m (if m%8=3 || m%8=5 then -g else g) |n->J (m%n) n (if m%4=3 && n%4=3 then -g else g) J (n%m)...
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 ...
#Factor
Factor
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...
#Rust
Rust
use rand::Rng;   extern crate rand;   fn knuth_shuffle<T>(v: &mut [T]) { let mut rng = rand::thread_rng(); let l = v.len();   for n in 0..l { let i = rng.gen_range(0, l - n); v.swap(i, l - n - 1); } }   fn main() { let mut v: Vec<_> = (0..10).collect();   println!("before: {:?}",...
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...
#Forth
Forth
: sum 0 s>f 1+ swap ?do i over execute f+ loop drop ; :noname s>f 1 s>f fswap f/ ; 1 100 sum f.
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...
#Fortran
Fortran
FUNCTION SUM(I,LO,HI,TERM) SUM = 0 DO I = LO,HI SUM = SUM + TERM END DO END FUNCTION SUM WRITE (6,*) SUM(I,1,100,1.0/I) END