code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
func dot(v1: [Double], v2: [Double]) -> Double { return reduce(lazy(zip(v1, v2)).map(*), 0, +) } println(dot([1, 3, -5], [4, -2, -1]))
938Dot product
17swift
4ph5g
DECLARE @s VARCHAR(10) SET @s = '1234.56' print isnumeric(@s) --prints 1 if numeric, 0 if not. IF isnumeric(@s)=1 BEGIN print 'Numeric' END ELSE print 'Non-numeric'
956Determine if a string is numeric
19sql
zlat4
func isNumeric(a: String) -> Bool { return Double(a)!= nil }
956Determine if a string is numeric
17swift
0trs6
package main import ( "fmt" "math/big" "rcu" ) func main() { count := 0 limit := 25 n := int64(17) repunit := big.NewInt(1111111111111111) t := new(big.Int) zero := new(big.Int) eleven := big.NewInt(11) hundred := big.NewInt(100) var deceptive []int64 for count < li...
959Deceptive numbers
0go
eoca6
use strict; use warnings; use Math::AnyNum qw(imod is_prime); my($x,@D) = 2; while ($x++) { push @D, $x if 1 == $x%2 and !is_prime $x and 0 == imod(1x($x-1),$x); last if 25 == @D } print "@D\n";
959Deceptive numbers
2perl
vj020
null
959Deceptive numbers
15rust
gpn4o
typedef struct{ int a; }layer1; typedef struct{ layer1 l1; float b,c; }layer2; typedef struct{ layer2 l2; layer1 l1; int d,e; }layer3; void showCake(layer3 cake){ printf(,cake.d); printf(,cake.e); printf(,cake.l1.a); printf(,cake.l2.b); printf(,cake.l2.l1.a); } int main() { layer3 cake1,cake2; cake1.d...
960Deepcopy
5c
m5ays
package main import "fmt"
960Deepcopy
0go
a8m1f
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class DeepCopy { public static void main(String[] args) { Person p1 = new Person("Clark", "Kent", new Address("1 World Center"...
960Deepcopy
9java
o348d
var deepcopy = function(o){ return JSON.parse(JSON.stringify(src)); }; var src = {foo:0,bar:[0,1]}; print(JSON.stringify(src)); var dst = deepcopy(src); print(JSON.stringify(src));
960Deepcopy
10javascript
tchfm
null
960Deepcopy
11kotlin
xnlws
double PI; typedef double complex cplx; void _fft(cplx buf[], cplx out[], int n, int step) { if (step < n) { _fft(out, buf, n, step * 2); _fft(out + step, buf + step, n, step * 2); for (int i = 0; i < n; i += 2 * step) { cplx t = cexp(-I * PI * i / n) * out[i + step]; buf[i / 2] = out[i] + t; buf[...
961Deconvolution/1D
5c
4b85t
function _deepcopy(o, tables) if type(o) ~= 'table' then return o end if tables[o] ~= nil then return tables[o] end local new_o = {} tables[o] = new_o for k, v in next, o, nil do local new_k = _deepcopy(k, tables) local new_v = _deepcopy(v, tables) new_o[new_k] = new_v end ret...
960Deepcopy
1lua
qd2x0
package main import "fmt" func main() { h := []float64{-8, -9, -3, -1, -6, 7} f := []float64{-3, -6, -1, 8, -6, 3, -1, -9, -9, 3, -2, 5, 2, -2, -7, -1} g := []float64{24, 75, 71, -34, 3, 22, -45, 23, 245, 25, 52, 25, -67, -96, 96, 31, 55, 36, 29, -43, -7} fmt.Println(h) fmt.Println(deconv(...
961Deconvolution/1D
0go
o358q
use strict; use warnings; use Storable; use Data::Dumper; my $src = { foo => 0, bar => [0, 1] }; $src->{baz} = $src; my $dst = Storable::dclone($src); print Dumper($src); print Dumper($dst);
960Deepcopy
2perl
27qlf
deconv1d :: [Double] -> [Double] -> [Double] deconv1d xs ys = takeWhile (/= 0) $ deconv xs ys where [] `deconv` _ = [] (0:xs) `deconv` (0:ys) = xs `deconv` ys (x:xs) `deconv` (y:ys) = let q = x / y in q: zipWith (-) xs (scale q ys ++ repeat 0) `deconv` (y: ys) scale :: Double -> [Double] -> [...
961Deconvolution/1D
8haskell
27xll
<?php class Foo { public function __clone() { $this->child = clone $this->child; } } $object = new Foo; $object->some_value = 1; $object->child = new stdClass; $object->child->some_value = 1; $deepcopy = clone $object; $deepcopy->some_value++; $deepcopy->child->some_value++; echo , ; ?>
960Deepcopy
12php
sfvqs
import java.util.Arrays; public class Deconvolution1D { public static int[] deconv(int[] g, int[] f) { int[] h = new int[g.length - f.length + 1]; for (int n = 0; n < h.length; n++) { h[n] = g[n]; int lower = Math.max(n - f.length + 1, 0); for (int i = lower; i <...
961Deconvolution/1D
9java
6vb3z
import copy deepcopy_of_obj = copy.deepcopy(obj)
960Deepcopy
3python
vjs29
(defn tinyint [^long value] (if (<= 1 value 10) (proxy [Number] [] (doubleValue [] value) (longValue [] value)) (throw (ArithmeticException. "integer overflow"))))
962Define a primitive data type
6clojure
jen7m
null
961Deconvolution/1D
11kotlin
dmrnz
function deconvolve(f, g) local h = setmetatable({}, {__index = function(self, n) if n == 1 then self[1] = g[1] / f[1] else self[n] = g[n] for i = 1, n - 1 do self[n] = self[n] - self[i] * (f[n - i + 1] or 0) end self[n] = self[n] / f[1] end ret...
961Deconvolution/1D
1lua
f97dp
orig = { :num => 1, :ary => [2, 3] } orig[:cycle] = orig copy = Marshal.load(Marshal.dump orig) orig[:ary] << 4 orig[:rng] = (5..6) p orig p copy p [(orig.equal? orig[:cycle]), (copy.equal? copy[:cycle]), (not orig.equal? copy)]
960Deepcopy
14ruby
5k8uj
null
960Deepcopy
15rust
4bo5u
const char *shades = ; double light[3] = { -50, 0, 50 }; void normalize(double * v) { double len = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); v[0] /= len; v[1] /= len; v[2] /= len; } double dot(double *x, double *y) { double d = x[0]*y[0] + x[1]*y[1] + x[2]*y[2]; return d < 0 ? -d : 0; } typedef struct { double cx...
963Death Star
5c
qd9xc
use Math::Cartesian::Product; sub deconvolve { our @g; local *g = shift; our @f; local *f = shift; my(@m,@d); my $h = 1 + @g - @f; push @m, [(0) x $h, $g[$_]] for 0..$ for my $j (0..$h-1) { for my $k (0..$ $m[$j + $k][$j] = $f[$k] } } rref(\@m); push @d,...
961Deconvolution/1D
2perl
jed7f
def ToReducedRowEchelonForm( M ): if not M: return lead = 0 rowCount = len(M) columnCount = len(M[0]) for r in range(rowCount): if lead >= columnCount: return i = r while M[i][lead] == 0: i += 1 if i == rowCount: i = r ...
961Deconvolution/1D
3python
hwfjw
wchar_t s_suits[] = L, s_nums[] = L; static int seed = 1; int rnd(void) { return (seed = (seed * 214013 + 2531011) & RMAX32) >> 16; } void srnd(int x) { seed = x; } void show(const int *c) { int i; for (i = 0; i < 52; c++) { printf(, 32 - (1 + *c) % 4 / 2, s_suits[*c % 4], s_nums[*c / 4]); if (!(++i % 8) |...
964Deal cards for FreeCell
5c
327za
conv <- function(a, b) { p <- length(a) q <- length(b) n <- p + q - 1 r <- nextn(n, f=2) y <- fft(fft(c(a, rep(0, r-p))) * fft(c(b, rep(0, r-q))), inverse=TRUE)/r y[1:n] } deconv <- function(a, b) { p <- length(a) q <- length(b) n <- p - q + 1 r <- nextn(max(p, q), f=2) y <- fft(fft(c(a, rep(0, r-p))) / fft...
961Deconvolution/1D
13r
gpo47
double PI; typedef double complex cplx; void _fft(cplx buf[], cplx out[], int n, int step) { if (step < n) { _fft(out, buf, n, step * 2); _fft(out + step, buf + step, n, step * 2); for (int i = 0; i < n; i += 2 * step) { cplx t = cexp(-I * PI * i / n) * out[i + step]; buf[i / 2] = out[i] + t; buf[...
965Deconvolution/2D+
5c
r1sg7
package main import ( "fmt" "image" "image/color" "image/png" "math" "os" ) type vector [3]float64 func (v *vector) normalize() { invLen := 1 / math.Sqrt(dot(v, v)) v[0] *= invLen v[1] *= invLen v[2] *= invLen } func dot(x, y *vector) float64 { return x[0]*y[0] + x[1]*y[1...
963Death Star
0go
27el7
package main import ( "bytes" "fmt" "strconv" "strings" ) const digits = "0123456789" func deBruijn(k, n int) string { alphabet := digits[0:k] a := make([]byte, k*n) var seq []byte var db func(int, int)
966de Bruijn sequences
0go
5keul
import Data.List (genericLength) shades = ".:!*oe%#&@" n = genericLength shades dot a b = sum $ zipWith (*) a b normalize x = (/ sqrt (x `dot` x)) <$> x deathStar r k amb = unlines $ [ [ if x*x + y*y <= r*r then let vec = normalize $ normal x y b = (light `dot` vec) ** k + amb in...
963Death Star
8haskell
a831g
package main import ( "fmt" "math" "math/cmplx" ) func fft(buf []complex128, n int) { out := make([]complex128, n) copy(out, buf) fft2(buf, out, n, 1) } func fft2(buf, out []complex128, n, step int) { if step < n { fft2(out, buf, n, step*2) fft2(out[step:], buf[step:], n, ...
965Deconvolution/2D+
0go
nyvi1
(def deck (into [] (for [rank "A23456789TJQK" suit "CDHS"] (str rank suit)))) (defn lcg [seed] (map #(bit-shift-right % 16) (rest (iterate #(mod (+ (* % 214013) 2531011) (bit-shift-left 1 31)) seed)))) (defn gen [seed] (map (fn [rnd rng] (into [] [(mod rnd rng) (dec rng)])) (lcg seed) (range 52 0 -1))) ...
964Deal cards for FreeCell
6clojure
cgp9b
import java.util.function.BiConsumer class DeBruijn { interface Recursable<T, U> { void apply(T t, U u, Recursable<T, U> r); } static <T, U> BiConsumer<T, U> recurse(Recursable<T, U> f) { return { t, u -> f.apply(t, u, f) } } private static String deBruijn(int k, int n) { ...
966de Bruijn sequences
7groovy
cgk9i
package main import "fmt" type TinyInt int func NewTinyInt(i int) TinyInt { if i < 1 { i = 1 } else if i > 10 { i = 10 } return TinyInt(i) } func (t1 TinyInt) Add(t2 TinyInt) TinyInt { return NewTinyInt(int(t1) + int(t2)) } func (t1 TinyInt) Sub(t2 TinyInt) TinyInt { return ...
962Define a primitive data type
0go
8zv0g
object Deconvolution1D extends App { val (h, f) = (Array(-8, -9, -3, -1, -6, 7), Array(-3, -6, -1, 8, -6, 3, -1, -9, -9, 3, -2, 5, 2, -2, -7, -1)) val g = Array(24, 75, 71, -34, 3, 22, -45, 23, 245, 25, 52, 25, -67, -96, 96, 31, 55, 36, 29, -43, -7) val sb = new StringBuilder private def deconv(g: Array[Int], ...
961Deconvolution/1D
16scala
eomab
import Data.List import Data.Map ((!)) import qualified Data.Map as M cycleForm :: [Int] -> [[Int]] cycleForm p = unfoldr getCycle $ M.fromList $ zip [0..] p where getCycle p | M.null p = Nothing | otherwise = let Just ((x,y), m) = M.minViewWithKey p c = if x == y then [] el...
966de Bruijn sequences
8haskell
xn3w4
data Check a b = Check { unCheck :: b } deriving (Eq, Ord) class Checked a b where check :: b -> Check a b lift f x = f (unCheck x) liftc f x = check $ f (unCheck x) lift2 f x y = f (unCheck x) (unCheck y) lift2c f x y = check $ f (unCheck x) (unCheck y) lift2p f x y = (check u, check v) where (u,v) = f (unCheck...
962Define a primitive data type
8haskell
lrech
import javafx.application.Application; import javafx.event.EventHandler; import javafx.geometry.Point3D; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; import javafx.scene.shape.MeshView; import javafx.scene.shape.TriangleMesh; import javafx....
963Death Star
9java
jei7c
func deconv(g: [Double], f: [Double]) -> [Double] { let fs = f.count var ret = [Double](repeating: 0, count: g.count - fs + 1) for n in 0..<ret.count { ret[n] = g[n] let lower = n >= fs? n - fs + 1: 0 for i in lower..<n { ret[n] -= ret[i] * f[n - i] } ret[n] /= f[0] } return ret ...
961Deconvolution/1D
17swift
kxthx
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.function.BiConsumer; public class DeBruijn { public interface Recursable<T, U> { void apply(T t, U u, Recursable<T, U> r); } public static <T, U> BiConsumer<T, U> recurse(Recursable<T, U> f) { retu...
966de Bruijn sequences
9java
bqik3
<!DOCTYPE html> <html> <body style="margin:0"> <canvas id="myCanvas" width="250" height="250" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag. </canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d");
963Death Star
10javascript
10zp7
const val digits = "0123456789" fun deBruijn(k: Int, n: Int): String { val alphabet = digits.substring(0, k) val a = ByteArray(k * n) val seq = mutableListOf<Byte>() fun db(t: Int, p: Int) { if (t > n) { if (n % p == 0) { seq.addAll(a.sliceArray(1..p).asList()) ...
966de Bruijn sequences
11kotlin
r1qgo
class BoundedIntOutOfBoundsException extends Exception { public BoundedIntOutOfBoundsException(int v, int l, int u) { super("value " + v + " is out of bounds [" + l + "," + u + "]"); } } class BoundedInt { private int value; private int lower; private int upper; public BoundedInt(int l, int u) { l...
962Define a primitive data type
9java
32hzg
function tprint(tbl) for i,v in pairs(tbl) do print(v) end end function deBruijn(k, n) local a = {} for i=1, k*n do table.insert(a, 0) end local seq = {} function db(t, p) if t > n then if n % p == 0 then for i=1, p do ...
966de Bruijn sequences
1lua
7asru
function Num(n){ n = Math.floor(n); if(isNaN(n)) throw new TypeError("Not a Number"); if(n < 1 || n > 10) throw new TypeError("Out of range"); this._value = n; } Num.prototype.valueOf = function() { return this._value; } Num.prototype.toString = function () { return this._value.toString(...
962Define a primitive data type
10javascript
cga9j
function V3(x,y,z) return {x=x,y=y,z=z} end function dot(v,w) return v.x*w.x + v.y*w.y + v.z*w.z end function norm(v) local m=math.sqrt(dot(v,v)) return V3(v.x/m, v.y/m, v.z/m) end function clamp(n,lo,hi) return math.floor(math.min(math.max(lo,n),hi)) end function hittest(s, x, y) local z = s.r^2 - (x-s.x)^2 - (y-s.y...
963Death Star
1lua
4bs5c
use feature 'say'; use ntheory qw/forsetproduct/; sub deconvolve_N { our @g; local *g = shift; our @f; local *f = shift; my @df = shape(@f); my @dg = shape(@g); my @hsize; push @hsize, $dg[$_] - $df[$_] + 1 for 0..$ my @toSolve = map { [row(\@g, \@f, \@hsize, $_)] } coords(shape(@g)); ...
965Deconvolution/2D+
2perl
kxihc
null
962Define a primitive data type
11kotlin
ny4ij
import numpy import pprint h = [ [[-6, -8, -5, 9], [-7, 9, -6, -8], [2, -7, 9, 8]], [[7, 4, 4, -6], [9, 9, 4, -4], [-3, 7, -2, -3]]] f = [ [[-9, 5, -8], [3, 5, 1]], [[-1, -7, 2], [-5, -6, 6]], [[8, 5, 8],[-2, -6, -4]]] g = [ [ [54, 42, 53, -42, 85, -72], [45...
965Deconvolution/2D+
3python
bqnkr
use strict; use warnings; use feature 'say'; my $seq; for my $x (0..99) { my $a = sprintf '%02d', $x; next if substr($a,1,1) < substr($a,0,1); $seq .= (substr($a,0,1) == substr($a,1,1)) ? substr($a,0,1) : $a; for ($a+1 .. 99) { next if substr(sprintf('%02d', $_), 1,1) <= substr($a,0,1); ...
966de Bruijn sequences
2perl
dmvnw
BI = {
962Define a primitive data type
1lua
dmgnq
use strict; sub sq { my $s = 0; $s += $_ ** 2 for @_; $s; } sub hit { my ($sph, $x, $y) = @_; $x -= $sph->[0]; $y -= $sph->[1]; my $z = sq($sph->[3]) - sq($x, $y); return if $z < 0; $z = sqrt $z; return $sph->[2] - $z, $sph->[2] + $z; } sub normalize { my $v = shift; my $n = sqrt sq(@$v); $_ /= $n for...
963Death Star
2perl
o3v8x
def de_bruijn(k, n): try: _ = int(k) alphabet = list(map(str, range(k))) except (ValueError, TypeError): alphabet = k k = len(k) a = [0] * k * n sequence = [] def db(t, p): if t > n: if n% p == 0: sequence....
966de Bruijn sequences
3python
f9ude
import sys, math, collections Sphere = collections.namedtuple(, ) V3 = collections.namedtuple(, ) def normalize((x, y, z)): len = math.sqrt(x**2 + y**2 + z**2) return V3(x / len, y / len, z / len) def dot(v1, v2): d = v1.x*v2.x + v1.y*v2.y + v1.z*v2.z return -d if d < 0 else 0.0 def hit_sphere(sph, ...
963Death Star
3python
i6uof
package main import ( "fmt" "math" "math/rand" "os" "strconv" "time" ) const sSuits = "CDHS" const sNums = "A23456789TJQK" const rMax32 = math.MaxInt32 var seed = 1 func rnd() int { seed = (seed*214013 + 2531011) & rMax32 return seed >> 16 } func deal(s int) []int { seed = s ...
964Deal cards for FreeCell
0go
bqdkh
class FreeCell{ int seed List<String> createDeck(){ List<String> suits = ['','','',''] List<String> values = ['A','2','3','4','5','6','7','8','9','10','J','Q','K'] return [suits,values].combinations{suit,value -> "$suit$value"} } int random() { seed = (214013 * seed + 2...
964Deal cards for FreeCell
7groovy
r10gh
import Data.Int import Data.Bits import Data.List import Data.Array.ST import Control.Monad import Control.Monad.ST import System.Environment srnd :: Int32 -> [Int] srnd = map (fromIntegral . flip shiftR 16) . tail . iterate (\x -> (x * 214013 + 2531011) .&. maxBound) deal :: Int32 -> [String] deal s = runST (...
964Deal cards for FreeCell
8haskell
dm5n4
def deBruijn(k, n) alphabet = @a = Array.new(k * n, 0) @seq = [] def db(k, n, t, p) if t > n then if n % p == 0 then temp = @a[1 .. p] @seq.concat temp end else @a[t] = @a[t - p] db(k, n, t + 1, p) ...
966de Bruijn sequences
14ruby
zl4tw
package One_To_Ten; use Carp qw(croak); use Tie::Scalar qw(); use base qw(Tie::StdScalar); sub STORE { my $self = shift; my $val = int shift; croak 'out of bounds' if $val < 1 or $val > 10; $$self = $val; }; package main; tie my $t, 'One_To_Ten'; $t = 3; $t = 5.2; $t = -2; $t = 11; $t = 'xyzzy...
962Define a primitive data type
2perl
7airh
package main import ( "fmt" "rcu" "strconv" "strings" ) func findFirst(list []int) (int, int) { for i, n := range list { if n > 1e7 { return n, i } } return -1, -1 } func reverse(s string) string { chars := []rune(s) for i, j := 0, len(chars)-1; i < j; ...
967Cyclops numbers
0go
vjp2m
import java.util.Arrays; public class Shuffler { private int seed; private String[] deck = { "AC", "AD", "AH", "AS", "2C", "2D", "2H", "2S", "3C", "3D", "3H", "3S", "4C", "4D", "4H", "4S", "5C", "5D", "5H", "5S", "6C", "6D", "6H", "6S", "7C", "7D", "7H", "7S", "8C", "8D", "8H", "8S", "9C...
964Deal cards for FreeCell
9java
sf9q0
typedef unsigned char byte; byte *grid = 0; int w, h, len; unsigned long long cnt; static int next[4], dir[4][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}}; void walk(int y, int x) { int i, t; if (!y || y == h || !x || x == w) { cnt += 2; return; } t = y * (w + 1) + x; grid[t]++, grid[len - t]++; for (i = 0; i...
968Cut a rectangle
5c
o3m80
import Control.Monad (replicateM) import Data.Numbers.Primes (isPrime) cyclops :: [Integer] cyclops = [0 ..] >>= flankingDigits where flankingDigits 0 = [0] flankingDigits n = fmap (\s -> read s :: Integer) ( (fmap ((<>) . (<> "0")) >>= (<*>)) (replicateM n ['1' .. '9']) ...
967Cyclops numbers
8haskell
eofai
"use strict"; Class('MSRand', { has: { seed: { is: rw, }, }, methods: { rand: function() { this.setSeed((this.getSeed() * 214013 + 2531011) & 0x7FFFFFFF); return ((this.getSeed() >> 16) & 0x7fff); }, max_rand: function(mymax) { return th...
964Deal cards for FreeCell
10javascript
nyuiy
null
964Deal cards for FreeCell
11kotlin
a8z13
>>> class num(int): def __init__(self, b): if 1 <= b <= 10: return int.__init__(self+0) else: raise ValueError,% b >>> x = num(3) >>> x = num(11) Traceback (most recent call last): File , line 1, in <module> x = num(11) File , line 6, in __init__ raise ValueErr...
962Define a primitive data type
3python
jen7p
deck = {} rank = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K"} suit = {"C", "D", "H", "S"} two31, state = bit32.lshift(1, 31), 0 function rng() state = (214013 * state + 2531011) % two31 return bit32.rshift(state, 16) end function initdeck() for i, r in ipairs(rank) do for j, s...
964Deal cards for FreeCell
1lua
eo3ac
package main import ( "fmt" "math/big" ) func main() { zero := big.NewInt(0) one := big.NewInt(1) for k := int64(2); k <= 10; k += 2 { bk := big.NewInt(k) fmt.Println("The first 50 Curzon numbers using a base of", k, ":") count := 0 n := int64(1) pow := big....
969Curzon numbers
0go
yu464
use strict; use warnings; use feature 'say'; use ntheory 'is_prime'; use List::AllUtils 'firstidx'; sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r } my @cyclops = 0; for my $exp (0..3) { my @oom = grep { ! /0/ } 10**$exp .. 10**($exp+1)-1; for my $l (@oom) { for my $r (@oom) { ...
967Cyclops numbers
2perl
i6co3
int main() { struct tm ts; time_t t; const char *d = ; strptime(d, , &ts); t = mktime(&ts); t += 12*60*60; printf(, ctime(&t)); return EXIT_SUCCESS; }
970Date manipulation
5c
tclf4
Some object-oriented languages won't let you subclass the data types like integers. Other languages implement those data types as classes, so you can subclass them, no questions asked. Ruby implements numbers as classes (Integer, with its concrete subclasses Fixnum and Bignum), and you can subclass those classes. If y...
962Define a primitive data type
14ruby
kxfhg
use std::convert::TryFrom; mod test_mod { use std::convert::TryFrom; use std::fmt;
962Define a primitive data type
15rust
bqtkx
class TinyInt(val int: Byte) { import TinyInt._ require(int >= lower && int <= upper, "TinyInt out of bounds.") override def toString = int.toString } object TinyInt { val (lower, upper) = (1, 10) def apply(i: Byte) = new TinyInt(i) } val test = (TinyInt.lower to TinyInt.upper).map(n => ...
962Define a primitive data type
16scala
a861n
int wday(int year, int month, int day) { int adjustment, mm, yy; adjustment = (14 - month) / 12; mm = month + 12 * adjustment - 2; yy = year - adjustment; return (day + (13 * mm - 1) / 5 + yy + yy / 4 - yy / 100 + yy / 400) % 7; } int main() { int y; for (y = 2008; y <= 2121; y++) { if (wday(y, 12, 25) ==...
971Day of the week
5c
277lo
use strict; use warnings; use Math::AnyNum 'ipow'; sub curzon { my($base,$cnt) = @_; my($n,@C) = 0; while (++$n) { push @C, $n if 0 == (ipow($base,$n) + 1) % ($base * $n + 1); return @C if $cnt == @C; } } my $upto = 50; for my $k (<2 4 6 8 10>) { my @C = curzon($k,1000); print ...
969Curzon numbers
2perl
xnfw8
null
969Curzon numbers
15rust
8z607
package main import "fmt" var grid []byte var w, h, last int var cnt int var next [4]int var dir = [4][2]int{{0, -1}, {-1, 0}, {0, 1}, {1, 0}} func walk(y, x int) { if y == 0 || y == h || x == 0 || x == w { cnt += 2 return } t := y*(w+1) + x grid[t]++ grid[last-t]++ for i, d :...
968Cut a rectangle
0go
4ba52
(import java.util.Date java.text.SimpleDateFormat) (defn time+12 [s] (let [sdf (SimpleDateFormat. "MMMM d yyyy h:mma zzz")] (-> (.parse sdf s) (.getTime ,) (+ , 43200000) long (Date. ,) (->> , (.format sdf ,)))))
970Date manipulation
6clojure
m54yq
struct SmallInt { var value: Int init(value: Int) { guard value >= 1 && value <= 10 else { fatalError("SmallInts must be in the range [1, 10]") } self.value = value } static func +(_ lhs: SmallInt, _ rhs: SmallInt) -> SmallInt { SmallInt(value: lhs.value + rhs.value) } static func -(_ lhs...
962Define a primitive data type
17swift
hwdj0
class CutRectangle { private static int[][] dirs = [[0, -1], [-1, 0], [0, 1], [1, 0]] static void main(String[] args) { cutRectangle(2, 2) cutRectangle(4, 3) } static void cutRectangle(int w, int h) { if (w % 2 == 1 && h % 2 == 1) { return } int[][]...
968Cut a rectangle
7groovy
lrhc1
require 'prime' NONZEROS = %w(1 2 3 4 5 6 7 8 9) cyclopes = Enumerator.new do |y| (0..).each do |n| NONZEROS.repeated_permutation(n) do |lside| NONZEROS.repeated_permutation(n) do |rside| y << (lside.join + + rside.join).to_i end end end end prime_cyclopes = Enumerator.ne...
967Cyclops numbers
14ruby
f9vdr
use strict; use warnings; use utf8; sub deal { my $s = shift; my $rnd = sub { return (($s = ($s * 214013 + 2531011) & 0x7fffffff) >> 16 ); }; my @d; for my $b (split "", "A23456789TJQK") { push @d, map("$_$b", qw/ /); } for my $idx (reverse 0 .. $ my $r = $rnd-...
964Deal cards for FreeCell
2perl
94bmn
(import '(java.util GregorianCalendar)) (defn yuletide [start end] (filter #(= (. (new GregorianCalendar % (. GregorianCalendar DECEMBER) 25) get (. GregorianCalendar DAY_OF_WEEK)) (. GregorianCalendar SUNDAY)) (range start (inc end)))) (yuletide 2008 2121)
971Day of the week
6clojure
gpp4f
import qualified Data.Vector.Unboxed.Mutable as V import Data.STRef import Control.Monad (forM_, when) import Control.Monad.ST dir :: [(Int, Int)] dir = [(1, 0), (-1, 0), (0, -1), (0, 1)] data Env = Env { w, h, len, count, ret :: !Int, next :: ![Int] } cutIt :: STRef s Env -> ST s () cutIt env = do e <- readSTRe...
968Cut a rectangle
8haskell
qdzx9
package main import ( "fmt" "log" "math" "sort" "strings" ) const ( algo = 2 maxAllFactors = 100000 ) func iabs(i int) int { if i < 0 { return -i } return i } type term struct{ coef, exp int } func (t term) mul(t2 term) term { return term{t.coef * t2.coe...
972Cyclotomic polynomial
0go
6v23p
class FreeCell_Deal { protected $deck = array( 'AC', 'AD', 'AH', 'AS', '2C', '2D', '2H', '2S', '3C', '3D', '3H', '3S', '4C', '4D', '4H', '4S', '5C', '5D', '5H', '5S', '6C', '6D', '6H', '6S', '7C', '7D', '7H', '7S', '8C', '8D', '8H', '8S', '9C', '9D', '9H', '9S', 'TC', 'TD', 'TH', ...
964Deal cards for FreeCell
12php
wi6ep
int cusipCheck(char str[10]){ int sum=0,i,v; for(i=0;i<8;i++){ if(str[i]>='0'&&str[i]<='9') v = str[i]-'0'; else if(str[i]>='A'&&str[i]<='Z') v = (str[i] - 'A' + 10); else if(str[i]=='*') v = 36; else if(str[i]=='@') v = 37; else if(str[i]==' v = 38; if(i%2!=0) v*=2; sum += ((int)(v/...
973CUSIP
5c
wi8ec
bool damm(unsigned char *input, size_t length) { static const unsigned char table[10][10] = { {0, 3, 1, 7, 5, 9, 8, 6, 4, 2}, {7, 0, 9, 2, 1, 5, 4, 8, 6, 3}, {4, 2, 0, 6, 8, 7, 1, 3, 5, 9}, {1, 7, 5, 0, 9, 8, 3, 4, 2, 6}, {6, 1, 2, 3, 0, 4, 5, 9, 7, 8}, {3, 6, 7, 4, 2...
974Damm algorithm
5c
cgu9c
import Data.List import Data.Numbers.Primes (primeFactors) negateVar p = zipWith (*) p $ reverse $ take (length p) $ cycle [1,-1] lift p 1 = p lift p n = intercalate (replicate (n-1) 0) (pure <$> p) shortDiv :: [Integer] -> [Integer] -> [Integer] shortDiv p1 (_:p2) = unfoldr go (length p1 - length p2, p1) where ...
972Cyclotomic polynomial
8haskell
jea7g
import java.util.*; public class CutRectangle { private static int[][] dirs = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}}; public static void main(String[] args) { cutRectangle(2, 2); cutRectangle(4, 3); } static void cutRectangle(int w, int h) { if (w % 2 == 1 && h % 2 == 1) ...
968Cut a rectangle
9java
psob3
long int factorial(int n){ if(n>1) return n*factorial(n-1); return 1; } long int sumOfFactorials(int num,...){ va_list vaList; long int sum = 0; va_start(vaList,num); while(num--) sum += factorial(va_arg(vaList,int)); va_end(vaList); return sum; } int main() { printf(,sumOfFactorials(5,1,2,3,4,5)); ...
975Currying
5c
lrucy
def randomGenerator(seed=1): max_int32 = (1 << 31) - 1 seed = seed & max_int32 while True: seed = (seed * 214013 + 2531011) & max_int32 yield seed >> 16 def deal(seed): nc = 52 cards = list(range(nc - 1, -1, -1)) rnd = randomGenerator(seed) for i, r in zip(range(nc), rnd): ...
964Deal cards for FreeCell
3python
cgp9q
package main import ( "fmt" big "github.com/ncw/gmp" ) func cullen(n uint) *big.Int { one := big.NewInt(1) bn := big.NewInt(int64(n)) res := new(big.Int).Lsh(one, n) res.Mul(res, bn) return res.Add(res, one) } func woodall(n uint) *big.Int { res := cullen(n) return res.Sub(res, bi...
976Cullen and Woodall numbers
0go
kxphz
import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; public class CyclotomicPolynomial { @SuppressWarnings("unused") private static int divisions = 0; private static int algor...
972Cyclotomic polynomial
9java
uhjvv
null
968Cut a rectangle
11kotlin
7axr4
library(gmp) rand_MS <- function(n = 1, seed = 1) { a <- as.bigz(214013) c <- as.bigz(2531011) m <- as.bigz(2^31) x <- rep(as.bigz(0), n) x[1] <- (a * as.bigz(seed) + c)%% m i <- 1 while (i < n) { x[i+1] <- (a * x[i] + c)%% m i <- i + 1 } as.integer(x / 2^16) } dealFreeCell <- function(...
964Deal cards for FreeCell
13r
6vj3e
(defn- char->value "convert the given char c to a value used to calculate the cusip check sum" [c] (let [int-char (int c)] (cond (and (>= int-char (int \0)) (<= int-char (int \9))) (- int-char 48) (and (>= int-char (int \A)) (<= int-char (int \Z))) (- int-char 55) (= c \*) 36 (= c \@) ...
973CUSIP
6clojure
8zf05