code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
@js.annotation.JSExportTopLevel("ScalaFiddle")
object ScalaFiddle { | 748Hilbert curve | 16scala | 4xn50 |
use strict; use warnings;
use Date::Calc qw(:all);
my @abbr = qw( Not Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my %c_hols = (
Easter=> 0,
Ascension=> 39,
Pentecost=> 49,
Trinity=> 56,
Corpus=> 60
);
sub easter {
my $year=shift;
my $ay=$year % 19;
my $by=int($year / 100);
my $cy=$yea... | 745Holidays related to Easter | 2perl | j8y7f |
use warnings ;
use strict ;
my $limit = 2 ** 20 ;
my @numbers = ( 0 , 1 , 1 ) ;
my $mallows ;
my $max_i ;
foreach my $i ( 3..$limit ) {
push ( @numbers , $numbers[ $numbers[ $i - 1 ]] + $numbers[ $i - $numbers[ $i - 1 ] ] ) ;
}
for ( my $rangelimit = 1 ; $rangelimit < 20 ; $rangelimit++ ) {
my $max = 0 ;
for... | 743Hofstadter-Conway $10,000 sequence | 2perl | vaf20 |
qSequence = tail qq where
qq = 0: 1: 1: map g [3..]
g n = qq !! (n - qq !! (n-1)) + qq !! (n - qq !! (n-2))
*Main> (take 10 qSequence, qSequence !! (1000-1))
([1,1,2,3,3,4,5,5,6,6],502)
(0.00 secs, 525044 bytes) | 749Hofstadter Q sequence | 8haskell | ue8v2 |
<?php
function horner($coeff, $x) {
$result = 0;
foreach (array_reverse($coeff) as $c)
$result = $result * $x + $c;
return $result;
}
$coeff = array(-19.0, 7, -4, 6);
$x = 3;
echo horner($coeff, $x), ;
?> | 740Horner's rule for polynomial evaluation | 12php | va32v |
function identity(n) {
if (n < 1) return "Not defined";
else if (n == 1) return 1;
else {
var idMatrix:number[][];
for (var i: number = 0; i < n; i++) {
for (var j: number = 0; j < n; j++) {
if (i!= j) idMatrix[i][j] = 0;
else idMatrix[i][j] = 1;
... | 730Identity matrix | 20typescript | hipjt |
import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | 752Heronian triangles | 11kotlin | 70ir4 |
$r = [nil, 1]
$s = [nil, 2]
def buildSeq(n)
current = [ $r[-1], $s[-1] ].max
while $r.length <= n || $s.length <= n
idx = [ $r.length, $s.length ].min - 1
current += 1
if current == $r[idx] + $s[idx]
$r << current
else
$s << current
end
end
end
def ffr(n)
buildSeq(n)
$r[n]
en... | 747Hofstadter Figure-Figure sequences | 14ruby | dukns |
from __future__ import print_function
import math
try: raw_input
except: raw_input = input
lat = float(raw_input())
lng = float(raw_input())
ref = float(raw_input())
print()
slat = math.sin(math.radians(lat))
print(% slat)
print(% (lng-ref))
print()
print()
for h in range(-6, 7):
hra = 15 * h
hra -= lng - ref
... | 739Horizontal sundial calculations | 3python | 1frpc |
null | 752Heronian triangles | 1lua | j8n71 |
use Socket;
my $port = 8080;
my $protocol = getprotobyname( "tcp" );
socket( SOCK, PF_INET, SOCK_STREAM, $protocol ) or die "couldn't open a socket: $!";
setsockopt( SOCK, SOL_SOCKET, SO_REUSEADDR, 1 ) or die "couldn't set socket options: $!";
bind( SOCK, sockaddr_in($port, INADDR_ANY) ) or die "couldn'... | 750Hello world/Web server | 2perl | du7nw |
use std::collections::HashMap;
struct Hffs {
sequence_r: HashMap<usize, usize>,
sequence_s: HashMap<usize, usize>,
}
impl Hffs {
fn new() -> Hffs {
Hffs {
sequence_r: HashMap::new(),
sequence_s: HashMap::new(),
}
}
fn ffr(&mut self, n: usize) -> usize { | 747Hofstadter Figure-Figure sequences | 15rust | f5bd6 |
object HofstadterFigFigSeq extends App {
import scala.collection.mutable.ListBuffer
val r = ListBuffer(0, 1)
val s = ListBuffer(0, 2)
def ffr(n: Int): Int = {
val ffri: Int => Unit = i => {
val nrk = r.size - 1
val rNext = r(nrk)+s(nrk)
r += rNext
(r(nrk)+2 to rNext-1).foreach{s +=... | 747Hofstadter Figure-Figure sequences | 16scala | 3razy |
require 'priority_queue'
def huffman_encoding(str)
char_count = Hash.new(0)
str.each_char {|c| char_count[c] += 1}
pq = CPriorityQueue.new
char_count.each {|char, count| pq.push(char, count)}
while pq.length > 1
key1, prio1 = pq.delete_min
key2, prio2 = pq.delete_min
pq.push([key1, key2], pr... | 736Huffman coding | 14ruby | pdjbh |
local http = require("socket.http")
local url = require("socket.url")
local page = http.request('http://www.google.com/m/search?q=' .. url.escape("lua"))
print(page) | 741HTTP | 1lua | ho2j8 |
from __future__ import division
def maxandmallows(nmaxpower2):
nmax = 2**nmaxpower2
mx = (0.5, 2)
mxpow2 = []
mallows = None
hc = [None, 1, 1]
for n in range(2, nmax + 1):
ratio = hc[n] / n
if ratio > mx[0]:
mx = (ratio, n)
if ratio >= 0.55:
... | 743Hofstadter-Conway $10,000 sequence | 3python | uetvd |
import java.util.HashMap;
import java.util.Map;
public class HofQ {
private static Map<Integer, Integer> q = new HashMap<Integer, Integer>(){{
put(1, 1);
put(2, 1);
}};
private static int[] nUses = new int[100001]; | 749Hofstadter Q sequence | 9java | mheym |
use std::collections::BTreeMap;
use std::collections::binary_heap::BinaryHeap;
#[derive(Debug, Eq, PartialEq)]
enum NodeKind {
Internal(Box<Node>, Box<Node>),
Leaf(char),
}
#[derive(Debug, Eq, PartialEq)]
struct Node {
frequency: usize,
kind: NodeKind,
}
impl Ord for Node {
fn cmp(&self, rhs: &Se... | 736Huffman coding | 15rust | 1fhpu |
f = local(
{a = c(1, 1)
function(n)
{if (is.na(a[n]))
a[n] <<- f(f(n - 1)) + f(n - f(n - 1))
a[n]}}) | 743Hofstadter-Conway $10,000 sequence | 13r | cbi95 |
var hofstadterQ = function() {
var memo = [1,1,1];
var Q = function (n) {
var result = memo[n];
if (typeof result !== 'number') {
result = Q(n - Q(n-1)) + Q(n - Q(n-2));
memo[n] = result;
}
return result;
};
return Q;
}();
for (var i = 1; i <=10; i += 1) {
c... | 749Hofstadter Q sequence | 10javascript | va025 |
<?php
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die('Failed to create socket!');
socket_bind($socket, 0, 8080);
socket_listen($socket);
$msg = '<html><head><title>Goodbye, world!</title></head><body>Goodbye, world!</body></html>'... | 750Hello world/Web server | 12php | j8f7z |
>>> def horner(coeffs, x):
acc = 0
for c in reversed(coeffs):
acc = acc * x + c
return acc
>>> horner( (-19, 7, -4, 6), 3)
128 | 740Horner's rule for polynomial evaluation | 3python | smbq9 |
horner <- function(a, x) {
y <- 0
for(c in rev(a)) {
y <- y * x + c
}
y
}
cat(horner(c(-19, 7, -4, 6), 3), "\n") | 740Horner's rule for polynomial evaluation | 13r | ez7ad |
include Math
DtoR = PI/180
print 'Enter latitude: '
lat = Float( gets )
print 'Enter longitude: '
lng = Float( gets )
print 'Enter legal meridian: '
ref = Float( gets )
puts
slat = sin( lat * DtoR )
puts % slat
puts % (lng-ref)
puts
puts 'Hour, sun hour angle, dial hour line angle from 6am to 6pm'
-6.upto(6) do |h|
... | 739Horizontal sundial calculations | 14ruby | ezjax |
object Huffman {
import scala.collection.mutable.{Map, PriorityQueue}
sealed abstract class Tree
case class Node(left: Tree, right: Tree) extends Tree
case class Leaf(c: Char) extends Tree
def treeOrdering(m: Map[Tree, Int]) = new Ordering[Tree] {
def compare(x: Tree, y: Tree) = m(y).compare(m(x))
}... | 736Huffman coding | 16scala | w3pes |
from dateutil.easter import *
import datetime, calendar
class Holiday(object):
def __init__(self, date, offset=0):
self.holiday = date + datetime.timedelta(days=offset)
def __str__(self):
dayofweek = calendar.day_name[self.holiday.weekday()][0:3]
month = calendar.month_name[self.holida... | 745Holidays related to Easter | 3python | homjw |
use std::io;
struct SundialCalculation {
hour_angle: f64,
hour_line_angle: f64,
}
fn get_input(prompt: &str) -> Result<f64, Box<dyn std::error::Error>> {
println!("{}", prompt);
let mut input = String::new();
let stdin = io::stdin();
stdin.read_line(&mut input)?;
Ok(input.trim().parse::<f64... | 739Horizontal sundial calculations | 15rust | w3he4 |
warn "Goodbye, World!\n"; | 753Hello world/Standard error | 2perl | x6mw8 |
fprintf(STDERR, ); | 753Hello world/Standard error | 12php | 21el4 |
null | 749Hofstadter Q sequence | 11kotlin | t4kf0 |
library(tidyverse)
library(lubridate)
pretty_date = stamp_date("Thu, Jun 1, 2000")
tibble(year = c(seq(400, 2100, 100), 2010:2020))%>%
arrange(year)%>%
mutate(a = year%% 19,
b = year%% 4,
c = year%% 7,
k = year%/% 100,
p = (13 + 8 * k)%/% 25,
q = k%/% 4,
M ... | 745Holidays related to Easter | 13r | gqz47 |
import java.util.Scanner
import scala.math.{atan2, cos, sin, toDegrees, toRadians}
object Sundial extends App {
var lat, slat,lng, ref = .0
val sc = new Scanner(System.in)
print("Enter latitude: ")
lat = sc.nextDouble
print("Enter longitude: ")
lng = sc.nextDouble
print("Enter legal meridian: ")
ref =... | 739Horizontal sundial calculations | 16scala | smpqo |
class HofstadterConway10000
def initialize
@sequence = [nil, 1, 1]
end
def [](n)
raise ArgumentError, if n < 1
a = @sequence
a.length.upto(n) {|i| a[i] = a[a[i-1]] + a[i-a[i-1]] }
a[n]
end
end
hc = HofstadterConway10000.new
mallows = nil
(1...20).each do |i|
j = i + 1
max_n, max_v = ... | 743Hofstadter-Conway $10,000 sequence | 14ruby | 4x35p |
use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | 752Heronian triangles | 2perl | f5rd7 |
from wsgiref.simple_server import make_server
def app(environ, start_response):
start_response('200 OK', [('Content-Type','text/html')])
yield b
server = make_server('127.0.0.1', 8080, app)
server.serve_forever() | 750Hello world/Web server | 3python | f5jde |
library(httpuv)
runServer("0.0.0.0", 5000,
list(
call = function(req) {
list(status = 200L, headers = list('Content-Type' = 'text/html'), body = "Hello world!")
}
)
) | 750Hello world/Web server | 13r | ol484 |
struct HofstadterConway {
current: usize,
sequence: Vec<usize>,
}
impl HofstadterConway { | 743Hofstadter-Conway $10,000 sequence | 15rust | gq64o |
object HofstadterConway {
def pow2(n: Int): Int = (Iterator.fill(n)(2)).product
def makeHCSequence(max: Int): Seq[Int] =
(0 to max - 1).foldLeft (Vector[Int]()) { (v, idx) =>
if (idx <= 1) v :+ 1 else v :+ (v(v(idx - 1) - 1) + v(idx - v(idx - 1)))
}
val max = pow2(20)
val maxSeq = makeHCSeque... | 743Hofstadter-Conway $10,000 sequence | 16scala | j897i |
import sys
print >> sys.stderr, | 753Hello world/Standard error | 3python | qy9xi |
def horner(coeffs, x)
coeffs.reverse.inject(0) {|acc, coeff| acc * x + coeff}
end
p horner([-19, 7, -4, 6], 3) | 740Horner's rule for polynomial evaluation | 14ruby | 8c101 |
cat("Goodbye, World!", file=stderr()) | 753Hello world/Standard error | 13r | at31z |
fn horner(v: &[f64], x: f64) -> f64 {
v.iter().rev().fold(0.0, |acc, coeff| acc*x + coeff)
}
fn main() {
let v = [-19., 7., -4., 6.];
println!("result: {}", horner(&v, 3.0));
} | 740Horner's rule for polynomial evaluation | 15rust | ola83 |
enum HuffmanTree<T> {
case Leaf(T)
indirect case Node(HuffmanTree<T>, HuffmanTree<T>)
func printCodes(prefix: String) {
switch(self) {
case let .Leaf(c):
print("\(c)\t\(prefix)")
case let .Node(l, r):
l.printCodes(prefix + "0")
r.printCodes(prefix + "1")
}
}
}
func buildTree<... | 736Huffman coding | 17swift | bn7kd |
STDERR.puts | 753Hello world/Standard error | 14ruby | 09lsu |
from __future__ import division, print_function
from math import gcd, sqrt
def hero(a, b, c):
s = (a + b + c) / 2
a2 = s * (s - a) * (s - b) * (s - c)
return sqrt(a2) if a2 > 0 else 0
def is_heronian(a, b, c):
a = hero(a, b, c)
return a > 0 and a.is_integer()
def gcd3(x, y, z):
return gcd(... | 752Heronian triangles | 3python | t47fw |
require 'webrick'
server = WEBrick::HTTPServer.new(:Port => 8080)
server.mount_proc('/') {|request, response| response.body = }
trap() {server.shutdown}
server.start | 750Hello world/Web server | 14ruby | zgktw |
def horner(coeffs:List[Double], x:Double)=
coeffs.reverse.foldLeft(0.0){(a,c)=> a*x+c} | 740Horner's rule for polynomial evaluation | 16scala | duxng |
require 'date'
def easter_date(year)
a = year % 19
b, c = year.divmod(100)
d, e = b.divmod(4)
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19*a + b - d - g + 15) % 30
i, k = c.divmod(4)
l = (32 + 2*e + 2*i - h - k) % 7
m = (a + 11*h + 22*l) / 451
numerator = h + l - 7*m + 114
... | 745Holidays related to Easter | 14ruby | bnckq |
func doSqnc(m:Int) {
var aList = [Int](count: m + 1, repeatedValue: 0)
var k1 = 2
var lg2 = 1
var amax:Double = 0
aList[0] = 1
aList[1] = 1
var v = aList[2]
for n in 2...m {
let add = aList[v] + aList[n - v]
aList[n] = add
v = aList[n]
if amax < Double(... | 743Hofstadter-Conway $10,000 sequence | 17swift | 5wzu8 |
fn main() {
eprintln!("Hello, {}!", "world");
} | 753Hello world/Standard error | 15rust | 8c207 |
Console.err.println("Goodbye, World!") | 753Hello world/Standard error | 16scala | nv5ic |
area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | 752Heronian triangles | 13r | i25o5 |
use std::net::{Shutdown, TcpListener};
use std::thread;
use std::io::Write;
const RESPONSE: &'static [u8] = b"HTTP/1.1 200 OK\r
Content-Type: text/html; charset=UTF-8\r\n\r
<!DOCTYPE html><html><head><title>Bye-bye baby bye-bye</title>
<style>body { background-color: #111 }
h1 { font-size:4cm; text-align: center; colo... | 750Hello world/Web server | 15rust | 3rbz8 |
use std::ops::Add;
use chrono::{prelude::*, Duration};
#[allow(clippy::cast_possible_truncation)]
#[allow(clippy::cast_sign_loss)]
#[allow(clippy::cast_possible_wrap)]
fn get_easter_day(year: u32) -> chrono::NaiveDate {
let k = (f64::from(year) / 100.).floor();
let d = (19 * (year% 19)
+ ((15 - ((13. ... | 745Holidays related to Easter | 15rust | pdlbu |
import java.io.PrintWriter
import java.net.ServerSocket
object HelloWorld extends App {
val text =
<HTML>
<HEAD>
<TITLE>Hello world </TITLE>
</HEAD>
<BODY LANG="en-US" BGCOLOR="#e6e6ff" DIR="LTR">
<P ALIGN="CENTER"> <FONT FACE="Arial, sans-serif" SIZE="6">Goodbye, World!</FONT>... | 750Hello world/Web server | 16scala | mhayc |
import java.util._
import scala.swing._
def easter(year: Int) = { | 745Holidays related to Easter | 16scala | ezuab |
func horner(coefs: [Double], x: Double) -> Double {
return reduce(lazy(coefs).reverse(), 0) { $0 * x + $1 }
}
println(horner([-19, 7, -4, 6], 3)) | 740Horner's rule for polynomial evaluation | 17swift | 09ps6 |
import Foundation
let out = NSOutputStream(toFileAtPath: "/dev/stderr", append: true)
let err = "Goodbye, World!".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
out?.open()
let success = out?.write(UnsafePointer<UInt8>(err!.bytes), maxLength: err!.length)
out?.close()
if let bytes = success {
... | 753Hello world/Standard error | 17swift | smcqt |
my @Q = (0,1,1);
push @Q, $Q[-$Q[-1]] + $Q[-$Q[-2]] for 1..100_000;
say "First 10 terms: [@Q[1..10]]";
say "Term 1000: $Q[1000]";
say "Terms less than preceding in first 100k: ",scalar(grep { $Q[$_] < $Q[$_-1] } 2..100000); | 749Hofstadter Q sequence | 2perl | ki3hc |
class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - c))
... | 752Heronian triangles | 14ruby | 3rhz7 |
use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... | 752Heronian triangles | 15rust | 67k3l |
use strict; use warnings;
require 5.014;
use HTTP::Tiny;
print( HTTP::Tiny->new()->get( 'http://rosettacode.org')->{content} ); | 741HTTP | 2perl | t4qfg |
object Heron extends scala.collection.mutable.MutableList[Seq[Int]] with App {
private final val n = 200
for (c <- 1 to n; b <- 1 to c; a <- 1 to b if gcd(gcd(a, b), c) == 1) {
val p = a + b + c
val s = p / 2D
val area = Math.sqrt(s * (s - a) * (s - b) * (s - c))
if (isHeron(area... | 752Heronian triangles | 16scala | 9k1m5 |
readfile(); | 741HTTP | 12php | kivhv |
def q(n):
if n < 1 or type(n) != int: raise ValueError()
try:
return q.seq[n]
except IndexError:
ans = q(n - q(n - 1)) + q(n - q(n - 2))
q.seq.append(ans)
return ans
q.seq = [None, 1, 1]
if __name__ == '__main__':
first10 = [q(i) for i in range(1,11)]
assert first10 ... | 749Hofstadter Q sequence | 3python | bn6kr |
import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * (s -... | 752Heronian triangles | 17swift | zgjtu |
cache <- vector("integer", 0)
cache[1] <- 1
cache[2] <- 1
Q <- function(n) {
if (is.na(cache[n])) {
value <- Q(n-Q(n-1)) + Q(n-Q(n-2))
cache[n] <<- value
}
cache[n]
}
for (i in 1:1e5) {
Q(i)
}
for (i in 1:10) {
cat(Q(i)," ",sep = "")
}
cat("\n")
cat(Q(1000),"\n")
count <- 0
for (i in 2:1e5) {
if... | 749Hofstadter Q sequence | 13r | 70fry |
import urllib.request
print(urllib.request.urlopen().read()) | 741HTTP | 3python | zgstt |
library(RCurl)
webpage <- getURL("http://rosettacode.org")
webpage <- getURL("http://www.rosettacode.org", .opts=list(followlocation=TRUE))
webpage <- getURL("http://rosettacode.org",
.opts=list(proxy="123.123.123.123", proxyusername="domain\\username", proxypassword="mypassword", proxyport=8080)) | 741HTTP | 13r | nvei2 |
@cache = []
def Q(n)
if @cache[n].nil?
case n
when 1, 2 then @cache[n] = 1
else @cache[n] = Q(n - Q(n-1)) + Q(n - Q(n-2))
end
end
@cache[n]
end
puts
puts
prev = Q(1)
count = 0
2.upto(100_000) do |n|
q = Q(n)
count += 1 if q < prev
prev = q
end
puts | 749Hofstadter Q sequence | 14ruby | 1fmpw |
fn hofq(q: &mut Vec<u32>, x: u32) -> u32 {
let cur_len=q.len()-1;
let i=x as usize;
if i>cur_len { | 749Hofstadter Q sequence | 15rust | at914 |
object HofstadterQseq extends App {
val Q: Int => Int = n => {
if (n <= 2) 1
else Q(n-Q(n-1))+Q(n-Q(n-2))
}
(1 to 10).map(i=>(i,Q(i))).foreach(t=>println("Q("+t._1+") = "+t._2))
println("Q("+1000+") = "+Q(1000))
} | 749Hofstadter Q sequence | 16scala | x62wg |
require 'open-uri'
print open() {|f| f.read} | 741HTTP | 14ruby | 6783t |
let n = 100000
var q = Array(repeating: 0, count: n)
q[0] = 1
q[1] = 1
for i in 2..<n {
q[i] = q[i - q[i - 1]] + q[i - q[i - 2]]
}
print("First 10 elements of the sequence: \(q[0..<10])")
print("1000th element of the sequence: \(q[999])")
var count = 0
for i in 1..<n {
if q[i] < q[i - 1] {
count += ... | 749Hofstadter Q sequence | 17swift | pdybl |
[dependencies]
hyper = "0.6" | 741HTTP | 15rust | yjo68 |
import scala.io.Source
object HttpTest extends App {
System.setProperty("http.agent", "*")
Source.fromURL("http: | 741HTTP | 16scala | cbd93 |
package main
import "fmt"
func func1(f func(string) string) string { return f("a string") }
func func2(s string) string { return "func2 called with " + s }
func main() { fmt.Println(func1(func2)) } | 754Higher-order functions | 0go | hoijq |
first = { func -> func() }
second = { println "second" }
first(second) | 754Higher-order functions | 7groovy | 4xq5f |
func1 f = f "a string"
func2 s = "func2 called with " ++ s
main = putStrLn $ func1 func2 | 754Higher-order functions | 8haskell | i2vor |
import Foundation
let request = NSURLRequest(URL: NSURL(string: "http: | 741HTTP | 17swift | 3r0z2 |
echo "Hello world!" | 755Hello world/Text | 4bash | cbb96 |
public class NewClass {
public NewClass() {
first(new AnEventOrCallback() {
public void call() {
second();
}
});
}
public void first(AnEventOrCallback obj) {
obj.call();
}
public void second() {
System.out.println("Second");
}
pub... | 754Higher-order functions | 9java | x6ywy |
function first (func) {
return func();
}
function second () {
return "second";
}
var result = first(second);
result = first(function () { return "third"; }); | 754Higher-order functions | 10javascript | ol286 |
fun main(args: Array<String>) {
val list = listOf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0)
val a = list.map({ x -> x + 2 }).average()
val h = list.map({ x -> x * x }).average()
val g = list.map({ x -> x * x * x }).average()
println("A =%f G =%f H =%f".format(a, g, h))
} | 754Higher-order functions | 11kotlin | pdfb6 |
a = function() return 1 end
b = function(r) print( r() ) end
b(a) | 754Higher-order functions | 1lua | 1ftpo |
int main(void)
{
printf();
return EXIT_SUCCESS;
} | 755Hello world/Text | 5c | 211lo |
sub another {
my $func = shift;
my $val = shift;
return $func->($val);
};
sub reverser {
return scalar reverse shift;
};
print another \&reverser, 'data';
print another sub {return scalar reverse shift}, 'data';
my %dispatch = (
square => sub {return shift() ** 2},
cube => s... | 754Higher-order functions | 2perl | yjh6u |
function first($func) {
return $func();
}
function second() {
return 'second';
}
$result = first('second'); | 754Higher-order functions | 12php | atz12 |
(println "Hello world!") | 755Hello world/Text | 6clojure | gqq4f |
def first(function):
return function()
def second():
return
result = first(second) | 754Higher-order functions | 3python | mhkyh |
int main()
{
FILE *lp;
lp = fopen(,);
fprintf(lp,);
fclose(lp);
return 0;
} | 756Hello world/Line printer | 5c | pdnby |
f <- function(f0) f0(pi)
tf <- function(x) x^pi
print(f(sin))
print(f(cos))
print(f(tf)) | 754Higher-order functions | 13r | zgrth |
(ns rosetta-code.line-printer
(:import java.io.FileWriter))
(defn -main [& args]
(with-open [wr (new FileWriter "/dev/lp0")]
(.write wr "Hello, World!"))) | 756Hello world/Line printer | 6clojure | x63wk |
succ = proc{|x| x+1}
def to2(&f)
f[2]
end
to2(&succ)
to2{|x| x+1} | 754Higher-order functions | 14ruby | cbp9k |
package main
import (
"fmt"
"os"
)
func main() {
lp0, err := os.Create("/dev/lp0")
if err != nil {
panic(err)
}
defer lp0.Close()
fmt.Fprintln(lp0, "Hello World!")
} | 756Hello world/Line printer | 0go | 67r3p |
new File('/dev/lp0').write('Hello World!\n') | 756Hello world/Line printer | 7groovy | duvn3 |
fn execute_with_10<F: Fn(u64) -> u64> (f: F) -> u64 {
f(10)
}
fn square(n: u64) -> u64 {
n*n
}
fn main() {
println!("{}", execute_with_10(|n| n*n )); | 754Higher-order functions | 15rust | lp1cc |
def functionWithAFunctionArgument(x : int, y : int, f : (int, int) => int) = f(x,y) | 754Higher-order functions | 16scala | uewv8 |
import System.Process (ProcessHandle, runCommand)
main :: IO ProcessHandle
main = runCommand "echo \"Hello World!\" | lpr" | 756Hello world/Line printer | 8haskell | j807g |
import java.io.FileWriter;
import java.io.IOException;
public class LinePrinter {
public static void main(String[] args) {
try {
FileWriter lp0 = new FileWriter("/dev/lp0");
lp0.write("Hello World!");
lp0.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
} | 756Hello world/Line printer | 9java | ueavv |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.