code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
MyClass::method($someParameter); $foo = 'MyClass'; $foo::method($someParameter); $myInstance->method($someParameter);
1,065Call an object method
12php
kazhv
char *list; const char *line = ; int len = 0; int irand(int n) { int r, rand_max = RAND_MAX - (RAND_MAX % n); do { r = rand(); } while(r >= rand_max); return r / (rand_max / n); } char* get_digits(int n, char *ret) { int i, j; char d[] = ; for (i = 0; i < n; i++) { j = irand(9 - i); ret[i] = d[i + j]; i...
1,073Bulls and cows/Player
5c
rkwg7
tcc -DSTRUCT=struct -DCONST=const -DINT=int -DCHAR=char -DVOID=void -DMAIN=main -DIF=if -DELSE=else -DWHILE=while -DFOR=for -DDO=do -DBREAK=break -DRETURN=return -DPUTCHAR=putchar UCCALENDAR.c
1,074Calendar - for "REAL" programmers
5c
8d604
package main
1,070Call a foreign-language function
0go
8dc0g
fn compare_co9_efficiency(base: u64, upto: u64) { let naive_candidates: Vec<u64> = (1u64..upto).collect(); let co9_candidates: Vec<u64> = naive_candidates.iter().cloned() .filter(|&x| x% (base - 1) == (x * x)% (base - 1)) .collect(); for candidate in &co9_candidates { print!("{} ", c...
1,060Casting out nines
15rust
1x2pu
object kaprekar{
1,060Casting out nines
16scala
w05es
fn main() { let dog = "Benjamin"; let Dog = "Samba"; let DOG = "Bernie"; println!("The three dogs are named {}, {} and {}.", dog, Dog, DOG); }
1,057Case-sensitivity of identifiers
15rust
573uq
val dog = "Benjamin" val Dog = "Samba" val DOG = "Bernie" println("There are three dogs named " + dog + ", " + Dog + ", and " + DOG + ".")
1,057Case-sensitivity of identifiers
16scala
rkmgn
sub cartesian { my $sets = shift @_; for (@$sets) { return [] unless @$_ } my $products = [[]]; for my $set (reverse @$sets) { my $partial = $products; $products = []; for my $item (@$set) { for my $product (@$partial) { push @$products, [$item, @$pro...
1,058Cartesian product of two or more lists
2perl
gh64e
import ctypes user32_dll = ctypes.cdll.LoadLibrary('User32.dll') print user32_dll.GetDoubleClickTime()
1,066Call a function in a shared library
3python
rkigq
(defn inverse-plus-1 [n] (+ 1 (/ 1 n))) (defn e-return [n] (Math/pow (inverse-plus-1 n) n)) (time (e-return 100000.)) (defn method-e [n] (loop [e-aprx 0M value-add 1M p 1M] (if (> p n) e-aprx (recur (+ e-aprx value-add) (/ value-add p) (inc p))))) (time (with-precision 110 (m...
1,072Calculating the value of e
6clojure
cuh9b
import Foreign (free) import Foreign.C.String (CString, withCString, peekCString) foreign import ccall unsafe "string.h strdup" strdup :: CString -> IO CString testC = withCString "Hello World!" (\s -> do s2 <- strdup s s2_hs <- peekCString s2 putStrLn s2_hs f...
1,070Call a foreign-language function
8haskell
l5pch
null
1,067Cantor set
11kotlin
qocx1
cw = Enumerator.new do |y| y << a = 1.to_r loop { y << a = 1/(2*a.floor + 1 - a) } end def term_num(rat) num, den, res, pwr, dig = rat.numerator, rat.denominator, 0, 0, 1 while den > 0 num, (digit, den) = den, num.divmod(den) digit.times do res |= dig << pwr pwr += 1 end dig ^= 1 ...
1,069Calkin-Wilf sequence
14ruby
bedkq
null
1,069Calkin-Wilf sequence
15rust
pwfbu
require 'prime' Prime.each(61) do |p| (2...p).each do |h3| g = h3 + p (1...g).each do |d| next if (g*(p-1)) % d!= 0 or (-p*p) % h3!= d % h3 q = 1 + ((p - 1) * g / d) next unless q.prime? r = 1 + (p * q / h3) next unless r.prime? and (q * r) % (p - 1) == 1 puts end ...
1,064Carmichael 3 strong pseudoprimes
14ruby
8d401
class MyClass(object): @classmethod def myClassMethod(self, x): pass @staticmethod def myStaticMethod(x): pass def myMethod(self, x): return 42 + x myInstance = MyClass() myInstance.myMethod(someParameter) MyClass.myMethod(myInstance, someParameter) MyClass.myClassMethod(someParameter) MyClass.myStati...
1,065Call an object method
3python
zmktt
dyn.load("my/special/R/lib.so") .Call("my_lib_fun", arg1, arg2)
1,066Call a function in a shared library
13r
ursvx
package main import ( "fmt" "sort" "strings" ) const stx = "\002" const etx = "\003" func bwt(s string) (string, error) { if strings.Index(s, stx) >= 0 || strings.Index(s, etx) >= 0 { return "", fmt.Errorf("String can't contain STX or ETX") } s = stx + s + etx le := len(s) tab...
1,071Burrows–Wheeler transform
0go
24pl7
local WIDTH = 81 local HEIGHT = 5 local lines = {} function cantor(start, length, index)
1,067Cantor set
1lua
silq8
fn is_prime(n: i64) -> bool { if n > 1 { (2..((n / 2) + 1)).all(|x| n% x!= 0) } else { false } }
1,064Carmichael 3 strong pseudoprimes
15rust
ofg83
package main import ( "fmt" "math" "rcu" "sort" ) var primes = rcu.Primes(1e8 - 1) type res struct { bc interface{} next int } func getBrilliant(digits, limit int, countOnly bool) res { var brilliant []int count := 0 pow := 1 next := math.MaxInt for k := 1; k <= digits;...
1,075Brilliant numbers
0go
vgh2m
class BWT { private static final String STX = "\u0002" private static final String ETX = "\u0003" private static String bwt(String s) { if (s.contains(STX) || s.contains(ETX)) { throw new IllegalArgumentException("String cannot contain STX or ETX") } String ss = STX + s...
1,071Burrows–Wheeler transform
7groovy
yl76o
public class JNIDemo { static { System.loadLibrary("JNIDemo"); } public static void main(String[] args) { System.out.println(callStrdup("Hello World!")); } private static native String callStrdup(String s); }
1,070Call a foreign-language function
9java
39rzg
MyClass.some_method(some_parameter) foo = MyClass foo.some_method(some_parameter) my_instance.a_method(some_parameter) my_instance.a_method some_parameter my_instance.another_method
1,065Call an object method
14ruby
6cp3t
struct Foo; impl Foo {
1,065Call an object method
15rust
yl168
require 'fiddle/import' module FakeImgLib extend Fiddle::Importer begin dlload './fakeimglib.so' extern 'int openimage(const char *)' rescue Fiddle::DLError @@handle = -1 def openimage(path) $stderr.puts @@handle += 1 end module_function :openimage end end handle = Fa...
1,066Call a function in a shared library
14ruby
jpd7x
import Control.Monad (join) import Data.Bifunctor (bimap) import Data.List (intercalate, transpose) import Data.List.Split (chunksOf, splitWhen) import Data.Numbers.Primes (primeFactors) import Text.Printf (printf) isBrilliant :: (Integral a, Show a) => a -> Bool isBrilliant n = case primeFactors n of [a, b] -> le...
1,075Brilliant numbers
8haskell
esiai
import Data.List ((!!), find, sort, tails, transpose) import Data.Maybe (fromJust) import Text.Printf (printf) newtype BWT a = BWT [Val a] bwt :: Ord a => [a] -> BWT a bwt xs = let n = length xs + 2 ys = transpose $ sort $ take n $ tails $ cycle $ pos xs in BWT $ ys !! (n-1) invBwt :: Ord a =>...
1,071Burrows–Wheeler transform
8haskell
aqf1g
#include <napi.h> #include <openssl/md5.h> #include <iomanip> #include <iostream> #include <sstream> #include <string> using namespace Napi; Napi::Value md5sum(const Napi::CallbackInfo& info) { std::string input = info[0].ToString(); unsigned char result[MD5_DIGEST_LENGTH]; MD5((unsigned char*)input.c_str(), i...
1,070Call a foreign-language function
10javascript
cub9j
import Foundation extension BinaryInteger { @inlinable public var isPrime: Bool { if self == 0 || self == 1 { return false } else if self == 2 { return true } let max = Self(ceil((Double(self).squareRoot()))) for i in stride(from: 2, through: max, by: 1) { if self% i == 0 { ...
1,064Carmichael 3 strong pseudoprimes
17swift
0n5s6
class MyClass(val memberVal: Int) {
1,065Call an object method
16scala
cuw93
#![allow(unused_unsafe)] extern crate libc; use std::io::{self,Write}; use std::{mem,ffi,process}; use libc::{c_double, RTLD_NOW};
1,066Call a function in a shared library
15rust
h1fj2
import net.java.dev.sna.SNA import com.sun.jna.ptr.IntByReference object GetDiskFreeSpace extends App with SNA { snaLibrary = "Kernel32"
1,066Call a function in a shared library
16scala
pw3bj
import java.util.*; public class BrilliantNumbers { public static void main(String[] args) { var primesByDigits = getPrimesByDigits(100000000); System.out.println("First 100 brilliant numbers:"); List<Integer> brilliantNumbers = new ArrayList<>(); for (var primes : primesByDigits) {...
1,075Brilliant numbers
9java
h1xjm
import java.util.ArrayList; import java.util.List; public class BWT { private static final String STX = "\u0002"; private static final String ETX = "\u0003"; private static String bwt(String s) { if (s.contains(STX) || s.contains(ETX)) { throw new IllegalArgumentException("String canno...
1,071Burrows–Wheeler transform
9java
jp07c
null
1,070Call a foreign-language function
11kotlin
nzvij
use strict; use feature 'say'; sub cantor { our($height) = @_; my $width = 3 ** ($height - 1); our @lines = (' sub trim_middle_third { my($len, $start, $index) = @_; my $seg = int $len / 3 or return; for my $i ( $index .. $height - 1 ) { for my $j ( 0 .....
1,067Cantor set
2perl
vgx20
let dog = "Benjamin" let Dog = "Samba" let DOG = "Bernie" println("The three dogs are named \(dog), \(Dog), and \(DOG).")
1,057Case-sensitivity of identifiers
17swift
vgt2r
import itertools def cp(lsts): return list(itertools.product(*lsts)) if __name__ == '__main__': from pprint import pprint as pp for lists in [[[1,2],[3,4]], [[3,4],[1,2]], [[], [1, 2]], [[1, 2], []], ((1776, 1789), (7, 12), (4, 14, 23), (0, 1)), ((1, 2, 3), (30,), (50...
1,058Cartesian product of two or more lists
3python
rkygq
use strict; use warnings; use feature 'say'; use List::AllUtils <max head firstidx uniqint>; use ntheory <primes is_semiprime forsetproduct>; sub table { my $t = shift() * (my $c = 1 + length max @_); ( sprintf( ('%'.$c.'d')x@_, @_) ) =~ s/.{1,$t}\K/\n/gr } sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s...
1,075Brilliant numbers
2perl
ityo3
(ns a) (def ^:private priv:secret) user=> @a/priv user=> @#'a/priv :secret
1,076Break OO privacy
6clojure
tycfv
f(); g(1, 2, 3); int op_arg(); int main() { op_arg(1); op_arg(1, 2); op_arg(1, 2, 3); return 0; } int op_arg(int a, int b) { printf(, a, b, (&b)[1]); return a; } void h(int a, ...) { va_list ap; va_start(ap); ... } h(1, 2, 3, 4, , (void*)0); struct v_args { int arg1; int arg2; char _sent...
1,077Call a function
5c
1xspj
null
1,065Call an object method
17swift
39bz2
null
1,071Burrows–Wheeler transform
11kotlin
57eua
PACKAGE MAIN IMPORT ( "FMT" "TIME" ) CONST PAGEWIDTH = 80 FUNC MAIN() { PRINTCAL(1969) } FUNC PRINTCAL(YEAR INT) { THISDATE := TIME.DATE(YEAR, 1, 1, 1, 1, 1, 1, TIME.UTC) VAR ( DAYARR [12][7][6]INT
1,074Calendar - for "REAL" programmers
0go
57pul
local ffi = require("ffi") ffi.cdef[[ char * strndup(const char * s, size_t n); int strlen(const char *s); ]] local s1 = "Hello, world!" print("Original: " .. s1) local s_s1 = ffi.C.strlen(s1) print("strlen: " .. s_s1) local s2 = ffi.string(ffi.C.strndup(s1, s_s1), s_s1) print("Copy: " .. s2) print("strlen: " .. ffi....
1,070Call a foreign-language function
1lua
d3unq
one_w_many <- function(one, many) lapply(many, function(x) c(one,x)) "%p%" <- function( a, b ) { p = c( sapply(a, function (x) one_w_many(x, b) ) ) if (is.null(unlist(p))) list() else p} display_prod <- function (xs) { for (x in xs) cat( paste(x, collapse=", "), "\n" ) } fmt_vec <- function(v) sprintf("(%s)"...
1,058Cartesian product of two or more lists
13r
urtvx
from primesieve.numpy import primes from math import isqrt import numpy as np max_order = 9 blocks = [primes(10**n, 10**(n + 1)) for n in range(max_order)] def smallest_brilliant(lb): pos = 1 root = isqrt(lb) for blk in blocks: n = len(blk) if blk[-1]*blk[-1] < lb: pos += n*(n...
1,075Brilliant numbers
3python
nzmiz
STX = string.char(tonumber(2,16)) ETX = string.char(tonumber(3,16)) function bwt(s) if s:find(STX, 1, true) then error("String cannot contain STX") end if s:find(ETX, 1, true) then error("String cannot contain ETX") end local ss = STX .. s .. ETX local tbl = {} for i=1,#ss ...
1,071Burrows–Wheeler transform
1lua
4jw5c
WIDTH = 81 HEIGHT = 5 lines=[] def cantor(start, len, index): seg = len / 3 if seg == 0: return None for it in xrange(HEIGHT-index): i = index + it for jt in xrange(seg): j = start + seg + jt pos = i * WIDTH + j lines[pos] = ' ' cantor(start, ...
1,067Cantor set
3python
urqvd
null
1,075Brilliant numbers
15rust
tylfd
package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func main() { fmt.Println(`Cows and bulls/player You think of four digit number of unique digits in the range 1 to 9. I guess. You score my guess: A correct digit but not in the correct place is a cow. A correct digit in t...
1,073Bulls and cows/Player
0go
nzci1
null
1,075Brilliant numbers
17swift
d39nh
typedef unsigned char character; typedef character *string; typedef struct node_t node; struct node_t { enum tag_t { NODE_LEAF, NODE_TREE, NODE_SEQ, } tag; union { string str; node *root; } data; node *next; }; node *allocate_node(enum tag_t tag) { nod...
1,078Brace expansion
5c
tymf4
package main import ( "bufio" "errors" "fmt" "os" "reflect" "unsafe" ) type foobar struct { Exported int
1,076Break OO privacy
0go
4jb52
void draw_brownian_tree(int world[SIZE][SIZE]){ int px, py; int dx, dy; int i; world[rand() % SIZE][rand() % SIZE] = 1; for (i = 0; i < NUM_PARTICLES; i++){ px = rand() % SIZE; py = rand() % SIZE; while (1){ dx = rand() % 3 - 1; dy = rand() % 3 - 1; if (dx + ...
1,079Brownian tree
5c
244lo
import Data.List import Control.Monad import System.Random (randomRIO) import Data.Char(digitToInt) combinationsOf 0 _ = [[]] combinationsOf _ [] = [] combinationsOf k (x:xs) = map (x:) (combinationsOf (k-1) xs) ++ combinationsOf k xs player = do let ps = concatMap permutations $ combinationsOf 4 ['1'..'9'] play ...
1,073Bulls and cows/Player
8haskell
urpv2
(defn one [] "Function that takes no arguments and returns 1" 1) (one)
1,077Call a function
6clojure
qonxt
cantorSet <- function() { depth <- 6L cs <- vector('list', depth) cs[[1L]] <- c(0, 1) for(k in seq_len(depth)) { cs[[k + 1L]] <- unlist(sapply(seq_len(length(cs[[k]]) / 2L), function(j) { p <- cs[[k]][2L] / 3 h <- 2L * (j - 1L) c( cs[[k]][h + 1L] + c(0, p), cs[[k]][h + 2L] ...
1,067Cantor set
13r
cua95
use List::Util 'reduce'; print +(reduce {$a + $b} 1 .. 10), "\n"; sub func { $b & 1 ? "$a $b" : "$b $a" } print +(reduce \&func, 1 .. 10), "\n"
1,061Catamorphism
2perl
4jf5d
use utf8; binmode STDOUT, ":utf8"; use constant STX => ' '; sub transform { my($s) = @_; my($t); warn "String can't contain STX character." and exit if $s =~ /STX/; $s = STX . $s; $t .= substr($_,-1,1) for sort map { rotate($s,$_) } 1..length($s); return $t; } sub rotate { my($s,$n) = @_; joi...
1,071Burrows–Wheeler transform
2perl
ofc8x
import java.lang.reflect.*; class Example { private String _name; public Example(String name) { _name = name; } public String toString() { return "Hello, I am " + _name; } } public class BreakPrivacy { public static final void main(String[] args) throws Exception { Example foo = new Example("Eric"); for (Fie...
1,076Break OO privacy
9java
pwsb3
public class BullsAndCowsPlayerGame { private static int count; private static Console io = System.console(); private final GameNumber secret; private List<AutoGuessNumber> pool = new ArrayList<>(); public BullsAndCowsPlayerGame(GameNumber secret) { this.secret = secret; fillPool(...
1,073Bulls and cows/Player
9java
m2rym
IMPORT JAVA.TEXT.* IMPORT JAVA.UTIL.* IMPORT JAVA.IO.PRINTSTREAM INTERNAL FUN PRINTSTREAM.PRINTCALENDAR(YEAR: INT, NCOLS: BYTE, LOCALE: LOCALE?) { IF (NCOLS < 1 || NCOLS > 12) THROW ILLEGALARGUMENTEXCEPTION("ILLEGAL COLUMN WIDTH.") VAL W = NCOLS * 24 VAL NROWS = MATH.CEIL(12.0 / NCOLS).TOINT() ...
1,074Calendar - for "REAL" programmers
11kotlin
rkego
p [1, 2].product([3, 4]) p [3, 4].product([1, 2]) p [1, 2].product([]) p [].product([1, 2]) p [1776, 1789].product([7, 12], [4, 14, 23], [0, 1]) p [1, 2, 3].product([30], [500, 100]) p [1, 2, 3].product([], [500, 100])
1,058Cartesian product of two or more lists
14ruby
jp97x
import kotlin.reflect.full.declaredMemberProperties import kotlin.reflect.jvm.isAccessible class ToBeBroken { @Suppress("unused") private val secret: Int = 42 } fun main(args: Array<String>) { val tbb = ToBeBroken() val props = ToBeBroken::class.declaredMemberProperties for (prop in props) { ...
1,076Break OO privacy
11kotlin
7bar4
local function Counter()
1,076Break OO privacy
1lua
jpe71
def bwt(s): assert not in s and not in s, s = + s + table = sorted(s[i:] + s[:i] for i in range(len(s))) last_column = [row[-1:] for row in table] return .join(last_column) def ibwt(r): table = [] * len(r) for i in range(len(r)): table = sorted(r[i] + table...
1,071Burrows–Wheeler transform
3python
itlof
null
1,073Bulls and cows/Player
11kotlin
tyvf0
FUNCTION PRINT_CAL(YEAR) LOCAL MONTHS={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE", "JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"} LOCAL DAYSTITLE="MO TU WE TH FR SA SU" LOCAL DAYSPERMONTH={31,28,31,30,31,30,31,31,30,31,30,31} LOCAL STARTDAY=((YEAR-1)*365+MATH.FLOOR((YEAR-1)/...
1,074Calendar - for "REAL" programmers
1lua
7bwru
lines = 5 (0..lines).each do |exp| seg_size = 3**(lines-exp-1) chars = (3**exp).times.map{ |n| n.digits(3).any?(1)? : } puts chars.map{ |c| c * seg_size }.join end
1,067Cantor set
14ruby
4j05p
fn cartesian_product(lists: &Vec<Vec<u32>>) -> Vec<Vec<u32>> { let mut res = vec![]; let mut list_iter = lists.iter(); if let Some(first_list) = list_iter.next() { for &i in first_list { res.push(vec![i]); } } for l in list_iter { let mut tmp = vec![]; fo...
1,058Cartesian product of two or more lists
15rust
h1cj2
typedef char bool; bool same_digits(int n, int b) { int f = n % b; n /= b; while (n > 0) { if (n % b != f) return FALSE; n /= b; } return TRUE; } bool is_brazilian(int n) { int b; if (n < 7) return FALSE; if (!(n % 2) && n >= 8) return TRUE; for (b = 2; b < n - 1...
1,080Brazilian numbers
5c
pweby
use convert_base::Convert; use std::fmt; struct CantorSet { cells: Vec<Vec<bool>>, } fn number_to_vec(n: usize) -> Vec<u32> {
1,067Cantor set
15rust
gh84o
object CantorSetQD extends App { val (width, height) = (81, 5) val lines = Seq.fill[Array[Char]](height)(Array.fill[Char](width)('*')) def cantor(start: Int, len: Int, index: Int) { val seg = len / 3 println(start, len, index) if (seg != 0) { for (i <- index until height; j <- (st...
1,067Cantor set
16scala
jpn7i
>>> >>> from operator import add >>> listoflists = [['the', 'cat'], ['sat', 'on'], ['the', 'mat']] >>> help(reduce) Help on built-in function reduce in module __builtin__: reduce(...) reduce(function, sequence[, initial]) -> value Apply a function of two arguments cumulatively to the items of a sequence, ...
1,061Catamorphism
3python
ght4h
def cartesianProduct[T](lst: List[T]*): List[List[T]] = { def pel(e: T, ll: List[List[T]], a: List[List[T]] = Nil): List[List[T]] = ll match { case Nil => a.reverse case x :: xs => pel(e, xs, (e :: x) :: a ) } lst.toList match { case Nil => Nil case x :: Nil => L...
1,058Cartesian product of two or more lists
16scala
pwvbj
package main import ( "fmt" "math/big" ) func main() { var b, c big.Int for n := int64(0); n < 15; n++ { fmt.Println(c.Div(b.Binomial(n*2, n), c.SetInt64(n+1))) } }
1,068Catalan numbers
0go
aq31f
package expand
1,078Brace expansion
0go
h1ajq
int width = 80, year = 1969; int cols, lead, gap; const char *wdays[] = { , , , , , , }; struct months { const char *name; int days, start_wday, at; } months[12] = { { , 31, 0, 0 }, { , 28, 0, 0 }, { , 31, 0, 0 }, { , 30, 0, 0 }, { , 31, 0, 0 }, { , 30, 0, 0 }, { , 31, 0, 0 }, { , 31, 0, 0 }, { , 30, 0, 0 ...
1,081Calendar
5c
w0qec
package main import ( "fmt" "math" ) const epsilon = 1.0e-15 func main() { fact := uint64(1) e := 2.0 n := uint64(2) for { e0 := e fact *= n n++ e += 1.0 / float64(fact) if math.Abs(e - e0) < epsilon { break } } fmt.Printf("e...
1,072Calculating the value of e
0go
beokh
local line = "
1,073Bulls and cows/Player
1lua
zmuty
void main() {
1,077Call a function
18dart
7b1r7
Reduce('+', c(2,30,400,5000)) 5432
1,061Catamorphism
13r
vgi27
class Catalan { public static void main(String[] args) { BigInteger N = 15; BigInteger k,n,num,den; BigInteger catalan; print(1); for(n=2;n<=N;n++) { num = 1; den = 1; for(k=2;k<=n;k++) { num = num*(n+k); ...
1,068Catalan numbers
7groovy
h1nj9
class BraceExpansion { static void main(String[] args) { for (String s: [ "It{{em,alic}iz,erat}e{d,}, please.", "~/{Downloads,Pictures}/*.{jpg,gif,png}", "{,{,gotta have{ ,\\, again\\, }}more }cowbell!", "{}} some }{,{\\\\{ edge, edge} \\,}{ ca...
1,078Brace expansion
7groovy
4jh5f
package Foo; sub new { my $class = shift; my $self = { _bar => 'I am ostensibly private' }; return bless $self, $class; } sub get_bar { my $self = shift; return $self->{_bar}; } package main; my $foo = Foo->new(); print "$_\n" for $foo->get_bar(), $foo->{_bar};
1,076Break OO privacy
2perl
f69d7
int yp=LINE_BEGIN, xp=0; char number[5]; char guess[5]; void mvaddstrf(int y, int x, const char *fmt, ...) { va_list args; char buf[MAX_STR]; va_start(args, fmt); vsprintf(buf, fmt, args); move(y, x); clrtoeol(); addstr(buf); va_end(args); } void ask_for_a_number() { int i=0; char symbols[] = ;...
1,082Bulls and cows
5c
cul9c
STX = ETX = def bwt(s) for c in s.split('') if c == STX or c == ETX then raise ArgumentError.new() end end ss = ( % [STX, s, ETX]).split('') table = [] for i in 0 .. ss.length - 1 table.append(ss.join) ss = ss.rotate(-1) end table = table.sort...
1,071Burrows–Wheeler transform
14ruby
d3vns
caesar_cipher() { local -a _ABC=( "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" ) local -a _abc=( "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" ) local _out if (( $ echo "Usage...
1,083Caesar cipher
4bash
9v9ms
def = 1.0e-15 def = 1/ def generateAddends = { def addends = [] def n = 0.0 def fact = 1.0 while (true) { fact *= (n < 2 ? 1.0: n) as double addends << 1.0/fact if (fact > ) break
1,072Calculating the value of e
7groovy
rkxgh
eApprox :: Int -> Double eApprox n = (sum . take n) $ (1 /) <$> scanl (*) 1 [1 ..] main :: IO () main = print $ eApprox 20
1,072Calculating the value of e
8haskell
d32n4
$PROGRAM = '\' MY @START_DOW = (3, 6, 6, 2, 4, 0, 2, 5, 1, 3, 6, 1); MY @DAYS = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); MY @MONTHS; FOREACH MY $M (0 .. 11) { FOREACH MY $R (0 .. 5) { $MONTHS[$M][$R] = JOIN " ", MAP { $_ < 1 || $_ > $DAYS[$M]? " ": SPRIN...
1,074Calendar - for "REAL" programmers
2perl
d3cnw
import qualified Text.Parsec as P showExpansion :: String -> String showExpansion = (<>) . (<> "\n parser :: P.Parsec String u [String] parser = expansion P.anyChar expansion :: P.Parsec String u Char -> P.Parsec String u [String] expansion = fmap expand . P.many . ((P.try alts P.<|> P.try alt1 P.<|> escape)...
1,078Brace expansion
8haskell
itzor
<?php class SimpleClass { private $answer = world\nforever:)^SimpleClass::__set_state\(\)$"', ';', $class_content); $new_class = eval($class_content); echo $new_class['answer'];
1,076Break OO privacy
12php
h1wjf
>>> class MyClassName: __private = 123 non_private = __private * 2 >>> mine = MyClassName() >>> mine.non_private 246 >>> mine.__private Traceback (most recent call last): File , line 1, in <module> mine.__private AttributeError: 'MyClassName' object has no attribute '__private' >>> mine._MyClassName__private ...
1,076Break OO privacy
3python
tycfw
use core::cmp::Ordering; const STX: char = '\u{0002}'; const ETX: char = '\u{0003}';
1,071Burrows–Wheeler transform
15rust
f6ud6
import scala.collection.mutable.ArrayBuffer object BWT { val STX = '\u0002' val ETX = '\u0003' def bwt(s: String): String = { if (s.contains(STX) || s.contains(ETX)) { throw new RuntimeException("String can't contain STX or ETX") } var ss = STX + s + ETX var table = new ArrayBuffer[String]...
1,071Burrows–Wheeler transform
16scala
39gzy
use Inline C => q{ char *copy; char * c_dup(char *orig) { return copy = strdup(orig); } void c_free() { free(copy); } }; print c_dup('Hello'), "\n"; c_free();
1,070Call a foreign-language function
2perl
7b0rh