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/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#K
K
  / Rosetta code - Middle three digits / mid3.k mid3: {qs:$x;:[qs[0]="-";qs: 1 _ qs];:[(#qs)<3;:"small";(1+#qs)!2;:"even"];p:(-3+#qs)%2;:(|p _|p _ qs)}  
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Prolog
Prolog
:- module(primality, [is_prime/2]).   % is_prime/2 returns false if N is composite, true if N probably prime % implements a Miller-Rabin primality test and is deterministic for N < 3.415e+14, % and is probabilistic for larger N. Adapted from the Erlang version. is_prime(1, Ret) :- Ret = false, !. % 1 is ...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#Kotlin
Kotlin
// version 1.1.2   fun menu(list: List<String>): String { if (list.isEmpty()) return "" val n = list.size while (true) { println("\n M E N U\n") for (i in 0 until n) println("${i + 1}: ${list[i]}") print("\nEnter your choice 1 - $n : ") val index = readLine()!!.toIntOrNull(...
http://rosettacode.org/wiki/MD5/Implementation
MD5/Implementation
The purpose of this task to code and validate an implementation of the MD5 Message Digest Algorithm by coding the algorithm directly (not using a call to a built-in or external hashing library). For details of the algorithm refer to MD5 on Wikipedia or the MD5 definition in IETF RFC (1321). The implementation needs t...
#Python
Python
import math   rotate_amounts = [7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#Klingphix
Klingphix
include ..\Utilitys.tlhy   ( 123 12345 1234567 987654321 10001 -10001 -123 -100 100 -12345 1 2 -1 -10 2002 -2002 0 )   len [ get ( dup " : " ) lprint abs tostr len >ps tps 3 < ( ["too short" ?] [ tps 2 mod ( [tps 2 / 3 slice ?] ["is even" ?] ) if] ) if ...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#PureBasic
PureBasic
Enumeration #Composite #Probably_prime EndEnumeration   Procedure Miller_Rabin(n, k) Protected d=n-1, s, x, r If n=2 ProcedureReturn #Probably_prime ElseIf n%2=0 Or n<2 ProcedureReturn #Composite EndIf While d%2=0 d/2 s+1 Wend While k>0 k-1 x=Int(Pow(2+Random(n-4),d))%n If...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#langur
langur
val .select = f(.entries) { if not isArray(.entries): throw "invalid args" if len(.entries) == 0: return ZLS   # print the menu writeln join "\n", map(f $"\.i:2;: \.e;", .entries, 1..len .entries)   val .idx = toNumber read( "Select entry #: ", f(.x) { if not matching(RE/...
http://rosettacode.org/wiki/MD5/Implementation
MD5/Implementation
The purpose of this task to code and validate an implementation of the MD5 Message Digest Algorithm by coding the algorithm directly (not using a call to a built-in or external hashing library). For details of the algorithm refer to MD5 on Wikipedia or the MD5 definition in IETF RFC (1321). The implementation needs t...
#Racket
Racket
  #lang racket (require file/md5) (md5 #"Rosetta Code")  
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#Klong
Klong
items::[123 12345 1234567 987654321 10001 -10001 -123 -100 100 -12345 1 2 -1 -10 2002 -2002 0]   mid3::{[d k];:[3>k::#$#x;"small":|0=k!2;"even";(-d)_(d::_(k%2)-1)_$#x]} .p(mid3'items)
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Python
Python
    import random   def is_Prime(n): """ Miller-Rabin primality test.   A return value of False means n is certainly not prime. A return value of True means n is very likely a prime. """ if n!=int(n): return False n=int(n) #Miller-Rabin test for prime if n==0 or n==1 or n==4 ...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#Logo
Logo
to select :prompt [:options] foreach :options [(print # ?)] forever [ type :prompt type "| | make "n readword if (and [number? :n] [:n >= 1] [:n <= count :options]) [output item :n :options] print sentence [Must enter a number between 1 and] count :options ] end   print equal? [huff and puff] (sel...
http://rosettacode.org/wiki/MD5/Implementation
MD5/Implementation
The purpose of this task to code and validate an implementation of the MD5 Message Digest Algorithm by coding the algorithm directly (not using a call to a built-in or external hashing library). For details of the algorithm refer to MD5 on Wikipedia or the MD5 definition in IETF RFC (1321). The implementation needs t...
#Raku
Raku
sub infix:<⊞>(uint32 $a, uint32 $b --> uint32) { ($a + $b) +& 0xffffffff } sub infix:«<<<»(uint32 $a, UInt $n --> uint32) { ($a +< $n) +& 0xffffffff +| ($a +> (32-$n)) }   constant FGHI = { ($^a +& $^b) +| (+^$a +& $^c) }, { ($^a +& $^c) +| ($^b +& +^$c) }, { $^a +^ $^b +^ $^c ...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#Kotlin
Kotlin
fun middleThree(x: Int): Int? { val s = Math.abs(x).toString() return when { s.length < 3 -> null // throw Exception("too short!") s.length % 2 == 0 -> null // throw Exception("even number of digits") else -> ((s.length / 2) - 1).let { s.substring(it, it + 3) }.toInt() } }   fun main...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Racket
Racket
#lang racket (define (miller-rabin-expmod base exp m) (define (squaremod-with-check x) (define (check-nontrivial-sqrt1 x square) (if (and (= square 1) (not (= x 1)) (not (= x (- m 1)))) 0 square)) (check-nontrivial-sqrt1 x (remainder (expt x 2) m))) ...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#Lua
Lua
function select (list) if not list or #list == 0 then return "" end local last, sel = #list repeat for i,option in ipairs(list) do io.write(i, ". ", option, "\n") end io.write("Choose an item (1-", tostring(last), "): ") sel = tonumber(string.match(io.read("*l"), "^%d+...
http://rosettacode.org/wiki/MD5/Implementation
MD5/Implementation
The purpose of this task to code and validate an implementation of the MD5 Message Digest Algorithm by coding the algorithm directly (not using a call to a built-in or external hashing library). For details of the algorithm refer to MD5 on Wikipedia or the MD5 definition in IETF RFC (1321). The implementation needs t...
#REXX
REXX
/*REXX program tests the MD5 procedure (below) as per a test suite from IETF RFC (1321).*/ @.1 = /*─────MD5 test suite [from above doc].*/ @.2 = 'a' @.3 = 'abc' @.4 = 'message digest' @.5 = 'abcdefghijklmnopqrstuvwxyz' @.6 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxy...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#Lambdatalk
Lambdatalk
  {def S 123 12345 1234567 987654321 10001 -10001 -123 -100 100 -12345 1 2 -1 -10 2002 -2002 0} -> S   {def middle3digits {lambda {:w} {let { {:w {abs :w}} {:l {W.length {abs :w}}} } {if {= {% :l 2} 0} then has an even number of digits else {if {< :l 3} then has ...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Raku
Raku
# the expmod-function from: http://rosettacode.org/wiki/Modular_exponentiation sub expmod(Int $a is copy, Int $b is copy, $n) { my $c = 1; repeat while $b div= 2 { ($c *= $a) %= $n if $b % 2; ($a *= $a) %= $n; } $c; }   subset PrimeCandidate of Int where { $_ > 2 and $_ % 2 };   my Bool multi sub is_prime(Int $...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
textMenu[data_List] := Module[{choice}, If[Length@data == 0, Return@""]; While[!(IntegerQ@choice && Length@data >= choice > 0), MapIndexed[Print[#2[[1]], ") ", #1]&, data]; choice = Input["Enter selection..."] ]; data[[choice]] ]
http://rosettacode.org/wiki/MD5/Implementation
MD5/Implementation
The purpose of this task to code and validate an implementation of the MD5 Message Digest Algorithm by coding the algorithm directly (not using a call to a built-in or external hashing library). For details of the algorithm refer to MD5 on Wikipedia or the MD5 definition in IETF RFC (1321). The implementation needs t...
#RPG
RPG
**FREE Ctl-opt MAIN(Main); Ctl-opt DFTACTGRP(*NO) ACTGRP(*NEW);   dcl-pr QDCXLATE EXTPGM('QDCXLATE'); dataLen packed(5 : 0) CONST; data char(32767) options(*VARSIZE); conversionTable char(10) CONST; end-pr;   dcl-c MASK32 CONST(4294967295); dcl-s SHIFT_AMTS int(3) dim(16) CTDATA PERRCD(16); dcl...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#Lasso
Lasso
define middlethree(value::integer) => { local( pos_value = math_abs(#value), stringvalue = #pos_value -> asstring, intlength = #stringvalue -> size, middle = integer((#intlength + 1) / 2), prefix = string(#value) -> padleading(15)& + ': ' )   #intlength < 3 ? return #prefix + 'Error: too few digits' not...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#REXX
REXX
/*REXX program puts the Miller─Rabin primality test through its paces. */ parse arg limit times seed . /*obtain optional arguments from the CL*/ if limit=='' | limit=="," then limit= 1000 /*Not specified? Then use the default.*/ if times=='' | times=="," then times= 10 ...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#MATLAB
MATLAB
function sucess = menu(list)   if numel(list) == 0 sucess = ''; return end   while(true)   disp('Please select one of these options:');   for i = (1:numel(list))   disp([num2str(i) ') ' list{i}]);   end   disp([num2str(numel(list)+1) ') exit']);   ...
http://rosettacode.org/wiki/MD5/Implementation
MD5/Implementation
The purpose of this task to code and validate an implementation of the MD5 Message Digest Algorithm by coding the algorithm directly (not using a call to a built-in or external hashing library). For details of the algorithm refer to MD5 on Wikipedia or the MD5 definition in IETF RFC (1321). The implementation needs t...
#Rust
Rust
  #![allow(non_snake_case)] // RFC 1321 uses many capitalized variables use std::mem;   fn md5(mut msg: Vec<u8>) -> (u32, u32, u32, u32) { let bitcount = msg.len().saturating_mul(8) as u64;   // Step 1: Append Padding Bits msg.push(0b10000000); while (msg.len() * 8) % 512 != 448 { msg.push(0u8);...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#Logo
Logo
to middle3digits :n if [less? :n 0] [make "n minus :n] local "len make "len count :n if [less? :len 3] [(throw "error [Number must have at least 3 digits])] if [equal? 0 modulo :len 2] [(throw "error [Number must have odd number of digits])] while [greater? count :n 3] [ make "n butlast butfirst :n ] ...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Ring
Ring
  # Project : Miller–Rabin primality test   see "Input a number: " give n see "Input test: " give k   test = millerrabin(n,k) if test = 0 see "Probably Prime" + nl else see "Composite" + nl ok   func millerrabin(n, k) if n = 2 millerRabin = 0 return millerRabin ok if...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#min
min
(  :prompt =list (list bool) (list (' dup append) map prompt choose) ("") if ) :menu   ("fee fie" "huff and puff" "mirror mirror" "tick tock") "Enter an option" menu "You chose: " print! puts!
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#Modula-2
Modula-2
MODULE Menu;   FROM InOut IMPORT WriteString, WriteCard, WriteLn, ReadCard;   CONST StringLength = 100; MenuSize = 4;   TYPE String = ARRAY[0..StringLength-1] OF CHAR;   VAR menu : ARRAY[0..MenuSize] OF String; selection, index : CARDINAL;   BEGIN menu[...
http://rosettacode.org/wiki/MD5/Implementation
MD5/Implementation
The purpose of this task to code and validate an implementation of the MD5 Message Digest Algorithm by coding the algorithm directly (not using a call to a built-in or external hashing library). For details of the algorithm refer to MD5 on Wikipedia or the MD5 definition in IETF RFC (1321). The implementation needs t...
#Scala
Scala
object MD5 extends App {   def hash(s: String) = { def b = s.getBytes("UTF-8")   def m = java.security.MessageDigest.getInstance("MD5").digest(b)   BigInt(1, m).toString(16).reverse.padTo(32, "0").reverse.mkString }   assert("d41d8cd98f00b204e9800998ecf8427e" == hash("")) assert("0000045c5e2b3911eb9...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#Lua
Lua
function middle_three(n) if n < 0 then n = -n end   n = tostring(n) if #n % 2 == 0 then return "Error: the number of digits is even." elseif #n < 3 then return "Error: the number has less than 3 digits." end   local l = math.floor(#n/2) return n:sub(l, l+2) end   -- test do local t = {123, 12345, 1234567...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Ruby
Ruby
def miller_rabin_prime?(n, g) d = n - 1 s = 0 while d % 2 == 0 d /= 2 s += 1 end g.times do a = 2 + rand(n - 4) x = a.pow(d, n) # x = (a**d) % n next if x == 1 || x == n - 1 for r in (1..s - 1) x = x.pow(2, n) # x = (x**2) % n return false if x == 1 break if x == n -...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#MUMPS
MUMPS
MENU(STRINGS,SEP)  ;http://rosettacode.org/wiki/Menu NEW I,A,MAX  ;I is a loop variable  ;A is the string read in from the user  ;MAX is the number of substrings in the STRINGS list  ;SET STRINGS="fee fie^huff and puff^mirror mirror^tick tock" SET MAX=$LENGTH(STRINGS,SEP) QUIT:MAX=0 "" WRITEMENU FOR I=1:1:MAX WRIT...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#Nanoquery
Nanoquery
def _menu($items) for ($i = 0) ($i < len($items)) ($i = $i + 1) println " " + $i + ") " + $items[$i] end end   def _ok($reply, $itemcount) try $n = int($reply) return (($n >= 0) && ($n < $itemcount)) catch return $false end end   def selector($items, $pmt) // Prompt to select an item from the items if (...
http://rosettacode.org/wiki/MD5/Implementation
MD5/Implementation
The purpose of this task to code and validate an implementation of the MD5 Message Digest Algorithm by coding the algorithm directly (not using a call to a built-in or external hashing library). For details of the algorithm refer to MD5 on Wikipedia or the MD5 definition in IETF RFC (1321). The implementation needs t...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "bytedata.s7i"; include "bin32.s7i"; include "float.s7i"; include "math.s7i";   # Use binary integer part of the sines of integers (Radians) as constants: const func array integer: createMd5Table is func result var array integer: k is 64 times 0; local var integer: ...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#Maple
Maple
middleDigits := proc(n) local nList, start; nList := [seq(parse(i), i in convert (abs(n), string))]; if numelems(nList) < 3 then printf ("%9a: Error: Not enough digits.", n); elif numelems(nList) mod 2 = 0 then printf ("%9a: Error: Even number of digits.", n); else start := (numelems(nList)-1)/2; printf("%...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Run_BASIC
Run BASIC
input "Input a number:";n input "Input test:";k   test = millerRabin(n,k) if test = 0 then print "Probably Prime" else print "Composite" end if wait   ' ---------------------------------------- ' Returns ' Composite = 1 ' Probably Prime = 0 ' ---------------------------------------- FUNCTION millerRabin(...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#Nim
Nim
import strutils, rdstdin   proc menu(xs: openArray[string]) = for i, x in xs: echo " ", i, ") ", x   proc ok(reply: string; count: Positive): bool = try: let n = parseInt(reply) return 0 <= n and n < count except: return false   proc selector(xs: openArray[string]; prompt: string): string = if xs.len =...
http://rosettacode.org/wiki/MD5/Implementation
MD5/Implementation
The purpose of this task to code and validate an implementation of the MD5 Message Digest Algorithm by coding the algorithm directly (not using a call to a built-in or external hashing library). For details of the algorithm refer to MD5 on Wikipedia or the MD5 definition in IETF RFC (1321). The implementation needs t...
#Sidef
Sidef
class MD5(String msg) {   method init { msg = msg.bytes }   const FGHI = [ {|a,b,c| (a & b) | (~a & c) }, {|a,b,c| (a & c) | (b & ~c) }, {|a,b,c| (a ^ b ^ c) }, {|a,b,c| (b ^ (a | ~c)) }, ]   const S = [ [7, 12, 17, 22] * 4, [5, 9, ...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
middleThree[n_Integer] := Block[{digits = IntegerDigits[n], len}, len = Length[digits]; If[len < 3 || EvenQ[len], "number digits odd or less than 3", len = Ceiling[len/2]; StringJoin @@ (ToString /@ digits[[len - 1 ;; len + 1]])]]   testData = {123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, ...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Rust
Rust
/* Add these lines to the [dependencies] section of your Cargo.toml file: num = "0.2.0" rand = "0.6.5" */   use num::bigint::BigInt; use num::bigint::ToBigInt;     // The modular_exponentiation() function takes three identical types // (which get cast to BigInt), and returns a BigInt: fn modular_exponentiation<T: ToBig...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#OCaml
OCaml
  let select ?(prompt="Choice? ") = function | [] -> "" | choices -> let rec menu () = List.iteri (Printf.printf "%d: %s\n") choices; print_string prompt; try List.nth choices (read_int ()) with _ -> menu () in menu ()  
http://rosettacode.org/wiki/MD5/Implementation
MD5/Implementation
The purpose of this task to code and validate an implementation of the MD5 Message Digest Algorithm by coding the algorithm directly (not using a call to a built-in or external hashing library). For details of the algorithm refer to MD5 on Wikipedia or the MD5 definition in IETF RFC (1321). The implementation needs t...
#Swift
Swift
  import Foundation public class MD5 { /** specifies the per-round shift amounts */ private let s: [UInt32] = [7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#MATLAB_.2F_Octave
MATLAB / Octave
function s=middle_three_digits(a) % http://rosettacode.org/wiki/Middle_three_digits   s=num2str(abs(a));   if ~mod(length(s),2) s='*** error: number of digits must be odd ***'; return; end; if length(s)<3, s='*** error: number of digits must not be smaller than 3 ***'; return; end;   s = s((length(s)+1)/2+[-1:1]);
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Scala
Scala
import scala.math.BigInt   object MillerRabinPrimalityTest extends App { val (n, certainty )= (BigInt(args(0)), args(1).toInt) println(s"$n is ${if (n.isProbablePrime(certainty)) "probably prime" else "composite"}") }
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#OpenEdge.2FProgress
OpenEdge/Progress
FUNCTION bashMenu RETURNS CHAR( i_c AS CHAR ):   DEF VAR ii AS INT. DEF VAR hfr AS HANDLE. DEF VAR hmenu AS HANDLE EXTENT. DEF VAR ikey AS INT. DEF VAR ireturn AS INT INITIAL ?.   EXTENT( hmenu ) = NUM-ENTRIES( i_c ).   CREATE FRAME hfr ASSIGN WIDTH = 80 H...
http://rosettacode.org/wiki/MD5/Implementation
MD5/Implementation
The purpose of this task to code and validate an implementation of the MD5 Message Digest Algorithm by coding the algorithm directly (not using a call to a built-in or external hashing library). For details of the algorithm refer to MD5 on Wikipedia or the MD5 definition in IETF RFC (1321). The implementation needs t...
#Tcl
Tcl
# We just define the body of md5::md5 here; later we regsub to inline a few # function calls for speed variable ::md5::md5body { ### Step 1. Append Padding Bits   set msgLen [string length $msg]   set padLen [expr {56 - $msgLen%64}] if {$msgLen % 64 > 56} { incr padLen 64 }   # pad even if no p...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#MiniScript
MiniScript
middle3 = function(num) if num < 0 then num = -num s = str(num) if s.len < 3 then return "Input too short" if s.len % 2 == 0 then return "Input length not odd" mid = (s.len + 1) / 2 - 1 return s[mid-1:mid+2] end function   for test in [123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, ...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Scheme
Scheme
#!r6rs (import (rnrs base (6)) (srfi :27 random-bits))   ;; Fast modular exponentiation. (define (modexpt b e M) (cond ((zero? e) 1) ((even? e) (modexpt (mod (* b b) M) (div e 2) M)) ((odd? e) (mod (* b (modexpt b (- e 1) M)) M))))   ;; Return s, d such that d is odd and 2^s * d = n. (define (spli...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#Oz
Oz
declare fun {Select Prompt Items} case Items of nil then "" else for Item in Items Index in 1..{Length Items} do {System.showInfo Index#") "#Item} end {System.printInfo Prompt} try {Nth Items {ReadInt}} catch _ then {Select Prompt Items} end end end   fun {ReadInt} c...
http://rosettacode.org/wiki/MD5/Implementation
MD5/Implementation
The purpose of this task to code and validate an implementation of the MD5 Message Digest Algorithm by coding the algorithm directly (not using a call to a built-in or external hashing library). For details of the algorithm refer to MD5 on Wikipedia or the MD5 definition in IETF RFC (1321). The implementation needs t...
#Wren
Wren
import "/fmt" for Fmt   var k = [ 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee , 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501 , 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be , 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821 , 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa , 0xd62f105d, 0x024...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#.D0.9C.D0.9A-61.2F52
МК-61/52
П0 lg [x] 3 - x>=0 23 ИП0 1 0 / [x] ^ lg [x] 10^x П1 / {x} ИП1 * БП 00 1 + x=0 29 ИП0 С/П 0 /
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "bigint.s7i";   const func boolean: millerRabin (in bigInteger: n, in integer: k) is func result var boolean: probablyPrime is TRUE; local var bigInteger: d is 0_; var integer: r is 0; var integer: s is 0; var bigInteger: a is 0_; var bigInteger: x is 0_; ...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#PARI.2FGP
PARI/GP
choose(v)=my(n);for(i=1,#v,print(i". "v[i]));while(type(n=input())!="t_INT"|n>#v|n<1,);v[n] choose(["fee fie","huff and puff","mirror mirror","tick tock"])
http://rosettacode.org/wiki/MD5/Implementation
MD5/Implementation
The purpose of this task to code and validate an implementation of the MD5 Message Digest Algorithm by coding the algorithm directly (not using a call to a built-in or external hashing library). For details of the algorithm refer to MD5 on Wikipedia or the MD5 definition in IETF RFC (1321). The implementation needs t...
#x86_Assembly
x86 Assembly
section .text org 0x100 mov di, md5_for_display mov si, test_input_1 mov cx, test_input_1_len call compute_md5 call display_md5 mov si, test_input_2 mov cx, test_input_2_len call compute_md5 call display_md5 mov si, test_input_3 mov cx, test_input_3_len call compute_md5 call display_md5 mov si, test_input...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#ML
ML
  val test_array = ["123","12345","1234567","987654321","10001","~10001","~123","~100","100","~12345","1","2","~1","~10","2002","~2002","0"];   fun even (x rem 2 = 0) = true | _ = false;   fun middleThreeDigits (h :: t, s, 1 ) = s @ " --> too small" | (h :: t, s, 2 ) = s @ " --> has even digits" | (h :: t, s...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Sidef
Sidef
func miller_rabin(n, k=10) {   return false if (n <= 1) return true if (n == 2) return false if (n.is_even)   var t = n-1 var s = t.valuation(2) var d = t>>s   k.times { var a = irand(2, t) var x = powmod(a, d, n) next if (x ~~ [1, t])   (s-1).times { ...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#Pascal
Pascal
program Menu; {$ASSERTIONS ON} uses objects; var MenuItems :PUnSortedStrCollection; selected :string;   Function SelectMenuItem(MenuItems :PUnSortedStrCollection):string; var i, idx :integer; code :word; choice :string; begin // Return empty string if the collection is empty. if MenuItems^.Count = 0 ...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#MUMPS
MUMPS
/* MUMPS */ MID3(N)  ; N LEN,N2 S N2=$S(N<0:-N,1:N) I N2<100 Q "NUMBER TOO SMALL" ...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Smalltalk
Smalltalk
Integer extend [ millerRabinTest: kl [ |k| k := kl. self <= 3 ifTrue: [ ^true ] ifFalse: [ (self even) ifTrue: [ ^false ] ifFalse: [ |d s| d := self - 1. s := 0. [ (d rem: 2) == 0 ] whileTrue: [ ...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#Perl
Perl
sub menu { my ($prompt,@array) = @_; return '' unless @array;   print " $_: $array[$_]\n" for(0..$#array); print $prompt; $n = <>; return $array[$n] if $n =~ /^\d+$/ and defined $array[$n]; return &menu($prompt,@array); }   @a = ('fee fie', 'huff and puff', 'mirr...
http://rosettacode.org/wiki/McNuggets_problem
McNuggets problem
Wikipedia The McNuggets version of the coin problem was introduced by Henri Picciotto, who included it in his algebra textbook co-authored with Anita Wah. Picciotto thought of the application in the 1980s while dining with his son at McDonald's, working the problem out on a napkin. A McNugget number is the total number...
#11l
11l
V nuggets = Set(0..100) L(s, n, t) cart_product(0 .. 100 I/ 6, 0 .. 100 I/ 9, 0 .. 100 I/ 20) nuggets.discard(6*s + 9*n + 20*t)   print(max(nuggets))
http://rosettacode.org/wiki/Mayan_calendar
Mayan calendar
The ancient Maya people had two somewhat distinct calendar systems. In somewhat simplified terms, one is a cyclical calendar known as The Calendar Round, that meshes several sacred and civil cycles; the other is an offset calendar known as The Long Count, similar in many ways to the Gregorian calendar. The Calendar R...
#Fortran
Fortran
  PROGRAM MAYA_DRIVER IMPLICIT NONE ! ! Local variables ! CHARACTER(80) :: haab_carry CHARACTER(80) :: long_carry CHARACTER(80) :: nightlord CHARACTER(80) :: tzolkin_carry INTEGER,DIMENSION(8) :: DAY, MONTH, YEAR INTEGER :: INDEX DATA YEAR /2071,2004,2012,20...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   sl = '123 12345 1234567 987654321 10001 -10001 -123 -100 100 -12345' - '1 2 -1 -10 2002 -2002 0' - 'abc 1e3 -17e-3 4004.5 12345678 9876543210' -- extras   parse arg digsL digsR . if \digsL.datatype('w') then digsL = 3 if \digsR.dat...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Standard_ML
Standard ML
open LargeInt;   val mr_iterations = Int.toLarge 20; val rng = Random.rand (557216670, 13504100); (* arbitrary pair to seed RNG *)   fun expmod base 0 m = 1 | expmod base exp m = if exp mod 2 = 0 then let val rt = expmod base (exp div 2) m; val sq = (rt*rt) mod m in if sq = 1 ...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#Phix
Phix
function menu_select(sequence items, object prompt) sequence res = "" items = remove_all("",items) if length(items)!=0 then while 1 do for i=1 to length(items) do printf(1,"%d) %s\n",{i,items[i]}) end for puts(1,iff(atom(prompt)?"Choice?":prompt)) ...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#PHP
PHP
<?php $stdin = fopen("php://stdin", "r"); $allowed = array(1 => 'fee fie', 'huff and puff', 'mirror mirror', 'tick tock');   for(;;) { foreach ($allowed as $id => $name) { echo " $id: $name\n"; } echo "Which is from the four pigs: "; $stdin_string = fgets($stdin, 4096); if (isset($allowed[(...
http://rosettacode.org/wiki/McNuggets_problem
McNuggets problem
Wikipedia The McNuggets version of the coin problem was introduced by Henri Picciotto, who included it in his algebra textbook co-authored with Anita Wah. Picciotto thought of the application in the 1980s while dining with his son at McDonald's, working the problem out on a napkin. A McNugget number is the total number...
#Action.21
Action!
PROC Main() BYTE x,y,z,n BYTE ARRAY nuggets(101)   FOR n=0 TO 100 DO nuggets(n)=0 OD   FOR x=0 TO 100 STEP 6 DO FOR y=0 TO 100 STEP 9 DO FOR z=0 TO 100 STEP 20 DO n=x+y+z IF n<=100 THEN nuggets(n)=1 FI OD OD OD   n=100 DO IF nug...
http://rosettacode.org/wiki/McNuggets_problem
McNuggets problem
Wikipedia The McNuggets version of the coin problem was introduced by Henri Picciotto, who included it in his algebra textbook co-authored with Anita Wah. Picciotto thought of the application in the 1980s while dining with his son at McDonald's, working the problem out on a napkin. A McNugget number is the total number...
#Ada
Ada
with Ada.Text_IO; use Ada.Text_IO;   procedure McNugget is Limit : constant  := 100; List  : array (0 .. Limit) of Boolean := (others => False); N  : Integer; begin for A in 0 .. Limit / 6 loop for B in 0 .. Limit / 9 loop for C in 0 .. Limit / 20 loop N := ...
http://rosettacode.org/wiki/Mayan_calendar
Mayan calendar
The ancient Maya people had two somewhat distinct calendar systems. In somewhat simplified terms, one is a cyclical calendar known as The Calendar Round, that meshes several sacred and civil cycles; the other is an offset calendar known as The Long Count, similar in many ways to the Gregorian calendar. The Calendar R...
#Go
Go
package main   import ( "fmt" "strconv" "strings" "time" )   var sacred = strings.Fields("Imix’ Ik’ Ak’bal K’an Chikchan Kimi Manik’ Lamat Muluk Ok Chuwen Eb Ben Hix Men K’ib’ Kaban Etz’nab’ Kawak Ajaw")   var civil = strings.Fields("Pop Wo’ Sip Sotz’ Sek Xul Yaxk’in Mol Ch’en Yax Sak’ Keh Mak K’ank’in ...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#NewLISP
NewLISP
  (define (middle3 x) (if (even? (length x)) (println "You entered " x ". I need an odd number of digits, not " (length x) ".") (if (< (length x) 3) (println "You entered " x ". Sorry, but I need 3 or more digits.") (println "The middle 3 digits of " x " are " ((- (/ (- (leng...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Swift
Swift
import BigInt   private let numTrails = 5   func isPrime(_ n: BigInt) -> Bool { guard n >= 2 else { fatalError() } guard n != 2 else { return true } guard n % 2 != 0 else { return false }   var s = 0 var d = n - 1   while true { let (quo, rem) = (d / 2, d % 2)   guard rem != 1 else { break }   s...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#PicoLisp
PicoLisp
(de choose (Prompt Items) (use N (loop (for (I . Item) Items (prinl I ": " Item) ) (prin Prompt " ") (flush) (NIL (setq N (in NIL (read)))) (T (>= (length Items) N 1) (prinl (get Items N))) ) ) ) (choose "Which is from the three pigs?" '("fee fie" "hu...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#PL.2FI
PL/I
    test: proc options (main);   declare menu(4) character(100) varying static initial ( 'fee fie', 'huff and puff', 'mirror mirror', 'tick tock'); declare (i, k) fixed binary;   do i = lbound(menu,1) to hbound(menu,1); put skip edit (trim(i), ': ', menu(i) ) (a); end; put skip list ('please choose an item number...
http://rosettacode.org/wiki/McNuggets_problem
McNuggets problem
Wikipedia The McNuggets version of the coin problem was introduced by Henri Picciotto, who included it in his algebra textbook co-authored with Anita Wah. Picciotto thought of the application in the 1980s while dining with his son at McDonald's, working the problem out on a napkin. A McNugget number is the total number...
#ALGOL_68
ALGOL 68
BEGIN # Solve the McNuggets problem: find the largest n <= 100 for which there # # are no non-negative integers x, y, z such that 6x + 9y + 20z = n # INT max nuggets = 100; [ 0 : max nuggets ]BOOL sum; FOR i FROM LWB sum TO UPB sum DO sum[ i ] := FALSE OD; FOR x FROM 0 BY 6 TO max nuggets ...
http://rosettacode.org/wiki/Mayan_calendar
Mayan calendar
The ancient Maya people had two somewhat distinct calendar systems. In somewhat simplified terms, one is a cyclical calendar known as The Calendar Round, that meshes several sacred and civil cycles; the other is an offset calendar known as The Long Count, similar in many ways to the Gregorian calendar. The Calendar R...
#J
J
require 'types/datetime'   NB. 1794214= (0 20 18 20 20#.13 0 0 0 0)-todayno 2012 12 21 longcount=: {{ rplc&' .'":0 20 18 20 20#:y+1794214 }}   tsolkin=: (cut {{)n Imix’ Ik’ Ak’bal K’an Chikchan Kimi Manik’ Lamat Muluk Ok Chuwen Eb Ben Hix Men K’ib’ Kaban Etz’nab’ K...
http://rosettacode.org/wiki/Mayan_calendar
Mayan calendar
The ancient Maya people had two somewhat distinct calendar systems. In somewhat simplified terms, one is a cyclical calendar known as The Calendar Round, that meshes several sacred and civil cycles; the other is an offset calendar known as The Long Count, similar in many ways to the Gregorian calendar. The Calendar R...
#Julia
Julia
using Dates   const Tzolk´in = [ "Imix´", "Ik´", "Ak´bal", "K´an", "Chikchan", "Kimi", "Manik´", "Lamat", "Muluk", "Ok", "Chuwen", "Eb", "Ben", "Hix", "Men", "K´ib´", "Kaban", "Etz´nab´", "Kawak", "Ajaw" ] const Haab´ = [ "Pop", "Wo´", "Sip", "Sotz´", "Sek", "Xul", "Yaxk´in", "Mol", "Ch´en", "Yax", "Sak´", "Keh", "Mak"...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#Nim
Nim
proc middleThreeDigits(i: int): string = var s = $abs(i) if s.len < 3 or s.len mod 2 == 0: raise newException(ValueError, "Need odd and >= 3 digits") let mid = s.len div 2 return s[mid-1..mid+1]   const passing = @[123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -12345] const failing = @[1, ...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Tcl
Tcl
package require Tcl 8.5   proc miller_rabin {n k} { if {$n <= 3} {return true} if {$n % 2 == 0} {return false}   # write n - 1 as 2^s·d with d odd by factoring powers of 2 from n − 1 set d [expr {$n - 1}] set s 0 while {$d % 2 == 0} { set d [expr {$d / 2}] incr s }   whil...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#PowerShell
PowerShell
  function Select-TextItem { <# .SYNOPSIS Prints a textual menu formatted as an index value followed by its corresponding string for each object in the list. .DESCRIPTION Prints a textual menu formatted as an index value followed by its corresponding string for each object in the list; ...
http://rosettacode.org/wiki/McNuggets_problem
McNuggets problem
Wikipedia The McNuggets version of the coin problem was introduced by Henri Picciotto, who included it in his algebra textbook co-authored with Anita Wah. Picciotto thought of the application in the 1980s while dining with his son at McDonald's, working the problem out on a napkin. A McNugget number is the total number...
#APL
APL
100 (⌈/(⍳⊣)~(⊂⊢)(+/×)¨(,⎕IO-⍨(⍳∘⌊÷))) 6 9 20
http://rosettacode.org/wiki/McNuggets_problem
McNuggets problem
Wikipedia The McNuggets version of the coin problem was introduced by Henri Picciotto, who included it in his algebra textbook co-authored with Anita Wah. Picciotto thought of the application in the 1980s while dining with his son at McDonald's, working the problem out on a napkin. A McNugget number is the total number...
#AppleScript
AppleScript
use AppleScript version "2.4" use framework "Foundation" use scripting additions     on run set setNuggets to mcNuggetSet(100, 6, 9, 20)   script isMcNugget on |λ|(x) setMember(x, setNuggets) end |λ| end script set xs to dropWhile(isMcNugget, enumFromThenTo(100, 99, 1))   ...
http://rosettacode.org/wiki/Mayan_calendar
Mayan calendar
The ancient Maya people had two somewhat distinct calendar systems. In somewhat simplified terms, one is a cyclical calendar known as The Calendar Round, that meshes several sacred and civil cycles; the other is an offset calendar known as The Long Count, similar in many ways to the Gregorian calendar. The Calendar R...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
sacred = {"Imix\[CloseCurlyQuote]", "Ik\[CloseCurlyQuote]", "Ak\[CloseCurlyQuote]bal", "K\[CloseCurlyQuote]an", "Chikchan", "Kimi", "Manik\[CloseCurlyQuote]", "Lamat", "Muluk", "Ok", "Chuwen", "Eb", "Ben", "Hix", "Men", "K\[CloseCurlyQuote]ib\[CloseCurlyQuote]", "Kaban", "Etz\[CloseCurlyQuote]nab\[C...
http://rosettacode.org/wiki/Mayan_calendar
Mayan calendar
The ancient Maya people had two somewhat distinct calendar systems. In somewhat simplified terms, one is a cyclical calendar known as The Calendar Round, that meshes several sacred and civil cycles; the other is an offset calendar known as The Long Count, similar in many ways to the Gregorian calendar. The Calendar R...
#Nim
Nim
import math, strformat, times   const   Tzolk´in = ["Imix´", "Ik´", "Ak´bal", "K´an", "Chikchan", "Kimi", "Manik´", "Lamat", "Muluk", "Ok", "Chuwen", "Eb", "Ben", "Hix", "Men", "K´ib´", "Kaban", "Etz´nab´", "Kawak", "Ajaw"]   Haab´ = ["Pop", "Wo´", "Sip", "Sotz´", "Sek", "Xul", "Yaxk´in", "Mol", "Ch´e...
http://rosettacode.org/wiki/Mayan_calendar
Mayan calendar
The ancient Maya people had two somewhat distinct calendar systems. In somewhat simplified terms, one is a cyclical calendar known as The Calendar Round, that meshes several sacred and civil cycles; the other is an offset calendar known as The Long Count, similar in many ways to the Gregorian calendar. The Calendar R...
#Perl
Perl
use strict; use warnings; use utf8; binmode STDOUT, ":utf8"; use Math::BaseArith; use Date::Calc 'Delta_Days';   my @sacred = qw<Imix’ Ik’ Ak’bal K’an Chikchan Kimi Manik’ Lamat Muluk Ok Chuwen Eb Ben Hix Men K’ib’ Kaban Etz’nab’ Kawak Ajaw>;   my @civil = qw<Pop Wo’ Sip Sotz’ Sek Xul Yaxk’in Mol Ch’en Ya...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#Objeck
Objeck
  class Test { function : Main(args : String[]) ~ Nil { text := "123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0"; ins := text->Split(","); each(i : ins) { in := ins[i]->Trim(); IO.Console->Print(in)->Print(": "); in := (in->Size() > ...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#Wren
Wren
import "/big" for BigInt   var iters = 10 // find all primes < 100 System.print("The following numbers less than 100 are prime:") System.write("2 ") for (i in 3..99) { if (BigInt.new(i).isProbablePrime(iters)) System.write("%(i) ") } System.print("\n") var bia = [ BigInt.new("45473371723763001119553307583421474...
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#ProDOS
ProDOS
  :a printline ==========MENU========== printline 1. Fee Fie printline 2. Huff Puff printline 3. Mirror, Mirror printline 4. Tick, Tock editvar /newvar /value=a /userinput=1 /title=What page do you want to go to? if -a- /hasvalue 1 printline You chose a line from the book Jack and the Beanstalk. & exitcurrentprogram 1...
http://rosettacode.org/wiki/McNuggets_problem
McNuggets problem
Wikipedia The McNuggets version of the coin problem was introduced by Henri Picciotto, who included it in his algebra textbook co-authored with Anita Wah. Picciotto thought of the application in the 1980s while dining with his son at McDonald's, working the problem out on a napkin. A McNugget number is the total number...
#Arturo
Arturo
nonMcNuggets: function [lim][ result: new 0..lim   loop range.step:6 1 lim 'x [ loop range.step:9 1 lim 'y [ loop range.step:20 1 lim 'z -> 'result -- sum @[x y z] ] ]   return result ]   print max nonMcNuggets 100
http://rosettacode.org/wiki/Mayan_calendar
Mayan calendar
The ancient Maya people had two somewhat distinct calendar systems. In somewhat simplified terms, one is a cyclical calendar known as The Calendar Round, that meshes several sacred and civil cycles; the other is an offset calendar known as The Long Count, similar in many ways to the Gregorian calendar. The Calendar R...
#Phix
Phix
with javascript_semantics include timedate.e sequence sacred = split("Imix' Ik' Ak'bal K'an Chikchan Kimi Manik' Lamat Muluk Ok Chuwen Eb Ben Hix Men K'ib' Kaban Etz'nab' Kawak Ajaw"), civil = split("Pop Wo' Sip Sotz' Sek Xul Yaxk'in Mol Ch'en Yax Sak' Keh Mak K'ank'in Muwan' Pax K'ayab Kumk'u Wayeb'"), ...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#OCaml
OCaml
let even x = (x land 1) <> 1   let middle_three_digits x = let s = string_of_int (abs x) in let n = String.length s in if n < 3 then failwith "need >= 3 digits" else if even n then failwith "need odd number of digits" else String.sub s (n / 2 - 1) 3   let passing = [123; 12345; 1234567; 987654321; 10001; -100...
http://rosettacode.org/wiki/Miller%E2%80%93Rabin_primality_test
Miller–Rabin primality test
This page uses content from Wikipedia. The original article was at Miller–Rabin primality test. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) The Miller–Rabin primality test or Rabin–Miller prima...
#zkl
zkl
zkl: var BN=Import("zklBigNum"); zkl: BN("4547337172376300111955330758342147474062293202868155909489").probablyPrime() True zkl: BN("4547337172376300111955330758342147474062293202868155909393").probablyPrime() False
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#Prolog
Prolog
  rosetta_menu([], "") :- !. %% Incase of an empty list. rosetta_menu(Items, SelectedItem) :- repeat, %% Repeat until everything that follows is true. display_menu(Items), %% IO get_choice(Choice), %% IO number(Choice), ...
http://rosettacode.org/wiki/McNuggets_problem
McNuggets problem
Wikipedia The McNuggets version of the coin problem was introduced by Henri Picciotto, who included it in his algebra textbook co-authored with Anita Wah. Picciotto thought of the application in the 1980s while dining with his son at McDonald's, working the problem out on a napkin. A McNugget number is the total number...
#AWK
AWK
  # syntax: GAWK -f MCNUGGETS_PROBLEM.AWK # converted from Go BEGIN { limit = 100 for (a=0; a<=limit; a+=6) { for (b=a; b<=limit; b+=9) { for (c=b; c<=limit; c+=20) { arr[c] = 1 } } } for (i=limit; i>=0; i--) { if (!arr[i]+0) { printf("%d\n",i) ...
http://rosettacode.org/wiki/Mayan_calendar
Mayan calendar
The ancient Maya people had two somewhat distinct calendar systems. In somewhat simplified terms, one is a cyclical calendar known as The Calendar Round, that meshes several sacred and civil cycles; the other is an offset calendar known as The Long Count, similar in many ways to the Gregorian calendar. The Calendar R...
#Python
Python
  import datetime     def g2m(date, gtm_correlation=True): """ Translates Gregorian date into Mayan date, see https://rosettacode.org/wiki/Mayan_calendar   Input arguments:   date: string date in ISO-8601 format: YYYY-MM-DD gtm_correlation: GTM correlation to apply if True, Astronomical correl...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#Oforth
Oforth
: middle3 | s sz | abs asString dup ->s size ->sz sz 3 < ifTrue: [ "Too short" println return ] sz isEven ifTrue: [ "Not odd number of digits" println return ] sz 3 - 2 / 1+ dup 2 + s extract ;
http://rosettacode.org/wiki/Menu
Menu
Task Given a prompt and a list containing a number of strings of which one is to be selected, create a function that: prints a textual menu formatted as an index value followed by its corresponding string for each item in the list; prompts the user to enter a number; returns the string corresponding to the selecte...
#PureBasic
PureBasic
If OpenConsole() Define i, txt$, choice Dim txts.s(4) EnableGraphicalConsole(1) ;- Enable graphical mode in the console Repeat ClearConsole() Restore TheStrings ; Set reads address For i=1 To 4 Read.s txt$ txts(i)=txt$ ConsoleLocate(3,i): Print(Str(i)+": "+txt$) Next ...
http://rosettacode.org/wiki/McNuggets_problem
McNuggets problem
Wikipedia The McNuggets version of the coin problem was introduced by Henri Picciotto, who included it in his algebra textbook co-authored with Anita Wah. Picciotto thought of the application in the 1980s while dining with his son at McDonald's, working the problem out on a napkin. A McNugget number is the total number...
#BASIC
BASIC
10 DEFINT A-Z: DIM F(100) 20 FOR A=0 TO 100 STEP 6 30 FOR B=A TO 100 STEP 9 40 FOR C=B TO 100 STEP 20 50 F(C)=-1 60 NEXT C,B,A 70 FOR A=100 TO 0 STEP -1 80 IF NOT F(A) THEN PRINT A: END 90 NEXT A
http://rosettacode.org/wiki/McNuggets_problem
McNuggets problem
Wikipedia The McNuggets version of the coin problem was introduced by Henri Picciotto, who included it in his algebra textbook co-authored with Anita Wah. Picciotto thought of the application in the 1980s while dining with his son at McDonald's, working the problem out on a napkin. A McNugget number is the total number...
#BCPL
BCPL
get "libhdr" manifest $( limit = 100 $)   let start() be $( let flags = vec limit for i = 0 to limit do flags!i := false   for a = 0 to limit by 6 for b = a to limit by 9 for c = b to limit by 20 do flags!c := true   for i = limit to 0 by -1 unless flags!i ...
http://rosettacode.org/wiki/Mayan_calendar
Mayan calendar
The ancient Maya people had two somewhat distinct calendar systems. In somewhat simplified terms, one is a cyclical calendar known as The Calendar Round, that meshes several sacred and civil cycles; the other is an offset calendar known as The Long Count, similar in many ways to the Gregorian calendar. The Calendar R...
#Raku
Raku
my @sacred = <Imix’ Ik’ Ak’bal K’an Chikchan Kimi Manik’ Lamat Muluk Ok Chuwen Eb Ben Hix Men K’ib’ Kaban Etz’nab’ Kawak Ajaw>;   my @civil = <Pop Wo’ Sip Sotz’ Sek Xul Yaxk’in Mol Ch’en Yax Sak’ Keh Mak K’ank’in Muwan’ Pax K’ayab Kumk’u Wayeb’>;   my %correlation = :GMT({ :gregorian(Date...
http://rosettacode.org/wiki/Middle_three_digits
Middle three digits
Task Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible. Note: The order of the middle digits should be preserved. Your function should be tested with the following values;...
#PARI.2FGP
PARI/GP
middle(n)=my(v=digits(n));if(#v>2&&#v%2,100*v[#v\2]+10*v[#v\2+1]+v[#v\2+2],"no middle 3 digits"); apply(middle,[123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0])