code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
package main
import (
"fmt"
)
func main() {
a := []int{0, 1, 1} | 743Hofstadter-Conway $10,000 sequence | 0go | ez4a6 |
(binding [*out* *err*]
(println "Goodbye, world!")) | 753Hello world/Standard error | 6clojure | qy9xt |
null | 746Hickerson series of almost integers | 11kotlin | nvkij |
import 'dart:io';
main() async {
var server = await HttpServer.bind('127.0.0.1', 8080);
await for (HttpRequest request in server) {
request.response
..write('Hello, world')
..close();
}
} | 750Hello world/Web server | 18dart | ez9an |
function horner(coeffs, x) {
return coeffs.reduceRight( function(acc, coeff) { return(acc * x + coeff) }, 0);
}
console.log(horner([-19,7,-4,6],3)); | 740Horner's rule for polynomial evaluation | 10javascript | hovjh |
const hilbert = (width, spacing, points) => (x, y, lg, i1, i2, f) => {
if (lg === 1) {
const px = (width - x) * spacing;
const py = (width - y) * spacing;
points.push(px, py);
return;
}
lg >>= 1;
f(x + i1 * lg, y + i1 * lg, lg, i1, 1 - i2, f);
f(x + i2 * lg, y + (1 - ... | 748Hilbert curve | 10javascript | nvjiy |
(struct Hex (x y letter clicked?)
(define hexes
(let* ([A (char->integer
[letters (take (shuffle (map (compose string integer->char)
(range A (+ A 26))))
20)])
(for*/list ([row 4] [column 5])
(Hex (* 3/2 column) (* 2 (+ row (if (odd? ... | 742Honeycombs | 3python | rsmgq |
package main
import (
"fmt"
"time"
)
type holiday struct {
time.Time
}
func easter(y int) holiday {
c := y / 100
n := mod(y, 19)
i := mod(c-c/4-(c-(c-17)/25)/3+19*n+15, 30)
i -= (i / 28) * (1 - (i/28)*(29/(i+1))*((21-n)/11))
l := i - mod(y+y/4+i+2-c+c/4, 7)
m := 3 + (l+40)/44
... | 745Holidays related to Easter | 0go | olh8q |
print(ProcessInfo.processInfo.hostName) | 737Hostname | 17swift | rsvgg |
import Data.List
import Data.Ord
import Data.Array
import Text.Printf
hc :: Int -> Array Int Int
hc n = arr
where arr = listArray (1, n) $ 1: 1: map (f (arr!)) [3 .. n]
f a i = a (a $ i - 1) + a (i - a (i - 1))
printMaxima :: (Int, (Int, Double)) -> IO ()
printMaxima (n, (pos, m)) =
printf "Max between ... | 743Hofstadter-Conway $10,000 sequence | 8haskell | 3rqzj |
package History;
sub TIESCALAR {
my $cls = shift;
my $cur_val = shift;
return bless [];
}
sub FETCH {
return shift->[-1]
}
sub STORE {
my ($var, $val) = @_;
push @$var, $val;
return $val;
}
sub get(\$) { @{tied ${+shift}} }
sub on(\$) { tie ${+shift}, __PACKAGE__ }
sub off(\$) { untie ${+shift} }
sub undo(\... | 744History variables | 2perl | 21nlf |
import java.util.*;
class Hofstadter
{
private static List<Integer> getSequence(int rlistSize, int slistSize)
{
List<Integer> rlist = new ArrayList<Integer>();
List<Integer> slist = new ArrayList<Integer>();
Collections.addAll(rlist, 1, 3, 7);
Collections.addAll(slist, 2, 4, 5, 6);
List<Integer... | 747Hofstadter Figure-Figure sequences | 9java | j837c |
null | 740Horner's rule for polynomial evaluation | 11kotlin | lptcp |
Shoes.app(title: , height: 700, width: 700) do
C = Math::cos(Math::PI/3)
S = Math::sin(Math::PI/3)
Radius = 60.0
letters = [
%w[L A R N D 1 2],
%w[G U I Y T 3 4],
%w[P C F E B 5 6],
%w[V S O M K 7 8],
%w[Q X J Z H 9 0],
]
def highlight(hexagon)
hexagon.style(fill: magenta)
end
de... | 742Honeycombs | 14ruby | j8c7x |
use 5.10.0;
use strict;
sub walk {
my ($node, $code, $h, $rev_h) = @_;
my $c = $node->[0];
if (ref $c) { walk($c->[$_], $code.$_, $h, $rev_h) for 0,1 }
else { $h->{$c} = $code; $rev_h->{$code} = $c }
$h, $rev_h
}
sub mktree {
my (%freq, @nodes);
$freq{$_}++ for split '', shift;
@nodes = map([$_, $f... | 736Huffman coding | 2perl | hogjl |
def identity(size)
Array.new(size){|i| Array.new(size){|j| i==j? 1: 0}}
end
[4,5,6].each do |size|
puts size, identity(size).map {|r| r.to_s},
end | 730Identity matrix | 14ruby | mklyj |
int Q(int n) => n>2? Q(n-Q(n-1))+Q(n-Q(n-2)): 1;
main() {
for(int i=1;i<=10;i++) {
print("Q($i)=${Q(i)}");
}
print("Q(1000)=${Q(1000)}");
} | 749Hofstadter Q sequence | 18dart | 21slp |
var m = ` leading spaces
and blank lines` | 751Here document | 0go | vaq2m |
println '''
Time's a strange fellow;
more he gives than takes
(and he takes all) nor any marvel finds
quite disappearance but some keener makes
losing, gaining
--love! if a world ends
''' | 751Here document | 7groovy | mh1y5 |
var R = [null, 1];
var S = [null, 2];
var extend_sequences = function (n) {
var current = Math.max(R[R.length-1],S[S.length-1]);
var i;
while (R.length <= n || S.length <= n) {
i = Math.min(R.length, S.length) - 1;
current += 1;
if (current === R[i] + S[i]) {
R.push(current);
} else {
S.push(current);... | 747Hofstadter Figure-Figure sequences | 10javascript | 1fcp7 |
null | 748Hilbert curve | 11kotlin | atc13 |
import java.awt.{BasicStroke, BorderLayout, Color, Dimension,
Font, FontMetrics, Graphics, Graphics2D, Point, Polygon, RenderingHints}
import java.awt.event.{KeyAdapter, KeyEvent, MouseAdapter, MouseEvent}
import javax.swing.{JFrame, JPanel}
import scala.math.{Pi, cos, sin}
object Honeycombs extends App {
privat... | 742Honeycombs | 16scala | pdubj |
io.write("Enter latitude => ")
lat = tonumber(io.read())
io.write("Enter longitude => ")
lng = tonumber(io.read())
io.write("Enter legal meridian => ")
ref = tonumber(io.read())
print()
slat = math.sin(math.rad(lat))
print(string.format(" sine of latitude: %.3f", slat))
print(string.format(" diff... | 739Horizontal sundial calculations | 1lua | 67i39 |
a = (print ; gets).to_i
b = (print ; gets).to_i
puts if a < b
puts if a > b
puts if a == b | 725Integer comparison | 14ruby | veh2n |
import 'dart:io';
void main() {
stderr.writeln('Goodbye, World!');
} | 753Hello world/Standard error | 18dart | 70or7 |
use strict;
use warnings;
use Math::BigFloat;
my $iln2 = 1 / Math::BigFloat->new(2)->blog;
my $h = $iln2 / 2;
for my $n ( 1 .. 17 ) {
$h *= $iln2;
$h *= $n;
my $s = $h->copy->bfround(-3)->bstr;
printf "h(%2d) =%22s is%s almost an integer.\n",
$n, $s, ($s =~ /\.[09]/ ? "" : " NOT");
} | 746Hickerson series of almost integers | 2perl | 703rh |
main :: IO ()
main = do
putStrLn "Hello\
\ World!\n"
putStrLn $ unwords ["This", "is", "an", "example", "text!\n"]
putStrLn $ unlines [
unwords ["This", "is", "the", "first" , "line."]
, unwords ["This", "is", "the", "second", "line."]
, unwords ["This", "is", ... | 751Here document | 8haskell | ezmai |
function horners_rule( coeff, x )
local res = 0
for i = #coeff, 1, -1 do
res = res * x + coeff[i]
end
return res
end
x = 3
coefficients = { -19, 7, -4, 6 }
print( horners_rule( coefficients, x ) ) | 740Horner's rule for polynomial evaluation | 1lua | 21zl3 |
import java.text.DateFormatSymbols;
import java.util.*;
public class EasterRelatedHolidays {
final static Map<String, Integer> holidayOffsets;
static {
holidayOffsets = new LinkedHashMap<>();
holidayOffsets.put("Easter", 0);
holidayOffsets.put("Ascension", 39);
holidayOffsets.... | 745Holidays related to Easter | 9java | 67x3z |
<?php
function encode($symb2freq) {
$heap = new SplPriorityQueue;
$heap->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
foreach ($symb2freq as $sym => $wt)
$heap->insert(array($sym => ''), -$wt);
while ($heap->count() > 1) {
$lo = $heap->extract();
$hi = $heap->extract();
... | 736Huffman coding | 12php | zgnt1 |
extern crate num;
struct Matrix<T> {
data: Vec<T>,
size: usize,
}
impl<T> Matrix<T>
where
T: num::Num + Clone + Copy,
{
fn new(size: usize) -> Self {
Self {
data: vec![T::zero(); size * size],
size: size,
}
}
fn get(&mut self, x: usize, y: usize) -> T {
... | 730Identity matrix | 15rust | 9b2mm |
use std::io::{self, BufRead};
fn main() {
let mut reader = io::stdin();
let mut buffer = String::new();
let mut lines = reader.lock().lines().take(2);
let nums: Vec<i32>= lines.map(|string|
string.unwrap().trim().parse().unwrap()
).collect();
let a: i32 = nums[0];
let b: i32 = n... | 725Integer comparison | 15rust | uwkvj |
package main
import (
"io"
"log"
"net/http"
"os"
)
func main() {
r, err := http.Get("http: | 741HTTP | 0go | gqm4n |
null | 743Hofstadter-Conway $10,000 sequence | 9java | i2pos |
const myVar = 123;
const tempLit = `Here is some
multi-line string. And here is
the value of "myVar": ${myVar}
That's all.`;
console.log(tempLit) | 751Here document | 10javascript | aty10 |
null | 751Here document | 11kotlin | 4x857 |
import sys
HIST = {}
def trace(frame, event, arg):
for name,val in frame.f_locals.items():
if name not in HIST:
HIST[name] = []
else:
if HIST[name][-1] is val:
continue
HIST[name].append(val)
return trace
def undo(name):
HIST[name].pop(-1)
... | 744History variables | 3python | vad29 |
fun ffr(n: Int) = get(n, 0)[n - 1]
fun ffs(n: Int) = get(0, n)[n - 1]
internal fun get(rSize: Int, sSize: Int): List<Int> {
val rlist = arrayListOf(1, 3, 7)
val slist = arrayListOf(2, 4, 5, 6)
val list = if (rSize > 0) rlist else slist
val targetSize = if (rSize > 0) rSize else sSize
while (list.... | 747Hofstadter Figure-Figure sequences | 11kotlin | 5wnua |
null | 748Hilbert curve | 1lua | ezlac |
const = => {
let = ( % 19 * 19 + 15) % 30;
+= ( % 4 * 2 + % 7 * 4 + 6 * + 6) % 7;
if ( >= 1918) += ( / 100 | 0) - ( / 400 | 0) - 2;
return new Date(, 2, 22 + );
};
for (let = 400; <= 2100; += < 2000 ? 100 : >= 2020 ? 80 : < 2010 ? 10 : 1) {
const _ = ();
document.write(
+ ": " +
[ ["Easter", 1]... | 745Holidays related to Easter | 10javascript | lpocf |
def identityMatrix(n:Int)=Array.tabulate(n,n)((x,y) => if(x==y) 1 else 0)
def printMatrix[T](m:Array[Array[T]])=m map (_.mkString("[", ", ", "]")) mkString "\n"
printMatrix(identityMatrix(5)) | 730Identity matrix | 16scala | 2a5lb |
new URL("http: | 741HTTP | 7groovy | 21tlv |
var hofst_10k = function(n) {
var memo = [1, 1];
var a = function(n) {
var result = memo[n-1];
if (typeof result !== 'number') {
result = a(a(n-1))+a(n-a(n-1));
memo[n-1] = result;
}
return result;
}
return a;
}();
var maxima_between_twos = function(exp) {
var current_max = 0;
for(var i = Math.p... | 743Hofstadter-Conway $10,000 sequence | 10javascript | zgxt2 |
print([[
This is a long paragraph of text
it is the simplest while using it
with lua, however it will have the
same line breaks and spacing as
you set in this block.
]])
print([=[by using equals signs, ]] may be embedded.]=])
local msg = [[this is a message that spans
multiple lines and will have the next lines
... | 751Here document | 1lua | gqo4j |
object IntCompare {
def main(args: Array[String]): Unit = {
val a=Console.readInt
val b=Console.readInt
if (a < b)
printf("%d is less than%d\n", a, b)
if (a == b)
printf("%d is equal to%d\n", a, b)
if (a > b)
printf("%d is greater than%d\n", a, b)
}
} | 725Integer comparison | 16scala | gs14i |
from decimal import Decimal
import math
def h(n):
'Simple, reduced precision calculation'
return math.factorial(n) / (2 * math.log(2) ** (n + 1))
def h2(n):
'Extended precision Hickerson function'
return Decimal(math.factorial(n)) / (2 * Decimal(2).ln() ** (n + 1))
for n in range(18):
x = h2(n)
... | 746Hickerson series of almost integers | 3python | j867p |
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintln(w, "Goodbye, World!")
})
log.Fatal(http.ListenAndServe(":8080", nil))
} | 750Hello world/Web server | 0go | 5w8ul |
import Data.ByteString.Char8 ()
import Data.Conduit ( ($$), yield )
import Data.Conduit.Network ( ServerSettings(..), runTCPServer )
main :: IO ()
main = runTCPServer (ServerSettings 8080 "127.0.0.1") $ const (yield response $$)
where response = "HTTP/1.0 200 OK\nContent-Length: 16\n\nGoodbye, World!\n" | 750Hello world/Web server | 8haskell | x6lw4 |
foo_hist = []
trace_var(:$foo){|v| foo_hist.unshift(v)}
$foo =
$foo =
$foo =
p foo_hist | 744History variables | 14ruby | 5wtuj |
use SVG;
use List::Util qw(max min);
use constant pi => 2 * atan2(1, 0);
%rules = (
A => '-BF+AFA+FB-',
B => '+AF-BFB-FA+'
);
$hilbert = 'A';
$hilbert =~ s/([AB])/$rules{$1}/eg for 1..6;
($x, $y) = (0, 0);
$theta = pi/2;
$r = 5;
for (split //, $hilbert) {
if (/F/) {
push @X, sprintf "%... | 748Hilbert curve | 2perl | 9kxmn |
null | 745Holidays related to Easter | 11kotlin | dupnz |
import Network.Browser
import Network.HTTP
import Network.URI
main = do
rsp <- Network.Browser.browse $ do
setAllowRedirects True
setOutHandler $ const (return ())
request $ getRequest "http://www.rosettacode.org/"
putStrLn $ rspBody $ snd rsp | 741HTTP | 8haskell | smkqk |
null | 743Hofstadter-Conway $10,000 sequence | 11kotlin | qy7x1 |
#[derive(Clone, Debug)]
struct HVar<T> {
history: Vec<T>,
current: T,
}
impl<T> HVar<T> {
fn new(val: T) -> Self {
HVar {
history: Vec::new(),
current: val,
}
}
fn get(&self) -> &T {
&self.current
}
fn set(&mut self, val: T) {
self.h... | 744History variables | 15rust | 4xz5u |
class HVar[A](initialValue: A) extends Proxy {
override def self = !this
override def toString = "HVar(" + !this + ")"
def history = _history
private var _history = List(initialValue)
def unary_! = _history.head
def :=(newValue: A): Unit = {
_history = newValue :: _history
}
def modify(f: A => A):... | 744History variables | 16scala | 70yr9 |
use strict;
use warnings;
my @r = ( undef, 1 );
my @s = ( undef, 2 );
sub ffsr {
my $n = shift;
while( $
push @r, $s[$
push @s, grep { $s[-1]<$_ } $s[-1]+1..$r[-1]-1, $r[-1]+1;
}
return $n;
}
sub ffr { $r[ffsr shift] }
sub ffs { $s[ffsr shift] }
printf " i: R(i) S(i)\n";
printf "==============\n";
... | 747Hofstadter Figure-Figure sequences | 2perl | ol78x |
local Time = require("time")
function div (x, y) return math.floor(x / y) end
function easter (year)
local G = year % 19
local C = div(year, 100)
local H = (C - div(C, 4) - div((8 * C + 13), 25) + 19 * G + 15) % 30
local I = H - div(H, 28) * (1 - div(29, H + 1)) * (div(21 - G, 11))
local J = (year... | 745Holidays related to Easter | 1lua | f51dp |
local fmt, write=string.format,io.write
local hof=coroutine.wrap(function()
local yield=coroutine.yield
local a={1,1}
yield(a[1], 1)
yield(a[2], 2)
local n=a[#a]
repeat
n=a[n]+a[1+#a-n]
a[#a+1]=n
yield(n, #a)
until false
end)
local mallows, mdiv=0,0
for p=1,20 do
local max, div, num, last, fdiv=0,0,0,0,0... | 743Hofstadter-Conway $10,000 sequence | 1lua | smjq8 |
package main
func main() { println("Goodbye, World!") } | 753Hello world/Standard error | 0go | yjk64 |
require
LN2 = BigMath::log(2,16)
FACTORIALS = Hash.new{|h,k| h[k] = k * h[k-1]}
FACTORIALS[0] = 1
def hickerson(n)
FACTORIALS[n] / (2 * LN2 ** (n+1))
end
def nearly_int?(n)
int = n.round
n.between?(int - 0.1, int + 0.1)
end
1.upto(17) do |n|
h = hickerson(n)
str = nearly_int?(h)? :
puts % [n, h.to_... | 746Hickerson series of almost integers | 14ruby | kimhg |
import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class HelloWorld{
public static void main(String[] args) throws IOException{
ServerSocket listener = new ServerSocket(8080);
while(true){
Socket sock = listener.accept();
new Print... | 750Hello world/Web server | 9java | bn3k3 |
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Goodbye, World!\n');
}).listen(8080, '127.0.0.1'); | 750Hello world/Web server | 10javascript | w3ce2 |
$address = <<END;
1, High Street,
$town_name,
West Midlands.
WM4 5HD.
END | 751Here document | 2perl | i24o3 |
$address = <<<END
1, High Street,
$town_name,
West Midlands.
WM4 5HD.
END; | 751Here document | 12php | rsige |
System.err.println("Goodbye, World!") | 753Hello world/Standard error | 7groovy | f5gdn |
import System.IO
main = hPutStrLn stderr "Goodbye, World!" | 753Hello world/Standard error | 8haskell | honju |
use decimal::d128;
use factorial::Factorial;
fn hickerson(n: u64) -> d128 {
d128::from(n.factorial()) / (d128!(2) * (d128!(2).ln().pow(d128::from(n + 1))))
} | 746Hickerson series of almost integers | 15rust | bn9kx |
import scala.annotation.tailrec
object Hickerson extends App {
def almostInteger(n: Int): Boolean = {
def ln2 = BigDecimal("0.69314718055994530941723212145818")
def div: BigDecimal = ln2.pow(n + 1) * 2
def factorial(num: Int): Long = {
@tailrec
def accumulated(acc: Long, n: Long): Long =
... | 746Hickerson series of almost integers | 16scala | at21n |
package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... | 752Heronian triangles | 0go | 4x052 |
void myFuncSimple( void (*funcParameter)(void) )
{
(*funcParameter)();
funcParameter();
} | 754Higher-order functions | 5c | t4gf4 |
print() | 751Here document | 3python | nvgiz |
var historyOfHistory = [Int]()
var history:Int = 0 {
willSet {
historyOfHistory.append(history)
}
}
history = 2
history = 3
history = 4
println(historyOfHistory) | 744History variables | 17swift | uefvg |
'''Hilbert curve'''
from itertools import (chain, islice)
def hilbertCurve(n):
'''An SVG string representing a
Hilbert curve of degree n.
'''
w = 1024
return svgFromPoints(w)(
hilbertPoints(w)(
hilbertTree(n)
)
)
def hilbertTree(n):
'''Nth application of... | 748Hilbert curve | 3python | cbq9q |
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.Charset;
public class Main {
public static void main(String[] args) {
var request = HttpRequest.newBuilder(URI.create("https: | 741HTTP | 9java | 1f4p2 |
public class Err{
public static void main(String[] args){
System.err.println("Goodbye, World!");
}
} | 753Hello world/Standard error | 9java | 5wquf |
WScript.StdErr.WriteLine("Goodbye, World!"); | 753Hello world/Standard error | 10javascript | j8i7n |
import qualified Data.List as L
import Data.Maybe
import Data.Ord
import Text.Printf
perfectSqrt :: Integral a => a -> Maybe a
perfectSqrt n
| n == 1 = Just 1
| n < 4 = Nothing
| otherwise =
let search low high =
let guess = (low + high) `div` 2
square = guess ^ 2
next
... | 752Heronian triangles | 8haskell | qycx9 |
import java.io.PrintWriter
import java.net.ServerSocket
fun main(args: Array<String>) {
val listener = ServerSocket(8080)
while(true) {
val sock = listener.accept()
PrintWriter(sock.outputStream, true).println("Goodbye, World!")
sock.close()
}
} | 750Hello world/Web server | 11kotlin | rsngo |
address = <<END
1, High Street,
West Midlands.
WM4 5HD.
END | 751Here document | 14ruby | f57dr |
from heapq import heappush, heappop, heapify
from collections import defaultdict
def encode(symb2freq):
heap = [[wt, [sym, ]] for sym, wt in symb2freq.items()]
heapify(heap)
while len(heap) > 1:
lo = heappop(heap)
hi = heappop(heap)
for pair in lo[1:]:
pair[1] = '0'... | 736Huffman coding | 3python | kirhf |
DROP TABLE test;
CREATE TABLE test(a INTEGER, b INTEGER);
INSERT INTO test VALUES (1,2);
INSERT INTO test VALUES (2,2);
INSERT INTO test VALUES (2,1);
SELECT to_char(a)||' is less than '||to_char(b) less_than
FROM test
WHERE a < b;
SELECT to_char(a)||' is equal to '||to_char(b) equal_to
FROM test
WHERE a = b;
SE... | 725Integer comparison | 19sql | jow7e |
var req = new XMLHttpRequest();
req.onload = function() {
console.log(this.responseText);
};
req.open('get', 'http: | 741HTTP | 10javascript | qyhx8 |
fun main(args: Array<String>) {
System.err.println("Goodbye, World!")
} | 753Hello world/Standard error | 11kotlin | cb198 |
local socket = require "socket"
local headers = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length:%d\r\n\r\n%s"
local content = "<!doctype html><html><title>Goodbye, World!</title><h1>Goodbye, World!"
local server = assert(socket.bind("localhost", 8080))
repeat
local client = server:accept... | 750Hello world/Web server | 1lua | 70dru |
let x = r#"
This is a "raw string literal," roughly equivalent to a heredoc.
"#;
let y = r##"
This string contains a #.
"##; | 751Here document | 15rust | t4jfd |
object temp {
val MemoriesOfHolland=
"""Thinking of Holland
|I see broad rivers
|slowly chuntering
|through endless lowlands,
|rows of implausibly
|airy poplars
|standing like tall plumes
|against the horizon;
|and sunk in the unbounded
|vastness of space
|homesteads and boweri... | 751Here document | 16scala | 67b31 |
def ffr(n):
if n < 1 or type(n) != int: raise ValueError()
try:
return ffr.r[n]
except IndexError:
r, s = ffr.r, ffs.s
ffr_n_1 = ffr(n-1)
lastr = r[-1]
s += list(range(s[-1] + 1, lastr))
if s[-1] < lastr: s += [lastr + 1]
len_s = len(... | 747Hofstadter Figure-Figure sequences | 3python | i2jof |
use utf8;
binmode STDOUT, ":utf8";
use constant => 3.14159265;
sub d2r { $_[0] * / 180 }
sub r2d { $_[0] * 180 / }
print 'Enter latitude => '; $latitude = <>;
print 'Enter longitude => '; $longitude = <>;
print 'Enter legal meridian => '; $meridian = <>;
$lat_sin = sin( d2r($latitude) );
$offset =... | 739Horizontal sundial calculations | 2perl | pdgb0 |
package main
import "fmt"
var m map[int]int
func initMap() {
m = make(map[int]int)
m[1] = 1
m[2] = 1
}
func q(n int) (r int) {
if r = m[n]; r == 0 {
r = q(n-q(n-1)) + q(n-q(n-2))
m[n] = r
}
return
}
func main() {
initMap() | 749Hofstadter Q sequence | 0go | nv7i1 |
import java.util.ArrayList;
public class Heron {
public static void main(String[] args) {
ArrayList<int[]> list = new ArrayList<>();
for (int c = 1; c <= 200; c++) {
for (int b = 1; b <= c; b++) {
for (int a = 1; a <= b; a++) {
if (gcd(gcd(a, b), c)... | 752Heronian triangles | 9java | pdzb3 |
rValues <- 1
sValues <- 2
ffr <- function(n)
{
if(!is.na(rValues[n])) rValues[n] else (rValues[n] <<- ffr(n-1) + ffs(n-1))
}
ffs <- function(n)
{
if(!is.na(sValues[n])) sValues[n] else (sValues[n] <<- setdiff(seq_len(1 + ffr(n)), rValues)[n])
}
invisible(ffr(10))
print(rValues)
invisible(ffs(500))
invisib... | 747Hofstadter Figure-Figure sequences | 13r | sm4qy |
load_library :grammar
attr_reader :hilbert
def settings
size 600, 600
end
def setup
sketch_title '2D Hilbert'
@hilbert = Hilbert.new
hilbert.create_grammar 5
no_loop
end
def draw
background 0
hilbert.render
end
Turtle = Struct.new(:x, :y, :theta)
class Hilbert
include Processing::Proxy
attr_read... | 748Hilbert curve | 14ruby | 210lw |
func identityMatrix(size: Int) -> [[Int]] {
return (0..<size).map({i in
return (0..<size).map({ $0 == i? 1: 0})
})
}
print(identityMatrix(size: 5)) | 730Identity matrix | 17swift | yhc6e |
import Cocoa
var input = NSFileHandle.fileHandleWithStandardInput()
println("Enter two integers separated by a space: ")
let data = input.availableData
let stringArray = NSString(data: data, encoding: NSUTF8StringEncoding)?.componentsSeparatedByString(" ")
var a:Int!
var b:Int!
if (stringArray?.count == 2) {
a =... | 725Integer comparison | 17swift | 2ajlj |
null | 741HTTP | 11kotlin | j8l7r |
io.stderr:write("Goodbye, World!\n") | 753Hello world/Standard error | 1lua | lpack |
window.onload = function(){
var list = [];
var j = 0;
for(var c = 1; c <= 200; c++)
for(var b = 1; b <= c; b++)
for(var a = 1; a <= b; a++)
if(gcd(gcd(a, b), c) == 1 && isHeron(heronArea(a, b, c)))
list[j++] = new Array(a, b, c, a + b + c, heronArea(a, b, c));
... | 752Heronian triangles | 10javascript | x69w9 |
(defn append-hello [s]
(str "Hello " s))
(defn modify-string [f s]
(f s))
(println (modify-string append-hello "World!")) | 754Higher-order functions | 6clojure | mhkyq |
use 5.10.0;
use strict;
use warnings;
sub horner(\@$){
my ($coef, $x) = @_;
my $result = 0;
$result = $result * $x + $_ for reverse @$coef;
return $result;
}
my @coeff = (-19.0, 7, -4, 6);
my $x = 3;
say horner @coeff, $x; | 740Horner's rule for polynomial evaluation | 2perl | qykx6 |
null | 748Hilbert curve | 15rust | va82t |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.