code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
abstract class X { type A var B: A val C: A def D(a: A): A } trait Y { val x: X }
1,166Abstract type
16scala
p1cbj
def ack(m, n) if m == 0 n + 1 elsif n == 0 ack(m-1, 1) else ack(m-1, ack(m, n-1)) end end
1,162Ackermann function
14ruby
m9oyj
shopt -s expand_aliases alias bind_variables=' { local -ri goal_count=21 local -ri player_human=0 local -ri player_computer=1 local -i turn=1 local -i total_count=0 local -i input_number=0 local -i choose_turn=0 } ' whose_turn() { case $(( ( turn + choose_turn ) % 2 )) in ${player_human}) echo "playe...
1,17221 game
4bash
p1zbb
import java.math.BigInteger; import java.util.*; import static java.util.Arrays.asList; import static java.util.stream.Collectors.toList; import static java.util.stream.IntStream.range; import static java.lang.Math.min; public class Test { static List<BigInteger> cumu(int n) { List<List<BigInteger>> cache...
1,1709 billion names of God the integer
9java
aem1y
null
1,169Abundant odd numbers
1lua
oig8h
static char DESCRIPTION[] = ; static int total; void update(char* player, int move) { printf(, player, total + move, total, move); total += move; if (total == GOAL) printf(_(), player); } int ai() { static const int precomputed[] = { 1, 1, 3, 2, 1, 1, 3, 2, 1...
1,17221 game
5c
ae611
(function () { var cache = [ [1] ];
1,1709 billion names of God the integer
10javascript
s0vqz
fn ack(m: isize, n: isize) -> isize { if m == 0 { n + 1 } else if n == 0 { ack(m - 1, 1) } else { ack(m - 1, ack(m, n - 1)) } } fn main() { let a = ack(3, 4); println!("{}", a);
1,162Ackermann function
15rust
9cimm
require File.read().each_line do |line| next if line.strip.empty? abbr = line.split.abbrev.invert puts , abbr.inspect, end
1,168Abbreviations, automatic
14ruby
p1mbh
use std::fs::File; use std::io; use std::io::{BufRead, BufReader}; fn main() { let table = read_days("weekdays.txt").expect("Error in Function read_days:"); for line in table { if line.len() == 0 { continue; }; let mut max_same = 0; for i in 0..(line.len() - 1) { ...
1,168Abbreviations, automatic
15rust
1a9pu
import java.lang.Math.min import java.math.BigInteger import java.util.ArrayList import java.util.Arrays.asList fun namesOfGod(n: Int): List<BigInteger> { val cache = ArrayList<List<BigInteger>>() cache.add(asList(BigInteger.ONE)) (cache.size..n).forEach { l -> val r = ArrayList<BigInteger>() ...
1,1709 billion names of God the integer
11kotlin
hktj3
name := "Abbreviations-automatic" scalaVersion := "2.13.0" version := "0.1" homepage := Some(url("http:
1,168Abbreviations, automatic
16scala
wx2es
int can_make_words(char **b, char *word) { int i, ret = 0, c = toupper(*word); if (!c) return 1; if (!b[0]) return 0; for (i = 0; b[i] && !ret; i++) { if (b[i][0] != c && b[i][1] != c) continue; SWAP(b[i], b[0]); ret = can_make_words(b + 1, word + 1); SWAP(b[i], b[0]); } return ret; } int main(void)...
1,173ABC problem
5c
inuo2
function nog(n) local tri = {{1}} for r = 2, n do tri[r] = {} for c = 1, r do tri[r][c] = (tri[r-1][c-1] or 0) + (tri[r-c] and tri[r-c][c] or 0) end end return tri end function G(n) local tri, sum = nog(n), 0 for _, v in ipairs(tri[n]) do sum = sum + v end return sum end tri = nog(25) ...
1,1709 billion names of God the integer
1lua
kbzh2
def ack(m: BigInt, n: BigInt): BigInt = { if (m==0) n+1 else if (n==0) ack(m-1, 1) else ack(m-1, ack(m, n-1)) }
1,162Ackermann function
16scala
2vflb
(def blocks (-> "BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM" (.split " ") vec)) (defn omit "return bs with (one instance of) b omitted" [bs b] (let [[before after] (split-with #(not= b %) bs)] (concat before (rest after)))) (defn abc "return lazy sequence of solutions (i.e. block lis...
1,173ABC problem
6clojure
z37tj
package main import "fmt" func main(){ n, c := getCombs(1,7,true) fmt.Printf("%d unique solutions in 1 to 7\n",n) fmt.Println(c) n, c = getCombs(3,9,true) fmt.Printf("%d unique solutions in 3 to 9\n",n) fmt.Println(c) n, _ = getCombs(0,9,false) fmt.Printf("%d non-unique solutions in 0 to 9\n",n) } func getCo...
1,1714-rings or 4-squares puzzle
0go
ft7d0
class FourRings { static void main(String[] args) { fourSquare(1, 7, true, true) fourSquare(3, 9, true, true) fourSquare(0, 9, false, false) } private static void fourSquare(int low, int high, boolean unique, boolean print) { int count = 0 if (print) { p...
1,1714-rings or 4-squares puzzle
7groovy
8ou0b
use strict; use warnings; use feature 'say'; use ntheory qw/divisor_sum divisors/; sub odd_abundants { my($start,$count) = @_; my $n = int(( $start + 2 ) / 3); $n += 1 if 0 == $n % 2; $n *= 3; my @out; while (@out < $count) { $n += 6; next unless (my $ds = divisor_sum($n)) >...
1,169Abundant odd numbers
2perl
4gi5d
import Data.List import Control.Monad perms :: (Eq a) => [a] -> [[a]] perms [] = [[]] perms xs = [ x:xr | x <- xs, xr <- perms (xs\\[x]) ] combs :: (Eq a) => Int -> [a] -> [[a]] combs 0 _ = [[]] combs n xs = [ x:xr | x <- xs, xr <- combs (n-1) xs ] ringCheck :: [Int] -> Bool ringCheck [x0, x1, x2, x3, x4, x5, x6] = ...
1,1714-rings or 4-squares puzzle
8haskell
4g85s
use ntheory qw/:all/; sub triangle_row { my($n,@row) = (shift); forpart { $row[ $_[0] - 1 ]++ } $n; @row; } printf "%2d:%s\n", $_, join(" ",triangle_row($_)) for 1..25; print "\n"; say "P($_) = ", partitions($_) for (23, 123, 1234, 12345);
1,1709 billion names of God the integer
2perl
z3ktb
typedef struct {int val, op, left, right;} Node; Node nodes[10000]; int iNodes; int b; float eval(Node x){ if (x.op != -1){ float l = eval(nodes[x.left]), r = eval(nodes[x.right]); switch(x.op){ case 0: return l+r; case 1: return l-r; case 2: return r-l; ...
1,17424 game/Solve
5c
vue2o
import java.util.Arrays; public class FourSquares { public static void main(String[] args) { fourSquare(1, 7, true, true); fourSquare(3, 9, true, true); fourSquare(0, 9, false, false); } private static void fourSquare(int low, int high, boolean unique, boolean print) { int ...
1,1714-rings or 4-squares puzzle
9java
cle9h
package main import ( "bufio" "fmt" "log" "math/rand" "os" "strconv" "time" ) var scanner = bufio.NewScanner(os.Stdin) var ( total = 0 quit = false ) func itob(i int) bool { if i == 0 { return false } return true } func getChoice() { for { fmt.Pr...
1,17221 game
0go
m9pyi
(() => {
1,1714-rings or 4-squares puzzle
10javascript
540ur
import System.Random import System.IO import System.Exit import Control.Monad import Text.Read import Data.Maybe promptAgain :: IO Int promptAgain = do putStrLn "Invalid input - must be a number among 1,2 or 3. Try again." playerMove playerMove :: IO Int playerMove = do putStr "Your choice(1 to 3):" number <-...
1,17221 game
8haskell
kbfh0
oddNumber = 1 aCount = 0 dSum = 0 from math import sqrt def divisorSum(n): sum = 1 i = int(sqrt(n)+1) for d in range (2, i): if n% d == 0: sum += d otherD = n if otherD != d: sum += otherD return sum print () while aCount < 25: dSu...
1,169Abundant odd numbers
3python
grn4h
cache = [[1]] def cumu(n): for l in range(len(cache), n+1): r = [0] for x in range(1, l+1): r.append(r[-1] + cache[l-x][min(x, l-x)]) cache.append(r) return cache[n] def row(n): r = cumu(n) return [r[i+1] - r[i] for i in range(n)] print for x in range(1, 11): print...
1,1709 billion names of God the integer
3python
36bzc
import java.util.Random; import java.util.Scanner; public class TwentyOneGame { public static void main(String[] args) { new TwentyOneGame().run(true, 21, new int[] {1, 2, 3}); } public void run(boolean computerPlay, int max, int[] valid) { String comma = ""; for ( int i = 0 ; i <...
1,17221 game
9java
4g058
(ns rosettacode.24game.solve (:require [clojure.math.combinatorics:as c] [clojure.walk:as w])) (def ^:private op-maps (map #(zipmap [:o1:o2:o3] %) (c/selections '(* + - /) 3))) (def ^:private patterns '( (:o1 (:o2:n1:n2) (:o3:n3:n4)) (:o1:n1 (:o2:n2 (:o3:n3:n4))) (:o1 (:o2 (:o3:n1:n2):n3):n4))) ...
1,17424 game/Solve
6clojure
r70g2
null
1,1714-rings or 4-squares puzzle
11kotlin
36kz5
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8"> <meta name="keywords" content="Game 21"> <meta name="description" content=" 21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose ...
1,17221 game
10javascript
hkdjh
function valid(unique,needle,haystack) if unique then for _,value in pairs(haystack) do if needle == value then return false end end end return true end function fourSquare(low,high,unique,prnt) count = 0 if prnt then print("a", "b", "...
1,1714-rings or 4-squares puzzle
1lua
6yb39
jmp_buf ctx; const char *msg; enum { OP_NONE = 0, OP_NUM, OP_ADD, OP_SUB, OP_MUL, OP_DIV }; typedef struct expr_t *expr, expr_t; struct expr_t { int op, val, used; expr left, right; }; expr_t digits[N_DIGITS]; void gen_digits() { int i; for (i = 0; i < N_DIGITS; i++) digits[i].val = 1 + rand() % 9; } char ...
1,17524 game
5c
9ckm1
find_div_sum <- function(x){ if (x < 16) return(0) root <- sqrt(x) vec <- as.vector(1) for (i in seq.int(3, root - 1, by = 2)){ if(x%% i == 0){ vec <- c(vec, i, x/i) } } if (root == trunc(root)) vec = c(vec, root) return(sum(vec)) } get_n_abun <- function(index = 1, total = 25, print_all...
1,169Abundant odd numbers
13r
vu027
gamewon = false running_total = 0 player = 1 opponent = 2 while not gamewon do num = 0 if player == 1 then opponent = 2 repeat print("Enter a number between 1 and 3 (0 to quit):") num = io.read("*n") if num == 0 then os.exit() end until (num > 0) and (num <=3) end ...
1,17221 game
1lua
2vwl3
def g(n,g) return 1 unless 1 < g and g < n-1 (2..g).inject(1){|res,q| res + (q > n-g? 0: g(n-g,q))} end (1..25).each {|n| puts (1..n).map {|g| % g(n,g)}.join }
1,1709 billion names of God the integer
14ruby
ym16n
typedef struct{ int cardNum; bool hasBeenOpened; }drawer; drawer *drawerSet; void initialize(int prisoners){ int i,j,card; bool unique; drawerSet = ((drawer*)malloc(prisoners * sizeof(drawer))) -1; card = rand()%prisoners + 1; drawerSet[1] = (drawer){.cardNum = card, .hasBeenOpened = false}; for(i=1 + 1;i<...
1,176100 prisoners
5c
m9jys
extern crate num; use std::cmp; use num::bigint::BigUint; fn cumu(n: usize, cache: &mut Vec<Vec<BigUint>>) { for l in cache.len()..n+1 { let mut r = vec![BigUint::from(0u32)]; for x in 1..l+1 { let prev = r[r.len() - 1].clone(); r.push(prev + cache[l-x][cmp::min(x, l-x)].cl...
1,1709 billion names of God the integer
15rust
m9aya
object Main {
1,1709 billion names of God the integer
16scala
l2xcq
(ns rosettacode.24game) (def ^:dynamic *luser* "You guessed wrong, or your input was not in prefix notation.") (def ^:private start #(println "Your numbers are: " %1 ". Your goal is " %2 ".\n" "Use the ops [+ - * /] in prefix notation to reach" %2 ".\n" "q[enter] to quit.")) (defn play ([] (play 24)) ([goal] (p...
1,17524 game
6clojure
u5evi
func ackerman(m:Int, n:Int) -> Int { if m == 0 { return n+1 } else if n == 0 { return ackerman(m-1, 1) } else { return ackerman(m-1, ackerman(m, n-1)) } }
1,162Ackermann function
17swift
ym86e
use ntheory qw/forperm/; use Set::CrossProduct; sub four_sq_permute { my($list) = @_; my @solutions; forperm { @c = @$list[@_]; push @solutions, [@c] if check(@c); } @$list; print +@solutions . " unique solutions found using: " . join(', ', @$list) . "\n"; return @solutions; } su...
1,1714-rings or 4-squares puzzle
2perl
p13b0
(ns clojure-sandbox.prisoners) (defn random-drawers [] "Returns a list of shuffled numbers" (-> 100 range shuffle)) (defn search-50-random-drawers [prisoner-number drawers] "Select 50 random drawers and return true if the prisoner's number was found" (->> drawers shuffle (take 50) ...
1,176100 prisoners
6clojure
vu12f
require class Integer def proper_divisors return [] if self == 1 primes = prime_division.flat_map{|prime, freq| [prime] * freq} (1...primes.size).each_with_object([1]) do |n, res| primes.combination(n).map{|combi| res << combi.inject(:*)} end.flatten.uniq end end def generator_odd_abundants...
1,169Abundant odd numbers
14ruby
7jfri
fn divisors(n: u64) -> Vec<u64> { let mut divs = vec![1]; let mut divs2 = Vec::new(); for i in (2..).take_while(|x| x * x <= n).filter(|x| n% x == 0) { divs.push(i); let j = n / i; if i!= j { divs2.push(j); } } divs.extend(divs2.iter().rev()); divs }...
1,169Abundant odd numbers
15rust
jht72
import scala.collection.mutable.ListBuffer object Abundant { def divisors(n: Int): ListBuffer[Int] = { val divs = new ListBuffer[Int] divs.append(1) val divs2 = new ListBuffer[Int] var i = 2 while (i * i <= n) { if (n % i == 0) { val j = n / i divs.append(i) if (i ...
1,169Abundant odd numbers
16scala
bp6k6
print <<'HERE'; The 21 game. Each player chooses to add 1, 2, or 3 to a running total. The player whose turn it is when the total reaches 21 wins. Enter q to quit. HERE my $total = 0; while () { print "Running total is: $total\n"; my ($me,$comp); while () { print 'What number do you play> '; ...
1,17221 game
2perl
qscx6
typedef unsigned char u8t; typedef unsigned short u16t; enum { NR=4, NC=4, NCELLS = NR*NC }; enum { UP, DOWN, LEFT, RIGHT, NDIRS }; enum { OK = 1<<8, XX = 1<<9, FOUND = 1<<10, zz=0x80 }; enum { MAX_INT=0x7E, MAX_NODES=(16*65536)*90}; enum { BIT_HDR=1<<0, BIT_GRID=1<<1, BIT_OTHER=1<<2 }; enum { PHASE1,PHASE2 }; typed...
1,17715 puzzle solver
5c
4ge5t
var cache = [[1]] func namesOfGod(n:Int) -> [Int] { for l in cache.count...n { var r = [0] for x in 1...l { r.append(r[r.count - 1] + cache[l - x][min(x, l-x)]) } cache.append(r) } return cache[n] } func row(n:Int) -> [Int] { let r = namesOfGod(n) var ret...
1,1709 billion names of God the integer
17swift
6yp3j
int main() { int a, b; scanf(, &a, &b); printf(, a + b); return 0; }
1,178A+B
5c
541uk
<!DOCTYPE html> <html lang=> <head> <meta charset=> <meta name= content=> <meta name= content=> <!--DCMI metadata (Dublin Core Metadata Initiative)--> <meta name= content=> <meta name= content=> <meta name= content=> <meta name= content=> <title> 21 Game </tit...
1,17221 game
12php
vux2v
extension BinaryInteger { @inlinable public func factors(sorted: Bool = true) -> [Self] { let maxN = Self(Double(self).squareRoot()) var res = Set<Self>() for factor in stride(from: 1, through: maxN, by: 1) where self% factor == 0 { res.insert(factor) res.insert(self / factor) } re...
1,169Abundant odd numbers
17swift
r7dgg
import itertools def all_equal(a,b,c,d,e,f,g): return a+b == b+c+d == d+e+f == f+g def foursquares(lo,hi,unique,show): solutions = 0 if unique: uorn = citer = itertools.combinations(range(lo,hi+1),7) else: uorn = citer = itertools.combinations_with_replacement(range(...
1,1714-rings or 4-squares puzzle
3python
1a6pc
from random import randint def start(): game_count=0 print(.format(game_count)) roundno=1 while game_count<21: print(.format(roundno)) t = select_count(game_count) game_count = game_count+t print(.format(game_count)) if game_count>=21: print() return 0 t = request_count() if not t: print('OK,...
1,17221 game
3python
s0lq9
perms <- function (n, r, v = 1:n, repeats.allowed = FALSE) { if (repeats.allowed) sub <- function(n, r, v) { if (r == 1) matrix(v, n, 1) else if (n == 1) matrix(v, 1, r) else { inner <- Recall(n, r - 1, v) cbind(rep(v, rep(nrow(inner), n)), matrix(t(inner), ...
1,1714-rings or 4-squares puzzle
13r
hkfjj
(println (+ (Integer/parseInt (read-line)) (Integer/parseInt (read-line)))) 3 4 =>7
1,178A+B
6clojure
jhq7m
package main import ( "fmt" "math/rand" "time" ) const ( op_num = iota op_add op_sub op_mul op_div ) type frac struct { num, denom int }
1,17424 game/Solve
0go
s09qa
game21<-function(first = c("player","ai","random"),sleep=.5){ state = 0 finished = F turn = 1 if(length(first)==1 && startsWith(tolower(first),"r")){ first = rbinom(1,1,.5) }else{ first = (length(first)>1 || startsWith(tolower(first),"p")) } while(!finished){ if(turn>1 || first){ cat("Th...
1,17221 game
13r
ewyad
package main import "fmt" var ( Nr = [16]int{3, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3} Nc = [16]int{3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2} ) var ( n, _n int N0, N3, N4 [85]int N2 [85]uint64 ) const ( i = 1 g = 8 e = 2 l = 4 ) func fY() bool { if N...
1,17715 puzzle solver
0go
oi98q
import Data.List import Data.Ratio import Control.Monad import System.Environment (getArgs) data Expr = Constant Rational | Expr:+ Expr | Expr:- Expr | Expr:* Expr | Expr:/ Expr deriving (Eq) ops = [(:+), (:-), (:*), (:/)] instance Show Expr where show (Constant x) = show $ numerator x sho...
1,17424 game/Solve
8haskell
9cbmo
const long values[] = { 0, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048 }; const char *colors[] = { , , , , , , , , , , , }; struct gamestate_struct__ { int grid[4][4]; int have_moved; long total_score; long score_last_move; int blocks_in_play; } game; struct termios oldt, newt; void ...
1,1792048
5c
qstxc
def four_squares(low, high, unique=true, show=unique) f = -> (a,b,c,d,e,f,g) {[a+b, b+c+d, d+e+f, f+g].uniq.size == 1} if unique uniq = solutions = [*low..high].permutation(7).select{|ary| f.call(*ary)} else uniq = solutions = [*low..high].repeated_permutation(7).select{|ary| f.call(*ary)} end...
1,1714-rings or 4-squares puzzle
14ruby
ewmax
#!/usr/bin/lua
1,17715 puzzle solver
1lua
ftvdp
package main import ( "fmt" "strings" ) func newSpeller(blocks string) func(string) bool { bl := strings.Fields(blocks) return func(word string) bool { return r(word, bl) } } func r(word string, bl []string) bool { if word == "" { return true } c := word[0] | 32 for i, b := range bl { if c == b[0]|32 ...
1,173ABC problem
0go
gr04n
#![feature(inclusive_range_syntax)] fn is_unique(a: u8, b: u8, c: u8, d: u8, e: u8, f: u8, g: u8) -> bool { a!= b && a!= c && a!= d && a!= e && a!= f && a!= g && b!= c && b!= d && b!= e && b!= f && b!= g && c!= d && c!= e && c!= f && c!= g && d!= e && d!= f && d!= g && e!= f && e!= g && f!= g }...
1,1714-rings or 4-squares puzzle
15rust
wx9e4
class ABCSolver { def blocks ABCSolver(blocks = []) { this.blocks = blocks } boolean canMakeWord(rawWord) { if (rawWord == '' || rawWord == null) { return true; } def word = rawWord.toUpperCase() def blocksLeft = [] + blocks word.every { letter -> blocksLeft.remove(blocksLe...
1,173ABC problem
7groovy
2velv
import java.util.*; public class Game24Player { final String[] patterns = {"nnonnoo", "nnonono", "nnnoono", "nnnonoo", "nnnnooo"}; final String ops = "+-*/^"; String solution; List<Integer> digits; public static void main(String[] args) { new Game24Player().play(); } void...
1,17424 game/Solve
9java
tzgf9
(ns 2048 (:require [clojure.string:as str])) (def textures {:wall "----+" :cell "%4s|" :cell-edge "|" :wall-edge "+"}) (def directions {:w:up :s:down :a:left :d:right}) (def field-size {:y 4:x 4}) (defn cells->st...
1,1792048
6clojure
inmom
object FourRings { def fourSquare(low: Int, high: Int, unique: Boolean, print: Boolean): Unit = { def isValid(needle: Integer, haystack: Integer*) = !unique || !haystack.contains(needle) if (print) println("a b c d e f g") var count = 0 for { a <- low to high b <- low to high if isValid...
1,1714-rings or 4-squares puzzle
16scala
s02qo
GOAL = 21 MIN_MOVE = 1 MAX_MOVE = 3 DESCRIPTION = def best_move(total) move = rand(1..3) MIN_MOVE.upto(MAX_MOVE) do |i| move = i if (total + i - 1) % (MAX_MOVE + 1) == 0 end MIN_MOVE.upto(MAX_MOVE) do |i| move = i if total + i == GOAL end move end def get_move print answer = gets mo...
1,17221 game
14ruby
8ov01
var ar=[],order=[0,1,2],op=[],val=[]; var NOVAL=9999,oper="+-*/",out; function rnd(n){return Math.floor(Math.random()*n)} function say(s){ try{document.write(s+"<br>")} catch(e){WScript.Echo(s)} } function getvalue(x,dir){ var r=NOVAL; if(dir>0)++x; while(1){ if(val[x]!=NOVAL){ r=val[x]; val[x]=NOVAL; ...
1,17424 game/Solve
10javascript
m9kyv
import Data.List (delete) import Data.Char (toUpper) abc :: (Eq a) => [[a]] -> [a] -> [[[a]]] abc _ [] = [[]] abc blocks (c:cs) = [b:ans | b <- blocks, c `elem` b, ans <- abc (delete b blocks) cs] blocks = ["BO", "XK", "DQ", "CP", "NA", "GT", "RE", "TG", "QD", "FS", "JW", "HU",...
1,173ABC problem
8haskell
s0cqk
use rand::Rng; use std::io; #[derive(Clone)] enum PlayerType { Human, Computer, } #[derive(Clone)] struct Player { name: String, wins: u32,
1,17221 game
15rust
oiu83
use strict; no warnings; use enum qw(False True); use constant Nr => <3 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3>; use constant Nc => <3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2>; my ($n, $m) = (0, 0); my(@N0, @N2, @N3, @N4); sub fY { printf "Solution found in $n moves:%s\n", join('', @N3) and exit if $N2[$n] == 0x123456789abcdef0; ...
1,17715 puzzle solver
2perl
jhs7f
import 'dart:io';
1,178A+B
18dart
9c7m8
object Game21 { import scala.collection.mutable.ListBuffer import scala.util.Random val N = 21
1,17221 game
16scala
dfgng
package main import ( "fmt" "math" "math/rand" "time" ) func main() { rand.Seed(time.Now().Unix()) n := make([]rune, 4) for i := range n { n[i] = rune(rand.Intn(9) + '1') } fmt.Printf("Your numbers:%c\n", n) fmt.Print("Enter RPN: ") var expr string fmt.Scan(&exp...
1,17524 game
0go
ewza6
null
1,17424 game/Solve
11kotlin
oi28z
enum Move{UP,DOWN,LEFT,RIGHT};int hR;int hC;int cc[N][M];const int nS=100;int update(enum Move m){const int dx[]={0,0,-1,1};const int dy[]={-1,1,0,0};int i=hR +dy[m];int j=hC+dx[m];if(i>= 0&&i<N&&j>=0&&j<M){cc[hR][hC]=cc[i][j];cc[i][j]=0; hR=i;hC=j;return 1;}return 0;}void setup(void){int i,j,k;for(i=0;i<N;i++)for(j=0 ...
1,18015 puzzle game
5c
36vza
import java.util.Arrays; import java.util.Collections; import java.util.List; public class ABC { public static void main(String[] args) { List<String> blocks = Arrays.asList( "BO", "XK", "DQ", "CP", "NA", "GT", "RE", "TG", "QD", "FS", "JW", "HU", "VI", "AN",...
1,173ABC problem
9java
1azp2
final random = new Random() final input = new Scanner(System.in) def evaluate = { expr -> if (expr == 'QUIT') { return 'QUIT' } else { try { Eval.me(expr.replaceAll(/(\d)/, '$1.0')) } catch (e) { 'syntax error' } } } def readGuess = { digits -> while (true) { print "E...
1,17524 game
7groovy
kbih7
var blocks = "BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM"; function CheckWord(blocks, word) {
1,173ABC problem
10javascript
qs9x8
package main import ( "fmt" "math/rand" "time" )
1,176100 prisoners
0go
aef1f
local SIZE = #arg[1] local GOAL = tonumber(arg[2]) or 24 local input = {} for v in arg[1]:gmatch("%d") do table.insert(input, v) end assert(#input == SIZE, 'Invalid input') local operations = {'+', '-', '*', '/'} local function BinaryTrees(vert) if vert == 0 then return {false} else local buf = {} for lefte...
1,17424 game/Solve
1lua
invot
import Data.List (sort) import Data.Char (isDigit) import Data.Maybe (fromJust) import Control.Monad (foldM) import System.Random (randomRs, getStdGen) import System.IO (hSetBuffering, stdout, BufferMode(NoBuffering)) main = do hSetBuffering stdout NoBuffering mapM_ putStrLn [ "THE 24 GAME\n" , "Given ...
1,17524 game
8haskell
36rzj
import java.util.function.Function import java.util.stream.Collectors import java.util.stream.IntStream class Prisoners { private static boolean playOptimal(int n) { List<Integer> secretList = IntStream.range(0, n).boxed().collect(Collectors.toList()) Collections.shuffle(secretList) prison...
1,176100 prisoners
7groovy
hk8j9
import System.Random import Control.Monad.State numRuns = 10000 numPrisoners = 100 numDrawerTries = 50 type Drawers = [Int] type Prisoner = Int type Prisoners = [Int] main = do gen <- getStdGen putStrLn $ "Chance of winning when choosing randomly: " ++ (show $ evalState runRandomly gen) putStrLn $...
1,176100 prisoners
8haskell
z34t0
object ABC_block_checker { fun run() { println("\"\": " + blocks.canMakeWord("")) for (w in words) println("$w: " + blocks.canMakeWord(w)) } private fun Array<String>.swap(i: Int, j: Int) { val tmp = this[i] this[i] = this[j] this[j] = tmp } private fun Arra...
1,173ABC problem
11kotlin
jhi7r
sub permute (&@) { my $code = shift; my @idx = 0..$ while ( $code->(@_[@idx]) ) { my $p = $ --$p while $idx[$p-1] > $idx[$p]; my $q = $p or return; push @idx, reverse splice @idx, $p; ++$q while $idx[$p-1] > $idx[$q]; @idx[$p-1,$q]=@idx[$q,$p-1]; } } @formats = ( '((%d%s%d)%s%d)%s%d', '(%d...
1,17424 game/Solve
2perl
grs4e
import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.IntStream; public class Main { private static boolean playOptimal(int n) { List<Integer> secretL...
1,176100 prisoners
9java
oic8d
package main import ( "bufio" "fmt" "log" "math/rand" "os" "os/exec" "strconv" "strings" "text/template" "time" "unicode" "golang.org/x/crypto/ssh/terminal" ) const maxPoints = 2048 const ( fieldSizeX = 4 fieldSizeY = 4 ) const tilesAtStart = 2 const probFor2 = 0.9 type button int const ( _ button =...
1,1792048
0go
2vhl7
import java.util.*; public class Game24 { static Random r = new Random(); public static void main(String[] args) { int[] digits = randomDigits(); Scanner in = new Scanner(System.in); System.out.print("Make 24 using these digits: "); System.out.println(Arrays.toString(digits))...
1,17524 game
9java
in2os
const _ = require('lodash'); const numPlays = 100000; const setupSecrets = () => {
1,176100 prisoners
10javascript
tz5fm
import System.IO import Data.List import Data.Maybe import Control.Monad import Data.Random import Data.Random.Distribution.Categorical import System.Console.ANSI import Control.Lens prob4 :: Double prob4 = 0.1 type Position = [[Int]] combine, shift :: [Int]->[Int] combine (x:y:l) | x==y = (2*x): combine l combin...
1,1792048
8haskell
aei1g
function twentyfour(numbers, input) { var invalidChars = /[^\d\+\*\/\s-\(\)]/; var validNums = function(str) {
1,17524 game
10javascript
z3gt2
blocks = { {"B","O"}; {"X","K"}; {"D","Q"}; {"C","P"}; {"N","A"}; {"G","T"}; {"R","E"}; {"T","G"}; {"Q","D"}; {"F","S"}; {"J","W"}; {"H","U"}; {"V","I"}; {"A","N"}; {"O","B"}; {"E","R"}; {"F","S"}; {"L","Y"}; {"P","C"}; {"Z","M"}; }; function canUse(table, letter) for i,v in pairs(blocks) do if (v[1] == lette...
1,173ABC problem
1lua
hknj8
import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.swing.*; public class Game2048 extends JPanel { enum State { start, won, running, over } final Color[] colorTable = { new Color(0x701710), new Color(0xFFE4C3), new Color(0xfff4d3), new Color(0xffdac3...
1,1792048
9java
jhx7c
import java.util.Random import java.util.Scanner import java.util.Stack internal object Game24 { fun run() { val r = Random() val digits = IntArray(4).map { r.nextInt(9) + 1 } println("Make 24 using these digits: $digits") print("> ") val s = Stack<Float>() var tota...
1,17524 game
11kotlin
qsyx1
val playOptimal: () -> Boolean = { val secrets = (0..99).toMutableList() var ret = true secrets.shuffle() prisoner@ for(i in 0 until 100){ var prev = i draw@ for(j in 0 until 50){ if (secrets[prev] == i) continue@prisoner prev = secrets[prev] } re...
1,176100 prisoners
11kotlin
xq3ws