code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
package main import ( "log" gc "code.google.com/p/goncurses" ) func main() { _, err := gc.Init() if err != nil { log.Fatal("init:", err) } defer gc.End() gc.FlushInput() }
681Keyboard input/Flush the keyboard buffer
0go
ykp64
package main import "fmt" type Item struct { name string weight, value, qty int } var items = []Item{ {"map", 9, 150, 1}, {"compass", 13, 35, 1}, {"water", 153, 200, 2}, {"sandwich", 50, 60, 2}, {"glucose", 15, 60, 2}, {"tin", 68, 45, 3}, {"banana", 27, 60, 3}, {"apple", 39, 40, 3},...
678Knapsack problem/Bounded
0go
5qiul
import Control.Concurrent (threadDelay) import Control.Monad (when) import System.IO (hFlush, stdout) import System.Posix termFlush :: Fd -> IO () termFlush fd = do isTerm <- queryTerminal fd when isTerm $ discardData fd InputQueue main :: IO () main = do putStrLn "Type some stuff...\n" threadDelay $ 3 * 10...
681Keyboard input/Flush the keyboard buffer
8haskell
hnfju
package main import ( "log" gc "code.google.com/p/goncurses" ) func main() { s, err := gc.Init() if err != nil { log.Fatal("init:", err) } defer gc.End() var k gc.Key for { gc.FlushInput() s.MovePrint(20, 0, "Press y/n ") s.Refresh() switch k = ...
676Keyboard input/Obtain a Y or N response
0go
bf9kh
def totalWeight = { list -> list.collect{ it.item.weight * it.count }.sum() } def totalValue = { list -> list.collect{ it.item.value * it.count }.sum() } def knapsackBounded = { possibleItems -> def n = possibleItems.size() def m = (0..n).collect{ i -> (0..400).collect{ w -> []} } (1..400).each { w -> ...
678Knapsack problem/Bounded
7groovy
c1q9i
null
681Keyboard input/Flush the keyboard buffer
11kotlin
c1e98
inv = [("map",9,150,1), ("compass",13,35,1), ("water",153,200,2), ("sandwich",50,60,2), ("glucose",15,60,2), ("tin",68,45,3), ("banana",27,60,3), ("apple",39,40,3), ("cheese",23,30,1), ("beer",52,10,3), ("cream",11,70,1), ("camera",32,30,1), ("tshirt",24,15,2), ("trousers",48,10,2), ("umbrella",73,40,1), ("wtrous...
678Knapsack problem/Bounded
8haskell
xmvw4
package main import ( "log" "time" gc "code.google.com/p/goncurses" ) func main() { s, err := gc.Init() if err != nil { log.Fatal("init:", err) } defer gc.End() gc.Cursor(0) s.Move(20, 0) s.Print("Key check in ") for i := 3; i >= 1; i-- { s.MovePrint(20, 13...
680Keyboard input/Keypress check
0go
4so52
import System.IO hFlushInput :: Handle -> IO () hFlushInput hdl = do r <- hReady hdl if r then do c <- hGetChar hdl hFlushInput hdl else return () yorn :: IO Char yorn = do c <- getChar if c == 'Y' || c == 'N' then return c else if c == 'y' then return 'Y' else if c == 'n' then return 'N' ...
676Keyboard input/Obtain a Y or N response
8haskell
d4bn4
Shoes.app do @info = para keypress do |k| @info.replace end end
675Keyboard macros
14ruby
d4pns
import Control.Concurrent import Control.Monad import Data.Maybe import System.IO main = do c <- newEmptyMVar hSetBuffering stdin NoBuffering forkIO $ do a <- getChar putMVar c a putStrLn $ "\nChar '" ++ [a] ++ "' read and stored in MVar" wait c where wait c = do ...
680Keyboard input/Keypress check
8haskell
q92x9
use Term::ReadKey; ReadMode 'restore'; use Term::ReadKey; ReadMode 'cbreak'; while (defined ReadKey -1) { } ReadMode 'restore';
681Keyboard input/Flush the keyboard buffer
2perl
xmcw8
import java.awt.event.{KeyAdapter, KeyEvent} import javax.swing.{JFrame, JLabel, WindowConstants} object KeyboardMacroDemo extends App { val directions = "<html><b>Ctrl-S</b> to show frame title<br>" + "<b>Ctrl-H</b> to hide it</html>" new JFrame { add(new JLabel(directions)) addKeyListener(new KeyAdap...
675Keyboard macros
16scala
3jwzy
package hu.pj.alg.test; import hu.pj.alg.BoundedKnapsack; import hu.pj.obj.Item; import java.util.*; import java.text.*; public class BoundedKnapsackForTourists { public BoundedKnapsackForTourists() { BoundedKnapsack bok = new BoundedKnapsack(400);
678Knapsack problem/Bounded
9java
bfyk3
import java.awt.event.*; import javax.swing.*; public class Test extends JFrame { Test() { addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); System.out.println(keyCode); } ...
680Keyboard input/Keypress check
9java
pt6b3
let thePressedKey; function handleKey(evt) { thePressedKey = evt; console.log(thePressedKey); } document.addEventListener('keydown', handleKey);
680Keyboard input/Keypress check
10javascript
xmlw9
def flush_input(): try: import msvcrt while msvcrt.kbhit(): msvcrt.getch() except ImportError: import sys, termios termios.tcflush(sys.stdin, termios.TCIOFLUSH)
681Keyboard input/Flush the keyboard buffer
3python
q9lxi
const readline = require('readline'); readline.emitKeypressEvents(process.stdin); process.stdin.setRawMode(true); var wait_key = async function() { return await new Promise(function(resolve,reject) { var key_listen = function(str,key) { process.stdin.removeListener('keypress', key_listen); resolve(st...
676Keyboard input/Obtain a Y or N response
10javascript
n5kiy
<html><head><title></title></head><body></body></html> <script type="text/javascript"> var data= [ {name: 'map', weight: 9, value:150, pieces:1}, {name: 'compass', weight: 13, value: 35, pieces:1}, {name: 'water', weight:153, value:200, pieces:2}, {name: 'san...
678Knapsack problem/Bounded
10javascript
wy2e2
null
680Keyboard input/Keypress check
11kotlin
7odr4
package main import ( "fmt" "sort" ) type item struct { item string weight float64 price float64 } type items []item var all = items{ {"beef", 3.8, 36}, {"pork", 5.4, 43}, {"ham", 3.6, 90}, {"greaves", 2.4, 45}, {"flitch", 4.0, 30}, {"brawn", 2.5, 56}, {"welt", 3.7...
677Knapsack problem/Continuous
0go
n5hi1
null
676Keyboard input/Obtain a Y or N response
11kotlin
a3213
import static java.math.RoundingMode.* def knapsackCont = { list, maxWeight = 15.0 -> list.sort{ it.weight / it.value } def remainder = maxWeight List sack = [] for (item in list) { if (item.weight < remainder) { sack << [name: item.name, weight: item.weight, ...
677Knapsack problem/Continuous
7groovy
sc4q1
require 'io/console' $stdin.iflush
681Keyboard input/Flush the keyboard buffer
14ruby
0lvsu
def flush() { out.flush() }
681Keyboard input/Flush the keyboard buffer
16scala
n5gic
package main import "fmt" type Item struct { Name string Value int Weight, Volume float64 } type Result struct { Counts []int Sum int } func min(a, b int) int { if a < b { return a } return b } func Knapsack(items []Item, weight, volume float64) (best Result) { if len(items) == 0 {...
679Knapsack problem/Unbounded
0go
vw02m
import Data.List (sortBy) import Data.Ord (comparing) import Text.Printf (printf) import Control.Monad (forM_) import Data.Ratio (numerator, denominator) maxWgt :: Rational maxWgt = 15 data Bounty = Bounty { itemName :: String , itemVal, itemWgt :: Rational } items :: [Bounty] items = [ Bounty "beef" 36 3.8 ...
677Knapsack problem/Continuous
8haskell
uxiv2
null
678Knapsack problem/Bounded
11kotlin
r8fgo
while read line do [[ ${line done < data.txt
682Kernighans large earthquake problem
4bash
d4gnp
def totalWeight = { list -> list.collect{ it.item.weight * it.count }.sum() } def totalVolume = { list -> list.collect{ it.item.volume * it.count }.sum() } def totalValue = { list -> list.collect{ it.item.value * it.count }.sum() } def knapsackUnbounded = { possibleItems, BigDecimal weightMax, BigDecimal volumeMax -> ...
679Knapsack problem/Unbounded
7groovy
mbey5
use strict; use warnings; use Term::ReadKey; ReadMode 4; my $key; until(defined($key = ReadKey(-1))){ sleep 1; } print "got key '$key'\n"; ReadMode('restore');
680Keyboard input/Keypress check
2perl
fgjd7
int main() { FILE *fp; char *line = NULL; size_t len = 0; ssize_t read; char *lw, *lt; fp = fopen(, ); if (fp == NULL) { printf(); exit(1); } printf(); while ((read = getline(&line, &len, fp)) != EOF) { if (read < 2) continue; lw = strrchr(line,...
682Kernighans large earthquake problem
5c
tr7f4
import Data.List (maximumBy) import Data.Ord (comparing) (maxWgt, maxVol) = (25, 0.25) items = [Bounty "panacea" 3000 0.3 0.025, Bounty "ichor" 1800 0.2 0.015, Bounty "gold" 2500 2.0 0.002] data Bounty = Bounty {itemName :: String, itemVal :: Int, itemWgt, itemVol :: Double} na...
679Knapsack problem/Unbounded
8haskell
e6cai
struct kd_node_t{ double x[MAX_DIM]; struct kd_node_t *left, *right; }; inline double dist(struct kd_node_t *a, struct kd_node_t *b, int dim) { double t, d = 0; while (dim--) { t = a->x[dim] - b->x[dim]; d += t * t; } return d; } inline void swap(struct kd_node_t *x, struct ...
683K-d tree
5c
2eelo
from __future__ import absolute_import, division, unicode_literals, print_function import tty, termios import sys if sys.version_info.major < 3: import thread as _thread else: import _thread import time try: from msvcrt import getch except ImportError: def getch(): fd = sys.stdin.fileno(...
680Keyboard input/Keypress check
3python
trhfw
package hu.pj.alg.test; import hu.pj.alg.ContinuousKnapsack; import hu.pj.obj.Item; import java.util.*; import java.text.*; public class ContinousKnapsackForRobber { final private double tolerance = 0.0005; public ContinousKnapsackForRobber() { ContinuousKnapsack cok = new ContinuousKnapsack(15);
677Knapsack problem/Continuous
9java
mbxym
if (x > 0) goto positive; else goto negative; positive: printf(); goto both; negative: printf(); both: ...
684Jump anywhere
5c
ptfby
typedef struct { double x; double y; int group; } POINT; POINT * gen_xy(int num_pts, double radius) { int i; double ang, r; POINT * pts; pts = (POINT*) malloc(sizeof(POINT) * num_pts); for ( i = 0; i < num_pts; i++ ) { ang = 2.0 * M_PI * rand() / (RAND_MAX - 1.); r = radius * rand() / (RAND_MAX - 1.)...
685K-means++ clustering
5c
wy3ec
int rrand(int m) { return (int)((double)m * ( rand() / (RAND_MAX+1.0) )); } void shuffle(void *obj, size_t nmemb, size_t size) { void *temp = malloc(size); size_t n = nmemb; while ( n > 1 ) { size_t k = rrand(n--); memcpy(temp, BYTE(obj) + n*size, size); memcpy(BYTE(obj) + n*size, BYTE(obj) + k*si...
686Knuth shuffle
5c
c1k9c
package hu.pj.alg; import hu.pj.obj.Item; import java.text.*; public class UnboundedKnapsack { protected Item [] items = { new Item("panacea", 3000, 0.3, 0.025), new Item("ichor" , 1800, 0.2, 0.015), new Item("gold" ...
679Knapsack problem/Unbounded
9java
hnzjm
begin check = STDIN.read_nonblock(1) rescue IO::WaitReadable check = false end puts check if check
680Keyboard input/Keypress check
14ruby
3jbz7
import java.awt.event.{KeyAdapter, KeyEvent} import javax.swing.{JFrame, SwingUtilities} class KeypressCheck() extends JFrame { addKeyListener(new KeyAdapter() { override def keyPressed(e: KeyEvent): Unit = { val keyCode = e.getKeyCode if (keyCode == KeyEvent.VK_ENTER) { dispose() S...
680Keyboard input/Keypress check
16scala
9pem5
var gold = { 'value': 2500, 'weight': 2.0, 'volume': 0.002 }, panacea = { 'value': 3000, 'weight': 0.3, 'volume': 0.025 }, ichor = { 'value': 1800, 'weight': 0.2, 'volume': 0.015 }, items = [gold, panacea, ichor], knapsack = {'weight': 25, 'volume': 0.25}, max_val = 0, solutions = [], g, p,...
679Knapsack problem/Unbounded
10javascript
a3910
null
677Knapsack problem/Continuous
11kotlin
trpf0
null
683K-d tree
0go
q99xz
package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func main() { f, err := os.Open("data.txt") if err != nil { fmt.Println("Unable to open the file") return } defer f.Close() fmt.Println("Those earthquakes with a magnitude > 6.0 are:\n") input :=...
682Kernighans large earthquake problem
0go
hndjq
import java.util.regex.Pattern class LargeEarthquake { static void main(String[] args) { def r = Pattern.compile("\\s+") println("Those earthquakes with a magnitude > 6.0 are:\n") def f = new File("data.txt") f.eachLine { it -> if (r.split(it)[2].toDouble() > 6.0) { ...
682Kernighans large earthquake problem
7groovy
4s05f
package main import ( "fmt" "log"
687Juggler sequence
0go
xmzwf
import System.Random import Data.List (sortBy, genericLength, minimumBy) import Data.Ord (comparing) type DimensionalAccessors a b = [a -> b] data Tree a = Node a (Tree a) (Tree a) | Empty instance Show a => Show (Tree a) where show Empty = "Empty" show (Node value left right) = "(" ++ show va...
683K-d tree
8haskell
mbbyf
(defn shuffle [vect] (reduce (fn [v i] (let [r (rand-int i)] (assoc v i (v r) r (v i)))) vect (range (dec (count vect)) 1 -1)))
686Knuth shuffle
6clojure
5qeuz
package main import ( "fmt" "image" "image/color" "image/draw" "image/png" "math" "math/rand" "os" "time" ) type r2 struct { x, y float64 } type r2c struct { r2 c int
685K-means++ clustering
0go
c1b9g
import qualified Data.ByteString.Lazy.Char8 as C main :: IO () main = do cs <- C.readFile "data.txt" mapM_ print $ C.lines cs >>= (\x -> [ x | 6 < (read (last (C.unpack <$> C.words x)) :: Float) ])
682Kernighans large earthquake problem
8haskell
iu5or
use strict; my $raw = <<'TABLE'; map 9 150 1 compass 13 35 1 water 153 200 2 sandwich 50 60 2 glucose 15 60 2 tin 68 45 3 banana 27 60 3 apple 39 40 3 cheese 23 30 1 beer 52 10 1 suntancre...
678Knapsack problem/Bounded
2perl
d4hnw
import Text.Printf import Data.List juggler :: Integer -> [Integer] juggler = takeWhile (> 1) . iterate (\x -> if odd x then isqrt (x*x*x) else isqrt x) task :: Integer -> IO () task n = printf s n (length ns + 1) (i :: Int) (showMa...
687Juggler sequence
8haskell
ykr66
module KMeans where import Control.Applicative import Control.Monad.Random import Data.List (minimumBy, genericLength, transpose) import Data.Ord (comparing) import qualified Data.Map.Strict as M type Vec = [Float] type Cluster = [Vec] kMeansIteration :: [Vec] -> [Vec] -> [Cluster] kMeansIteration pts = clusterize ...
685K-means++ clustering
8haskell
ptdbt
import java.io.BufferedReader; import java.io.FileReader; public class KernighansLargeEarthquakeProblem { public static void main(String[] args) throws Exception { try (BufferedReader reader = new BufferedReader(new FileReader("data.txt")); ) { String inLine = null; while ( (inLin...
682Kernighans large earthquake problem
9java
xm9wy
const fs = require("fs"); const readline = require("readline"); const args = process.argv.slice(2); if (!args.length) { console.error("must supply file name"); process.exit(1); } const fname = args[0]; const readInterface = readline.createInterface({ input: fs.createReadStream(fname), console: false,...
682Kernighans large earthquake problem
10javascript
ovu86
<executable name> <width of graphics window> <height of graphics window> <real part of complex number> <imag part of complex number> <limiting radius> <Number of iterations to be tested>
688Julia set
5c
z7utx
null
679Knapsack problem/Unbounded
11kotlin
4si57
use Term::ReadKey; ReadMode 4; my $key = ''; while($key !~ /(Y|N)/i) { 1 while defined ReadKey -1; print "Type Y/N: "; $key = ReadKey 0; print "$key\n"; } ReadMode 0; print "\nYou typed: $key\n";
676Keyboard input/Obtain a Y or N response
2perl
9psmn
void clear() { for(int n = 0;n < 10; n++) { printf(); } } int main() { clear(); system(); printf(HOME); printf(); char c = 1; while(c) { c = getc(stdin); clear(); switch (c) { case 'a': printf(LEFT); break; case 'd': printf(RIGHT); break; case 'w': printf(UP); ...
689Joystick position
5c
6h532
import java.util.*; public class KdTree { private int dimensions_; private Node root_ = null; private Node best_ = null; private double bestDistance_ = 0; private int visited_ = 0; public KdTree(int dimensions, List<Node> nodes) { dimensions_ = dimensions; root_ = makeTree(node...
683K-d tree
9java
fggdv
items = { ["panaea"] = { ["value"] = 3000, ["weight"] = 0.3, ["volume"] = 0.025 }, ["ichor"] = { ["value"] = 1800, ["weight"] = 0.2, ["volume"] = 0.015 }, ["gold"] = { ["value"] = 2500, ["weight"] = 2.0, ["volume"] = 0.002 } } max_weight = 25 max_volume = 0.25 max_num_items = {} f...
679Knapsack problem/Unbounded
1lua
g0n4j
use strict; use warnings; use Math::BigInt lib => 'GMP'; print " n l(n) i(n) h(n) or d(n)\n"; print " ------- ---- ---- ------------\n"; for my $i ( 20 .. 39, 113, 173, 193, 2183, 11229, 15065, 15845, 30817, 48443, 275485, 1267909, 2264915, 5812827, 7110201 ) { my $max = my $n = Math::BigInt->...
687Juggler sequence
2perl
5qau2
null
683K-d tree
11kotlin
8220q
typedef unsigned char cell; int dx[] = { -2, -2, -1, 1, 2, 2, 1, -1 }; int dy[] = { -1, 1, 2, 2, 1, -1, -2, -2 }; void init_board(int w, int h, cell **a, cell **b) { int i, j, k, x, y, p = w + 4, q = h + 4; a[0] = (cell*)(a + q); b[0] = a[0] + 2; for (i = 1; i < q; i++) { a[i] = a[i-1] + p; b[i] = a[i] ...
690Knight's tour
5c
la7cy
null
682Kernighans large earthquake problem
11kotlin
ptzb6
null
682Kernighans large earthquake problem
1lua
1z3po
from math import isqrt def juggler(k, countdig=True, maxiters=1000): m, maxj, maxjpos = k, k, 0 for i in range(1, maxiters): m = isqrt(m) if m% 2 == 0 else isqrt(m * m * m) if m >= maxj: maxj, maxjpos = m, i if m == 1: print(f) return i print() ...
687Juggler sequence
3python
4se5k
static void print_callback (void *ctx, const char *str, size_t len) { FILE *f = (FILE *) ctx; fwrite (str, 1, len, f); } static void check_status (yajl_gen_status status) { if (status != yajl_gen_status_ok) { fprintf (stderr, , (int) status); exit (EXIT_FAILURE); } } static void serialize_va...
691JSON
5c
7oarg
package main import ( "fmt" "github.com/nsf/termbox-go" "github.com/simulatedsimian/joystick" "log" "os" "strconv" "time" ) func printAt(x, y int, s string) { for _, r := range s { termbox.SetCell(x, y, r, termbox.ColorDefault, termbox.ColorDefault) x++ } } func re...
689Joystick position
0go
pt8bg
import java.util.Random; public class KMeansWithKpp{
685K-means++ clustering
9java
r8sg0
perl -n -e '/(\S+)\s*$/ and $1 > 6 and print' data.txt
682Kernighans large earthquake problem
2perl
ykb6u
try: from msvcrt import getch except ImportError: def getch(): import sys, tty, termios fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) ch = sys.stdin.read(1) finally: termios.tcsetattr(f...
676Keyboard input/Obtain a Y or N response
3python
c109q
import qualified Graphics.UI.GLFW as GLFW import Graphics.Win32.Key import Control.Monad.RWS.Strict (liftIO) main = do liftIO $ do _ <- GLFW.init GLFW.pollEvents (jxrot, jyrot) <- liftIO $ getJoystickDirections GLFW.Joystick'1 putStrLn $ (show jxrot) ++ " " ++ (show jyrot)...
689Joystick position
8haskell
fgld1
from random import seed, random from time import time from operator import itemgetter from collections import namedtuple from math import sqrt from copy import deepcopy def sqd(p1, p2): return sum((c1 - c2) ** 2 for c1, c2 in zip(p1, p2)) class KdNode(object): __slots__ = (, , , ) def __init__(self, do...
683K-d tree
3python
g004h
define(function () { "use strict"; function distanceSquared(p, q) { const d = p.length;
685K-means++ clustering
10javascript
bfnki
<?php if ( ! isset( $argv[1] ) ) die( 'Data file name required' ); if ( ! $fh = fopen( $argv[1], 'r' ) ) die ( 'Cannot open file: ' . $argv[1] ); while ( list( $date, $loc, $mag ) = fscanf( $fh, ) ) { if ( $mag > 6 ) { printf( , $date, $loc, $mag ); } } fclose( $fh );
682Kernighans large earthquake problem
12php
a3612
from itertools import groupby from collections import namedtuple def anyvalidcomb(items, maxwt, val=0, wt=0): ' All combinations below the maxwt ' if not items: yield [], val, wt else: this, *items = items for n in range(this.number + 1): w = wt + n * this.w...
678Knapsack problem/Bounded
3python
fgkde
typedef struct { char *name; int weight; int value; } item_t; item_t items[] = { {, 9, 150}, {, 13, 35}, {, 153, 200}, {, 50, 160}, {, 15, 60}, {, 68, 45}, {, ...
692Knapsack problem/0-1
5c
fgmd3
def juggler(k) = k.even?? Integer.sqrt(k): Integer.sqrt(k*k*k) (20..39).chain([113, 173, 193, 2183, 11229, 15065, 15845, 30817, 48443, 275485, 1267909, 2264915]).each do |k| k1 = k l = h = i = 0 until k == 1 do h, i = k, l if k > h l += 1 k = juggler(k) end if k1 < 40 then puts else p...
687Juggler sequence
14ruby
r8xgs
library(tidyverse) library(rvest) task_html= read_html("http://rosettacode.org/wiki/Knapsack_problem/Bounded") task_table= html_nodes(html, "table")[[1]]%>% html_table(table, header= T, trim= T)%>% set_names(c("items", "weight", "value", "pieces"))%>% filter(items!= "knapsack")%>% mutate(weight= as.numeric(wei...
678Knapsack problem/Bounded
13r
ovr84
typedef uint64_t ulong; int kaprekar(ulong n, int base) { ulong nn = n * n, r, tens = 1; if ((nn - n) % (base - 1)) return 0; while (tens < n) tens *= base; if (n == tens) return 1 == n; while ((r = nn % tens) < n) { if (nn / tens + r == n) return tens; tens *= base; } return 0; } void print_num(ulong ...
693Kaprekar numbers
5c
0ldst
(use 'clojure.data.json) (def json-map (read-json "{ \"foo\": 1, \"bar\": [10, \"apples\"] }")) (pr-str json-map) (pprint-json json-map)
691JSON
6clojure
ptsbd
use std::cmp::Ordering; use std::cmp::Ordering::Less; use std::ops::Sub; use std::time::Instant; use rand::prelude::*; #[derive(Clone, PartialEq, Debug)] struct Point { pub coords: Vec<f32>, } impl<'a, 'b> Sub<&'b Point> for &'a Point { type Output = Point; fn sub(self, rhs: &Point) -> Point { a...
683K-d tree
15rust
jii72
object KDTree { import Numeric._
683K-d tree
16scala
bffk6
(defn isin? [x li] (not= [] (filter #(= x %) li))) (defn options [movements pmoves n] (let [x (first (last movements)) y (second (last movements)) op (vec (map #(vector (+ x (first %)) (+ y (second %))) pmoves)) vop (filter #(and (>= (first %) 0) (>= (last %) 0)) op) vop1 (filter #(and (< (...
690Knight's tour
6clojure
4sp5o
python -c ' with open() as f: for ln in f: if float(ln.strip().split()[2]) > 6: print(ln.strip())'
682Kernighans large earthquake problem
3python
mbpyh
def yesno begin system() str = STDIN.getc ensure system() end if str == return true elsif str == return false else raise end end
676Keyboard input/Obtain a Y or N response
14ruby
2eolw
my @items = sort { $b->[2]/$b->[1] <=> $a->[2]/$a->[1] } ( [qw'beef 3.8 36'], [qw'pork 5.4 43'], [qw'ham 3.6 90'], [qw'greaves 2.4 45'], [qw'flitch 4.0 30'], [qw'brawn 2.5 56'], [qw'welt 3.7 67'], [qw'salami 3.0 95'], [qw'sausage 5...
677Knapsack problem/Continuous
2perl
kdyhc
null
685K-means++ clustering
11kotlin
vwa21
null
676Keyboard input/Obtain a Y or N response
15rust
vwi2t
package main import "fmt" func main() { outer: for i := 0; i < 4; i++ { for j := 0; j < 4; j++ { if i + j == 4 { continue outer } if i + j == 5 { break outer } fmt.Println(i + j) } } k := 3 if k == 3 { goto later } fmt.Println(k)
684Jump anywhere
0go
6hj3p
local function load_data(npoints, radius)
685K-means++ clustering
1lua
uxevl
ruby -nae data.txt
682Kernighans large earthquake problem
14ruby
c1a9k
fn main() -> Result<(), Box<dyn std::error::Error>> { use std::io::{BufRead, BufReader}; for line in BufReader::new(std::fs::OpenOptions::new().read(true).open("data.txt")?).lines() { let line = line?; let magnitude = line .split_whitespace() .nth(2) .and_th...
682Kernighans large earthquake problem
15rust
laecc
scala.io.Source.fromFile("data.txt").getLines .map("\\s+".r.split(_)) .filter(_(2).toDouble > 6.0) .map(_.mkString("\t")) .foreach(println)
682Kernighans large earthquake problem
16scala
uxqv8
println(if (scala.io.StdIn.readBoolean) "Yes typed." else "Something else.")
676Keyboard input/Obtain a Y or N response
16scala
4sf50
$data = [ [ 'name'=>'beef', 'weight'=>3.8, 'cost'=>36, ], [ 'name'=>'pork', 'weight'=>5.4, 'cost'=>43, ], [ 'name'=>'ham', 'weight'=>3.6, 'cost'=>90, ], [ 'name'=>'greaves', 'weight'=>2.4, 'cost'=>45, ], [ 'name'=>'flitch', 'weight'=>4.0...
677Knapsack problem/Continuous
12php
3jazq
import Control.Monad.Cont data LabelT r m = LabelT (ContT r m ()) label :: ContT r m (LabelT r m) label = callCC subprog where subprog lbl = let l = LabelT (lbl l) in return l goto :: LabelT r m -> ContT r m b goto (LabelT l) = const undefined <$> l runProgram :: Monad m => ContT r m r -> m r runProgram program =...
684Jump anywhere
8haskell
jio7g