code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
io.write("Goodbye, World!") | 761Hello world/Newline omission | 1lua | w3iea |
function(keys,values)
local t = {}
for i=1, #keys do
t[keys[i]] = values[i]
end
end | 759Hash from two arrays | 1lua | 8c60e |
file main.c | 768GUI enabling/disabling of controls | 5c | x6xwu |
func hashJoin<A, B, K: Hashable>(_ first: [(K, A)], _ second: [(K, B)]) -> [(A, K, B)] {
var map = [K: [B]]()
for (key, val) in second {
map[key, default: []].append(val)
}
var res = [(A, K, B)]()
for (key, val) in first {
guard let vals = map[key] else {
continue
}
res += vals.map({... | 757Hash join | 17swift | ol98k |
import java.awt.{Dimension, Insets, Toolkit}
import javax.swing.JFrame
class MaxWindowDims() extends JFrame {
val toolkit: Toolkit = Toolkit.getDefaultToolkit
val (insets0, screenSize) = (toolkit.getScreenInsets(getGraphicsConfiguration), toolkit.getScreenSize)
println("Physical screen size: " + screenSize)
... | 765GUI/Maximum window dimensions | 16scala | yjc63 |
import Foundation
let startTime = NSDate()
var signalReceived: sig_atomic_t = 0
signal(SIGINT) { signal in signalReceived = 1 }
for var i = 0;; {
if signalReceived == 1 { break }
usleep(500_000)
if signalReceived == 1 { break }
print(++i)
}
let endTime = NSDate()
print("Program has run for \(endTime... | 763Handle a signal | 17swift | 1fqpt |
(ns experimentation.core
(:import (javax.swing JOptionPane JFrame JTextArea JButton)
(java.awt FlowLayout)))
(JOptionPane/showMessageDialog nil "Goodbye, World!")
(let [button (JButton. "Goodbye, World!")
window (JFrame. "Goodbye, World!")
text (JTextArea. "Goodbye, World!")]
(doto window
(.se... | 767Hello world/Graphical | 6clojure | 098sj |
package main
import (
"github.com/gotk3/gotk3/gtk"
"log"
"math/rand"
"strconv"
"time"
)
func validateInput(window *gtk.Window, str string) (int64, bool) {
i, err := strconv.ParseInt(str, 10, 64)
if err != nil {
dialog := gtk.MessageDialogNew(
window,
gtk.DIA... | 768GUI enabling/disabling of controls | 0go | lplcw |
package main
import "fmt"
type is func() int
func newSum() is {
var ms is
ms = func() int {
ms = newSum()
return ms()
}
var msd, d int
return func() int {
if d < 9 {
d++
} else {
d = 0
msd = ms()
}
return msd + d
... | 762Harshad or Niven series | 0go | x6iwf |
class HarshadNiven{ public static boolean find(int x)
{
int sum = 0,temp,var;
var = x;
while(x>0)
{
temp = x%10;
sum = sum + temp;
x = x/10;
}
if(var%sum==0) temp = 1;
else temp = 0;
return temp;
}
public static void main(String[] args)
{
... | 762Harshad or Niven series | 7groovy | pdqbo |
import 'package:flutter/material.dart';
main() => runApp( MaterialApp( home: Text( "Goodbye, World!" ) ) ); | 767Hello world/Graphical | 18dart | hokjb |
print "Goodbye, World!"; | 761Hello world/Newline omission | 2perl | cbg9a |
my @keys = qw(a b c);
my @vals = (1, 2, 3);
my %hash;
@hash{@keys} = @vals; | 759Hash from two arrays | 2perl | 5wpu2 |
import Data.Char (digitToInt)
harshads :: [Int]
harshads =
let digsum = sum . map digitToInt . show
in filter ((0 ==) . (mod <*> digsum)) [1 ..]
main :: IO ()
main = mapM_ print [take 20 harshads, [(head . filter (> 1000)) harshads]] | 762Harshad or Niven series | 8haskell | yjv66 |
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
pu... | 768GUI enabling/disabling of controls | 9java | 707rj |
int main(){
int bounds[ 2 ] = {1, 100};
char input[ 2 ] = ;
int choice = (bounds[ 0 ] + bounds[ 1 ]) / 2;
printf( , bounds[ 0 ], bounds[ 1 ] );
do{
switch( input[ 0 ] ){
case 'H':
bounds[ 1 ] = choice;
break;
case 'L':
bounds[ 0 ] = choice;
break;
... | 769Guess the number/With feedback (player) | 5c | y736f |
echo ; | 761Hello world/Newline omission | 12php | x6nw5 |
$keys = array('a', 'b', 'c');
$values = array(1, 2, 3);
$hash = array_combine($keys, $values); | 759Hash from two arrays | 12php | oly85 |
null | 768GUI enabling/disabling of controls | 11kotlin | ueuvc |
file main.c | 770GUI component interaction | 5c | v1c2o |
(require '[clojure.string:as str])
(defn guess-game [low high]
(printf "Think of a number between%s and%s.\n (use (h)igh (l)ow (c)orrect)\n" low high)
(loop [guess (/ (inc (- high low)) 2)
[step & more] (next (iterate #(/ % 2) guess))]
(printf "I guess%s\n=> " (Math/round (float guess)))
(flush)
... | 769Guess the number/With feedback (player) | 6clojure | 2pcl1 |
import sys
sys.stdout.write() | 761Hello world/Newline omission | 3python | lprcv |
cat("Goodbye, world!") | 761Hello world/Newline omission | 13r | yju6h |
public class Harshad{
private static long sumDigits(long n){
long sum = 0;
for(char digit:Long.toString(n).toCharArray()){
sum += Character.digit(digit, 10);
}
return sum;
}
public static void main(String[] args){
for(int count = 0, i = 1; count < 20;i++){... | 762Harshad or Niven series | 9java | duyn9 |
function isHarshad(n) {
var s = 0;
var n_str = new String(n);
for (var i = 0; i < n_str.length; ++i) {
s += parseInt(n_str.charAt(i));
}
return n % s === 0;
}
var count = 0;
var harshads = [];
for (var n = 1; count < 20; ++n) {
if (isHarshad(n)) {
count++;
harshads.push... | 762Harshad or Niven series | 10javascript | 67238 |
keys = ['a', 'b', 'c']
values = [1, 2, 3]
hash = {key: value for key, value in zip(keys, values)} | 759Hash from two arrays | 3python | 4x15k |
package main
import (
"fmt"
"math"
)
func haversine( float64) float64 {
return .5 * (1 - math.Cos())
}
type pos struct {
float64 | 766Haversine formula | 0go | 70hr2 |
print | 761Hello world/Newline omission | 14ruby | vaj2n |
fn main () {
print!("Goodbye, World!");
} | 761Hello world/Newline omission | 15rust | uehvj |
keys <- c("John Smith", "Lisa Smith", "Sam Doe", "Sandra Dee", "Ted Baker")
values <- c(152, 1, 254, 152, 153)
names(values) <- keys
values["Sam Doe"]
names(values)[values==152] | 759Hash from two arrays | 13r | 21hlg |
use strict;
use warnings;
use Tk;
use Tk::Dialog;
use Tk::LabFrame;
my $value = 0;
my $mw = MainWindow->new;
$mw->title( 'GUI component enable/disable' );
my $lf = $mw->LabFrame( -label => 'Value' )->pack(-fill => 'x',-expand => 1);
my $entry = $lf->Entry( -width => 10, -textvariable => \$value,
-validate => 'key',... | 768GUI enabling/disabling of controls | 2perl | 8c80w |
enum { h_unknown = 0, h_yes, h_no };
unsigned char buf[CACHE] = {0, h_yes, 0};
int happy(int n)
{
int sum = 0, x, nn;
if (n < CACHE) {
if (buf[n]) return 2 - buf[n];
buf[n] = h_no;
}
for (nn = n; nn; nn /= 10) x = nn % 10, sum += x * x;
x = happy(sum);
if (n < CACHE) buf[n] = 2 - x;
return x;
}
int main(... | 771Happy numbers | 5c | uacv4 |
def haversine(lat1, lon1, lat2, lon2) {
def R = 6372.8 | 766Haversine formula | 7groovy | ue4v9 |
print("Goodbye, World!") | 761Hello world/Newline omission | 16scala | gqp4i |
void gsplot (cairo_t *cr,int x,int y,double s) {
cairo_set_source_rgb (cr,s,s,s);
cairo_move_to (cr,x+0.5,y);
cairo_rel_line_to (cr,0,1);
cairo_stroke (cr);
}
gboolean expose_event (GtkWidget *widget,GdkEventExpose *event,gpointer data) {
int r,c,x=0;
cairo_t *cr;
cr = gdk_cairo_create (wid... | 772Greyscale bars/Display | 5c | gx245 |
import Control.Monad (join)
import Data.Bifunctor (bimap)
import Text.Printf (printf)
haversine :: Float -> Float
haversine = (^ 2) . sin . (/ 2)
greatCircleDistance ::
(Float, Float) ->
(Float, Float) ->
Float
greatCircleDistance = distDeg 6371
where
distDeg radius p1 p2 =
distRad
rad... | 766Haversine formula | 8haskell | 8ci0z |
null | 762Harshad or Niven series | 11kotlin | 09fsf |
print("Goodbye, World!", terminator: "") | 761Hello world/Newline omission | 17swift | 217lj |
keys = ['hal',666,[1,2,3]]
vals = ['ibm','devil',123]
hash = Hash[keys.zip(vals)]
p hash
puts hash[ [1,2,3] ] | 759Hash from two arrays | 14ruby | rsegs |
use std::collections::HashMap;
fn main() {
let keys = ["a", "b", "c"];
let values = [1, 2, 3];
let hash = keys.iter().zip(values.iter()).collect::<HashMap<_, _>>();
println!("{:?}", hash);
} | 759Hash from two arrays | 15rust | 70wrc |
package main
import (
"github.com/gotk3/gotk3/gtk"
"log"
"math/rand"
"strconv"
"time"
)
func validateInput(window *gtk.Window, str string) (int64, bool) {
i, err := strconv.ParseInt(str, 10, 64)
if err != nil {
dialog := gtk.MessageDialogNew(
window,
gtk.DIA... | 770GUI component interaction | 0go | sywqa |
(defn happy? [n]
(loop [n n, seen #{}]
(cond
(= n 1) true
(seen n) false
:else
(recur (->> (str n)
(map #(Character/digit % 10))
(map #(* % %))
(reduce +))
(conj seen n)))))
(def happy-numbers (filter happy? (it... | 771Happy numbers | 6clojure | 7s5r0 |
val keys = List(1, 2, 3)
val values = Array("A", "B", "C") | 759Hash from two arrays | 16scala | kishk |
function isHarshad(n)
local s=0
local n_str=tostring(n)
for i=1,#n_str do
s=s+tonumber(n_str:sub(i,i))
end
return n%s==0
end
local count=0
local harshads={}
local n=1
while count<20 do
if isHarshad(n) then
count=count+1
table.insert(harshads, n)
end
n=n+1
end
p... | 762Harshad or Niven series | 1lua | 8ct0e |
import Graphics.UI.WX
import System.Random
main :: IO ()
main = start $ do
frm <- frame [text:= "Interact"]
fld <- textEntry frm [text:= "0", on keyboard:= checkKeys]
inc <- button frm [text:= "increment", on command:= increment fld]
ran <- button frm [text:= "random", on command:= (randReplace... | 770GUI component interaction | 8haskell | 9h6mo |
import tkinter as tk
class MyForm(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.pack(expand=True, fill=, padx=10, pady=10)
self.master.title()
self.setupUI()
def setupUI(self):
self.value_entry = tk.Entry(self, justify=tk.CENTER)
... | 768GUI enabling/disabling of controls | 3python | olo81 |
package main
import (
"fmt"
"sort"
)
func main() {
lower, upper := 0, 100
fmt.Printf(`Instructions:
Think of integer number from%d (inclusive) to%d (exclusive) and
I will guess it. After each guess, I will ask you if it is less than
or equal to some number, and you will respond with "yes" or "no".
`, ... | 769Guess the number/With feedback (player) | 0go | 1dbp5 |
public class Haversine {
public static final double R = 6372.8; | 766Haversine formula | 9java | ezxa5 |
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
publi... | 770GUI component interaction | 9java | t5nf9 |
library(gWidgets)
options(guiToolkit="RGtk2")
w <- gwindow("Disable components")
g <- ggroup(cont=w, horizontal=FALSE)
e <- gedit("0", cont=g, coerce.with=as.numeric)
bg <- ggroup(cont=g)
down_btn <- gbutton("-", cont=bg)
up_btn <- gbutton("+", cont=bg)
update_ctrls <- function(h,...) {
val <- svalue(e)
enable... | 768GUI enabling/disabling of controls | 13r | qyqxs |
package main
import (
"github.com/fogleman/gg"
"math"
)
func greyBars(dc *gg.Context) {
run := 0
colorComp := 0.0 | 772Greyscale bars/Display | 0go | ilqog |
import Graphics.UI.Gtk
import Graphics.UI.Gtk.Gdk.GC
import Control.Monad.Trans (liftIO)
main = do
initGUI
window <- windowNew
buf <- pixbufNewFromXPMData bars
widgetAddEvents window [ButtonPressMask]
on window objectDestroy mainQuit
on window exposeEvent (paint buf)
on window buttonPr... | 772Greyscale bars/Display | 8haskell | v1m2k |
main :: IO ()
main = do
putStrLn "Please enter the range:"
putStr "From: "
from <- getLine
putStr "To: "
to <- getLine
case (from, to) of
(_) | [(from', "")] <- reads from
, [(to' , "")] <- reads to
, from' < to' -> loop from' to'
(_) ... | 769Guess the number/With feedback (player) | 8haskell | t5df7 |
function haversine() {
var radians = Array.prototype.map.call(arguments, function(deg) { return deg/180.0 * Math.PI; });
var lat1 = radians[0], lon1 = radians[1], lat2 = radians[2], lon2 = radians[3];
var R = 6372.8; | 766Haversine formula | 10javascript | 09osz |
package main
import "github.com/mattn/go-gtk/gtk"
func main() {
gtk.Init(nil)
win := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
win.SetTitle("Goodbye, World!")
win.SetSizeRequest(300, 200)
win.Connect("destroy", gtk.MainQuit)
button := gtk.NewButtonWithLabel("Goodbye, World!")
win.Add(button)
button.C... | 767Hello world/Graphical | 0go | 9kcmt |
import java.awt.GridLayout
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import java.awt.event.KeyEvent
import java.awt.event.KeyListener
import javax.swing.*
class Interact : JFrame() {
val numberField = JTextField()
val incButton = JButton("Increment")
val randButton = JButton("R... | 770GUI component interaction | 11kotlin | ocs8z |
import groovy.swing.SwingBuilder
import javax.swing.JFrame
new SwingBuilder().edt {
optionPane().showMessageDialog(null, "Goodbye, World!")
frame(title:'Goodbye, World!', defaultCloseOperation:JFrame.EXIT_ON_CLOSE, pack:true, show: true) {
flowLayout()
button(text:'Goodbye, World!')
textArea(text:'Good... | 767Hello world/Graphical | 7groovy | zg3t5 |
import javax.swing.* ;
import java.awt.* ;
public class Greybars extends JFrame {
private int width ;
private int height ;
public Greybars( ) {
super( "grey bars example!" ) ;
width = 640 ;
height = 320 ;
setSize( width , height ) ;
setDefaultCloseOperation( JFrame.EXIT_ON_CLOS... | 772Greyscale bars/Display | 9java | y7f6g |
import java.lang.Math.*
const val R = 6372.8 | 766Haversine formula | 11kotlin | kiph3 |
let keys = ["a","b","c"]
let vals = [1,2,3]
var hash = [String: Int]()
for (key, val) in zip(keys, vals) {
hash[key] = val
} | 759Hash from two arrays | 17swift | gqa49 |
int main(void)
{
int n;
int g;
char c;
srand(time(NULL));
n = 1 + (rand() % 10);
puts();
puts();
while (1) {
if (scanf(, &g) != 1) {
scanf(, &c);
continue;
}
if (g == n) {
puts();
return 0;
}
puts();
}
} | 773Guess the number | 5c | 2p6lo |
typedef struct Range {
int start, end, sum;
} Range;
Range maxSubseq(const int sequence[], const int len) {
int maxSum = 0, thisSum = 0, i = 0;
int start = 0, end = -1, j;
for (j = 0; j < len; j++) {
thisSum += sequence[j];
if (thisSum < 0) {
i = j + 1;
thisSum ... | 774Greatest subsequential sum | 5c | n2xi6 |
<html><body>
<script type="text/javascript">
var width = 640; var height = 400;
var c = document.createElement("canvas");
c.setAttribute('id', 'myCanvas');
c.setAttribute('style', 'border:1px solid black;');
c.setAttribute('width', width);
c.setAttribute('height', height);
document.body.appendChild(c);
var ctx =... | 772Greyscale bars/Display | 10javascript | 2pylr |
import java.util.AbstractList;
import java.util.Collections;
import java.util.Scanner;
public class GuessNumber {
public static final int LOWER = 0, UPPER = 100;
public static void main(String[] args) {
System.out.printf("Instructions:\n" +
"Think of integer number from%d (inclusive) to%d (exclusive) and... | 769Guess the number/With feedback (player) | 9java | 89s06 |
import Graphics.UI.Gtk
import Control.Monad
messDialog = do
initGUI
dialog <- messageDialogNew Nothing [] MessageInfo ButtonsOk "Goodbye, World!"
rs <- dialogRun dialog
when (rs == ResponseOk || rs == ResponseDeleteEvent) $ widgetDestroy dialog
dialog `onDestroy` mainQuit
mainGUI | 767Hello world/Graphical | 8haskell | bnpk2 |
typedef unsigned char luminance;
typedef luminance pixel1[1];
typedef struct {
unsigned int width;
unsigned int height;
luminance *buf;
} grayimage_t;
typedef grayimage_t *grayimage;
grayimage alloc_grayimg(unsigned int, unsigned int);
grayimage tograyscale(image);
image tocolor(grayimage); | 775Grayscale image | 5c | j0270 |
Shoes.app do
@number = edit_line
@number.change {update_controls}
@incr = button('Increment') {update_controls(@number.text.to_i + 1)}
@decr = button('Decrement') {update_controls(@number.text.to_i - 1)}
def update_controls(value = @number.text.to_i)
@number.text = value
@incr.state = value.to_i >= ... | 768GUI enabling/disabling of controls | 14ruby | nvnit |
int main(){
int number, guess;
srand( time( 0 ) );
number = lower_limit + rand() % (upper_limit - lower_limit + 1);
printf( , lower_limit, upper_limit );
while( scanf( , &guess ) == 1 ){
if( number == guess ){
printf( );
break;
}
printf( , number < guess ? : );
}
return 0;
} | 776Guess the number/With feedback | 5c | afg11 |
null | 772Greyscale bars/Display | 11kotlin | fu8do |
#!/usr/bin/env js
var DONE = RIGHT = 0, HIGH = 1, LOW = -1;
function main() {
showInstructions();
while (guess(1, 100) !== DONE);
}
function guess(low, high) {
if (low > high) {
print("I can't guess it. Perhaps you changed your number.");
return DONE;
}
var g = Math.floor((low + ... | 769Guess the number/With feedback (player) | 10javascript | fundg |
main() {
HashMap<int,bool> happy=new HashMap<int,bool>();
happy[1]=true;
int count=0;
int i=0;
while(count<8) {
if(happy[i]==null) {
int j=i;
Set<int> sequence=new Set<int>();
while(happy[j]==null &&!sequence.contains(j)) {
sequence.add(j);
int sum=0;
int val=j;... | 771Happy numbers | 18dart | mjzyb |
local function haversine(x1, y1, x2, y2)
r=0.017453292519943295769236907684886127;
x1= x1*r; x2= x2*r; y1= y1*r; y2= y2*r; dy = y2-y1; dx = x2-x1;
a = math.pow(math.sin(dx/2),2) + math.cos(x1) * math.cos(x2) * math.pow(math.sin(dy/2),2); c = 2 * math.asin(math.sqrt(a)); d = 6372.8 * c;
return d;
end | 766Haversine formula | 1lua | bn1ka |
package main
import (
"fmt"
"sort"
)
type graph struct {
nn int | 777Graph colouring | 0go | gxy4n |
(import '[java.io File]
'[javax.imageio ImageIO]
'[java.awt Color]
'[java.awt.image BufferedImage]))
(defn rgb-to-gray [color-image]
(let [width (.getWidth color-image)]
(partition width
(for [x (range width)
y (range (.getHeight color-image))]
... | 775Grayscale image | 6clojure | 1dgpy |
' Go Fish ~ Pesca!
Const cartas =
Declare Sub Reparto_Cartas
Declare Sub Pescar_Carta_Jug
Declare Sub Pescar_Carta_CPU
Declare Sub Comprobar_Libro_Jug
Declare Sub Comprobar_Libro_CPU
Declare Sub Comprobar_Fin_Partida
Declare Sub Intro
Dim Shared As Integer play(13), compu(13), deck(13), guess(13), poss(13), asked(1... | 778Go Fish | 5c | v1f2o |
(def target (inc (rand-int 10))
(loop [n 0]
(println "Guess a number between 1 and 10 until you get it right:")
(let [guess (read)]
(if (= guess target)
(printf "Correct on the%d guess.\n" n)
(do
(println "Try again")
(recur (inc n)))))) | 773Guess the number | 6clojure | gxl4f |
import swing.{ BoxPanel, Button, GridPanel, Orientation, Swing, TextField }
import swing.event.{ ButtonClicked, Key, KeyPressed, KeyTyped }
object Enabling extends swing.SimpleSwingApplication {
def top = new swing.MainFrame {
title = "Rosetta Code >>> Task: GUI enabling/disabling of controls | Language: Scala"
... | 768GUI enabling/disabling of controls | 16scala | zgztr |
null | 769Guess the number/With feedback (player) | 11kotlin | wzaek |
use strict;
use warnings;
use Tk;
use Tk::Dialog;
use Tk::LabFrame;
my $value = 0;
my $mw = MainWindow->new;
$mw->title( 'GUI component interaction' );
my $lf = $mw->LabFrame( -label => 'Value' )->pack(-fill => 'x',-expand => 1);
$lf->Entry( -width => 10, -textvariable => \$value,
-validate => 'key', -validatecomma... | 770GUI component interaction | 2perl | gxu4e |
import Data.Maybe
import Data.List
import Control.Monad.State
import qualified Data.Map as M
import Text.Printf
type Node = Int
type Color = Int
type Graph = M.Map Node [Node]
nodes :: Graph -> [Node]
nodes = M.keys
adjacentNodes :: Graph -> Node -> [Node]
adjacentNodes g n = fromMaybe [] $ M.lookup n g
degree ... | 777Graph colouring | 8haskell | syhqk |
(defn max-subseq-sum [coll]
(->> (take-while seq (iterate rest coll))
(mapcat #(reductions conj [] %))
(apply max-key #(reduce + %)))) | 774Greatest subsequential sum | 6clojure | 3gozr |
function T(t) return setmetatable(t, {__index=table}) end
table.range = function(t,n) local s=T{} for i=1,n do s[i]=i end return s end
table.map = function(t,f) local s=T{} for i=1,#t do s[i]=f(t[i]) end return s end
table.batch = function(t,n,f) for i=1,#t,n do local s=T{} for j=1,n do s[j]=t[i+j-1] end f(s) end retur... | 779Goldbach's comet | 1lua | sy7q8 |
typedef unsigned long long ham;
size_t alloc = 0, n = 1;
ham *q = 0;
void qpush(ham h)
{
int i, j;
if (alloc <= n) {
alloc = alloc ? alloc * 2 : 16;
q = realloc(q, sizeof(ham) * alloc);
}
for (i = n++; (j = i/2) && q[j] > h; q[i] = q[j], i = j);
q[i] = h;
}
ham qpop()
{
int i, j;
ham r, t;
for (r = q[... | 780Hamming numbers | 5c | mjsys |
function wait(waittime) | 769Guess the number/With feedback (player) | 1lua | x3ewz |
use strict;
use warnings;
no warnings 'uninitialized';
use feature 'say';
use constant True => 1;
use List::Util qw(head uniq);
sub GraphNodeColor {
my(%OneMany, %NodeColor, %NodePool, @ColorPool);
my(@data) = @_;
for (@data) {
my($a,$b) = @$_;
push @{$OneMany{$a}}, $b;
push @{$One... | 777Graph colouring | 2perl | t5xfg |
use strict;
use warnings;
use feature 'say';
use List::Util 'max';
use GD::Graph::bars;
use ntheory 'is_prime';
sub table { my $t = shift() * (my $c = 1 + max map {length} @_); ( sprintf( ('%'.$c.'s')x@_, @_) ) =~ s/.{1,$t}\K/\n/gr }
sub G {
my($n) = @_;
scalar grep { is_prime($_) and is_prime($n - $_) } 2 .... | 779Goldbach's comet | 2perl | v1d20 |
import 'dart:math';
import 'dart:io';
main() {
final n = (1 + new Random().nextInt(10)).toString();
print("Guess which number I've chosen in the range 1 to 10");
do { stdout.write(" Your guess: "); } while (n!= stdin.readLineSync());
print("\nWell guessed!");
} | 773Guess the number | 18dart | 6rn34 |
sub partition {
my($all, $div) = @_;
my @marks = 0;
push @marks, $_/$div * $all for 1..$div;
my @copy = @marks;
$marks[$_] -= $copy[$_-1] for 1..$
@marks[1..$
}
sub bars {
my($h,$w,$p,$rev) = @_;
my (@nums,@vals,$line,$d);
$d = 2**$p;
push @nums, int $_/($d-1) * (2**16-1) for ... | 772Greyscale bars/Display | 2perl | h84jl |
(defn guess-run []
(let [start 1
end 100
target (+ start (rand-int (inc (- end start))))]
(printf "Guess a number between%d and%d" start end)
(loop [i 1]
(printf "Your guess%d:\n" i)
(let [ans (read)]
(if (cond
(not (number? ans)) (println "Invalid format")
(or (< ans start) (> ans ... | 776Guess the number/With feedback | 6clojure | sykqr |
import javax.swing.*;
import java.awt.*;
public class OutputSwing {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
JOptionPane.showMessageDialog (null, "Goodbye, World!"); | 767Hello world/Graphical | 9java | gqr4m |
import re
from collections import defaultdict
from itertools import count
connection_re = r
class Graph:
def __init__(self, name, connections):
self.name = name
self.connections = connections
g = self.graph = defaultdict(list)
matches = re.finditer(connection_re, connections,
... | 777Graph colouring | 3python | z4qtt |
from matplotlib.pyplot import scatter, show
from sympy import isprime
def g(n):
assert n > 2 and n% 2 == 0, 'n in goldbach function g(n) must be even'
count = 0
for i in range(1, n
if isprime(i) and isprime(n - i):
count += 1
return count
print('The first 100 G numbers ar... | 779Goldbach's comet | 3python | uafvd |
#!/usr/bin/perl
use strict; # https: | 778Go Fish | 0go | syjqa |
alert("Goodbye, World!"); | 767Hello world/Graphical | 10javascript | kibhq |
import random, tkMessageBox
from Tkinter import *
window = Tk()
window.geometry()
options = { :5, :5}
s=StringVar()
s.set(1)
def increase():
s.set(int(s.get())+1)
def rand():
if tkMessageBox.askyesno(, ):
s.set(random.randrange(0,5000))
def update(e):
if not e.char.isdigit():
tkMessageBox.sh... | 770GUI component interaction | 3python | rq5gq |
#!/usr/bin/perl
use strict; # https://rosettacode.org/wiki/Go_Fish
use warnings;
use List::Util qw( first shuffle );
my $pat = qr/[atjqk2-9]/; # ranks
my $deck = join '', shuffle map { my $rank = $_; map "$rank$_", qw( S H C D ) }
qw( a t j q k ), 2 .. 9;
my $mebooks = my $youbooks = 0;
my $me = substr $deck, 0, ... | 778Go Fish | 8haskell | 9homo |
(defn smerge [xs ys]
(lazy-seq
(let [x (first xs),
y (first ys),
[z xs* ys*]
(cond
(< x y) [x (rest xs) ys]
(> x y) [y xs (rest ys)]
:else [x (rest xs) (rest ys)])]
(cons z (smerge xs* ys*)))))
(def hamming
(lazy-seq
(->> (map #(*' 5 ... | 780Hamming numbers | 6clojure | v1n2f |
from livewires import *
horiz=640; vert=480; pruh=vert/4; dpp=255.0
begin_graphics(width=horiz,height=vert,title=,background=Colour.black)
def ty_pruhy(each):
hiy=each[0]*pruh; loy=hiy-pruh
krok=horiz/each[1]; piecol=255.0/(each[1]-1)
for x in xrange(0,each[1]):
barva=Colour(piecol*x/dpp,piecol*x/dpp,piecol*x/dp... | 772Greyscale bars/Display | 3python | koghf |
mat <- matrix(c(rep(1:8, each = 8) / 8,
rep(16:1, each = 4) / 16,
rep(1:32, each = 2) / 32,
rep(64:1, each = 1) / 64),
nrow = 4, byrow = TRUE)
par(mar = rep(0, 4))
image(t(mat[4:1, ]), col = gray(1:64/64), axes = FALSE) | 772Greyscale bars/Display | 13r | rqvgj |
use strict ;
use warnings ;
use List::Util qw ( sum ) ;
sub createHarshads {
my @harshads ;
my $number = 1 ;
do {
if ( $number % sum ( split ( // , $number ) ) == 0 ) {
push @harshads , $number ;
}
$number++ ;
} until ( $harshads[ -1 ] > 1000 ) ;
return @harshads ;
}
my @harshadnumb... | 762Harshad or Niven series | 2perl | 5whu2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.