code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
<?php function a() { static $i = 0; print ++$i . ; a(); } a();
841Find limit of recursion
12php
qzax3
int turn(int base, int n) { int sum = 0; while (n != 0) { int rem = n % base; n = n / base; sum += rem; } return sum % base; } void fairshare(int base, int count) { int i; printf(, base); for (i = 0; i < count; i++) { int t = turn(base, i); printf(, ...
856Fairshare between two and more
5c
35kza
max_it = 13 max_it_j = 10 a1 = 1.0 a2 = 0.0 d1 = 3.2 a = 0.0 print for i in range(2, max_it + 1): a = a1 + (a1 - a2) / d1 for j in range(1, max_it_j + 1): x = 0.0 y = 0.0 for k in range(1, (1 << i) + 1): y = 1.0 - 2.0 * y * x x = a - x * x a = a - x / y ...
848Feigenbaum constant calculation
3python
s3jq9
fn main() { let exts = ["zip", "rar", "7z", "gz", "archive", "A##", "tar.bz2"]; let filenames = [ "MyData.a##", "MyData.tar.Gz", "MyData.gzip", "MyData.7z.backup", "MyData...", "MyData", "MyData_v1.0.tar.bz2", "MyData_v1.0.bz2", ]; println...
847File extension is in extensions list
15rust
wfre4
def isExt(fileName: String, extensions: List[String]): Boolean = { extensions.map { _.toLowerCase }.exists { fileName.toLowerCase endsWith "." + _ } }
847File extension is in extensions list
16scala
s3hqo
file.info(filename)$mtime shell("copy /b /v filename +,,>nul") shell("touch -m filename")
844File modification time
13r
rwlgj
package main import "fmt" func main() { for i := 1; i <= 100; i++ { switch { case i%15==0: fmt.Println("FizzBuzz") case i%3==0: fmt.Println("Fizz") case i%5==0: fmt.Println("Buzz") default: fmt.Println(i) } } }
835FizzBuzz
0go
d2zne
package main import ( "fmt" "math" )
851Fibonacci word
0go
edva6
package main import ( "bufio" "fmt" "os" ) func main() { f, err := os.Open("rc.fasta") if err != nil { fmt.Println(err) return } defer f.Close() s := bufio.NewScanner(f) headerFound := false for s.Scan() { ...
854FASTA format
0go
8y40g
void farey(int n) { typedef struct { int d, n; } frac; frac f1 = {0, 1}, f2 = {1, n}, t; int k; printf(, 0, 1, 1, n); while (f2.n > 1) { k = (n + f1.n) / f2.n; t = f1, f1 = f2, f2 = (frac) { f2.d * k - t.d, f2.n * k - t.n }; printf(, f2.d, f2.n); } putchar('\n'); } typedef unsigned long long ull; ull *c...
857Farey sequence
5c
rwog7
import sys print(sys.getrecursionlimit())
841Find limit of recursion
3python
2kmlz
module Main where import Control.Monad import Data.List import Data.Monoid import Text.Printf entropy :: (Ord a) => [a] -> Double entropy = sum . map (\c -> (c *) . logBase 2 $ 1.0 / c) . (\cs -> let { sc = sum cs } in map (/ sc) cs) . map (fromIntegral . length) . group . sort...
851Fibonacci word
8haskell
35ezj
import Data.List ( groupBy ) parseFasta :: FilePath -> IO () parseFasta fileName = do file <- readFile fileName let pairedFasta = readFasta $ lines file mapM_ (\(name, code) -> putStrLn $ name ++ ": " ++ code) pairedFasta readFasta :: [String] -> [(String, String)] readFasta = pair . map concat . groupBy (\x y ...
854FASTA format
8haskell
lhqch
package main import ( "fmt" "math/big" ) func bernoulli(z *big.Rat, n int64) *big.Rat { if z == nil { z = new(big.Rat) } a := make([]big.Rat, n+1) for m := range a { a[m].SetFrac64(1, int64(m+1)) for j := m; j >= 1; j-- { d := &a[j-1] d.Mul(z.SetInt64(int64(j)), d.Sub(d, &a[j])) } } return z.Set...
852Faulhaber's formula
0go
anl1f
This uses the `factor` function from the `coreutils` library that comes standard with most GNU/Linux, BSD, and Unix systems. https: https:
849Fermat numbers
14ruby
64q3t
def main maxIt = 13 maxItJ = 10 a1 = 1.0 a2 = 0.0 d1 = 3.2 puts for i in 2 .. maxIt a = a1 + (a1 - a2) / d1 for j in 1 .. maxItJ x = 0.0 y = 0.0 for k in 1 .. 1 << i y = 1.0 - 2.0 * y * x x = a - x * x ...
848Feigenbaum constant calculation
14ruby
8yk01
object Feigenbaum1 extends App { val (max_it, max_it_j) = (13, 10) var (a1, a2, d1, a) = (1.0, 0.0, 3.2, 0.0) println(" i d") var i: Int = 2 while (i <= max_it) { a = a1 + (a1 - a2) / d1 for (_ <- 0 until max_it_j) { var (x, y) = (0.0, 0.0) for (_ <- 0 until 1 << i) { y = 1....
848Feigenbaum constant calculation
16scala
dlang
modtime = File.mtime('filename') File.utime(actime, mtime, 'path') File.utime(File.atime('path'), mtime, 'path') File.utime(nil, nil, 'path')
844File modification time
14ruby
pogbh
def fibonacci_word(n) words = [, ] (n-1).times{ words << words[-1] + words[-2] } words[n] end def print_fractal(word) area = Hash.new() x = y = 0 dx, dy = 0, -1 area[[x,y]] = word.each_char.with_index(1) do |c,n| area[[x+dx, y+dy]] = dx.zero?? : x, y = x+2*dx, y+2*dy area[[x, y]] = d...
846Fibonacci word/fractal
14ruby
ygo6n
null
846Fibonacci word/fractal
15rust
mriya
options("expressions") options(expressions = 10000) recurse <- function(x) { print(x) recurse(x+1) } recurse(0)
841Find limit of recursion
13r
mrzy4
import java.io.*; import java.util.Scanner; public class ReadFastaFile { public static void main(String[] args) throws FileNotFoundException { boolean first = true; try (Scanner sc = new Scanner(new File("test.fasta"))) { while (sc.hasNextLine()) { String line = sc.ne...
854FASTA format
9java
35pzg
const fs = require("fs"); const readline = require("readline"); const args = process.argv.slice(2); if (!args.length) { console.error("must supply file name"); process.exit(1); } const fname = args[0]; const readInterface = readline.createInterface({ input: fs.createReadStream(fname), console: false,...
854FASTA format
10javascript
cjx9j
package main import ( "fmt" "math/big" ) func bernoulli(n uint) *big.Rat { a := make([]big.Rat, n+1) z := new(big.Rat) for m := range a { a[m].SetFrac64(1, int64(m+1)) for j := m; j >= 1; j-- { d := &a[j-1] d.Mul(z.SetInt64(int64(j)), d.Sub(d, &a[j])) ...
855Faulhaber's triangle
0go
2kql7
import java.util.stream.IntStream class FaulhabersFormula { private static long gcd(long a, long b) { if (b == 0) { return a } return gcd(b, a % b) } private static class Frac implements Comparable<Frac> { private long num private long denom pub...
852Faulhaber's formula
7groovy
hs6j9
struct DivisorGen { curr: u64, last: u64, } impl Iterator for DivisorGen { type Item = u64; fn next(&mut self) -> Option<u64> { self.curr += 2u64; if self.curr < self.last{ None } else { Some(self.curr) } } } fn divisor_gen(num: u64) -> Div...
849Fermat numbers
15rust
ygs68
import scala.collection.mutable import scala.collection.mutable.ListBuffer object FermatNumbers { def main(args: Array[String]): Unit = { println("First 10 Fermat numbers:") for (i <- 0 to 9) { println(f"F[$i] = ${fermat(i)}") } println() println("First 12 Fermat numbers factored:") for...
849Fermat numbers
16scala
cjo93
import Foundation func feigenbaum(iterations: Int = 13) { var a = 0.0 var a1 = 1.0 var a2 = 0.0 var d = 0.0 var d1 = 3.2 print(" i d") for i in 2...iterations { a = a1 + (a1 - a2) / d1 for _ in 1...10 { var x = 0.0 var y = 0.0 for _ in 1...1<<i { y = 1.0 - 2.0 ...
848Feigenbaum constant calculation
17swift
06hs6
use std::fs; fn main() -> std::io::Result<()> { let metadata = fs::metadata("foo.txt")?; if let Ok(time) = metadata.accessed() { println!("{:?}", time); } else { println!("Not supported on this platform"); } Ok(()) }
844File modification time
15rust
1irpu
import java.io.File import java.util.Date object FileModificationTime extends App { def test(file: File) { val (t, init) = (file.lastModified(), s"The following ${if (file.isDirectory()) "directory" else "file"} called ${file.getPath()}") println(init + (if (t == 0) " does not exist." else " was modif...
844File modification time
16scala
wfhes
def fibIt = Iterator.iterate(("1","0")){case (f1,f2) => (f2,f1+f2)}.map(_._1) def turnLeft(c: Char): Char = c match { case 'R' => 'U' case 'U' => 'L' case 'L' => 'D' case 'D' => 'R' } def turnRight(c: Char): Char = c match { case 'R' => 'D' case 'D' => 'L' case 'L' => 'U' case 'U' => 'R' } def direct...
846Fibonacci word/fractal
16scala
lhfcq
import java.util.*; public class FWord { private String fWord0 = ""; private String fWord1 = ""; private String nextFWord () { final String result; if ( "".equals ( fWord1 ) ) result = "1"; else if ( "".equals ( fWord0 ) ) result = "0"; else ...
851Fibonacci word
9java
i9hos
null
854FASTA format
11kotlin
nc7ij
package main import ( "fmt" "sort" "strconv" "strings" ) func fairshare(n, base int) []int { res := make([]int, n) for i := 0; i < n; i++ { j := i sum := 0 for j > 0 { sum += j % base j /= base } res[i] = sum % base } retu...
856Fairshare between two and more
0go
b8zkh
import java.math.MathContext import java.util.stream.LongStream class FaulhabersTriangle { private static final MathContext MC = new MathContext(256) private static long gcd(long a, long b) { if (b == 0) { return a } return gcd(b, a % b) } private static class Frac...
855Faulhaber's triangle
7groovy
yg16o
import Data.Ratio ((%), numerator, denominator) import Data.List (intercalate, transpose) import Data.Bifunctor (bimap) import Data.Char (isSpace) import Data.Monoid ((<>)) import Data.Bool (bool) faulhaber :: [[Rational]] faulhaber = tail $ scanl (\rs n -> let xs = zipWith ((*) . (n %)) [2 ..] rs ...
852Faulhaber's formula
8haskell
zu1t0
sub common_prefix { my $sep = shift; my $paths = join "\0", map { $_.$sep } @_; $paths =~ /^ ( [^\0]* ) $sep [^\0]* (?: \0 \1 $sep [^\0]* )* $/x; return $1; }
843Find common directory path
2perl
rw2gd
1.upto(100) { i -> println "${i% 3? '': 'Fizz'}${i% 5? '': 'Buzz'}" ?: i }
835FizzBuzz
7groovy
0yish
null
851Fibonacci word
10javascript
zuat2
local file = io.open("input.txt","r") local data = file:read("*a") file:close() local output = {} local key = nil
854FASTA format
1lua
dljnq
double PI; typedef double complex cplx; void _fft(cplx buf[], cplx out[], int n, int step) { if (step < n) { _fft(out, buf, n, step * 2); _fft(out + step, buf + step, n, step * 2); for (int i = 0; i < n; i += 2 * step) { cplx t = cexp(-I * PI * i / n) * out[i + step]; buf[i / 2] = out[i] + t; buf[...
858Fast Fourier transform
5c
8y204
import Data.Bool (bool) import Data.List (intercalate, unfoldr) import Data.Tuple (swap) thueMorse :: Int -> [Int] thueMorse base = baseDigitsSumModBase base <$> [0 ..] baseDigitsSumModBase :: Int -> Int -> Int baseDigitsSumModBase base n = mod ( sum $ unfoldr ( bool Nothing . ...
856Fairshare between two and more
8haskell
dlrn4
import Data.Ratio (Ratio, denominator, numerator, (%)) faulhaber :: Int -> Rational -> Rational faulhaber p n = sum $ zipWith ((*) . (n ^)) [1 ..] (faulhaberTriangle !! p) faulhaberTriangle :: [[Rational]] faulhaberTriangle = tail $ scanl ( \rs n -> let xs = zipWith ((*) . (n %)) [2 ..]...
855Faulhaber's triangle
8haskell
anm1g
int * anynacci (int *seedArray, int howMany) { int *result = malloc (howMany * sizeof (int)); int i, j, initialCardinality; for (i = 0; seedArray[i] != 0; i++); initialCardinality = i; for (i = 0; i < initialCardinality; i++) result[i] = seedArray[i]; for (i = initialCardinality; i < howMany; i++) ...
859Fibonacci n-step number sequences
5c
s39q5
<?php function _commonPath($dirList) { $arr = array(); foreach($dirList as $i => $path) { $dirList[$i] = explode('/', $path); unset($dirList[$i][0]); $arr[$i] = count($dirList[$i]); } $min = min($arr); for($i = 0; $i < count($dirList); $i++) { while(count($dirList[$i]) > $min) { array_pop($dir...
843Find common directory path
12php
dlsn8
def recurse x puts x recurse(x+1) end recurse(0)
841Find limit of recursion
14ruby
upcvz
my $size1 = -s 'input.txt'; my $size2 = -s '/input.txt';
845File size
2perl
4am5d
package main import ( "fmt" "io/ioutil" ) func main() { b, err := ioutil.ReadFile("input.txt") if err != nil { fmt.Println(err) return } if err = ioutil.WriteFile("output.txt", b, 0666); err != nil { fmt.Println(err) } }
850File input/output
0go
s3rqa
content = new File('input.txt').text new File('output.txt').write(content)
850File input/output
7groovy
anv1p
import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class FairshareBetweenTwoAndMore { public static void main(String[] args) { for ( int base : Arrays.asList(2, 3, 5, 11) ) { System.out.printf("Base%d =%s%n", base, thueMorseSequence(25, base)); } } ...
856Fairshare between two and more
9java
s32q0
import java.util.Arrays; import java.util.stream.IntStream; public class FaulhabersFormula { private static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } private static class Frac implements Comparable<Frac> { private long num; ...
852Faulhaber's formula
9java
om78d
fn recurse(n: i32) { println!("depth: {}", n); recurse(n + 1) } fn main() { recurse(0); }
841Find limit of recursion
15rust
51luq
def recurseTest(i:Int):Unit={ try{ recurseTest(i+1) } catch { case e:java.lang.StackOverflowError => println("Recursion depth on this system is " + i + ".") } } recurseTest(0)
841Find limit of recursion
16scala
rwugn
fizzbuzz :: Int -> String fizzbuzz x | f 15 = "FizzBuzz" | f 3 = "Fizz" | f 5 = "Buzz" | otherwise = show x where f = (0 ==) . rem x main :: IO () main = mapM_ (putStrLn . fizzbuzz) [1 .. 100]
835FizzBuzz
8haskell
5arug
<?php echo filesize('input.txt'), ; echo filesize('/input.txt'), ; ?>
845File size
12php
i9eov
main = readFile "input.txt" >>= writeFile "output.txt"
850File input/output
8haskell
970mo
null
851Fibonacci word
11kotlin
qz4x1
int isPrime(int n){ if (n%2==0) return n==2; if (n%3==0) return n==3; int d=5; while(d*d<=n){ if(n%d==0) return 0; d+=2; if(n%d==0) return 0; d+=4;} return 1;} main() {int i,d,p,r,q=929; if (!isPrime(q)) return 1; r=q; while(r>0) r<<=1; d=2*q+1; do { for(p=r, i= 1; p; p<<= 1){ i=((long long)i * ...
860Factors of a Mersenne number
5c
oml80
(() => { 'use strict';
856Fairshare between two and more
10javascript
ncgiy
import java.math.BigDecimal; import java.math.MathContext; import java.util.Arrays; import java.util.stream.LongStream; public class FaulhabersTriangle { private static final MathContext MC = new MathContext(256); private static long gcd(long a, long b) { if (b == 0) { return a; } ...
855Faulhaber's triangle
9java
jqf7c
null
851Fibonacci word
1lua
s3gq8
my $fasta_example = <<'END_FASTA_EXAMPLE'; >Rosetta_Example_1 THERECANBENOSPACE >Rosetta_Example_2 THERECANBESEVERAL LINESBUTTHEYALLMUST BECONCATENATED END_FASTA_EXAMPLE my $num_newlines = 0; while ( < $fasta_example > ) { if (/\A\>(.*)/) { print "\n" x $num_newlines, $1, ': '; } else { $num_newlines = 1; pri...
854FASTA format
2perl
7xfrh
fun turn(base: Int, n: Int): Int { var sum = 0 var n2 = n while (n2 != 0) { val re = n2 % base n2 /= base sum += re } return sum % base } fun fairShare(base: Int, count: Int) { print(String.format("Base%2d:", base)) for (i in 0 until count) { val t = turn(bas...
856Fairshare between two and more
11kotlin
any13
(() => {
855Faulhaber's triangle
10javascript
1iyp7
null
852Faulhaber's formula
11kotlin
xtuws
(defn nacci [init] (letfn [(s [] (lazy-cat init (apply map + (map #(drop % (s)) (range (count init))))))] (s))) (let [show (fn [name init] (println "first 20" name (take 20 (nacci init))))] (show "Fibonacci" [1 1]) (show "Tribonacci" [1 1 2]) (show "Tetranacci" [1 1 2 4]) (show "Lucas" [2 1]))
859Fibonacci n-step number sequences
6clojure
ncuik
import os size = os.path.getsize('input.txt') size = os.path.getsize('/input.txt')
845File size
3python
ge94h
function turn(base, n) local sum = 0 while n ~= 0 do local re = n % base n = math.floor(n / base) sum = sum + re end return sum % base end function fairShare(base, count) io.write(string.format("Base%2d:", base)) for i=1,count do local t = turn(base, i - 1) ...
856Fairshare between two and more
1lua
edmac
function binomial(n,k) if n<0 or k<0 or n<k then return -1 end if n==0 or k==0 then return 1 end local num = 1 for i=k+1,n do num = num * i end local denom = 1 for i=2,n-k do denom = denom * i end return num / denom end function gcd(a,b) while b ~= 0 do ...
852Faulhaber's formula
1lua
qz5x0
var n = 1 func recurse() { print(n) n += 1 recurse() } recurse()
841Find limit of recursion
17swift
vb92r
sizeinwd <- file.info('input.txt')[["size"]] sizeinroot <- file.info('/input.txt')[["size"]]
845File size
13r
vb327
import io FASTA='''\ >Rosetta_Example_1 THERECANBENOSPACE >Rosetta_Example_2 THERECANBESEVERAL LINESBUTTHEYALLMUST BECONCATENATED''' infile = io.StringIO(FASTA) def fasta_parse(infile): key = '' for line in infile: if line.startswith('>'): if key: yield key, val ...
854FASTA format
3python
jqt7p
(ns mersennenumber (:gen-class)) (defn m* [p q m] " Computes (p*q) mod m " (mod (*' p q) m)) (defn power "modular exponentiation (i.e. b^e mod m" [b e m] (loop [b b, e e, x 1] (if (zero? e) x (if (even? e) (recur (m* b b m) (quot e 2) x) (recur (m* b b m) (quot e 2) (m*...
860Factors of a Mersenne number
6clojure
tv4fv
use strict; use warnings; use Math::AnyNum qw(sum polymod); sub fairshare { my($b, $n) = @_; sprintf '%3d'x$n, map { sum ( polymod($_, $b, $b )) % $b } 0 .. $n-1; } for (<2 3 5 11>) { printf "%3s:%s\n", $_, fairshare($_, 25); }
856Fairshare between two and more
2perl
97amn
null
855Faulhaber's triangle
11kotlin
518ua
>>> import os >>> os.path.commonpath(['/home/user1/tmp/coverage/test', '/home/user1/tmp/covert/operator', '/home/user1/tmp/coven/members']) '/home/user1/tmp'
843Find common directory path
3python
7xvrm
get_common_dir <- function(paths, delim = "/") { path_chunks <- strsplit(paths, delim) i <- 1 repeat({ current_chunk <- sapply(path_chunks, function(x) x[i]) if(any(current_chunk!= current_chunk[1])) break i <- i + 1 }) paste(path_chunks[[1]][seq_len(i - 1)], collapse = delim) } paths <- c( ...
843Find common directory path
13r
519uy
import java.io.*; public class FileIODemo { public static void main(String[] args) { try { FileInputStream in = new FileInputStream("input.txt"); FileOutputStream out = new FileOutputStream("ouput.txt"); int c; while ((c = in.read()) != -1) { out.write(c); } } catch (Fil...
850File input/output
9java
tvaf9
library("seqinr") data <- c(">Rosetta_Example_1","THERECANBENOSPACE",">Rosetta_Example_2","THERECANBESEVERAL","LINESBUTTHEYALLMUST","BECONCATENATED") fname <- "rosettacode.fasta" f <- file(fname,"w+") writeLines(data,f) close(f) fasta <- read.fasta(file = fname, as.string = TRUE, seqtype = "AA") for (aline in fasta) ...
854FASTA format
13r
4ai5y
from itertools import count, islice def _basechange_int(num, b): if num == 0: return [0] result = [] while num != 0: num, d = divmod(num, b) result.append(d) return result[::-1] def fairshare(b=2): for i in count(): yield sum(_basechange_int(i, b))% b if __nam...
856Fairshare between two and more
3python
cje9q
function binomial(n,k) if n<0 or k<0 or n<k then return -1 end if n==0 or k==0 then return 1 end local num = 1 for i=k+1,n do num = num * i end local denom = 1 for i=2,n-k do denom = denom * i end return num / denom end function gcd(a,b) while b ~= 0 do ...
855Faulhaber's triangle
1lua
4ao5c
var fso = new ActiveXObject("Scripting.FileSystemObject"); var ForReading = 1, ForWriting = 2; var f_in = fso.OpenTextFile('input.txt', ForReading); var f_out = fso.OpenTextFile('output.txt', ForWriting, true);
850File input/output
10javascript
mrsyv
package main import "fmt" type frac struct{ num, den int } func (f frac) String() string { return fmt.Sprintf("%d/%d", f.num, f.den) } func f(l, r frac, n int) { m := frac{l.num + r.num, l.den + r.den} if m.den <= n { f(l, m, n) fmt.Print(m, " ") f(m, r, n) } } func main() {
857Farey sequence
0go
nc4i1
size = File.size('input.txt') size = File.size('/input.txt')
845File size
14ruby
7xlri
def fasta_format(strings) out, text = [], strings.split().each do |line| if line[0] == '>' out << text unless text.empty? text = line[1..-1] + else text << line end end out << text unless text.empty? end data = <<'EOS' >Rosetta_Example_1 THERECANBENOSPACE >Rosetta_Example_2 THER...
854FASTA format
14ruby
k03hg
use std::env; use std::io::{BufReader, Lines}; use std::io::prelude::*; use std::fs::File; fn main() { let args: Vec<String> = env::args().collect(); let f = File::open(&args[1]).unwrap(); for line in FastaIter::new(f) { println!("{}", line); } } struct FastaIter<T> { buffer_lines: Lines<B...
854FASTA format
15rust
b86kx
import Data.List (unfoldr, mapAccumR) import Data.Ratio ((%), denominator, numerator) import Text.Printf (PrintfArg, printf) farey :: Integer -> [Rational] farey n = 0: unfoldr step (0, 1, 1, n) where step (a, b, c, d) | c > n = Nothing | otherwise = let k = (n + b) `quot` d in Just ...
857Farey sequence
8haskell
upqv2
require 'abbrev' dirs = %w( /home/user1/tmp/coverage/test /home/user1/tmp/covert/operator /home/user1/tmp/coven/members ) common_prefix = dirs.abbrev.keys.min_by {|key| key.length}.chop common_directory = common_prefix.sub(%r{/[^/]*$}, '')
843Find common directory path
14ruby
hs5jx
use std::{env, fs, process}; use std::io::{self, Write}; use std::fmt::Display; fn main() { let file_name = env::args().nth(1).unwrap_or_else(|| exit_err("No file name supplied", 1)); let metadata = fs::metadata(file_name).unwrap_or_else(|e| exit_err(e, 2)); println!("Size of file.txt is {} bytes", metada...
845File size
15rust
jq272
import java.io.File object FileSize extends App { val name = "pg1661.txt" println(s"$name : ${new File(name).length()} bytes") println(s"/$name: ${new File(s"${File.separator}$name").length()} bytes") }
845File size
16scala
b85k6
null
850File input/output
11kotlin
omh8z
sub fiboword; { my ($a, $b, $count) = (1, 0, 0); sub fiboword { $count++; return $a if $count == 1; return $b if $count == 2; ($a, $b) = ($b, "$b$a"); return $b; } } sub entropy { my %c; $c{$_}++ for split //, my $str = shift; my $e = 0; for (values %c...
851Fibonacci word
2perl
vbi20
import java.io.File import java.util.Scanner object ReadFastaFile extends App { val sc = new Scanner(new File("test.fasta")) var first = true while (sc.hasNextLine) { val line = sc.nextLine.trim if (line.charAt(0) == '>') { if (first) first = false else println() printf("%s: ", line.su...
854FASTA format
16scala
an91n
import java.util.TreeSet; public class Farey{ private static class Frac implements Comparable<Frac>{ int num; int den; public Frac(int num, int den){ this.num = num; this.den = den; } @Override public String toString(){ return num + "/" + den; } @Override public int compareTo(Frac o){ ...
857Farey sequence
9java
mrpym
def turn(base, n) sum = 0 while n!= 0 do rem = n % base n = n / base sum = sum + rem end return sum % base end def fairshare(base, count) print % [base] for i in 0 .. count - 1 do t = turn(base, i) print % [t] end print end def turnCount(base,...
856Fairshare between two and more
14ruby
2kxlw
use std::path::{Path, PathBuf}; fn main() { let paths = [ Path::new("/home/user1/tmp/coverage/test"), Path::new("/home/user1/tmp/covert/operator"), Path::new("/home/user1/tmp/coven/members"), ]; match common_path(&paths) { Some(p) => println!("The common path is: {:#?}", p),...
843Find common directory path
15rust
k04h5
null
857Farey sequence
11kotlin
tv7f0
struct Digits { rest: usize, base: usize, } impl Iterator for Digits { type Item = usize; fn next(&mut self) -> Option<usize> { if self.rest == 0 { return None; } let (digit, rest) = (self.rest% self.base, self.rest / self.base); self.rest = rest; So...
856Fairshare between two and more
15rust
vbq2t
use 5.010; use List::Util qw(sum); use Math::BigRat try => 'GMP'; use ntheory qw(binomial bernfrac); sub faulhaber_triangle { my ($p) = @_; map { Math::BigRat->new(bernfrac($_)) * binomial($p, $_) / $p } reverse(0 .. $p-1); } foreach my $p (1 .. 10) { say map { sprintf("%6...
855Faulhaber's triangle
2perl
om48x
use 5.014; use Math::Algebra::Symbols; sub bernoulli_number { my ($n) = @_; return 0 if $n > 1 && $n % 2; my @A; for my $m (0 .. $n) { $A[$m] = symbols(1) / ($m + 1); for (my $j = $m ; $j > 0 ; $j--) { $A[$j - 1] = $j * ($A[$j - 1] - $A[$j]); } } return $...
852Faulhaber's formula
2perl
2k8lf