code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
use List::Util qw(shuffle);
my $turn = 0;
my @jumble = shuffle 1..9;
while ( join('', @jumble) eq '123456789' ) {
@jumble = shuffle 1..9;
}
until ( join('', @jumble) eq '123456789' ) {
$turn++;
printf "%2d: @jumble - Flip how many digits? ", $turn;
my $d = <>;
@jumble[0..$d-1] = reverse @jumble... | 514Number reversal game | 2perl | 31uzs |
def evolve(ary)
([0]+ary+[0]).each_cons(3).map{|a,b,c| a+b+c == 2? 1: 0}
end
def printit(ary)
puts ary.join.tr(,)
end
ary = [0,1,1,1,0,1,1,0,1,0,1,0,1,0,1,0,0,1,0,0]
printit ary
until ary == (new = evolve(ary))
printit ary = new
end | 512One-dimensional cellular automata | 14ruby | 9xjmz |
void nb(int cells, int total_block_size, int* blocks, int block_count,
char* output, int offset, int* count) {
if (block_count == 0) {
printf(, ++*count, output);
return;
}
int block_size = blocks[0];
int max_pos = cells - (total_block_size + block_count - 1);
total_block_siz... | 516Nonoblock | 5c | xvnwu |
use Lingua::EN::Numbers 'num2en';
print num2en(123456789), "\n"; | 515Number names | 2perl | s5tq3 |
class ReversalGame {
private $numbers;
public function __construct() {
$this->initialize();
}
public function play() {
$i = 0;
$moveCount = 0;
while (true) {
echo json_encode($this->numbers) . ;
echo ;
$i = intval(rtrim(fgets(STDIN), ... | 514Number reversal game | 12php | pm8ba |
fn get_new_state(windowed: &[bool]) -> bool {
match windowed {
[false, true, true] | [true, true, false] => true,
_ => false
}
}
fn next_gen(cell: &mut [bool]) {
let mut v = Vec::with_capacity(cell.len());
v.push(cell[0]);
for i in cell.windows(3) {
v.push(get_new_state(i));... | 512One-dimensional cellular automata | 15rust | cqh9z |
def cellularAutomata(s: String) = {
def it = Iterator.iterate(s) ( generation =>
("_%s_" format generation).iterator
sliding 3
map (_ count (_ == '#'))
map Map(2 -> "#").withDefaultValue("_")
mkString
)
(it drop 1) zip it takeWhile Function.tupled(_ != _) map (_._2) foreach println
} | 512One-dimensional cellular automata | 16scala | v8p2s |
$orderOfMag = array('Hundred', 'Thousand,', 'Million,', 'Billion,', 'Trillion,');
$smallNumbers = array('Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine',
'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen');
$decades = array('', '', ... | 515Number names | 12php | uokv5 |
package main
import (
"fmt"
"strings"
)
func printBlock(data string, le int) {
a := []byte(data)
sumBytes := 0
for _, b := range a {
sumBytes += int(b - 48)
}
fmt.Printf("\nblocks%c, cells%d\n", a, le)
if le-sumBytes <= 0 {
fmt.Println("No solution")
return
... | 516Nonoblock | 0go | lsrcw |
package main
import (
"fmt"
"sort"
)
func fourFaceCombs() (res [][4]int) {
found := make([]bool, 256)
for i := 1; i <= 4; i++ {
for j := 1; j <= 4; j++ {
for k := 1; k <= 4; k++ {
for l := 1; l <= 4; l++ {
c := [4]int{i, j, k, l}
... | 517Non-transitive dice | 0go | 19sp5 |
int main()
{
int num;
sscanf(, , &num);
printf(, num);
sscanf(, , &num);
printf(, num);
sscanf(, , &num);
printf(, num);
return 0;
} | 518Non-decimal radices/Input | 5c | v8r2o |
'''
number reversal game
Given a jumbled list of the numbers 1 to 9
Show the list.
Ask the player how many digits from the left to reverse.
Reverse those digits then ask again.
until all the digits end up in ascending order.
'''
import random
print(__doc__)
data, trials = list('123456789'), 0
whi... | 514Number reversal game | 3python | 6a53w |
import java.util.*;
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.toList;
public class Nonoblock {
public static void main(String[] args) {
printBlock("21", 5);
printBlock("", 5);
printBlock("8", 10);
printBlock("2323", 15);
printBlock("23... | 516Nonoblock | 9java | 7tarj |
import Data.List
import Control.Monad
newtype Dice = Dice [Int]
instance Show Dice where
show (Dice s) = "(" ++ unwords (show <$> s) ++ ")"
instance Eq Dice where
d1 == d2 = d1 `compare` d2 == EQ
instance Ord Dice where
Dice d1 `compare` Dice d2 = (add $ compare <$> d1 <*> d2) `compare` 0
where
add... | 517Non-transitive dice | 8haskell | tb9f7 |
const compose = (...fn) => (...x) => fn.reduce((a, b) => c => a(b(c)))(...x);
const inv = b => !b;
const arrJoin = str => arr => arr.join(str);
const mkArr = (l, f) => Array(l).fill(f);
const sumArr = arr => arr.reduce((a, b) => a + b, 0);
const sumsTo = val => arr => sumArr(arr) === val;
const zipper = arr => (p, c, i... | 516Nonoblock | 10javascript | pmsb7 |
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
private static List<List<Integer>> fourFaceCombos() {
List<List<Integer>> res = new ArrayList<>();
Set<Intege... | 517Non-transitive dice | 9java | 8gt06 |
int main()
{
int i;
for(i=1; i <= 33; i++)
printf(, i, i, i);
return 0;
} | 519Non-decimal radices/Output | 5c | uorv4 |
reversalGame <- function(){
cat("Welcome to the Number Reversal Game! \n")
cat("Sort the numbers into ascending order by repeatedly \n",
"reversing the first n digits, where you specify n. \n \n", sep="")
data <- sample(1:9, 9)
while (all(data == 1:9)){
cat("What were the chances...? \n")
data... | 514Number reversal game | 13r | fkldc |
fun fourFaceCombos(): List<Array<Int>> {
val res = mutableListOf<Array<Int>>()
val found = mutableSetOf<Int>()
for (i in 1..4) {
for (j in 1..4) {
for (k in 1..4) {
for (l in 1..4) {
val c = arrayOf(i, j, k, l)
c.sort()
... | 517Non-transitive dice | 11kotlin | w2oek |
null | 516Nonoblock | 11kotlin | uohvc |
(Integer/toBinaryString 25)
(Integer/toOctalString 25)
(Integer/toHexString 25)
(dotimes [i 20]
(println (Integer/toHexString i))) | 519Non-decimal radices/Output | 6clojure | 7tbr0 |
TENS = [None, None, , , ,
, , , , ]
SMALL = [, , , , , ,
, , , , , ,
, , , ,
, , , ]
HUGE = [None, None] + [h +
for h in (, , , , , ,
, , , )]
def nonzero(c, n, connect=''):
return if n == 0 else connect + c + spell_int... | 515Number names | 3python | 04zsq |
local examples = {
{5, {2, 1}},
{5, {}},
{10, {8}},
{15, {2, 3, 2, 3}},
{5, {2, 3}},
}
function deep (blocks, iBlock, freedom, str)
if iBlock == #blocks then | 516Nonoblock | 1lua | 5iku6 |
use strict;
use warnings;
sub fourFaceCombs {
my %found = ();
my @res = ();
for (my $i = 1; $i <= 4; $i++) {
for (my $j = 1; $j <= 4; $j++) {
for (my $k = 1; $k <= 4; $k++) {
for (my $l = 1; $l <= 4; $l++) {
my @c = sort ($i, $j, $k, $l);
... | 517Non-transitive dice | 2perl | lsgc5 |
ones <- c("", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen")
tens <- c("ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety")
mags <- c("", "tho... | 515Number names | 13r | w2ne5 |
from collections import namedtuple
from itertools import permutations, product
from functools import lru_cache
Die = namedtuple('Die', 'name, faces')
@lru_cache(maxsize=None)
def cmpd(die1, die2):
'compares two die returning 1, -1 or 0 for >, < =='
tot = [0, 0, 0]
for d1, d2 in product(die1.fac... | 517Non-transitive dice | 3python | 20rlz |
int main(int c, char **v)
{
unsigned int n = 1 << (c - 1), i = n, j, k;
assert(n);
while (i--) {
if (!(i & (i + (i & -(int)i))))
continue;
for (j = n, k = 1; j >>= 1; k++)
if (i & j) printf(, v[k]);
putchar('\n');
}
return 0;
} | 520Non-continuous subsequences | 5c | gdj45 |
package main
import (
"fmt"
"math/big"
"strconv"
)
func main() { | 518Non-decimal radices/Input | 0go | s5nqa |
findNonTrans <- function()
{
diceSet <- unique(t(apply(expand.grid(1:4, 1:4, 1:4, 1:4), 1, sort)))
winningDice <- function(X, Y)
{
comparisonTable <- data.frame(X = rep(X, each = length(X)), Y = rep(Y, times = length(Y)))
rowWinner <- ifelse(comparisonTable["X"] > comparisonTable["Y"], "X",
... | 517Non-transitive dice | 13r | mwuy4 |
Prelude> read "123459" :: Integer
123459
Prelude> read "0xabcf123" :: Integer
180154659
Prelude> read "0o7651" :: Integer
4009 | 518Non-decimal radices/Input | 8haskell | 9xumo |
use strict;
use warnings;
while( <DATA> )
{
print "\n$_", tr/\n/=/cr;
my ($cells, @blocks) = split;
my $letter = 'A';
$_ = join '.', map { $letter++ x $_ } @blocks;
$cells < length and print("no solution\n"), next;
$_ .= '.' x ($cells - length) . "\n";
1 while print, s/^(\.*)\b(.*?)\b(\w+)\.\B/$2$1.$3/... | 516Nonoblock | 2perl | 8gz0w |
ary = (1..9).to_a
ary.shuffle! while ary == ary.sort
score = 0
until ary == ary.sort
print
num = gets.to_i
ary[0, num] = ary[0, num].reverse
score += 1
end
p ary
puts | 514Number reversal game | 14ruby | mwgyj |
package main
import (
"fmt"
"strings"
)
type BitSet []bool
func (bs BitSet) and(other BitSet) {
for i := range bs {
if bs[i] && other[i] {
bs[i] = true
} else {
bs[i] = false
}
}
}
func (bs BitSet) or(other BitSet) {
for i := range bs {
if ... | 521Nonogram solver | 0go | qu0xz |
(use '[clojure.contrib.combinatorics :only (subsets)])
(defn of-min-length [min-length]
(fn [s] (>= (count s) min-length)))
(defn runs [c l]
(map (partial take l) (take-while not-empty (iterate rest c))))
(defn is-subseq? [c sub]
(some identity (map = (runs c (count sub)) (repeat sub))))
(defn non-continuous-... | 520Non-continuous subsequences | 6clojure | k61hs |
Scanner sc = new Scanner(System.in); | 518Non-decimal radices/Input | 9java | tbmf9 |
+"0123459"; | 518Non-decimal radices/Input | 10javascript | mwvyv |
package main
import (
"fmt"
"math/big"
"strconv"
)
func main() { | 519Non-decimal radices/Output | 0go | 04nsk |
{{index .P n}} | 522Nested templated data | 0go | rf7gm |
data Template a = Val a | List [Template a]
deriving ( Show
, Functor
, Foldable
, Traversable ) | 522Nested templated data | 8haskell | 048s7 |
import java.util.*;
import static java.util.Arrays.*;
import static java.util.stream.Collectors.toList;
public class NonogramSolver {
static String[] p1 = {"C BA CB BB F AE F A B", "AB CA AE GA E C D C"};
static String[] p2 = {"F CAC ACAC CN AAA AABB EBB EAA ECCC HCCC", "D D AE "
+ "CD AE A DA BBB CC... | 521Nonogram solver | 9java | fkzdv |
def nonoblocks(blocks, cells):
if not blocks or blocks[0] == 0:
yield [(0, 0)]
else:
assert sum(blocks) + len(blocks)-1 <= cells, \
'Those blocks will not fit in those cells'
blength, brest = blocks[0], blocks[1:]
minspace4rest = sum(1+b for b in brest)
... | 516Nonoblock | 3python | or381 |
null | 518Non-decimal radices/Input | 11kotlin | ort8z |
import Text.Printf
main :: IO ()
main = mapM_ f [0..33] where
f :: Int -> IO ()
f n = printf "%3o%2d%2X\n" n n n | 519Non-decimal radices/Output | 8haskell | cqu94 |
SMALL = %w(zero one two three four five six seven eight nine ten
eleven twelve thirteen fourteen fifteen sixteen seventeen
eighteen nineteen)
TENS = %w(wrong wrong twenty thirty forty fifty sixty seventy
eighty ninety)
BIG = [nil, ] +
%w( m b tr quadr quint sext sept oct non dec)... | 515Number names | 14ruby | or68v |
use rand::prelude::*;
use std::io::stdin;
fn is_sorted(seq: &[impl PartialOrd]) -> bool {
if seq.len() < 2 {
return true;
} | 514Number reversal game | 15rust | 9xrmm |
void swap(char* str, int i, int j) {
char c = str[i];
str[i] = str[j];
str[j] = c;
}
void reverse(char* str, int i, int j) {
for (; i < j; ++i, --j)
swap(str, i, j);
}
bool next_permutation(char* str) {
int len = strlen(str);
if (len < 2)
return false;
for (int i = len - 1;... | 523Next highest int from digits | 5c | jzj70 |
print( tonumber("123") )
print( tonumber("a5b0", 16) )
print( tonumber("011101", 2) )
print( tonumber("za3r", 36) ) | 518Non-decimal radices/Input | 1lua | i7zot |
use std::io::{self, Write, stdout};
const SMALL: &[&str] = &[
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
"nineteen",
];
const TENS: &[&str] = &[
"PANIC", "PANIC", "twe... | 515Number names | 15rust | i7yod |
object NumberReversalGame extends App {
def play(n: Int, cur: List[Int], goal: List[Int]) {
readLine(s"""$n. ${cur mkString " "} How many to flip? """) match {
case null => println
case s => scala.util.Try(s.toInt) match {
case scala.util.Success(i) if i > 0 && i <= cur.length =>
(c... | 514Number reversal game | 16scala | 20hlb |
int playerTurn(int numTokens, int take);
int computerTurn(int numTokens);
int main(void)
{
printf();
int Tokens = 12;
while(Tokens > 0)
{
printf();
int uin;
scanf(, &uin);
int nextTokens = playerTurn(Tokens, uin);
if (nextTokens == Tokens)
{
continue;
}
Tokens = nextTokens;
Tokens = com... | 524Nim game | 5c | a9p11 |
null | 521Nonogram solver | 11kotlin | 8gi0q |
public static void main(String args[]){
for(int a= 0;a < 33;a++){
System.out.println(Integer.toBinaryString(a));
System.out.println(Integer.toOctalString(a));
System.out.println(Integer.toHexString(a)); | 519Non-decimal radices/Output | 9java | zpmtq |
import scala.annotation.tailrec
import scala.collection.parallel.ParSeq
trait LongHand {
def longhand(numeral: BigInt,
showAnd: Boolean = false,
zeroString: String = "zero",
showHyphen: Boolean = true): String = {
val condAndString = if (showAnd) "and " else ""
... | 515Number names | 16scala | fkcd4 |
typedef struct{
char str[30];
}item;
item* makeList(char* separator){
int counter = 0,i;
item* list = (item*)malloc(3*sizeof(item));
item makeItem(){
item holder;
char names[5][10] = {,,,,};
sprintf(holder.str,,++counter,separator,names[counter]);
return holder;
}
for(i=0;i<3;i++)
list[i] = makeIt... | 525Nested function | 5c | ir0o2 |
sub fulfill {
my @payloads;
push @payloads, 'Payload
my @result;
push @result, ref $_ eq 'ARRAY' ? [@payloads[@$_]] : @payloads[$_] for @{@_[0]};
return [@result];
}
sub formatted {
my $result;
$result .= ref $_ eq 'ARRAY' ? '[ "'. join('", "', @$_) . '" ], ' : qq{"$_"} for @{@_[0... | 522Nested templated data | 2perl | zp3tb |
var bases = [2, 8, 10, 16, 24];
for (var n = 0; n <= 33; n++) {
var row = [];
for (var i = 0; i < bases.length; i++)
row.push( n.toString(bases[i]) );
print(row.join(', '));
} | 519Non-decimal radices/Output | 10javascript | 9xvml |
def nonoblocks(cell, blocks)
raise 'Those blocks will not fit in those cells' if cell < blocks.inject(0,:+) + blocks.size - 1
nblock(cell, blocks, '', [])
end
def nblock(cell, blocks, position, result)
if cell <= 0
result << position[0..cell-1]
elsif blocks.empty? or blocks[0].zero?
result << position ... | 516Nonoblock | 14ruby | njyit |
null | 519Non-decimal radices/Output | 11kotlin | i7to4 |
package main
import (
"fmt"
"sort"
)
func permute(s string) []string {
var res []string
if len(s) == 0 {
return res
}
b := []byte(s)
var rc func(int) | 523Next highest int from digits | 0go | fkfd0 |
(defn make-list [separator]
(let [x (atom 0)]
(letfn [(make-item [item] (swap! x inc) (println (format "%s%s%s" @x separator item)))]
(make-item "first")
(make-item "second")
(make-item "third"))))
(make-list ". ") | 525Nested function | 6clojure | zbdtj |
int main(){
int i,times,hour,min,sec,min1,min2;
time_t t;
struct tm* currentTime;
while(1){
time(&t);
currentTime = localtime(&t);
hour = currentTime->tm_hour;
min = currentTime->tm_min;
sec = currentTime->tm_sec;
hour = 12;
min = 0;
sec = 0;
if((min==0 || min==30) && sec==0)
times = ((hou... | 526Nautical bell | 5c | v092o |
from pprint import pprint as pp
class Template():
def __init__(self, structure):
self.structure = structure
self.used_payloads, self.missed_payloads = [], []
def inject_payload(self, id2data):
def _inject_payload(substruct, i2d, used, missed):
used.extend(i2d[x] for x in s... | 522Nested templated data | 3python | 316zc |
struct Nonoblock {
width: usize,
config: Vec<usize>,
spaces: Vec<usize>,
}
impl Nonoblock {
pub fn new(width: usize, config: Vec<usize>) -> Nonoblock {
Nonoblock {
width: width,
config: config,
spaces: Vec::new(),
}
}
pub fn solve(&mut self) -> Vec<Vec<i32>> {
let mut output:... | 516Nonoblock | 15rust | dhmny |
for i = 1, 33 do
print( string.format( "%o \t%d \t%x", i, i, i ) )
end | 519Non-decimal radices/Output | 1lua | njzi8 |
const char DIGITS[] = ;
const int DIGITS_LEN = 64;
void encodeNegativeBase(long n, long base, char *out) {
char *ptr = out;
if (base > -1 || base < -62) {
out = ;
return;
}
if (n == 0) {
out = ;
return;
}
while (n != 0) {
long rem... | 527Negative base numbers | 5c | 9wzm1 |
import Data.List (nub, permutations, sort)
digitShuffleSuccessors :: Integer -> [Integer]
digitShuffleSuccessors n =
(fmap . (+) <*> (nub . sort . concatMap go . permutations . show)) n
where
go ds
| 0 >= delta = []
| otherwise = [delta]
where
delta = (read ds :: Integer) - n
main :... | 523Next highest int from digits | 8haskell | 4n45s |
fill_template <- function(x, template, prefix = "Payload
for (i in seq_along(template)) {
temp_slice <- template[[i]]
if (is.list(temp_slice)) {
template[[i]] <- fill_template(x, temp_slice, prefix)
} else {
temp_slice <- paste0(prefix, temp_slice)
template[[i]] <- x[match(temp_slice, x)... | 522Nested templated data | 13r | dhfnt |
use strict;
use warnings;
my $file = 'nonogram_problems.txt';
open my $fd, '<', $file or die "$! opening $file";
while(my $row = <$fd> )
{
$row =~ /\S/ or next;
my $column = <$fd>;
my @rpats = makepatterns($row);
my @cpats = makepatterns($column);
my @rows = ( '.' x @cpats ) x @rpats;
for( my $prev = ''... | 521Nonogram solver | 2perl | 4nr5d |
import Foundation
func nonoblock(cells: Int, blocks: [Int]) {
print("\(cells) cells and blocks \(blocks):")
let totalBlockSize = blocks.reduce(0, +)
if cells < totalBlockSize + blocks.count - 1 {
print("no solution")
return
}
func solve(cells: Int, index: Int, totalBlockSize: Int, ... | 516Nonoblock | 17swift | i76o0 |
package main
import "fmt"
const ( | 520Non-continuous subsequences | 0go | i7fog |
char *to_base(int64_t num, int base)
{
char *tbl = ;
char buf[66] = {'\0'};
char *out;
uint64_t n;
int i, len = 0, neg = 0;
if (base > 36) {
fprintf(stderr, , base);
return 0;
}
n = ((neg = num < 0)) ? (~num) + 1 : num;
do { buf[len++] = tbl[n % base]; } while(n /= base);
out = malloc... | 528Non-decimal radices/Convert | 5c | mefys |
my $dec = "0123459";
my $hex_noprefix = "abcf123";
my $hex_withprefix = "0xabcf123";
my $oct_noprefix = "7651";
my $oct_withprefix = "07651";
my $bin_withprefix = "0b101011001";
print 0 + $dec, "\n";
print hex($hex_noprefix), "\n";
print hex($hex_withprefix), "\n";
print oct($hex_withprefix), "\n";
prin... | 518Non-decimal radices/Input | 2perl | gdk4e |
import java.math.BigInteger;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class NextHighestIntFromDigits {
public static void main(String[] args) {
for ( String s : new String[] {"0", ... | 523Next highest int from digits | 9java | cqc9h |
action p x = if p x then succ x else x
fenceM p q s [] = guard (q s) >> return []
fenceM p q s (x:xs) = do
(f,g) <- p
ys <- fenceM p q (g s) xs
return $ f x ys
ncsubseq = fenceM [((:), action even), (flip const, action odd)] (>= 3) 0 | 520Non-continuous subsequences | 8haskell | v842k |
<?php
echo +, ;
echo intval(), ;
echo hexdec(), ;
echo octdec(), ;
echo bindec(), ;
?> | 518Non-decimal radices/Input | 12php | nj3ig |
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func showTokens(tokens int) {
fmt.Println("Tokens remaining", tokens, "\n")
}
func main() {
tokens := 12
scanner := bufio.NewScanner(os.Stdin)
for {
showTokens(tokens)
fmt.Print(" How many tokens 1, 2 or 3? ")
... | 524Nim game | 0go | me6yi |
const compose = (...fn) => (...x) => fn.reduce((a, b) => c => a(b(c)))(...x);
const toString = x => x + '';
const reverse = x => Array.from(x).reduce((p, c) => [c, ...p], []);
const minBiggerThanN = (arr, n) => arr.filter(e => e > n).sort()[0];
const remEl = (arr, e) => {
const r = arr.indexOf(e);
return arr.filter... | 523Next highest int from digits | 10javascript | 5i5ur |
package main
import (
"fmt"
"strings"
"time"
)
func main() {
watches := []string{
"First", "Middle", "Morning", "Forenoon",
"Afternoon", "Dog", "First",
}
for {
t := time.Now()
h := t.Hour()
m := t.Minute()
s := t.Second()
if (m == 0 || m... | 526Nautical bell | 0go | sueqa |
public class NonContinuousSubsequences {
public static void main(String args[]) {
seqR("1234", "", 0, 0);
}
private static void seqR(String s, String c, int i, int added) {
if (i == s.length()) {
if (c.trim().length() > added)
System.out.println(c);
} el... | 520Non-continuous subsequences | 9java | yec6g |
SELECT val, to_char(to_date(val,'j'),'jsp') name
FROM
(
SELECT
round( dbms_random.VALUE(1, 5373484)) val
FROM dual
CONNECT BY level <= 5
);
SELECT to_char(to_date(5373485,'j'),'jsp') FROM dual; | 515Number names | 19sql | 31vz1 |
import Data.Char (isDigit, digitToInt)
import System.IO
prompt :: String
prompt = "How many do you take? 1, 2 or 3? "
getPlayerSelection :: IO Int
getPlayerSelection = do
hSetBuffering stdin NoBuffering
c <- getChar
putChar '\n'
if isDigit c && digitToInt c <= 3 then
pure (digitToInt c)
else do
pu... | 524Nim game | 8haskell | k3jh0 |
extern void*stdin;main(){ char*p = ,a[300],b[300];sprintf(a,p,34,p,34);fgets(b,300,stdin);putchar(48+!strcmp(a,b)); } | 529Narcissist | 5c | 4i95t |
import Control.Concurrent
import Control.Monad
import Data.Time
import Text.Printf
type Microsecond = Int
type Scheduler = TimeOfDay -> Microsecond
getTime :: TimeZone -> IO TimeOfDay
getTime tz = do
t <- getCurrentTime
return $ localTimeOfDay $ utcToLocalTime tz t
getGMTTime = getTime utc
getLocalTime... | 526Nautical bell | 8haskell | 9w3mo |
function non_continuous_subsequences(ary) {
var non_continuous = new Array();
for (var i = 0; i < ary.length; i++) {
if (! is_array_continuous(ary[i])) {
non_continuous.push(ary[i]);
}
}
return non_continuous;
}
function is_array_continuous(ary) {
if (ary.length < 2)
... | 520Non-continuous subsequences | 10javascript | 205lr |
foreach my $n (0..33) {
printf "%6b%3o%2d%2X\n", $n, $n, $n, $n;
} | 519Non-decimal radices/Output | 2perl | rfkgd |
extension Int {
private static let bigNames = [
1_000: "thousand",
1_000_000: "million",
1_000_000_000: "billion",
1_000_000_000_000: "trillion",
1_000_000_000_000_000: "quadrillion",
1_000_000_000_000_000_000: "quintillion"
]
private static let names = [
1: "one",
2: "two",
3... | 515Number names | 17swift | 8g30v |
import java.math.BigInteger
import java.text.NumberFormat
fun main() {
for (s in arrayOf(
"0",
"9",
"12",
"21",
"12453",
"738440",
"45072010",
"95322020",
"9589776899767587796600",
"3345333"
)) {
println("${format(s)} -> ${... | 523Next highest int from digits | 11kotlin | 313z5 |
package main
import "fmt"
func makeList(separator string) string {
counter := 1
makeItem := func(item string) string {
result := fmt.Sprintf("%d%s%s\n", counter, separator, item)
counter += 1
return result
}
return makeItem("first") + makeItem("second") + makeItem("third")
}
... | 525Nested function | 0go | gnu4n |
import Control.Monad.ST
import Data.STRef
makeList :: String -> String
makeList separator = concat $ runST $ do
counter <- newSTRef 1
let makeItem item = do
x <- readSTRef counter
let result = show x ++ separator ++ item ++ "\n"
modifySTRef counter (+ 1)
return result
mapM makeIte... | 525Nested function | 8haskell | suwqk |
from itertools import izip
def gen_row(w, s):
def gen_seg(o, sp):
if not o:
return [[2] * sp]
return [[2] * x + o[0] + tail
for x in xrange(1, sp - len(o) + 2)
for tail in gen_seg(o[1:], sp - x)]
return [x[1:] for x in gen_seg([[1] * i for i in ... | 521Nonogram solver | 3python | gd74h |
>>> text = '100'
>>> for base in range(2,21):
print (
% (text, base, int(text, base)))
String '100' in base 2 is 4 in base 10
String '100' in base 3 is 9 in base 10
String '100' in base 4 is 16 in base 10
String '100' in base 5 is 25 in base 10
String '100' in base 6 is 36 in base 10
String '100' ... | 518Non-decimal radices/Input | 3python | rfbgq |
<?php
foreach (range(0, 33) as $n) {
echo decbin($n), , decoct($n), , $n, , dechex($n), ;
}
?> | 519Non-decimal radices/Output | 12php | dh3n8 |
package main
import (
"fmt"
"log"
"strings"
)
const digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
func reverse(bs []byte) []byte {
for i, j := 0, len(bs)-1; i < len(bs)/2; i, j = i+1, j-1 {
bs[i], bs[j] = bs[j], bs[i]
}
return bs
}
func encodeNegBase(n, b ... | 527Negative base numbers | 0go | ecka6 |
import java.util.Scanner;
public class NimGame {
public static void main(String[] args) {
runGame(12);
}
private static void runGame(int tokens) {
System.out.printf("Nim game.%n%n");
Scanner in = new Scanner(System.in);;
do {
boolean humanInputOk ... | 524Nim game | 9java | 4iu58 |
package main; import "os"; import "fmt"; import "bytes"; import "io/ioutil"; func main() {ios := "os"; ifmt := "fmt"; ibytes := "bytes"; iioutil := "io/ioutil"; zero := "Reject"; one := "Accept"; x := "package main; import%q; import%q; import%q; import%q; func main() {ios:=%q; ifmt:=%q; ibytes:=%q; iioutil:=%q; zero:=%... | 529Narcissist | 0go | oge8q |
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
public class NestedFunctionsDemo {
static String makeList(String separator) {
AtomicInteger counter = new AtomicInteger(1);
Function<String, String> makeItem = item -> counter.getAndIncrement() + separator + ite... | 525Nested function | 9java | 1mkp2 |
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
public class NauticalBell extends Thread {
public static void main(String[] args) {
NauticalBell bells = new NauticalBell();
bells.setDaemon(true);
bells.start();
try {
bells.join... | 526Nautical bell | 9java | tkif9 |
null | 520Non-continuous subsequences | 11kotlin | fk3do |
as.numeric("20")
as.numeric("0x20")
as.hexmode(as.numeric("32"))
as.octmode(as.numeric("20")) | 518Non-decimal radices/Input | 13r | uo7vx |
import Data.Char (chr, ord)
import Numeric (showIntAtBase)
quotRemP :: Integral a => a -> a -> (a, a)
quotRemP n d = let (q, r) = quotRem n d
in if r < 0 then (q+1, r-d) else (q, r)
toNegBase :: Integral a => a -> a -> a
toNegBase b n = let (q, r) = quotRemP n b
in if q == 0 then r e... | 527Negative base numbers | 8haskell | 3pnzj |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.