code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
cat("")
135Terminal control/Display an extended character
13r
saoqy
use warnings; use strict; use Math::Random::ISAAC; my $message = "a Top Secret secret"; my $key = "this is my secret key"; my $enc = xor_isaac($key, $message); my $dec = xor_isaac($key, join "", pack "H*", $enc); print "Message: $message\n"; print "Key : $key\n"; print "XOR : $enc\n"; print "XOR dcr: ", join("",...
128The ISAAC Cipher
2perl
q1zx6
>>> def isint(f): return complex(f).imag == 0 and complex(f).real.is_integer() >>> [isint(f) for f in (1.0, 2, (3.0+0.0j), 4.1, (3+4j), (5.6+0j))] [True, True, True, False, False, False] >>> ... >>> isint(25.000000) True >>> isint(24.999999) False >>> isint(25.000100) False >>> isint(-2.1e120) True >>> isint(-5...
129Test integerness
3python
zivtt
(let [numbers '(first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth) gifts ["And a partridge in a pear tree", "Two turtle doves", "Three French hens", "Four calling birds", "Five gold rings", "Six geese a-laying...
139The Twelve Days of Christmas
6clojure
nqoik
use Term::Size; ($cols, $rows) = Term::Size::chars; print "The terminal has $cols columns and $rows lines\n";
137Terminal control/Dimensions
2perl
kgbhc
puts
135Terminal control/Display an extended character
14ruby
d0zns
object ExtendedCharacter extends App { println("") println("") }
135Terminal control/Display an extended character
16scala
3nmzy
out, max_out, max_times = 0, -1, [] for job in open('mlijobs.txt'): out += 1 if in job else -1 if out > max_out: max_out, max_times = out, [] if out == max_out: max_times.append(job.split()[3]) print(% max_out) print(' ' + '\n '.join(max_times))
125Text processing/Max licenses in use
3python
g2q4h
char *strings[] = {, , , , , , , }; int main() { int i,j,MAXROW,MAXCOL; struct text_info tInfo; gettextinfo(&tInfo); MAXROW = tInfo.screenheight; MAXCOL = tInfo.screenwidth; clrscr(); cprintf(); getch(); for(i=0;i<8;i++) { clrscr(); gotoxy(5,MAXROW/2); ...
141Terminal control/Cursor movement
5c
17hpj
use Term::Cap; my $t = Term::Cap->Tgetent; print $t->Tgoto("cm", 2, 5); print "Hello";
140Terminal control/Cursor positioning
2perl
f0id7
dfr <- read.table("mlijobs.txt") dfr <- dfr[,c(2,4)] n.checked.out <- cumsum(ifelse(dfr$V2=="OUT", 1, -1)) times <- strptime(dfr$V4, "%Y/%m/%d_%H:%M:%S") most.checked.out <- max(n.checked.out) when.most.checked.out <- times[which(n.checked.out==most.checked.out)] plot(times, n.checked.out, type="s")
125Text processing/Max licenses in use
13r
vma27
import os def get_windows_terminal(): from ctypes import windll, create_string_buffer h = windll.kernel32.GetStdHandle(-12) csbi = create_string_buffer(22) res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi) if not res: return 80, 25 import struct (bufx, bufy, curx, cury, watt...
137Terminal control/Dimensions
3python
brpkr
void table(const char *title, const char *mode) { int f, b; printf(, title); for (b = 40; b <= 107; b++) { if (b == 48) b = 100; printf(, b, mode, b); for (f = 30; f <= 97; f++) { if (f == 38) f = 90; printf(, f, f); } puts(); } } int main(void) { int fg, bg, blink, inverse; table(, ); table(, ...
142Terminal control/Coloured text
5c
t8of4
echo .$x..$y.; echo .$n.; echo .$n.; echo .$n.; echo .$n.; echo ;
140Terminal control/Cursor positioning
12php
h5rjf
import random import collections INT_MASK = 0xFFFFFFFF class IsaacRandom(random.Random): def seed(self, seed=None): def mix(): init_state[0] ^= ((init_state[1]<<11)&INT_MASK); init_state[3] += init_state[0]; init_state[3] &= INT_MASK; init_state[1] += init_state[2]; init_...
128The ISAAC Cipher
3python
sa3q9
class Numeric def to_i? self == self.to_i rescue false end end ar = [25.000000, 24.999999, 25.000100, -2.1e120, -5e-2, Float::NAN, Float::INFINITY, 2r, 2.5r, 2+0i, 2+0.0i, 5-5i] ar.each{|num|...
129Test integerness
14ruby
6d53t
use strict; use warnings; use Test; my %tests; BEGIN { %tests = ( 'A man, a plan, a canal: Panama.' => 1, 'My dog has fleas' => 0, "Madam, I'm Adam." => 1, '1 on 1' => 0, 'In...
130Test a function
2perl
g214e
def winsize require 'io/console' IO.console.winsize rescue LoadError [Integer(`tput li`), Integer(`tput co`)] end rows, cols = winsize printf , rows, cols
137Terminal control/Dimensions
14ruby
1japw
package main import ( "fmt" "time" "os" "os/exec" "strconv" ) func main() { tput("clear")
141Terminal control/Cursor movement
0go
ydt64
print()
140Terminal control/Cursor positioning
3python
t8nfw
int string_compare(gconstpointer p1, gconstpointer p2) { const char* const* s1 = p1; const char* const* s2 = p2; return strcmp(*s1, *s2); } GPtrArray* load_dictionary(const char* file, GError** error_ptr) { GError* error = NULL; GIOChannel* channel = g_io_channel_new_file(file, , &error); if (c...
143Teacup rim text
5c
266lo
val (lines, columns) = (System.getenv("LINES"), System.getenv("COLUMNS")) println(s"Lines = $lines, Columns = $columns")
137Terminal control/Dimensions
16scala
xpqwg
null
141Terminal control/Cursor movement
11kotlin
cz698
require 'curses' Curses.init_screen begin Curses.setpos(6, 3) Curses.addstr() Curses.getch ensure Curses.close_screen end
140Terminal control/Cursor positioning
14ruby
3ifz7
object Main extends App { print("\u001Bc")
140Terminal control/Cursor positioning
16scala
9t6m5
package main import ( "bufio" "fmt" "log" "os" "strconv" "strings" ) const ( filename = "readings.txt" readings = 24
136Text processing/1
0go
br1kh
out = 0 max_out = -1 max_times = [] File.foreach('mlijobs.txt') do |line| out += line.include?()? 1: -1 if out > max_out max_out = out max_times = [] end max_times << line.split[3] if out == max_out end puts max_times.each {|time| puts }
125Text processing/Max licenses in use
14ruby
7u0ri
system "tput cub1"; sleep 1; system "tput cuf1"; sleep 1; system "tput cuu1"; sleep 1; system "tput cud1"; sleep 1; system "tput cr"; sleep 1; system "tput home"; sleep 1; $_ = qx[stty -a </dev/tty 2>&1]; my($rows,$cols) = /(\d+) rows; (\d+) col/; $rows--; $cols--; system "tput cup $rows $cols"; sleep ...
141Terminal control/Cursor movement
2perl
xb1w8
import Data.List import Numeric import Control.Arrow import Control.Monad import Text.Printf import System.Environment import Data.Function type Date = String type Value = Double type Flag = Bool readFlg :: String -> Flag readFlg = (> 0).read readNum :: String -> Value readNum = fst.head.readFloat take2 = takeWhile...
136Text processing/1
8haskell
d0tn4
type Timestamp = String; fn compute_usage<R, S, E>(lines: R) -> Result<(u32, Vec<Timestamp>), E> where S: AsRef<str>, R: Iterator<Item = Result<S, E>>, { let mut timestamps = Vec::new(); let mut current = 0; let mut maximum = 0; for line in lines { let line = line?; let line = ...
125Text processing/Max licenses in use
15rust
j5872
import java.io.{BufferedReader, InputStreamReader} import java.net.URL object License0 extends App { val url = new URL("https:
125Text processing/Max licenses in use
16scala
brnk6
def is_palindrome(s): ''' >>> is_palindrome('') True >>> is_palindrome('a') True >>> is_palindrome('aa') True >>> is_palindrome('baa') False >>> is_palindrome('baab') True >>> is_palindrome('ba_ab') True >>> is_p...
130Test a function
3python
rvagq
typedef unsigned long long xint; typedef unsigned uint; typedef struct { uint x, y; xint value; } sum_t; xint *cube; uint n_cubes; sum_t *pq; uint pq_len, pq_cap; void add_cube(void) { uint x = n_cubes++; cube = realloc(cube, sizeof(xint) * (n_cubes + 1)); cube[n_cubes] = (xint) n_cubes*n_cubes*n_cubes; if (x...
144Taxicab numbers
5c
prgby
unsigned int divisor_count(unsigned int n) { unsigned int total = 1; unsigned int p; for (; (n & 1) == 0; n >>= 1) { ++total; } for (p = 3; p * p <= n; p += 2) { unsigned int count = 1; for (; n % p == 0; n /= p) { ++count; } total *= co...
145Tau number
5c
wkjec
struct edge { void *from; void *to; }; struct components { int nnodes; void **nodes; struct components *next; }; struct node { int index; int lowlink; bool onStack; void *data; }; struct tjstate { int index; int sp; int nedges; struct edge *edges; struct node **stack; struct components *head; struct ...
146Tarjan
5c
czd9c
package main import ( "bufio" "fmt" "log" "os" "sort" "strings" ) func check(err error) { if err != nil { log.Fatal(err) } } func readWords(fileName string) []string { file, err := os.Open(fileName) check(err) defer file.Close() var words []string scanner :...
143Teacup rim text
0go
qppxz
null
128The ISAAC Cipher
15rust
oxm83
checkTrue(palindroc("aba")) checkTrue(!palindroc("ab")) checkException(palindroc()) checkTrue(palindroc(""))
130Test a function
13r
u9kvx
import curses scr = curses.initscr() def move_left(): y,x = curses.getyx() curses.move(y,x-1) def move_right(): y,x = curses.getyx() curses.move(y,x+1) def move_up(): y,x = curses.getyx() curses.move(y-1,x) def move_down(): y,x = curses.getyx() curses.move(y+1,x) def move_line_home() y,x = curses.ge...
141Terminal control/Cursor movement
3python
qpaxi
import Data.List (groupBy, intercalate, sort, sortBy) import qualified Data.Set as S import Data.Ord (comparing) import Data.Function (on) main :: IO () main = readFile "mitWords.txt" >>= (putStrLn . showGroups . circularWords . lines) circularWords :: [String] -> [String] circularWords ws = let lexicon = S.fromL...
143Teacup rim text
8haskell
mffyf
package main import ( "fmt" "os" "os/exec" ) func main() { color(red) fmt.Println("Red") color(green) fmt.Println("Green") color(blue) fmt.Println("Blue") } const ( blue = "1" green = "2" red = "4" ) func color(c string) { cmd := exec.Command("tput", "setf", c)...
142Terminal control/Coloured text
0go
h54jq
import java.io.*; import java.util.*; public class Teacup { public static void main(String[] args) { if (args.length != 1) { System.err.println("usage: java Teacup dictionary"); System.exit(1); } try { findTeacupWords(loadDictionary(args[0])); } c...
143Teacup rim text
9java
f00dv
import java.io.File; import java.util.*; import static java.lang.System.out; public class TextProcessing1 { public static void main(String[] args) throws Exception { Locale.setDefault(new Locale("en", "US")); Metrics metrics = new Metrics(); int dataGap = 0; String gapBeginDate = ...
136Text processing/1
9java
sa8q0
#!/usr/bin/runhaskell import System.Console.ANSI colorStrLn :: ColorIntensity -> Color -> ColorIntensity -> Color -> String -> IO () colorStrLn fgi fg bgi bg str = do setSGR [SetColor Foreground fgi fg, SetColor Background bgi bg] putStr str setSGR [] putStrLn "" main = do colorStrLn Vivid White Vivid Red ...
142Terminal control/Coloured text
8haskell
ixqor
object CursorMovement extends App { val ESC = "\u001B"
141Terminal control/Cursor movement
16scala
nq0ic
(ns test-project-intellij.core (:gen-class)) (defn cube [x] "Cube a number through triple multiplication" (* x x x)) (defn sum3 [[i j]] " [i j] -> i^3 + j^3" (+ (cube i) (cube j))) (defn next-pair [[i j]] " Generate next [i j] pair of sequence (producing lower triangle pairs) " (if (< j i) [i (in...
144Taxicab numbers
6clojure
xbkwk
package main import ( "fmt" "math/big" )
146Tarjan
0go
wk7eg
(() => { 'use strict';
143Teacup rim text
10javascript
ydd6r
package main import "fmt" type trit int8 const ( trFalse trit = iota - 1 trMaybe trTrue ) func (t trit) String() string { switch t { case trFalse: return "False" case trMaybe: return "Maybe" case trTrue: return "True " } panic("Invalid trit") } func trNot...
138Ternary logic
0go
5c5ul
var filename = 'readings.txt'; var show_lines = 5; var file_stats = { 'num_readings': 0, 'total': 0, 'reject_run': 0, 'reject_run_max': 0, 'reject_run_date': '' }; var fh = new ActiveXObject("Scripting.FileSystemObject").openTextFile(filename, 1);
136Text processing/1
10javascript
nsfiy
def palindrome?(s) s == s.reverse end require 'test/unit' class MyTests < Test::Unit::TestCase def test_palindrome_ok assert(palindrome? ) end def test_palindrome_nok assert_equal(false, palindrome?()) end def test_object_without_reverse assert_raise(NoMethodError) {palindrome? 42} end d...
130Test a function
14ruby
j5w7x
null
130Test a function
15rust
h4xj2
null
146Tarjan
11kotlin
s1kq7
unsigned int divisor_count(unsigned int n) { unsigned int total = 1; for (; (n & 1) == 0; n >>= 1) { ++total; } for (unsigned int p = 3; p * p <= n; p += 2) { unsigned int count = 1; for (; n % p == 0; n /= p) { ++count; } total *= count; ...
147Tau function
5c
l3dcy
enum Trit { TRUE, MAYBE, FALSE private Trit nand(Trit that) { switch ([this,that]) { case { FALSE in it }: return TRUE case { MAYBE in it }: return MAYBE default : return FALSE } } private Trit nor(Trit that) { this.or(that).not() } Tr...
138Ternary logic
7groovy
c3c9i
import org.scalacheck._ import Prop._ import Gen._ object PalindromeCheck extends Properties("Palindrome") { property("A string concatenated with its reverse is a palindrome") = forAll { s: String => isPalindrome(s + s.reverse) } property("A string concatenated with any character and its reverse is a palindro...
130Test a function
16scala
p70bj
null
142Terminal control/Coloured text
11kotlin
pr7b6
const char *code = ; int main() { sqlite3 *db = NULL; char *errmsg; if ( sqlite3_open(, &db) == SQLITE_OK ) { if ( sqlite3_exec(db, code, NULL, NULL, &errmsg) != SQLITE_OK ) { fprintf(stderr, errmsg); sqlite3_free(errmsg); sqlite3_close(db); exit(EXIT_FAILURE); } sqli...
148Table creation/Postal addresses
5c
zoxtx
(require '[clojure.java.jdbc:as sql]) (def db {:classname "org.h2.Driver" :subprotocol "h2:file" :subname "db/my-dbname"}) (sql/db-do-commands db (sql/create-table-ddl:address [:id "bigint primary key auto_increment"] [:street "varchar"] [:city "varchar"] [:state "varchar"] [:zip...
148Table creation/Postal addresses
6clojure
9toma
use strict; use warnings; use feature <say state current_sub>; use List::Util qw(min); sub tarjan { my (%k) = @_; my (%onstack, %index, %lowlink, @stack, @connected); my sub strong_connect { my ($vertex, $i) = @_; $index{$vertex} = $i; $lowlink{$vertex} = $i + 1; $onstack...
146Tarjan
2perl
um3vr
import Prelude hiding (Bool(..), not, (&&), (||), (==)) main = mapM_ (putStrLn . unlines . map unwords) [ table "not" $ unary not , table "and" $ binary (&&) , table "or" $ binary (||) , table "implies" $ binary (=->) , table "equals" $ binary (==) ] data Trit = False | Maybe | T...
138Ternary logic
8haskell
xpxw4
import Cocoa import XCTest class PalindromTests: XCTestCase { override func setUp() { super.setUp() } override func tearDown() { super.tearDown() } func testPalindrome() {
130Test a function
17swift
7uerq
package main import "fmt" func countDivisors(n int) int { count := 0 i := 1 k := 2 if n%2 == 0 { k = 1 } for i*i <= n { if n%i == 0 { count++ j := n / i if j != i { count++ } } i += k } retu...
145Tau number
0go
czf9g
null
136Text processing/1
11kotlin
ahw13
package main import ( "fmt" ) func main() { days := []string{"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"} gifts := []string{"A Partridge in a Pear Tree", "Two Turtle Doves and", "Three French Hens", "Four Calling Birds", "Five Gold Rings...
139The Twelve Days of Christmas
0go
vyl2m
print("Normal \027[1mBold\027[0m \027[4mUnderline\027[0m \027[7mInverse\027[0m") colors = { 30,31,32,33,34,35,36,37,90,91,92,93,94,95,96,97 } for _,bg in ipairs(colors) do for _,fg in ipairs(colors) do io.write("\027["..fg..";"..(bg+10).."mX") end print("\027[0m")
142Terminal control/Coloured text
1lua
17jpo
package main import ( "database/sql" "fmt" "log" _ "github.com/mattn/go-sqlite3" ) func main() {
148Table creation/Postal addresses
0go
k4lhz
tau :: Integral a => a -> a tau n | n <= 0 = error "Not a positive integer" tau n = go 0 (1, 1) where yo i = (i, i * i) go r (i, ii) | n < ii = r | n == ii = r + 1 | 0 == mod n i = go (r + 2) (yo $ i + 1) | otherwise = go r (yo $ i + 1) isTau :: Integral a => a -> Bool isTau...
145Tau number
8haskell
pr4bt
from collections import defaultdict def from_edges(edges): '''translate list of edges to list of nodes''' class Node: def __init__(self): self.root = None self.succ = [] nodes = defaultdict(Node) for v,w in edges: ...
146Tarjan
3python
596ux
use strict; use warnings; use feature 'say'; use List::Util qw(uniqstr any); my(%words,@teacups,%seen); open my $fh, '<', 'ref/wordlist.10000'; while (<$fh>) { chomp(my $w = uc $_); next if length $w < 3; push @{$words{join '', sort split //, $w}}, $w;} for my $these (values %words) { next if @$these...
143Teacup rim text
2perl
4cc5d
filename = "readings.txt" io.input( filename ) file_sum, file_cnt_data, file_lines = 0, 0, 0 max_rejected, n_rejected = 0, 0 max_rejected_date, rejected_date = "", "" while true do data = io.read("*line") if data == nil then break end date = string.match( data, "%d+%-%d+%-%d+" ) if date == nil then b...
136Text processing/1
1lua
ekxac
def presents = ['A partridge in a pear tree.', 'Two turtle doves', 'Three french hens', 'Four calling birds', 'Five golden rings', 'Six geese a-laying', 'Seven swans a-swimming', 'Eight maids a-milking', 'Nine ladies dancing', 'Ten lords a-leaping', 'Eleven pipers piping', 'Twelve drummers drumming'] ['...
139The Twelve Days of Christmas
7groovy
mf6y5
void fail(const char *message) { perror(message); exit(1); } cothread_t reader; cothread_t printer; struct { char *buf; size_t len; size_t cap; } line; size_t count; void reader_entry(void) { FILE *input; size_t newcap; int c, eof, eol; char *newbuf; input = fopen(, ); if (input == NULL) fail(); ...
149Synchronous concurrency
5c
6nq32
import Database.SQLite.Simple main = do db <- open "postal.db" execute_ db "\ \CREATE TABLE address (\ \addrID INTEGER PRIMARY KEY AUTOINCREMENT, \ \addrStreet TEXT NOT NULL, \ \addrCity TEXT NOT NULL, \ \addrState TEXT NOT NULL, \ \addrZIP TEXT NOT NUL...
148Table creation/Postal addresses
8haskell
nq1ie
null
148Table creation/Postal addresses
11kotlin
17upd
int main(int argc, char**argv) { FILE *note = 0; time_t tm; int i; char *p; if (argc < 2) { if ((note = fopen(note_file, ))) while ((i = fgetc(note)) != EOF) putchar(i); } else if ((note = fopen(note_file, ))) { tm = time(0); p = ctime(&tm); while (*p) fputc(*p != '\n'?*p:'\t', note), p++; ...
150Take notes on the command line
5c
l3ocy
public class Tau { private static long divisorCount(long n) { long total = 1;
145Tau number
9java
r2cg0
package main import ( "os" "os/exec" ) func main() { c := exec.Command("clear") c.Stdout = os.Stdout c.Run() }
151Terminal control/Clear the screen
0go
dsbne
import System.Console.ANSI main = clearScreen
151Terminal control/Clear the screen
8haskell
59dug
public class Logic{ public static enum Trit{ TRUE, MAYBE, FALSE; public Trit and(Trit other){ if(this == TRUE){ return other; }else if(this == MAYBE){ return (other == FALSE) ? FALSE: MAYBE; }else{ return FALSE; } } public Trit or(Trit other){ if(this == TRUE){ return TRUE; ...
138Ternary logic
9java
brbk3
gifts :: [String] gifts = [ "And a partridge in a pear tree!", "Two turtle doves,", "Three french hens,", "Four calling birds,", "FIVE GOLDEN RINGS,", "Six geese a-laying,", "Seven swans a-swimming,", "Eight maids a-milking,", "Nine ladies dancing,", "Ten lords a-leaping,", "El...
139The Twelve Days of Christmas
8haskell
eh1ai
null
148Table creation/Postal addresses
1lua
aj51v
char *super = 0; int pos, cnt[MAX]; int fact_sum(int n) { int s, x, f; for (s = 0, x = 0, f = 1; x < n; f *= ++x, s += f); return s; } int r(int n) { if (!n) return 0; char c = super[pos - n]; if (!--cnt[n]) { cnt[n] = n; if (!r(n-1)) return 0; } super[pos++] = c; return 1; } void superperm(int n) { ...
152Superpermutation minimisation
5c
f0bd3
function divisor_count(n) local total = 1
145Tau number
1lua
um6vl
public class Clear { public static void main (String[] args) { System.out.print("\033[2J"); } }
151Terminal control/Clear the screen
9java
9tsmu
var L3 = new Object(); L3.not = function(a) { if (typeof a == "boolean") return !a; if (a == undefined) return undefined; throw("Invalid Ternary Expression."); } L3.and = function(a, b) { if (typeof a == "boolean" && typeof b == "boolean") return a && b; if ((a == true && b == undefined) || (a == undefined ...
138Ternary logic
10javascript
wbwe2
(ns rosettacode.notes (:use [clojure.string:only [join]])) (defn notes [notes] (if (seq notes) (spit "NOTES.txt" (str (java.util.Date.) "\n" "\t" (join " " notes) "\n") :append true) (println (slurp "NOTES.txt")))) (notes *command-line-args*)
150Take notes on the command line
6clojure
4ct5o
use std::collections::{BTreeMap, BTreeSet};
146Tarjan
15rust
r29g5
'''Teacup rim text''' from itertools import chain, groupby from os.path import expanduser from functools import reduce def main(): '''Circular anagram groups, of more than one word, and containing words of length > 2, found in: https: ''' print('\n'.join( concatMap(circularGroup)( ...
143Teacup rim text
3python
gll4h
public class TwelveDaysOfChristmas { final static String[] gifts = { "A partridge in a pear tree.", "Two turtle doves and", "Three french hens", "Four calling birds", "Five golden rings", "Six geese a-laying", "Seven swans a-swimming", "Eight maids a-milking", "Nine ladies d...
139The Twelve Days of Christmas
9java
h57jm
my %colors = ( red => "\e[1;31m", green => "\e[1;32m", yellow => "\e[1;33m", blue => "\e[1;34m", magenta => "\e[1;35m", cyan => "\e[1;36m" ); $clr = "\e[0m"; print "$colors{$_}$_ text $clr\n" for sort keys %colors; use feature 'say'; use Term::ANSIColor; say colored('RED ON WHIT...
142Terminal control/Coloured text
2perl
ydf6u
(use '[clojure.java.io:as io]) (def writer (agent 0)) (defn write-line [state line] (println line) (inc state))
149Synchronous concurrency
6clojure
l3icb
package main import ( "container/heap" "fmt" "strings" ) type CubeSum struct { x, y uint16 value uint64 } func (c *CubeSum) fixvalue() { c.value = cubes[c.x] + cubes[c.y] } type CubeSumHeap []*CubeSum func (h CubeSumHeap) Len() int { return len(h) } func (h CubeSumHeap) Less(i, j int) bool { retu...
144Taxicab numbers
0go
6ni3p
package main import "fmt" func countDivisors(n int) int { count := 0 i := 1 k := 2 if n%2 == 0 { k = 1 } for i*i <= n { if n%i == 0 { count++ j := n / i if j != i { count++ } } i += k } retu...
147Tau function
0go
xb7wf
null
151Terminal control/Clear the screen
11kotlin
zoats
use strict; use warnings; my $nodata = 0; my $nodata_max = -1; my $nodata_maxline = "!"; my $infiles = join ", ", @ARGV; my $tot_file = 0; my $num_file = 0; while (<>) { chomp; my $tot_line = 0; my $num_line = 0; my $rejects = 0; my ($date, @fie...
136Text processing/1
2perl
9zlmn
var days = [ 'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth', ]; var gifts = [ "A partridge in a pear tree", "Two turtle doves", "Three french hens", "Four calling birds", "Five golden rings", "Six geese a-laying", ...
139The Twelve Days of Christmas
10javascript
ajp10
use DBI; my $db = DBI->connect('DBI:mysql:database:server','login','password'); my $statment = <<EOF; CREATE TABLE `Address` ( `addrID` int(11) NOT NULL auto_increment, `addrStreet` varchar(50) NOT NULL default '', `addrCity` varchar(25) NOT NULL default '', `addrState` char(2...
148Table creation/Postal addresses
2perl
mf8yz
int main() { for (unsigned int d = 2; d <= 9; ++d) { printf(, d); char digits[16] = { 0 }; memset(digits, '0' + d, d); mpz_t bignum; mpz_init(bignum); for (unsigned int count = 0, n = 1; count < 10; ++n) { mpz_ui_pow_ui(bignum, n, d); mpz_mul_u...
153Super-d numbers
5c
0a4st
import Data.List (groupBy, sortOn, tails, transpose) import Data.Function (on) taxis :: Int -> [[(Int, ((Int, Int), (Int, Int)))]] taxis nCubes = filter ((> 1) . length) $ groupBy (on (==) fst) $ sortOn fst [ (fst x + fst y, (x, y)) | (x:t) <- tails $ ((^ 3) >>= (,)) <$> [1 .. nCubes] , y <- t ] ...
144Taxicab numbers
8haskell
juv7g