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/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...
#Python
Python
def _menu(items): for indexitem in enumerate(items): print ("  %2i) %s" % indexitem)   def _ok(reply, itemcount): try: n = int(reply) return 0 <= n < itemcount except: return False   def selector(items, prompt): 'Prompt to select an item from the items' if not items: ...
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...
#BQN
BQN
100 ((↕⊣)(⌈´⊣×⊣¬∘∊⥊∘⊢)(<⊢)(+´×)¨(↕⌊∘÷)) 6‿9‿20
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...
#Wren
Wren
import "/date" for Date import "/fmt" for Fmt   var 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".split(" ")   var 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’".split(" ")   var...
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;...
#Pascal
Pascal
program Midl3dig; {$IFDEF FPC} {$MODE Delphi} //result /integer => Int32 aka longInt etc.. {$ELSE} {$APPTYPE console} // Delphi {$ENDIF} uses sysutils; //IntToStr function GetMid3dig(i:NativeInt):Ansistring; var n,l: NativeInt; Begin setlength(result,0); //n = |i| jumpless abs n := i-((ORD(i>0)-1)AND (2...
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...
#R
R
showmenu <- function(choices = NULL) { if (is.null(choices)) return("") ans <- menu(choices) if(ans==0) "" else choices[ans]   } str <- showmenu(c("fee fie", "huff and puff", "mirror mirror", "tick tock")) str <- showmenu()  
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...
#Racket
Racket
  #lang racket   (define (menu choices) (cond [(null? choices) ""] [else (for ([c choices] [i (in-naturals 1)]) (printf "~a. ~a\n" i c)) (printf "Enter a number: ") (define n (string->number (read-line))) (or (and (exact-integer? n) (<= 1 n (len...
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...
#C
C
#include <stdio.h>   int main() { int max = 0, i = 0, sixes, nines, twenties;   loopstart: while (i < 100) { for (sixes = 0; sixes*6 < i; sixes++) { if (sixes*6 == i) { i++; goto loopstart; }   for (nines = 0; nines*9 < i; nines++) { ...
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#Ada
Ada
with Ada.Text_IO;   with CryptAda.Digests.Message_Digests.MD4; with CryptAda.Digests.Hashes; with CryptAda.Pragmatics; with CryptAda.Utils.Format;   procedure RC_MD4 is use CryptAda.Digests.Message_Digests; use CryptAda.Digests; use CryptAda.Pragmatics;   function To_Byte_Array (Item : String) return Byte_A...
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...
#zkl
zkl
var [const] sacred=T("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=T("Pop","Wo'","Sip","Sotz'","Sek","Xul","Yaxk'in","Mol","Ch'en","Yax","Sak'","Keh", "Mak","K'ank'in","Muwan'","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;...
#Perl
Perl
#!/usr/bin/perl use strict ; use warnings ;   sub middlethree { my $number = shift ; my $testnumber = abs $number ; my $error = "Middle 3 digits can't be shown" ; my $numberlength = length $testnumber ; if ( $numberlength < 3 ) { print "$error : $number too short!\n" ; return ; } 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...
#Raku
Raku
sub menu ( $prompt, @items ) { return '' unless @items.elems; repeat until my $selection ~~ /^ \d+ $/ && @items[--$selection] { my $i = 1; say " {$i++}) $_" for @items; $selection = prompt $prompt; } return @items[$selection]; }   my @choices = 'fee fie', 'huff and puff', 'mirro...
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...
#C.23
C#
  using System;   public class McNuggets { public static void Main() { bool[] isMcNuggetNumber = new bool[101];   for (int x = 0; x <= 100/6; x++) { for (int y = 0; y <= 100/9; y++) { for (int z = 0; z <= 100/20; z++) { int mcNuggetNumber ...
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#AutoHotkey
AutoHotkey
str := "Rosetta Code" MsgBox, % "String:`n" (str) "`n`nMD4:`n" MD4(str)       ; MD4 =============================================================================== MD4(string, encoding = "utf-8") { return CalcStringHash(string, 0x8002, encoding) }   ; CalcAddrHash ===================================================...
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;...
#Phix
Phix
procedure mid3(integer i) string s = sprintf("%d",abs(i)) integer k = length(s)-3 printf(1,"%10d: %s\n",{i,iff(k<0 or and_bits(k,1)?"error":s[k/2+1..k/2+3])}) end procedure constant tests = {123,12345,1234567,987654321,10001,-10001,-123,-100,100,-12345, 1,2,-1,-10,2002,-2002,0} for i=1 t...
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...
#REBOL
REBOL
rebol [ Title: "Text Menu" URL: http://rosettacode.org/wiki/Select ]   choices: ["fee fie" "huff and puff" "mirror mirror" "tick tock"] choice: ""   valid?: func [ choices [block! list! series!] choice ][ if error? try [choice: to-integer choice] [return false] all [0 < choice choice <= length? choices] ]   whil...
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...
#Clojure
Clojure
(defn cart [colls] (if (empty? colls) '(()) (for [more (cart (rest colls)) x (first colls)] (cons x more))))   (defn nuggets [[n6 n9 n20]] (+ (* 6 n6) (* 9 n9) (* 20 n20)))   (let [possible (distinct (map nuggets (cart (map range [18 13 6])))) mcmax (apply max (filter (fn [x] (not-any? #...
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#C
C
  /* * * Author: George Mossessian * * The MD4 hash algorithm, as described in https://tools.ietf.org/html/rfc1320 */     #include <stdlib.h> #include <string.h> #include <stdint.h>   char *MD4(char *str, int len); //this is the prototype you want to call. Everything else is internal.   typedef struct st...
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;...
#PHP
PHP
// 32-bit builds of PHP: Integers can be from -2147483648 to 2147483647 // 64-bit builds of PHP: Integers can be from -9223372036854775808 to 9223372036854775807   function middlethree($integer) { $int = (int)str_replace('-','',$integer); $length = strlen($int);   if(is_int($int)) { if($length >= 3) { if($l...
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...
#Red
Red
Red ["text menu"]   menu: function [items][ print either empty? items [""] [until [ repeat n length? items [print [n ":" items/:n]] attempt [pick items to-integer ask "Your 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...
#CLU
CLU
% Recursive nugget iterator. % This yields all the nugget numbers of the given box sizes from start to max. gen_nuggets = iter (start, max: int, sizes: sequence[int]) yields (int) si = sequence[int] if si$empty(sizes) then yield(start) else for i: int in int$from_to_by(start, max, si$botto...
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...
#COBOL
COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. MCNUGGETS.   DATA DIVISION. WORKING-STORAGE SECTION. 01 NUGGETS. 03 NUGGET-FLAGS PIC X OCCURS 100 TIMES. 88 IS-NUGGET VALUE 'X'.   01 A PIC 999. 01 B PIC 999. ...
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#C.23
C#
using System; using System.Collections.Generic; using System.Linq; using System.Text; static class Md4 { public static string Md4Hash(this string input) { // get padded uints from bytes List<byte> bytes = Encoding.ASCII.GetBytes(input).ToList(); uint bitCount = (uint)(bytes.Count) * 8; ...
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;...
#Picat
Picat
get_middle_f1(Str) = [X,Y,Z] => append(Pre,[X,Y,Z],Post,Str), length(Pre) = length(Post).
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...
#REXX
REXX
/*REXX program displays a list, then prompts the user for a selection number (integer).*/ do forever /*keep prompting until response is OK. */ call list_create /*create the list from scratch. */ call list_show ...
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...
#Comal
Comal
0010 limit#:=100 0020 DIM nugget#(0:limit#) 0030 FOR a#:=0 TO limit# STEP 6 DO 0040 FOR b#:=a# TO limit# STEP 9 DO 0050 FOR c#:=b# TO limit# STEP 20 DO nugget#(c#):=TRUE 0060 ENDFOR b# 0070 ENDFOR a# 0080 FOR i#:=limit# TO 0 STEP -1 DO 0090 IF NOT nugget#(i#) THEN 0100 PRINT "Maximum non-McNuggets number:...
http://rosettacode.org/wiki/Maximum_triangle_path_sum
Maximum triangle path sum
Starting from the top of a pyramid of numbers like this, you can walk down going one step on the right or on the left, until you reach the bottom row: 55 94 48 95 30 96 77 71 26 67 One of such walks is 55 - 94 - 30 - 26. You...
#11l
11l
F solve(&tri) L tri.len > 1 V t0 = tri.pop() V t1 = tri.pop() tri.append(enumerate(t1).map((i, t) -> max(@t0[i], @t0[i + 1]) + t)) R tri[0][0]   V data = ‘ 55 94 48 95 30 96 77 71 26 67 97 13 7...
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#Clojure
Clojure
(use 'pandect.core) (md4 "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;...
#PicoLisp
PicoLisp
(de middle3digits (N) (let (Lst (chop (abs N)) Len (length Lst)) (tab (10 -2 -30) N ":" (cond ((> 3 Len) "not enough digits") ((bit? 1 Len) (head 3 (nth Lst (/ Len 2))) ) (T "even number of digits") ) ) ) )
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...
#Ring
Ring
  aList = ["fee fie", "huff and puff", "mirror mirror", "tick tock"] selected = menu(aList, "please make a selection: ") see "" + selected + nl   func menu aList, prompt ndex = 1 while index>0 and index<=len(aList) for index = 1 to len(aList) if aList[index]!="" see "" + index + " : ...
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...
#Cowgol
Cowgol
include "cowgol.coh"; const LIMIT := 100;   var flags: uint8[LIMIT+1]; MemZero(&flags[0], @bytesof flags);   var a: @indexof flags; var b: @indexof flags; var c: @indexof flags;   a := 0; while a <= LIMIT loop b := a; while b <= LIMIT loop c := b; while c <= LIMIT loop flags[c] := 1;...
http://rosettacode.org/wiki/Maximum_triangle_path_sum
Maximum triangle path sum
Starting from the top of a pyramid of numbers like this, you can walk down going one step on the right or on the left, until you reach the bottom row: 55 94 48 95 30 96 77 71 26 67 One of such walks is 55 - 94 - 30 - 26. You...
#Action.21
Action!
INT FUNC Max(INT a,b) IF a>b THEN RETURN (a) FI RETURN (b)   PROC Main() DEFINE ROWCOUNT="18" INT i,row,len,a,b INT ARRAY rows(ROWCOUNT) INT ARRAY data=[ 55 94 48 95 30 96 77 71 26 67 97...
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#Common_Lisp
Common Lisp
(ql:quickload 'ironclad) (defun md4 (str) (ironclad:byte-array-to-hex-string (ironclad:digest-sequence :md4 (ironclad:ascii-string-to-byte-array str))))   (md4 "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;...
#Pike
Pike
string middlethree(int i) { i = abs(i); int length = sizeof((string)i);   if(length >= 3) { if(length % 2 == 1) { int middle = (int)floor(length / 2) - 1; return(((string)i)[middle..middle+2]); } else { return "The value must contain an odd amount of digits..."; } } else { return "The value mus...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#8th
8th
  "md5" cr:hash! "Some text" cr:hash cr:hash>s . cr bye  
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...
#Ruby
Ruby
  def select(prompt, items = []) if items.empty? '' else answer = -1 until (0...items.length).cover?(answer) items.each_with_index {|i,j| puts "#{j}. #{i}"} print "#{prompt}: " begin answer = Integer(gets) rescue ArgumentError redo end end items[answ...
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...
#Dart
Dart
import 'dart:math'; main() { var nuggets = List<int>.generate(101, (int index) => index); for (int small in List<int>.generate((100 ~/ (6 + 1)), (int index) => index)) { for (int medium in List<int>.generate((100 ~/ (9 + 1)), (int index) => index)) { for (int large in List<int>.generate((100 ~/ (20 + 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...
#Draco
Draco
proc nonrec main() void: byte LIMIT = 100; [LIMIT+1] bool nugget; byte a, b, c;   for a from 0 upto LIMIT do nugget[a] := false od;   for a from 0 by 6 upto LIMIT do for b from a by 9 upto LIMIT do for c from b by 20 upto LIMIT do nugget[c] := true ...
http://rosettacode.org/wiki/Maze_solving
Maze solving
Task For a maze generated by this task, write a function that finds (and displays) the shortest path between two cells. Note that because these mazes are generated by the Depth-first search algorithm, they contain no circular paths, and a simple depth-first tree search can be used.
#11l
11l
F dijkstra(graph, source) V n = graph.len V dist = [Float.infinity] * n V previous = [-1] * n dist[source] = 0 V Q = Array(0 .< n) L !Q.empty V u = min(Q, key' n -> @dist[n]) Q.remove(u) I dist[u] == Float.infinity L.break L(v) 0 .< n I graph[u][v] & (v C Q) ...
http://rosettacode.org/wiki/Maximum_triangle_path_sum
Maximum triangle path sum
Starting from the top of a pyramid of numbers like this, you can walk down going one step on the right or on the left, until you reach the bottom row: 55 94 48 95 30 96 77 71 26 67 One of such walks is 55 - 94 - 30 - 26. You...
#Ada
Ada
with Ada.Text_Io; use Ada.Text_Io;   procedure Max_Sum is   Triangle : array (Positive range <>) of integer := (55, 94, 48, 95, 30, 96, 77, 71, 26, 67, ...
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#D
D
import std.stdio, std.string, std.range;   ubyte[16] md4(const(ubyte)[] inData) pure nothrow { enum f = (uint x, uint y, uint z) => (x & y) | (~x & z); enum g = (uint x, uint y, uint z) => (x & y) | (x & z) | (y & z); enum h = (uint x, uint y, uint z) => x ^ y ^ z; enum r = (uint v, uint s) => (v << s) ...
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;...
#PL.2FI
PL/I
  middle: procedure options (main); /* 29 October 2013 */ declare n fixed (15); declare s character (25) varying; declare in file input;   open file (in) title ('/MIDDLE.DAT,type(text),recsize(100)'); on endfile (in) stop;   do forever; get file (in) list (n); put skip list (n); n = a...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program MD5_64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantesARM64.i...
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...
#Run_BASIC
Run BASIC
dim choose$(5) choose$(1) = "1 Fee Fie" choose$(2) = "2 Huff Puff" choose$(3) = "3 Mirror, Mirror" choose$(4) = "4 Tick, Tock" choose$(5) = "Exit"   [start] print "Menu Selection" listbox #lb,choose$(),5 button #sel, "Accept",[select] wait   [select] selected$=#lb selection$() print " " if selected$<>"" then print "Y...
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...
#Rust
Rust
  fn menu_select<'a>(items: &'a [&'a str]) -> &'a str { if items.len() == 0 { return ""; }   let stdin = std::io::stdin(); let mut buffer = String::new();   loop { for (i, item) in items.iter().enumerate() { println!("{}) {}", i + 1, item); } print!("Pick ...
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...
#Dyalect
Dyalect
func mcnugget(limit) { var sv = Array.Empty(limit + 1, false) for s in 0^6..limit { for n in s^9..limit { for t in n^20..limit { sv[t] = true } } } for i in limit^-1..0 { if !sv[i] { print("Maximum non-McNuggets number is \(i)")...
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...
#Elixir
Elixir
defmodule Mcnugget do def solve(limit) do 0..limit |> MapSet.new() |> MapSet.difference( for( x <- 0..limit, y <- 0..limit, z <- 0..limit, Integer.mod(x, 6) == 0, Integer.mod(y, 9) == 0, Integer.mod(z, 20) == 0, x + y + z <= limit, into...
http://rosettacode.org/wiki/Maze_solving
Maze solving
Task For a maze generated by this task, write a function that finds (and displays) the shortest path between two cells. Note that because these mazes are generated by the Depth-first search algorithm, they contain no circular paths, and a simple depth-first tree search can be used.
#Action.21
Action!
DEFINE TOP="0" DEFINE RIGHT="1" DEFINE BOTTOM="2" DEFINE LEFT="3" DEFINE WIDTH="160" DEFINE HEIGHT="96"   DEFINE STACK_SIZE="5000" BYTE ARRAY stack(STACK_SIZE) INT stackSize   PROC InitStack() stackSize=0 RETURN   BYTE FUNC IsEmpty() IF stackSize=0 THEN RETURN (1) FI RETURN (0)   BYTE FUNC IsFull() IF stack...
http://rosettacode.org/wiki/Maximum_triangle_path_sum
Maximum triangle path sum
Starting from the top of a pyramid of numbers like this, you can walk down going one step on the right or on the left, until you reach the bottom row: 55 94 48 95 30 96 77 71 26 67 One of such walks is 55 - 94 - 30 - 26. You...
#ALGOL_68
ALGOL 68
# create a triangular array of the required values #   [ 1]INT row 1 := ( 55 ); [ 2]INT row 2 := ( 94, 48 ); [ 3]INT row 3 := ( 95, 30, 96 ); [ 4]INT row 4 := ( 77, 71, 26, 67 ); [ 5]INT row 5 := ...
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#Delphi
Delphi
  program CalcMD4;   {$APPTYPE CONSOLE}   uses System.SysUtils, DCPmd4;   function MD4(const Str: string): string; var HashDigest: array of byte; d: Byte; begin Result := ''; with TDCP_md4.Create(nil) do begin Init; UpdateStr(Str); SetLength(HashDigest, GetHashSize div 8); final(HashDigest...
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;...
#Plain_English
Plain English
To run: Start up. Test 123. Test 12345. Test 1234567. Test 987654321. Test 10001. Test -10001. Test -123. Test -100. Test 100. Test -12345. Test 1. Test 2. Test -1. Test -10. Test 2002. Test -2002. Test 0. Wait for the escape key. Shut down.   To get the middle three digits of a number giving a string: Privatize the nu...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#Ada
Ada
with Ada.Text_IO; use Ada.Text_IO; with GNAT.MD5;   procedure MD5_Digest is begin Put(GNAT.MD5.Digest("Foo bar baz")); end MD5_Digest;
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...
#Scala
Scala
import scala.util.Try   object Menu extends App { val choice = menu(list)   def menu(menuList: Seq[String]): String = { if (menuList.isEmpty) "" else { val n = menuList.size   def getChoice: Try[Int] = { println("\n M E N U\n") menuList.zipWithIndex.map { case (text, index) => 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...
#Seed7
Seed7
$ include "seed7_05.s7i";   const func string: menuSelect (in array string: items, in string: prompt) is func result var string: selection is ""; local var string: item is ""; var integer: index is 0; var integer: num is 0; begin if length(items) <> 0 then repeat for item key ind...
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...
#F.23
F#
  // McNuggets. Nigel Galloway: October 28th., 2018 let fN n g = Seq.initInfinite(fun ng->ng*n+g)|>Seq.takeWhile(fun n->n<=100) printfn "%d" (Set.maxElement(Set.difference (set[1..100]) (fN 20 0|>Seq.collect(fun n->fN 9 n)|>Seq.collect(fun n->fN 6 n)|>Set.ofSeq)))  
http://rosettacode.org/wiki/Maze_solving
Maze solving
Task For a maze generated by this task, write a function that finds (and displays) the shortest path between two cells. Note that because these mazes are generated by the Depth-first search algorithm, they contain no circular paths, and a simple depth-first tree search can be used.
#Ada
Ada
with Ada.Text_IO;   procedure Maze_Solver is   X_Size: constant Natural := 45; Y_Size: constant Natural := 17;   subtype X_Range is Natural range 1 .. X_Size; subtype Y_Range is Natural range 1 .. Y_Size;   East: constant X_Range := 2; South: constant Y_Range := 1;   X_Start: constant X_Range  := ...
http://rosettacode.org/wiki/Maximum_triangle_path_sum
Maximum triangle path sum
Starting from the top of a pyramid of numbers like this, you can walk down going one step on the right or on the left, until you reach the bottom row: 55 94 48 95 30 96 77 71 26 67 One of such walks is 55 - 94 - 30 - 26. You...
#AppleScript
AppleScript
---------------- MAXIMUM TRIANGLE PATH SUM ---------------   -- Working from the bottom of the triangle upwards, -- summing each number with the larger of the two below -- until the maximum emerges at the top.   -- maxPathSum :: [[Int]] -> Int on maxPathSum(xss)   -- With the last row as the initial accumulator, ...
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#Emacs_Lisp
Emacs Lisp
(require 'md4) (require 'hex-util) (let* ((s "Rosetta Code") (m (md4 s (length s)))) ;; m = 16 binary bytes (encode-hex-string m)) => "a52bcfc6a0d0d300cdc5ddbfbefe478b"
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;...
#PowerShell
PowerShell
function middle3($inp){   $str = [Math]::abs($inp)   $leng = "$str".length   if ($leng -lt 3){ Write-host $inp": [ERROR] too short." Return } if (($leng % 2) -eq 0){ Write-host $inp": [ERROR] even number of digits." } else { $trimmer = ($leng - 3) / 2 $ans = "$str".subString($trimmer,3)   Write-host $...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#ALGOL_68
ALGOL 68
    # Based on wikipedia article pseudocode #   # s specifies the per-round shift amounts # []INT s = (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...
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...
#Sidef
Sidef
func menu (prompt, arr) { arr.len > 0 || return '' loop { for i in ^arr { say " #{i}: #{arr[i]}" } var n = Sys.scanln(prompt) \\ return() n ~~ /^[0-9]+\z/ ? Num(n) : next arr.exists(n) && return arr[n] } }   var list = ['fee fie', 'huff and puff', 'mirror...
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...
#Factor
Factor
USING: backtrack kernel math.ranges prettyprint sequences sets ; 101 <iota> [ 0 6 9 20 [ 100 swap <range> amb-lazy ] tri@ ] bag-of diff last .
http://rosettacode.org/wiki/Maze_solving
Maze solving
Task For a maze generated by this task, write a function that finds (and displays) the shortest path between two cells. Note that because these mazes are generated by the Depth-first search algorithm, they contain no circular paths, and a simple depth-first tree search can be used.
#AutoHotkey
AutoHotkey
Width := 10, Height := 10 ; set grid size SleepTime := 0   gosub, Startup   Gui, +AlwaysOnTop Gui, font, s12, consolas Gui, add, edit, vEditGrid x10, % maze Gui, add, button, xs gStartup Default, Generate maze Gui, add, button, x+10 gSolve, Solve Gui, show,, maze GuiControl,, EditGrid, % maze ; sh...
http://rosettacode.org/wiki/Maximum_triangle_path_sum
Maximum triangle path sum
Starting from the top of a pyramid of numbers like this, you can walk down going one step on the right or on the left, until you reach the bottom row: 55 94 48 95 30 96 77 71 26 67 One of such walks is 55 - 94 - 30 - 26. You...
#Astro
Astro
fun maxpathsum(t): #: Array{Array{I}} let a = val t for i in a.length-1..-1..1, c in linearindices a[r]: a[r, c] += max(a[r+1, c], a[r=1, c+1]) return a[1, 1]   let test = [ [55], [94, 48], [95, 30, 96], [77, 71, 26, 67], [97, 13, 76, 38, 45], [07, 36, 79, 16, 37, 68], [4...
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#Erlang
Erlang
  -module(md4). -export([md4/0]).   md4() -> <<MD4:128>> = crypto:md4("Rosetta Code"), io:fwrite("Rosetta Code => ~.16B~n",[MD4]).  
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;...
#Prolog
Prolog
  middle_3_digits(Number, [D1,D2,D3]) :- verify_middle_3_able(Number, Digits), append(FrontDigits, [D1,D2,D3| BackDigits], Digits), same_length(FrontDigits, BackDigits).   verify_middle_3_able(Number, Digits) :- must_be(number, Number), AbsNumber is abs(Number), number_chars(AbsNumber, Digit...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#APL
APL
  md5←{ ⍝ index origin zero ⎕IO←0 ⍝ decoding UTF-8 & padding M←(⊢,(0⍴⍨512|448-512|≢))1,⍨l←,⍉(8⍴2)⊤'UTF-8'⎕UCS ⍵ ⍝ add length M,←,⍉(8⍴2)⊤⌽(8⍴256)⊤≢l ⍝ init registers A←16⊥6 7 4 5 2 3 0 1 B←16⊥14 15 12 13 10 11 8 9 C←16⊥9 8 11 10 13 12 15 14 D←16⊥1 0 3 2 5 4 7 6 ...
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...
#Swift
Swift
func getMenuInput(selections: [String]) -> String { guard !selections.isEmpty else { return "" }   func printMenu() { for (i, str) in selections.enumerated() { print("\(i + 1)) \(str)") }   print("Selection: ", terminator: "") }   while true { printMenu()   guard let input = read...
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...
#FOCAL
FOCAL
01.10 F N=0,100;S T(N)=0 01.20 F A=0,6,100;F B=A,9,100;F C=B,20,100;S T(C)=-1 01.30 S N=101 01.40 S N=N-1 01.50 I (T(N))1.4 01.60 T %3,N,! 01.70 Q
http://rosettacode.org/wiki/Maze_solving
Maze solving
Task For a maze generated by this task, write a function that finds (and displays) the shortest path between two cells. Note that because these mazes are generated by the Depth-first search algorithm, they contain no circular paths, and a simple depth-first tree search can be used.
#BBC_BASIC
BBC BASIC
MazeWidth% = 11 MazeHeight% = 9 MazeCell% = 50   VDU 23,22,MazeWidth%*MazeCell%/2+3;MazeHeight%*MazeCell%/2+3;8,16,16,128 VDU 23,23,3;0;0;0; : REM Line thickness OFF PROCgeneratemaze(Maze&(), MazeWidth%, MazeHeight%, MazeCell%) PROCsolvemaze(Path{()}, Maze&(), 0, MazeHeig...
http://rosettacode.org/wiki/Maximum_triangle_path_sum
Maximum triangle path sum
Starting from the top of a pyramid of numbers like this, you can walk down going one step on the right or on the left, until you reach the bottom row: 55 94 48 95 30 96 77 71 26 67 One of such walks is 55 - 94 - 30 - 26. You...
#AutoHotkey
AutoHotkey
 
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#FreeBASIC
FreeBASIC
' version 19-10-2016 ' translation of the (pseudo) code in RFC 1320 ' compile with: fbc -s console   Function MD4(test_str As String) As String   Dim As String message = test_str ' string are passed as ByRef   ' some macro's #Macro F(X, Y, Z) (((X) And (Y)) Or ((Not(X)) And (Z))) #EndMacro   #Macro G(X, Y...
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;...
#Python
Python
>>> def middle_three_digits(i): s = str(abs(i)) length = len(s) assert length >= 3 and length % 2 == 1, "Need odd and >= 3 digits" mid = length // 2 return s[mid-1:mid+2]   >>> passing = [123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -12345] >>> failing = [1, 2, -1, -10, 2002, -2002, 0] >>> for x...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#Arturo
Arturo
print digest "The quick brown fox jumped over the lazy dog's back"
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...
#Tcl
Tcl
proc select {prompt choices} { set nc [llength $choices] if {!$nc} { return "" } set numWidth [string length $nc] while true { set i 0 foreach s $choices { puts [format "  %-*d: %s" $numWidth [incr i] $s] } puts -nonewline "$prompt: " flush stdout gets stdin num if {[string is int -stri...
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...
#FreeBASIC
FreeBASIC
  Dim As Integer l(100), a, b, c, n For a = 0 To 100/6 For b = 0 To 100/9 For c = 0 To 100/20 n = a*6 + b*9 + c*20 If n <= 100 Then l(n) = true Next c Next b Next a For n = 100 To 1 Step -1 If l(n) = false Then Print "El mayor número que no sea McNugget es:"; n: Exit...
http://rosettacode.org/wiki/Mayan_numerals
Mayan numerals
Task Present numbers using the Mayan numbering system   (displaying the Mayan numerals in a cartouche). Mayan numbers Normally, Mayan numbers are written vertically   (top─to─bottom)   with the most significant numeral at the top   (in the sense that decimal numbers are written left─to─right with the most signific...
#11l
11l
-V UL = ‘╔’ UC = ‘╦’ UR = ‘╗’ LL = ‘╚’ LC = ‘╩’ LR = ‘╝’ HB = ‘═’ VB = ‘║’   Mayan = [‘ ’, ‘ ∙ ’, ‘ ∙∙ ’, ‘∙∙∙ ’, ‘∙∙∙∙’]   M0 = ‘ @ ’ M5 = ‘────’   F toBase20(=n) V result = [n % 20] n I/= 20 L n != 0 result [+]= n % 2...
http://rosettacode.org/wiki/Maze_solving
Maze solving
Task For a maze generated by this task, write a function that finds (and displays) the shortest path between two cells. Note that because these mazes are generated by the Depth-first search algorithm, they contain no circular paths, and a simple depth-first tree search can be used.
#C
C
  #include <windows.h> #include <iostream> #include <string>   //-------------------------------------------------------------------------------------------------- using namespace std;   //-------------------------------------------------------------------------------------------------- const int BMP_SIZE = 512, CELL_S...
http://rosettacode.org/wiki/Maximum_triangle_path_sum
Maximum triangle path sum
Starting from the top of a pyramid of numbers like this, you can walk down going one step on the right or on the left, until you reach the bottom row: 55 94 48 95 30 96 77 71 26 67 One of such walks is 55 - 94 - 30 - 26. You...
#AWK
AWK
  # syntax: GAWK -f MAXIMUM_TRIANGLE_PATH_SUM.AWK filename(s) { printf("%s\n",$0) cols[FNR] = NF for (i=1; i<=NF; i++) { arr[FNR][i] = $i } } ENDFILE { for (row=FNR-1; row>0; row--) { for (col=1; col<=cols[row]; col++) { arr[row][col] += max(arr[row+1][col],arr[row+1][col+1]) ...
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#Go
Go
package main   import ( "golang.org/x/crypto/md4" "fmt" )   func main() { h := md4.New() h.Write([]byte("Rosetta Code")) fmt.Printf("%x\n", h.Sum(nil)) }
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;...
#Quackery
Quackery
[ 1 & not ] is even ( n --> b )   [ over size - space swap of swap join ] is justify ( $ n --> $ )   [ abs number$ dup size dup 3 < iff [ 2drop $ "too few digits" ] done dup even iff [ 2drop $ "even digit count" ] done dup...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program MD5.s */   /* REMARK 1 : this program use routines in a include file see task Include a file language arm assembly for the routine affichageMess conversion10 see at end of this program the instruction include */ /* for constantes see task include a file in ar...
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...
#TI-83_BASIC
TI-83 BASIC
Input "",Str1 //input as ITEM 1:ITEM 2:ITEM 3... ":"+Str1+":→Str1 Σ(sub(Str1,X,1)=":",X,1,length(Str1→X 0→dim(L₁ For(Z,2,length(Str1 inString(Str1,":",Z-1 1+Ans+.01inString(Str1,":",Ans+1→L₁(1+dim(L₁ ᴇ2fPart(Ans→Z End seq(iPart(L₁(X))+.01(ᴇ2fPart(L₁(X))-iPart(L₁(X))),X,1,dim(L₁→L₁ Repeat A>0 and A<X ClrHome For(Z,1,dim...
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...
#Go
Go
package main   import "fmt"   func mcnugget(limit int) { sv := make([]bool, limit+1) // all false by default for s := 0; s <= limit; s += 6 { for n := s; n <= limit; n += 9 { for t := n; t <= limit; t += 20 { sv[t] = true } } } for i := limit; i >=...
http://rosettacode.org/wiki/Mayan_numerals
Mayan numerals
Task Present numbers using the Mayan numbering system   (displaying the Mayan numerals in a cartouche). Mayan numbers Normally, Mayan numbers are written vertically   (top─to─bottom)   with the most significant numeral at the top   (in the sense that decimal numbers are written left─to─right with the most signific...
#8080_Assembly
8080 Assembly
putch: equ 2 puts: equ 9 org 100h lxi h,80h ; Get length of command line input mov a,m cpi 2 rc ; If no input, stop add l mov l,a ; Go to end of numbers mov c,l ; C = end of numbers inx h mvi m,0FFh ; Terminate digit sequence with FFh dcx h sub0: mov a,m cpi 32 ; When space reached, we're at the beginning ...
http://rosettacode.org/wiki/Mayan_numerals
Mayan numerals
Task Present numbers using the Mayan numbering system   (displaying the Mayan numerals in a cartouche). Mayan numbers Normally, Mayan numbers are written vertically   (top─to─bottom)   with the most significant numeral at the top   (in the sense that decimal numbers are written left─to─right with the most signific...
#APL
APL
mayan←{ ds←6 4⍴' . .. ... ....────' d←{ ⍵=0:4 4⍴¯14↑'Θ' ds[1+5⌊0⌈⍵-15 10 5 0;] }¨20(⊥⍣¯1)⍵ top←'╔',(1↓∊(≢d)⍴⊂'╦════'),'╗' btm←'╚',(1↓∊(≢d)⍴⊂'╩════'),'╝' top⍪((⊃,/'║',¨d),'║')⍪btm }
http://rosettacode.org/wiki/Maze_solving
Maze solving
Task For a maze generated by this task, write a function that finds (and displays) the shortest path between two cells. Note that because these mazes are generated by the Depth-first search algorithm, they contain no circular paths, and a simple depth-first tree search can be used.
#C.2B.2B
C++
  #include <windows.h> #include <iostream> #include <string>   //-------------------------------------------------------------------------------------------------- using namespace std;   //-------------------------------------------------------------------------------------------------- const int BMP_SIZE = 512, CELL_S...
http://rosettacode.org/wiki/Maximum_triangle_path_sum
Maximum triangle path sum
Starting from the top of a pyramid of numbers like this, you can walk down going one step on the right or on the left, until you reach the bottom row: 55 94 48 95 30 96 77 71 26 67 One of such walks is 55 - 94 - 30 - 26. You...
#Bracmat
Bracmat
( " 55 94 48 95 30 96 77 71 26 67 97 13 76 38 45 07 36 79 16 37 68 48 07 09 18 70 26 06 18 72 79 46 59 79 29 90 20 76 87 11 32 07 07 49 18 ...
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#Haskell
Haskell
#!/usr/bin/env runhaskell   import Data.ByteString.Char8 (pack) import System.Environment (getArgs) import Crypto.Hash   main :: IO () main = print . md4 . pack . unwords =<< getArgs where md4 x = hash x :: Digest MD4
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;...
#Racket
Racket
#lang racket (define (middle x) (cond [(negative? x) (middle (- x))] [(< x 100) "error: number too small"] [else (define s (number->string x)) (define l (string-length s)) (cond [(even? l) "error: number has even length"] [else (define i (quotient l 2)) (su...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#AutoHotkey
AutoHotkey
data := "abc" MsgBox % MD5(data,StrLen(data)) ; 900150983cd24fb0d6963f7d28e17f72   MD5( ByRef V, L=0 ) { VarSetCapacity( MD5_CTX,104,0 ), DllCall( "advapi32\MD5Init", Str,MD5_CTX ) DllCall( "advapi32\MD5Update", Str,MD5_CTX, Str,V, UInt,L ? L : VarSetCapacity(V) ) DllCall( "advapi32\MD5Final", Str,MD5_CTX ) Loop...
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...
#True_BASIC
True BASIC
DIM menu$(4) MAT READ menu$ DATA "fee fie", "huff and puff", "mirror mirror", "tick tock"   FUNCTION sel$(choices$()) IF UBOUND(choices$) - LBOUND(choices$) = 0 THEN LET sel$ = "" LET ret$ = "" DO FOR i = LBOUND(choices$) TO UBOUND(choices$) PRINT i; ": "; choices$(i) NEXT i ...
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...
#Haskell
Haskell
import Data.Set (Set, fromList, member)   gaps :: [Int] gaps = dropWhile (`member` mcNuggets) [100,99 .. 1]   mcNuggets :: Set Int mcNuggets = let size = enumFromTo 0 . quot 100 in fromList $ size 6 >>= \x -> size 9 >>= \y -> size 20 >>= \z -> let v = su...
http://rosettacode.org/wiki/Mayan_numerals
Mayan numerals
Task Present numbers using the Mayan numbering system   (displaying the Mayan numerals in a cartouche). Mayan numbers Normally, Mayan numbers are written vertically   (top─to─bottom)   with the most significant numeral at the top   (in the sense that decimal numbers are written left─to─right with the most signific...
#AppleScript
AppleScript
use AppleScript version "2.4" use framework "Foundation" use scripting additions   -- MAYAN NUMBERS ------------------------------------------   -- mayanNumber:: Int -> [[String]] on mayanNumber(n) showIntAtBase(20, my mayanDigit, n, {}) end mayanNumber   -- mayanDigit :: Int -> String on mayanDigit(n) if 0 < n...
http://rosettacode.org/wiki/Maze_solving
Maze solving
Task For a maze generated by this task, write a function that finds (and displays) the shortest path between two cells. Note that because these mazes are generated by the Depth-first search algorithm, they contain no circular paths, and a simple depth-first tree search can be used.
#Clojure
Clojure
(ns small-projects.find-shortest-way (:require [clojure.string :as str]))   ;Misk functions (defn cell-empty? [maze coords] (= :empty (get-in maze coords)))   (defn wall? [maze coords] (= :wall (get-in maze coords)))   (defn track? [maze coords] (= :track (get-in maze coords)))   (defn get-neighbours [maze [y x...
http://rosettacode.org/wiki/Maximum_triangle_path_sum
Maximum triangle path sum
Starting from the top of a pyramid of numbers like this, you can walk down going one step on the right or on the left, until you reach the bottom row: 55 94 48 95 30 96 77 71 26 67 One of such walks is 55 - 94 - 30 - 26. You...
#C
C
  #include <stdio.h> #include <math.h>   #define max(x,y) ((x) > (y) ? (x) : (y))   int tri[] = { 55, 94, 48, 95, 30, 96, 77, 71, 26, 67, 97, 13, 76, 38, 45, 7, 36, 79, 16, 37, 68, 48, 7, 9, 18, 70, 26, 6, 18, 72, 79, 46, 59, 79, 29, 90, 20, 76, 87, 11, 32, 7, 7, 49, 18, 27, 83, 58, 35, 71, 11, 25, 57...
http://rosettacode.org/wiki/MD4
MD4
Find the MD4 message digest of a string of octets. Use the ASCII encoded string “Rosetta Code” (without quotes). You may either call an MD4 library, or implement MD4 in your language. MD4 is an obsolete hash function that computes a 128-bit message digest that sometimes appears in obsolete protocols. RFC 1320 specifi...
#J
J
require 'ide/qt' gethash_jqtide_ 'MD4';'Rosetta Code' a52bcfc6a0d0d300cdc5ddbfbefe478b
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;...
#Raku
Raku
sub middle-three($n) { given $n.abs { when .chars < 3 { "$n is too short" } when .chars %% 2 { "$n has an even number of digits" } default { "The three middle digits of $n are: ", .substr: (.chars - 3)/2, 3 } } }   say middle-three($_) for < 123 12345 1234567 987654321 1000...
http://rosettacode.org/wiki/MD5
MD5
Task Encode a string using an MD5 algorithm.   The algorithm can be found on   Wikipedia. Optionally, validate your implementation by running all of the test values in   IETF RFC (1321)   for MD5. Additionally,   RFC 1321   provides more precise information on the algorithm than the Wikipedia article. Warning:...
#BaCon
BaCon
  PRAGMA INCLUDE <stdio.h> PRAGMA INCLUDE <stdlib.h> PRAGMA INCLUDE <string.h> PRAGMA INCLUDE <openssl/md5.h> PRAGMA LDFLAGS -lcrypto -lm -w   DECLARE result TYPE unsigned char * DECLARE string TYPE const char *   string = "Rosetta code" strlenght = LEN(string)   result = MD5( string, strlenght , 0)   FOR i = 0 TO MD...
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...
#UNIX_Shell
UNIX Shell
# choose 'choice 1' 'choice 2' ... # Prints menu to standard error. Prompts with PS3. # Reads REPLY from standard input. Sets CHOICE. choose() { CHOICE= # Default CHOICE is empty string. [[ $# -gt 0 ]] || return # Return if "$@" is empty. select CHOICE; do # Select from ...
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...
#J
J
>./(i.100)-.,+/&>{(* i.@>.@%~&101)&.>6 9 20 43