code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
import math
shades = ('.',':','!','*','o','e','&','
def normalize(v):
len = math.sqrt(v[0]**2 + v[1]**2 + v[2]**2)
return (v[0]/len, v[1]/len, v[2]/len)
def dot(x,y):
d = x[0]*y[0] + x[1]*y[1] + x[2]*y[2]
return -d if d < 0 else 0
def draw_sphere(r, k, ambient, light):
for i in range(int(math.floor(-r)),int(ma... | 925Draw a sphere | 3python | hxtjw |
int main(int argC, char* argV[])
{
int i,zeroCount= 0,firstNonZero = -1;
double* vector;
if(argC == 1){
printf(,argV[0]);
}
else{
printf();
for(i=1;i<argC;i++){
printf(,argV[i]);
}
printf();
vector = (double*)malloc((argC-1)*sizeof(double));
for(i=1;i<=argC;i++){
vector[i-1] = atof(argV[... | 928Display a linear combination | 5c | 3vjza |
int add(int a, int b) {
return a + b;
} | 929Documentation | 5c | ra0g7 |
float mean(float* arr,int size){
int i = 0;
float sum = 0;
while(i != size)
sum += arr[i++];
return sum/size;
}
float variance(float reference,float* arr, int size){
int i=0;
float* newArr = (float*)malloc(size*sizeof(float));
for(;i<size;i++)
newArr[i] = (reference - arr[i])*(reference - arr[i]);
retu... | 930Diversity prediction theorem | 5c | 83c04 |
Shoes.app(:width=>205, :height => 228, :title => ) do
def draw_ray(width, start, stop, ratio)
angle = Math::PI * 2 * ratio - Math::PI/2
strokewidth width
cos = Math::cos(angle)
sin = Math::sin(angle)
line 101+cos*start, 101+sin*start, 101+cos*stop, 101+sin*stop
end
def update
t = Time.now... | 926Draw a clock | 14ruby | kqthg |
int main(int c, char **v)
{
int tids[10];
int parent, spawn;
int i_data, i2;
double f_data;
if (c > 1) {
spawn = pvm_spawn(, 0, PvmTaskDefault, 0, 1, tids);
if (spawn <= 0) {
printf();
return 1;
}
printf();
pvm_recv(-1, 2);
pvm_unpackf(, &i_data, &i2);
printf(, i_data, i2);
pvm_recv(-1... | 931Distributed programming | 5c | styq5 |
(def
#^{:doc "Metadata can contain documentation and can be added to vars like this."}
test1)
(defn test2
"defn and some other macros allow you add documentation like this. Works the same way"
[]) | 929Documentation | 6clojure | bsdkz |
int
main()
{
struct addrinfo hints, *res, *res0;
int error;
char host[NI_MAXHOST];
memset(&hints, 0, sizeof hints);
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
error = getaddrinfo(, NULL, &hints, &res0);
if (error) {
fprintf(stderr, , gai_strerror(error));
exit(1);
}
for (... | 932DNS query | 5c | o6980 |
(defn diversity-theorem [truth predictions]
(let [square (fn[x] (* x x))
mean (/ (reduce + predictions) (count predictions))
avg-sq-diff (fn[a] (/ (reduce + (for [x predictions] (square (- x a)))) (count predictions)))]
{:average-error (avg-sq-diff truth)
:crowd-error (square (- truth mean))
... | 930Diversity prediction theorem | 6clojure | fc5dm |
Shoes.app :width => 500, :height => 500, :resizable => false do
image 400, 470, :top => 30, :left => 50 do
nostroke
fill
image :top => 230, :left => 0 do
oval 70, 130, 260, 40
blur 30
end
oval 10, 10, 380, 380
image :top => 0, :left => 0 do
fill
oval 30, 30, 338, 338
... | 925Draw a sphere | 14ruby | bs3kq |
null | 926Draw a clock | 15rust | bszkx |
null | 925Draw a sphere | 15rust | p06bu |
package main
import (
"fmt"
"strings"
)
type nNode struct {
name string
children []nNode
}
type iNode struct {
level int
name string
}
func toNest(iNodes []iNode, start, level int, n *nNode) {
if level == 0 {
n.name = iNodes[0].name
}
for i := start + 1; i < len(iNod... | 933Display an outline as a nested table | 0go | y5g64 |
import java.util.{ Timer, TimerTask }
import java.time.LocalTime
import scala.math._
object Clock extends App {
private val (width, height) = (80, 35)
def getGrid(localTime: LocalTime): Array[Array[Char]] = {
val (minute, second) = (localTime.getMinute, localTime.getSecond())
val grid = Array.fill[Char](h... | 926Draw a clock | 16scala | aoy1n |
(import java.net.InetAddress java.net.Inet4Address java.net.Inet6Address)
(doseq [addr (InetAddress/getAllByName "www.kame.net")]
(cond
(instance? Inet4Address addr) (println "IPv4:" (.getHostAddress addr))
(instance? Inet6Address addr) (println "IPv6:" (.getHostAddress addr)))) | 932DNS query | 6clojure | tlufv |
object Sphere extends App {
private val (shades, light) = (Seq('.', ':', '!', '*', 'o', 'e', '&', '#', '%', '@'), Array(30d, 30d, -50d))
private def drawSphere(r: Double, k: Double, ambient: Double): Unit = {
def dot(x: Array[Double], y: Array[Double]) = {
val d = x.head * y.head + x(1) * y(1) + x.last *... | 925Draw a sphere | 16scala | ei9ab |
module OutlineTree where
import Data.Bifunctor (first)
import Data.Bool (bool)
import Data.Char (isSpace)
import Data.List (find, intercalate)
import Data.Tree (Tree (..), foldTree, levels)
wikiTablesFromOutline :: [String] -> String -> String
wikiTablesFromOutline colorSwatch outline =
intercalate "\n\n" $
w... | 933Display an outline as a nested table | 8haskell | hxsju |
package main
import "fmt"
func averageSquareDiff(f float64, preds []float64) (av float64) {
for _, pred := range preds {
av += (pred - f) * (pred - f)
}
av /= float64(len(preds))
return
}
func diversityTheorem(truth float64, preds []float64) (float64, float64, float64) {
av := 0.0
for... | 930Diversity prediction theorem | 0go | 5bwul |
package main
import (
"errors"
"log"
"net"
"net/http"
"net/rpc"
)
type TaxComputer float64
func (taxRate TaxComputer) Tax(x float64, r *float64) error {
if x < 0 {
return errors.New("Negative values not allowed")
}
*r = x * float64(taxRate)
return nil
}
func main() {
... | 931Distributed programming | 0go | vh12m |
null | 929Documentation | 0go | nmui1 |
class DiversityPredictionTheorem {
private static double square(double d) {
return d * d
}
private static double averageSquareDiff(double d, double[] predictions) {
return Arrays.stream(predictions)
.map({ it -> square(it - d) })
.average()
.o... | 930Diversity prediction theorem | 7groovy | crb9i |
(() => {
"use strict"; | 933Display an outline as a nested table | 10javascript | jwq7n |
var net = require('net')
var server = net.createServer(function (c){
c.write('hello\r\n')
c.pipe(c) // echo messages back
})
server.listen(3000, 'localhost') | 931Distributed programming | 8haskell | eitai |
var net = require('net')
var server = net.createServer(function (c){
c.write('hello\r\n')
c.pipe(c) | 931Distributed programming | 10javascript | aof10 |
package main
import (
"fmt"
"strings"
)
func linearCombo(c []int) string {
var sb strings.Builder
for i, n := range c {
if n == 0 {
continue
}
var op string
switch {
case n < 0 && sb.Len() == 0:
op = "-"
case n < 0:
op... | 928Display a linear combination | 0go | bsfkh |
square1 :: Int -> Int
square1 x = x * x
square2 :: Int -> Int
square2 x = x * x
square3 :: Int -> Int
square3 x = x * x
square4 :: Int -> Int
square4 x = x * x
data Tree a = Leaf a | Node [Tree a]
class Foo a where
bar :: a | 929Documentation | 8haskell | ukwv2 |
mean :: (Fractional a, Foldable t) => t a -> a
mean lst = sum lst / fromIntegral (length lst)
meanSq :: Fractional c => c -> [c] -> c
meanSq x = mean . map (\y -> (x-y)^^2)
diversityPrediction x estimates = do
putStrLn $ "TrueValue:\t" ++ show x
putStrLn $ "CrowdEstimates:\t" ++ show estimates
let avg = mean... | 930Diversity prediction theorem | 8haskell | xd6w4 |
package main
import (
"fmt"
"net"
)
func main() {
if addrs, err := net.LookupHost("www.kame.net"); err == nil {
fmt.Println(addrs)
} else {
fmt.Println(err)
}
} | 932DNS query | 0go | 4pe52 |
use SVG;
use List::Util qw(max min);
use constant pi => 2 * atan2(1, 0);
my %rules = (
X => 'X+YF+',
Y => '-FX-Y'
);
my $dragon = 'FX';
$dragon =~ s/([XY])/$rules{$1}/eg for 1..10;
($x, $y) = (0, 0);
$theta = 0;
$r = 6;
for (split //, $dragon) {
if (/F/) {
push @X, sprintf "%.0f", $x;
... | 927Dragon curve | 2perl | o6u8x |
class LinearCombination {
private static String linearCombo(int[] c) {
StringBuilder sb = new StringBuilder()
for (int i = 0; i < c.length; ++i) {
if (c[i] == 0) continue
String op
if (c[i] < 0 && sb.length() == 0) {
op = "-"
} else if ... | 928Display a linear combination | 7groovy | ra8gh |
public class Doc{
private String field;
public int method(long num) throws BadException{ | 929Documentation | 9java | m4kym |
import java.util.Arrays;
public class DiversityPredictionTheorem {
private static double square(double d) {
return d * d;
}
private static double averageSquareDiff(double d, double[] predictions) {
return Arrays.stream(predictions)
.map(it -> square(it - d))
.averag... | 930Diversity prediction theorem | 9java | bsnk3 |
class Sphere: UIView{
override func drawRect(rect: CGRect)
{
let context = UIGraphicsGetCurrentContext()
let locations: [CGFloat] = [0.0, 1.0]
let colors = [UIColor.whiteColor().CGColor,
UIColor.blueColor().CGColor]
let colorspace = CGColorSpaceCreateDeviceRGB()
let gradient = CGGradie... | 925Draw a sphere | 17swift | kqzhx |
use strict;
use warnings;
my @rows;
my $row = -1;
my $width = 0;
my $color = 0;
our $bg = 'e0ffe0';
parseoutline( do { local $/; <DATA> =~ s/\t/ /gr } );
print "<table border=1 cellspacing=0>\n";
for ( @rows )
{
my $start = 0;
print " <tr>\n";
for ( @$_ )
{
my ($data, $col, $span, $bg) = @$_;
... | 933Display an outline as a nested table | 2perl | xdtw8 |
def addresses = InetAddress.getAllByName('www.kame.net')
println "IPv4: ${addresses.find { it instanceof Inet4Address }?.hostAddress}"
println "IPv6: ${addresses.find { it instanceof Inet6Address }?.hostAddress}" | 932DNS query | 7groovy | l7kc1 |
module Main where
import Network.Socket
getWebAddresses :: HostName -> IO [SockAddr]
getWebAddresses host = do
results <- getAddrInfo (Just defaultHints) (Just host) (Just "http")
return [ addrAddress a | a <- results, addrSocketType a == Stream ]
showIPs :: HostName -> IO ()
showIPs host = do
putStrLn $ "IP a... | 932DNS query | 8haskell | qf3x9 |
import Text.Printf (printf)
linearForm :: [Int] -> String
linearForm = strip . concat . zipWith term [1..]
where
term :: Int -> Int -> String
term i c = case c of
0 -> mempty
1 -> printf "+e(%d)" i
-1 -> printf "-e(%d)" i
c -> printf "%+d*e(%d)" c i
strip str = case str of
... | 928Display a linear combination | 8haskell | d94n4 |
class Group<T>(val name: String) {
fun add(member: T): Int { ... }
} | 929Documentation | 11kotlin | tlgf0 |
'use strict';
function sum(array) {
return array.reduce(function (a, b) {
return a + b;
});
}
function square(x) {
return x * x;
}
function mean(array) {
return sum(array) / array.length;
}
function averageSquareDiff(a, predictions) {
return mean(predictions.map(function (x) {
re... | 930Diversity prediction theorem | 10javascript | wn3e2 |
null | 929Documentation | 1lua | z2rty |
import itertools
import re
import sys
from collections import deque
from typing import NamedTuple
RE_OUTLINE = re.compile(r, re.M)
COLORS = itertools.cycle(
[
,
,
,
,
,
]
)
class Node:
def __init__(self, indent, value, parent, children=None):
self.indent... | 933Display an outline as a nested table | 3python | qfzxi |
use Data::Dumper;
use IO::Socket::INET;
use Safe;
sub get_data {
my $sock = new IO::Socket::INET
LocalHost => "localhost",
LocalPort => "10000",
Proto => "tcp",
Listen => 1,
Reuse => 1;
unless ($sock) { die "Socket creation failure" }
my $cli = $sock->accept();
my $safe = new Safe;
my $x = $safe->r... | 931Distributed programming | 2perl | iylo3 |
import java.net.InetAddress;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.UnknownHostException;
class DnsQuery {
public static void main(String[] args) {
try {
InetAddress[] ipAddr = InetAddress.getAllByName("www.kame.net");
for(int i=0; i < ipAddr.len... | 932DNS query | 9java | p0ib3 |
const dns = require("dns");
dns.lookup("www.kame.net", {
all: true
}, (err, addresses) => {
if(err) return console.error(err);
console.log(addresses);
}) | 932DNS query | 10javascript | xdzw9 |
import java.util.Arrays;
public class LinearCombination {
private static String linearCombo(int[] c) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < c.length; ++i) {
if (c[i] == 0) continue;
String op;
if (c[i] < 0 && sb.length() == 0) {
... | 928Display a linear combination | 9java | stcq0 |
null | 932DNS query | 11kotlin | 7eqr4 |
null | 930Diversity prediction theorem | 11kotlin | rasgo |
function square(x)
return x * x
end
function mean(a)
local s = 0
local c = 0
for i,v in pairs(a) do
s = s + v
c = c + 1
end
return s / c
end
function averageSquareDiff(a, predictions)
local results = {}
for i,x in pairs(predictions) do
table.insert(results, squa... | 930Diversity prediction theorem | 1lua | 7e0ru |
struct List {
struct MNode *head;
struct MNode *tail;
struct MNode *tail_pred;
};
struct MNode {
struct MNode *succ;
struct MNode *pred;
};
typedef struct MNode *NODE;
typedef struct List *LIST;
LIST newList(void);
int isEmpty(LIST);
NODE getTail(LIST);
NODE getHead(LIST);
NODE addTail(LIST, ... | 934Doubly-linked list/Definition | 5c | tl2f4 |
import SimpleXMLRPCServer
class MyHandlerInstance:
def echo(self, data):
'''Method for returning data got from client'''
return 'Server responded:%s'% data
def div(self, num1, num2):
'''Method for divide 2 numbers'''
return num1/num2
def foo_function():
'''A function (not ... | 931Distributed programming | 3python | nm2iz |
local socket = require('socket')
local ip_tbl = socket.dns.getaddrinfo('www.kame.net')
for _, v in ipairs(ip_tbl) do
io.write(string.format('%s:%s\n', v.family, v.addr))
end | 932DNS query | 1lua | jws71 |
null | 928Display a linear combination | 11kotlin | ao313 |
procedure StoreVar(integer N, integer NTyp)
--
-- Store a variable, applying any final operator as needed.
-- If N is zero, PopFactor (ie store in a new temporary variable of
-- the specified type). Otherwise N should be an index to symtab.
-- If storeConst is 1, NTyp is ignored/overridden, otherwise it
-- should usu... | 929Documentation | 2perl | kqnhc |
: (doc 'car)
: (doc '+Entity)
: (doc '+ 'firefox) | 929Documentation | 12php | 3v7zq |
sub diversity {
my($truth, @pred) = @_;
my($ae,$ce,$cp,$pd,$stats);
$cp += $_/@pred for @pred;
$ae = avg_error($truth, @pred);
$ce = ($cp - $truth)**2;
$pd = avg_error($cp, @pred);
my $fmt = "%13s:%6.3f\n";
$stats = sprintf $fmt, 'average-error', $ae;
$stats .= ... | 930Diversity prediction theorem | 2perl | d9unw |
require 'drb/drb'
URI=
class TimeServer
def get_current_time
return Time.now
end
end
FRONT_OBJECT = TimeServer.new
$SAFE = 1
DRb.start_service(URI, FRONT_OBJECT)
DRb.thread.join | 931Distributed programming | 14ruby | fcudr |
function t2s(t)
local s = "["
for i,v in pairs(t) do
if i > 1 then
s = s .. ", " .. v
else
s = s .. v
end
end
return s .. "]"
end
function linearCombo(c)
local sb = ""
for i,n in pairs(c) do
local skip = false
if n < 0 then
... | 928Display a linear combination | 1lua | ei6ac |
(ns double-list)
(defprotocol PDoubleList
(get-head [this])
(add-head [this x])
(get-tail [this])
(add-tail [this x])
(remove-node [this node])
(add-before [this node x])
(add-after [this node x])
(get-nth [this n]))
(defrecord Node [prev next data])
(defn make-node
"Create an internal or finalized... | 934Doubly-linked list/Definition | 6clojure | m4gyq |
use feature 'say';
use Socket qw(getaddrinfo getnameinfo);
my ($err, @res) = getaddrinfo('orange.kame.net', 0, { protocol=>Socket::IPPROTO_TCP } );
die "getaddrinfo error: $err" if $err;
say ((getnameinfo($_->{addr}, Socket::NI_NUMERICHOST))[1]) for @res | 932DNS query | 2perl | fcvd7 |
class Doc(object):
def method(self, num):
pass | 929Documentation | 3python | bsdkr |
example(package.skeleton) | 929Documentation | 13r | 7e8ry |
package main
import (
"fmt"
"strconv"
)
const DMAX = 20 | 935Disarium numbers | 0go | qffxz |
use strict;
use warnings;
use feature 'say';
sub linear_combination {
my(@coef) = @$_;
my $e = '';
for my $c (1..+@coef) { $e .= "$coef[$c-1]*e($c) + " if $coef[$c-1] }
$e =~ s/ \+ $//;
$e =~ s/1\*//g;
$e =~ s/\+ -/- /g;
$e or 0;
}
say linear_combination($_) for
[1, 2, 3], [0, 1, 2, 3], ... | 928Display a linear combination | 2perl | 9gpmn |
'''Diversity prediction theorem'''
from itertools import chain
from functools import reduce
def diversityValues(x):
'''The mean error, crowd error and
diversity, for a given observation x
and a non-empty list of predictions ps.
'''
def go(ps):
mp = mean(ps)
return {
... | 930Diversity prediction theorem | 3python | fc5de |
module Disarium
where
import Data.Char ( digitToInt)
isDisarium :: Int -> Bool
isDisarium n = (sum $ map (\(c , i ) -> (digitToInt c ) ^ i )
$ zip ( show n ) [1 , 2 ..]) == n
solution :: [Int]
solution = take 18 $ filter isDisarium [0, 1 ..] | 935Disarium numbers | 8haskell | m44yf |
<?php
$ipv4_record = dns_get_record(,DNS_A);
$ipv6_record = dns_get_record(,DNS_AAAA);
print . $ipv4_record[0][] . ;
print . $ipv6_record[0][] . ;
?> | 932DNS query | 12php | hx0jf |
from turtle import *
def dragon(step, length):
dcr(step, length)
def dcr(step, length):
step -= 1
length /= 1.41421
if step > 0:
right(45)
dcr(step, length)
left(90)
dcl(step, length)
right(45)
else:
right(45)
forward(length)
left(90)... | 927Dragon curve | 3python | iy5of |
diversityStats <- function(trueValue, estimates)
{
collectivePrediction <- mean(estimates)
data.frame("True Value" = trueValue,
as.list(setNames(estimates, paste("Guess", seq_along(estimates)))),
"Average Error" = mean((trueValue - estimates)^2),
"Crowd Error" = (trueValue - ... | 930Diversity prediction theorem | 13r | o6l84 |
use strict;
use warnings;
my ($n,@D) = (0, 0);
while (++$n) {
my($m,$sum);
map { $sum += $_ ** ++$m } split '', $n;
push @D, $n if $n == $sum;
last if 19 == @D;
}
print "@D\n"; | 935Disarium numbers | 2perl | 4pp5d |
>>> import socket
>>> ips = set(i[4][0] for i in socket.getaddrinfo('www.kame.net', 80))
>>> for ip in ips: print ip
...
2001:200:dff:fff1:216:3eff:feb1:44d7
203.178.141.194 | 932DNS query | 3python | tlufw |
using namespace Rcpp ;
// [[Rcpp::export]]
CharacterVector getNameInfo(std::string fqdn) {
struct addrinfo hints, *res, *res0;
int error;
char host[NI_MAXHOST];
memset(&hints, 0, sizeof hints);
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
error = getaddrinfo(fqdn.c_str(), NULL, &hints, &res... | 932DNS query | 13r | iyco5 |
=begin rdoc
RDoc is documented here[http:
This is a class documentation comment. This text shows at the top of the page
for the class.
Comments can be written inside / blocks or
in normal '
There are no '@parameters' like javadoc, but 'name-value' lists can be written:
Author:: Joe Schmoe
Date:: today
=end
class ... | 929Documentation | 14ruby | 18tpw |
null | 929Documentation | 15rust | aoz14 |
class Doc {
private val field = 0
def method(num: Long): Int = { | 929Documentation | 16scala | xdywg |
Dragon<-function(Iters){
Rotation<-matrix(c(0,-1,1,0),ncol=2,byrow=T)
Iteration<-list()
Iteration[[1]] <- matrix(rep(0,16), ncol = 4)
Iteration[[1]][1,]<-c(0,0,1,0)
Iteration[[1]][2,]<-c(1,0,1,-1)
Moveposition<-rep(0,Iters)
Moveposition[1]<-4
if(Iters > 1){
for(l in 2:Iters){
Moveposition[l... | 927Dragon curve | 13r | stlqy |
def linear(x):
return ' + '.join(['{}e({})'.format('-' if v == -1 else '' if v == 1 else str(v) + '*', i + 1)
for i, v in enumerate(x) if v] or ['0']).replace(' + -', ' - ')
list(map(lambda x: print(linear(x)), [[1, 2, 3], [0, 1, 2, 3], [1, 0, 3, 4], [1, 2, 0],
[0, 0, 0], [0], [1, 1, 1], [-1, -1, -... | 928Display a linear combination | 3python | cr19q |
def mean(a) = a.sum(0.0) / a.size
def mean_square_diff(a, predictions) = mean(predictions.map { |x| square(x - a)**2 })
def diversity_theorem(truth, predictions)
average = mean(predictions)
puts ,
,
,
,
end
diversity_theorem(49.0, [48.0, 47.0, 51.0])
diversity_theorem(49.0, [48.0, 4... | 930Diversity prediction theorem | 14ruby | z2gtw |
def isDisarium(n):
digitos = len(str(n))
suma = 0
x = n
while x != 0:
suma += (x% 10) ** digitos
digitos -= 1
x
if suma == n:
return True
else:
return False
if __name__ == '__main__':
limite = 19
cont = 0
n = 0
print(,limite,)
while c... | 935Disarium numbers | 3python | g114h |
irb(main):001:0> require 'socket'
=> true
irb(main):002:0> Addrinfo.getaddrinfo(, nil, nil, :DGRAM) \
irb(main):003:0* .map! { |ai| ai.ip_address }
=> [, ] | 932DNS query | 14ruby | 3v4z7 |
func add(a: Int, b: Int) -> Int {
return a + b
} | 929Documentation | 17swift | p0fbl |
object DiversityPredictionTheorem {
def square(d: Double): Double
= d * d
def average(a: Array[Double]): Double
= a.sum / a.length
def averageSquareDiff(d: Double, predictions: Array[Double]): Double
= average(predictions.map(it => square(it - d)))
def diversityTheorem(truth: Double, predictions: Array... | 930Diversity prediction theorem | 16scala | m4hyc |
use std::net::ToSocketAddrs;
fn main() {
let host = "www.kame.net"; | 932DNS query | 15rust | 6ug3l |
import java.net._
InetAddress.getAllByName("www.kame.net").foreach(x => println(x.getHostAddress)) | 932DNS query | 16scala | 9gjm5 |
function sum(array: Array<number>): number {
return array.reduce((a, b) => a + b)
}
function square(x: number):number {
return x * x
}
function mean(array: Array<number>): number {
return sum(array) / array.length
}
function averageSquareDiff(a: number, predictions: Array<number>): number {
return me... | 930Diversity prediction theorem | 20typescript | g1q4g |
def linearCombo(c)
sb =
c.each_with_index { |n, i|
if n == 0 then
next
end
if n < 0 then
if sb.length == 0 then
op =
else
op =
end
elsif n > 0 then
if sb.length > 0 then
... | 928Display a linear combination | 14ruby | 2jelw |
type dlNode struct {
int
next, prev *dlNode
} | 934Doubly-linked list/Definition | 0go | hxqjq |
use std::fmt::{Display, Formatter, Result};
use std::process::exit;
struct Coefficient(usize, f64);
impl Display for Coefficient {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let i = self.0;
let c = self.1;
if c == 0. {
return Ok(());
}
write!(
... | 928Display a linear combination | 15rust | vhw2t |
object LinearCombination extends App {
val combos = Seq(Seq(1, 2, 3), Seq(0, 1, 2, 3),
Seq(1, 0, 3, 4), Seq(1, 2, 0), Seq(0, 0, 0), Seq(0),
Seq(1, 1, 1), Seq(-1, -1, -1), Seq(-1, -2, 0, -3), Seq(-1))
private def linearCombo(c: Seq[Int]): String = {
val sb = new StringBuilder
for {i <- c.indic... | 928Display a linear combination | 16scala | 4ps50 |
import qualified Data.Map as M
type NodeID = Maybe Rational
data Node a = Node
{vNode :: a,
pNode, nNode :: NodeID}
type DLList a = M.Map Rational (Node a)
empty = M.empty
singleton a = M.singleton 0 $ Node a Nothing Nothing
fcons :: a -> DLList a -> DLList a
fcons a list | M.null list = singleton a
... | 934Doubly-linked list/Definition | 8haskell | iymor |
Point = Struct.new(:x, :y)
Line = Struct.new(:start, :stop)
Shoes.app(:width => 800, :height => 600, :resizable => false) do
def split_segments(n)
dir = 1
@segments = @segments.inject([]) do |new, l|
a, b, c, d = l.start.x, l.start.y, l.stop.x, l.stop.y
mid_x = a + (c-a)/2.0 - (d-b)/2.0*dir
... | 927Dragon curve | 14ruby | d9gns |
use ggez::{
conf::{WindowMode, WindowSetup},
error::GameResult,
event,
graphics::{clear, draw, present, Color, MeshBuilder},
nalgebra::Point2,
Context,
};
use std::time::Duration; | 927Dragon curve | 15rust | fcrd6 |
import java.util.LinkedList;
public class DoublyLinkedList {
public static void main(String[] args) {
LinkedList<String> list = new LinkedList<String>();
list.addFirst("Add First");
list.addLast("Add Last 1");
list.addLast("Add Last 2");
list.addLast("Add Last 1");
... | 934Doubly-linked list/Definition | 9java | xdfwy |
import javax.swing.JFrame
import java.awt.Graphics
class DragonCurve(depth: Int) extends JFrame(s"Dragon Curve (depth $depth)") {
setBounds(100, 100, 800, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
val len = 400 / Math.pow(2, depth / 2.0);
val startingAngle = -depth * (Math.PI / 4);
val steps = ... | 927Dragon curve | 16scala | 3vhzy |
show(DLNode) | 934Doubly-linked list/Definition | 10javascript | o6y86 |
do { *rmp = 0; _mdr(rmdr, rmp, n); } while (0)
void _mdr(int *rmdr, int *rmp, long long n)
{
int r = n ? 1 : 0;
while (n) {
r *= (n % 10);
n /= 10;
}
(*rmp)++;
if (r >= 10)
_mdr(rmdr, rmp, r);
else
*rmdr = r;
}
int main(void)
{
int i, j, vmdr, vmp;
... | 936Digital root/Multiplicative digital root | 5c | p0sby |
null | 934Doubly-linked list/Definition | 11kotlin | p08b6 |
package main
import (
"fmt"
"strings"
)
func sentenceType(s string) string {
if len(s) == 0 {
return ""
}
var types []string
for _, c := range s {
if c == '?' {
types = append(types, "Q")
} else if c == '!' {
types = append(types, "E")
} ... | 937Determine sentence type | 0go | cr49g |
null | 934Doubly-linked list/Definition | 1lua | 18opo |
text = "hi there, how are you today? I'd like to present to you the washing machine 9001. You have been nominated to win one of these! Just make sure you don't break it"
p2t = { [""]="N", ["."]="S", ["!"]="E", ["?"]="Q" }
for s, p in text:gmatch("%s*([^%!%?%.]+)([%!%?%.]?)") do
print(s..p..": "..p2t[p])
end | 937Determine sentence type | 1lua | ukjvl |
use strict;
use warnings;
use feature 'say';
use Lingua::Sentence;
my $para1 = <<'EOP';
hi there, how are you today? I'd like to present to you the washing machine
9001. You have been nominated to win one of these! Just make sure you don't
break it
EOP
my $para2 = <<'EOP';
Just because there are punctuation character... | 937Determine sentence type | 2perl | 0zfs4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.