code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
from __future__ import print_function class Node(object): def __init__(self): self.edges = {} self.link = None self.len = 0 class Eertree(object): def __init__(self): self.nodes = [] self.rto = Node() self.rte = Node() self.rto.link = self.rte.link = self.rto; self.rto.len = -1 self.rt...
909Eertree
3python
d9in1
package main import ( "fmt" "net" "bufio" ) func echo(s net.Conn, i int) { defer s.Close(); fmt.Printf("%d:%v <->%v\n", i, s.LocalAddr(), s.RemoteAddr()) b := bufio.NewReader(s) for { line, e := b.ReadBytes('\n') if e != nil { break } s.Write(line) } fmt.Printf("%d: closed\n", i) } func main() {...
907Echo server
0go
dcfne
null
911Earliest difference between prime gaps
15rust
iysod
module Main where import Network (withSocketsDo, accept, listenOn, sClose, PortID(PortNumber)) import Control.Monad (forever) import System.IO (hGetLine, hPutStrLn, hFlush, hClose) import System.IO.Error (isEOFError) import Control.Concurrent (forkIO) import Control.Exception (bracket) withListenOn port body = bracke...
907Echo server
8haskell
5p4ug
null
905Empty program
17swift
2h5lj
package main import ( "fmt" "math/big" "math/rand" "strings" ) func main() { const cells = 20 const generations = 9 fmt.Println("Single 1, rule 90:") a := big.NewInt(1) a.Lsh(a, cells/2) elem(90, cells, generations, a) fmt.Println("Random intial state, rule 30:") a = bi...
910Elementary cellular automaton
0go
7e4r2
package main import ( "fmt" "math" "rcu" ) func isSquare(n int) bool { s := int(math.Sqrt(float64(n))) return s*s == n } func main() { limit := 200000
915Duffinian numbers
0go
0zpsk
class Node def initialize(length, edges = {}, suffix = 0) @length = length @edges = edges @suffix = suffix end attr_reader :length attr_reader :edges attr_accessor :suffix end EVEN_ROOT = 0 ODD_ROOT = 1 def eertree(s) tree = [ Node.new(0, {}, ODD_ROOT), ...
909Eertree
14ruby
tldf2
import Data.Array (listArray, (!), bounds, elems) step rule a = listArray (l,r) res where (l,r) = bounds a res = [rule (a!r) (a!l) (a!(l+1)) ] ++ [rule (a!(i-1)) (a!i) (a!(i+1)) | i <- [l+1..r-1] ] ++ [rule (a!(r-1)) (a!r) (a!l) ] runCA rule = iterate (step rule)
910Elementary cellular automaton
8haskell
83q0z
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; public class EchoServer { pub...
907Echo server
9java
9rcmu
struct Interval { int start, end; bool print; }; int main() { struct Interval intervals[] = { {2, 1000, true}, {1000, 4000, true}, {2, 10000, false}, {2, 100000, false}, {2, 1000000, false}, {2, 10000000, false}, {2, 100000000, false}, {2, 100...
916Eban numbers
5c
g1m45
use strict; use warnings; use feature <say state>; use List::Util 'max'; use ntheory qw<divisor_sum is_prime gcd>; sub table { my $t = shift() * (my $c = 1 + max map {length} @_); ( sprintf( ('%'.$c.'s')x@_, @_) ) =~ s/.{1,$t}\K/\n/gr } sub duffinian { my($n) = @_; state $c = 1; state @D; do { push @D, $c...
915Duffinian numbers
2perl
racgd
(eval `(def ~(symbol (read)) 42))
917Dynamic variable names
6clojure
g1y4f
import java.awt.*; import java.awt.event.ActionEvent; import javax.swing.*; import javax.swing.Timer; public class WolframCA extends JPanel { final int[] ruleSet = {30, 45, 50, 57, 62, 70, 73, 75, 86, 89, 90, 99, 101, 105, 109, 110, 124, 129, 133, 135, 137, 139, 141, 164,170, 232}; byte[][] cells; ...
910Elementary cellular automaton
9java
eipa5
const net = require('net'); function handleClient(conn) { console.log('Connection from ' + conn.remoteAddress + ' on port ' + conn.remotePort); conn.setEncoding('utf-8'); let buffer = ''; function handleData(data) { for (let i = 0; i < data.length; i++) { const char = data.charAt...
907Echo server
10javascript
ub5vb
const alive = '#'; const dead = '.';
910Elementary cellular automaton
10javascript
0zxsz
import java.net.ServerSocket import java.net.Socket fun main() { fun handleClient(conn: Socket) { conn.use { val input = conn.inputStream.bufferedReader() val output = conn.outputStream.bufferedWriter() input.forEachLine { line -> output.write(line) ...
907Echo server
11kotlin
zv3ts
package element import ( "fmt" "math" ) type Matrix struct { ele []float64 stride int } func MatrixFromRows(rows [][]float64) Matrix { if len(rows) == 0 { return Matrix{nil, 0} } m := Matrix{make([]float64, len(rows)*len(rows[0])), len(rows[0])} for rx, row := range rows { ...
912Element-wise operations
0go
l76cw
package main import ( "fmt" "math/big" "strings" ) var zero = new(big.Int) var one = big.NewInt(1) func toEgyptianRecursive(br *big.Rat, fracs []*big.Rat) []*big.Rat { if br.Num().Cmp(zero) == 0 { return fracs } iquo := new(big.Int) irem := new(big.Int) iquo.QuoRem(br.Denom(),...
913Egyptian fractions
0go
187p5
def halve(x) x/2 end def double(x) x*2 end def ethiopian_multiply(a, b) product = 0 while a >= 1 p [a, b, a.even?? : ] if $DEBUG product += b unless a.even? a = halve(a) b = double(b) end product end def rec_ethiopian_multiply(a, b) return 0 if a < 1 p [a, b, a.even?? : ] if $DEBUG...
901Ethiopian multiplication
14ruby
im6oh
null
910Elementary cellular automaton
11kotlin
kq7h3
class NaiveMatrix { List<List<Number>> contents = [] NaiveMatrix(Iterable<Iterable<Number>> elements) { contents.addAll(elements.collect{ row -> row.collect{ cell -> cell } }) assertWellFormed() } void assertWellFormed() { assert contents != null assert contents.size()...
912Element-wise operations
7groovy
6ud3o
import Data.Ratio (Ratio, (%), denominator, numerator) egyptianFraction :: Integral a => Ratio a -> [Ratio a] egyptianFraction n | n < 0 = map negate (egyptianFraction (-n)) | n == 0 = [] | x == 1 = [n] | x > y = (x `div` y % 1): egyptianFraction (x `mod` y % y) | otherwise = (1 % r): egyptianFraction ((-y) ...
913Egyptian fractions
8haskell
tl8f7
fn double(a: i32) -> i32 { 2*a } fn halve(a: i32) -> i32 { a/2 } fn is_even(a: i32) -> bool { a% 2 == 0 } fn ethiopian_multiplication(mut x: i32, mut y: i32) -> i32 { let mut sum = 0; while x >= 1 { print!("{} \t {}", x, y); match is_even(x) { true => println!("\t No...
901Ethiopian multiplication
15rust
n9yi4
local CA = { state = "..............................#..............................", bstr = { [0]="...", "..#", ".#.", ".##", "#..", "#.#", "##.", "###" }, new = function(self, rule) local inst = setmetatable({rule=rule}, self) for b = 0,7 do inst[inst.bstr[b]] = rule%2==0 and "." or "#" rule...
910Elementary cellular automaton
1lua
bsjka
local socket = require("socket") local function has_value(tab, value) for i, v in ipairs(tab) do if v == value then return i end end return false end local function checkOn(client) local line, err = client:receive() if line then client:send(line .. "\n") end if err and err ~= "timeout" the...
907Echo server
1lua
3u6zo
import Data.Array (Array, Ix) import Data.Array.Base zipWithA :: (IArray arr a, IArray arr b, IArray arr c, Ix i) => (a -> b -> c) -> arr i a -> arr i b -> arr i c zipWithA f a b = case bounds a of ba -> if ba /= bounds b then error "elemwise: bounds mismatch" else let n =...
912Element-wise operations
8haskell
18jps
package main import "fmt" func egyptianDivide(dividend, divisor int) (quotient, remainder int) { if dividend < 0 || divisor <= 0 { panic("Invalid argument(s)") } if dividend < divisor { return 0, dividend } powersOfTwo := []int{1} doublings := []int{divisor} doubling := div...
914Egyptian division
0go
stpqa
package main import "fmt" type Range struct { start, end uint64 print bool } func main() { rgs := []Range{ {2, 1000, true}, {1000, 4000, true}, {2, 1e4, false}, {2, 1e5, false}, {2, 1e6, false}, {2, 1e7, false}, {2, 1e8, false}, {2, 1e9...
916Eban numbers
0go
iyaog
package main import ( "bufio" "fmt" "log" "os" "strconv" "strings" ) func check(err error) { if err != nil { log.Fatal(err) } } func main() { scanner := bufio.NewScanner(os.Stdin) n := 0 for n < 1 || n > 5 { fmt.Print("How many integer variables do you want...
917Dynamic variable names
0go
qfjxz
int main() { initwindow(320,240,); putpixel(100,100,RED); getch(); return 0; }
918Draw a pixel
5c
nm1i6
class EgyptianDivision { static void main(String[] args) { divide(580, 34) } static void divide(int dividend, int divisor) { List<Integer> powersOf2 = new ArrayList<>() List<Integer> doublings = new ArrayList<>()
914Egyptian division
7groovy
ao71p
import java.math.BigDecimal; import java.math.BigInteger; import java.math.MathContext; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class EgyptianFractions { private static BigInteger gcd(BigInteger a, BigInteger b) { if (b.equals(BigInteger.ZERO)) { ...
913Egyptian fractions
9java
83e06
def ethiopian(i:Int, j:Int):Int= pairIterator(i,j).filter(x=> !isEven(x._1)).map(x=>x._2).foldLeft(0){(x,y)=>x+y} def ethiopian2(i:Int, j:Int):Int= pairIterator(i,j).map(x=>if(isEven(x._1)) 0 else x._2).foldLeft(0){(x,y)=>x+y} def ethiopian3(i:Int, j:Int):Int= { var res=0; for((h,d) <- pairIterator(i,j) i...
901Ethiopian multiplication
16scala
t2cfb
class Main { private static class Range { int start int end boolean print Range(int s, int e, boolean p) { start = s end = e print = p } } static void main(String[] args) { List<Range> rgs = Arrays.asList( ...
916Eban numbers
7groovy
qfhxp
def varname = 'foo' def value = 42 new GroovyShell(this.binding).evaluate("${varname} = ${value}") assert foo == 42
917Dynamic variable names
7groovy
185p6
data Var a = Var String a deriving Show main = do putStrLn "please enter you variable name" vName <- getLine let var = Var vName 42 putStrLn $ "this is your variable: " ++ show var
917Dynamic variable names
8haskell
m4oyf
import Data.List (unfoldr) egyptianQuotRem :: Integer -> Integer -> (Integer, Integer) egyptianQuotRem m n = let expansion (i, x) | x > m = Nothing | otherwise = Just ((i, x), (i + i, x + x)) collapse (i, x) (q, r) | x < r = (q + i, r - x) | otherwise = (q, r) in foldr collaps...
914Egyptian division
8haskell
9gfmo
use strict; use warnings; package Automaton { sub new { my $class = shift; my $rule = [ reverse split //, sprintf "%08b", shift ]; return bless { rule => $rule, cells => [ @_ ] }, $class; } sub next { my $this = shift; my @previous = @{$this->{cells}}; $this->{cells} = [ @{$this->{rule}}[ m...
910Elementary cellular automaton
2perl
3vfzs
import Data.List (intercalate) import Text.Printf (printf) import Data.List.Split (chunksOf) isEban :: Int -> Bool isEban n = all (`elem` [0, 2, 4, 6]) z where (b, r1) = n `quotRem` (10 ^ 9) (m, r2) = r1 `quotRem` (10 ^ 6) (t, r3) = r2 `quotRem` (10 ^ 3) z = b: map (\x -> if x >= 30 && x <= 66 then x `...
916Eban numbers
8haskell
vhz2k
double rot = 0; float matCol[] = {1,0,0,0}; void display(){ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(30,1,1,0); glRotatef(rot,0,1,1); glMaterialfv(GL_FRONT,GL_DIFFUSE,matCol); glutWireCube(1); glPopMatrix(); glFlush(); } void onIdle(){ rot += 0.1; glutPostRedisplay(); } ...
919Draw a rotating cube
5c
jwm70
import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.function.BiFunction; import java.util.stream.Stream; @SuppressWarnings("serial") public class ElementWiseOp { static final Map<String, BiFunction<Double, Double, Double>> OPERATIONS = new HashMap<String, BiFunction<Double, Doubl...
912Element-wise operations
9java
7eurj
public static void main(String... args){ HashMap<String, Integer> vars = new HashMap<String, Integer>();
917Dynamic variable names
9java
fcwdv
import java.util.ArrayList; import java.util.List; public class EgyptianDivision { public static void main(String[] args) { divide(580, 34); } public static void divide(int dividend, int divisor) { List<Integer> powersOf2 = new ArrayList<>(); List<Integer> doublings =...
914Egyptian division
9java
tl0f9
null
913Egyptian fractions
11kotlin
wnkek
var varname = 'foo';
917Dynamic variable names
10javascript
y586r
(() => { 'use strict';
914Egyptian division
10javascript
m4dyv
import java.util.List; public class Main { private static class Range { int start; int end; boolean print; public Range(int s, int e, boolean p) { start = s; end = e; print = p; } } public static void main(String[] args) { ...
916Eban numbers
9java
y5o6g
null
917Dynamic variable names
11kotlin
83b0q
null
914Egyptian division
11kotlin
o6e8z
def eca(cells, rule): lencells = len(cells) c = + cells + rulebits = '{0:08b}'.format(rule) neighbours2next = {'{0:03b}'.format(n):rulebits[::-1][n] for n in range(8)} yield c[1:-1] while True: c = ''.join(['0', ''.join(neighbours2next[c[i-1:i+2]] ...
910Elementary cellular automaton
3python
6ut3w
use IO::Socket; my $use_fork = 1; my $sock = new IO::Socket::INET ( LocalHost => '127.0.0.1', LocalPort => '12321', Proto => 'tcp', Listen => 1, Reuse ...
907Echo server
2perl
b0pk4
null
912Element-wise operations
11kotlin
uk9vc
package main import ( "fmt" "image" "image/color" "image/draw" ) func main() { rect := image.Rect(0, 0, 320, 240) img := image.NewRGBA(rect)
918Draw a pixel
0go
raygm
function egyptian_divmod(dividend,divisor) local pwrs, dbls = {1}, {divisor} while dbls[#dbls] <= dividend do table.insert(pwrs, pwrs[#pwrs] * 2) table.insert(dbls, pwrs[#pwrs] * divisor) end local ans, accum = 0, 0 for i=#pwrs-1,1,-1 do if accum + dbls[i] <= dividend then ...
914Egyptian division
1lua
iywot
null
916Eban numbers
11kotlin
fcxdo
_G[io.read()] = 5
917Dynamic variable names
1lua
o6p8h
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); socket_bind($socket, '127.0.0.1', 12321); socket_listen($socket); $client_count = 0; while (true){ if (($client = socket_accept($socket)) === false) continue; $client_count++; $client_name = 'Unknown'; socket_getpeername($client, $client_name); echo ; ...
907Echo server
12php
65y3g
function makeInterval(s,e,p) return {start=s, end_=e, print_=p} end function main() local intervals = { makeInterval( 2, 1000, true), makeInterval(1000, 4000, true), makeInterval( 2, 10000, false), makeInterval( 2, 1000000, false), makeInterval(...
916Eban numbers
1lua
tlqfn
void insert(link* anchor, link* newlink) { newlink->next = anchor->next; newlink->prev = anchor; (newlink->next)->prev = newlink; anchor->next = newlink; }
920Doubly-linked list/Element insertion
5c
aov11
import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; public class DrawAPixel extends JFrame{ public DrawAPixel() { super("Red Pixel"); setSize(320, 240); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } @Override public void paint(Graphics g) { g.setColor(new Col...
918Draw a pixel
9java
ao51y
sub egyptian_divmod { my($dividend, $divisor) = @_; die "Invalid divisor" if $divisor <= 0; my @table = ($divisor); push @table, 2*$table[-1] while $table[-1] <= $dividend; my $accumulator = 0; for my $k (reverse 0 .. $ next unless $dividend >= $table[$k]; $accumulator += 1 << ...
914Egyptian division
2perl
g1c4e
use strict; use warnings; use bigint; sub isEgyption{ my $nr = int($_[0]); my $de = int($_[1]); if($nr == 0 or $de == 0){ return; } if($de % $nr == 0){ printf "1/" . int($de/$nr); return; } if($nr % $de == 0){ printf $nr/$de; return; } if($nr > $de){ printf int($nr...
913Egyptian fractions
2perl
l73c5
class ElemCellAutomat include Enumerable def initialize (start_str, rule, disp=false) @cur = start_str @patterns = Hash[8.times.map{|i|[%i, [rule[i]]]}] puts if disp end def each return to_enum unless block_given? loop do yield @cur str = @cur[-1] + @cur + @cur[0] @cur =...
910Elementary cellular automaton
14ruby
m43yj
use strict; use warnings; use feature 'say'; use Lingua::EN::Numbers qw(num2en); sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r } sub e_ban { my($power) = @_; my @n; for (1..10**$power) { next unless 0 == $_%2; next if $_ =~ /[789]/ or /[12].$/ or /[135]..$/ or /[135]....
916Eban numbers
2perl
hx2jl
package main import ( "image" "image/color" "image/gif" "log" "math" "os" ) const ( width, height = 640, 640 offset = height / 2 fileName = "rotatingCube.gif" ) var nodes = [][]float64{{-100, -100, -100}, {-100, -100, 100}, {-100, 100, -100}, {-100, 100, 100}, {100, -100, -100}, {100, -100, 100...
919Draw a rotating cube
0go
fcad0
(defrecord Node [prev next data]) (defn new-node [prev next data] (Node. (ref prev) (ref next) data)) (defn new-list [head tail] (List. (ref head) (ref tail))) (defn insert-between [node1 node2 new-node] (dosync (ref-set (:next node1) new-node) (ref-set (:prev new-node) node1) (ref-set (:next new-node...
920Doubly-linked list/Element insertion
6clojure
strqr
null
918Draw a pixel
11kotlin
hxcj3
import Darwin func ethiopian(var #int1:Int, var #int2:Int) -> Int { var lhs = [int1], rhs = [int2] func isEven(#n:Int) -> Bool {return n% 2 == 0} func double(#n:Int) -> Int {return n * 2} func halve(#n:Int) -> Int {return n / 2} while int1!= 1 { lhs.append(halve(n: int1)) rhs.append(double(n: int2)...
901Ethiopian multiplication
17swift
oy38k
fn main() { struct ElementaryCA { rule: u8, state: u64, } impl ElementaryCA { fn new(rule: u8) -> (u64, ElementaryCA) { let out = ElementaryCA { rule, state: 1, }; (out.state, out) } fn next(&mut self...
910Elementary cellular automaton
15rust
9g6mm
import java.awt._ import java.awt.event.ActionEvent import javax.swing._ object ElementaryCellularAutomaton extends App { SwingUtilities.invokeLater(() => new JFrame("Elementary Cellular Automaton") { class ElementaryCellularAutomaton extends JPanel { private val dim = new Dimension(900, 450) ...
910Elementary cellular automaton
16scala
2j9lb
import Reflex.Dom import Data.Map as DM (Map, lookup, insert, empty, fromList) import Data.Matrix import Data.Time.Clock import Control.Monad.Trans size = 500 updateFrequency = 0.2 rotationStep = pi/10 data Color = Red | Green | Blue | Yellow | Orange | Purple | Black deriving (Show,Eq,Ord,Enum) zRot :: Float ->...
919Draw a rotating cube
8haskell
4pz5s
typedef struct sListEntry { const char *value; struct sListEntry *next; struct sListEntry *prev; } *ListEntry, *LinkedList; typedef struct sListIterator{ ListEntry link; LinkedList head; } *LIterator; LinkedList NewList() { ListEntry le = malloc(sizeof(struct sListEntry)); if (le) { ...
921Doubly-linked list/Traversal
5c
iyho2
int compar(const void *a, const void *b){ char c1=*(const char*)a, c2=*(const char*)b; return c1-c2; } _Bool issorted(char *balls){ int i,state; state=0; for(i=0;i<NUMBALLS;i++){ if(balls[i]<state)return false; if(balls[i]>state)state=balls[i]; } return true; } void printout(char *balls){ int i; char st...
922Dutch national flag problem
5c
vho2o
import SocketServer HOST = PORT = 12321 class EchoServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): pass class EchoRequestHandler(SocketServer.StreamRequestHandler): def handle(self): print % self.client_address[0] while True: line = self.rfile.readline() ...
907Echo server
3python
p81bm
import inflect import time before = time.perf_counter() p = inflect.engine() print(' ') print('eban numbers up to and including 1000:') print(' ') count = 0 for i in range(1,1001): if not 'e' in p.number_to_words(i): print(str(i)+' ',end='') count += 1 print(' ') print(' ') print('count = '+...
916Eban numbers
3python
kqvhf
local SDL = require "SDL" local ret = SDL.init { SDL.flags.Video } local window = SDL.createWindow { title = "Pixel", height = 320, width = 240 } local renderer = SDL.createRenderer(window, 0, 0) renderer:clear() renderer:setDrawColor(0xFF0000) renderer:drawPoint({x = 100,y = 100}) renderer:present() SDL.delay(5...
918Draw a pixel
1lua
kqlh2
from itertools import product def egyptian_divmod(dividend, divisor): assert divisor != 0 pwrs, dbls = [1], [divisor] while dbls[-1] <= dividend: pwrs.append(pwrs[-1] * 2) dbls.append(pwrs[-1] * divisor) ans, accum = 0, 0 for pwr, dbl in zip(pwrs[-2::-1], dbls[-2::-1]): if a...
914Egyptian division
3python
ralgq
from fractions import Fraction from math import ceil class Fr(Fraction): def __repr__(self): return '%s/%s'% (self.numerator, self.denominator) def ef(fr): ans = [] if fr >= 1: if fr.denominator == 1: return [[int(fr)], Fr(0, 1)] intfr = int(fr) ans, fr = [[intf...
913Egyptian fractions
3python
2j6lz
import java.awt.*; import java.awt.event.ActionEvent; import static java.lang.Math.*; import javax.swing.*; public class RotatingCube extends JPanel { double[][] nodes = {{-1, -1, -1}, {-1, -1, 1}, {-1, 1, -1}, {-1, 1, 1}, {1, -1, -1}, {1, -1, 1}, {1, 1, -1}, {1, 1, 1}}; int[][] edges = {{0, 1}, {1, 3}, {...
919Draw a rotating cube
9java
cro9h
package Elementwise; use Exporter 'import'; use overload '=' => sub { $_[0]->clone() }, '+' => sub { $_[0]->add($_[1]) }, '-' => sub { $_[0]->sub($_[1]) }, '*' => sub { $_[0]->mul($_[1]) }, '/' => sub { $_[0]->div($_[1]) }, '**' => sub { $_[0]->exp($_[1]) }, ; sub new { my ($class, $v) = @_; return bless $v,...
912Element-wise operations
2perl
83w0w
(def dl (double-list [:a:b:c:d])) ((juxt seq rseq) dl) (take-while identity (iterate get-next (get-head dl))) (take-while identity (iterate get-prev (get-tail dl)))
921Doubly-linked list/Traversal
6clojure
z2atj
struct Node { struct Node *next; struct Node *prev; void *data; };
923Doubly-linked list/Element definition
5c
9gxm1
print "Enter a variable name: "; $varname = <STDIN>; chomp($varname); $$varname = 42; print "$foo\n";
917Dynamic variable names
2perl
4p65d
<?php $varname = rtrim(fgets(STDIN)); $$varname = 42; echo ; ?>
917Dynamic variable names
12php
iy1ov
Egyptian_division <- function(num, den){ pow2 = 0 row = 1 Table = data.frame(powers_of_2 = 2^pow2, doubling = den) while(Table$doubling[nrow(Table)] < num){ row = row + 1 pow2 = pow2 + 1 Table[row, 1] <- 2^pow2 Table[row, 2] <- 2^pow2 * den } Table <- Table[-nrow(Tab...
914Egyptian division
13r
ukyvx
null
901Ethiopian multiplication
20typescript
2h7lu
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> canvas { background-color: black; } </style> </head> <body> <canvas></canvas> <script> var canvas = document.querySelector("canvas"); canvas.width = window.innerWidth; canvas.he...
919Draw a rotating cube
10javascript
5btur
(defn dutch-flag-order [color] (get {:red 1:white 2:blue 3} color)) (defn sort-in-dutch-flag-order [balls] (sort-by dutch-flag-order balls)) (defn random-balls [num-balls] (repeatedly num-balls #(rand-nth [:red:white:blue]))) (defn starting-balls [num-balls] (let [balls (random-balls num-ball...
922Dutch national flag problem
6clojure
ratg2
const char *shades = ; void vsub(double *v1, double *v2, double *s) { s[0] = v1[0] - v2[0]; s[1] = v1[1] - v2[1]; s[2] = v1[2] - v2[2]; } double 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; return len; } double dot(double *x,...
924Draw a cuboid
5c
m4eys
def main intervals = [ [2, 1000, true], [1000, 4000, true], [2, 10000, false], [2, 100000, false], [2, 1000000, false], [2, 10000000, false], [2, 100000000, false], [2, 1000000000, false] ] for intv in intervals (start, ending, display)...
916Eban numbers
14ruby
p05bh
package main import "fmt" type dlNode struct { string next, prev *dlNode } type dlList struct { head, tail *dlNode } func (list *dlList) String() string { if list.head == nil { return fmt.Sprint(list.head) } r := "[" + list.head.string for p := list.head.next; p != nil; p = p.nex...
920Doubly-linked list/Element insertion
0go
m4syi
insert _ Leaf = Leaf insert nv l@(Node pl v r) = (\(Node c _ _) -> c) new where new = updateLeft left . updateRight right $ Node l nv r left = Node pl v new right = case r of Leaf -> Leaf Node _ v r -> Node new v r
920Doubly-linked list/Element insertion
8haskell
kq9h0
(defrecord Node [prev next data]) (defn new-node [prev next data] (Node. (ref prev) (ref next) data))
923Doubly-linked list/Element definition
6clojure
ukovi
>>> name = raw_input() Enter a variable name: X >>> globals()[name] = 42 >>> X 42
917Dynamic variable names
3python
g1y4h
object EbanNumbers { class ERange(s: Int, e: Int, p: Boolean) { val start: Int = s val end: Int = e val print: Boolean = p } def main(args: Array[String]): Unit = { val rgs = List( new ERange(2, 1000, true), new ERange(1000, 4000, true), new ERange(2, 10000, false), new E...
916Eban numbers
16scala
wn7es
null
919Draw a rotating cube
11kotlin
3vxz5
>>> import random >>> from operator import add, sub, mul, floordiv >>> from pprint import pprint as pp >>> >>> def ewise(matrix1, matrix2, op): return [[op(e1,e2) for e1,e2 in zip(row1, row2)] for row1,row2 in zip(matrix1, matrix2)] >>> m,n = 3,4 >>> a0 = [[random.randint(1,9) for y in range(n)] for x in range(m)]...
912Element-wise operations
3python
o6x81
import java.util.LinkedList; @SuppressWarnings("serial") public class DoublyLinkedListInsertion<T> extends LinkedList<T> { public static void main(String[] args) { DoublyLinkedListInsertion<String> list = new DoublyLinkedListInsertion<String>(); list.addFirst("Add First 1"); list.addFirst(...
920Doubly-linked list/Element insertion
9java
4pt58
varname <- readline("Please name your variable >") varname <- make.names(varname) message(paste("The variable being assigned is '", varname, "'")) assign(varname, 42) ls(pattern=varname) get(varname)
917Dynamic variable names
13r
vht27