code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
$handle = fopen(, ); $missformcount = 0; $totalcount = 0; $dates = array(); while (!feof($handle)) { $buffer = fgets($handle); $line = preg_replace('/\s+/',' ',$buffer); $line = explode(' ',trim($line)); $datepattern = '/^\d{4}-\d{2}-\d{2}$/'; $valpattern = '/^\d+\.{1}\d{3}$/'; $flagpattern = '/^[1-9]{1}$/'; ...
124Text processing/2
12php
zirt1
import sys if in sys.stdout.encoding: print() else: raise Exception()
126Terminal control/Unicode output
3python
3ngzc
if (any(grepl("UTF", toupper(Sys.getenv(c("LANG", "LC_ALL", "LC_CTYPE")))))) { cat("Unicode is supported on this terminal and U+25B3 is: \u25b3\n") } else { cat("Unicode is not supported on this terminal.") }
126Terminal control/Unicode output
13r
d0vnt
if ENV.values_at(,,).compact.first.include?() puts else raise end
126Terminal control/Unicode output
14ruby
yf76n
scala> println(s"Unicode is supported on this terminal and U+25B3 is: \u25b3") Unicode is supported on this terminal and U+25B3 is :
126Terminal control/Unicode output
16scala
l6bcq
int main() { printf(); return 0; }
127Terminal control/Ringing the terminal bell
5c
j5s70
typedef unsigned __int32 uint32_t; typedef uint32_t ub4; ub4 randrsl[256], randcnt; static ub4 mm[256]; static ub4 aa=0, bb=0, cc=0; void isaac() { register ub4 i,x,y; cc = cc + 1; bb = bb + cc; for (i=0; i<256; ++i) { x = mm[i]; switch (i%4) { case 0: aa ...
128The ISAAC Cipher
5c
ahn11
float: , double: , \ long double: , unsigned int: , \ unsigned long: , unsigned long long: , \ int: , long: , long long: , \ default: ) I * (long double)(y))) printf(FMTSPEC(i), i), printf(), printf(FMTSPEC(j), j), \ printf(, (isint(CMPPARTS(i, j))? : )) printf(FMTSPEC(i), ...
129Test integerness
5c
iqmo2
int IsPalindrome(char *Str); int main() { assert(IsPalindrome()); assert(IsPalindrome()); }
130Test a function
5c
vmh2o
(println (char 7))
127Terminal control/Ringing the terminal bell
6clojure
1jnpy
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.LinkedList; public class License { public static void main(String[] args) throws FileNotFoundException, IOException{ BufferedReader in = new BufferedReader(new FileReader(a...
125Text processing/Max licenses in use
9java
f85dv
(use 'clojure.test) (deftest test-palindrome? (is (palindrome? "amanaplanacanalpanama")) (is (not (palindrome? "Test 1, 2, 3"))) (run-tests)
130Test a function
6clojure
rvag2
var file_system = new ActiveXObject("Scripting.FileSystemObject"); var fh = file_system.openTextFile('mlijobs.txt', 1);
125Text processing/Max licenses in use
10javascript
yfj6r
import re import zipfile import StringIO def munge2(readings): datePat = re.compile(r'\d{4}-\d{2}-\d{2}') valuPat = re.compile(r'[-+]?\d+\.\d+') statPat = re.compile(r'-?\d+') allOk, totalLines = 0, 0 datestamps = set([]) for line in readings: totalLines += 1 fields = line.split('\t') ...
124Text processing/2
3python
kgnhf
int main() { int i; printf(); printf(); for (i = 5; i; i--) { printf(, i); fflush(stdout); sleep(1); } printf(); return 0; }
131Terminal control/Preserve screen
5c
9z4m1
null
125Text processing/Max licenses in use
11kotlin
8wc0q
dfr <- read.delim("d:/readings.txt", colClasses=c("character", rep(c("numeric", "integer"), 24))) dates <- strptime(dfr[,1], "%Y-%m-%d") dfr[which(is.na(dfr))] dates[duplicated(dates)] flags <- as.matrix(dfr[,seq(3,49,2)])>0 sum(apply(flags, 1, all))
124Text processing/2
13r
rv0gj
package main import "fmt" func main() { fmt.Print("\a") }
127Terminal control/Ringing the terminal bell
0go
f8vd0
println '\7'
127Terminal control/Ringing the terminal bell
7groovy
8wm0b
filename = "mlijobs.txt" io.input( filename ) max_out, n_out = 0, 0 occurr_dates = {} while true do line = io.read( "*line" ) if line == nil then break end if string.find( line, "OUT" ) ~= nil then n_out = n_out + 1 if n_out > max_out then max_out = n_out occurr_da...
125Text processing/Max licenses in use
1lua
oxl8h
main = putStr "\a"
127Terminal control/Ringing the terminal bell
8haskell
4le5s
public class Bell{ public static void main(String[] args){ java.awt.Toolkit.getDefaultToolkit().beep();
127Terminal control/Ringing the terminal bell
9java
c3h9h
package main import ( "fmt" "time" ) func main() { fmt.Print("\033[?1049h\033[H") fmt.Println("Alternate screen buffer\n") s := "s" for i := 5; i > 0; i-- { if i == 1 { s = "" } fmt.Printf("\rgoing back in%d second%s...", i, s) time.Sleep(time.Second...
131Terminal control/Preserve screen
0go
ekoa6
null
127Terminal control/Ringing the terminal bell
11kotlin
3n4z5
public class PreserveScreen { public static void main(String[] args) throws InterruptedException { System.out.print("\033[?1049h\033[H"); System.out.println("Alternate screen buffer\n"); for (int i = 5; i > 0; i--) { String s = (i > 1) ? "s" : ""; System.out.printf("\...
131Terminal control/Preserve screen
9java
iq6os
(function() { var orig= document.body.innerHTML document.body.innerHTML= ''; setTimeout(function() { document.body.innerHTML= 'something'; setTimeout(function() { document.body.innerHTML= orig; }, 1000); }, 1000); })();
131Terminal control/Preserve screen
10javascript
zilt2
int main() { CONSOLE_SCREEN_BUFFER_INFO info; COORD pos; HANDLE conout; long len; wchar_t c; conout = CreateFileW(L, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (conout == INVALID_HANDLE_VALUE) return 1; if (GetConsoleScreenBufferInfo(con...
132Terminal control/Positional read
5c
mtuys
require 'set' def munge2(readings, debug=false) datePat = /^\d{4}-\d{2}-\d{2}/ valuPat = /^[-+]?\d+\.\d+/ statPat = /^-?\d+/ totalLines = 0 dupdate, badform, badlen, badreading = Set[], Set[], Set[], 0 datestamps = Set[[]] for line in readings totalLines += 1 fields = line.split(/\t/) ...
124Text processing/2
14ruby
p7fbh
print("\a")
127Terminal control/Ringing the terminal bell
1lua
6dg39
null
131Terminal control/Preserve screen
11kotlin
q1dx1
print "\033[?1049h\033[H"; print "Alternate screen buffer\n"; for (my $i = 5; $i > 0; --$i) { print "going back in $i...\n"; sleep(1); } print "\033[?1049l";
131Terminal control/Preserve screen
2perl
vmj20
package main import "C" import "fmt" func main() { for i := 0; i < 80*25; i++ { fmt.Print("A")
132Terminal control/Positional read
0go
ah01f
null
132Terminal control/Positional read
11kotlin
xpiws
package main import "fmt" const ( msg = "a Top Secret secret" key = "this is my secret key" ) func main() { var z state z.seed(key) fmt.Println("Message: ", msg) fmt.Println("Key : ", key) fmt.Println("XOR : ", z.vernam(msg)) } type state struct { aa, bb, cc uint32 mm ...
128The ISAAC Cipher
0go
mtryi
package main import ( "fmt" "math" "math/big" "reflect" "strings" "unsafe" )
129Test integerness
0go
g2a4n
object DataMunging2 { import scala.io.Source import scala.collection.immutable.{TreeMap => Map} val pattern = """^(\d+-\d+-\d+)""" + """\s+(\d+\.\d+)\s+(-?\d+)""" * 24 + "$" r; def main(args: Array[String]) { val files = args map (new java.io.File(_)) filter (file => file.isFile && file.canRead) val (...
124Text processing/2
16scala
wb6es
import time print print for i in xrange(5, 0, -1): print , i time.sleep(1) print
131Terminal control/Preserve screen
3python
u9hvd
cat("\033[?1049h\033[H") cat("Alternate screen buffer\n") for (i in 5:1) { cat("\rgoing back in ", i, "...", sep = "") Sys.sleep(1) cat("\33[2J") } cat("\033[?1049l")
131Terminal control/Preserve screen
13r
c3g95
use strict; use warnings; use Curses; initscr or die; my $win = Curses->new; foreach my $row (0..9) { $win->addstr( $row , 0, join('', map { chr(int(rand(50)) + 41) } (0..9))) }; my $icol = 3 - 1; my $irow = 6 - 1; my $ch = $win->inch($irow,$icol); $win->addstr( $irow, $icol+10, 'Character at column 3, row 6 ...
132Terminal control/Positional read
2perl
2yrlf
import Data.Array (Array, (!), (//), array, elems) import Data.Word (Word, Word32) import Data.Bits (shift, xor) import Data.Char (toUpper) import Data.List (unfoldr) import Numeric (showHex) type IArray = Array Word32 Word32 data IsaacState = IState { randrsl :: IArray , randcnt :: Word32 , mm :: IArray , aa...
128The ISAAC Cipher
8haskell
kg0h0
import Data.Decimal import Data.Ratio import Data.Complex
129Test integerness
8haskell
sazqk
print "\a";
127Terminal control/Ringing the terminal bell
2perl
p7ib0
use std::io::{stdout, Write}; use std::time::Duration; fn main() { let mut output = stdout(); print!("\x1b[?1049h\x1b[H"); println!("Alternate screen buffer"); for i in (1..=5).rev() { print!("\rgoing back in {}...", i); output.flush().unwrap(); std::thread::sleep(Duration::fr...
131Terminal control/Preserve screen
15rust
g2p4o
int main () { printf (); napms (5000); curs_set (0); printf (); napms (5000); printf (); return 0; }
133Terminal control/Hiding the cursor
5c
4lh5t
int main() { printf(); return 0; }
134Terminal control/Inverse video
5c
5c7uk
import curses from random import randint stdscr = curses.initscr() for rows in range(10): line = ''.join([chr(randint(41, 90)) for i in range(10)]) stdscr.addstr(line + '\n') icol = 3 - 1 irow = 6 - 1 ch = stdscr.instr(irow, icol, 1).decode(encoding=) stdscr.move(irow, icol + 10) stdscr.addstr('Character...
132Terminal control/Positional read
3python
vm729
import java.math.BigDecimal; import java.util.List; public class TestIntegerness { private static boolean isLong(double d) { return isLong(d, 0.0); } private static boolean isLong(double d, double tolerance) { return (d - Math.floor(d)) <= tolerance || (Math.ceil(d) - d) <= tolerance; ...
129Test integerness
9java
1jop2
package pal import "testing" func TestPals(t *testing.T) { pals := []string{ "", ".", "11", "ere", "ingirumimusnocteetconsumimurigni", } for _, s := range pals { if !IsPal(s) { t.Error("IsPal returned false on palindrome,", s) } } } ...
130Test a function
0go
satqa
<?php echo ;
127Terminal control/Ringing the terminal bell
12php
yfr61
print("\033[?1049h\033[H") println("Alternate buffer!") for (i <- 5 to 0 by -1) { println(s"Going back in: $i") Thread.sleep(1000) } print("\033[?1049l")
131Terminal control/Preserve screen
16scala
j5e7i
public let CSI = ESC+"["
131Terminal control/Preserve screen
17swift
5cku8
package main import ( "os" "os/exec" "time" ) func main() { tput("civis")
133Terminal control/Hiding the cursor
0go
oxt8q
package main import ( "fmt" "os" "os/exec" ) func main() { tput("rev") fmt.Print("Rosetta") tput("sgr0") fmt.Println(" Code") } func tput(arg string) error { cmd := exec.Command("tput", arg) cmd.Stdout = os.Stdout return cmd.Run() }
134Terminal control/Inverse video
0go
8wd0g
int main() { puts(); puts(); return 0; }
135Terminal control/Display an extended character
5c
q18xc
import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.Random; public class IsaacRandom extends Random { private static final long serialVersionUID = 1L; private final int[] randResult = new int[256];
128The ISAAC Cipher
9java
4la58
import Test.QuickCheck isPalindrome :: String -> Bool isPalindrome x = x == reverse x instance Arbitrary Char where arbitrary = choose ('\32', '\127') main = do putStr "Even palindromes: " >> quickCheck (\s -> isPalindrome (s ++ reverse s)) putStr "Odd palindromes: " >> quickCheck (\s...
130Test a function
8haskell
9zgmo
null
133Terminal control/Hiding the cursor
11kotlin
d06nz
null
134Terminal control/Inverse video
11kotlin
nszij
(println "")
135Terminal control/Display an extended character
6clojure
iqfom
null
129Test integerness
11kotlin
j5x7r
use strict; my $out = 0; my $max_out = -1; my @max_times; open FH, '<mlijobs.txt' or die "Can't open file: $!"; while (<FH>) { chomp; if (/OUT/) { $out++; } else { $out--; } if ($out > $max_out) { $max_out = $out; @max_times = (); } if ($out == $max_out) { ...
125Text processing/Max licenses in use
2perl
4lx5d
import static ExampleClass.pali;
130Test a function
9java
tolf9
print
127Terminal control/Ringing the terminal bell
3python
1jnpc
alarm()
127Terminal control/Ringing the terminal bell
13r
h40jj
print "\e[?25l"; print "Enter anything, press RETURN: "; $input = <>; print "\e[0H\e[0J\e[?25h";
133Terminal control/Hiding the cursor
2perl
j517f
print "normal\n"; system "tput rev"; print "reversed\n"; system "tput sgr0"; print "normal\n";
134Terminal control/Inverse video
2perl
7ubrh
static int badHrs, maxBadHrs; static double hrsTot = 0.0; static int rdgsTot = 0; char bhEndDate[40]; int mungeLine( char *line, int lno, FILE *fout ) { char date[40], *tkn; int dHrs, flag, hrs2, hrs; double hrsSum; int hrsCnt = 0; double avg; tkn = strtok(line, ); if (tkn) { ...
136Text processing/1
5c
3nyza
null
128The ISAAC Cipher
11kotlin
l6hcp
function isInt (x) return type(x) == "number" and x == math.floor(x) end print("Value\tInteger?") print("=====\t========") local testCases = {2, 0, -1, 3.5, "String!", true} for _, input in pairs(testCases) do print(input, isInt(input)) end
129Test integerness
1lua
h4qj8
const assert = require('assert'); describe('palindrome', () => { const pali = require('../lib/palindrome'); describe('.check()', () => { it('should return true on encountering a palindrome', () => { assert.ok(pali.check('racecar')); assert.ok(pali.check('abcba')); assert.ok(pali.check('aa'))...
130Test a function
10javascript
mt4yv
print() print()
133Terminal control/Hiding the cursor
3python
h4ajw
cat("\x1b[?25l") Sys.sleep(2) cat("\x1b[?25h")
133Terminal control/Hiding the cursor
13r
g2k47
print
134Terminal control/Inverse video
3python
j5p7p
int main() { struct winsize ws; int fd; fd = open(, O_RDWR); if (fd < 0) err(1, ); if (ioctl(fd, TIOCGWINSZ, &ws) < 0) err(1, ); printf(, ws.ws_row, ws.ws_col); printf(, ws.ws_xpixel, ws.ws_ypixel); close(fd); return 0; }
137Terminal control/Dimensions
5c
rv7g7
package main import "fmt" func main() { fmt.Println("") }
135Terminal control/Display an extended character
0go
2y5l7
module Main where main = do putStrLn "" putStrLn ""
135Terminal control/Display an extended character
8haskell
ahx1g
#!/usr/bin/env lua
128The ISAAC Cipher
1lua
2ykl3
$handle = fopen (, ); $maxcount = 0; $count = 0; $times = array(); while (!feof($handle)) { $buffer = fgets($handle); $op = trim(substr($buffer,8,3)); switch ($op){ case 'IN': $count--; break; case 'OUT': $count++; preg_match('/([\d|\/|_|:]+)/',$bu...
125Text processing/Max licenses in use
12php
iq2ov
print
127Terminal control/Ringing the terminal bell
14ruby
ekfax
fn main() { print!("\x07"); }
127Terminal control/Ringing the terminal bell
15rust
wbte4
java.awt.Toolkit.getDefaultToolkit().beep()
127Terminal control/Ringing the terminal bell
16scala
sa6qo
require include Curses init_screen begin curs_set(1) sleep 3 curs_set(0) sleep 3 curs_set(1) sleep 3 ensure close_screen end
133Terminal control/Hiding the cursor
14ruby
brwkq
object Main extends App { print("\u001B[?25l")
133Terminal control/Hiding the cursor
16scala
ek0ab
puts
134Terminal control/Inverse video
14ruby
kgahg
object Main extends App { println("\u001B[7mInverse\u001B[m Normal") }
134Terminal control/Inverse video
16scala
ahq1n
typedef enum { TRITTRUE, TRITMAYBE, TRITFALSE } trit; trit tritNot[3] = {TRITFALSE , TRITMAYBE, TRITTRUE}; trit tritAnd[3][3] = { {TRITTRUE, TRITMAYBE, TRITFALSE}, {TRITMAYBE, TRITMAYBE, TRITFALSE}, {TRITFALSE, TRITFALSE, TRITFALSE} }; trit tritOr[3][3] = { {T...
138Ternary logic
5c
8w804
import java.io.PrintStream; import java.io.UnsupportedEncodingException; public class Main { public static void main(String[] args) throws UnsupportedEncodingException { PrintStream writer = new PrintStream(System.out, true, "UTF-8"); writer.println(""); writer.println(""); } }
135Terminal control/Display an extended character
9java
j5b7c
null
135Terminal control/Display an extended character
11kotlin
5crua
(ns rosettacode.textprocessing1 (:require [clojure.string:as str])) (defn parse-line [s] (let [[date & data-toks] (str/split s #"\s+")] {:date date :hour-vals (for [[v flag] (partition 2 data-toks)] {:val (Double. v) :flag (Long. flag)})})) (defn analyze-line [m] (le...
136Text processing/1
6clojure
c329b
use Math::Complex; sub is_int { my $number = shift; if (ref $number eq 'Math::Complex') { return 0 if $number->Im != 0; $number = $number->Re; } return int($number) == $number; } for (5, 4.1, sqrt(2), sqrt(4), 1.1e10, 3.0-0.0*i, 4-3*i, 5.6+0*i) { printf "%20s is%s an integer\n", ...
129Test integerness
2perl
to2fg
null
130Test a function
11kotlin
ox68z
int main() { int i,j; char days[12][10] = { , , , , , , , , , , , }; char gifts[12][33] = { , , , , , , , , , , ...
139The Twelve Days of Christmas
5c
s1xq5
print(string.char(156))
135Terminal control/Display an extended character
1lua
4l75c
assert( ispalindrome("ABCBA") ) assert( ispalindrome("ABCDE") )
130Test a function
1lua
iqyot
package main import ( "fmt" "os" "golang.org/x/crypto/ssh/terminal" ) func main() { w, h, err := terminal.GetSize(int(os.Stdout.Fd())) if err != nil { fmt.Println(err) return } fmt.Println(h, w) }
137Terminal control/Dimensions
0go
nsdi1
package main import ( "bytes" "fmt" "os" "os/exec" ) func main() { cmd := exec.Command("tput", "-S") cmd.Stdin = bytes.NewBufferString("clear\ncup 5 2") cmd.Stdout = os.Stdout cmd.Run() fmt.Println("Hello") }
140Terminal control/Cursor positioning
0go
4cv52
use feature 'say'; say ''; binmode STDOUT, ":utf8"; say "\N{FULLWIDTH POUND SIGN}"; say "\x{FFE1}"; say chr 0xffe1;
135Terminal control/Display an extended character
2perl
oxd8x
null
137Terminal control/Dimensions
11kotlin
tozf0
null
140Terminal control/Cursor positioning
11kotlin
7v4r4
print u'\u00a3'
135Terminal control/Display an extended character
3python
iqfof