code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
require 'bit-struct'
class RS232_9 < BitStruct
unsigned :cd, 1,
unsigned :rd, 1,
unsigned :td, 1,
unsigned :dtr, 1,
unsigned :sg, 1,
unsigned :dsr, 1,
unsigned :rts, 1,
unsigned :cts, 1,
unsigned :ri, 1,
def self.new_with_int(... | 577Memory layout of a data structure | 14ruby | ig5oh |
(defn middle3 [v]
(let [no (Math/abs v)
digits (str no)
len (count digits)]
(cond
(< len 3):too_short
(even? len):no_middle_in_even_no_of_digits
:else (let [mid (/ len 2)
start (- mid 2)]
(apply str
(take 3
... | 581Middle three digits | 6clojure | lxbcb |
<?php
define('MINEGRID_WIDTH', 6);
define('MINEGRID_HEIGHT', 4);
define('MINESWEEPER_NOT_EXPLORED', -1);
define('MINESWEEPER_MINE', -2);
define('MINESWEEPER_FLAGGED', -3);
define('MINESWEEPER_FLAGGED_MINE', -4);
define('ACTIVATED_MINE', -5);
function check_field($field) {
if ($field === MI... | 568Minesweeper game | 12php | wcgep |
import Foundation
let size = 12
func printRow(with:Int, upto:Int) {
print(String(repeating: " ", count: (with-1)*4), terminator: "")
for i in with...upto {
print(String(format: "%l4d", i*with), terminator: "")
}
print()
}
print(" ", terminator: ""); printRow( with: 1, upto: size)
pri... | 560Multiplication tables | 17swift | 0uxs6 |
import scala.language.experimental.macros
import scala.reflect.macros.Context
object Macros {
def impl(c: Context) = {
import c.universe._
c.Expr[Unit](q"""println("Hello World")""")
}
def hello: Unit = macro impl
} | 572Metaprogramming | 16scala | 9eqm5 |
const char *menu_select(const char *const *items, const char *prompt);
int
main(void)
{
const char *items[] = {, , , , NULL};
const char *prompt = ;
printf(, menu_select(items, prompt));
return EXIT_SUCCESS;
}
const char *
menu_select(const char *const *items, const char *prompt)
{
char buf[BUFSIZ];
int i;
i... | 582Menu | 5c | lxkcy |
object Rs232Pins9 extends App {
val (off: Boolean, on: Boolean) = (false, true)
val plug = new Rs232Pins9(carrierDetect = on, receivedData = on) | 577Memory layout of a data structure | 16scala | th7fb |
bpm = Integer(ARGV[0]) rescue 60
msr = Integer(ARGV[1]) rescue 4
i = 0
loop do
(msr-1).times do
puts
sleep(60.0/bpm)
end
puts
sleep(60.0/bpm)
end | 573Metronome | 14ruby | 0u4su |
def metronome(bpm: Int, bpb: Int, maxBeats: Int = Int.MaxValue) {
val delay = 60000L / bpm
var beats = 0
do {
Thread.sleep(delay)
if (beats % bpb == 0) print("\nTICK ")
else print("tick ")
beats+=1
}
while (beats < maxBeats)
println()
}
metronome(120, 4, 20) | 573Metronome | 16scala | nrjic |
sealed public class Digest
{
public uint A;
public uint B;
public uint C;
public uint D;
public Digest()
{
A=(uint)MD5InitializerConstant.A;
B=(uint)MD5InitializerConstant.B;
C=(uint)MD5InitializerConstant.C;
D=(uint)MD5InitializerConstant.D;
}
public override string ToStrin... | 583MD5/Implementation | 5c | 7dxrg |
func inc(n int) {
x := n + 1
println(x)
} | 579Memory allocation | 0go | xlywf |
my $fmt = '|%-11s' x 5 . "|\n";
printf $fmt, qw( PATIENT_ID LASTNAME LAST_VISIT SCORE_SUM SCORE_AVG);
my ($names, $visits) = do { local $/; split /^\n/m, <DATA> };
my %score;
for ( $visits =~ /^\d.*/gm )
{
my ($id, undef, $score) = split /,/;
$score{$id} //= ['', ''];
$score and $score{$id}[0]++, $score{$id}[1]... | 578Merge and aggregate datasets | 2perl | u0xvr |
import Foreign
bytealloc :: IO ()
bytealloc = do
a0 <- mallocBytes 100
free a0
allocaBytes 100 $ \a ->
poke (a::Ptr Word32) 0 | 579Memory allocation | 8haskell | y1h66 |
null | 579Memory allocation | 9java | d75n9 |
'''
Minesweeper game.
There is an n by m grid that has a random number of between 20% to 60%
of randomly hidden mines that need to be found.
Positions in the grid are modified by entering their coordinates
where the first coordinate is horizontal in the grid and the second
vertical. The top left ... | 568Minesweeper game | 3python | cwi9q |
(defn menu [prompt choices]
(if (empty? choices)
""
(let [menutxt (apply str (interleave
(iterate inc 1)
(map #(str \space % \newline) choices)))]
(println menutxt)
(print prompt)
(flush)
(let [index (read-string (read-line))... | 582Menu | 6clojure | 4oe5o |
null | 579Memory allocation | 11kotlin | 0ucsf |
import pandas as pd
df_patients = pd.read_csv (r'patients.csv', sep = , decimal=)
df_visits = pd.read_csv (r'visits.csv', sep = , decimal=)
'''
import io
str_patients =
df_patients = pd.read_csv(io.StringIO(str_patients), sep = , decimal=)
str_visits =
df_visits = pd.read_csv(io.StringIO(str_visits), sep = , deci... | 578Merge and aggregate datasets | 3python | 58qux |
import'dart:math';
int length(int x)
{
int i,y;
for(i=0;;i++)
{
y=pow(10,i);
if(x%y==x)
break;
}
return i;
}
int middle(int x,int l)
{
int a=(x/10)-((x%10)/10);
int b=a%(pow(10,l-2));
int l2=length(b);
if(l2==3)
{
return b;
}
if(l2!=3)
{
... | 581Middle three digits | 18dart | nr2iq |
null | 560Multiplication tables | 20typescript | cwy99 |
df_patient <- read.table(text = "
PATIENT_ID,LASTNAME
1001,Hopper
4004,Wirth
3003,Kemeny
2002,Gosling
5005,Kurtz
", header = TRUE, sep = ",")
df_visits <- read.table(text = "
PATIENT_ID,VISIT_DATE,SCORE
2002,2020-09-10,6.8
1001,2020-09-17,5.5
4004,2020-09-24,8.4
2002,2020-10-08,
1001,,6.6
3003,2020-11-12,
4004,2020-1... | 578Merge and aggregate datasets | 13r | lxace |
package main
import "log"
func main() { | 576Miller–Rabin primality test | 0go | 6pb3p |
puts <<EOS
Minesweeper game.
There is an n by m grid that has a random number of between 20% to 60%
of randomly hidden mines that need to be found.
Positions in the grid are modified by entering their coordinates
where the first coordinate is horizontal in the grid and the second
vertical. Th... | 568Minesweeper game | 14ruby | 2qdlw |
module Primes where
import System.Random
import System.IO.Unsafe
isPrime :: Integer -> Bool
isPrime n = unsafePerformIO (isMillerRabinPrime 100 n)
isMillerRabinPrime :: Int -> Integer -> IO Bool
isMillerRabinPrime k n
| even n = return (n==2)
| n < 100 = return (n `elem` primesTo100)
| otherwise = do... | 576Miller–Rabin primality test | 8haskell | jfd7g |
package main
import "fmt"
func mertens(to int) ([]int, int, int) {
if to < 1 {
to = 1
}
merts := make([]int, to+1)
primes := []int{2}
var sum, zeros, crosses int
for i := 1; i <= to; i++ {
j := i
cp := 0 | 580Mertens function | 0go | kzihz |
extern crate rand;
use std::io;
use std::io::Write;
fn main() {
use minesweeper::{MineSweeper, GameStatus};
let mut width = 6;
let mut height = 4;
let mut mine_perctg = 10;
let mut game = MineSweeper::new(width, height, mine_perctg);
loop {
let mut command = String::new();
... | 568Minesweeper game | 15rust | vsf2t |
import Data.List.Split (chunksOf)
import qualified Data.MemoCombinators as Memo
import Math.NumberTheory.Primes (unPrime, factorise)
import Text.Printf (printf)
moebius :: Integer -> Int
moebius = product . fmap m . factorise
where
m (p, e)
| unPrime p =... | 580Mertens function | 8haskell | nrvie |
-- drop tables
DROP TABLE IF EXISTS tmp_patients;
DROP TABLE IF EXISTS tmp_visits;
-- create tables
CREATE TABLE tmp_patients(
PATIENT_ID INT,
LASTNAME VARCHAR(20)
);
CREATE TABLE tmp_visits(
PATIENT_ID INT,
VISIT_DATE DATE,
SCORE NUMERIC(4,1)
);
-- load data from csv files
-- load data hard coded
INSERT INTO... | 578Merge and aggregate datasets | 19sql | p6tb1 |
package main
import (
"fmt"
"math"
"bytes"
"encoding/binary"
)
type testCase struct {
hashCode string
string
}
var testCases = []testCase{
{"d41d8cd98f00b204e9800998ecf8427e", ""},
{"0cc175b9c0f1b6a831c399e269772661", "a"},
{"900150983cd24fb0d6963f7d28e17f72", "abc"},
{"f96b69... | 583MD5/Implementation | 0go | d7lne |
import java.math.BigInteger;
public class MillerRabinPrimalityTest {
public static void main(String[] args) {
BigInteger n = new BigInteger(args[0]);
int certainty = Integer.parseInt(args[1]);
System.out.println(n.toString() + " is " + (n.isProbablePrime(certainty) ? "probably prime" : "composite"));
}... | 576Miller–Rabin primality test | 9java | u0svv |
public class MertensFunction {
public static void main(String[] args) {
System.out.printf("First 199 terms of the merten function are as follows:%n ");
for ( int n = 1 ; n < 200 ; n++ ) {
System.out.printf("%2d ", mertenFunction(n));
if ( (n+1) % 20 == 0 ) {
... | 580Mertens function | 9java | q2yxa |
class MD5 {
private static final int INIT_A = 0x67452301
private static final int INIT_B = (int)0xEFCDAB89L
private static final int INIT_C = (int)0x98BADCFEL
private static final int INIT_D = 0x10325476
private static final int[] SHIFT_AMTS = [
7, 12, 17, 22,
5, 9, 14, 20... | 583MD5/Implementation | 7groovy | 0u6sh |
function probablyPrime(n) {
if (n === 2 || n === 3) return true
if (n % 2 === 0 || n < 2) return false | 576Miller–Rabin primality test | 10javascript | 7dnrd |
import Control.Monad (replicateM)
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Lazy.Char8 as BLC
import Data.Binary.Get
import Data.Binary.Put
import Data.Bits
import Data.Array (Array, listArray, (!))
import Data.List (foldl)
import Data.Word (Word32)
import Numeric (showHex)
type... | 583MD5/Implementation | 8haskell | 581ug |
atom addr = allocate(512) -- limit is 1,610,612,728 bytes on 32-bit systems
...
free(addr)
atom addr2 = allocate(512,1) -- automatically freed when addr2 drops out of scope or re-assigned
atom addr3 = allocate_string("a string",1) -- automatically freed when addr3 drops out of scope or re... | 579Memory allocation | 2perl | 58xu2 |
null | 576Miller–Rabin primality test | 11kotlin | 9eamh |
class MD5
{
private static final int INIT_A = 0x67452301;
private static final int INIT_B = (int)0xEFCDAB89L;
private static final int INIT_C = (int)0x98BADCFEL;
private static final int INIT_D = 0x10325476;
private static final int[] SHIFT_AMTS = {
7, 12, 17, 22,
5, 9, 14, 20,
4, 11, 16, 23,
... | 583MD5/Implementation | 9java | 9e7mu |
>>> from array import array
>>> argslist = [('l', []), ('c', 'hello world'), ('u', u'hello \u2641'),
('l', [1, 2, 3, 4, 5]), ('d', [1.0, 2.0, 3.14])]
>>> for typecode, initializer in argslist:
a = array(typecode, initializer)
print a
del a
array('l')
array('c', 'hello world')
array('u', u'hello \u2641')
array('l'... | 579Memory allocation | 3python | 4oq5k |
function MRIsPrime(n, k) | 576Miller–Rabin primality test | 1lua | cwe92 |
x=numeric(10)
rm(x)
x=vector("list",10)
x=vector("numeric",10)
rm(x) | 579Memory allocation | 13r | 2qalg |
use utf8;
use strict;
use warnings;
use feature 'say';
use List::Util 'uniq';
sub prime_factors {
my ($n, $d, @factors) = (shift, 1);
while ($n > 1 and $d++) {
$n /= $d, push @factors, $d until $n % $d;
}
@factors
}
sub {
my @p = prime_factors(shift);
@p == uniq(@p) ? 0 == @p%2 ? 1 : ... | 580Mertens function | 2perl | mahyz |
null | 583MD5/Implementation | 11kotlin | zkuts |
package m3
import (
"errors"
"strconv"
)
var (
ErrorLT3 = errors.New("N of at least three digits required.")
ErrorEven = errors.New("N with odd number of digits required.")
)
func Digits(i int) (string, error) {
if i < 0 {
i = -i
}
if i < 100 {
return "", ErrorLT3
}
... | 581Middle three digits | 0go | p6nbg |
package main
import "fmt"
func menu(choices []string, prompt string) string {
if len(choices) == 0 {
return ""
}
var c int
for {
fmt.Println("")
for i, s := range choices {
fmt.Printf("%d. %s\n", i+1, s)
}
fmt.Print(prompt)
_, err := fmt.Scan... | 582Menu | 0go | xlzwf |
class Thingamajig
def initialize
fail 'not yet implemented'
end
end
t = Thingamajig.allocate | 579Memory allocation | 14ruby | rn0gs |
null | 579Memory allocation | 15rust | 7d8rc |
null | 583MD5/Implementation | 1lua | 3b5zo |
PRINT PEEK 16388+256*16389 | 579Memory allocation | 16scala | kznhk |
def middleThree(Number number) {
def text = Math.abs(number) as String
assert text.size() >= 3: "'$number' must be more than 3 numeric digits"
assert text.size() % 2 == 1: "'$number' must have an odd number of digits"
int start = text.size() / 2 - 1
text[start..(start+2)]
} | 581Middle three digits | 7groovy | 7dsrz |
module RosettaSelect where
import Data.Maybe (listToMaybe)
import Control.Monad (guard)
select :: [String] -> IO String
select [] = return ""
select menu = do
putStr $ showMenu menu
putStr "Choose an item: "
choice <- getLine
maybe (select menu) return $ choose menu choice
showMenu :: [String] -> String
sh... | 582Menu | 8haskell | y1r66 |
mid3 :: Int -> Either String String
mid3 n
| m < 100 = Left "is too small"
| even lng = Left "has an even number of digits"
| otherwise = Right . take 3 $ drop ((lng - 3) `div` 2) s
where
m = abs n
s = show m
lng = length s
main :: IO ()
main = do
let xs =
[ 123
, 12345
,... | 581Middle three digits | 8haskell | fjud1 |
def mertens(count):
m = [None, 1]
for n in range(2, count+1):
m.append(1)
for k in range(2, n+1):
m[n] -= m[n
return m
ms = mertens(1000)
print()
print(, end=' ')
col = 1
for n in ms[1:100]:
print(.format(n), end=' ')
col += 1
if col == 10:
print()
... | 580Mertens function | 3python | 9ekmf |
use bigint try => 'GMP';
sub is_prime {
my ($n, $k) = @_;
return 1 if $n == 2;
return 0 if $n < 2 or $n % 2 == 0;
my $d = $n - 1;
my $s = 0;
while (!($d % 2)) {
$d /= 2;
$s++;
}
LOOP: for (1 .. $k) {
my $a = 2 + int(rand($n - 2));
my $x = $a->bmodpow($d... | 576Miller–Rabin primality test | 2perl | wc9e6 |
public class MiddleThreeDigits {
public static void main(String[] args) {
final long[] passing = {123, 12345, 1234567, 987654321, 10001, -10001,
-123, -100, 100, -12345, Long.MIN_VALUE, Long.MAX_VALUE};
final int[] failing = {1, 2, -1, -10, 2002, -2002, 0, Integer.MIN_VALUE,
... | 581Middle three digits | 9java | 0umse |
require 'prime'
def (n)
return 1 if self == 1
pd = n.prime_division
return 0 unless pd.map(&:last).all?(1)
pd.size.even?? 1: -1
end
def M(n)
(1..n).sum{|n| (n)}
end
([] + (1..199).map{|n| % M(n)}).each_slice(20){|line| puts line.join() }
ar = (1..1000).map{|n| M(n)}
puts
puts | 580Mertens function | 14ruby | lxpcl |
public static String select(List<String> list, String prompt){
if(list.size() == 0) return "";
Scanner sc = new Scanner(System.in);
String ret = null;
do{
for(int i=0;i<list.size();i++){
System.out.println(i + ": "+list.get(i));
}
System.out.print(prompt);
int... | 582Menu | 9java | d72n9 |
function middleThree(x){
var n=''+Math.abs(x); var l=n.length-1;
if(l<2||l%2) throw new Error(x+': Invalid length '+(l+1));
return n.slice(l/2-1,l/2+2);
}
[123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -12345,
1, 2, -1, -10, 2002, -2002, 0].forEach(function(n){
try{console.log(n,middleThree(n... | 581Middle three digits | 10javascript | d7vnu |
<?php
function is_prime($n, $k) {
if ($n == 2)
return true;
if ($n < 2 || $n % 2 == 0)
return false;
$d = $n - 1;
$s = 0;
while ($d % 2 == 0) {
$d /= 2;
$s++;
}
for ($i = 0; $i < $k; $i++) {
$a = rand(2, $n-1);
$x = bcpowmod($a, $d, $n);
... | 576Miller–Rabin primality test | 12php | lxwcj |
import Foundation
func mertensNumbers(max: Int) -> [Int] {
var mertens = Array(repeating: 1, count: max + 1)
for n in 2...max {
for k in 2...n {
mertens[n] -= mertens[n / k]
}
}
return mertens
}
let max = 1000
let mertens = mertensNumbers(max: max)
let count = 200
let colu... | 580Mertens function | 17swift | cwb9t |
const readline = require('readline');
async function menuSelect(question, choices) {
if (choices.length === 0) return '';
const prompt = choices.reduce((promptPart, choice, i) => {
return promptPart += `${i + 1}. ${choice}\n`;
}, '');
let inputChoice = -1;
while (inputChoice < 1 || inputChoice > choice... | 582Menu | 10javascript | 6pg38 |
use strict;
use warnings;
use integer;
use Test::More;
BEGIN { plan tests => 7 }
sub A() { 0x67_45_23_01 }
sub B() { 0xef_cd_ab_89 }
sub C() { 0x98_ba_dc_fe }
sub D() { 0x10_32_54_76 }
sub MAX() { 0xFFFFFFFF }
sub padding {
my $l = length (my $msg = shift() . chr(128));
$msg .= "\0" x (($l%64<=56?56:... | 583MD5/Implementation | 2perl | b38k4 |
null | 582Menu | 11kotlin | 0uysf |
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,... | 583MD5/Implementation | 3python | p6obm |
import random
def is_Prime(n):
if n!=int(n):
return False
n=int(n)
if n==0 or n==1 or n==4 or n==6 or n==8 or n==9:
return False
if n==2 or n==3 or n==5 or n==7:
return True
s = 0
d = n-1
while d%2==0:
d>>=1
s+=1
assert(2**s * d == n-1)... | 576Miller–Rabin primality test | 3python | xlcwr |
fun middleThree(x: Int): Int? {
val s = Math.abs(x).toString()
return when {
s.length < 3 -> null | 581Middle three digits | 11kotlin | e9ta4 |
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+... | 582Menu | 1lua | 85m0e |
#![allow(non_snake_case)] | 583MD5/Implementation | 15rust | e9daj |
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("0000045c5e2b3911eb937d9... | 583MD5/Implementation | 16scala | q2zxw |
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 | 581Middle three digits | 1lua | wczea |
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)
next if x == 1 || x == n - 1
for r in (1..s - 1)
x = x.pow(2, n)
return false if x == 1
break if x == n - 1
end
return false if x... | 576Miller–Rabin primality test | 14ruby | sv2qw |
use num::bigint::BigInt;
use num::bigint::ToBigInt; | 576Miller–Rabin primality test | 15rust | 0uvsl |
import Foundation
public class MD5 {
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, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, ... | 583MD5/Implementation | 17swift | 1yipt |
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"}")
} | 576Miller–Rabin primality test | 16scala | ig4ox |
sub menu
{
my ($prompt,@array) = @_;
return '' unless @array;
print " $_: $array[$_]\n" for(0..$
print $prompt;
$n = <>;
return $array[$n] if $n =~ /^\d+$/ and defined $array[$n];
return &menu($prompt,@array);
}
@a = ('fee fie', 'huff and puff', 'mirror mirror'... | 582Menu | 2perl | 58au2 |
<?php
$stdin = fopen(, );
$allowed = array(1 => 'fee fie', 'huff and puff', 'mirror mirror', 'tick tock');
for(;;) {
foreach ($allowed as $id => $name) {
echo ;
}
echo ;
$stdin_string = fgets($stdin, 4096);
if (isset($allowed[(int) $stdin_string])) {
echo ;
break;
}
} | 582Menu | 12php | o4985 |
package main
import (
"fmt"
"strconv"
"strings"
"time"
)
var sacred = strings.Fields("Imix Ik Akbal Kan Chikchan Kimi Manik Lamat Muluk Ok Chuwen Eb Ben Hix Men Kib Kaban Etznab Kawak Ajaw")
var civil = strings.Fields("Pop Wo Sip Sotz Sek Xul Yaxkin Mol Chen Yax Sak Keh Mak Kankin Muwan Pax Kayab Kum... | 584Mayan calendar | 0go | jfx7d |
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 += 1
d... | 576Miller–Rabin primality test | 17swift | q2lxg |
use strict;
use warnings;
use utf8;
binmode STDOUT, ":utf8";
use Math::BaseArith;
use Date::Calc 'Delta_Days';
my @sacred = qw<Imix Ik Akbal Kan Chikchan Kimi Manik Lamat Muluk Ok
Chuwen Eb Ben Hix Men Kib Kaban Etznab Kawak Ajaw>;
my @civil = qw<Pop Wo Sip Sotz Sek Xul Yaxkin Mol Chen Yax Sak Keh
... | 584Mayan calendar | 2perl | 6p536 |
import datetime
def g2m(date, gtm_correlation=True):
correlation = 584283 if gtm_correlation else 584285
long_count_days = [144000, 7200, 360, 20, 1]
tzolkin_months = ['Imix', 'Ik', 'Akbal', 'Kan', 'Chikchan', 'Kimi', 'Manik', 'Lamat', 'Muluk', 'Ok', 'Chuwen',
'Eb', 'Be... | 584Mayan calendar | 3python | y146q |
def _menu(items):
for indexitem in enumerate(items):
print (% 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: return ''
... | 582Menu | 3python | 4oe5k |
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() | 582Menu | 13r | 2qblg |
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++) {
if (sixes*6 +... | 585McNuggets problem | 5c | 0uzst |
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 ( $numberlength % 2 =... | 581Middle three digits | 2perl | cwk9a |
(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? #{x... | 585McNuggets problem | 6clojure | d79nb |
char *MD4(char *str, int len);
typedef struct string{
char *c;
int len;
char sign;
}string;
static uint32_t *MD4Digest(uint32_t *w, int len);
static void setMD4Registers(uint32_t AA, uint32_t BB, uint32_t CC, uint32_t DD);
static uint32_t changeEndianness(uint32_t x);
static void resetMD4Regi... | 586MD4 | 5c | d7mnv |
function middlethree($integer)
{
$int = (int)str_replace('-','',$integer);
$length = strlen($int);
if(is_int($int))
{
if($length >= 3)
{
if($length % 2 == 1)
{
$middle = floor($length / 2) - 1;
return substr($int,$middle, 3);
}
else
{
return 'The value must contain an odd amount of ... | 581Middle three digits | 12php | xl3w5 |
(use 'pandect.core)
(md4 "Rosetta Code") | 586MD4 | 6clojure | 6pv3q |
def select(prompt, items = [])
if items.empty?
''
else
answer = -1
until (0...items.length).cover?(answer)
items.each_with_index {|i,j| puts }
print
begin
answer = Integer(gets)
rescue ArgumentError
redo
end
end
items[answer]
end
end
response = ... | 582Menu | 14ruby | rnxgs |
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)),... | 585McNuggets problem | 18dart | amo1h |
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 a nu... | 582Menu | 15rust | 7dqrc |
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"${ind... | 582Menu | 16scala | kz8hk |
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 = readLine(... | 582Menu | 17swift | giw49 |
>>> def middle_three_digits(i):
s = str(abs(i))
length = len(s)
assert length >= 3 and length% 2 == 1,
mid = length
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 in passing + failing:
try:
a... | 581Middle three digits | 3python | lxbcv |
using namespace std;
const int BMP_SIZE = 512, CELL_SIZE = 8;
enum directions { NONE, NOR = 1, EAS = 2, SOU = 4, WES = 8 };
class myBitmap
{
public:
myBitmap() : pen( NULL ) {}
~myBitmap()
{
DeleteObject( pen );
DeleteDC( hdc );
DeleteObject( bmp );
}
bool create( int w, int h )
{
BIT... | 587Maze solving | 5c | e98av |
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))
} | 586MD4 | 0go | 7dar2 |
package main
import "fmt"
func mcnugget(limit int) {
sv := make([]bool, limit+1) | 585McNuggets problem | 0go | u0kvt |
#!/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 | 586MD4 | 8haskell | 85z0z |
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 = sum ... | 585McNuggets problem | 8haskell | wcned |
(ns small-projects.find-shortest-way
(:require [clojure.string:as str]))
(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 cell]]
[[y (dec x)] ... | 587Maze solving | 6clojure | 0ufsj |
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, 29, 85,
14, 64, 36, 96, 27, 11, 58, 56, 92, 18, 55,
2, 90, 3, 60, 48, 49, 41, 46,... | 588Maximum triangle path sum | 5c | xlowu |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.