code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
import Math.{addExact => ++, multiplyExact => **, negateExact => ~~, subtractExact => --} def requireOverflow(f: => Unit) = try {f; println("Undetected overflow")} catch{case e: Exception => } println("Testing overflow detection for 32-bit unsigned integers") requireOverflow(~~(--(~~(2147483647), 1)))
710Integer overflow
16scala
azv1n
if File.exist? @data = Marshal.load open() else @data = {} end class String def index_sanitize self.split.collect do |token| token.downcase.gsub(/\W/, '') end end end ARGV.each do |filename| open filename do |file| file.read.index_sanitize.each do |word| @data[word] ||= [] ...
708Inverted index
14ruby
5xzuj
const starttxt = """ ATTENTION ALL WUMPUS LOVERS!!! THERE ARE NOW TWO ADDITIONS TO THE WUMPUS FAMILY OF PROGRAMS. WUMP2: SOME DIFFERENT CAVE ARRANGEMENTS WUMP3: DIFFERENT HAZARDS """ const helptxt = """ WELCOME TO 'HUNT THE WUMPUS' THE WUMPUS LIVES IN A CAVE OF 20 ROOMS. EACH...
724Hunt the Wumpus
9java
qmtxa
use strict; use warnings; use feature 'say'; use Math::Complex; use List::AllUtils qw(sum mesh); use ntheory qw<todigitstring fromdigits>; sub zip { my($a,$b) = @_; my($la, $lb) = (length $a, length $b); my $l = '0' x abs $la - $lb; $a .= $l if $la < $lb; $b .= $l if $lb < $la; (join('', mesh(...
720Imaginary base numbers
2perl
w63e6
import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.util.Arrays; import java.util.Random; import javax.swing.*; public class ImageNoise { int framecount = 0; int fps = 0; BufferedImage image; Kernel kernel; ConvolveOp cop; JFrame frame = new JFrame("Java Image Noise...
722Image noise
9java
nulih
null
708Inverted index
15rust
4q35u
char * incr(char *s) { int i, begin, tail, len; int neg = (*s == '-'); char tgt = neg ? '0' : '9'; if (!strcmp(s, )) { s[0] = '0', s[1] = '\0'; return s; } len = strlen(s); begin = (*s == '-' || *s == '+') ? 1 : 0; for (tail = len - 1; tail >= begin && s[tail] == tgt; tail--); if (tail < begin && !...
727Increment a numerical string
5c
781rg
package Animal; 1;
712Inheritance/Single
2perl
9bqmn
class Animal { } class Dog extends Animal { } class Cat extends Animal { } class Lab extends Dog { } class Collie extends Dog { }
712Inheritance/Single
12php
w6vep
const starttxt = """ ATTENTION ALL WUMPUS LOVERS!!! THERE ARE NOW TWO ADDITIONS TO THE WUMPUS FAMILY OF PROGRAMS. WUMP2: SOME DIFFERENT CAVE ARRANGEMENTS WUMP3: DIFFERENT HAZARDS """ const helptxt = """ WELCOME TO 'HUNT THE WUMPUS' THE WUMPUS LIVES IN A CAVE OF 20 ROOMS. EACH...
724Hunt the Wumpus
10javascript
ivmol
<body> <canvas id='c'></canvas> <script> var canvas = document.getElementById('c'); var ctx = canvas.getContext('2d'); var w = canvas.width = 320; var h = canvas.height = 240; var t1 = new Date().getTime(); var frame_count = 0; ctx.font = 'normal 400 24px/2 Unknown Font, sans-serif'; var img = ctx.createImageData(w, ...
722Image noise
10javascript
374z0
null
710Integer overflow
17swift
himj0
lines = {} str = io.read() while str do table.insert(lines,str) str = io.read() end
713Input loop
1lua
zrpty
object InvertedIndex extends App { import java.io.File
708Inverted index
16scala
78mr9
exit if RUBY_VERSION < '1.8.6' puts bloop.abs if defined?(bloop) and bloop.respond_to?(:abs)
709Introspection
14ruby
bdlkq
import math import re def inv(c): denom = c.real * c.real + c.imag * c.imag return complex(c.real / denom, -c.imag / denom) class QuaterImaginary: twoI = complex(0, 2) invTwoI = inv(twoI) def __init__(self, str): if not re.match(, str) or str.count('.') > 1: raise Exception('I...
720Imaginary base numbers
3python
xy6wr
null
722Image noise
11kotlin
s96q7
use strict; use warnings; use PDL; use PDL::Image2D; my $kernel = pdl [[-2, -1, 0],[-1, 1, 1], [0, 1, 2]]; my $image = rpic 'pythagoras_tree.png'; my $smoothed = conv2d $image, $kernel, {Boundary => 'Truncate'}; wpic $smoothed, 'pythagoras_convolution.png';
721Image convolution
2perl
0cms4
object VersCheck extends App { val minimalVersion = 1.7 val vers = System.getProperty("java.specification.version"); println(if (vers.toDouble >= minimalVersion) "YAY!" else s"Must use Java >= $minimalVersion"); val bloop = Option(-42) if (bloop.isDefined) bloop.get.abs }
709Introspection
16scala
e35ab
>>> def j(n, k): p, i, seq = list(range(n)), 0, [] while p: i = (i+k-1)% len(p) seq.append(p.pop(i)) return 'Prisoner killing order:%s.\nSurvivor:%i'% (', '.join(str(i) for i in seq[:-1]), seq[-1]) >>> print(j(5, 2)) Prisoner killing order: 1, 3, 0, 4. Survivor: 2 >>> print(j(41, 3)) Prisoner killing order: 2, ...
702Josephus problem
3python
37nzc
null
723Include a file
0go
xytwf
class Animal: pass class Dog(Animal): pass class Cat(Animal): pass class Lab(Dog): pass class Collie(Dog): pass
712Inheritance/Single
3python
cps9q
aCollie <- "woof" class(aCollie) <- c("Collie", "Dog", "Animal")
712Inheritance/Single
13r
6je3e
use strict; use warnings; use List::Util qw( shuffle ); $| = 1; my %tunnels = qw(A BKT B ACL C BDM D CEN E DFO F EGP G FHQ H GIR I HJS J IKT K AJL L BKM M CLN N DMO O ENP P FOQ Q GPR R HQS S IRT T AJS); my ($you, $wumpus, $bat1, $bat2, $pit1, $pit2) = shuffle keys %tunnels; my $arrows = 5; print "\nTo shoot, enter ...
724Hunt the Wumpus
2perl
mkgyz
from PIL import Image, ImageFilter if __name__==: im = Image.open() kernelValues = [-2,-1,0,-1,1,1,0,1,2] kernel = ImageFilter.Kernel((3,3), kernelValues) im2 = im.filter(kernel) im2.show()
721Image convolution
3python
8l90o
package main import "fmt" func main() { for i := 1;; i++ { fmt.Println(i) } }
714Integer sequence
0go
5xoul
%{ int cie, cei, ie, ei; %} %% cie ++cie, ++ie; cei ++cei, ++ei; ie ++ie; ei ++ei; .|\n ; %% int main() { cie = cei = ie = ei = 0; yylex(); printf(,, (2*ei < ie ? : )); printf(,, (2*cie < cei ? : )); printf(,, (2*(cie+ei) < (cei+ie) ? : )); return 0; }
728I before E except after C
5c
f4yd3
(str (inc (Integer/parseInt "1234")))
727Increment a numerical string
6clojure
pfqbd
(let [[a b] (repeatedly read)] (doseq [[op string] [[< "less than"] [> "greater than"] [= "equal to"]]] (when (op a b) (println (str a " is " string " " b)))))
725Integer comparison
6clojure
l17cb
import SomeModule #include "SomeModule.hs"
723Include a file
8haskell
yhg66
int valid_cc(const char *iban, int len) { V(, 28); V(, 24); V(, 20); V(, 28); V(, 16); V(, 22); V(, 20); V(, 29); V(, 22); V(, 21); V(, 21); V(, 28); V(, 24); V(, 18); V(, 28); V(, 20); V(, 18); V(, 18); V(, 27); V(, 22); V(, 22); V(, 23); V(, 27); V(, 18); V(, 28); V(, 28); V(, 26); V(, 22); V(, 23); V...
729IBAN
5c
0cnst
def base2i_decode(qi) return 0 if qi == '0' md = qi.match(/^(?<int>[0-3]+)(?:\.(?<frc>[0-3]+))?$/) raise 'ill-formed quarter-imaginary base value' if!md ls_pow = md[:frc]? -(md[:frc].length): 0 value = 0 (md[:int] + (md[:frc]? md[:frc]: '')).reverse.each_char.with_index do |dig, inx| value += dig.to_i *...
720Imaginary base numbers
14ruby
s9mqw
null
714Integer sequence
7groovy
cpx9i
my $x = 0 + "inf"; my $y = 0 + "+inf";
716Infinity
2perl
f47d7
jose <-function(s, r,n){ y <- 0:(r-1) for (i in (r+1):n) y <- (y + s) %% i return(y) } > jose(3,1,41) [1] 30
702Josephus problem
13r
d50nt
class Animal def self.inherited(subclass) puts end end class Dog < Animal end class Cat < Animal end class Lab < Dog end class Collie < Dog end
712Inheritance/Single
14ruby
2a8lw
trait Animal {} trait Cat: Animal {} trait Dog: Animal {} trait Lab: Dog {} trait Collie: Dog {}
712Inheritance/Single
15rust
veo2t
class Animal class Dog extends Animal class Cat extends Animal class Lab extends Dog class Collie extends Dog
712Inheritance/Single
16scala
4qd50
class Pixmap def convolute(kernel) newimg = Pixmap.new(@width, @height) pb = ProgressBar.new(@width) if $DEBUG @width.times do |x| @height.times do |y| apply_kernel(x, y, kernel, newimg) end pb.update(x) if $DEBUG end pb.close if $DEBUG newimg end def apply...
721Image convolution
14ruby
ivloh
INF
716Infinity
12php
hifjf
public class Class1 extends Class2 {
723Include a file
9java
d5ln9
var s = document.createElement('script'); s.type = 'application/javascript';
723Include a file
10javascript
6j438
for i in `seq $1`;do printf '%*s\n' $1|tr ' ' '0'|sed "s/0/1/$i";done
730Identity matrix
4bash
ivfop
import random class WumpusGame(object): def __init__(self, edges=[]): if edges: cave = {} N = max([edges[i][0] for i in range(len(edges))]) for i in range(N): exits = [edge[1] for edge in edges if edge[0] == i] cave[i] = exits else: cave = {1: [2,3,4], 2: [1,5,6], 3: [1,7,8], 4: [1,9...
724Hunt the Wumpus
3python
9brmf
mapM_ print [1..]
714Integer sequence
8haskell
xy2w4
(ns i-before-e.core (:require [clojure.string:as s]) (:gen-class)) (def patterns {:cie #"cie":ie #"(?<!c)ie":cei #"cei":ei #"(?<!c)ei"}) (defn update-counts "Given a map of counts of matching patterns and a word, increment any count if the word matches it's pattern." [counts [word freq]] (apply hash-map (ma...
728I before E except after C
6clojure
yh26b
fun f() = println("f called")
723Include a file
11kotlin
0c6sf
class Animal {
712Inheritance/Single
17swift
l10c2
package main import ( "fmt" "math/big" ) var ( one = new(big.Int).SetUint64(1) two = new(big.Int).SetUint64(2) three = new(big.Int).SetUint64(3) five = new(big.Int).SetUint64(5) seven = new(big.Int).SetUint64(7) ten = new(big.Int).SetUint64(10) ) func min(a, b *big.Int) *big.In...
726Humble numbers
0go
xynwf
>>> float('infinity') inf
716Infinity
3python
tgjfw
(def explen {"AL" 28 "AD" 24 "AT" 20 "AZ" 28 "BE" 16 "BH" 22 "BA" 20 "BR" 29 "BG" 22 "CR" 21 "HR" 21 "CY" 28 "CZ" 24 "DK" 18 "DO" 28 "EE" 20 "FO" 18 "FI" 18 "FR" 27 "GE" 22 "DE" 22 "GI" 23 "GR" 27 "GL" 18 "GT" 28 "HU" 28 "IS" 26 "IE" 22 "IL" 23 "IT" 27 "KZ" 20 "KW" 30 "LV" 21 "LB" 28 "LI" 21 "LT" 20 "LU" ...
729IBAN
6clojure
d53nb
import Data.Set (deleteFindMin, fromList, union) import Data.List.Split (chunksOf) import Data.List (group) import Data.Bool (bool) humbles :: [Integer] humbles = go $ fromList [1] where go sofar = x: go (union pruned $ fromList ((x *) <$> [2, 3, 5, 7])) where (x, pruned) = deleteFindMin sofar ...
726Humble numbers
8haskell
yhu66
-- HUNT THE WUMPUS -- BY GREGORY YOB -- SenseTalk adaptation by Jonathan Gover answer with or if it is then showInstructions -- SET UP CAVE (DODECAHEDRAL NODE LIST) set rooms to [ [2,5,8],[1,3,10],[2,4,12],[3,5,14],[1,4,6], [5,7,15],[6,8,17],[1,7,9],[8,10,18],[2,9,11], [10,12,19],[3,11,13],[12,14,20],[4,13,15...
724Hunt the Wumpus
14ruby
l1jcl
use Gtk3 '-init'; use Glib qw/TRUE FALSE/; use Time::HiRes qw/ tv_interval gettimeofday/; my $time0 = [gettimeofday]; my $frames = -8; my $window = Gtk3::Window->new(); $window->set_default_size(320, 240); $window->set_border_width(0); $window->set_title("Image_noise"); $window->set_app_paintable(TRUE); my $da = Gt...
722Image noise
2perl
uw1vr
public class Count{ public static void main(String[] args){ for(long i = 1; ;i++) System.out.println(i); } }
714Integer sequence
9java
bd6k3
Inf -Inf .Machine$double.xmax is.finite forcefinite <- function(x) ifelse(is.finite(x), x, sign(x)*.Machine$double.xmax) forcefinite(c(1, -1, 0, .Machine$double.xmax, -.Machine$double.xmax, Inf, -Inf))
716Infinity
13r
iv4o5
require "myheader"
723Include a file
1lua
8ly0e
import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; public class HumbleNumbers { public static void main(String[] args) { System.out.println("First 50 humble numbers:"); ...
726Humble numbers
9java
d5mn9
-- HUNT THE WUMPUS -- BY GREGORY YOB -- SenseTalk adaptation by Jonathan Gover answer "INSTRUCTIONS (Y-N)" with "No" or "Yes" if it is "Yes" then showInstructions -- SET UP CAVE (DODECAHEDRAL NODE LIST) set rooms to [ [2,5,8],[1,3,10],[2,4,12],[3,5,14],[1,4,6], [5,7,15],[6,8,17],[1,7,9],[8,10,18],[2,9,11], [10,12...
724Hunt the Wumpus
15rust
2ahlt
var i = 0; while (true) document.write(++i + ' ');
714Integer sequence
10javascript
w6le2
a = 1.0/0 a.finite? a.infinite? a = -1/0.0 a.infinite? a = Float::MAX a.finite? a.infinite?
716Infinity
14ruby
37kz7
fn main() { let inf = f32::INFINITY; println!("{}", inf); }
716Infinity
15rust
6jb3l
val inf = Double.PositiveInfinity
716Infinity
16scala
9bam5
(() => { 'use strict';
726Humble numbers
10javascript
6jv38
import Foundation
724Hunt the Wumpus
17swift
cp79t
open FH, "< $filename" or die "can't open file: $!"; while (my $line = <FH>) { chomp $line; } close FH or die "can't close file: $!";
713Input loop
2perl
kn6hc
n = (ARGV[0] || 41).to_i k = (ARGV[1] || 3).to_i prisoners = (0...n).to_a prisoners.rotate!(k-1).shift while prisoners.length > 1 puts prisoners.first
702Josephus problem
14ruby
yhf6n
int main(int argc, char** argv) { if (argc < 2) { printf(); exit(EXIT_FAILURE); } int rowsize = atoi(argv[1]); if (rowsize < 0) { printf(); exit(EXIT_FAILURE); } int numElements = rowsize * rowsize; if (numElements < rowsize) { printf(, rowsize, numElements); abo...
730Identity matrix
5c
d5znv
import java.math.BigInteger
714Integer sequence
11kotlin
r0dgo
let inf = Double.infinity inf.isInfinite
716Infinity
17swift
zrhtu
$fh = fopen($filename, 'r'); if ($fh) { while (!feof($fh)) { $line = rtrim(fgets($fh)); } fclose($fh); }
713Input loop
12php
371zq
const N: usize = 41; const K: usize = 3; const M: usize = 3; const POSITION: usize = 5; fn main() { let mut prisoners: Vec<usize> = Vec::new(); let mut executed: Vec<usize> = Vec::new(); for pos in 0..N { prisoners.push(pos); } let mut to_kill: usize = 0; let mut len: usize = prisoners...
702Josephus problem
15rust
mktya
fun isHumble(i: Int): Boolean { if (i <= 1) return true if (i % 2 == 0) return isHumble(i / 2) if (i % 3 == 0) return isHumble(i / 3) if (i % 5 == 0) return isHumble(i / 5) if (i % 7 == 0) return isHumble(i / 7) return false } fun main() { val limit: Int = Short.MAX_VALUE.toInt() val hu...
726Humble numbers
11kotlin
0ctsf
import time import random import Tkinter import Image, ImageTk class App(object): def __init__(self, size, root): self.root = root self.root.title() self.img = Image.new(, size) self.label = Tkinter.Label(root) self.label.pack() self.time = 0.0 self.frames...
722Image noise
3python
5xaux
def executed( prisonerCount:Int, step:Int ) = { val prisoners = ((0 until prisonerCount) map (_.toString)).toList def behead( dead:Seq[String], alive:Seq[String] )(countOff:Int) : (Seq[String], Seq[String]) = { val group = if( alive.size < countOff ) countOff - alive.size else countOff (dead ++ alive.tak...
702Josephus problem
16scala
l16cq
function isHumble(n) local n2 = math.floor(n) if n2 <= 1 then return true end if n2 % 2 == 0 then return isHumble(n2 / 2) end if n2 % 3 == 0 then return isHumble(n2 / 3) end if n2 % 5 == 0 then return isHumble(n2 / 5) end if n2 % 7 == 0 then ...
726Humble numbers
1lua
8lz0e
while(True): x = input() print(x)
713Input loop
3python
bdykr
lines <- readLines("file.txt")
713Input loop
13r
78try
'( (0 1) (2 3) )
730Identity matrix
6clojure
6j93q
require 'rubygems' require 'gl' require 'glut' W, H = 320, 240 SIZE = W * H Glut.glutInit ARGV Glut.glutInitWindowSize W, H Glut.glutIdleFunc lambda { i = Time.now noise = (1..SIZE).map { rand > 0.5? 0xFFFFFFFF: 0xFF000000 }.pack() Gl.glClear Gl::GL_COLOR_BUFFER_BIT Gl.glDrawPixels W, H, Gl::GL_RGBA, Gl::GL...
722Image noise
14ruby
gsw4q
use strict; use warnings; use List::Util 'min'; use Math::GMPz; sub humble_gen { my @s = ([1], [1], [1], [1]); my @m = (2, 3, 5, 7); @m = map { Math::GMPz->new($_) } @m; return sub { my $n = min $s[0][0], $s[1][0], $s[2][0], $s[3][0]; for (0..3) { shift @{$s[$_]} if $s[$_][0] =...
726Humble numbers
2perl
5xku2
import java.awt.event.{ActionEvent, ActionListener} import swing.{Panel, MainFrame, SimpleSwingApplication} import javax.swing.Timer import java.awt.{Font, Color, Graphics2D, Dimension} object ImageNoise extends SimpleSwingApplication { var delay_ms = 2 var framecount = 0 var fps = 0 def top = new MainFrame {...
722Image noise
16scala
hi0ja
i = 1
714Integer sequence
1lua
78fru
class Josephus { class func lineUp(#numberOfPeople:Int) -> [Int] { var people = [Int]() for (var i = 0; i < numberOfPeople; i++) { people.append(i) } return people } class func execute(#numberOfPeople:Int, spacing:Int) -> Int { var killIndex = 0 ...
702Josephus problem
17swift
6jd3j
do "include.pl"; sayhello();
723Include a file
2perl
5x1u2
stream = $stdin stream.each do |line| end
713Input loop
14ruby
1t9pw
function josephus(n: number, k: number): number { if (!n) { return 1; } return ((josephus(n - 1, k) + k - 1)% n) + 1; }
702Josephus problem
20typescript
jo57l
include()
723Include a file
12php
o2m85
use std::io::{self, BufReader, Read, BufRead}; use std::fs::File; fn main() { print_by_line(io::stdin()) .expect("Could not read from stdin"); File::open("/etc/fstab") .and_then(print_by_line) .expect("Could not read from file"); } fn print_by_line<T: Read>(reader: T) -> io::Result<()...
713Input loop
15rust
azc14
scala.io.Source.fromFile("input.txt").getLines().foreach { line => ... }
713Input loop
16scala
xyvwg
package main import ( "bufio" "fmt" "log" "os" "regexp" "strings" ) func main() { f, err := os.Open("unixdict.txt") if err != nil { log.Fatalln(err) } defer f.Close() s := bufio.NewScanner(f) rie := regexp.MustCompile("^ie|[^c]ie") rei := regexp.MustCompile("^ei|[^c]ei") var cie, ie int var cei, ei ...
728I before E except after C
0go
jo17d
package main import ( "regexp" "strings" "testing" ) var lengthByCountryCode = map[string]int{ "AL": 28, "AD": 24, "AT": 20, "AZ": 28, "BE": 16, "BH": 22, "BA": 20, "BR": 29, "BG": 22, "CR": 21, "HR": 21, "CY": 28, "CZ": 24, "DK": 18, "DO": 28, "EE": 20, "FO": 18, "FI": 18, "FR": 27, "GE": 22, "DE": 22, "GI": ...
729IBAN
0go
uwrvt
import Network.HTTP import Text.Regex.TDFA import Text.Printf getWordList :: IO String getWordList = do response <- simpleHTTP.getRequest$ url getResponseBody response where url = "http://wiki.puzzlers.org/pub/wordlists/unixdict.txt" main = do words <- getWordList putStrLn "Checking Rule 1...
728I before E except after C
8haskell
o2t8p
package main import "fmt" import "strconv" func main() { i, _ := strconv.Atoi("1234") fmt.Println(strconv.Itoa(i + 1)) }
727Increment a numerical string
0go
d5yne
import mymodule
723Include a file
3python
4qa5k
def validateIBAN(String iban) { def iso = [AL: 28, AD: 24, AT: 20, AZ: 28, BE: 16, BH: 22, BA: 20, BR: 29, BG: 22, HR: 21, CY: 28, CZ: 24, DK: 18, DO: 28, EE: 20, FO: 18, FI: 18, FR: 27, GE: 22, DE: 22, GI: 23, GL: 18, GT: 28, HU: 28, IS: 26, IE: 22, IL: 23, IT: 27, KZ: 20, KW: 30, LV: 21, L...
729IBAN
7groovy
9bvm4
'''Humble numbers''' from itertools import groupby, islice from functools import reduce def humbles(): '''A non-finite stream of Humble numbers. OEIS A002473 ''' hs = set([1]) while True: nxt = min(hs) yield nxt hs.remove(nxt) hs.update(nxt * x for x in [2, 3, ...
726Humble numbers
3python
4qb5k
println ((("23455" as BigDecimal) + 1) as String) println ((("23455.78" as BigDecimal) + 1) as String)
727Increment a numerical string
7groovy
0cfsh
source("filename.R")
723Include a file
13r
2aklg
import Data.Char (toUpper) import Data.Maybe (fromJust) validateIBAN :: String -> Either String String validateIBAN [] = Left "No IBAN number." validateIBAN xs = case lookupCountry of Nothing -> invalidBecause "Country does not exist." Just l -> if length normalized /= l th...
729IBAN
8haskell
w60ed