code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
public class McNuggets { public static void main(String... args) { int[] SIZES = new int[] { 6, 9, 20 }; int MAX_TOTAL = 100;
585McNuggets problem
9java
kzqhm
import org.bouncycastle.crypto.digests.MD4Digest; import org.bouncycastle.util.encoders.Hex; public class RosettaMD4 { public static void main (String[] argv) throws Exception { byte[] r = "Rosetta Code".getBytes("US-ASCII"); MD4Digest d = new MD4Digest(); d.update (r, 0, r.length); ...
586MD4
9java
e9oa5
(() => { 'use strict';
585McNuggets problem
10javascript
e9iao
size_t base20(unsigned int n, uint8_t *out) { uint8_t *start = out; do {*out++ = n % 20;} while (n /= 20); size_t length = out - start; while (out > start) { uint8_t x = *--out; *out = *start; *start++ = x; } return length; } void make_digit(int n, char *plac...
589Mayan numerals
5c
y1l6f
const md4func = () => { const hexcase = 0; const b64pad = ""; const chrsz = 8; const tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; const hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; const safe_add = (x, y) => { const lsw = (x & 0xFFFF) + (y & 0xFFFF);...
586MD4
10javascript
0utsz
(ns clojure.examples.rosetta (:gen-class) (:require [clojure.string:as string])) (def rosetta "55 94 48 95 30 96 77 71 26 67 97 13 76 38 45 07 36 79 16 37 68 48 ...
588Maximum triangle path sum
6clojure
o4t8j
def middle_three_digits(num) num = num.abs length = (str = num.to_s).length raise ArgumentError, if length < 3 raise ArgumentError, if length.even? return str[length/2 - 1, 3].to_i end
581Middle three digits
14ruby
vs12n
const char *string = ; int main() { int i; unsigned char result[MD5_DIGEST_LENGTH]; MD5(string, strlen(string), result); for(i = 0; i < MD5_DIGEST_LENGTH; i++) printf(, result[i]); printf(); return EXIT_SUCCESS; }
590MD5
5c
vs42o
null
585McNuggets problem
11kotlin
gi14d
null
586MD4
11kotlin
kzxh3
fn middle_three_digits(x: i32) -> Result<String, String> { let s: String = x.abs().to_string(); let len = s.len(); if len < 3 { Err("Too short".into()) } else if len% 2 == 0 { Err("Even number of digits".into()) } else { Ok(s[len/2 - 1 .. len/2 + 2].to_owned()) } } fn pr...
581Middle three digits
15rust
u0avj
function range(A,B) return function() return coroutine.wrap(function() for i = A, B do coroutine.yield(i) end end) end end function filter(stream, f) return function() return coroutine.wrap(function() for i in stream() do if f(i) then coroutin...
585McNuggets problem
1lua
rnaga
package main import ( "fmt" "strconv" ) const ( ul = "" uc = "" ur = "" ll = "" lc = "" lr = "" hb = "" vb = "" ) var mayan = [5]string{ " ", " ", " ", " ", "", } const ( m0 = " " m5 = "" ) func dec2vig(n uint64) []uint64 { vig := strc...
589Mayan numerals
0go
1yxp5
#!/usr/bin/lua require "crypto" print(crypto.digest("MD4", "Rosetta Code"))
586MD4
1lua
b3qka
def middleThree( s:Int ) : Option[Int] = s.abs.toString match { case v if v.length % 2 == 0 => None
581Middle three digits
16scala
gix4i
import Data.Bool (bool) import Data.List (intercalate, transpose) import qualified Data.Map.Strict as M import Data.Maybe (maybe) main :: IO () main = (putStrLn . unlines) $ mayanFramed <$> [ 4005, 8017, 326205, 886205, 1081439556, 1000000, ...
589Mayan numerals
8haskell
thyf7
(apply str (map (partial format "%02x") (.digest (doto (java.security.MessageDigest/getInstance "MD5") .reset (.update (.getBytes "The quick brown fox jumps over the lazy dog"))))))
590MD5
6clojure
rnhg2
import java.math.BigInteger; public class MayanNumerals { public static void main(String[] args) { for ( long base10 : new long[] {4005, 8017, 326205, 886205, 1000000000, 1081439556L, 26960840421L, 503491211079L }) { displayMyan(BigInteger.valueOf(base10)); System.out.printf("%n");...
589Mayan numerals
9java
85d06
typedef struct squareMtxStruct { int dim; double *cells; double **m; } *SquareMtx; typedef void (*FillFunc)( double *cells, int r, int dim, void *ff_data); SquareMtx NewSquareMtx( int dim, FillFunc fillFunc, void *ff_data ) { SquareMtx sm = malloc(sizeof(struct squareMtxStruct)); if (sm) { ...
591Matrix-exponentiation operator
5c
u04v4
int **m; int **s; void optimal_matrix_chain_order(int *dims, int n) { int len, i, j, k, temp, cost; n--; m = (int **)malloc(n * sizeof(int *)); for (i = 0; i < n; ++i) { m[i] = (int *)calloc(n, sizeof(int)); } s = (int **)malloc(n * sizeof(int *)); for (i = 0; i < n; ++i) { ...
592Matrix chain multiplication
5c
gir45
package main import ( "bytes" "fmt" "math/rand" "time" ) type maze struct { c2 [][]byte
587Maze solving
0go
9e5mt
(() => { 'use strict'; const main = () => unlines( map(mayanFramed, [4005, 8017, 326205, 886205, 1081439556, 1000000, 1000000000] ) );
589Mayan numerals
10javascript
fj6dg
#!/usr/bin/runhaskell import Data.Maybe (fromMaybe) average :: (Int, Int) -> (Int, Int) -> (Int, Int) average (x, y) (x_, y_) = ((x + x_) `div` 2, (y + y_) `div` 2) notBlocked :: [String] -> ((Int, Int), (Int, Int)) -> Bool notBlocked maze (_, (x, y)) = ' ' == (maze !! y) !! x substitute :: [a] -> Int -> a -...
587Maze solving
8haskell
b3xk2
;WITH DATA AS (SELECT CAST(ABS(NUMBER) AS NVARCHAR(MAX)) charNum, NUMBER, LEN(CAST(ABS(NUMBER) AS NVARCHAR(MAX))) LcharNum FROM TABLE1) SELECT CASE WHEN ( LCHARNUM >= 3 AND LCHARNUM% 2 = 1 ) THEN SUBSTRING(CHARNUM, LCHARNUM / 2, 3) ...
581Middle three digits
19sql
jf07e
sub md4(@) { my @input = grep { defined && length > 0 } split /(.{64})/s, join '', @_; push @input, '' if !@input || length($input[$ my @A = (0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476); my @T = (0, 0x5A827999, 0x6ED9EBA1); my @L = qw(3 7 11 19 3 5 9 13 3 9 11 15); my @O = (1, 4, 4, ...
586MD4
2perl
3b2zs
var num:Int = \\enter your number here if num<0{num = -num} var numArray:[Int]=[] while num>0{ var temp:Int=num%10 numArray.append(temp) num=num/10 } var i:Int=numArray.count if i<3||i%2==0{ print("Invalid Input") } else{ i=i/2 print("\(numArray[i+1]),\(numArray[i]),\(numArray[i-1])") }
581Middle three digits
17swift
2qplj
use ntheory qw/forperm gcd vecmin/; sub Mcnugget_number { my $counts = shift; return 'No maximum' if 1 < gcd @$counts; my $min = vecmin @$counts; my @meals; my @min; my $a = -1; while (1) { $a++; for my $b (0..$a) { for my $c (0..$b) { my @s = ...
585McNuggets problem
2perl
nrmiw
$ sudo apt install libncurses5-dev
593Matrix digital rain
5c
2q2lo
package main import "fmt"
592Matrix chain multiplication
0go
ignog
use ntheory qw/fromdigits todigitstring/; my $t_style = '"border-collapse: separate; text-align: center; border-spacing: 3px 0px;"'; my $c_style = '"border: solid black 2px;background-color: 'border-radius: 1em;-moz-border-radius: 1em;-webkit-border-radius: 1em;'. 'vertical-align: bottom;width: 3.25em;"'; sub ca...
589Mayan numerals
2perl
lx5c5
import Data.List (elemIndex) import Data.Char (chr, ord) import Data.Maybe (fromJust) mats :: [[Int]] mats = [ [5, 6, 3, 1] , [1, 5, 25, 30, 100, 70, 2, 1, 100, 250, 1, 1000, 2] , [1000, 1, 500, 12, 1, 700, 2500, 3, 2, 5, 14, 10] ] cost :: [Int] -> Int -> Int -> (Int, Int) cost a i j | i < j = let m = ...
592Matrix chain multiplication
8haskell
vsu2k
import java.io.*; import java.util.*; public class MazeSolver { private static String[] readLines (InputStream f) throws IOException { BufferedReader r = new BufferedReader (new InputStreamReader (f, "US-ASCII")); ArrayList<String> lines = new ArrayList<String>(); Strin...
587Maze solving
9java
gib4m
echo hash('md4', ), ;
586MD4
12php
p6sba
package main import ( gc "github.com/rthornton128/goncurses" "log" "math/rand" "time" )
593Matrix digital rain
0go
q2qxz
import java.util.Arrays; public class MatrixChainMultiplication { public static void main(String[] args) { runMatrixChainMultiplication(new int[] {5, 6, 3, 1}); runMatrixChainMultiplication(new int[] {1, 5, 25, 30, 100, 70, 2, 1, 100, 250, 1, 1000, 2}); runMatrixChainMultiplication(new int...
592Matrix chain multiplication
9java
y1m6g
var ctx, wid, hei, cols, rows, maze, stack = [], start = {x:-1, y:-1}, end = {x:-1, y:-1}, grid = 8; function drawMaze() { for( var i = 0; i < cols; i++ ) { for( var j = 0; j < rows; j++ ) { switch( maze[i][j] ) { case 0: ctx.fillStyle = "black"; break; case 1: ct...
587Maze solving
10javascript
kzwhq
null
592Matrix chain multiplication
11kotlin
fjtdo
package main import ( "fmt" "strconv" "strings" ) const t = ` 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...
588Maximum triangle path sum
0go
lx4cw
import hashlib print hashlib.new(,raw_input().encode('utf-16le')).hexdigest().upper()
586MD4
3python
6pv3w
var tileSize = 20;
593Matrix digital rain
10javascript
y1y6r
package main import ( "errors" "flag" "fmt" "log" "math/rand" "strings" "time" ) func main() { log.SetPrefix("mastermind: ") log.SetFlags(0) colours := flag.Int("colours", 6, "number of colours to use (2-20)") flag.IntVar(colours, "colors", 6, "alias for colours") holes := flag.Int("holes", 4, "number of ...
594Mastermind
0go
ri4gm
null
592Matrix chain multiplication
1lua
thzfn
null
587Maze solving
11kotlin
2qrli
parse = map (map read . words) . lines f x y z = x + max y z g xs ys = zipWith3 f xs ys $ tail ys solve = head . foldr1 g main = readFile "triangle.txt" >>= print . solve . parse
588Maximum triangle path sum
8haskell
1yqps
>>> from itertools import product >>> nuggets = set(range(101)) >>> for s, n, t in product(range(100 nuggets.discard(6*s + 9*n + 20*t) >>> max(nuggets) 43 >>>
585McNuggets problem
3python
d79n1
'''Mayan numerals''' from functools import (reduce) def mayanNumerals(n): '''Rows of Mayan digit cells, representing the integer n. ''' return showIntAtBase(20)( mayanDigit )(n)([]) def mayanDigit(n): '''List of strings representing a Mayan digit.''' if 0 < n: r =...
589Mayan numerals
3python
2q4lz
int main (int argc, char **argv) { char *str, *s; struct stat statBuf; if (argc != 2) { fprintf (stderr, , basename (argv[0])); exit (1); } s = argv[1]; while ((str = strtok (s, )) != NULL) { if (str != s) { str[-1] = '/'; } if (stat (argv[1],...
595Make directory path
5c
jdg70
class Mastermind { constructor() { this.colorsCnt; this.rptColors; this.codeLen; this.guessCnt; this.guesses; this.code; this.selected; this.game_over; this.clear = (el) => { while (el.hasChildNodes()) { el.removeChild(el.firstChild); } }; this.colors = ...
594Mastermind
10javascript
s2xqz
allInputs <- expand.grid(x = 0:(100 %/% 6), y = 0:(100 %/% 9), z = 0:(100 %/% 20)) mcNuggets <- do.call(function(x, y, z) 6 * x + 9 * y + 20 * z, allInputs)
585McNuggets problem
13r
8530x
(defn mkdirp [path] (let [dir (java.io.File. path)] (if (.exists dir) true (.mkdirs dir))))
595Make directory path
6clojure
16kpy
static unsigned char const k8[16] = { 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 }; static unsigned char const k7[16] = { 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 }; static unsigned char const k6[16] = { 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 }; static ...
596Main step of GOST 28147-89
5c
ayk11
wchar_t glyph[] = LSPCSPC; typedef unsigned char byte; enum { N = 1, S = 2, W = 4, E = 8, V = 16 }; byte **cell; int w, h, avail; int irand(int n) { int r, rmax = n * (RAND_MAX / n); while ((r = rand()) >= rmax); return r / (RAND_MAX/n); } void show() { int i, j, c; each(i, 0, 2 * h) { each(j, 0, 2 * w) { ...
597Maze generation
5c
i4qo2
package main import "fmt" type vector = []float64 type matrix []vector func (m1 matrix) mul(m2 matrix) matrix { rows1, cols1 := len(m1), len(m1[0]) rows2, cols2 := len(m2), len(m2[0]) if cols1 != rows2 { panic("Matrices cannot be multiplied.") } result := make(matrix, rows1) for i := ...
591Matrix-exponentiation operator
0go
0uosk
null
594Mastermind
11kotlin
hf7j3
use strict; use feature 'say'; sub matrix_mult_chaining { my(@dimensions) = @_; my(@cp,@path); $cp[$_][$_] = 0 for keys @dimensions; my $n = $ for my $chain_length (1..$n) { for my $start (0 .. $n - $chain_length - 1) { my $end = $start + $chain_length; $cp[$e...
592Matrix chain multiplication
2perl
htkjl
import java.nio.file.*; import static java.util.Arrays.stream; public class MaxPathSum { public static void main(String[] args) throws Exception { int[][] data = Files.lines(Paths.get("triangle.txt")) .map(s -> stream(s.trim().split("\\s+")) .mapToInt(Integer::parse...
588Maximum triangle path sum
9java
7dprj
require 'openssl' puts OpenSSL::Digest::MD4.hexdigest('Rosetta Code')
586MD4
14ruby
ma5yj
numbers = ARGV.map(&:to_i) if numbers.length == 0 puts puts() exit end def maya_print(number) digits5s1s = number.to_s(20).chars.map { |ch| ch.to_i(20) }.map { |dig| dig.divmod(5) } puts(('+----' * digits5s1s.length) + '+') 3.downto(0) do |row| digits5s1s.each do |d5s1s| if row < d5s1s[0] ...
589Mayan numerals
14ruby
u0rvz
typedef int bool; typedef unsigned long long ull; bool is_prime(ull n) { ull d; if (n < 2) return FALSE; if (!(n % 2)) return n == 2; if (!(n % 3)) return n == 3; d = 5; while (d * d <= n) { if (!(n % d)) return FALSE; d += 2; if (!(n % d)) return FALSE; d +=...
598Magnanimous numbers
5c
vqy2o
import Data.List (transpose) (<+>) :: Num a => [a] -> [a] -> [a] (<+>) = zipWith (+) (<*>) :: Num a => [a] -> [a] -> a (<*>) = (sum .) . zipWith (*) newtype Mat a = Mat [[a]] deriving (Eq, Show) instance Num a => Num (Mat a) where negate (Mat x) = Mat $ map (map negate) x Mat x + Mat y = Ma...
591Matrix-exponentiation operator
8haskell
cw294
math.randomseed( os.time() ) local black, white, none, code = "X", "O", "-" local colors, codeLen, maxGuess, rept, alpha, opt = 6, 4, 10, false, "ABCDEFGHIJKLMNOPQRST", "" local guesses, results function createCode() code = "" local dic, a = "" for i = 1, colors do dic = dic .. alpha:sub( i, i ) ...
594Mastermind
1lua
ktjh2
use strict; use warnings; my ($width, $height) = @ARGV; $_ ||= 10 for $width, $height; my %visited; my $h_barrier = "+" . ("--+" x $width) . "\n"; my $v_barrier = "|" . (" |" x $width) . "\n"; my @output = ($h_barrier, $v_barrier) x $height; push @output, $h_barrier; my @dx = qw(-1 1 0 0); my @dy = qw(0 0 -1 1); s...
587Maze solving
2perl
svdq3
var arr = [ [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], [27, 83, 58, 35, 71, 11, 25, 57, 29, 85], [14, 64, 36, 96, 27, 11, 58, 56, 92, 18, 55], [02, 90, 03, 60, 48, 4...
588Maximum triangle path sum
10javascript
p6xb7
null
586MD4
15rust
9e4mm
const ONE: &str = ""; const FIVE: &str = ""; const ZERO: &str = ""; fn main() { println!("{}", mayan(4005)); println!("{}", mayan(8017)); println!("{}", mayan(326_205)); println!("{}", mayan(886_205)); println!("{}", mayan(69)); println!("{}", mayan(420)); println!("{}", mayan(1_063_715_456...
589Mayan numerals
15rust
587uq
null
591Matrix-exponentiation operator
10javascript
9elml
use strict; use warnings; use Tk; my $delay = 50; my $fade = 8; my $base_color = ' my $fontname = 'Times'; my $fontsize = 12; my $font = "{$fontname} $fontsize bold"; my @objects; my ( $xv,...
593Matrix digital rain
2perl
4o45d
def parens(n): def aux(n, k): if n == 1: yield k elif n == 2: yield [k, k + 1] else: a = [] for i in range(1, n): for u in aux(i, k): for v in aux(n - i, k + i): yield [u, v] yield...
592Matrix chain multiplication
3python
kzbhf
aux <- function(i, j, u) { k <- u[[i, j]] if (k < 0) { i } else { paste0("(", Recall(i, k, u), "*", Recall(i + k, j - k, u), ")") } } chain.mul <- function(a) { n <- length(a) - 1 u <- matrix(0, n, n) v <- matrix(0, n, n) u[, 1] <- -1 for (j in seq(2, n)) { for (i in seq(n - j + 1)) { ...
592Matrix chain multiplication
13r
rn7gj
import org.bouncycastle.crypto.digests.MD4Digest object RosettaRIPEMD160 extends App { val (raw, messageDigest) = ("Rosetta Code".getBytes("US-ASCII"), new MD4Digest()) messageDigest.update(raw, 0, raw.length) val out = Array.fill[Byte](messageDigest.getDigestSize())(0) messageDigest.doFinal(out, 0) assert(...
586MD4
16scala
2q7lb
def mcnugget(limit) sv = (0..limit).to_a (0..limit).step(6) do |s| (0..limit).step(9) do |n| (0..limit).step(20) do |t| sv.delete(s + n + t) end end end sv.max end puts(mcnugget 100)
585McNuggets problem
14ruby
thlf2
os.MkdirAll("/tmp/some/path/to/dir", 0770)
595Make directory path
0go
f7id0
typedef struct arg { int (*fn)(struct arg*); int *k; struct arg *x1, *x2, *x3, *x4, *x5; } ARG; int f_1 (ARG* _) { return -1; } int f0 (ARG* _) { return 0; } int f1 (ARG* _) { return 1; } int eval(ARG* a) { return a->fn(a); } int A(ARG*); int B(ARG* a) { int k = *a->k -= 1; return A(...
599Man or boy test
5c
9afm1
(ns maze.core (:require [clojure.set:refer [intersection select]] [clojure.string:as str])) (defn neighborhood ([] (neighborhood [0 0])) ([coord] (neighborhood coord 1)) ([[y x] r] (let [y-- (- y r) y++ (+ y r) x-- (- x r) x++ (+ x r)] #{[y++ x] [y...
597Maze generation
6clojure
zhitj
use List::Util qw(any); print 'Enter pool size, puzzle size, attempts allowed: '; ($pool,$length,$tries) = split /\s+/, <>; $length = 4 if $length eq '' or $length < 3 or $length > 11; $pool = 6 if $pool eq '' or $pool < 2 or $pool > 21; $tries = 10 if $tries eq '' or $tries < 7 or $tries > 21; @valid ...
594Mastermind
2perl
zhftb
fn main() { let test_cases = vec![ [6, 9, 20], [12, 14, 17], [12, 13, 34], [5, 9, 21], [10, 18, 21], [71, 98, 99], [7_074_047, 8_214_596, 9_098_139], [582_795_988, 1_753_241_221, 6_814_151_015], [4, 30, 16], [12, 12, 13], [6, 15...
585McNuggets problem
15rust
zk2to
func maxNugget(limit: Int) -> Int { var (max, sixes, nines, twenties, i) = (0, 0, 0, 0, 0) mainLoop: while i < limit { sixes = 0 while sixes * 6 < i { if sixes * 6 == i { i += 1 continue mainLoop } nines = 0 while nines * 9 < i { if sixes * 6 + nines * 9 =...
585McNuggets problem
17swift
fjcdk
int** oddMagicSquare(int n) { if (n < 3 || n % 2 == 0) return NULL; int value = 0; int squareSize = n * n; int c = n / 2, r = 0,i; int** result = (int**)malloc(n*sizeof(int*)); for(i=0;i<n;i++) result[i] = (int*)malloc(n*sizeof(int)); while (++value <...
600Magic squares of singly even order
5c
m1nys
package main import ( "fmt" "math" "rcu" ) func magicConstant(n int) int { return (n*n + 1) * n / 2 } var ss = []string{ "\u2070", "\u00b9", "\u00b2", "\u00b3", "\u2074", "\u2075", "\u2076", "\u2077", "\u2078", "\u2079", } func superscript(n int) string { if n < 10 { return ss[n]...
601Magic constant
0go
o518q
import System.Directory (createDirectory, setCurrentDirectory) import Data.List.Split (splitOn) main :: IO () main = do let path = splitOn "/" "path/to/dir" mapM_ (\x -> createDirectory x >> setCurrentDirectory x) path
595Make directory path
8haskell
48v5s
import java.io.File; public interface Test { public static void main(String[] args) { try { File f = new File("C:/parent/test"); if (f.mkdirs()) System.out.println("path successfully created"); } catch (Exception e) { e.printStackTrace(); ...
595Make directory path
9java
cey9h
var path = require('path'); var fs = require('fs'); function mkdirp (p, cb) { cb = cb || function () {}; p = path.resolve(p); fs.mkdir(p, function (er) { if (!er) { return cb(null); } switch (er.code) { case 'ENOENT':
595Make directory path
10javascript
502ur
package main import "fmt" type sBox [8][16]byte type gost struct { k87, k65, k43, k21 [256]byte enc []byte } func newGost(s *sBox) *gost { var g gost for i := range g.k87 { g.k87[i] = s[7][i>>4]<<4 | s[6][i&15] g.k65[i] = s[5][i>>4]<<4 | s[4][i&15] g.k43[i] = s...
596Main step of GOST 28147-89
0go
m1zyi
int main() { int i; puts(); for(i=0;i<=10;i++) { printf(,i,mapRange(0,10,-1,0,i)); } return 0; }
602Map range
5c
503uk
import curses import random import time ROW_DELAY=.0001 def get_rand_in_range(min, max): return random.randrange(min,max+1) try: chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] total_chars = len(chars) stdscr = curses.initscr() curses.noecho() curses.curs_set(False) ...
593Matrix digital rain
3python
gig4h
use std::collections::HashMap; fn main() { println!("{}\n", mcm_display(vec![5, 6, 3, 1])); println!( "{}\n", mcm_display(vec![1, 5, 25, 30, 100, 70, 2, 1, 100, 250, 1, 1000, 2]) ); println!( "{}\n", mcm_display(vec![1000, 1, 500, 12, 1, 700, 2500, 3, 2, 5, 14, 10]) ...
592Matrix chain multiplication
15rust
1yapu
null
588Maximum triangle path sum
11kotlin
u07vc
use strict; use warnings; my @twenty = map $_ * ( $_ ** 2 + 1 ) / 2, 3 .. 22; print "first twenty: @twenty\n\n" =~ s/.{50}\K /\n/gr; my $thousandth = 1002 * ( 1002 ** 2 + 1 ) / 2; print "thousandth: $thousandth\n\n"; print "10**N order\n"; for my $i ( 1 .. 20 ) { printf "%3d%9d\n", $i, (10 ** $i * 2) ** ( 1 /...
601Magic constant
2perl
jdl7f
null
595Make directory path
11kotlin
3kfz5
require("lfs") function mkdir (path) local sep, pStr = package.config:sub(1, 1), "" for dir in path:gmatch("[^" .. sep .. "]+") do pStr = pStr .. dir .. sep lfs.mkdir(pStr) end end mkdir("C:\\path\\to\\dir")
595Make directory path
1lua
6bt39
const _ = [ [ 4, 10, 9, 2, 13, 8, 0, 14, 6, 11, 1, 12, 7, 15, 5, 3], [14, 11, 4, 12, 6, 13, 15, 10, 2, 3, 8, 1, 0, 7, 5, 9], [ 5, 8, 1, 13, 10, 3, 4, 2, 14, 15, 12, 7, 6, 0, 9, 11], [ 7, 13, 10, 1, 0, 8, 9, 15, 14, 4, 6, 12, 11, 2, 5, 3], [ 6, 12, 7, 1, 5, 15, 13, 8, 4, 10...
596Main step of GOST 28147-89
10javascript
hfgjh
package main import "fmt"
598Magnanimous numbers
0go
s21qa
null
591Matrix-exponentiation operator
11kotlin
igdo4
(defn maprange [[a1 a2] [b1 b2] s] (+ b1 (/ (* (- s a1) (- b2 b1)) (- a2 a1)))) > (doseq [s (range 11)] (printf "%2s maps to%s\n" s (maprange [0 10] [-1 0] s))) 0 maps to -1 1 maps to -9/10 2 maps to -4/5 3 maps to -7/10 4 maps to -3/5 5 maps to -1/2 6 maps to -2/5 7 maps to -3/10 8 maps to -1/5 9 m...
602Map range
6clojure
jdc7m
import random def encode(correct, guess): output_arr = [''] * len(correct) for i, (correct_char, guess_char) in enumerate(zip(correct, guess)): output_arr[i] = 'X' if guess_char == correct_char else 'O' if guess_char in correct else '-' return ''.join(output_arr) def safe_int_input(prompt, min...
594Mastermind
3python
3ktzc
local triangleSmall = { { 55 }, { 94, 48 }, { 95, 30, 96 }, { 77, 71, 26, 67 }, } local triangleLarge = { { 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,...
588Maximum triangle path sum
1lua
58ju6
(declare a) (defn man-or-boy "Man or boy test for Clojure" [k] (let [k (atom k)] (a k (fn [] 1) (fn [] -1) (fn [] -1) (fn [] 1) (fn [] 0)))) (defn a [k x1 x2 x3 x4 x5] (let [k (atom @k)] (letfn [(b [] (swap! k dec) (a k b x1 x2 x3 x4))...
599Man or boy test
6clojure
usyvi
null
596Main step of GOST 28147-89
11kotlin
lwycp
import Data.List.Split ( chunksOf ) import Data.List ( (!!) ) isPrime :: Int -> Bool isPrime n |n == 2 = True |n == 1 = False |otherwise = null $ filter (\i -> mod n i == 0 ) [2 .. root] where root :: Int root = floor $ sqrt $ fromIntegral n isMagnanimous :: Int -> Bool isMagnanimous n = all ...
598Magnanimous numbers
8haskell
9atmo
package main import ( "crypto/md5" "fmt" ) func main() { for _, p := range [][2]string{
590MD5
0go
svoqa