code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
findCullen :: Int -> Integer findCullen n = toInteger ( n * 2 ^ n + 1 ) cullens :: [Integer] cullens = map findCullen [1 .. 20] woodalls :: [Integer] woodalls = map (\i -> i - 2 ) cullens main :: IO ( ) main = do putStrLn "First 20 Cullen numbers:" print cullens putStrLn "First 20 Woodall numbers:" print...
976Cullen and Woodall numbers
8haskell
nyfie
function T(t) return setmetatable(t, {__index=table}) end table.range = function(t,n) local s=T{} for i=1,n do s[i]=i end return s end table.map = function(t,f) local s=T{} for i=1,#t do s[i]=f(t[i]) end return s end function cullen(n) return (n<<n)+1 end print("First 20 Cullen numbers:") print(T{}:range(20):map(culle...
976Cullen and Woodall numbers
1lua
a8w1v
(def 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 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]]...
974Damm algorithm
6clojure
5k7uz
(def plus-a-hundred (partial + 100)) (assert (= (plus-a-hundred 1) 101))
975Currying
6clojure
4b75o
function array1D(w, d) local t = {} for i=1,w do table.insert(t, d) end return t end function array2D(h, w, d) local t = {} for i=1,h do table.insert(t, array1D(w, d)) end return t end function push(s, v) s[#s + 1] = v end function pop(s) return table.remove(s,...
968Cut a rectangle
1lua
jeq71
int main(void) { char buf[MAX_BUF]; time_t seconds = time(NULL); struct tm *now = localtime(&seconds); const char *months[] = {, , , , , , , , , , , }; const char *days[] = {, , , ,,,}; (void) printf(, now->tm_year + 1900, now->tm_mon + 1, now->tm_mday); (void) printf(,days[now...
977Date format
5c
6vy32
use strict; use warnings; use bigint; use ntheory 'is_prime'; use constant Inf => 1e10; sub cullen { my($n,$c) = @_; ($n * 2**$n) + $c; } my($m,$n); ($m,$n) = (20,0); print "First $m Cullen numbers:\n"; print do { $n < $m ? (++$n and cullen($_,1) . ' ') : last } for 1 .. Inf; ($m,$n) = (20,0); print "\n\nF...
976Cullen and Woodall numbers
2perl
m5cyz
import java.util.TreeMap import kotlin.math.abs import kotlin.math.pow import kotlin.math.sqrt private const val algorithm = 2 fun main() { println("Task 1: cyclotomic polynomials for n <= 30:") for (i in 1..30) { val p = cyclotomicPolynomial(i) println("CP[$i] = $p") } println() ...
972Cyclotomic polynomial
11kotlin
945mh
use strict; use warnings; my @grid = 0; my ($w, $h, $len); my $cnt = 0; my @next; my @dir = ([0, -1], [-1, 0], [0, 1], [1, 0]); sub walk { my ($y, $x) = @_; if (!$y || $y == $h || !$x || $x == $w) { $cnt += 2; return; } my $t = $y * ($w + 1) + $x; $grid[$_]++ for $t, $len - $t; for my $i...
968Cut a rectangle
2perl
f92d7
package main import ( "fmt" "time" ) const taskDate = "March 7 2009 7:30pm EST" const taskFormat = "January 2 2006 3:04pm MST" func main() { if etz, err := time.LoadLocation("US/Eastern"); err == nil { time.Local = etz } fmt.Println("Input: ", taskDate) t, err := time.Pars...
970Date manipulation
0go
hwxjq
begin games = ARGV.map {|s| Integer(s)} rescue => err $stderr.puts err.inspect $stderr.puts abort end games.empty? and games = [rand(32000)] orig_deck = %w{A 2 3 4 5 6 7 8 9 T J Q K}.product(%w{C D H S}).map(&:join) games.each do |seed| deck = orig_deck.dup state = seed 52.downto(2) do |len| ...
964Deal cards for FreeCell
14ruby
27alw
(let [now (.getTime (java.util.Calendar/getInstance)) f1 (java.text.SimpleDateFormat. "yyyy-MM-dd") f2 (java.text.SimpleDateFormat. "EEEE, MMMM dd, yyyy")] (println (.format f1 now)) (println (.format f2 now)))
977Date format
6clojure
lr2cb
print() print() for n in range(1,20): num = n*pow(2,n)+1 print(str(num),end= ) print() print() for n in range(1,20): num = n*pow(2,n)-1 print(str(num),end=) print() print()
976Cullen and Woodall numbers
3python
94lmf
import org.joda.time.* import java.text.* def dateString = 'March 7 2009 7:30pm EST' def sdf = new SimpleDateFormat('MMMM d yyyy h:mma zzz') DateTime dt = new DateTime(sdf.parse(dateString)) println (dt) println (dt.plusHours(12)) println (dt.plusHours(12).withZone(DateTimeZone.UTC))
970Date manipulation
7groovy
4bp5f
import qualified Data.Time.Clock.POSIX as P import qualified Data.Time.Format as F main :: IO () main = print t2 where t1 = F.parseTimeOrError True F.defaultTimeLocale "%B%e%Y%l:%M%P%Z" "March 7 2009 7:30pm EST" t2 = P.posixSecondsToUTCTime $ 12 * 60 * 60 + P.utcTimeToP...
970Date manipulation
8haskell
i6yor
null
964Deal cards for FreeCell
15rust
vje2t
null
976Cullen and Woodall numbers
15rust
27ult
Floating point number or Float for short, is an arbitrary precision mantissa with a limited precision exponent. The C data type for such objects is mpf_t. For example: mpf_t fp;
978Currency
5c
lrlcy
int main() { int intspace; int *address; address = &intspace; *address = 65535; printf(, address, *address, intspace); *((char*)address) = 0x00; *((char*)address+1) = 0x00; *((char*)address+2) = 0xff; *((char*)address+3) = 0xff; printf(, address, *address, intspace); return 0; }
979Create an object at a given address
5c
71grg
def cut_it(h, w): dirs = ((1, 0), (-1, 0), (0, -1), (0, 1)) if h% 2: h, w = w, h if h% 2: return 0 if w == 1: return 1 count = 0 next = [w + 1, -w - 1, -1, 1] blen = (h + 1) * (w + 1) - 1 grid = [False] * (blen + 1) def walk(y, x, count): if not y or y == h or not x or x ==...
968Cut a rectangle
3python
tcvfw
object Shuffler extends App { private val suits = Array("C", "D", "H", "S") private val values = Array("A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K") private val deck = values.flatMap(v => suits.map(s => s"$v$s")) private var seed: Int = _ private def random() = { seed = (214013 * see...
964Deal cards for FreeCell
16scala
4bq50
(require '[clojurewerkz.money.amounts :as ma]) (require '[clojurewerkz.money.currencies:as mc]) (require '[clojurewerkz.money.format :as mf]) (let [burgers (ma/multiply (ma/amount-of mc/USD 5.50) 4000000000000000) milkshakes (ma/multiply (ma/amount-of mc/USD 2.86) 2) pre-tax (ma/plus burgers milkshak...
978Currency
6clojure
4b45o
enum Suit: String, CustomStringConvertible, CaseIterable { case clubs = "C", diamonds = "D", hearts = "H", spades = "S" var description: String { return self.rawValue } } enum Rank: Int, CustomStringConvertible, CaseIterable { case ace=1, two, three, four, five, six, seven case eight, nine, ...
964Deal cards for FreeCell
17swift
lr1c2
use feature 'say'; use List::Util qw(first); use Math::Polynomial::Cyclotomic qw(cyclo_poly_iterate); say 'First 30 cyclotomic polynomials:'; my $it = cyclo_poly_iterate(1); say "$_: " . $it->() for 1 .. 30; say "\nSmallest cyclotomic polynomial with n or -n as a coefficient:"; $it = cyclo_poly_iterate(1); for (my (...
972Cyclotomic polynomial
2perl
wioe6
import java.time.*; import java.time.format.*; class Main { public static void main(String args[]) { String dateStr = "March 7 2009 7:30pm EST"; DateTimeFormatter df = new DateTimeFormatterBuilder() .parseCaseInsensitive() .appendPattern("MMMM d yyyy h:mma zzz") .toFormatter(); ZonedDate...
970Date manipulation
9java
xndwy
package main import "fmt" func isCusip(s string) bool { if len(s) != 9 { return false } sum := 0 for i := 0; i < 8; i++ { c := s[i] var v int switch { case c >= '0' && c <= '9': v = int(c) - 48 case c >= 'A' && c <= 'Z': v = i...
973CUSIP
0go
cg59g
package main import( "fmt" "unsafe" "reflect" ) func pointer() { fmt.Printf("Pointer:\n")
979Create an object at a given address
0go
dyine
function add12hours(dateString) {
970Date manipulation
10javascript
o3686
class Cusip { private static Boolean isCusip(String s) { if (s.length() != 9) return false int sum = 0 for (int i = 0; i <= 7; i++) { char c = s.charAt(i) int v if (c >= ('0' as char) && c <= ('9' as char)) { v = c - 48 } else ...
973CUSIP
7groovy
32czd
int main() { FILE* fp = fopen(,); fprintf(fp,); fprintf(fp,); fprintf(fp,); fprintf(fp,); fprintf(fp,); fprintf(fp,); fprintf(fp,); fprintf(fp,); fclose(fp); return 0; }
980Create a file on magnetic tape
5c
fmid3
(spit "/dev/tape" "Hello, World!")
980Create a file on magnetic tape
6clojure
yvz6b
package main import ( "fmt" "log" "math/big" )
978Currency
0go
xnxwf
package main import ( "fmt" "math" ) func PowN(b float64) func(float64) float64 { return func(e float64) float64 { return math.Pow(b, e) } } func PowE(e float64) func(float64) float64 { return func(b float64) float64 { return math.Pow(b, e) } } type Foo int func (f Foo) Method(b int...
975Currying
0go
xn0wf
null
979Create an object at a given address
11kotlin
zcfts
local a = {10} local b = a print ("address a:"..tostring(a), "value a:"..a[1]) print ("address b:"..tostring(b), "value b:"..b[1]) b[1] = 42 print ("address a:"..tostring(a), "value a:"..a[1]) print ("address b:"..tostring(b), "value b:"..b[1])
979Create an object at a given address
1lua
3ltzo
from itertools import count, chain from collections import deque def primes(_cache=[2, 3]): yield from _cache for n in count(_cache[-1]+2, 2): if isprime(n): _cache.append(n) yield n def isprime(n): for p in primes(): if n%p == 0: return False if...
972Cyclotomic polynomial
3python
xniwr
def cut_it(h, w) if h.odd? return 0 if w.odd? h, w = w, h end return 1 if w == 1 nxt = [[w+1, 1, 0], [-w-1, -1, 0], [-1, 0, -1], [1, 0, 1]] blen = (h + 1) * (w + 1) - 1 grid = [false] * (blen + 1) walk = lambda do |y, x, count=0| return count+1 if y==0 or y==h or x==0 or x==w t = y ...
968Cut a rectangle
14ruby
325z7
import Data.List(elemIndex) data Result = Valid | BadCheck | TooLong | TooShort | InvalidContent deriving Show allMaybe :: [Maybe a] -> Maybe [a] allMaybe = sequence toValue :: Char -> Maybe Int toValue c = elemIndex c $ ['0'..'9'] ++ ['A'..'Z'] ++ "*@#" valid :: [Int] -> Bool valid ns0 = let ns1 ...
973CUSIP
8haskell
psxbt
package main import "fmt" var table = [10][10]byte{ {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, ...
974Damm algorithm
0go
wi0eg
import Data.Fixed import Text.Printf type Percent = Centi type Dollars = Centi tax :: Percent -> Dollars -> Dollars tax rate = MkFixed . round . (rate *) printAmount :: String -> Dollars -> IO () printAmount name = printf "%-10s%20s\n" name . showFixed False main :: IO () main = do let subtotal = 4000000000000000...
978Currency
8haskell
yuy66
def divide = { Number x, Number y -> x / y } def partsOf120 = divide.curry(120) println "120: half: ${partsOf120(2)}, third: ${partsOf120(3)}, quarter: ${partsOf120(4)}"
975Currying
7groovy
psebo
\ ->
975Currying
8haskell
yuc66
use strict; use warnings; print "Here is an integer : ", my $target = 42, "\n"; print "And its reference is : ", my $targetref = \$target, "\n"; print "Now assigns a new value to it : ", $$targetref = 69, "\n"; print "Then compare with the referent: ", $target, "\n";
979Create an object at a given address
2perl
bxhk4
fn cwalk(mut vis: &mut Vec<Vec<bool>>, count: &mut isize, w: usize, h: usize, y: usize, x: usize, d: usize) { if x == 0 || y == 0 || x == w || y == h { *count += 1; return; } vis[y][x] = true; vis[h - y][w - x] = true; if x!= 0 &&! vis[y][x - 1] { cwalk(&mut vis, count, w, ...
968Cut a rectangle
15rust
6v43l
null
970Date manipulation
11kotlin
ps0b6
class DammAlgorithm { private static final int[][] 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, ...
974Damm algorithm
7groovy
bqeky
typedef long long llong_t; struct PrimeArray { llong_t *ptr; size_t size; size_t capacity; }; struct PrimeArray allocate() { struct PrimeArray primes; primes.size = 0; primes.capacity = 10; primes.ptr = malloc(primes.capacity * sizeof(llong_t)); return primes; } void deallocate(struc...
981Cuban primes
5c
0fwst
package main import ( "archive/tar" "compress/gzip" "flag" "io" "log" "os" "time" ) func main() { filename := flag.String("file", "TAPE.FILE", "filename within TAR") data := flag.String("data", "", "data for file") outfile := flag.String(...
980Create a file on magnetic tape
0go
jag7d
import java.math.*; import java.util.*; public class Currency { final static String taxrate = "7.65"; enum MenuItem { Hamburger("5.50"), Milkshake("2.86"); private MenuItem(String p) { price = new BigDecimal(p); } public final BigDecimal price; } public ...
978Currency
9java
dmdn9
import java.util.List; public class Cusip { private static Boolean isCusip(String s) { if (s.length() != 9) return false; int sum = 0; for (int i = 0; i <= 7; i++) { char c = s.charAt(i); int v; if (c >= '0' && c <= '9') { v = c - 48; ...
973CUSIP
9java
r1bg0
typedef enum Action { STDDEV, MEAN, VAR, COUNT } Action; typedef struct stat_obj_struct { double sum, sum2; size_t num; Action action; } sStatObject, *StatObject; StatObject NewStatObject( Action action ) { StatObject so; so = malloc(sizeof(sStatObject)); so->sum = 0.0; so->sum2 = 0.0; so->num = ...
982Cumulative standard deviation
5c
dy0nv
typedef struct { char * delim; unsigned int rows; unsigned int cols; char ** table; } CSV; int trim(char ** str) { int trimmed; int n; int len; len = strlen(*str); n = len - 1; while((n>=0) && isspace((*str)[n])) { (*str)[n] = '\0'; trimmed += 1; n--; } n = 0; while((n < len) && (isspace((*...
983CSV data manipulation
5c
e8hav
import Data.Char (digitToInt) import Text.Printf (printf) damm :: String -> Bool damm = (==0) . foldl (\r -> (table !! r !!) . digitToInt) 0 where 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] ...
974Damm algorithm
8haskell
6vc3k
import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths class CreateFile { static void main(String[] args) throws IOException { String os = System.getProperty("os.name") if (os.contains("Windows")) { Path path = Paths.get("tape.file") Files.write(path...
980Create a file on magnetic tape
7groovy
5h2uv
module Main (main) where main :: IO () main = writeFile "/dev/tape" "Hello from Rosetta Code!"
980Create a file on magnetic tape
8haskell
ozs8p
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; public class CreateFile { public static void main(String[] args) throws IOException { String os = System.getProperty("os.name"); if (os.contains("Windows")) {...
980Create a file on magnetic tape
9java
wo1ej
const money = require('money-math') let hamburgers = 4000000000000000 let hamburgerPrice = 5.50 let shakes = 2 ...
978Currency
10javascript
6v638
str = string.lower( "March 7 2009 7:30pm EST" ) month = string.match( str, "%a+" ) if month == "january" then month = 1 elseif month == "february" then month = 2 elseif month == "march" then month = 3 elseif month == "april" then month = 4 elseif month == "may" then month = 5 elseif month == "jun...
970Date manipulation
1lua
108po
(() => { 'use strict';
973CUSIP
10javascript
bqwki
null
980Create a file on magnetic tape
11kotlin
bxjkb
require "lfs" local out if lfs.attributes('/dev/tape') then out = '/dev/tape' else out = 'tape.file' end file = io.open(out, 'w') file:write('Hello world') io.close(file)
980Create a file on magnetic tape
1lua
pqhbw
null
978Currency
11kotlin
0t0sf
public class Currier<ARG1, ARG2, RET> { public interface CurriableFunctor<ARG1, ARG2, RET> { RET evaluate(ARG1 arg1, ARG2 arg2); } public interface CurriedFunctor<ARG2, RET> { RET evaluate(ARG2 arg); } final CurriableFunctor<ARG1, ARG2, RET> functor; ...
975Currying
9java
dmzn9
use std::{mem,ptr}; fn main() { let mut data: i32;
979Create an object at a given address
15rust
e81aj
package require critcl # A command to 'make an integer object' and couple it to a Tcl variable critcl::cproc linkvar {Tcl_Interp* interp char* var1} int { int *intPtr = (int *) ckalloc(sizeof(int)); *intPtr = 0; Tcl_LinkVar(interp, var1, (void *) intPtr, TCL_LINK_INT); return (int) intPtr; } # A comm...
979Create an object at a given address
16scala
qnwxw
package main import "fmt" import "time" func main() { for year := 2008; year <= 2121; year++ { if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() == time.Sunday { fmt.Printf("25 December%d is Sunday\n", year) } } }
971Day of the week
0go
qddxz
null
973CUSIP
11kotlin
vjr21
public class DammAlgorithm { private static final int[][] 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}, ...
974Damm algorithm
9java
nyzih
>>> with open('/dev/tape', 'w') as t: t.write('Hi Tape!\n') ... >>>
980Create a file on magnetic tape
3python
yvz6q
C = setmetatable(require("bc"), {__call=function(t,...) return t.new(...) end}) C.digits(6)
978Currency
1lua
8z80e
function addN(n) { var curry = function(x) { return x + n; }; return curry; } add2 = addN(2); alert(add2); alert(add2(7));
975Currying
10javascript
6v938
def yuletide = { start, stop -> (start..stop).findAll { Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "Sun" } }
971Day of the week
7groovy
100p6
import Data.Time (fromGregorian) import Data.Time.Calendar.WeekDate (toWeekDate) isXmasSunday :: Integer -> Bool isXmasSunday year = 7 == weekDay where (_, _, weekDay) = toWeekDate $ fromGregorian year 12 25 main :: IO () main = mapM_ putStrLn [ "Sunday 25 December " <> show year | year <- [...
971Day of the week
8haskell
m55yf
function checkDigit (cusip) if #cusip ~= 8 then return false end local sum, c, v, p = 0 for i = 1, 8 do c = cusip:sub(i, i) if c:match("%d") then v = tonumber(c) elseif c:match("%a") then p = string.byte(c) - 55 v = p + 9 elseif c == "*" then v = 36 elseif c == "@" the...
973CUSIP
1lua
uh7vl
(defn stateful-std-deviation[x] (letfn [(std-dev[x] (let [v (deref (find-var (symbol (str *ns* "/v"))))] (swap! v conj x) (let [m (/ (reduce + @v) (count @v))] (Math/sqrt (/ (reduce + (map #(* (- m %) (- m %)) @v)) (count @v))))))] (when (nil? (resolve 'v)) ...
982Cumulative standard deviation
6clojure
62d3q
(require '[clojure.data.csv:as csv] '[clojure.java.io:as io]) (defn add-sum-column [coll] (let [titles (first coll) values (rest coll)] (cons (conj titles "SUM") (map #(conj % (reduce + (map read-string %))) values)))) (with-open [in-file (io/reader "test_in.csv")] (doall (let [ou...
983CSV data manipulation
6clojure
0fasj
const 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,...
974Damm algorithm
10javascript
329z0
File.open(, ) do |fh| fh.syswrite() end
980Create a file on magnetic tape
14ruby
956mz
use std::io::Write; use std::fs::File; fn main() -> std::io::Result<()> { File::open("/dev/tape")?.write_all(b"Hello from Rosetta Code!") }
980Create a file on magnetic tape
15rust
c4y9z
object LinePrinter extends App { import java.io.{ FileWriter, IOException } { val lp0 = new FileWriter("/dev/tape") lp0.write("Hello, world!") lp0.close() } }
980Create a file on magnetic tape
16scala
v7c2s
null
975Currying
11kotlin
0tisf
use Math::Decimal qw(dec_canonise dec_add dec_mul dec_rndiv_and_rem); @check = ( [<Hamburger 5.50 4000000000000000>], [<Milkshake 2.86 2>] ); my $fmt = "%-10s%8s%18s%22s\n"; printf $fmt, <Item Price Quantity Extension>; my $subtotal = dec_canonise(0); for $line (@check) { ($item,$price,$qu...
978Currency
2perl
5k5u2
null
974Damm algorithm
11kotlin
sfiq7
use DateTime; use DateTime::Format::Strptime 'strptime'; use feature 'say'; my $input = 'March 7 2009 7:30pm EST'; $input =~ s{EST}{America/New_York}; say strptime('%b%d%Y%I:%M%p%O', $input) ->add(hours => 12) ->set_time_zone('America/Edmonton') ->format_cldr('MMMM d yyyy h:mma zzz');
970Date manipulation
2perl
yu56u
import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Yuletide{ public static void main(String[] args) { for(int i = 2008;i<=2121;i++){ Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER, 25); if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){ Syst...
971Day of the week
9java
f99dv
local tab = { {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} } function check( n ) local idx, a = 0, tonumber( n:s...
974Damm algorithm
1lua
0tnsd
from decimal import Decimal as D from collections import namedtuple Item = namedtuple('Item', 'price, quant') items = dict( hamburger=Item(D('5.50'), D('4000000000000000')), milkshake=Item(D('2.86'), D('2')) ) tax_rate = D('0.0765') fmt = print(fmt% tuple('Item Price Quantity Extension'.upper().split(...
978Currency
3python
4b45k
function curry2(f) return function(x) return function(y) return f(x,y) end end end function add(x,y) return x+y end local adder = curry2(add) assert(adder(3)(4) == 3+4) local add2 = adder(2) assert(add2(3) == 2+3) assert(add2(5) == 2+5)
975Currying
1lua
8zn0e
<?php $time = new DateTime('March 7 2009 7:30pm EST'); $time->modify('+12 hours'); echo $time->format('c'); ?>
970Date manipulation
12php
a8o12
for (var year = 2008; year <= 2121; year++){ var xmas = new Date(year, 11, 25) if ( xmas.getDay() === 0 ) console.log(year) }
971Day of the week
10javascript
yuu6r
$cv{$_} = $i++ for '0'..'9', 'A'..'Z', '*', '@', ' sub cusip_check_digit { my @cusip = split m{}xms, shift; my $sum = 0; for $i (0..7) { return 'Invalid character found' unless $cusip[$i] =~ m{\A [[:digit:][:upper:]*@ $v = $cv{ $cusip[$i] }; $v *= 2 if $i%2; $sum += int($v...
973CUSIP
2perl
0tds4
int main() { const char *s = ; printf(, crc32(0, (const void*)s, strlen(s))); return 0; }
984CRC-32
5c
xikwu
package main import "time" import "fmt" func main() { fmt.Println(time.Now().Format("2006-01-02")) fmt.Println(time.Now().Format("Monday, January 2, 2006")) }
977Date format
0go
ps1bg
def isoFormat = { date -> date.format("yyyy-MM-dd") } def longFormat = { date -> date.format("EEEE, MMMM dd, yyyy") }
977Date format
7groovy
7ajrz
package main import ( "fmt" "math/big" ) func commatize(n uint64) string { s := fmt.Sprintf("%d", n) le := len(s) for i := le - 3; i >= 1; i -= 3 { s = s[0:i] + "," + s[i:] } return s } func main() { var z big.Int var cube1, cube2, cube100k, diff uint64 cubans := make(...
981Cuban primes
0go
ujcvt
import Data.Time (FormatTime, formatTime, defaultTimeLocale, utcToLocalTime, getCurrentTimeZone, getCurrentTime) formats :: FormatTime t => [t -> String] formats = (formatTime defaultTimeLocale) <$> ["%F", "%A,%B%d,%Y"] main :: IO () main = do t <- pure utcToLocalTime <*> getCurrentTimeZone <*> getC...
977Date format
8haskell
f9td1
class CubanPrimes { private static int MAX = 1_400_000 private static boolean[] primes = new boolean[MAX] static void main(String[] args) { preCompute() cubanPrime(200, true) for (int i = 1; i <= 5; i++) { int max = (int) Math.pow(10, i) printf("%,d-th cuban ...
981Cuban primes
7groovy
953m4
null
971Day of the week
11kotlin
8zz0q
function IsCusip(string $s) { if (strlen($s) != 9) return false; $sum = 0; for ($i = 0; $i <= 7; $i++) { $c = $s[$i]; if (ctype_digit($c)) { $v = intval($c); } elseif (ctype_alpha($c)) { $position = ord(strtoupper($c)) - ord('A') + 1;...
973CUSIP
12php
5kjus
(let [crc (new java.util.zip.CRC32) str "The quick brown fox jumps over the lazy dog"] (. crc update (. str getBytes)) (printf "CRC-32('%s') =%s\n" str (Long/toHexString (. crc getValue))))
984CRC-32
6clojure
oze8j