code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
null | 756Hello world/Line printer | 10javascript | 70srd |
import java.io.File
fun main(args: Array<String>) {
val text = "Hello World!\n"
File("/dev/lp0").writeText(text)
} | 756Hello world/Line printer | 11kotlin | 9khmh |
main() {
var bye = 'Hello world!';
print("$bye");
} | 755Hello world/Text | 18dart | 67734 |
(defn hash-join [table1 col1 table2 col2]
(let [hashed (group-by col1 table1)]
(flatten
(for [r table2]
(for [s (hashed (col2 r))]
(merge s r))))))
(def s '({:age 27:name "Jonah"}
{:age 18:name "Alan"}
{:age 28:name "Glory"}
{:age 18:name "Popeye"}
{:ag... | 757Hash join | 6clojure | 8cm05 |
open O, ">", "/dev/lp0";
print O "Hello World!\n";
close O; | 756Hello world/Line printer | 2perl | w3ze6 |
$ sudo apt-get install gcc | 758Hello world/Newbie | 5c | cbj9c |
func func1(f: String->String) -> String { return f("a string") }
func func2(s: String) -> String { return "func2 called with " + s }
println(func1(func2)) | 754Higher-order functions | 17swift | 9kbmj |
<?php
file_put_contents('/dev/lp0', 'Hello world!');
?> | 756Hello world/Line printer | 12php | lpbcj |
$ sudo apt-get install open-cobol | 758Hello world/Newbie | 6clojure | 5w1uz |
package main
import "fmt"
func main() {
tableA := []struct {
value int
key string
}{
{27, "Jonah"}, {18, "Alan"}, {28, "Glory"}, {18, "Popeye"},
{28, "Alan"},
}
tableB := []struct {
key string
value string
}{
{"Jonah", "Whales"}, {"Jonah"... | 757Hash join | 0go | cbh9g |
lp = open()
lp.write()
lp.close() | 756Hello world/Line printer | 3python | x63wr |
def hashJoin(table1, col1, table2, col2) {
def hashed = table1.groupBy { s -> s[col1] }
def q = [] as Set
table2.each { r ->
def join = hashed[r[col2]]
join.each { s ->
q << s.plus(r)
}
}
q
} | 757Hash join | 7groovy | 3r4zd |
import qualified Data.HashTable.ST.Basic as H
import Data.Hashable
import Control.Monad.ST
import Control.Monad
import Data.STRef
hashJoin :: (Eq k, Hashable k) =>
[t] -> (t -> k) -> [a] -> (a -> k) -> [(t, a)]
hashJoin xs fx ys fy = runST $ do
l <- newSTRef []
ht <- H.new
forM_ ys $ \y -> H.insert h... | 757Hash join | 8haskell | pdibt |
unsigned strhashkey( const char * key, int max)
{
unsigned h=0;
unsigned hl, hr;
while(*key) {
h += *key;
hl= 0x5C5 ^ (h&0xfff00000 )>>18;
hr =(h&0x000fffff );
h = hl ^ hr ^ *key++;
}
return h % max;
}
typedef struct sHme {
KeyType key;
ValType value;
... | 759Hash from two arrays | 5c | lpjcy |
open(, ) { |f| f.puts } | 756Hello world/Line printer | 14ruby | smyqw |
use std::fs::OpenOptions;
use std::io::Write;
fn main() {
let file = OpenOptions::new().write(true).open("/dev/lp0").unwrap();
file.write(b"Hello, World!").unwrap();
} | 756Hello world/Line printer | 15rust | 09msl |
import java.awt.print.PrinterException
import scala.swing.TextArea
object LinePrinter extends App {
val (show, context) = (false, "Hello, World!")
try | 756Hello world/Line printer | 16scala | i2lox |
import java.util.*;
public class HashJoin {
public static void main(String[] args) {
String[][] table1 = {{"27", "Jonah"}, {"18", "Alan"}, {"28", "Glory"},
{"18", "Popeye"}, {"28", "Alan"}};
String[][] table2 = {{"Jonah", "Whales"}, {"Jonah", "Spiders"},
{"Alan", "Ghosts"}, {"Alan... | 757Hash join | 9java | rsxg0 |
$ cat >hello.go | 758Hello world/Newbie | 0go | w3feg |
println 'Hello to the Groovy world' | 758Hello world/Newbie | 7groovy | bn8ky |
$ sudo apt-get install ghc | 758Hello world/Newbie | 8haskell | 6743k |
(() => {
'use strict'; | 757Hash join | 10javascript | bnoki |
(zipmap [\a \b \c] [1 2 3]) | 759Hash from two arrays | 6clojure | 4x15o |
javac -version | 758Hello world/Newbie | 9java | nvcih |
console.log("Hello, World!"); | 758Hello world/Newbie | 10javascript | 3r5z0 |
import Foundation
let out = NSOutputStream(toFileAtPath: "/dev/lp0", append: true)
let data = "Hello, World!".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
out?.open()
out?.write(UnsafePointer<UInt8>(data!.bytes), maxLength: data!.length)
out?.close() | 756Hello world/Line printer | 17swift | qy6xg |
notepad hello.kt | 758Hello world/Newbie | 11kotlin | sm3q7 |
package main
import (
"fmt"
"math/big"
)
func harmonic(n int) *big.Rat {
sum := new(big.Rat)
for i := int64(1); i <= int64(n); i++ {
r := big.NewRat(1, i)
sum.Add(sum, r)
}
return sum
}
func main() {
fmt.Println("The first 20 harmonic numbers and the 100th, expressed in ra... | 760Harmonic series | 0go | kiqhz |
data class A(val age: Int, val name: String)
data class B(val character: String, val nemesis: String)
data class C(val rowA: A, val rowB: B)
fun hashJoin(tableA: List<A>, tableB: List<B>): List<C> {
val mm = tableB.groupBy { it.character }
val tableC = mutableListOf<C>()
for (a in tableA) {
val v... | 757Hash join | 11kotlin | vap21 |
int main(int argc, char *argv[]) {
(void) printf();
return EXIT_SUCCESS;
} | 761Hello world/Newline omission | 5c | 67v32 |
import Data.List (find)
import Data.Ratio
harmonic :: [Rational]
harmonic =
scanl1
(\a x -> a + 1 / x)
[1 ..]
main :: IO ()
main = do
putStrLn "First 20 terms:"
mapM_ putStrLn $
showRatio <$> take 20 harmonic
putStrLn "\n100th term:"
putStrLn $ showRatio (harmonic !! 99)
putStrLn ""
put... | 760Harmonic series | 8haskell | nvmie |
local function recA(age, name) return { Age=age, Name=name } end
local tabA = { recA(27,"Jonah"), recA(18,"Alan"), recA(28,"Glory"), recA(18,"Popeye"), recA(28,"Alan") }
local function recB(character, nemesis) return { Character=character, Nemesis=nemesis } end
local tabB = { recB("Jonah","Whales"), recB("Jonah","Spid... | 757Hash join | 1lua | ue1vl |
(print "Goodbye, World!") | 761Hello world/Newline omission | 6clojure | lprcb |
io.write("Hello world, from ",_VERSION,"!\n") | 758Hello world/Newbie | 1lua | 096sd |
static int digsum(int n)
{
int sum = 0;
do { sum += n % 10; } while (n /= 10);
return sum;
}
int main(void)
{
int n, done, found;
for (n = 1, done = found = 0; !done; ++n) {
if (n % digsum(n) == 0) {
if (found++ < 20) printf(, n);
if (n > 1000) done = printf(, n);
... | 762Harshad or Niven series | 5c | lpgcy |
use strict;
use warnings;
use feature 'say';
use Math::AnyNum ':overload';
use List::AllUtils 'firstidx';
my(@H,$n) = 0;
do { ++$n and push @H, $H[-1] + 1/$n } until $H[-1] >= 10;
shift @H;
say 'First twenty harmonic numbers as rationals:';
my $c = 0;
printf("%20s", $_) and (not ++$c%5) and print "\n" for @H[0..19];
... | 760Harmonic series | 2perl | mh4yz |
volatile sig_atomic_t gotint = 0;
void handleSigint() {
gotint = 1;
}
int main() {
clock_t startTime = clock();
signal(SIGINT, handleSigint);
int i=0;
for (;;) {
if (gotint)
break;
usleep(500000);
if (gotint)
break;
printf(, ++i);
}
clo... | 763Handle a signal | 5c | 70prg |
from fractions import Fraction
def harmonic_series():
n, h = Fraction(1), Fraction(1)
while True:
yield h
h += 1 / (n + 1)
n += 1
if __name__ == '__main__':
from itertools import islice
for n, d in (h.as_integer_ratio() for h in islice(harmonic_series(), 20)):
print(n,... | 760Harmonic series | 3python | 9kgmf |
HofN <- function(n) sum(1/seq_len(n))
H <- sapply(1:100000, HofN)
print(H[1:20])
print(sapply(1:10, function(x) which.max(H > x))) | 760Harmonic series | 13r | 3rvzt |
int main(){int a=0, b=0, c=a/b;} | 764Halt and catch fire | 5c | f56d3 |
(require 'clojure.repl)
(def start (System/nanoTime))
(defn shutdown [_]
(println "Received INT after"
(/ (- (System/nanoTime) start) 1e9)
"seconds.")
(System/exit 0))
(clojure.repl/set-break-handler! shutdown)
(doseq [i (range)]
(prn i)
(Thread/sleep 500)) | 763Handle a signal | 6clojure | pdxbd |
(defn digsum [n acc]
(if (zero? n) acc
(digsum (quot n 10) (+ acc (mod n 10)))))
(let [harshads (filter
#(zero? (mod % (digsum % 0)))
(iterate inc 1))]
(prn (take 20 harshads))
(prn (first (filter #(> % 1000) harshads)))) | 762Harshad or Niven series | 6clojure | 4xk5o |
use Data::Dumper qw(Dumper);
sub hashJoin {
my ($table1, $index1, $table2, $index2) = @_;
my %h;
foreach my $s (@$table1) {
push @{ $h{$s->[$index1]} }, $s;
}
map { my $r = $_;
map [$_, $r], @{ $h{$r->[$index2]} }
} @$table2;
}
@table1 = ([27, "Jonah"],
[18, "Alan"],
... | 757Hash join | 2perl | 09ys4 |
use num::rational::Ratio;
use num::{BigInt, FromPrimitive};
fn main() {
for n in 1..=20 {
println!("Harmonic number {} = {}", n, harmonic_number(n.into()));
}
println!("Harmonic number 100 = {}", harmonic_number(100.into()));
let max = 5;
let mut target = 1;
let mut i = 1;
while t... | 760Harmonic series | 15rust | 21jlt |
package main; import "fmt"; func main(){a, b := 0, 0; fmt.Println(a/b)} | 764Halt and catch fire | 0go | j8p7d |
=head1 Obtaining perl
On the majority of UNIX and UNIX-like operating systems
(Linux, Solaris, AIX, HPUX, et cetera), perl will already be installed.
Mac OS X also ships with perl.
Note that "Perl" refers to the language
while "perl" refers to the interpreter used to run Perl programs.
Windows does not ship with ... | 758Hello world/Newbie | 2perl | uepvr |
<?php
echo 'Hello, world!';
?> | 758Hello world/Newbie | 12php | 8cy0m |
main = error "Instant crash" | 764Halt and catch fire | 8haskell | olf8p |
error(1) | 764Halt and catch fire | 1lua | pdwbw |
<?php
function hashJoin($table1, $index1, $table2, $index2) {
foreach ($table1 as $s)
$h[$s[$index1]][] = $s;
foreach ($table2 as $r)
foreach ($h[$r[$index2]] as $s)
$result[] = array($s, $r);
return $result;
}
$table1 = array(array(27, ),
array(18, ),
arra... | 757Hash join | 12php | 5waus |
&a | 764Halt and catch fire | 2perl | 67c36 |
0/0 | 764Halt and catch fire | 3python | yjl6q |
package main
import (
"fmt"
"os"
"os/signal"
"time"
)
func main() {
start := time.Now()
k := time.Tick(time.Second / 2)
sc := make(chan os.Signal, 1)
signal.Notify(sc, os.Interrupt)
for n := 1; ; { | 763Handle a signal | 0go | du6ne |
package main
import "fmt"
func main() {
keys := []string{"a", "b", "c"}
vals := []int{1, 2, 3}
hash := map[string]int{}
for i, key := range keys {
hash[key] = vals[i]
}
fmt.Println(hash)
} | 759Hash from two arrays | 0go | x6fwf |
def keys = ['a','b','c']
def vals = ['aaa', 'bbb', 'ccc']
def hash = [:]
keys.eachWithIndex { key, i ->
hash[key] = vals[i]
} | 759Hash from two arrays | 7groovy | pd8bo |
raise | 764Halt and catch fire | 14ruby | 9kvmz |
fn main(){panic!("");} | 764Halt and catch fire | 15rust | cbu9z |
fatalError("You've met with a terrible fate, haven't you?") | 764Halt and catch fire | 17swift | mh2yk |
import Prelude hiding (catch)
import Control.Exception (catch, throwIO, AsyncException(UserInterrupt))
import Data.Time.Clock (getCurrentTime, diffUTCTime)
import Control.Concurrent (threadDelay)
main = do t0 <- getCurrentTime
catch (loop 0)
(\e -> if e == UserInterrupt
... | 763Handle a signal | 8haskell | 5wjug |
import Data.Map
makeMap ks vs = fromList $ zip ks vs
mymap = makeMap ['a','b','c'] [1,2,3] | 759Hash from two arrays | 8haskell | yj466 |
>>> print('hello world') | 758Hello world/Newbie | 3python | 5w1ux |
import sun.misc.Signal;
import sun.misc.SignalHandler;
public class ExampleSignalHandler {
public static void main(String... args) throws InterruptedException {
final long start = System.nanoTime();
Signal.handle(new Signal("INT"), new SignalHandler() {
public void handle(Signal sig) {
... | 763Handle a signal | 9java | 9kumu |
int main()
{
printf(,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));
return 0;
} | 765GUI/Maximum window dimensions | 5c | 09ist |
(function(){
var count=0
secs=0
var i= setInterval( function (){
count++
secs+=0.5
console.log(count)
}, 500);
process.on('SIGINT', function() {
clearInterval(i)
console.log(secs+' seconds elapsed');
process.exit()
});
})(); | 763Handle a signal | 10javascript | ue7vb |
from collections import defaultdict
def hashJoin(table1, index1, table2, index2):
h = defaultdict(list)
for s in table1:
h[s[index1]].append(s)
return [(s, r) for r in table2 for s in h[r[index2]]]
table1 = [(27, ),
(18, ),
(28, ),
(18, ),
(28, )]
... | 757Hash join | 3python | 8cm0o |
package main
import "fmt"
func main() { fmt.Print("Goodbye, World!") } | 761Hello world/Newline omission | 0go | pdsbg |
null | 763Handle a signal | 11kotlin | zg9ts |
double dist(double th1, double ph1, double th2, double ph2)
{
double dx, dy, dz;
ph1 -= ph2;
ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD;
dz = sin(th1) - sin(th2);
dx = cos(ph1) * cos(th1) - cos(th2);
dy = sin(ph1) * cos(th1);
return asin(sqrt(dx * dx + dy * dy + dz * dz) / 2) * 2 * R;
}
int main()
{
double d... | 766Haversine formula | 5c | dutnv |
print "Goodbye, world" | 761Hello world/Newline omission | 7groovy | 70arz |
import java.util.HashMap;
public static void main(String[] args){
String[] keys= {"a", "b", "c"};
int[] vals= {1, 2, 3};
HashMap<String, Integer> hash= new HashMap<String, Integer>();
for(int i= 0; i < keys.length; i++){
hash.put(keys[i], vals[i]);
}
} | 759Hash from two arrays | 9java | ducn9 |
puts | 758Hello world/Newbie | 14ruby | gqe4q |
fn main() {
println!("Hello world!");
} | 758Hello world/Newbie | 15rust | rswg5 |
main = putStr "Goodbye, world" | 761Hello world/Newline omission | 8haskell | f59d1 |
var keys = ['a', 'b', 'c'];
var values = [1, 2, 3];
var map = {};
for(var i = 0; i < keys.length; i += 1) {
map[ keys[i] ] = values[i];
} | 759Hash from two arrays | 10javascript | 67538 |
scala -e 'println(\"Hello_world\")' | 758Hello world/Newbie | 16scala | hosja |
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
w, h := robotgo.GetScreenSize()
fmt.Printf("Screen size:%d x%d\n", w, h)
fpid, err := robotgo.FindIds("firefox")
if err == nil && len(fpid) > 0 {
pid := fpid[0]
robotgo.ActivePID(pid)
robotgo.MaxWin... | 765GUI/Maximum window dimensions | 0go | uegvt |
def window = java.awt.GraphicsEnvironment.localGraphicsEnvironment.maximumWindowBounds
println "width: $window.width, height: $window.height" | 765GUI/Maximum window dimensions | 7groovy | 9k2m4 |
import Graphics.UI.Gtk
import Control.Monad (when)
import Control.Monad.Trans (liftIO)
maximumWindowDimensions :: IO ()
maximumWindowDimensions = do
initGUI
window <- windowNew
on window objectDestroy mainQuit
on window configureEvent printSize
screen <- windowGetScreen win... | 765GUI/Maximum window dimensions | 8haskell | w3sed |
my $start = time;
my $arlm=5;
my $i;
$SIG{QUIT} = sub
{print " Ran for ", time - $start, " seconds.\n"; die; };
$SIG{INT} = sub
{print " Running for ", time - $start, " seconds.\n"; };
$SIG{ALRM} = sub
{print " After $arlm seconds i= $i. Executing for ", time - $start, " seconds.\n"; alarm $arlm };
a... | 763Handle a signal | 2perl | bnwk4 |
def hashJoin(table1, index1, table2, index2)
h = table1.group_by {|s| s[index1]}
h.default = []
table2.collect {|r|
h[r[index2]].collect {|s| [s, r]}
}.flatten(1)
end
table1 = [[27, ],
[18, ],
[28, ],
[18, ],
[28, ]]
table2 = [[, ],
[, ],
[,... | 757Hash join | 14ruby | i2coh |
(defn haversine
[{lon1:longitude lat1:latitude} {lon2:longitude lat2:latitude}]
(let [R 6372.8
dlat (Math/toRadians (- lat2 lat1))
dlon (Math/toRadians (- lon2 lon1))
lat1 (Math/toRadians lat1)
lat2 (Math/toRadians lat2)
a (+ (* (Math/sin (/ dlat 2)) (Math/sin (/ dlat 2))) (... | 766Haversine formula | 6clojure | 67m3q |
import java.awt.*;
import javax.swing.JFrame;
public class Test extends JFrame {
public static void main(String[] args) {
new Test();
}
Test() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
System.out.println("Physical scr... | 765GUI/Maximum window dimensions | 9java | ki1hm |
<?php
declare(ticks = 1);
$start = microtime(YES);
function mySigHandler() {
global $start;
$elapsed = microtime(YES) - $start;
echo ;
exit();
}
pcntl_signal(SIGINT, 'mySigHandler');
for ($n = 0; ; usleep(500000))
echo ++$n, ;
?> | 763Handle a signal | 12php | 67l3g |
public class HelloWorld
{
public static void main(String[] args)
{
System.out.print("Goodbye, World!");
}
} | 761Hello world/Newline omission | 9java | 09tse |
process.stdout.write("Goodbye, World!"); | 761Hello world/Newline omission | 10javascript | dumnu |
null | 759Hash from two arrays | 11kotlin | 093sf |
tclsh8.5 | 758Hello world/Newbie | 17swift | 4xa5g |
null | 765GUI/Maximum window dimensions | 11kotlin | gqj4d |
use std::collections::HashMap;
use std::hash::Hash; | 757Hash join | 15rust | nvli4 |
int main (int argc, char **argv) {
GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), );
g_signal_connect (G_OBJECT (window), , gtk_main_quit, NULL);
gtk_widget_show_all (window);
gtk_main();
return 0;
} | 767Hello world/Graphical | 5c | ezwav |
def join[Type](left: Seq[Seq[Type]], right: Seq[Seq[Type]]) = {
val hash = right.groupBy(_.head) withDefaultValue Seq()
left.flatMap(cols => hash(cols.last).map(cols ++ _.tail))
} | 757Hash join | 16scala | t4ufb |
fun main(args: Array<String>) = print("Goodbye, World!") | 761Hello world/Newline omission | 11kotlin | ezoa4 |
use strict;
use warnings;
use Tk;
sub get_size {
my $mw = MainWindow->new();
return ($mw->maxsize);
} | 765GUI/Maximum window dimensions | 2perl | nvtiw |
import time
def counter():
n = 0
t1 = time.time()
while True:
try:
time.sleep(0.5)
n += 1
print n
except KeyboardInterrupt, e:
print 'Program has run for%5.3f seconds.'% (time.time() - t1)
break
counter() | 763Handle a signal | 3python | pdxbm |
import tkinter as tk
root = tk.Tk()
root.state('zoomed')
root.update_idletasks()
tk.Label(root, text=(str(root.winfo_width())+ +str(root.winfo_height())),
font=(, 25)).pack()
root.mainloop() | 765GUI/Maximum window dimensions | 3python | duzn1 |
t1 = Time.now
catch :done do
Signal.trap('INT') do
Signal.trap('INT', 'DEFAULT')
throw :done
end
n = 0
loop do
sleep(0.5)
n += 1
puts n
end
end
tdelt = Time.now - t1
puts 'Program has run for%5.3f seconds.' % tdelt | 763Handle a signal | 14ruby | ats1s |
#[cfg(unix)]
fn main() {
use std::sync::atomic::{AtomicBool, Ordering};
use std::thread;
use std::time::{Duration, Instant};
use libc::{sighandler_t, SIGINT}; | 763Handle a signal | 15rust | ez0aj |
import sun.misc.Signal
import sun.misc.SignalHandler
object SignalHandl extends App {
val start = System.nanoTime()
var counter = 0
Signal.handle(new Signal("INT"), new SignalHandler() {
def handle(sig: Signal) {
println(f"\nProgram execution took ${(System.nanoTime() - start) / 1e9f}%f seconds\n")
... | 763Handle a signal | 16scala | qyixw |
-- setting up the test data
CREATE TABLE people (age NUMBER(3), name varchar2(30));
INSERT INTO people (age, name)
SELECT 27, 'Jonah' FROM dual UNION ALL
SELECT 18, 'Alan' FROM dual UNION ALL
SELECT 28, 'Glory' FROM dual UNION ALL
SELECT 18, 'Popeye' FROM dual UNION ALL
SELECT 28, 'Alan' FROM dual
;
C... | 757Hash join | 19sql | 67g3m |
import 'dart:math';
class Haversine {
static final R = 6372.8; | 766Haversine formula | 18dart | sm8q6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.