code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
import Data.Numbers.Primes (isPrime) import Data.List (intercalate) import Data.List.Split (chunksOf) import Text.Printf (printf) cubans :: [Int] cubans = filter isPrime . map (\x -> (succ x ^ 3) - (x ^ 3)) $ [1 ..] main :: IO () main = do mapM_ (\row -> mapM_ (printf "%10s" . thousands) row >> printf "\n") $ rows ...
981Cuban primes
8haskell
woped
require 'bigdecimal/util' before_tax = 4000000000000000 * 5.50.to_d + 2 * 2.86.to_d tax = (before_tax * 0.0765.to_d).round(2) total = before_tax + tax puts
978Currency
14ruby
r1rgs
extern crate num_bigint;
978Currency
15rust
7a7rc
sub curry{ my ($func, @args) = @_; sub { &$func(@args, @_); } } sub plusXY{ $_[0] + $_[1]; } my $plusXOne = curry(\&plusXY, 1); print &$plusXOne(3), "\n";
975Currying
2perl
5kru2
import datetime def mt(): datime1= formatting = datime2 = datime1[:-3] tdelta = datetime.timedelta(hours=12) s3 = datetime.datetime.strptime(datime2, formatting) datime2 = s3+tdelta print datime2.strftime() + datime1[-3:] mt()
970Date manipulation
3python
m54yh
time <- strptime("March 7 2009 7:30pm EST", "%B%d%Y%I:%M%p%Z") isotime <- ISOdatetime(1900 + time$year, time$mon, time$mday, time$hour, time$min, time$sec, "EST") twelvehourslater <- isotime + 12 * 60 * 60 timeincentraleurope <- format(isotime, tz="CET", usetz=TR...
970Date manipulation
13r
zl2th
import java.util.Calendar; import java.util.GregorianCalendar; import java.text.DateFormatSymbols; import java.text.DateFormat; public class Dates{ public static void main(String[] args){ Calendar now = new GregorianCalendar();
977Date format
9java
0t8se
public class CubanPrimes { private static int MAX = 1_400_000; private static boolean[] primes = new boolean[MAX]; public static void main(String[] args) { preCompute(); cubanPrime(200, true); for ( int i = 1 ; i <= 5 ; i++ ) { int max = (int) Math.pow(10, i); ...
981Cuban primes
9java
kwrhm
import java.text.NumberFormat import java.util.Locale object SizeMeUp extends App { val menu: Map[String, (String, Double)] = Map("burg" ->("Hamburger XL", 5.50), "milk" ->("Milkshake", 2.86)) val order = List((4000000000000000L, "burg"), (2L, "milk")) Locale.setDefault(new Locale("ru", "RU")) val (currSymb...
978Currency
16scala
kxkhk
<?php function curry($callable) { if (_number_of_required_params($callable) === 0) { return _make_function($callable); } if (_number_of_required_params($callable) === 1) { return _curry_array_args($callable, _rest(func_get_args())); } return _curry_array_args($callable, _rest(func_g...
975Currying
12php
o3d85
import math def cusip_check(cusip): if len(cusip) != 9: raise ValueError('CUSIP must be 9 characters') cusip = cusip.upper() total = 0 for i in range(8): c = cusip[i] if c.isdigit(): v = int(c) elif c.isalpha(): p = ord(c) - ord('A') + 1 ...
973CUSIP
3python
8zf0o
var now = new Date(), weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], fmt1 = now.getFullYear() + '-' + (1 + now.getMonth()) + '-' ...
977Date format
10javascript
dmfnu
sub damm { my(@digits) = split '', @_[0]; my @tbl =([< 0 3 1 7 5 9 8 6 4 2 >], [< 7 0 9 2 1 5 4 8 6 3 >], [< 4 2 0 6 8 7 1 3 5 9 >], [< 1 7 5 0 9 8 3 4 2 6 >], [< 6 1 2 3 0 4 5 9 7 8 >], [< 3 6 7 4 2 0 9 5 8 1 >], [< 5 8 6 9 7 2...
974Damm algorithm
2perl
uhrvr
require("date") for year=2008,2121 do if date(year, 12, 25):getweekday() == 1 then print(year) end end
971Day of the week
1lua
o338h
import kotlin.math.ceil import kotlin.math.sqrt fun main() { val primes = mutableListOf(3L, 5L) val cutOff = 200 val bigUn = 100_000 val chunks = 50 val little = bigUn / chunks println("The first $cutOff cuban primes:") var showEach = true var c = 0 var u = 0L var v = 1L va...
981Cuban primes
11kotlin
gbv4d
import Foundation extension Decimal { func rounded(_ scale: Int, _ roundingMode: NSDecimalNumber.RoundingMode) -> Decimal { var result = Decimal() var localCopy = self NSDecimalRound(&result, &localCopy, scale, roundingMode) return result } } let costHamburgers = Decimal(4000000000000000) * Decima...
978Currency
17swift
gpg49
def addN(n): def adder(x): return x + n return adder
975Currying
3python
4b75k
null
977Date format
11kotlin
eowa4
typedef struct { int n; double **elems; } SquareMatrix; SquareMatrix init_square_matrix(int n, double elems[n][n]) { SquareMatrix A = { .n = n, .elems = malloc(n * sizeof(double *)) }; for(int i = 0; i < n; ++i) { A.elems[i] = malloc(n * sizeof(double)); for(int j = ...
985Cramer's rule
5c
yvi6f
<?php function lookup($r,$c) { $table = array( array(0, 3, 1, 7, 5, 9, 8, 6, 4, 2), array(7, 0, 9, 2, 1, 5, 4, 8, 6, 3), array(4, 2, 0, 6, 8, 7, 1, 3, 5, 9), array(1, 7, 5, 0, 9, 8, 3, 4, 2, 6), array(6, 1, 2, 3, 0, 4, 5, 9, 7, 8), array(3, 6, 7, 4, 2, 0, 9, 5, 8, 1),...
974Damm algorithm
12php
8zd0m
local primes = {3, 5} local cutOff = 200 local bigUn = 100000 local chunks = 50 local little = math.floor(bigUn / chunks) local tn = " cuban prime" print(string.format("The first%d%ss", cutOff, tn)) local showEach = true local c = 0 local u = 0 local v = 1 for i=1,10000000000000 do local found = false u = u + 6...
981Cuban primes
1lua
rpuga
require 'time' d = t = Time.parse(d) puts t.rfc2822 puts t.zone new = t + 12*3600 puts new.rfc2822 puts new.zone require 'rubygems' require 'active_support' zone = ActiveSupport::TimeZone['Beijing'] remote = zone.at(new) puts remote.rfc2822 puts remote.zone
970Date manipulation
14ruby
cgr9k
int main(int argc, char **argv) { int user1 = 0, user2 = 0; printf(); scanf(,&user1, &user2); int array[user1][user2]; array[user1/2][user2/2] = user1 + user2; printf(,user1/2,user2/2,array[user1/2][user2/2]); return 0; }
986Create a two-dimensional array at runtime
5c
v7z2o
b = proc {|x, y, z| (x||0) + (y||0) + (z||0) } p b.curry[1][2][3] p b.curry[1, 2][3, 4] p b.curry(5)[1][2][3][4][5] p b.curry(5)[1, 2][3, 4][5] p b.curry(1)[1] b = proc {|x, y, z, *w| (x||0) + (y||0) + (z||0) + w.inject(0, &:+) } p b.curry[1][2][3] p b.curry[1, 2][3, 4] ...
975Currying
14ruby
r1hgs
use chrono::prelude::*; use chrono::Duration; fn main() {
970Date manipulation
15rust
lr7cc
def check_cusip(cusip) abort('CUSIP must be 9 characters') if cusip.size!= 9 sum = 0 cusip.split('').each_with_index do |char, i| next if i == cusip.size - 1 case when char.scan(/\D/).empty? v = char.to_i when char.scan(/\D/).any? pos = char.upcase.ord - 'A'.ord + 1 v = pos + 9 ...
973CUSIP
14ruby
i6zoh
fn add_n(n: i32) -> impl Fn(i32) -> i32 { move |x| n + x } fn main() { let adder = add_n(40); println!("The answer to life is {}.", adder(2)); }
975Currying
15rust
7akrc
def add(a: Int)(b: Int) = a + b val add5 = add(5) _ add5(2)
975Currying
16scala
kx1hk
import java.text.SimpleDateFormat import java.util.{Calendar, Locale, TimeZone} object DateManipulation { def main(args: Array[String]): Unit = { val input="March 7 2009 7:30pm EST" val df=new SimpleDateFormat("MMMM d yyyy h:mma z", Locale.ENGLISH) val c=Calendar.getInstance() c.setTime(df.parse(inpu...
970Date manipulation
16scala
uhkv8
fn cusip_check(cusip: &str) -> bool { if cusip.len()!= 9 { return false; } let mut v = 0; let capital_cusip = cusip.to_uppercase(); let char_indices = capital_cusip.as_str().char_indices().take(7); let total = char_indices.fold(0, |total, (i, c)| { v = match c { '*'...
973CUSIP
15rust
ny3i4
object Cusip extends App { val candidates = Seq("037833100", "17275R102", "38259P508", "594918104", "68389X106", "68389X105") for (candidate <- candidates) printf(f"$candidate%s -> ${if (isCusip(candidate)) "correct" else "incorrect"}%s%n") private def isCusip(s: String): Boolean = { if (s.length != 9)...
973CUSIP
16scala
tcmfb
const char *input = ; int main() { const char *s; printf(); for (s = input; *s; s++) { switch(*s) { case '\n': printf(); break; case ',': printf(); break; case '<': printf(); break; case '>': printf(); break; case '&': printf(); break; default: putchar(*s); } } puts(); retur...
987CSV to HTML translation
5c
ujzv4
use feature 'say'; use ntheory 'is_prime'; sub cuban_primes { my ($n) = @_; my @primes; for (my $k = 1 ; ; ++$k) { my $p = 3 * $k * ($k + 1) + 1; if (is_prime($p)) { push @primes, $p; last if @primes >= $n; } } return @primes; } sub commify { s...
981Cuban primes
2perl
n60iw
func addN(n:Int)->Int->Int { return {$0 + n} } var add2 = addN(2) println(add2)
975Currying
17swift
gpj49
struct CUSIP { var value: String private static let alphabet = Array("ABCDEFGHIJKLMNOPQRSTUVWXYZ") init?(value: String) { if value.count == 9 && String(value.last!) == CUSIP.checkDigit(cusipString: String(value.dropLast())) { self.value = value } else if value.count == 8, let checkDigit = CUSIP.ch...
973CUSIP
17swift
o3t8k
(let [rows (Integer/parseInt (read-line)) cols (Integer/parseInt (read-line)) a (to-array-2d (repeat rows (repeat cols nil)))] (aset a 0 0 12) (println "Element at 0,0:" (aget a 0 0)))
986Create a two-dimensional array at runtime
6clojure
rp9g2
print( os.date( "%Y-%m-%d" ) ) print( os.date( "%A,%B%d,%Y" ) )
977Date format
1lua
wixea
package main import ( "encoding/csv" "log" "os" "strconv" ) func main() { rows := readSample() appendSum(rows) writeChanges(rows) } func readSample() [][]string { f, err := os.Open("sample.csv") if err != nil { log.Fatal(err) } rows, err := csv.NewReader(f).ReadAll() f.Close() if err != nil { log.Fa...
983CSV data manipulation
0go
95tmt
def damm(num: int) -> bool: row = 0 for digit in str(num): row = _matrix[row][int(digit)] return row == 0 _matrix = ( (0, 3, 1, 7, 5, 9, 8, 6, 4, 2), (7, 0, 9, 2, 1, 5, 4, 8, 6, 3), (4, 2, 0, 6, 8, 7, 1, 3, 5, 9), (1, 7, 5, 0, 9, 8, 3, 4, 2, 6), (6, 1, 2, 3, 0, 4, 5, 9, 7, 8), ...
974Damm algorithm
3python
5k7ux
package main import ( "fmt" "hash/crc32" ) func main() { s := []byte("The quick brown fox jumps over the lazy dog") result := crc32.ChecksumIEEE(s) fmt.Printf("%X\n", result) }
984CRC-32
0go
lgzcw
def crc32(byte[] bytes) { new java.util.zip.CRC32().with { update bytes; value } }
984CRC-32
7groovy
62i3o
int main() { FILE *fh = fopen(, ); fclose(fh); return 0; }
988Create a file
5c
gb645
def csv = [] def loadCsv = { source -> source.splitEachLine(/,/) { csv << it.collect { it } } } def saveCsv = { target -> target.withWriter { writer -> csv.each { writer.println it.join(',') } } } loadCsv new File('csv.txt') csv[0][0] = 'Column0' (1..4).each { i -> csv[i][i] = i * 100 } saveCsv new File('csv_out.txt')
983CSV data manipulation
7groovy
zcot5
Damm_algo <- function(number){ row_i = 0 iterable = strsplit(toString(number), "")[[1]] validation_matrix = matrix( c( 0, 3, 1, 7, 5, 9, 8, 6, 4, 2, 7, 0, 9, 2, 1, 5, 4, 8, 6, 3, 4, 2, 0, 6, 8, 7, 1, 3, 5, 9, 1, 7, 5, 0, 9, 8, 3, 4, 2, 6, 6, 1, 2, 3, 0, 4, 5, 9...
974Damm algorithm
13r
lr5ce
import datetime import math primes = [ 3, 5 ] cutOff = 200 bigUn = 100_000 chunks = 50 little = bigUn / chunks tn = print (.format(cutOff, tn)) c = 0 showEach = True u = 0 v = 1 st = datetime.datetime.now() for i in range(1, int(math.pow(2,20))): found = False u += 6 v += u mx = int(math.sqrt(v)) for item...
981Cuban primes
3python
dy8n1
-- March 7 2009 7:30pm EST SELECT TO_TIMESTAMP_TZ( 'March 7 2009 7:30pm EST', 'MONTH DD YYYY HH:MIAM TZR' ) at TIME zone 'US/Eastern' orig_dt_time FROM dual; -- 12 hours later DST change SELECT (TO_TIMESTAMP_TZ( 'March 7 2009 7:30pm EST', 'MONTH DD YYYY HH:MIAM TZR' )+ INTERVAL '12' HOUR) at TIME zone 'US/Eastern'...
970Date manipulation
19sql
gp14k
import Data.Bits ((.&.), complement, shiftR, xor) import Data.Word (Word32) import Numeric (showHex) crcTable :: Word32 -> Word32 crcTable = (table !!) . fromIntegral where table = ((!! 8) . iterate xf) <$> [0 .. 255] shifted x = shiftR x 1 xf r | r .&. 1 == 1 = xor (shifted r) 0xedb88320 | o...
984CRC-32
8haskell
1srps
typedef struct { uint64_t x[2]; } i128; void show(i128 v) { uint32_t x[4] = {v.x[0], v.x[0] >> 32, v.x[1], v.x[1] >> 32}; int i, j = 0, len = 4; char buf[100]; do { uint64_t c = 0; for (i = len; i--; ) { c = (c << 32) + x[i]; x[i] = c / 10, c %= 10; } buf[j++] = c + '0'; for (len = 4; !x[len - 1]...
989Count the coins
5c
2rnlo
Character,Speech The multitude,The messiah! Show us the messiah! Brians mother,<angry>Now you listen here! He's not the messiah The multitude,Who are you? Brians mother,I'm his mother The multitude,Behold his mother! Behold his mother!
987CSV to HTML translation
6clojure
719r0
import Data.Array (Array(..), (//), bounds, elems, listArray) import Data.List (intercalate) import Control.Monad (when) import Data.Maybe (isJust) delimiters :: String delimiters = ",;:" fields :: String -> [String] fields [] = [] fields xs = let (item, rest) = break (`elem` delimiters) xs (_, next) = break ...
983CSV data manipulation
8haskell
bxgk2
import Foundation let formatter = DateFormatter() formatter.dateFormat = "MMMM dd yyyy hh:mma zzz" guard let date = formatter.date(from: "March 7 2009 7:30pm EST") else { fatalError() } print(formatter.string(from: date)) print(formatter.string(from: date + 60 * 60 * 12))
970Date manipulation
17swift
94gmj
package main import ( "fmt" "math" ) func newRsdv() func(float64) float64 { var n, a, q float64 return func(x float64) float64 { n++ a1 := a+(x-a)/n q, a = q+(x-a)*(x-a1), a1 return math.Sqrt(q/n) } } func main() { r := newRsdv() for _, x := range []float6...
982Cumulative standard deviation
0go
71ur2
(import '(java.io File)) (.createNewFile (new File "output.txt")) (.mkdir (new File "docs")) (.createNewFile (File. (str (File/separator) "output.txt"))) (.mkdir (File. (str (File/separator) "docs")))
988Create a file
6clojure
kwlhs
List samples = [] def stdDev = { def sample -> samples << sample def sum = samples.sum() def sumSq = samples.sum { it * it } def count = samples.size() (sumSq/count - (sum/count)**2)**0.5 } [2,4,4,4,5,5,7,9].each { println "${stdDev(it)}" }
982Cumulative standard deviation
7groovy
uj9v9
import java.util.zip.* ; public class CRCMaker { public static void main( String[ ] args ) { String toBeEncoded = new String( "The quick brown fox jumps over the lazy dog" ) ; CRC32 myCRC = new CRC32( ) ; myCRC.update( toBeEncoded.getBytes( ) ) ; System.out.println( "The CRC-32 value is: " +...
984CRC-32
9java
712rj
package main import ( "fmt" "gonum.org/v1/gonum/mat" ) var m = mat.NewDense(4, 4, []float64{ 2, -1, 5, 1, 3, 2, 2, -6, 1, 3, 3, -1, 5, -2, -3, 3, }) var v = []float64{-3, -32, -47, 49} func main() { x := make([]float64, len(v)) b := make([]float64, len(v)) d := mat.Det(m) fo...
985Cramer's rule
0go
1sgp5
import java.io.*; import java.awt.Point; import java.util.HashMap; import java.util.Scanner; public class CSV { private HashMap<Point, String> _map = new HashMap<Point, String>(); private int _cols; private int _rows; public void open(File file) throws FileNotFoundException, IOException { ope...
983CSV data manipulation
9java
gbl4m
TABLE = [ [0,3,1,7,5,9,8,6,4,2], [7,0,9,2,1,5,4,8,6,3], [4,2,0,6,8,7,1,3,5,9], [1,7,5,0,9,8,3,4,2,6], [6,1,2,3,0,4,5,9,7,8], [3,6,7,4,2,0,9,5,8,1], [5,8,6,9,7,2,0,1,3,4], [8,9,4,5,3,6,2,0,1,7], [9,4,3,8,6,1,7,2,0,5], [2,5,8,1,4,3,6,7,9,0] ] def damm_valid?(n) = n.digits.reverse.inject(0){|idx, a| T...
974Damm algorithm
14ruby
gph4q
require RE = /(\d)(?=(\d\d\d)+(?!\d))/ cuban_primes = Enumerator.new do |y| (1..).each do |n| cand = 3*n*(n+1) + 1 y << cand if OpenSSL::BN.new(cand).prime? end end def commatize(num) num.to_s.gsub(RE, ) end cbs = cuban_primes.take(200) formatted = cbs.map{|cb| commatize(cb).rjust(10) } puts formatte...
981Cuban primes
14ruby
t9if2
import Data.List (foldl') import Data.STRef import Control.Monad.ST data Pair a b = Pair !a !b sumLen :: [Double] -> Pair Double Double sumLen = fiof2 . foldl' (\(Pair s l) x -> Pair (s+x) (l+1)) (Pair 0.0 0) where fiof2 (Pair s l) = Pair s (fromIntegral l) divl :: Pair Double Double -> Double divl (Pair _ 0.0) ...
982Cumulative standard deviation
8haskell
8tw0z
(() => { 'use strict';
984CRC-32
10javascript
pqgb7
(def denomination-kind [1 5 10 25]) (defn- cc [amount denominations] (cond (= amount 0) 1 (or (< amount 0) (empty? denominations)) 0 :else (+ (cc amount (rest denominations)) (cc (- amount (first denominations)) denominations)))) (defn count-change "Calculates the number of times ...
989Count the coins
6clojure
gb34f
class CramersRule { static void main(String[] args) { Matrix mat = new Matrix(Arrays.asList(2d, -1d, 5d, 1d), Arrays.asList(3d, 2d, 2d, -6d), Arrays.asList(1d, 3d, 3d, -1d), Arrays.asList(5d, -2d, -3d, 3d)) List<Double> b = Arrays.asList(-3d, -32d, -47...
985Cramer's rule
7groovy
ja27o
(function () { 'use strict';
983CSV data manipulation
10javascript
kw4hq
fn damm(number: &str) -> u8 { static TABLE: [[u8; 10]; 10] = [ [0, 3, 1, 7, 5, 9, 8, 6, 4, 2], [7, 0, 9, 2, 1, 5, 4, 8, 6, 3], [4, 2, 0, 6, 8, 7, 1, 3, 5, 9], [1, 7, 5, 0, 9, 8, 3, 4, 2, 6], [6, 1, 2, 3, 0, 4, 5, 9, 7, 8], [3, 6, 7, 4, 2, 0, 9, 5, 8, 1], [5, 8...
974Damm algorithm
15rust
r1kg5
import scala.annotation.tailrec object DammAlgorithm extends App { private val numbers = Seq(5724, 5727, 112946, 112949) @tailrec private def damm(s: String, interim: Int): String = { def table = Vector( Vector(0, 3, 1, 7, 5, 9, 8, 6, 4, 2), Vector(7, 0, 9, 2, 1, 5, 4, 8, 6, 3), ...
974Damm algorithm
16scala
hw1ja
use std::time::Instant; use separator::Separatable; const NUMBER_OF_CUBAN_PRIMES: usize = 200; const COLUMNS: usize = 10; const LAST_CUBAN_PRIME: usize = 100_000; fn main() { println!("Calculating the first {} cuban primes and the {}th cuban prime...", NUMBER_OF_CUBAN_PRIMES, LAST_CUBAN_PRIME); let start = In...
981Cuban primes
15rust
zcnto
import spire.math.SafeLong import spire.implicits._ import scala.annotation.tailrec import scala.collection.parallel.immutable.ParVector object CubanPrimes { def main(args: Array[String]): Unit = { println(formatTable(cubanPrimes.take(200).toVector, 10)) println(f"The 100,000th cuban prime is: ${getNthCuban...
981Cuban primes
16scala
yvt63
int main() { int i; printf(text-align:center; border: 1px solid\ ); for (i = 0; i < 4; i++) { printf(, i, rand() % 10000, rand() % 10000, rand() % 10000); } printf(); return 0; }
990Create an HTML table
5c
n6bi6
import Data.Matrix solveCramer :: (Ord a, Fractional a) => Matrix a -> Matrix a -> Maybe [a] solveCramer a y | da == 0 = Nothing | otherwise = Just $ map (\i -> d i / da) [1..n] where da = detLU a d i = detLU $ submatrix 1 n 1 n $ switchCols i (n+1) ay ay = a <|> y n = ncols a task = sol...
985Cramer's rule
8haskell
t9sf7
null
984CRC-32
11kotlin
ujyvc
import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class CramersRule { public static void main(String[] args) { Matrix mat = new Matrix(Arrays.asList(2d, -1d, 5d, 1d), Arrays.asList(3d, 2d, 2d, -6d), Arrays.a...
985Cramer's rule
9java
8t106
null
983CSV data manipulation
11kotlin
2r6li
local compute=require"zlib".crc32() local sum=compute("The quick brown fox jumps over the lazy dog") print(string.format("0x%x", sum))
984CRC-32
1lua
5hmu6
typedef unsigned long long ULONG; ULONG get_prime(int idx) { static long n_primes = 0, alloc = 0; static ULONG *primes = 0; ULONG last, p; int i; if (idx >= n_primes) { if (n_primes >= alloc) { alloc += 16; primes...
991Count in factors
5c
ja670
var matrix = [ [2, -1, 5, 1], [3, 2, 2, -6], [1, 3, 3, -1], [5, -2, -3, 3] ]; var freeTerms = [-3, -32, -47, 49]; var result = cramersRule(matrix,freeTerms); console.log(result); function cramersRule(matrix,freeTerms) { var det = detr(matrix), returnArray = [], i, tmpMatrix; for(i=0; i < matrix[0...
985Cramer's rule
10javascript
fmqdg
local csv={} for line in io.lines('file.csv') do table.insert(csv, {}) local i=1 for j=1,#line do if line:sub(j,j) == ',' then table.insert(csv[#csv], line:sub(i,j-1)) i=j+1 end end table.insert(csv[#csv], line:sub(i,j)) end table.insert(csv[1], 'SUM') for i=...
983CSV data manipulation
1lua
v7y2x
use Time::Local; use strict; foreach my $i (2008 .. 2121) { my $time = timelocal(0,0,0,25,11,$i); my ($s,$m,$h,$md,$mon,$y,$wd,$yd,$is) = localtime($time); if ( $wd == 0 ) { print "25 Dec $i is Sunday\n"; } } exit 0;
971Day of the week
2perl
4bb5d
int match(const char *s, const char *p, int overlap) { int c = 0, l = strlen(p); while (*s != '\0') { if (strncmp(s++, p, l)) continue; if (!overlap) s += l - 1; c++; } return c; } int main() { printf(, match(, , 0)); prin...
992Count occurrences of a substring
5c
a0l11
(ns rosettacode.html-table (:use 'hiccup.core)) (defn <tr> [el sq] [:tr (map vector (cycle [el]) sq)]) (html [:table (<tr>:th ["" \X \Y \Z]) (for [n (range 1 4)] (->> #(rand-int 10000) (repeatedly 3) (cons n) (<tr>:td)))])
990Create an HTML table
6clojure
3lwzr
<?php for($i=2008; $i<2121; $i++) { $datetime = new DateTime(); if ( $datetime->format() == 0 ) { echo ; } } ?>
971Day of the week
12php
i66ov
var cache = new Map(); main() { var stopwatch = new Stopwatch()..start();
989Count the coins
18dart
62q34
int main() { unsigned int i = 0; do { printf(, i++); } while(i); return 0; }
993Count in octal
5c
i37o2
null
985Cramer's rule
11kotlin
wojek
public class StdDev { int n = 0; double sum = 0; double sum2 = 0; public double sd(double x) { n++; sum += x; sum2 += x*x; return Math.sqrt(sum2/n - sum*sum/n/n); } public static void main(String[] args) { double[] testData = {2,4,4,4,5,5,7,9}; StdDev sd = new StdDev(); ...
982Cumulative standard deviation
9java
e8ka5
(defn re-quote "Produces a string that can be used to create a Pattern that would match the string text as if it were a literal pattern. Metacharacters or escape sequences in text will be given no special meaning" [text] (java.util.regex.Pattern/quote text)) (defn count-substring [txt sub] (count (re-...
992Count occurrences of a substring
6clojure
sd4qr
(doseq [i (range)] (println (format "%o" i)))
993Count in octal
6clojure
zcptj
(ns listfactors (:gen-class)) (defn factors "Return a list of factors of N." ([n] (factors n 2 ())) ([n k acc] (cond (= n 1) (if (empty? acc) [n] (sort acc)) (>= k n) (if (empty? acc) [n] (sort (cons n acc))) (= 0 (rem n ...
991Count in factors
6clojure
1slpy
use POSIX; print strftime('%Y-%m-%d', 0, 0, 0, 10, 10, 107), "\n"; print strftime('%A,%B%d,%Y', 0, 0, 0, 10, 10, 107), "\n";
977Date format
2perl
cgl9a
local matrix = require "matrix"
985Cramer's rule
1lua
xihwz
function running_stddev() { var n = 0; var sum = 0.0; var sum_sq = 0.0; return function(num) { n++; sum += num; sum_sq += num*num; return Math.sqrt( (sum_sq / n) - Math.pow(sum / n, 2) ); } } var sd = running_stddev(); var nums = [2,4,4,4,5,5,7,9]; var stddev = []; f...
982Cumulative standard deviation
10javascript
0fesz
<?php echo date('Y-m-d', time()).; echo date('l, F j, Y', time()).; ?>
977Date format
12php
xnqw5
package main import "fmt" func main() { var row, col int fmt.Print("enter rows cols: ") fmt.Scan(&row, &col)
986Create a two-dimensional array at runtime
0go
sdkqa
from calendar import weekday, SUNDAY [year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]
971Day of the week
3python
gpp4h
def make2d = { nrows, ncols -> (0..<nrows).collect { [0]*ncols } }
986Create a two-dimensional array at runtime
7groovy
a0g1p
import Data.Array doit n m = a!(0,0) where a = array ((0,0),(n,m)) [((0,0),42)]
986Create a two-dimensional array at runtime
8haskell
95nmo
use Math::Matrix; sub cramers_rule { my ($A, $terms) = @_; my @solutions; my $det = $A->determinant; foreach my $i (0 .. $ my $Ai = $A->clone; foreach my $j (0 .. $ $Ai->[$j][$i] = $terms->[$j]; } push @solutions, $Ai->determinant / $det; } @solutions...
985Cramer's rule
2perl
lgtc5
years <- 2008:2121 xmas <- as.POSIXlt(paste0(years, '/12/25')) years[xmas$wday==0] xmas=seq(as.Date("2008/12/25"), as.Date("2121/12/25"), by="year") as.numeric(format(xmas[weekdays(xmas)== 'Sunday'], "%Y")) with(list(years=2008:2121), years[weekdays(ISOdate(years, 12, 25)) == "Sunday"]) subset(data.frame(years=2...
971Day of the week
13r
vjj27
null
982Cumulative standard deviation
11kotlin
kwgh3
use 5.010 ; use strict ; use warnings ; use Digest::CRC qw( crc32 ) ; my $crc = Digest::CRC->new( type => "crc32" ) ; $crc->add ( "The quick brown fox jumps over the lazy dog" ) ; say "The checksum is " . $crc->hexdigest( ) ;
984CRC-32
2perl
8ta0w