code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
$odd = function ($prev) use ( &$odd ) { $a = fgetc(STDIN); if (!ctype_alpha($a)) { $prev(); fwrite(STDOUT, $a); return $a != '.'; } $clos = function () use ($a , $prev) { fwrite(STDOUT, $a); $prev(); }; return $odd($clos); }; $even = function () { while (true) { $c = fgetc(STDIN); fwrite(STDOUT, $c...
504Odd word problem
12php
lsqcj
null
509Old lady swallowed a fly
11kotlin
el3a4
require 'rubygems' require 'gl' require 'glut' include Gl include Glut paint = lambda do glClearColor(0.3,0.3,0.3,0.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glShadeModel(GL_SMOOTH) glLoadIdentity glTranslatef(-15.0, -15.0, 0.0) glBegin(GL_TRIANGLES) glColor3f(1.0, 0.0, 0.0) glVerte...
499OpenGL
14ruby
fkadr
class NumberWithUncertainty def initialize(number, error) @num = number @err = error.abs end attr_reader :num, :err def +(other) if other.kind_of?(self.class) self.class.new(num + other.num, Math::hypot(err, other.err)) else self.class.new(num + other, err) end end def -(ot...
507Numeric error propagation
14ruby
rfogs
use glow::*; use glutin::event::*; use glutin::event_loop::{ControlFlow, EventLoop}; use std::os::raw::c_uint; const VERTEX: &str = "#version 410 const vec2 verts[3] = vec2[3]( vec2(0.5f, 1.0f), vec2(0.0f, 0.0f), vec2(1.0f, 0.0f) ); out vec2 vert; void main() { vert = verts[gl_VertexID]; gl_Positio...
499OpenGL
15rust
tbefd
from random import randrange try: range = xrange except: pass def one_of_n(lines): choice = None for i, line in enumerate(lines): if randrange(i+1) == 0: choice = line return choice def one_of_n_test(n=10, trials=1000000): bins = [0] * n if n: for i in range(trials...
502One of n lines in a file
3python
mwxyh
one_of_n <- function(n) { choice <- 1L for (i in 2:n) { if (i*runif(1) < 1) choice <- i } return(choice) } table(sapply(1:1000000, function(i) one_of_n(10)))
502One of n lines in a file
13r
zp1th
>>> [1,2,1,3,2] < [1,2,0,4,4,0,0,0] False
500Order two numerical lists
3python
tbafw
use strict; use warnings; open(FH, "<", "unixdict.txt") or die "Can't open file!\n"; my @words; while (<FH>) { chomp; push @{$words[length]}, $_ if $_ eq join("", sort split(//)); } close FH; print "@{$words[-1]}\n";
491Ordered words
2perl
v8920
import java.lang.Math._ class Approx(val : Double, val : Double = 0.0) { def this(a: Approx) = this(a., a.) def this(n: Number) = this(n.doubleValue(), 0.0) override def toString = s"$ $" def +(a: Approx) = Approx( + a., sqrt( * + a. * a.)) def +(d: Double) = Approx( + d, ) def -(a: Approx) ...
507Numeric error propagation
16scala
k6fhk
(defn flip-at [n coll] (let [[x y] (split-at n coll)] (concat (reverse x) y ))) (def sorted '(1 2 3 4 5 6 7 8 9)) (def unsorted? #(not= % sorted)) (loop [unsorted (first (filter unsorted? (iterate shuffle sorted))), steps 0] (if (= unsorted sorted) (printf "Done! That took you%d steps%n" steps) (do ...
514Number reversal game
6clojure
6a53q
import org.lwjgl.opengl.{ Display, DisplayMode } import org.lwjgl.opengl.GL11._ object OpenGlExample extends App { def render() { glClearColor(0.3f, 0.3f, 0.3f, 0.0f) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glShadeModel(GL_SMOOTH) glLoadIdentity() glTranslatef(-15.0f, -15.0f, 0.0f)...
499OpenGL
16scala
6aq31
import Foundation precedencegroup ExponentiationGroup { higherThan: MultiplicationPrecedence } infix operator **: ExponentiationGroup infix operator func (_ lhs: Double, _ rhs: Double) -> UncertainDouble { UncertainDouble(value: lhs, error: rhs) } struct UncertainDouble { var value: Double var error: Double ...
507Numeric error propagation
17swift
gd849
const char *ones[] = { 0, , , , , , , , , , , , , , , , , , , }; const char *tens[] = { 0, , , , , , , , , }; const char *llions[] = { 0, , , , , }; const int maxillion = sizeof(llions) / sizeof(llions[0]) * 3 - 3; int say_hundred(const char *s, int len, int depth, int has_lead) { int c[3], i; for (i = -3;...
515Number names
5c
eliav
use List::Util qw(sum); use constant pi => 3.14159265; sub legendre_pair { my($n, $x) = @_; if ($n == 1) { return $x, 1 } my ($m1, $m2) = legendre_pair($n - 1, $x); my $u = 1 - 1 / $n; (1 + $u) * $x * $m1 - $u * $m2, $m1; } sub legendre { my($n, $x) = @_; (legendre_pair($n, $x))[0] } sub ...
505Numerical integration/Gauss-Legendre Quadrature
2perl
04us4
animals = {"fly", "spider", "bird", "cat","dog", "goat", "cow", "horse"} phrases = { "", "That wriggled and jiggled and tickled inside her", "How absurd to swallow a bird", "Fancy that to swallow a cat", "What a hog, to swallow a dog", "She just opened her throat and swallowed a goat", "I do...
509Old lady swallowed a fly
1lua
w26ea
from sys import stdin, stdout def char_in(): return stdin.read(1) def char_out(c): stdout.write(c) def odd(prev = lambda: None): a = char_in() if not a.isalpha(): prev() char_out(a) return a != '.' def clos(): char_out(a) prev() return odd(clos) def even(): while True: c = char_in() char_out(c...
504Odd word problem
3python
xv2wr
def random_line(io) choice = io.gets; count = 1 while line = io.gets rand(count += 1).zero? and choice = line end choice end def one_of_n(n) (mock_io = Object.new).instance_eval do @count = 0 @last = n def self.gets (@count < @last)? (@count += 1): nil end end random_line(...
502One of n lines in a file
14ruby
cqs9k
>> ([1,2,1,3,2] <=> [1,2,0,4,4,0,0,0]) < 0 => false
500Order two numerical lists
14ruby
31wz7
extern crate rand; use rand::{Rng, thread_rng}; fn one_of_n<R: Rng>(rng: &mut R, n: usize) -> usize { (1..n).fold(0, |keep, cand| {
502One of n lines in a file
15rust
ls0cc
def one_of_n(n: Int, i: Int = 1, j: Int = 1): Int = if (n < 1) i else one_of_n(n - 1, if (scala.util.Random.nextInt(j) == 0) n else i, j + 1) def simulate(lines: Int, iterations: Int) = { val counts = new Array[Int](lines) for (_ <- 1 to iterations; i = one_of_n(lines) - 1) counts(i) = counts(i) + 1 counts } ...
502One of n lines in a file
16scala
uoiv8
vec![1, 2, 1, 3, 2] < vec![1, 2, 0, 4, 4, 0, 0, 0]
500Order two numerical lists
15rust
6ax3l
def lessThan1(a: List[Int], b: List[Int]): Boolean = if (b.isEmpty) false else if (a.isEmpty) true else if (a.head != b.head) a.head < b.head else lessThan1(a.tail, b.tail)
500Order two numerical lists
16scala
9x0m5
def palindrome?(s) s == s.reverse end
483Palindrome detection
14ruby
h6ajx
(clojure.pprint/cl-format nil "~R" 1234) => "one thousand, two hundred thirty-four"
515Number names
6clojure
04zsj
package main import ( "fmt" "math" )
511Numerical integration
0go
dhvne
from numpy import * def Legendre(n,x): x=array(x) if (n==0): return x*0+1.0 elif (n==1): return x else: return ((2.0*n-1.0)*x*Legendre(n-1,x)-(n-1)*Legendre(n-2,x))/n def DLegendre(n,x): x=array(x) if (n==0): return x*0 elif (n==1): return x*0+1.0 else: return (n/(x**2-1.0))*(x*Legendre(n,x)-L...
505Numerical integration/Gauss-Legendre Quadrature
3python
8g50o
f, r = nil fwd = proc {|c| c =~ /[[:alpha:]]/? [(print c), fwd[Fiber.yield f]][1]: c } rev = proc {|c| c =~ /[[:alpha:]]/? [rev[Fiber.yield r], (print c)][0]: c } (f = Fiber.new { loop { print fwd[Fiber.yield r] }}).resume (r = Fiber.new { loop { print rev[Fiber.yield f] }}).resume coro = f until $stdin.eof? co...
504Odd word problem
14ruby
s5uqw
def assertBounds = { List bounds, int nRect -> assert (bounds.size() == 2) && (bounds[0] instanceof Double) && (bounds[1] instanceof Double) && (nRect > 0) } def integral = { List bounds, int nRectangles, Closure f, List pointGuide, Closure integralCalculator-> double a = bounds[0], b = bounds[1], h = (b - a)/...
511Numerical integration
7groovy
04msh
func one_of_n(n: Int) -> Int { var result = 1 for i in 2...n { if arc4random_uniform(UInt32(i)) < 1 { result = i } } return result } var counts = [0,0,0,0,0,0,0,0,0,0] for _ in 1..1_000_000 { counts[one_of_n(10)-1]++ } println(counts)
502One of n lines in a file
17swift
9xqmj
fn is_palindrome(string: &str) -> bool { let half_len = string.len() / 2; string .chars() .take(half_len) .eq(string.chars().rev().take(half_len)) } macro_rules! test { ( $( $x:tt ),* ) => { $( println!("'{}': {}", $x, is_palindrome($x)); )* }; } fn main() { test!( "", ...
483Palindrome detection
15rust
kyeh5
import scala.io.Source import java.io.PrintStream def process(s: Source, p: PrintStream, w: Int = 0): Unit = if (s.hasNext) s.next match { case '.' => p append '.' case c if !Character.isAlphabetic(c) => p append c; reverse(s, p, w + 1) case c => p append c; process(s, p, w) } def reverse(s: Source, p: PrintStr...
504Odd word problem
16scala
i7rox
package main import "fmt" var ( s []int
513Null object
0go
uopvt
undefined error "oops" head []
513Null object
8haskell
w2fed
approx f xs ws = sum [w * f x | (x,w) <- zip xs ws]
511Numerical integration
8haskell
5ieug
let a = [1,2,1,3,2] let b = [1,2,0,4,4,0,0,0] println(lexicographicalCompare(a, b))
500Order two numerical lists
17swift
zpetu
my @animals = ( "fly", "spider/That wriggled and jiggled and tickled inside her.\n", "bird//Quite absurd!", "cat//Fancy that!", "dog//What a hog!", "pig//Her mouth was so big!", "goat//She just opened her throat!", "cow//I don't know how;", "donkey//It was rather wonkey!", "horse:", ); my $s = "swallow"; my ...
509Old lady swallowed a fly
2perl
cqp9a
import urllib.request url = 'http: words = urllib.request.urlopen(url).read().decode().split() ordered = [word for word in words if word==''.join(sorted(word))] maxlen = len(max(ordered, key=len)) maxorderedwords = [word for word in ordered if len(word) == maxlen] print(' '.join(maxorderedwords))
491Ordered words
3python
uocvd
def isPalindrome(s: String): Boolean = (s.size >= 2) && s == s.reverse
483Palindrome detection
16scala
1cqpf
null
513Null object
9java
k60hm
package main import "fmt" const ( start = "_###_##_#_#_#_#__#__" offLeft = '_' offRight = '_' dead = '_' ) func main() { fmt.Println(start) g := newGenerator(start, offLeft, offRight, dead) for i := 0; i < 10; i++ { fmt.Println(g()) } } func newGenerator(start string,...
512One-dimensional cellular automata
0go
jzs7d
class NumericalIntegration { interface FPFunction { double eval(double n); } public static double rectangularLeft(double a, double b, int n, FPFunction f) { return rectangular(a, b, n, f, 0); } public static double rectangularMidpoint(double a, double b, int n, FPFunction f) { return rect...
511Numerical integration
9java
9xhmu
import scala.math.{Pi, cos, exp} object GaussLegendreQuadrature extends App { private val N = 5 private def legeInte(a: Double, b: Double): Double = { val (c1, c2) = ((b - a) / 2, (b + a) / 2) val tuples: IndexedSeq[(Double, Double)] = { val lcoef = { val lcoef = Array.ofDim[Double](N + 1, N...
505Numerical integration/Gauss-Legendre Quadrature
16scala
tbhfb
if (object === null) { alert("object is null");
513Null object
10javascript
eldao
def life1D = { self -> def right = self[1..-1] + [false] def left = [false] + self[0..-2] [left, self, right].transpose().collect { hood -> hood.count { it } == 2 } }
512One-dimensional cellular automata
7groovy
5iauv
<?php $swallowed = array( array('swallowed' => 'fly.', 'reason' => ), array('swallowed' => 'spider,', 'aside' => , 'reason' => ), array('swallowed' => 'bird.', 'aside' => , 'reason' => ), array('swallowed' => 'cat.', 'aside' => , 'reason' => ), array('s...
509Old lady swallowed a fly
12php
xvyw5
words = scan("https://web.archive.org/web/20180611003215/http://www.puzzlers.org/pub/wordlists/unixdict.txt",what = "character") ordered = logical() for(i in 1:length(words)){ first = strsplit(words[i],"")[[1]][1:nchar(words[i])-1] second = strsplit(words[i],"")[[1]][2:nchar(words[i])] ordered[i] = all(first<=se...
491Ordered words
13r
cq695
import Data.List (unfoldr) import System.Random (newStdGen, randomRs) bnd :: String -> Char bnd "_##" = '#' bnd "#_#" = '#' bnd "##_" = '#' bnd _ = '_' nxt :: String -> String nxt = unfoldr go . ('_':) . (<> "_") where go [_, _] = Nothing go xs = Just (bnd $ take 3 xs, drop 1 xs) lahmahgaan :: String -> [S...
512One-dimensional cellular automata
8haskell
or98p
null
511Numerical integration
11kotlin
zp4ts
null
513Null object
11kotlin
gde4d
import zlib, base64 b64 = b''' eNrtVE1rwzAMvedXaKdeRn7ENrb21rHCzmrs1m49K9gOJv9+cko/HBcGg0LHcpOfnq2np0QL 2FuKgBbICDAoeoiKwEc0hqIUgLAxfV0tQJCdhQM7qh68kheswKeBt5ROYetTemYMCC3rii WMS3WkhXVyuFAaLT261JuBWwu4iDbvYp1tYzHVS68VEIObwFgaDB0KizuFs38aSdqKv3TgcJ uPYdn2B1opwIpeKE53qPftxRd88Y6uoVbdPzWxznrQ3ZUi3DudQ/bcELbevqM32iCIrj3II...
509Old lady swallowed a fly
3python
ls1cv
animals = list( c("fly", "I don't know why she swallowed a fly, perhaps she'll die."), c("spider", "It wiggled and jiggled and tickled inside her."), c("bird", "How absurd, to swallow a bird."), c("cat", "Imagine that, she swallowed a cat."), c("dog", "What a hog, to swallow a dog."), c("goat", "She just op...
509Old lady swallowed a fly
13r
yeh6h
require 'open-uri' ordered_words = open('http: word.strip! word.chars.sort.join == word end grouped = ordered_words.group_by &:size puts grouped[grouped.keys.max]
491Ordered words
14ruby
4n25p
public class Life{ public static void main(String[] args) throws Exception{ String start= "_###_##_#_#_#_#__#__"; int numGens = 10; for(int i= 0; i < numGens; i++){ System.out.println("Generation " + i + ": " + start); start= life(start); } } public static String life(String lastGen){ String newGen=...
512One-dimensional cellular automata
9java
w2tej
function caStep(old) { var old = [0].concat(old, [0]);
512One-dimensional cellular automata
10javascript
8gm0l
function leftRect( f, a, b, n ) local h = (b - a) / n local x = a local sum = 0 for i = 1, 100 do sum = sum + a + f(x) x = x + h end return sum * h end function rightRect( f, a, b, n ) local h = (b - a) / n local x = b local sum = 0 for i = 1, 100 do s...
511Numerical integration
1lua
31gzo
const FILE: &'static str = include_str!("./unixdict.txt"); fn is_ordered(s: &str) -> bool { let mut prev = '\x00'; for c in s.to_lowercase().chars() { if c < prev { return false; } prev = c; } return true; } fn find_longest_ordered_words(dict: Vec<&str>) -> Vec<&st...
491Ordered words
15rust
gdv4o
isnil = (object == nil) print(isnil)
513Null object
1lua
rfwga
descriptions = { :fly => , :spider => , :bird => , :cat => , :dog => , :goat => , :cow => , :horse => , } animals = descriptions.keys animals.each_with_index do |animal, idx| puts d = descriptions[animal] case d[-1] when then d[-1] = when then d[-1] = end puts d b...
509Old lady swallowed a fly
14ruby
v8e2n
val wordsAll = scala.io.Source.fromURL("http:
491Ordered words
16scala
jz47i
enum Action {Once, Every, Die} use Action::*; fn main() { let animals = [ ("horse" , Die , "She's dead, of course!") , ("donkey", Once , "It was rather wonky. To swallow a donkey.") , ("cow" , Once , "I don't know how. To swallow a cow.") , ("goat" , Once ,...
509Old lady swallowed a fly
15rust
uowvj
case class Verse(animal: String, remark: String, die: Boolean = false, always: Boolean = false) val verses = List( Verse("horse", "Shes dead, of course!", die = true), Verse("donkey", "It was rather wonky. To swallow a donkey."), Verse("cow", "I dont know how. To swallow a cow."), Verse("goat", "She just opene...
509Old lady swallowed a fly
16scala
gds4i
SET @txt = REPLACE('In girum imus nocte et consumimur igni', ' ', ''); SELECT REVERSE(@txt) = @txt;
483Palindrome detection
19sql
wv8ex
package main import "fmt" func main() { for _, n := range []int64{12, 1048576, 9e18, -2, 0} { fmt.Println(say(n)) } } var small = [...]string{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "ei...
515Number names
0go
9xgmt
null
512One-dimensional cellular automata
11kotlin
byokb
import Foundation
483Palindrome detection
17swift
j3174
def divMod(BigInteger number, BigInteger divisor) { def qr = number.divideAndRemainder(divisor) [div:qr[0], remainder:qr[1]] } def toText(value) { value = value as BigInteger def units = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelv...
515Number names
7groovy
zp2t5
package main import ( "fmt" "math/rand" "sort" "time" ) func main() { rand.Seed(time.Now().UnixNano()) var k []int for { k = rand.Perm(9) for i, r := range k { if r == 0 { k[i] = 9 } } if !sort.IntsAreSorted(k) { ...
514Number reversal game
0go
7twr2
import Data.List (intercalate, unfoldr) spellInteger :: Integer -> String spellInteger n | n < 0 = "negative " ++ spellInteger (-n) | n < 20 = small n | n < 100 = let (a, b) = n `divMod` 10 in tens a ++ nonzero '-' b | n < 1000 = let (a, b) = n `divMod` 100 in small a ++ "...
515Number names
8haskell
bysk2
sorted = [*(1..9)] arr = sorted.clone() void flipstart(n) { arr[0..<n] = arr[0..<n].reverse() } int steps = 0 while (arr==sorted) Collections.shuffle(arr) while (arr!=sorted) { println arr.join(' ') print 'Reverse how many? ' def flipcount = System.in.readLine() flipstart( flipcount.toInteger() ) ...
514Number reversal game
7groovy
uobv9
import Data.List import Control.Arrow import Rosetta.Knuthshuffle numberRevGame = do let goal = [1..9] shuffle xs = if xs /= goal then return xs else shuffle =<< knuthShuffle xs prefixFlipAt k = uncurry (++). first reverse. splitAt k prompt r ry = do putStr $ show r ++ ". " ++ concatMap...
514Number reversal game
8haskell
8g60z
num_iterations = 9 f = { 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0 } function Output( f, l ) io.write( l, ": " ) for i = 1, #f do local c if f[i] == 1 then c = '#' else c = '_' end io.write( c ) end print "" end Output( f, 0 ) for l = 1, num_iterations do ...
512One-dimensional cellular automata
1lua
pmibw
import Foundation guard let url = NSURL(string: "http:
491Ordered words
17swift
5ilu8
const detectNonLetterRegexp=/[^A-Z--]/g; function stripDiacritics(phrase:string){ return phrase.normalize('NFD').replace(/[\u0300-\u036f]/g, "") } function isPalindrome(phrase:string){ const TheLetters = stripDiacritics(phrase.toLocaleUpperCase().replace(detectNonLetterRegexp, '')); const middlePosition =...
483Palindrome detection
20typescript
o7t8l
use feature 'say'; sub leftrect { my($func, $a, $b, $n) = @_; my $h = ($b - $a) / $n; my $sum = 0; for ($_ = $a; $_ < $b; $_ += $h) { $sum += $func->($_) } $h * $sum } sub rightrect { my($func, $a, $b, $n) = @_; my $h = ($b - $a) / $n; my $sum = 0; for ($_ = $a+$h; $_ < $b+$h; $_ +...
511Numerical integration
2perl
byik4
public enum IntToWords { ; private static final String[] small = { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}; priva...
515Number names
9java
gd14m
const divMod = y => x => [Math.floor(y/x), y % x]; const sayNumber = value => { let name = ''; let quotient, remainder; const dm = divMod(value); const units = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', ...
515Number names
10javascript
k6qhq
print defined($x) ? 'Defined' : 'Undefined', ".\n";
513Null object
2perl
njciw
import java.util.List; import java.util.ArrayList; import java.util.Scanner; import java.util.Collections; public class ReversalGame { private List<Integer> gameList; public ReversalGame() { initialize(); } public void play() throws Exception { int i = 0; int moveCount = 0; ...
514Number reversal game
9java
elna5
from fractions import Fraction def left_rect(f,x,h): return f(x) def mid_rect(f,x,h): return f(x + h/2) def right_rect(f,x,h): return f(x+h) def trapezium(f,x,h): return (f(x) + f(x+h))/2.0 def simpson(f,x,h): return (f(x) + 4*f(x + h/2) + f(x+h))/6.0 def cube(x): return x*x*x def reciprocal(x): re...
511Numerical integration
3python
pmnbm
<html> <head> <title>Number Reversal Game</title> </head> <body> <div id="start"></div> <div id="progress"></div> <div id="score"></div> <script type="text/javascript">
514Number reversal game
10javascript
043sz
$x = NULL; if (is_null($x)) echo ;
513Null object
12php
7txrp
integ <- function(f, a, b, n, u, v) { h <- (b - a) / n s <- 0 for (i in seq(0, n - 1)) { s <- s + sum(v * f(a + i * h + u * h)) } s * h } test <- function(f, a, b, n) { c(rect.left = integ(f, a, b, n, 0, 1), rect.right = integ(f, a, b, n, 1, 1), rect.mid = integ(f, a, b, n, 0.5, 1), trapezo...
511Numerical integration
13r
jz078
null
515Number names
11kotlin
20jli
x = None if x is None: print else: print
513Null object
3python
dhln1
is.null(NULL) is.null(123) is.null(NA) 123==NULL foo <- function(){} foo()
513Null object
13r
8gy0x
null
514Number reversal game
11kotlin
k6sh3
$_="_ do { y/01/_ print; y/_ s/(?<=(.))(.)(?=(.))/$1 == $3? $1? 1-$2: 0: $2/eg; } while ($x ne $_ and $x=$_);
512One-dimensional cellular automata
2perl
6ag36
words = {"one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine "} levels = {"thousand ", "million ", "billion ", "trillion ", "quadrillion ", "quintillion ", "sextillion ", "septillion ", "octillion ", [0] = ""} iwords = {"ten ", "twenty ", "thirty ", "forty ", "fifty ", "sixty ", "seventy ", "e...
515Number names
1lua
v8h2x
null
514Number reversal game
1lua
by0ka
def leftrect(f, left, right) f.call(left) end def midrect(f, left, right) f.call((left+right)/2.0) end def rightrect(f, left, right) f.call(right) end def trapezium(f, left, right) (f.call(left) + f.call(right)) / 2.0 end def simpson(f, left, right) (f.call(left) + 4*f.call((left+right)/2.0) + f.call(righ...
511Numerical integration
14ruby
acf1s
puts if @object.nil? puts if $object.nil? object = 1 if false puts if object.nil? puts nil.class
513Null object
14ruby
tbvf2
null
513Null object
15rust
zputo
fn integral<F>(f: F, range: std::ops::Range<f64>, n_steps: u32) -> f64 where F: Fn(f64) -> f64 { let step_size = (range.end - range.start)/n_steps as f64; let mut integral = (f(range.start) + f(range.end))/2.; let mut pos = range.start + step_size; while pos < range.end { integral += f(pos)...
511Numerical integration
15rust
eltaj
scala> Nil res0: scala.collection.immutable.Nil.type = List() scala> Nil == List() res1: Boolean = true scala> Null <console>:8: error: not found: value Null Null ^ scala> null res3: Null = null scala> None res4: None.type = None scala> Unit res5: Unit.type = object scala.Unit scala> v...
513Null object
16scala
yeg63
object NumericalIntegration { def leftRect(f:Double=>Double, a:Double, b:Double)=f(a) def midRect(f:Double=>Double, a:Double, b:Double)=f((a+b)/2) def rightRect(f:Double=>Double, a:Double, b:Double)=f(b) def trapezoid(f:Double=>Double, a:Double, b:Double)=(f(a)+f(b))/2 def simpson(f:Double=>Double, a:Double...
511Numerical integration
16scala
qu6xw
import random printdead, printlive = '_ maxgenerations = 10 cellcount = 20 offendvalue = '0' universe = ''.join(random.choice('01') for i in range(cellcount)) neighbours2newstate = { '000': '0', '001': '0', '010': '0', '011': '1', '100': '0', '101': '1', '110': '1', '111': '0', } for i in range(maxgenerati...
512One-dimensional cellular automata
3python
yer6q
set.seed(15797, kind="Mersenne-Twister") maxgenerations = 10 cellcount = 20 offendvalue = FALSE universe <- c(offendvalue, sample( c(TRUE, FALSE), cellcount, replace=TRUE), offendvalue) stayingAlive <- lapply(list(c(1,1,0), c(1,0,1), ...
512One-dimensional cellular automata
13r
tbufz
let maybeInt: Int? = nil
513Null object
17swift
fk2dk
public enum IntegrationType: CaseIterable { case rectangularLeft case rectangularRight case rectangularMidpoint case trapezium case simpson } public func integrate( from: Double, to: Double, n: Int, using: IntegrationType = .simpson, f: (Double) -> Double ) -> Double { let integrationFunc: (Doubl...
511Numerical integration
17swift
19dpt