code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
package main import "fmt" type point struct { x, y float64 } func (p point) String() string { return fmt.Sprintf("(%.1f,%.1f)", p.x, p.y) } type triangle struct { p1, p2, p3 point } func (t *triangle) String() string { return fmt.Sprintf("Triangle%s,%s,%s", t.p1, t.p2, t.p3) } func (t *triangle) d...
950Determine if two triangles overlap
0go
sfbqa
int isNumeric (const char * s) { if (s == NULL || *s == '\0' || isspace(*s)) return 0; char * p; strtod (s, &p); return *p == '\0'; }
956Determine if a string is numeric
5c
a8211
null
948Determine if a string is collapsible
9java
7avrj
package main import "fmt" func analyze(s string) { chars := []rune(s) le := len(chars) fmt.Printf("Analyzing%q which has a length of%d:\n", s, le) if le > 1 { for i := 1; i < le; i++ { if chars[i] != chars[i-1] { fmt.Println(" Not all characters in the string are t...
949Determine if a string has all the same characters
0go
10rp5
import Data.Bifunctor (bimap) import Data.List (unfoldr) import Data.Tuple (swap) digSum :: Int -> Int -> Int digSum base = sum . unfoldr f where f 0 = Nothing f n = Just (swap (quotRem n base)) digRoot :: Int -> Int -> (Int, Int) digRoot base = head . dropWhile ((>= base) . snd) . iterate (bimap succ (...
945Digital root
8haskell
wi1ed
import Stream._ object MDR extends App { def mdr(x: BigInt, base: Int = 10): (BigInt, Long) = { def multiplyDigits(x: BigInt): BigInt = ((x.toString(base) map (_.asDigit)) :\ BigInt(1))(_*_) def loop(p: BigInt, c: Long): (BigInt, Long) = if (p < base) (p, c) else loop(multiplyDigits(p), c+1) loop(multip...
936Digital root/Multiplicative digital root
16scala
iy6ox
use strict; use warnings; use feature <state say>; use List::Util 1.33 qw(pairmap); use Algorithm::Permute qw(permute); our %predicates = ( 'on bottom' => [ '' , '$f[%s] == 1' ], 'on top' => [ '' , '$f[%s] == @f' ], 'lower than' => [...
939Dinesman's multiple-dwelling problem
2perl
5b7u2
dotp :: Num a => [a] -> [a] -> a dotp a b | length a == length b = sum (zipWith (*) a b) | otherwise = error "Vector sizes must match" main = print $ dotp [1, 3, -5] [4, -2, -1]
938Dot product
8haskell
6ul3k
null
954Deming's Funnel
11kotlin
hw9j3
(defprotocol Thing (thing [_])) (defprotocol Operation (operation [_])) (defrecord Delegator [delegate] Operation (operation [_] (try (thing delegate) (catch IllegalArgumentException e "default implementation")))) (defrecord Delegate [] Thing (thing [_] "delegate implementation"))
955Delegates
6clojure
102py
import java.util.function.BiFunction class TriangleOverlap { private static class Pair { double first double second Pair(double first, double second) { this.first = first this.second = second } @Override String toString() { retur...
950Determine if two triangles overlap
7groovy
a8r1p
package main import ( "fmt" "permute" ) func determinant(m [][]float64) (d float64) { p := make([]int, len(m)) for i := range p { p[i] = i } it := permute.Iter(p) for s := it(); s != 0; s = it() { pr := 1. for i, := range p { pr *= m[i][] } ...
947Determinant and permanent
0go
94zmt
String.prototype.collapse = function() { let str = this; for (let i = 0; i < str.length; i++) { while (str[i] == str[i+1]) str = str.substr(0,i) + str.substr(i+1); } return str; }
948Determine if a string is collapsible
10javascript
psrb7
class Main { static void main(String[] args) { String[] tests = ["", " ", "2", "333", ".55", "tttTTT", "4444 444k"] for (String s: tests) { analyze(s) } } static void analyze(String s) { println("Examining [$s] which has a length of ${s.length()}") if (...
949Determine if a string has all the same characters
7groovy
jev7o
fun main() { val testStrings = arrayOf( "", "\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln ", "..1111111111111111111111111111111111111111111111111111111111111117777888", "I never give 'em hell, I just tell the truth, and they think it's hell. ", " ...
946Determine if a string is squeezable
11kotlin
kxrh3
isOverlapping :: Triangle Double -> Triangle Double -> Bool isOverlapping t1 t2 = vertexInside || midLineInside where vertexInside = any (isInside t1) (vertices t2) || any (isInside t2) (vertices t1) isInside t = (Outside /=) . overlapping t midLineInside = any (\p -> isInside t1 p && ...
950Determine if two triangles overlap
8haskell
94dmo
int main() { remove(); remove(); remove(); remove(); return 0; }
957Delete a file
5c
i6jo2
sPermutations :: [a] -> [([a], Int)] sPermutations = flip zip (cycle [1, -1]) . foldl aux [[]] where aux items x = do (f, item) <- zip (cycle [reverse, id]) items f (insertEv x item) insertEv x [] = [[x]] insertEv x l@(y:ys) = (x: l): ((y:) <$>) (insertEv x ys) elemPos :: [[a]] -> Int -> Int ...
947Determinant and permanent
8haskell
bqrk2
(defn numeric? [s] (if-let [s (seq s)] (let [s (if (= (first s) \-) (next s) s) s (drop-while #(Character/isDigit %) s) s (if (= (first s) \.) (next s) s) s (drop-while #(Character/isDigit %) s)] (empty? s))))
956Determine if a string is numeric
6clojure
sfgqr
fun collapse(s: String): String { val cs = StringBuilder() var last: Char = 0.toChar() for (c in s) { if (c != last) { cs.append(c) last = c } } return cs.toString() } fun main() { val strings = arrayOf( "", "\"If I were two-faced, would I...
948Determine if a string is collapsible
11kotlin
uhmvc
import Numeric (showHex) import Data.List (span) import Data.Char (ord) inconsistentChar :: Eq a => [a] -> Maybe (Int, a) inconsistentChar [] = Nothing inconsistentChar xs@(x:_) = let (pre, post) = span (x ==) xs in if null post then Nothing else Just (length pre, head post) samples :: [String] sa...
949Determine if a string has all the same characters
8haskell
tc0f7
import java.math.BigInteger; class DigitalRoot { public static int[] calcDigitalRoot(String number, int base) { BigInteger bi = new BigInteger(number, base); int additivePersistence = 0; if (bi.signum() < 0) bi = bi.negate(); BigInteger biBase = BigInteger.valueOf(base); while (bi.compare...
945Digital root
9java
kx7hm
function squeezable(s, rune) print("squeeze: `" .. rune .. "`") print("old: <<<" .. s .. ">>>, length = " .. string.len(s)) local last = nil local le = 0 io.write("new: <<<") for c in s:gmatch"." do if c ~= last or c ~= rune then io.write(c) le = le + 1 e...
946Determine if a string is squeezable
1lua
bq7ka
class Delegator { var delegate; String operation() { if (delegate == null) return "default implementation"; else return delegate.thing(); } } class Delegate { String thing() => "delegate implementation"; } main() {
955Delegates
18dart
uhdvs
import java.util.function.BiFunction; public class TriangleOverlap { private static class Pair { double first; double second; Pair(double first, double second) { this.first = first; this.second = second; } @Override public String toString() ...
950Determine if two triangles overlap
9java
tcsf9
(import '(java.io File)) (.delete (File. "output.txt")) (.delete (File. "docs")) (.delete (new File (str (File/separator) "output.txt"))) (.delete (new File (str (File/separator) "docs")))
957Delete a file
6clojure
zl1tj
import java.util.Scanner; public class MatrixArithmetic { public static double[][] minor(double[][] a, int x, int y){ int length = a.length-1; double[][] result = new double[length][length]; for(int i=0;i<length;i++) for(int j=0;j<length;j++){ if(i<x && j<y){ result[i][j] = a[i][j]; }else if(i>=x && j...
947Determinant and permanent
9java
gp24m
function collapse(s) local ns = "" local last = nil for c in s:gmatch"." do if last then if last ~= c then ns = ns .. c end last = c else ns = ns .. c last = c end end return ns end function test(s) ...
948Determine if a string is collapsible
1lua
5k9u6
public class Main{ public static void main(String[] args){ String[] tests = {"", " ", "2", "333", ".55", "tttTTT", "4444 444k"}; for(String s:tests) analyze(s); } public static void analyze(String s){ System.out.printf("Examining [%s] which has a length of%d:\n", s, s.length()); if(s.length() > 1){ ...
949Determine if a string has all the same characters
9java
8za06
null
945Digital root
10javascript
eopao
const determinant = arr => arr.length === 1 ? ( arr[0][0] ) : arr[0].reduce( (sum, v, i) => sum + v * (-1) ** i * determinant( arr.slice(1) .map(x => x.filter((_, j) => i !== j)) ), 0 ); const permanent = arr => arr.length === 1 ? ( arr[0][0] ...
947Determinant and permanent
10javascript
kxghq
const check = s => { const arr = [...s]; const at = arr.findIndex( (v, i) => i === 0 ? false : v !== arr[i - 1] ) const l = arr.length; const ok = at === -1; const p = ok ? "" : at + 1; const v = ok ? "" : arr[at]; const vs = v === "" ? v : `"${v}"` const h = ok ? "" : `0x${v.codePointAt(0).toSt...
949Determine if a string has all the same characters
10javascript
f9sdg
use 5.010; use strict; use warnings; use Time::Piece (); my @seasons = (qw< Chaos Discord Confusion Bureaucracy >, 'The Aftermath'); my @week_days = (qw< Sweetmorn Boomtime Pungenday Prickle-Prickle >, 'Setting Orange'); sub ordinal { my ($n) = @_; return $n . "th" if int($n/10) == 1; return $n . ((qw< th st nd rd...
944Discordian date
2perl
6vz36
use strict; use warnings; use constant True => 1; sub add_edge { my ($g, $a, $b, $weight) = @_; $g->{$a} ||= {name => $a}; $g->{$b} ||= {name => $b}; push @{$g->{$a}{edges}}, {weight => $weight, vertex => $g->{$b}}; } sub push_priority { my ($a, $v) = @_; my $i = 0; my $j = $ while ($i...
942Dijkstra's algorithm
2perl
5b4u2
use strict; use warnings; use Unicode::UCD 'charinfo'; for ( ['', ' '], ['"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ', '-'], ['..1111111111111111111111111111111111111111111111111111111111111117777888', '7'], ["I never give 'em hell, I just tell the truth, and they think it's hell....
946Determine if a string is squeezable
2perl
32dzs
@dx = qw< -0.533 0.270 0.859 -0.043 -0.205 -0.127 -0.071 0.275 1.251 -0.231 -0.401 0.269 0.491 0.951 1.150 0.001 -0.382 0.161 0.915 2.080 -2.337 0.034 -0.126 0.014 0.709 0.129 -1.093 -0.483 -1.193 0.020 -0.051 0.047 -0.095 0.695 0.340 -0.182 0.287 0.213 -0.423 -0.021 -0.134...
954Deming's Funnel
2perl
zlwtb
package main import "fmt" func analyze(s string) { chars := []rune(s) le := len(chars) fmt.Printf("Analyzing%q which has a length of%d:\n", s, le) if le > 1 { for i := 0; i < le-1; i++ { for j := i + 1; j < le; j++ { if chars[j] == chars[i] { fmt...
952Determine if a string has all unique characters
0go
i61og
use threads; use threads::shared; my @names = qw(Aristotle Kant Spinoza Marx Russell); my @forks = ('On Table') x @names; share $forks[$_] for 0 .. $ sub pick_up_forks { my $philosopher = shift; my ($first, $second) = ($philosopher, $philosopher-1); ($first, $second) = ($second, $first) if $philosopher % 2; ...
941Dining philosophers
2perl
cr29a
null
945Digital root
11kotlin
gpu4d
public class DotProduct { public static void main(String[] args) { double[] a = {1, 3, -5}; double[] b = {4, -2, -1}; System.out.println(dotProd(a,b)); } public static double dotProd(double[] a, double[] b){ if(a.length != b.length){ throw new IllegalArgumentException("The dimensions have to be equal!"...
938Dot product
9java
nm3ih
package main import "fmt" type Delegator struct { delegate interface{}
955Delegates
0go
f91d0
null
950Determine if two triangles overlap
11kotlin
o3a8z
null
947Determinant and permanent
11kotlin
27yli
class StringUniqueCharacters { static void main(String[] args) { printf("%-40s %2s %10s %8s %s %s%n", "String", "Length", "All Unique", "1st Diff", "Hex", "Positions") printf("%-40s %2s %10s %8s %s %s%n", "------------------------", "------", "----------", "--------", "---", "---------") for...
952Determine if a string has all unique characters
7groovy
qdjxp
use strict; use warnings; use utf8; binmode STDOUT, ":utf8"; my @lines = split "\n", <<~'STRINGS'; "If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ..1111111111111111111111111111111111111111111111111111111111111117777888 I never give 'em hell, I just tell the truth, and they think i...
948Determine if a string is collapsible
2perl
8ze0w
fun analyze(s: String) { println("Examining [$s] which has a length of ${s.length}:") if (s.length > 1) { val b = s[0] for ((i, c) in s.withIndex()) { if (c != b) { println(" Not all characters in the string are the same.") println(" '$c' (0x${In...
949Determine if a string has all the same characters
11kotlin
wihek
<?php $Anerisia = array(31,28,31,30,31,30,31,31,30,31,30,31); $MONTHS = array(,,,,); $DAYS = array(,,,,); $Dsuff = array('th','st','nd','rd','th','th','th','th','th','th'); $Holy5 = array(,,,,); $Holy50 = array(,,,,); $edate = explode(,date('Y m j L')); $usery = $edate[0]; $userm = $...
944Discordian date
12php
10bpq
<?php function dijkstra($graph_array, $source, $target) { $vertices = array(); $neighbours = array(); foreach ($graph_array as $edge) { array_push($vertices, $edge[0], $edge[1]); $neighbours[$edge[0]][] = array( => $edge[1], => $edge[2]); $neighbours[$edge[1]][] = array( => $edge[0]...
942Dijkstra's algorithm
12php
o6i85
function digital_root(n, base) p = 0 while n > 9.5 do n = sum_digits(n, base) p = p + 1 end return n, p end print(digital_root(627615, 10)) print(digital_root(39390, 10)) print(digital_root(588225, 10)) print(digital_root(393900588225, 10))
945Digital root
1lua
r15ga
import re from itertools import product problem_re = re.compile(r) names, lennames = None, None floors = None constraint_expr = 'len(set(alloc)) == lennames' def do_namelist(txt): global names, lennames names = txt.replace(' and ', ' ').split(', ') lennames = len(names) def do_floorcount(txt): ...
939Dinesman's multiple-dwelling problem
3python
4pj5k
function dot_product(ary1, ary2) { if (ary1.length != ary2.length) throw "can't find dot product: arrays have different lengths"; var dotprod = 0; for (var i = 0; i < ary1.length; i++) dotprod += ary1[i] * ary2[i]; return dotprod; } print(dot_product([1,3,-5],[4,-2,-1]));
938Dot product
10javascript
3vcz0
<?php function squeezeString($string, $squeezeChar) { $previousChar = null; $squeeze = ''; $charArray = preg_split(' for ($i = 0 ; $i < count($charArray) ; $i++) { $currentChar = $charArray[$i]; if ($previousChar !== $currentChar || $currentChar !== $squeezeChar) { $squeeze ...
946Determine if a string is squeezable
12php
psjba
import math dxs = [-0.533, 0.27, 0.859, -0.043, -0.205, -0.127, -0.071, 0.275, 1.251, -0.231, -0.401, 0.269, 0.491, 0.951, 1.15, 0.001, -0.382, 0.161, 0.915, 2.08, -2.337, 0.034, -0.126, 0.014, 0.709, 0.129, -1.093, -0.483, -1.193, 0.02, -0.051, 0.047, -0.095, 0.695, 0.34, -0.182, 0.287, 0.213, ...
954Deming's Funnel
3python
32xzc
interface Thingable { String thing(); } class Delegator { public Thingable delegate; public String operation() { if (delegate == null) return "default implementation"; else return delegate.thing(); } } class Delegate implements Thingable { public String thi...
955Delegates
9java
cg89h
import Data.List (groupBy, intersperse, sort, transpose) import Data.Char (ord, toUpper) import Data.Function(on) import Numeric (showHex) hexFromChar :: Char -> String hexFromChar c = map toUpper $ showHex (ord c) "" string :: String -> String string xs = ('\"': xs) <> "\"" char :: Char -> String char c = ['\'', ...
952Determine if a string has all unique characters
8haskell
vjt2k
<?php function collapseString($string) { $previousChar = null; $collapse = ''; $charArray = preg_split(' for ($i = 0 ; $i < count($charArray) ; $i++) { $currentChar = $charArray[$i]; if ($previousChar !== $currentChar) { $collapse .= $charArray[$i]; } $previo...
948Determine if a string is collapsible
12php
4bc5n
function analyze(s) print(string.format("Examining [%s] which has a length of%d:", s, string.len(s))) if string.len(s) > 1 then local last = string.byte(string.sub(s,1,1)) for i=1,string.len(s) do local c = string.byte(string.sub(s,i,i)) if last ~= c then ...
949Determine if a string has all the same characters
1lua
xnkwz
names = unlist(strsplit("baker cooper fletcher miller smith", " ")) test <- function(floors) { f <- function(name) which(name == floors) if ((f('baker')!= 5) && (f('cooper')!= 1) && (any(f('fletcher') == 2:4)) && (f('miller') > f('cooper')) && (abs(f('fletcher') - f('cooper')) > 1) && ...
939Dinesman's multiple-dwelling problem
13r
2j4lg
from itertools import groupby def squeezer(s, txt): return ''.join(item if item == s else ''.join(grp) for item, grp in groupby(txt)) if __name__ == '__main__': strings = [ , ' --- Abraham Lincoln ', , , , , ...
946Determine if a string is squeezable
3python
6vf3w
int main() { int police,sanitation,fire; printf(); printf(); for(police=2;police<=6;police+=2){ for(sanitation=1;sanitation<=7;sanitation++){ for(fire=1;fire<=7;fire++){ if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ printf(,police,sanitation,fire); } ...
958Department numbers
5c
vj82o
function Delegator() { this.delegate = null ; this.operation = function(){ if(this.delegate && typeof(this.delegate.thing) == 'function') return this.delegate.thing() ; return 'default implementation' ; } } function Delegate() { this.thing = function(){ return 'Delegate Implementation' ; } ...
955Delegates
10javascript
5kfur
function det2D(p1,p2,p3) return p1.x * (p2.y - p3.y) + p2.x * (p3.y - p1.y) + p3.x * (p1.y - p2.y) end function checkTriWinding(p1,p2,p3,allowReversed) local detTri = det2D(p1,p2,p3) if detTri < 0.0 then if allowReversed then local t = p3 p3 = p2 ...
950Determine if two triangles overlap
1lua
i6eot
null
947Determinant and permanent
1lua
vjm2x
import java.util.HashMap; import java.util.Map;
952Determine if a string has all unique characters
9java
yu86g
squeeze_string <- function(string, character){ str_iterable <- strsplit(string, "")[[1]] message(paste0("Original String: ", "<<<", string, ">>>\n", "Length: ", length(str_iterable), "\n", "Character: ", character)) detect <- rep(TRUE, length(str_iterable)) fo...
946Determine if a string is squeezable
13r
f9odc
def funnel(dxs, &rule) x, rxs = 0, [] for dx in dxs rxs << (x + dx) x = rule[x, dx] end rxs end def mean(xs) xs.inject(:+) / xs.size end def stddev(xs) m = mean(xs) Math.sqrt(xs.inject(0.0){|sum,x| sum + (x-m)**2} / xs.size) end def experiment(label, dxs, dys, &rule) rxs, rys = funnel(dxs, &rul...
954Deming's Funnel
14ruby
yus6n
null
955Delegates
11kotlin
32wz5
package main import "fmt" func divCheck(x, y int) (q int, ok bool) { defer func() { recover() }() q = x / y return q, true } func main() { fmt.Println(divCheck(3, 2)) fmt.Println(divCheck(3, 0)) }
953Detect division by zero
0go
qd7xz
def dividesByZero = { double n, double d -> assert ! n.infinite: 'Algorithm fails if the numerator is already infinite.' (n/d).infinite || (n/d).naN }
953Detect division by zero
7groovy
10up6
(() => { 'use strict';
952Determine if a string has all unique characters
10javascript
27flr
from itertools import groupby def collapser(txt): return ''.join(item for item, grp in groupby(txt)) if __name__ == '__main__': strings = [ , ' --- Abraham Lincoln ', , , , , , , , ] for...
948Determine if a string is collapsible
3python
o3w81
from collections import namedtuple, deque from pprint import pprint as pp inf = float('inf') Edge = namedtuple('Edge', ['start', 'end', 'cost']) class Graph(): def __init__(self, edges): self.edges = [Edge(*edge) for edge in edges] self.vertices = {e.start for e in self.edges} | {e.end f...
942Dijkstra's algorithm
3python
4pg5k
fun dot(v1: Array<Double>, v2: Array<Double>) = v1.zip(v2).map { it.first * it.second }.reduce { a, b -> a + b } fun main(args: Array<String>) { dot(arrayOf(1.0, 3.0, -5.0), arrayOf(4.0, -2.0, -1.0)).let { println(it) } }
938Dot product
11kotlin
stnq7
local function Delegator() return { operation = function(self) if (type(self.delegate)=="table") and (type(self.delegate.thing)=="function") then return self.delegate:thing() else return "default implementation" end end } end local function Delegate() return { thing ...
955Delegates
1lua
6vx39
import qualified Control.Exception as C check x y = C.catch (x `div` y `seq` return False) (\_ -> return True)
953Detect division by zero
8haskell
m58yf
collapse_string <- function(string){ str_iterable <- strsplit(string, "")[[1]] message(paste0("Original String: ", "<<<", string, ">>>\n", "Length: ", length(str_iterable))) detect <- rep(TRUE, length(str_iterable)) for(i in 2:length(str_iterable)){ if(length(str_iterable...
948Determine if a string is collapsible
13r
qdpxs
strings = [, ' --- Abraham Lincoln ', , , , ,] squeeze_these = [, , , , , ] strings.zip(squeeze_these).each do |str, st| puts st.chars.each do |c| ssq = str.squeeze(c) puts end puts end
946Determine if a string is squeezable
14ruby
m5zyj
fn squeezable_string<'a>(s: &'a str, squeezable: char) -> impl Iterator<Item = char> + 'a { let mut previous = None; s.chars().filter(move |c| match previous { Some(p) if p == squeezable && p == *c => false, _ => { previous = Some(*c); true } }) } fn main() ...
946Determine if a string is squeezable
15rust
943mm
import Foundation let dxs = [ -0.533, 0.270, 0.859, -0.043, -0.205, -0.127, -0.071, 0.275, 1.251, -0.231, -0.401, 0.269, 0.491, 0.951, 1.150, 0.001, -0.382, 0.161, 0.915, 2.080, -2.337, 0.034, -0.126, 0.014, 0.709, 0.129, -1.093, -0.483, -1.193, 0.020, -0.051, 0.047, -0.095, 0.695, 0.340, -...
954Deming's Funnel
17swift
6vq3j
(let [n (range 1 8)] (for [police n sanitation n fire n :when (distinct? police sanitation fire) :when (even? police) :when (= 12 (+ police sanitation fire))] (println police sanitation fire)))
958Department numbers
6clojure
r1fg2
import java.util.HashMap fun main() { System.out.printf("%-40s %2s %10s %8s %s %s%n", "String", "Length", "All Unique", "1st Diff", "Hex", "Positions") System.out.printf("%-40s %2s %10s %8s %s %s%n", "------------------------", "------", "----------", "--------", "---", "---------") for (s in arrayOf("", "...
952Determine if a string has all unique characters
11kotlin
f9wdo
import threading import random import time class Philosopher(threading.Thread): running = True def __init__(self, xname, forkOnLeft, forkOnRight): threading.Thread.__init__(self) self.name = xname self.forkOnLeft = forkOnLeft self.forkOnRight = forkOnRight def ru...
941Dining philosophers
3python
l7vcv
use strict; use warnings; use PDL; use PDL::NiceSlice; sub permanent{ my $mat = shift; my $n = shift // $mat->dim(0); return undef if $mat->dim(0) != $mat->dim(1); return $mat(0,0) if $n == 1; my $sum = 0; --$n; my $m = $mat(1:,1:)->copy; for(my $i = 0; $i <= $n; ++$i){ $sum += $mat($i,0) * permanent($m, $n)...
947Determinant and permanent
2perl
sfaq3
local find, format = string.find, string.format local function printf(fmt, ...) print(format(fmt,...)) end local pattern = '(.).-%1'
952Determine if a string has all unique characters
1lua
tcxfn
strings = [, ' --- Abraham Lincoln ', , , , , , , ,] strings.each do |str| puts ssq = str.squeeze puts puts end
948Determine if a string is collapsible
14ruby
nyqit
fn collapse_string(val: &str) -> String { let mut output = String::new(); let mut chars = val.chars().peekable(); while let Some(c) = chars.next() { while let Some(&b) = chars.peek() { if b == c { chars.next(); } else { break; } ...
948Determine if a string is collapsible
15rust
dmsny
use strict; use warnings; use feature 'say'; use utf8; binmode(STDOUT, ':utf8'); use List::AllUtils qw(uniq); use Unicode::UCD 'charinfo'; use Unicode::Normalize qw(NFC); for my $str ( '', ' ', '2', '333', '.55', 'tttTTT', '4444 444k', '', '', "\N{LATIN CAPITAL LETTER A}\N{COM...
949Determine if a string has all the same characters
2perl
lrzc5
def solve( problem ) lines = problem.split() names = lines.first.scan( /[A-Z]\w*/ ) re_names = Regexp.union( names ) words = %w(first second third fourth fifth sixth seventh eighth ninth tenth bottom top higher lower adjacent) re_keywords = Regexp.union( words ) predicates = lines[1..-2].flat_map do ...
939Dinesman's multiple-dwelling problem
14ruby
rakgs
package main import "os" func main() { os.Remove("input.txt") os.Remove("/input.txt") os.Remove("docs") os.Remove("/docs")
957Delete a file
0go
gpf4n
public static boolean infinity(double numer, double denom){ return Double.isInfinite(numer/denom); }
953Detect division by zero
9java
f9edv
object CollapsibleString { def collapseString (s : String) : String = { var res = s var isOver = false var i = 0 if(res.size == 0) res else while(!isOver){ if(res(i) == res(i+1)){ res = res.take(i) ++ res.drop(i+1) i-=1 } i+=1 if(i==res.size-1) isOver = ...
948Determine if a string is collapsible
16scala
zlotr
import datetime, calendar DISCORDIAN_SEASONS = [, , , , ] def ddate(year, month, day): today = datetime.date(year, month, day) is_leap_year = calendar.isleap(year) if is_leap_year and month == 2 and day == 29: return + (year + 1166) day_of_year = today.timetuple().tm_yday - 1 if is_leap...
944Discordian date
3python
yu36q
use strict; use warnings; use List::Util qw(sum); my @digit = (0..9, 'a'..'z'); my %digit = map { +$digit[$_], $_ } 0 .. $ sub base { my ($n, $b) = @_; $b ||= 10; die if $b > @digit; my $result = ''; while( $n ) { $result .= $digit[ $n % $b ]; $n = int( $n / $b ); } reverse($result) |...
945Digital root
2perl
ny8iw
import scala.math.abs object Dinesman3 extends App { val tenants = List("Baker", "Cooper2", "Fletcher4", "Miller", "Smith") val (groundFloor, topFloor) = (1, tenants.size) val exclusions = List((suggestedFloor0: Map[String, Int]) => suggestedFloor0("Baker") != topFloor, (suggestedFloor1: Map[String...
939Dinesman's multiple-dwelling problem
16scala
kqahk
use strict; use warnings; sub det2D { my $p1 = shift or die "4 Missing first point\n"; my $p2 = shift or die "Missing second point\n"; my $p3 = shift or die "Missing third point\n"; return $p1->{x} * ($p2->{y} - $p3->{y}) + $p2->{x} * ($p3->{y} - $p1->{y}) + $p3->{x} * ($p1->{y} - $p...
950Determine if two triangles overlap
2perl
gp94e
null
957Delete a file
7groovy
278lv
function divByZero(dividend,divisor) { var quotient=dividend/divisor; if(isNaN(quotient)) return 0;
953Detect division by zero
10javascript
yu06r
class Graph Vertex = Struct.new(:name,:neighbours,:dist,:prev) def initialize(graph) @vertices = Hash.new{|h,k| h[k]=Vertex.new(k,[],Float::INFINITY)} @edges = {} graph.each do |(v1, v2, dist)| @vertices[v1].neighbours << v2 @vertices[v2].neighbours << v1 @edges[[v1, v2]] = @edges[[v2...
942Dijkstra's algorithm
14ruby
ra7gs
function dotprod(a, b) local ret = 0 for i = 1, #a do ret = ret + a[i] * b[i] end return ret end print(dotprod({1, 3, -5}, {4, -2, 1}))
938Dot product
1lua
0zdsd
import System.IO import System.Directory main = do removeFile "output.txt" removeDirectory "docs" removeFile "/output.txt" removeDirectory "/docs"
957Delete a file
8haskell
sf4qk