code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
use strict; use warnings; use feature 'say'; use enum qw(False True); use List::Util <max uniqint product>; use Algorithm::Combinatorics qw(combinations permutations); sub table { my $t = shift() * (my $c = 1 + length max @_); ( sprintf( ('%'.$c.'d')x@_, @_) ) =~ s/.{1,$t}\K/\n/gr } sub is_colorful { my($n) = @_;...
1,025Colorful numbers
2perl
4ht5d
package main import ( "github.com/fogleman/gg" "log" "os/exec" "runtime" ) var palette = [8]string{ "000000",
1,026Colour pinstripe/Printer
0go
rbzgm
from turtle import * from PIL import Image import time import subprocess colors = [, , , , , , , ] screen = getscreen() inch_width = 11.0 inch_height = 8.5 pixels_per_inch = 100 pix_width = int(inch_width*pixels_per_inch) pix_height = int(inch_height*pixels_per_inch) screen.setup (width=pix_width, height=pix...
1,026Colour pinstripe/Printer
3python
3cezc
void get_pixel_color (Display *d, int x, int y, XColor *color) { XImage *image; image = XGetImage (d, RootWindow (d, DefaultScreen (d)), x, y, 1, 1, AllPlanes, XYPixmap); color->pixel = XGetPixel (image, 0, 0); XFree (image); XQueryColor (d, DefaultColormap(d, DefaultScreen (d)), color); } XColor c; get_pix...
1,027Color of a screen pixel
5c
j1370
-- save these lines in a file called -- setupworld.sql -- turn off feedback for cleaner display SET feedback off -- 3 x 3 world -- alive has coordinates of living cells DROP TABLE alive; CREATE TABLE alive (x NUMBER,y NUMBER); -- three alive up the middle -- * -- * -- * INSERT INTO alive VALUES (2,1); INSE...
1,014Conway's Game of Life
19sql
1qbpg
struct Cell: Hashable { var x: Int var y: Int } struct Colony { private var height: Int private var width: Int private var cells: Set<Cell> init(cells: Set<Cell>, height: Int, width: Int) { self.cells = cells self.height = height self.width = width } private func neighborCounts() -> [Cell...
1,014Conway's Game of Life
17swift
gk549
(defn get-color-at [x y] (.getPixelColor (java.awt.Robot.) x y))
1,027Color of a screen pixel
6clojure
1qcpy
package main import ( "github.com/fogleman/gg" "math" ) const tau = 2 * math.Pi func hsb2rgb(hue, sat, bri float64) (r, g, b int) { u := int(bri*255 + 0.5) if sat == 0 { r, g, b = u, u, u } else { h := (hue - math.Floor(hue)) * 6 f := h - math.Floor(h) p := int(bri...
1,028Color wheel
0go
mvwyi
import java.awt.*; import javax.swing.*; public class ColorWheel { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { ColorWheelFrame frame = new ColorWheelFrame(); frame.setVisible(true); } ...
1,028Color wheel
9java
4hn58
null
1,023Conditional structures
1lua
n31i8
int main() { int d=DETECT,m,maxX,maxY,x,y,colour=0,increment=1; initgraph(&d,&m,); maxX = getmaxx(); maxY = getmaxy(); for(y=0;y<maxY;y+=maxY/sections) { for(x=0;x<maxX;x+=increment) { setfillstyle(SOLID_FILL,(colour++)%16); bar(x,y,x+increment,y+maxY/sections); } increment++; colour = 0; } g...
1,029Colour pinstripe/Display
5c
izro2
package main import ( "fmt" "github.com/go-vgo/robotgo" ) func main() {
1,027Color of a screen pixel
0go
fybd0
null
1,028Color wheel
11kotlin
l4scp
typedef struct oct_node_t oct_node_t, *oct_node; struct oct_node_t{ uint64_t r, g, b; int count, heap_idx; oct_node kids[8], parent; unsigned char n_kids, kid_idx, flags, depth; }; inline int cmp_node(oct_node a, oct_node b) { if (a->n_kids < b->n_kids) return -1; if (a->n_kids > b->n_kids) return 1; int ac...
1,030Color quantization
5c
vrs2o
import java.awt.Robot class GetPixelColor { static void main(args) { println getColorAt(args[0] as Integer, args[1] as Integer) } static getColorAt(x, y) { new Robot().getPixelColor(x, y) } }
1,027Color of a screen pixel
7groovy
8fr0b
local function hsv_to_rgb (h, s, v)
1,028Color wheel
1lua
2g0l3
public static Color getColorAt(int x, int y){ return new Robot().getPixelColor(x, y); }
1,027Color of a screen pixel
9java
c5s9h
import java.awt.* fun getMouseColor(): Color { val location = MouseInfo.getPointerInfo().location return getColorAt(location.x, location.y) } fun getColorAt(x: Int, y: Int): Color { return Robot().getPixelColor(x, y) }
1,027Color of a screen pixel
11kotlin
3caz5
use Imager; use Math::Complex qw(cplx i pi); my ($width, $height) = (300, 300); my $center = cplx($width/2, $height/2); my $img = Imager->new(xsize => $width, ysize => $height); foreach my $y (0 .. $height - 1) { foreach my $x (0 .. $width - 1) { my $vec = $center - $x - $y * i; ...
1,028Color wheel
2perl
qiux6
package main import ( "container/heap" "image" "image/color" "image/png" "log" "math" "os" "sort" ) func main() { f, err := os.Open("Quantum_frog.png") if err != nil { log.Fatal(err) } img, err := png.Decode(f) if ec := f.Close(); err != nil { log.Fa...
1,030Color quantization
0go
snvqa
package main import "github.com/fogleman/gg" var palette = [8]string{ "000000",
1,029Colour pinstripe/Display
0go
gkn4n
import qualified Data.ByteString.Lazy as BS import qualified Data.Foldable as Fold import qualified Data.List as List import Data.Ord import qualified Data.Sequence as Seq import Data.Word import System.Environment import Codec.Picture import Codec.Picture.Types type Accessor = PixelRGB8 -> Pixel8 red, blue, green...
1,030Color quantization
8haskell
9uemo
import java.awt.*; import static java.awt.Color.*; import javax.swing.*; public class ColourPinstripeDisplay extends JPanel { final static Color[] palette = {black, red, green, blue, magenta,cyan, yellow, white}; final int bands = 4; public ColourPinstripeDisplay() { setPreferredSize(new ...
1,029Colour pinstripe/Display
9java
1qmp2
use strict; use warnings; use GD; my $file = '/tmp/one-pixel-screen-capture.png'; system "screencapture -R 123,456,1,1 $file"; my $image = GD::Image->newFromPng($file); my $index = $image->getPixel(0,0); my($red,$green,$blue) = $image->rgb($index); print "RGB: $red, $green, $blue\n"; unlink $file;
1,027Color of a screen pixel
2perl
px9b0
from PIL import Image import colorsys import math if __name__ == : im = Image.new(, (300,300)) radius = min(im.size)/2.0 cx, cy = im.size[0]/2, im.size[1]/2 pix = im.load() for x in range(im.width): for y in range(im.height): rx = x - cx ry = y - cy s =...
1,028Color wheel
3python
sn5q9
null
1,029Colour pinstripe/Display
11kotlin
j1t7r
$img = imagegrabscreen(); $color = imagecolorat($im, 10, 50); imagedestroy($im);
1,027Color of a screen pixel
12php
y2w61
null
1,030Color quantization
11kotlin
ot48z
def get_pixel_colour(i_x, i_y): import win32gui i_desktop_window_id = win32gui.GetDesktopWindow() i_desktop_window_dc = win32gui.GetWindowDC(i_desktop_window_id) long_colour = win32gui.GetPixel(i_desktop_window_dc, i_x, i_y) i_colour = int(long_colour) win32gui.ReleaseDC(i_desktop_window_id,i_desktop_window_dc) ...
1,027Color of a screen pixel
3python
1qcpc
def settings size(300, 300) end def setup sketch_title 'Color Wheel' background(0) radius = width / 2.0 center = width / 2 grid(width, height) do |x, y| rx = x - center ry = y - center sat = Math.hypot(rx, ry) / radius if sat <= 1.0 hue = ((Math.atan2(ry, rx) / PI) + 1) / 2.0 co...
1,028Color wheel
14ruby
8fg01
null
1,028Color wheel
15rust
otr83
null
1,024Comments
2perl
ha9jl
use strict ; use GD ; my $image = new GD::Image( 320 , 240 ) ; my %colors = ( "white" => [ 255 , 255 , 255 ] , "red" => [255 , 0 , 0 ] , "green" => [ 0 , 255 , 0 ] , "blue" => [ 0 , 0 , 255 ] , "magenta" => [ 255 , 0 , 255 ] , "yellow" => [ 255 , 255 , 0 ] , "cyan" => [ 0 , 255 , 255 ] , "black" => ...
1,029Colour pinstripe/Display
2perl
tmkfg
module Screen IMPORT_COMMAND = '/usr/bin/import' def self.pixel(x, y) if m = ` m[1..3].map(&:to_i) else false end end end
1,027Color of a screen pixel
14ruby
e02ax
def getColorAt(x: Int, y: Int): Color = new Robot().getPixelColor(x, y)
1,027Color of a screen pixel
16scala
sn4qo
typedef unsigned long marker; marker one = 1; void comb(int pool, int need, marker chosen, int at) { if (pool < need + at) return; if (!need) { for (at = 0; at < pool; at++) if (chosen & (one << at)) printf(, at); printf(); return; } comb(pool, need - 1, chosen | (one << at), at + 1); comb(pool, n...
1,031Combinations
5c
9uam1
null
1,024Comments
12php
z9wt1
use strict; use warnings; use Imager; my $img = Imager->new; $img->read(file => 'frog.png'); my $img16 = $img->to_paletted({ max_colors => 16}); $img16->write(file => "frog-16.png")
1,030Color quantization
2perl
gki4e
from PIL import Image if __name__==: im = Image.open() im2 = im.quantize(16) im2.show()
1,030Color quantization
3python
rbngq
from turtle import * colors = [, , , , , , , ] screen = getscreen() left_edge = -screen.window_width() right_edge = screen.window_width() quarter_height = screen.window_height() half_height = quarter_height * 2 speed() for quarter in range(4): pensize(quarter+1) colornum = 0 min_y = half_height -...
1,029Colour pinstripe/Display
3python
z9btt
(defn combinations "If m=1, generate a nested list of numbers [0,n) If m>1, for each x in [0,n), and for each list in the recursion on [x+1,n), cons the two" [m n] (letfn [(comb-aux [m start] (if (= 1 m) (for [x (range start n)] (list x)) (for [x (range start n) xs (comb-aux (d...
1,031Combinations
6clojure
u7svi
import java.awt.Color._ import java.awt._ import javax.swing._ object ColourPinstripeDisplay extends App { private def palette = Seq(black, red, green, blue, magenta, cyan, yellow, white) SwingUtilities.invokeLater(() => new JFrame("Colour Pinstripe") { class ColourPinstripe_Display extends JPanel { ...
1,029Colour pinstripe/Display
16scala
c5x93
foo = 5
1,024Comments
3python
kechf
int main() { int colour=0,i,j,MAXROW,MAXCOL; struct text_info tInfo; gettextinfo(&tInfo); MAXROW = tInfo.screenheight; MAXCOL = tInfo.screenwidth; textbackground(BLACK); clrscr(); for(colour=0;colour<COLOURS;colour++) { getch(); gotoxy(1+colour*MAXCOL/COLOURS,1); textb...
1,032Colour bars/Display
5c
mvpys
null
1,024Comments
13r
rb6gj
x = =begin hello I a POD documentation comment like Perl =end puts
1,024Comments
14ruby
px2bh
package main import "github.com/fogleman/gg" var colors = [8]string{ "000000",
1,032Colour bars/Display
0go
as61f
#!/usr/bin/env stack import Graphics.Vty colorBars :: Int -> [(Int, Attr)] -> Image colorBars h bars = horizCat $ map colorBar bars where colorBar (w, attr) = charFill attr ' ' w h barWidths :: Int -> Int -> [Int] barWidths nBars totalWidth = map barWidth [0..nBars-1] where fracWidth = fromIntegral totalWidth /...
1,032Colour bars/Display
8haskell
z9jt0
null
1,024Comments
15rust
1qvpu
typedef int (*f_int)(); int _tmpl() { volatile int x = TAG; return x * x; } f_int dupf(int v) { size_t len = (void*)dupf - (void*)_tmpl; f_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0); char *p; if(ret == MAP_FAILED) { perror(); exit(-1); } memcpy(ret, _tmpl, len); for (p = (char*)ret; p < (char*)ret ...
1,033Closures/Value capture
5c
4hs5t
null
1,024Comments
16scala
w84es
import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; public class ColorFrame extends JFrame { public ColorFrame(int width, int height) { this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setSize(width, height); this.setVisible(true); } @Override public void paint(Graphics g) { Col...
1,032Colour bars/Display
9java
otu8d
import java.awt.Color import java.awt.Graphics import javax.swing.JFrame class ColorFrame(width: Int, height: Int): JFrame() { init { defaultCloseOperation = EXIT_ON_CLOSE setSize(width, height) isVisible = true } override fun paint(g: Graphics) { val colors = listOf(Color....
1,032Colour bars/Display
11kotlin
xo9ws
bool is_prime(uint32_t n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (uint32_t p = 3; p * p <= n; p += 2) { if (n % p == 0) return false; } return true; } uint32_t cycle(uint32_t n) { uint32_t m = n, p = 1; while (m >= 10) { ...
1,034Circular primes
5c
5jxuk
(def funcs (map #(fn [] (* % %)) (range 11))) (printf "%d\n%d\n" ((nth funcs 3)) ((nth funcs 4)))
1,033Closures/Value capture
6clojure
hanjr
use strict ; use GD ; my %colors = ( white => [ 255 , 255 , 255 ] , red => [255 , 0 , 0 ] , green => [ 0 , 255 , 0 ] , blue => [ 0 , 0 , 255 ] , magenta => [ 255 , 0 , 255 ] , yellow => [ 255 , 255 , 0 ] , cyan => [ 0 , 255 , 255 ] , black => [ 0 , 0 , 0 ] ) ; my $barwidth = 160 / 8 ; my $image = ne...
1,032Colour bars/Display
2perl
2gwlf
SELECT * FROM mytable -- Selects all columns and rows
1,024Comments
19sql
sn7qp
<?php $colors = array(array( 0, 0, 0), array(255, 0, 0), array( 0, 255, 0), array( 0, 0, 255), array(255, 0, 255), array( 0, 255, 255), array(255, 255, 0), array(255, ...
1,032Colour bars/Display
12php
snlqs
null
1,024Comments
17swift
bwlkd
char canvas[GRID_SIZE][GRID_SIZE]; void initN() { int i, j; for (i = 0; i < GRID_SIZE; i++) { for (j = 0; j < GRID_SIZE; j++) { canvas[i][j] = ' '; } canvas[i][5] = 'x'; } } void horizontal(size_t c1, size_t c2, size_t r) { size_t c; for (c = c1; c <= c2; c++) {...
1,035Cistercian numerals
5c
qiyxc
from livewires import * horiz=640; vert=480 begin_graphics(width=horiz,height=vert,title=,background=Colour.black) NameColors=[,,,,,,,] stepik=horiz/len(NameColors) for index,each in enumerate(NameColors): ExcStrng=+each+ exec ExcStrng box(index*stepik,0,(index+1)*stepik,vert,filled=1) while keys_pressed() != ['x...
1,032Colour bars/Display
3python
vrx29
package main import ( "fmt" big "github.com/ncw/gmp" "strings" )
1,034Circular primes
0go
8fl0g
pal <- c("black", "red", "green", "blue", "magenta", "cyan", "yellow", "white") par(mar = rep(0, 4)) image(matrix(1:8), col = pal, axes = FALSE)
1,032Colour bars/Display
13r
9u1mg
import Math.NumberTheory.Primes (Prime, unPrime, nextPrime) import Math.NumberTheory.Primes.Testing (isPrime, millerRabinV) import Text.Printf (printf) rotated :: [Integer] -> [Integer] rotated xs | any (< head xs) xs = [] | otherwise = map asNum $ take (pred $ length xs) $ rotate xs where rotate [] =...
1,034Circular primes
8haskell
l41ch
class Segment { public Segment(PointF p1, PointF p2) { P1 = p1; P2 = p2; } public readonly PointF P1; public readonly PointF P2; public float Length() { return (float)Math.Sqrt(LengthSquared()); } public float LengthSquared() { return (P1.X - P2...
1,036Closest-pair problem
5c
3cgza
package main import ( "fmt" ) func main() { comb(5, 3, func(c []int) { fmt.Println(c) }) } func comb(n, m int, emit func([]int)) { s := make([]int, m) last := m - 1 var rc func(int, int) rc = func(i, next int) { for j := next; j < n; j++ { s[i] = j ...
1,031Combinations
0go
e0ma6
PALETTE = %w[ def settings full_screen end def setup PALETTE.each_with_index do |col, idx| fill color(col) rect(idx * width / 8, 0, width / 8, height) end end
1,032Colour bars/Display
14ruby
5jsuj
use pixels::{Pixels, SurfaceTexture};
1,032Colour bars/Display
15rust
4h05u
package main import "fmt" func main() { fs := make([]func() int, 10) for i := range fs { i := i fs[i] = func() int { return i * i } } fmt.Println("func #0:", fs[0]()) fmt.Println("func #3:", fs[3]()) }
1,033Closures/Value capture
0go
otv8q
import java.math.BigInteger; import java.util.Arrays; public class CircularPrimes { public static void main(String[] args) { System.out.println("First 19 circular primes:"); int p = 2; for (int count = 0; count < 19; ++p) { if (isCircularPrime(p)) { if (count > 0...
1,034Circular primes
9java
3c7zg
def comb comb = { m, list -> def n = list.size() m == 0 ? [[]]: (0..(n-m)).inject([]) { newlist, k -> def sublist = (k+1 == n) ? []: list[(k+1)..<n] newlist += comb(m-1, sublist).collect { [list[k]] + it } } }
1,031Combinations
7groovy
keth7
if ($expression) { do_something; }
1,023Conditional structures
2perl
rbygd
import java.awt.Color import scala.swing._ class ColorBars extends Component { override def paintComponent(g:Graphics2D)={ val colors=List(Color.BLACK, Color.RED, Color.GREEN, Color.BLUE, Color.MAGENTA, Color.CYAN, Color.YELLOW, Color.WHITE) val colCount=colors.size val deltaX=size.width.toDouble/colCoun...
1,032Colour bars/Display
16scala
7pir9
def closures = (0..9).collect{ i -> { -> i*i } }
1,033Closures/Value capture
7groovy
xomwl
fs = map (\i _ -> i * i) [1 .. 10]
1,033Closures/Value capture
8haskell
2gell
int ar[10]; ar[0] = 1; ar[1] = 2; int* p; for (p=ar; p<(ar+cSize(ar)); p++) { printf(,*p); }
1,037Collections
5c
rbxg7
comb :: Int -> [a] -> [[a]] comb 0 _ = [[]] comb _ [] = [] comb m (x:xs) = map (x:) (comb (m-1) xs) ++ comb m xs
1,031Combinations
8haskell
3ckzj
typedef struct sMyClass { int variable; } *MyClass; MyClass MyClass_new() { MyClass pthis = malloc(sizeof *pthis); pthis->variable = 0; return pthis; } void MyClass_delete(MyClass* pthis) { if (pthis) { free(*pthis); *pthis = NULL; } } void MyClass_someMethod(MyClass pthis) { pthis->variable...
1,038Classes
5c
8fy04
package main import "fmt" var n = make([][]string, 15) func initN() { for i := 0; i < 15; i++ { n[i] = make([]string, 11) for j := 0; j < 11; j++ { n[i][j] = " " } n[i][5] = "x" } } func horiz(c1, c2, r int) { for c := c1; c <= c2; c++ { n[r][c] = "x" ...
1,035Cistercian numerals
0go
2g1l7
(defn distance [[x1 y1] [x2 y2]] (let [dx (- x2 x1), dy (- y2 y1)] (Math/sqrt (+ (* dx dx) (* dy dy))))) (defn brute-force [points] (let [n (count points)] (when (< 1 n) (apply min-key first (for [i (range 0 (dec n)),:let [p1 (nth points i)], j (range (inc i) n),:let [...
1,036Closest-pair problem
6clojure
c5k9b
import java.math.BigInteger val SMALL_PRIMES = listOf( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 2...
1,034Circular primes
11kotlin
n3uij
(defn zero [f] identity) (defn succ [n] (fn [f] (fn [x] (f ((n f) x))))) (defn add [n,m] (fn [f] (fn [x] ((m f)((n f) x))))) (defn mult [n,m] (fn [f] (fn [x] ((m (n f)) x)))) (defn power [b,e] (e b)) (defn to-int [c] ((c inc) 0)) (defn from-int [n] (letfn [(countdown [i] (if (zero? i) zero (succ (countdown (-...
1,039Church numerals
6clojure
n39ik
import java.util.Arrays; import java.util.List; public class Cistercian { private static final int SIZE = 15; private final char[][] canvas = new char[SIZE][SIZE]; public Cistercian(int n) { initN(); draw(n); } public void initN() { for (var row : canvas) { Arr...
1,035Cistercian numerals
9java
j187c
null
1,034Circular primes
1lua
d65nq
<?php $foo = 3; if ($foo == 2) if ($foo == 3) else if ($foo != 0) { } else { } ?>
1,023Conditional structures
12php
d6an8
null
1,035Cistercian numerals
10javascript
1qfp7
import java.util.function.Supplier; import java.util.ArrayList; public class ValueCapture { public static void main(String[] args) { ArrayList<Supplier<Integer>> funcs = new ArrayList<>(); for (int i = 0; i < 10; i++) { int j = i; funcs.add(() -> j * j); } Supplier<Integer> foo = funcs.get(3); Syst...
1,033Closures/Value capture
9java
6lh3z
{1 "a", "Q" 10} (hash-map 1 "a" "Q" 10) (let [my-map {1 "a"}] (assoc my-map "Q" 10))
1,037Collections
6clojure
bwokz
(defprotocol Foo (getFoo [this])) (defrecord Example1 [foo] Foo (getFoo [this] foo)) (-> (Example1. "Hi") .getFoo) "Hi"
1,038Classes
6clojure
fy2dm
import java.io.StringWriter class Cistercian() { constructor(number: Int) : this() { draw(number) } private val size = 15 private var canvas = Array(size) { Array(size) { ' ' } } init { initN() } private fun initN() { for (row in canvas) { row.fill(' '...
1,035Cistercian numerals
11kotlin
5jwua
var funcs = []; for (var i = 0; i < 10; i++) { funcs.push( (function(i) { return function() { return i * i; } })(i) ); } window.alert(funcs[3]());
1,033Closures/Value capture
10javascript
l4acf
import java.util.Collections; import java.util.LinkedList; public class Comb{ public static void main(String[] args){ System.out.println(comb(3,5)); } public static String bitprint(int u){ String s= ""; for(int n= 0;u > 0;++n, u>>= 1) ...
1,031Combinations
9java
iz4os
typedef unsigned long long int u64; int primality_pretest(u64 k) { if (!(k % 3) || !(k % 5) || !(k % 7) || !(k % 11) || !(k % 13) || !(k % 17) || !(k % 19) || !(k % 23)) return (k <= 23); return TRUE; } int probprime(u64 k, mpz_t n) { mpz_set_ui(n, k); return mpz_probab_prime_p(n, 0); } int is_...
1,040Chernick's Carmichael numbers
5c
ot680
function initN() local n = {} for i=1,15 do n[i] = {} for j=1,11 do n[i][j] = " " end n[i][6] = "x" end return n end function horiz(n, c1, c2, r) for c=c1,c2 do n[r+1][c+1] = "x" end end function verti(n, r1, r2, c) for r=r1,r2 do ...
1,035Cistercian numerals
1lua
4hx5c
null
1,033Closures/Value capture
11kotlin
d64nz
use strict; use warnings; use feature 'say'; use List::Util 'min'; use ntheory 'is_prime'; sub rotate { my($i,@a) = @_; join '', @a[$i .. @a-1, 0 .. $i-1] } sub isCircular { my ($n) = @_; return 0 unless is_prime($n); my @circular = split //, $n; return 0 if min(@circular) < $circular[0]; for (1 ....
1,034Circular primes
2perl
7p8rh
function bitprint(u) { var s=""; for (var n=0; u; ++n, u>>=1) if (u&1) s+=n+" "; return s; } function bitcount(u) { for (var n=0; u; ++n, u=u&(u-1)); return n; } function comb(c,n) { var s=[]; for (var u=0; u<1<<n; u++) if (bitcount(u)==c) s.push(bitprint(u)) return s.sort(); } comb(3,5)
1,031Combinations
10javascript
z9ht2
package main import "fmt" type any = interface{} type fn func(any) any type church func(fn) fn func zero(f fn) fn { return func(x any) any { return x } } func (c church) succ() church { return func(f fn) fn { return func(x any) any { return f(c(f)(x)) } } } fun...
1,039Church numerals
0go
vrk2m
unsigned chowla(const unsigned n) { unsigned sum = 0; for (unsigned i = 2, j; i * i <= n; i ++) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j); return sum; } int main(int argc, char const *argv[]) { unsigned a; for (unsigned n = 1; n < 38; n ++) printf(, n, chowla(n)); unsigned n, count = 0, power ...
1,041Chowla numbers
5c
1q0pj
class ChurchNumerals { static void main(args) { def zero = { f -> { a -> a } } def succ = { n -> { f -> { a -> f(n(f)(a)) } } } def add = { n -> { k -> { n(succ)(k) } } } def mult = { f -> { g -> { a -> f(g(a)) } } } def pow = { f -> { g -> g(f) } } def toChurchNum ...
1,039Church numerals
7groovy
mvgy5