code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
if (condition)
{
}
if (condition)
{
}
else if (condition2)
{
}
else
{
} | 1,023Conditional structures | 5c | u7tv4 |
package main
import (
"bufio"
"fmt"
"log"
"os"
)
type TokenType int
const (
tkEOI TokenType = iota
tkMul
tkDiv
tkMod
tkAdd
tkSub
tkNegate
tkNot
tkLss
tkLeq
tkGtr
tkGeq
tkEq
tkNeq
tkAssign
tkAnd
tkOr
tkIf
tkElse
tkWhile
... | 1,019Compiler/lexical analyzer | 0go | 9ufmt |
package main
import "fmt"
func combrep(n int, lst []string) [][]string {
if n == 0 {
return [][]string{nil}
}
if len(lst) == 0 {
return nil
}
r := combrep(n, lst[1:])
for _, x := range combrep(n-1, lst) {
r = append(r, append(x, lst[0]))
}
return r
}
func main(... | 1,021Combinations with repetitions | 0go | 1q4p5 |
import Control.Applicative hiding (many, some)
import Control.Monad.State.Lazy
import Control.Monad.Trans.Maybe (MaybeT, runMaybeT)
import Data.Char (isAsciiLower, isAsciiUpper, isDigit, ord)
import Data.Foldable (asum)
import Data.Functor (($>))
import Data.Text (Text)
import qualified Data.Text as T
import Prelude hi... | 1,019Compiler/lexical analyzer | 8haskell | bw4k2 |
null | 1,017Compare a list of strings | 11kotlin | gk24d |
combsWithRep :: Int -> [a] -> [[a]]
combsWithRep 0 _ = [[]]
combsWithRep _ [] = []
combsWithRep k xxs@(x:xs) =
(x:) <$> combsWithRep (k - 1) xxs ++ combsWithRep k xs
binomial n m = f n `div` f (n - m) `div` f m
where
f n =
if n == 0
then 1
else n * f (n - 1)
countCombsWithRep :: Int -> [... | 1,021Combinations with repetitions | 8haskell | tmqf7 |
use strict;
use warnings;
showoff( "Permutations", \&P, "P", 1 .. 12 );
showoff( "Combinations", \&C, "C", map $_*10, 1..6 );
showoff( "Permutations", \&P_big, "P", 5, 50, 500, 1000, 5000, 15000 );
showoff( "Combinations", \&C_big, "C", map $_*100, 1..10 );
sub showoff {
my ($text, $code, $fname, @n) = @_;
print "\... | 1,018Combinations and permutations | 2perl | 3cizs |
null | 1,024Comments | 5c | gk345 |
function identical(t_str)
_, fst = next(t_str)
if fst then
for _, i in pairs(t_str) do
if i ~= fst then return false end
end
end
return true
end
function ascending(t_str)
prev = false
for _, i in ipairs(t_str) do
if prev and prev >= i then return false end
... | 1,017Compare a list of strings | 1lua | rbvga |
import com.objectwave.utility.*;
public class MultiCombinationsTester {
public MultiCombinationsTester() throws CombinatoricException {
Object[] objects = {"iced", "jam", "plain"}; | 1,021Combinations with repetitions | 9java | 8fp06 |
from __future__ import print_function
from scipy.misc import factorial as fact
from scipy.misc import comb
def perm(N, k, exact=0):
return comb(N, k, exact) * fact(k, exact)
exact=True
print('Sample Perms 1..12')
for N in range(1, 13):
k = max(N-2, 1)
print('%iP%i ='% (N, k), perm(N, k, exact), end=', ' ... | 1,018Combinations and permutations | 3python | 6ln3w |
null | 1,019Compiler/lexical analyzer | 9java | gkc4m |
(if (= 1 1):yes:no)
(if (= 1 2):yes:no)
(if (= 1 2):yes) | 1,023Conditional structures | 6clojure | 7pmr0 |
<html><head><title>Donuts</title></head>
<body><pre id='x'></pre><script type="application/javascript">
function disp(x) {
var e = document.createTextNode(x + '\n');
document.getElementById('x').appendChild(e);
}
function pick(n, got, pos, from, show) {
var cnt = 0;
if (got.length == n) {
if (show) disp(got.join... | 1,021Combinations with repetitions | 10javascript | fyxdg |
perm <- function(n, k) choose(n, k) * factorial(k)
print(perm(seq(from = 3, to = 12, by = 3), seq(from = 2, to = 8, by = 2)))
print(choose(seq(from = 10, to = 60, by = 10), seq(from = 3, to = 18, by = 3)))
print(perm(seq(from = 1500, to = 15000, by = 1500), seq(from = 55, to = 100, by = 5)))
print(choose(seq(from = 100... | 1,018Combinations and permutations | 13r | fy0dc |
const TokenType = {
Keyword_if: 1, Keyword_else: 2, Keyword_print: 3, Keyword_putc: 4, Keyword_while: 5,
Op_add: 6, Op_and: 7, Op_assign: 8, Op_divide: 9, Op_equal: 10, Op_greater: 11,
Op_greaterequal: 12, Op_less: 13, Op_Lessequal: 14, Op_mod: 15, Op_multiply: 16, Op_not: 17,
Op_notequal: 18, Op_or: 19... | 1,019Compiler/lexical analyzer | 10javascript | ke5hq |
(defn foo []
123) | 1,024Comments | 6clojure | kechs |
package main
import (
"fmt"
"os"
)
func main() {
for i, x := range os.Args[1:] {
fmt.Printf("the argument #%d is%s\n", i, x)
}
} | 1,020Command-line arguments | 0go | l4tcw |
println args | 1,020Command-line arguments | 7groovy | 6lo3o |
package main
import (
"bytes"
"fmt"
"math/rand"
"time"
)
type Field struct {
s [][]bool
w, h int
}
func NewField(w, h int) Field {
s := make([][]bool, h)
for i := range s {
s[i] = make([]bool, w)
}
return Field{s: s, w: w, h: h}
}
func (f Field) Set(x, y int, b bool) {
f.s[y][x] = b
}
func (f Field... | 1,014Conway's Game of Life | 0go | xoewf |
null | 1,021Combinations with repetitions | 11kotlin | w87ek |
null | 1,019Compiler/lexical analyzer | 11kotlin | 2g3li |
import System
main = getArgs >>= print | 1,020Command-line arguments | 8haskell | 1qgps |
class GameOfLife {
int generations
int dimensions
def board
GameOfLife(generations = 5, dimensions = 5) {
this.generations = generations
this.dimensions = dimensions
this.board = createBlinkerBoard()
}
static def createBlinkerBoard() {
[
[].withDefault{0},
[0,0,1].withDefault{0},
[0,0,1].withD... | 1,014Conway's Game of Life | 7groovy | pxkbo |
include Math
class Integer
def permutation(k)
(self-k+1 .. self).inject(:*)
end
def combination(k)
self.permutation(k) / (1 .. k).inject(:*)
end
def big_permutation(k)
exp( lgamma_plus(self) - lgamma_plus(self -k))
end
def big_combination(k)
exp( lgamma_plus(self) - lgamma_plus(self ... | 1,018Combinations and permutations | 14ruby | mvfyj |
null | 1,019Compiler/lexical analyzer | 1lua | vr62x |
import Data.Array.Unboxed
type Grid = UArray (Int,Int) Bool
life :: Int -> Int -> Grid -> Grid
life w h old =
listArray b (map f (range b))
where b@((y1,x1),(y2,x2)) = bounds old
f (y, x) = ( c && (n == 2 || n == 3) ) || ( not c && n == 3 )
where c = get x y
n = count [get (... | 1,014Conway's Game of Life | 8haskell | y2366 |
function GenerateCombinations(tList, nMaxElements, tOutput, nStartIndex, nChosen, tCurrentCombination)
if not nStartIndex then
nStartIndex = 1
end
if not nChosen then
nChosen = 0
end
if not tOutput then
tOutput = {}
end
if not tCurrentCombination then
tCurrentCombination = {}
end
if nChosen == nMaxEle... | 1,021Combinations with repetitions | 1lua | xojwz |
null | 1,024Comments | 18dart | l4ict |
use List::Util 1.33 qw(all);
all { $strings[0] eq $strings[$_] } 1..$
all { $strings[$_-1] lt $strings[$_] } 1..$ | 1,017Compare a list of strings | 2perl | n3siw |
public class Arguments {
public static void main(String[] args) {
System.out.println("There are " + args.length + " arguments given.");
for(int i = 0; i < args.length; i++)
System.out.println("The argument #" + (i+1) + " is " + args[i] + " and is at index " + i);
}
} | 1,020Command-line arguments | 9java | 7plrj |
process.argv.forEach((val, index) => {
console.log(`${index}: ${val}`);
}); | 1,020Command-line arguments | 10javascript | px4b7 |
import BigInt
func permutations(n: Int, k: Int) -> BigInt {
let l = n - k + 1
guard l <= n else {
return 1
}
return (l...n).reduce(BigInt(1), { $0 * BigInt($1) })
}
func combinations(n: Int, k: Int) -> BigInt {
let fact = {() -> BigInt in
guard k > 1 else {
return 1
}
return (2...k)... | 1,018Combinations and permutations | 17swift | y2d6e |
package main
import (
"fmt"
"strings"
)
func q(s []string) string {
switch len(s) {
case 0:
return "{}"
case 1:
return "{" + s[0] + "}"
case 2:
return "{" + s[0] + " and " + s[1] + "}"
default:
return "{" +
strings.Join(s[:len(s)-1], ", ") +
... | 1,022Comma quibbling | 0go | snhqa |
fun main(args: Array<String>) {
println("There are " + args.size + " arguments given.")
args.forEachIndexed { i, a -> println("The argument #${i+1} is $a and is at index $i") }
} | 1,020Command-line arguments | 11kotlin | u76vc |
def commaQuibbling = { it.size() < 2 ? "{${it.join(', ')}}": "{${it[0..-2].join(', ')} and ${it[-1]}}" } | 1,022Comma quibbling | 7groovy | as41p |
quibble ws = "{" ++ quibbles ws ++ "}"
where quibbles [] = ""
quibbles [a] = a
quibbles [a,b] = a ++ " and " ++ b
quibbles (a:bs) = a ++ ", " ++ quibbles bs
main = mapM_ (putStrLn . quibble) $
[[], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H"]] ++
(map words ["One two three four", "M... | 1,022Comma quibbling | 8haskell | 9uimo |
sub p { $_[0] ? map p($_[0] - 1, [@{$_[1]}, $_[$_]], @_[$_ .. $
sub f { $_[0] ? $_[0] * f($_[0] - 1) : 1 }
sub pn{ f($_[0] + $_[1] - 1) / f($_[0]) / f($_[1] - 1) }
for (p(2, [], qw(iced jam plain))) {
print "@$_\n";
}
printf "\nThere are%d ways to pick 7 out of 10\n", pn(7,10); | 1,021Combinations with repetitions | 2perl | l4fc5 |
public class GameOfLife{
public static void main(String[] args){
String[] dish= {
"_#_",
"_#_",
"_#_",};
int gens= 3;
for(int i= 0;i < gens;i++){
System.out.println("Generation " + i + ":");
print(dish);
dish= life(dish);
}
}
public static String[] life(String[] dish){
String[] newGen... | 1,014Conway's Game of Life | 9java | d6in9 |
public class Quibbler {
public static String quibble(String[] words) {
String qText = "{";
for(int wIndex = 0; wIndex < words.length; wIndex++) {
qText += words[wIndex] + (wIndex == words.length-1 ? "" :
wIndex == words.length-2 ? " and " :
", ";
}
qText += "}";
return qText;
}
public... | 1,022Comma quibbling | 9java | tmxf9 |
<?php
function combos($arr, $k) {
if ($k == 0) {
return array(array());
}
if (count($arr) == 0) {
return array();
}
$head = $arr[0];
$combos = array();
$subcombos = combos($arr, $k-1);
foreach ($subcombos as $subcombo) {
array_unshift($subcombo, $head);
$comb... | 1,021Combinations with repetitions | 12php | qihx3 |
use strict;
use warnings;
no warnings 'once';
my @tokens = (
['Op_multiply' , '*' , ],
['Op_divide' , '/' , ],
['Op_mod' , '%' , ],
['Op_add' , '+' , ... | 1,019Compiler/lexical analyzer | 2perl | snpq3 |
print( "Program name:", arg[0] )
print "Arguments:"
for i = 1, #arg do
print( i," ", arg[i] )
end | 1,020Command-line arguments | 1lua | 5jyu6 |
function GameOfLife () {
this.init = function (turns,width,height) {
this.board = new Array(height);
for (var x = 0; x < height; x++) {
this.board[x] = new Array(width);
for (var y = 0; y < width; y++) {
this.board[x][y] = Math.round(Math.random());
}
}
this.turns = turns;
}
this.nextGen = fun... | 1,014Conway's Game of Life | 10javascript | 6lz38 |
function quibble(words) {
return "{" +
words.slice(0, words.length-1).join(",") +
(words.length > 1 ? " and " : "") +
(words[words.length-1] || '') +
"}";
}
[[], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H"]].forEach(
function(s) {
console.log(quibble(s));
}
); | 1,022Comma quibbling | 10javascript | mvoyv |
all(a == nexta for a, nexta in zip(strings, strings[1:]))
all(a < nexta for a, nexta in zip(strings, strings[1:]))
len(set(strings)) == 1
sorted(strings, reverse=True) == strings | 1,017Compare a list of strings | 3python | d60n1 |
chunks <- function (compare, xs) {
starts = which(c(T,!compare(head(xs, -1), xs[-1]), T))
lapply(seq(1,length(starts)-1),
function(i) xs[starts[i]:(starts[i+1]-1)] )
} | 1,017Compare a list of strings | 13r | 8fw0x |
null | 1,022Comma quibbling | 11kotlin | otp8z |
>>> from itertools import combinations_with_replacement
>>> n, k = 'iced jam plain'.split(), 2
>>> list(combinations_with_replacement(n,k))
[('iced', 'iced'), ('iced', 'jam'), ('iced', 'plain'), ('jam', 'jam'), ('jam', 'plain'), ('plain', 'plain')]
>>>
>>> len(list(combinations_with_replacement(range(10), 3)))
220
>>> | 1,021Combinations with repetitions | 3python | 2gtlz |
from __future__ import print_function
import sys
tk_EOI, tk_Mul, tk_Div, tk_Mod, tk_Add, tk_Sub, tk_Negate, tk_Not, tk_Lss, tk_Leq, tk_Gtr, \
tk_Geq, tk_Eq, tk_Neq, tk_Assign, tk_And, tk_Or, tk_If, tk_Else, tk_While, tk_Print, \
tk_Putc, tk_Lparen, tk_Rparen, tk_Lbrace, tk_Rbrace, tk_Semi, tk_Comma, tk_Ident, ... | 1,019Compiler/lexical analyzer | 3python | 0d1sq |
library(gtools)
combinations(3, 2, c("iced", "jam", "plain"), set = FALSE, repeats.allowed = TRUE)
nrow(combinations(10, 3, repeats.allowed = TRUE)) | 1,021Combinations with repetitions | 13r | mviy4 |
null | 1,014Conway's Game of Life | 11kotlin | 0dqsf |
function quibble (strTab)
local outString, join = "{"
for strNum = 1, #strTab do
if strNum == #strTab then
join = ""
elseif strNum == #strTab - 1 then
join = " and "
else
join = ", "
end
outString = outString .. strTab[strNum] .. join
... | 1,022Comma quibbling | 1lua | iz1ot |
local function T2D(w,h) local t={} for y=1,h do t[y]={} for x=1,w do t[y][x]=0 end end return t end
local Life = {
new = function(self,w,h)
return setmetatable({ w=w, h=h, gen=1, curr=T2D(w,h), next=T2D(w,h)}, {__index=self})
end,
set = function(self, coords)
for i = 1, #coords, 2 do
self.curr[coor... | 1,014Conway's Game of Life | 1lua | 8fs0e |
strings.uniq.one?
strings == strings.uniq.sort | 1,017Compare a list of strings | 14ruby | tmof2 |
fn strings_are_equal(seq: &[&str]) -> bool {
match seq {
&[] | &[_] => true,
&[x, y, ref tail@ ..] if x == y => strings_are_equal(&[&[y], tail].concat()),
_ => false
}
}
fn asc_strings(seq: &[&str]) -> bool {
match seq {
&[] | &[_] => true,
&[x, y, ref tail @ ..] if ... | 1,017Compare a list of strings | 15rust | z9ito |
possible_doughnuts = ['iced', 'jam', 'plain'].repeated_combination(2)
puts
possible_doughnuts.each{|doughnut_combi| puts doughnut_combi.join(' and ')}
possible_doughnuts = [*1..1000].repeated_combination(30)
puts , | 1,021Combinations with repetitions | 14ruby | u73vz |
def strings_are_equal(seq:List[String]):Boolean = seq match {
case Nil => true
case s::Nil => true
case el1 :: el2 :: tail => el1==el2 && strings_are_equal(el2::tail)
}
def asc_strings(seq:List[String]):Boolean = seq match {
case Nil => true
case s::Nil => true
case el1 :: el2 :: tail => el1.co... | 1,017Compare a list of strings | 16scala | y2f63 |
null | 1,021Combinations with repetitions | 15rust | 5j6uq |
object CombinationsWithRepetition {
def multi[A](as: List[A], k: Int): List[List[A]] =
(List.fill(k)(as)).flatten.combinations(k).toList
def main(args: Array[String]): Unit = {
val doughnuts = multi(List("iced", "jam", "plain"), 2)
for (combo <- doughnuts) println(combo.mkString(","))
val bonus ... | 1,021Combinations with repetitions | 16scala | rb9gn |
package xyz.hyperreal.rosettacodeCompiler
import scala.io.Source
import scala.util.matching.Regex
object LexicalAnalyzer {
private val EOT = '\u0004'
val symbols =
Map(
"*" -> "Op_multiply",
"/" -> "Op_divide",
"%" -> "Op_mod",
"+" -> "Op_add",
"-" -> "Op_minus",
"<" ... | 1,019Compiler/lexical analyzer | 16scala | fysd4 |
my @params = @ARGV;
my $params_size = @ARGV;
my $second = $ARGV[1];
my $fifth = $ARGV[4]; | 1,020Command-line arguments | 2perl | 8f10w |
<?php
$program_name = $argv[0];
$second_arg = $argv[2];
$all_args_without_program_name = array_shift($argv); | 1,020Command-line arguments | 12php | 4hm5n |
func combosWithRep<T>(var objects: [T], n: Int) -> [[T]] {
if n == 0 { return [[]] } else {
var combos = [[T]]()
while let element = objects.last {
combos.appendContentsOf(combosWithRep(objects, n: n - 1).map{ $0 + [element] })
objects.removeLast()
}
return combos
}
}
print(combosWithRep... | 1,021Combinations with repetitions | 17swift | vrz2r |
import sys
program_name = sys.argv[0]
arguments = sys.argv[1:]
count = len(arguments) | 1,020Command-line arguments | 3python | ota81 |
R CMD BATCH --vanilla --slave '--args a=1 b=c(2,5,6)' test.r test.out | 1,020Command-line arguments | 13r | qikxs |
sub comma_quibbling(@) {
return "{$_}" for
@_ < 2 ? "@_" :
join(', ', @_[0..@_-2]) . ' and ' . $_[-1];
}
print comma_quibbling(@$_), "\n" for
[], [qw(ABC)], [qw(ABC DEF)], [qw(ABC DEF G H)]; | 1,022Comma quibbling | 2perl | gky4e |
p ARGV | 1,020Command-line arguments | 14ruby | n3wit |
use std::env;
fn main(){
let args: Vec<_> = env::args().collect();
println!("{:?}", args);
} | 1,020Command-line arguments | 15rust | d6xny |
<?php
function quibble($arr){
$words = count($arr);
if($words == 0){
return '{}';
}elseif($words == 1){
return '{'.$arr[0].'}';
}elseif($words == 2){
return '{'.$arr[0].' and '.$arr[1].'}';
}else{
return '{'.implode(', ', array_splice($arr, 0, -1) ). ' and '.$arr[0].'}';
}
}
$tests = ... | 1,022Comma quibbling | 12php | n3aig |
object CommandLineArguments extends App {
println(s"Received the following arguments: + ${args.mkString("", ", ", ".")}")
} | 1,020Command-line arguments | 16scala | z90tr |
null | 1,024Comments | 0go | izbog |
100 REM Standard BASIC comments begin with "REM" (remark) and extend to the end of the line
110 PRINT "this is code": REM comment after statement | 1,024Comments | 7groovy | qirxp |
let args = Process.arguments
println("This program is named \(args[0]).")
println("There are \(args.count-1) arguments.")
for i in 1..<args.count {
println("the argument #\(i) is \(args[i])")
} | 1,020Command-line arguments | 17swift | izeo0 |
i code = True
let u x = x x (this code not compiled)
Are you? -}
i code = True
i code = True | 1,024Comments | 8haskell | vrd2k |
life.pl numrows numcols numiterations
life.pl 5 10 15 | 1,014Conway's Game of Life | 2perl | 5jvu2 |
if booleanExpression {
statements
} | 1,023Conditional structures | 0go | 0dhsk |
>>> def strcat(sequence):
return '{%s}'% ', '.join(sequence)[::-1].replace(',', 'dna ', 1)[::-1]
>>> for seq in ([], [], [, ], [, , , ]):
print('Input:%-24r -> Output:%r'% (seq, strcat(seq)))
Input: [] -> Output: '{}'
Input: ['ABC'] -> Output: '{ABC}'
Input: ['ABC', 'DE... | 1,022Comma quibbling | 3python | rbmgq |
fac x = if x==0 then
1
else x * fac (x - 1) | 1,023Conditional structures | 8haskell | c5i94 |
quib <- function(vect)
{
vect <- vect[nchar(vect) != 0]
len <- length(vect)
allButLastWord <- if(len >= 2) paste0(vect[seq_len(len - 1)], collapse = ", ") else ""
paste0("{", if(nchar(allButLastWord) == 0) vect else paste0(allButLastWord, " and ", vect[len]), "}")
}
quib(character(0))
quib("")
quib(" ")
... | 1,022Comma quibbling | 13r | u7zvx |
null | 1,024Comments | 9java | y2s6g |
n = n + 1; | 1,024Comments | 10javascript | 2gnlr |
def comma_quibbling(a)
%w<{ }>.join(a.length < 2? a.first:
)
end
[[], %w<ABC>, %w<ABC DEF>, %w<ABC DEF G H>].each do |a|
puts comma_quibbling(a)
end | 1,022Comma quibbling | 14ruby | j1c7x |
fn quibble(seq: &[&str]) -> String {
match seq.len() {
0 => "{}".to_string(),
1 => format!("{{{}}}", seq[0]),
_ => {
format!("{{{} and {}}}",
seq[..seq.len() - 1].join(", "),
seq.last().unwrap())
}
}
}
fn main() {
println!(... | 1,022Comma quibbling | 15rust | halj2 |
def quibble( s:List[String] ) = s match {
case m if m.isEmpty => "{}"
case m if m.length < 3 => m.mkString("{", " and ", "}")
case m => "{" + m.init.mkString(", ") + " and " + m.last + "}"
} | 1,022Comma quibbling | 16scala | pxubj |
null | 1,024Comments | 11kotlin | fyado |
import random
from collections import defaultdict
printdead, printlive = '-
maxgenerations = 3
cellcount = 3,3
celltable = defaultdict(int, {
(1, 2): 1,
(1, 3): 1,
(0, 3): 1,
} )
u = universe = defaultdict(int)
u[(1,0)], u[(1,1)], u[(1,2)] = 1,1,1
for i in range(maxgenerations):
prin... | 1,014Conway's Game of Life | 3python | 4hu5k |
gen.board <- function(type="random", nrow=3, ncol=3, seeds=NULL)
{
if(type=="random")
{
return(matrix(runif(nrow*ncol) > 0.5, nrow=nrow, ncol=ncol))
} else if(type=="blinker")
{
seeds <- list(c(2,1),c(2,2),c(2,3))
} else if(type=="glider")
{
seeds <- list(c(1,2),c(2,3),c(3,1... | 1,014Conway's Game of Life | 13r | 2gclg |
let inputs = [[], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H"]]
func quibbling(var words:[String]) {
if words.count == 0 {
println("{}")
} else if words.count == 1 {
println("{\(words[0])}")
} else if words.count == 2 {
println("{\(words[0]) and \(words[1])}")
} else {
... | 1,022Comma quibbling | 17swift | 7p9rq |
if(s.equals("Hello World"))
{
foo();
}
else if(s.equals("Bye World"))
bar(); | 1,023Conditional structures | 9java | z9xtq |
if( s == "Hello World" ) {
foo();
} else if( s == "Bye World" ) {
bar();
} else {
deusEx();
} | 1,023Conditional structures | 10javascript | 9uoml |
def game_of_life(name, size, generations, initial_life=nil)
board = new_board size
seed board, size, initial_life
print_board board, name, 0
reason = generations.times do |gen|
new = evolve board, size
print_board new, name, gen+1
break :all_dead if barren? new, size
break :static if board == ... | 1,014Conway's Game of Life | 14ruby | rb4gs |
use std::collections::HashMap;
use std::collections::HashSet;
type Cell = (i32, i32);
type Colony = HashSet<Cell>;
fn print_colony(col: &Colony, width: i32, height: i32) {
for y in 0..height {
for x in 0..width {
print!("{} ",
if col.contains(&(x, y)) {"O"}
else... | 1,014Conway's Game of Life | 15rust | 7pgrc |
bool colorful(int n) {
if (n < 0 || n > 98765432)
return false;
int digit_count[10] = {};
int digits[8] = {};
int num_digits = 0;
for (int m = n; m > 0; m /= 10) {
int d = m % 10;
if (n > 9 && (d == 0 || d == 1))
return false;
if (++digit_count[d] > 1... | 1,025Colorful numbers | 5c | 2gilo |
null | 1,024Comments | 1lua | tmefn |
;;An R6RS Scheme implementation of Conway's Game of Life --- assumes
;;all cells outside the defined grid are dead
;if n is outside bounds of list, return 0 else value at n
(define (nth n lst)
(cond ((> n (length lst)) 0)
((< n 1) 0)
((= n 1) (car lst))
(else (nth (- n 1) (cdr lst)))))
;retu... | 1,014Conway's Game of Life | 16scala | kejhk |
package main
import (
"fmt"
"rcu"
"strconv"
)
func isColorful(n int) bool {
if n < 0 {
return false
}
if n < 10 {
return true
}
digits := rcu.Digits(n, 10)
for _, d := range digits {
if d == 0 || d == 1 {
return false
}
}
set := m... | 1,025Colorful numbers | 0go | qigxz |
null | 1,023Conditional structures | 11kotlin | izpo4 |
import Data.List ( nub )
import Data.List.Split ( divvy )
import Data.Char ( digitToInt )
isColourful :: Integer -> Bool
isColourful n
|n >= 0 && n <= 10 = True
|n > 10 && n < 100 = ((length s) == (length $ nub s)) &&
(not $ any (\c -> elem c "01") s)
|n >= 100 = ((length s) == (length $ nub s)) && (n... | 1,025Colorful numbers | 8haskell | mvsyf |
public class ColorfulNumbers {
private int count[] = new int[8];
private boolean used[] = new boolean[10];
private int largest = 0;
public static void main(String[] args) {
System.out.printf("Colorful numbers less than 100:\n");
for (int n = 0, count = 0; n < 100; ++n) {
if ... | 1,025Colorful numbers | 9java | fy1dv |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.