code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
class Nim {
constructor(tokens, printFun) {
this.startTokens = tokens;
this.tokens = tokens;
this.printFun = printFun;
}
playerTurn(take) {
take = Math.round(take);
if (take < 1 || take > 3) {
this.printFun("take must be between 1 and 3.\n")
return false;
}
this.tokens -= take;
this.printFun(... | 524Nim game | 10javascript | hz7jh |
main = let fi t e c = if c then t else e in do ct <- getContents; putStrLn $ fi ['a','c','c','e','p','t'] ['r','e','j','e','c','t'] $ take (length ct - 1) ct == let q s = (s ++ show s) in q "main = let fi t e c = if c then t else e in do ct <- getContents; putStrLn $ fi ['a','c','c','e','p','t'] ['r','e','j','e','c','t... | 529Narcissist | 8haskell | 2s3ll |
use strict;
use warnings;
use feature 'say';
use bigint;
use List::Util 'first';
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }
sub next_greatest_index {
my($str) = @_;
my @i = reverse split //, $str;
@i-1 - (1 + first { $i[$_] > $i[$_+1] } 0 .. @i-1);
}
sub next_greatest_integer {... | 523Next highest int from digits | 2perl | pmpb0 |
function makeList(separator) {
var counter = 1;
function makeItem(item) {
return counter++ + separator + item + "\n";
}
return makeItem("first") + makeItem("second") + makeItem("third");
}
console.log(makeList(". ")); | 525Nested function | 10javascript | qvex8 |
null | 526Nautical bell | 11kotlin | ogq8z |
for n in range(34):
print % (n, n, n) | 519Non-decimal radices/Output | 3python | 7tbrm |
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class NegativeBaseNumbers {
private static final String DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
private static String encodeNegBase(long n, int b) {
if (b < -62 || b > -1) throw new Illegal... | 527Negative base numbers | 9java | irqos |
null | 524Nim game | 11kotlin | lq9cp |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Narcissist {
private static final String SOURCE = "import java.io.BufferedReader;%nimport java.io.IOException;%nimport java.io.InputStreamReader;%n%npublic class Narcissist {%n private static final String S... | 529Narcissist | 9java | 61i3z |
null | 525Nested function | 11kotlin | jtg7r |
dec1 =
hex2 =
oct3 =
bin4 =
p dec1.to_i
p hex2.hex
p oct3.oct | 518Non-decimal radices/Input | 14ruby | jz17x |
as.octmode(x)
as.hexmode(x)
as.integer(x)
as.numeric(x) | 519Non-decimal radices/Output | 13r | 5i7uy |
tokens = 12
print("Nim Game\n")
print("Starting with " .. tokens .. " tokens.\n\n")
function printRemaining()
print(tokens .. " tokens remaining.\n")
end
function playerTurn(take)
take = math.floor(take)
if (take < 1 or take > 3) then
print ("\nTake must be between 1 and 3.\n")
return false
end
tokens = to... | 524Nim game | 1lua | 2scl3 |
typedef struct wstr {
wchar_t *s;
int n, alloc;
} wstr;
wstr *w_new()
{
wstr *w = malloc(sizeof(wstr));
w->alloc = 1;
w->n = 0;
w->s = malloc(sizeof(wchar_t));
w->s[0] = 0;
return w;
}
void w_append(wstr *w, wchar_t c)
{
int n = w->n + 1;
if (n >= w->alloc) {
w->alloc *= 2;
w->s = realloc(w->s, w->all... | 530Natural sorting | 5c | 5oyuk |
var code='var q=String.fromCharCode(39);print("var code=" + q + code + q + "; eval(code)" == readline())'; eval(code) | 529Narcissist | 10javascript | lqzcf |
null | 529Narcissist | 11kotlin | djqnz |
def closest_more_than(n, lst):
large = max(lst) + 1
return lst.index(min(lst, key=lambda x: (large if x <= n else x)))
def nexthigh(n):
assert n == int(abs(n)),
this = list(int(digit) for digit in str(int(n)))[::-1]
mx = this[0]
for i, digit in enumerate(this[1:], 1):
if digi... | 523Next highest int from digits | 3python | 191pc |
function makeList (separator)
local counter = 0
local function makeItem(item)
counter = counter + 1
return counter .. separator .. item .. "\n"
end
return makeItem("first") .. makeItem("second") .. makeItem("third")
end
print(makeList(". ")) | 525Nested function | 1lua | hzrj8 |
fn main() {
println!(
"Parse from plain decimal: {}",
"123".parse::<u32>().unwrap()
);
println!(
"Parse with a given radix (2-36 supported): {}",
u32::from_str_radix("deadbeef", 16).unwrap()
);
} | 518Non-decimal radices/Input | 15rust | h3aj2 |
object Main extends App {
val (s, bases) = ("100", Seq(2, 8, 10, 16, 19, 36))
bases.foreach(base => println(f"String $s in base $base%2d is $BigInt(s, base)%5d"))
} | 518Non-decimal radices/Input | 16scala | pmxbj |
null | 527Negative base numbers | 11kotlin | qv1x1 |
double pow_ (double x, int e) {
int i;
double r = 1;
for (i = 0; i < e; i++) {
r *= x;
}
return r;
}
double root (int n, double x) {
double d, r = 1;
if (!x) {
return 0;
}
if (n < 1 || (x < 0 && !(n&1))) {
return 0.0 / 0.0;
}
do {
d = (x / po... | 531Nth root | 5c | qvhxc |
O_RDONLY, O_WRONLY, or O_RDWR. O_CREAT, O_EXCL, O_NOCTTY, and O_TRUNC | 532Naming conventions | 5c | 3psza |
use utf8;
binmode STDOUT, ":utf8";
use DateTime;
$| = 1;
my @watch = <Middle Morning Forenoon Afternoon Dog First>;
my @ordinal = <One Two Three Four Five Six Seven Eight>;
my $thishour;
my $thisminute = '';
while () {
my $utc = DateTime->now( time_zone => 'UTC' );
if ($utc->minute =~ /^(00|30)$/ and $utc-... | 526Nautical bell | 2perl | gnv4e |
local $/;
print do { open 0; <0> } eq <> ? "accept" : "reject"; | 529Narcissist | 2perl | jtv7f |
var xs = Array.Empty(10)
var ys = Array(1, 2, 3)
var str = xs.ToString()
type Maybe = Some(x) or None()
var x = Maybe.Some(42) | 532Naming conventions | 6clojure | cxn9b |
my ($max, @current);
sub non_continuous {
my ($idx, $has_gap) = @_;
my $found;
for ($idx .. $max) {
push @current, $_;
$found ++ if $has_gap;
$found += non_continuous($_ + 1, $has_gap) if $_ < $max;
pop @current;... | 520Non-continuous subsequences | 2perl | h3pjl |
for n in 0..33
puts % [n, n, n, n]
end
puts
[2,8,10,16,36].each {|i| puts } | 519Non-decimal radices/Output | 14ruby | h31jx |
fn main() { | 519Non-decimal radices/Output | 15rust | k6ah5 |
use strict;
use warnings;
use feature 'say';
my $tokens = 12;
say "$tokens tokens remaining.\n";
while (1) {
print "How many tokens do you want to remove; 1, 2 or 3?: ";
(my $player = <>) =~ s/\s//g;
say "Nice try. $tokens tokens remaining.\n" and next
unless $player =~ /^[123]$/;
$tokens -= ... | 524Nim game | 2perl | qvwx6 |
import sys
with open(sys.argv[0]) as quine:
code = raw_input()
if code == quine.read():
print()
else:
print() | 529Narcissist | 3python | hzujw |
fn next_permutation<T: PartialOrd>(array: &mut [T]) -> bool {
let len = array.len();
if len < 2 {
return false;
}
let mut i = len - 1;
while i > 0 {
let j = i;
i -= 1;
if array[i] < array[j] {
let mut k = len - 1;
while array[i] >= array[k] {
... | 523Next highest int from digits | 15rust | w2we4 |
sub makeList {
my $separator = shift;
my $counter = 1;
sub makeItem { $counter++ . $separator . shift . "\n" }
makeItem("first") . makeItem("second") . makeItem("third")
}
print makeList(". "); | 525Nested function | 2perl | tknfg |
object Main extends App {
val radices = List(2, 8, 10, 16, 19, 36)
for (base <- radices) print(f"$base%6d")
println(s"""\n${"-" * (6 * radices.length)}""")
for (i <- BigInt(0) to 35; | 519Non-decimal radices/Output | 16scala | 19xpf |
use strict;
use feature 'say';
use POSIX qw(floor);
use ntheory qw/fromdigits todigits/;
sub encode {
my($n, $b) = @_;
my @out;
my $r = 0;
while ($n) {
$r = $n % $b;
$n = floor $n/$b;
$n += 1, $r -= $b if $r < 0;
push @out, todigits($r, -$b) || 0;
}
join '', rev... | 527Negative base numbers | 2perl | v0m20 |
(ns test-project-intellij.core
(:gen-class))
(defn abs [x]
" Absolute value"
(if (< x 0) (- x) x))
(defn power [x n]
" x to power n, where n = 0, 1, 2, ... "
(apply * (repeat n x)))
(defn calc-delta [A x n]
" nth rooth algorithm delta calculation "
(/ (- (/ A (power x (- n 1))) x) n))
(defn nth-root
... | 531Nth root | 6clojure | iraom |
package main
import (
"fmt"
"regexp"
"sort"
"strconv"
"strings"
)
var tests = []struct {
descr string
list []string
}{
{"Ignoring leading spaces", []string{
"ignore leading spaces: 2-2",
" ignore leading spaces: 2-1",
" ignore leading spaces: 2+0",
" ... | 530Natural sorting | 0go | 8410g |
null | 532Naming conventions | 0go | b6vkh |
<?
function makeList($separator) {
$counter = 1;
$makeItem = function ($item) use ($separator, &$counter) {
return $counter++ . $separator . $item . ;
};
return $makeItem() . $makeItem() . $makeItem();
}
echo makeList();
?> | 525Nested function | 12php | k37hv |
import time, calendar, sched, winsound
duration = 750
freq = 1280
bellchar =
watches = 'Middle,Morning,Forenoon,Afternoon,First/Last dog,First'.split(',')
def gap(n=1):
time.sleep(n * duration / 1000)
off = gap
def on(n=1):
winsound.Beep(freq, n * duration)
def bong():
on(); off(0.5)
de... | 526Nautical bell | 3python | rdugq |
int main() {
const int MU_MAX = 1000000;
int i, j;
int *mu;
int sqroot;
sqroot = (int)sqrt(MU_MAX);
mu = malloc((MU_MAX + 1) * sizeof(int));
for (i = 0; i < MU_MAX;i++) {
mu[i] = 1;
}
for (i = 2; i <= sqroot; i++) {
if (mu[i] == 1) {
for (... | 533Möbius function | 5c | rdyg7 |
import Data.List
import Data.Char
import Data.String.Utils
import Data.List.Utils
import Data.Function (on)
printOutput = do
putStrLn "# Ignoring leading spaces \n"
printBlockOfMessages sample1Rule ignoringStartEndSpaces
putStrLn "\n # Ignoring multiple adjacent spaces ... | 530Natural sorting | 8haskell | lqtch |
s = ; puts(gets.chomp == (s % [34.chr, s, 34.chr])? 'accept': 'reject') | 529Narcissist | 14ruby | b64kq |
use std::io::{stdin, prelude::*};
fn main() {
let src = include_str!("main.rs");
let mut input = String::new();
stdin()
.lock()
.read_to_string(&mut input)
.expect("Could not read from STDIN");
println!("{}", src == input);
} | 529Narcissist | 15rust | pygbu |
import scala.io.StdIn
object Narcissist extends App {
val text = scala.io.Source.fromFile("Narcissist.scala", "UTF-8").toStream
println("Enter the number of lines to be input followed by those lines:\n")
val n = StdIn.readInt()
val lines = Stream {
StdIn.readLine()
}
if (lines.mkString("\r\n") == text)... | 529Narcissist | 16scala | ecjab |
// version 1.0.6
const val SOLAR_DIAMETER = 864938
enum class Planet { MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE, PLUTO } // Yeah, Pluto!
class Star(val name: String) {
fun showDiameter() {
println("The diameter of the $name is ${"%,d".format(SOLAR_DIAMETER)} miles")
}
}
class So... | 532Naming conventions | 8haskell | djen4 |
def makeList(separator):
counter = 1
def makeItem(item):
nonlocal counter
result = str(counter) + separator + item +
counter += 1
return result
return makeItem() + makeItem() + makeItem()
print(makeList()) | 525Nested function | 3python | zbdtt |
MakeList <- function(sep)
{
counter <- 0
MakeItem <- function() paste0(counter <<- counter + 1, sep, c("first", "second", "third")[counter])
cat(replicate(3, MakeItem()), sep = "\n")
}
MakeList(". ") | 525Nested function | 13r | n78i2 |
from __future__ import print_function
def EncodeNegBase(n, b):
if n == 0:
return
out = []
while n != 0:
n, rem = divmod(n, b)
if rem < 0:
n += 1
rem -= b
out.append(rem)
return .join(map(str, out[::-1]))
def DecodeNegBase(nstr, b):
if nstr == :
return 0
total = 0
for i, ch in enumerate(nstr... | 527Negative base numbers | 3python | u89vd |
print()
def getTokens(curTokens):
global tokens
print(, end='')
take = int(input())
if (take < 1 or take > 3):
print()
getTokens(curTokens)
return
tokens = curTokens - take
print(f'You take {take} tokens.')
print(f'{tokens} tokens remaining.\n')
def compTurn(curTokens):
global tokens
take = curToke... | 524Nim game | 3python | suxq9 |
tokens <- 12
while(tokens > 0) {
print(paste("Tokens remaining:",tokens))
playertaken <- 0
while(playertaken == 0) {
playeropts <- c(1:min(c(tokens,3)))
playertaken <- menu(playeropts, title = "Your go, how many tokens will you take? ")
tokens <- tokens - playertaken
if(tokens == 0) {print("Well ... | 524Nim game | 13r | ec1ad |
void* xmalloc(size_t n) {
void* ptr = malloc(n);
if (ptr == NULL) {
fprintf(stderr, );
exit(1);
}
return ptr;
}
void* xrealloc(void* p, size_t n) {
void* ptr = realloc(p, n);
if (ptr == NULL) {
fprintf(stderr, );
exit(1);
}
return ptr;
}
bool is_prime(ui... | 534N-smooth numbers | 5c | 84h04 |
typedef struct { int x, y, z; } FTest_args;
void FTest (FTest_args args) {
printf(, args.x, args.y, args.z);
}
void FTest2 (int x, int y, int z) {
printf(, x, y, z);
}
static inline void FTest2_default_wrapper (FTest_args args) {
return FTest2(args.x, args.y, args.z);
}
int main(int argc, char **arg... | 535Named parameters | 5c | surq5 |
#! /usr/bin/swift
import Foundation
let script = CommandLine.arguments[0]
print(script)
let mytext = try? String.init(contentsOfFile: script, encoding: .utf8)
var enteredtext = readLine()
if mytext == enteredtext {
print("Accept")
} else {
print("Reject")
} | 529Narcissist | 17swift | k35hx |
package main
import (
"fmt"
"math/big"
"strconv"
)
func main () {
s := strconv.FormatInt(26, 16) | 528Non-decimal radices/Convert | 0go | a9j1f |
var nsort = function(input) {
var e = function(s) {
return (' ' + s + ' ').replace(/[\s]+/g, ' ').toLowerCase().replace(/[\d]+/, function(d) {
d = '' + 1e20 + d;
return d.substring(d.length - 20);
});
};
return input.sort(function(a, b) {
return e(a).localeCompare(e(b));
});
};
console.... | 530Natural sorting | 10javascript | cxf9j |
null | 532Naming conventions | 11kotlin | a9413 |
def makeList(separator)
counter = 1
makeItem = lambda {|item|
result =
counter += 1
result
}
makeItem[] + makeItem[] + makeItem[]
end
print makeList() | 525Nested function | 14ruby | 61t3t |
fn make_list(sep: &str) -> String {
let mut counter = 0;
let mut make_item = |label| {
counter += 1;
format!("{}{}{}", counter, sep, label)
};
format!(
"{}\n{}\n{}",
make_item("First"),
make_item("Second"),
make_item("Third")
)
}
fn main() {
print... | 525Nested function | 15rust | yaz68 |
watches = [ , , , , , , , ]
watch_ends = [ , , , , , , , ]
words = [,,,,,,,]
sound =
loop do
time = Time.now
if time.sec == 0 and time.min % 30 == 0
num = (time.hour * 60 + time.min) / 30 % 8
num = 8 if num == 0
hr_min = time.strftime
idx = watch_ends.find_index {|t| hr_min <= t}
text = % ... | 526Nautical bell | 14ruby | jt47x |
def ncsub(seq, s=0):
if seq:
x = seq[:1]
xs = seq[1:]
p2 = s% 2
p1 = not p2
return [x + ys for ys in ncsub(xs, s + p1)] + ncsub(xs, s + p2)
else:
return [[]] if s >= 3 else [] | 520Non-continuous subsequences | 3python | k61hf |
def radixParse = { s, radix -> Integer.parseInt(s, radix) }
def radixFormat = { i, radix -> Integer.toString(i, radix) } | 528Non-decimal radices/Convert | 7groovy | hz5j9 |
(defn foo [& opts]
(let [opts (merge {:bar 1:baz 2} (apply hash-map opts))
{:keys [bar baz]} opts]
[bar baz])) | 535Named parameters | 6clojure | n7bik |
- constants use UPCASE_SNAKE
- variable names use lower_case_snake
- class-like structures use CamelCase
- other functions use smallCamelCase
- Use _ for unneeded variables
- Don't use Hungarian Notation | 532Naming conventions | 1lua | ecgac |
def main(args: Array[String]) {
val sep: String=". "
var c:Int=1;
def go(s: String):Unit={
println(c+sep+s)
c=c+1
}
go("first")
go("second")
go("third")
} | 525Nested function | 16scala | cxy93 |
ncsub <- function(x)
{
n <- length(x)
a <- seq_len(n)
seqlist <- list()
for(i in 2:(n-1))
{
seqs <- combn(a, i)
ok <- apply(seqs, 2, function(x) any(diff(x)!=1))
newseqs <- unlist(apply(seqs[,ok], 2, f... | 520Non-continuous subsequences | 13r | rfhgj |
Prelude> Numeric.showIntAtBase 16 Char.intToDigit 42 ""
"2a"
Prelude> fst $ head $ Numeric.readInt 16 Char.isHexDigit Char.digitToInt "2a"
42 | 528Non-decimal radices/Convert | 8haskell | zbot0 |
[12, 8, 4].each do |remaining|
puts
unless (num=gets.to_i).between?(1, 3)
puts
redo
end
puts
end
puts | 524Nim game | 14ruby | 84s01 |
$ALL_CAPS_HERE constants
$Some_Caps_Here package-wide global/static
$no_caps_here function scope my/our/local variables
$_internal_use private | 532Naming conventions | 2perl | 9wimn |
DIGITS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
def negative_base_encode(n, b)
raise 'base out of range' if (b < -62) || (b > -2)
return '0' if n == 0
revdigs = []
while n!= 0 do
n, r = n.divmod(b)
if r < 0
n += 1
r -= b
end
revdigs << r
end
return re... | 527Negative base numbers | 14ruby | 4il5p |
fn main() {
let mut tokens = 12;
println!("Nim game");
println!("Starting with {} tokens.", tokens);
println!("");
loop {
tokens = p_turn(&tokens);
print_remaining(&tokens);
tokens = c_turn(&tokens);
print_remaining(&tokens);
if tokens == 0 {
pri... | 524Nim game | 15rust | og083 |
var tokens = 12
def playerTurn(curTokens: Int): Unit =
{
val take = readLine("How many tokens would you like to take? ").toInt
if (take < 1 || take > 3) {
println("Number must be between 1 and 3.")
playerTurn(curTokens)
}
else {
tokens = curTokens - take
println(s"You take $take tokens. $tokens... | 524Nim game | 16scala | djing |
null | 530Natural sorting | 11kotlin | n7wij |
render-game-state
send-message-to-client
traverse-forest | 532Naming conventions | 3python | cxn9q |
func makeList(_ separator: String) -> String {
var counter = 1
func makeItem(_ item: String) -> String {
let result = String(counter) + separator + item + "\n"
counter += 1
return result
}
return makeItem("first") + makeItem("second") + makeItem("third")
}
print(makeList(". ")) | 525Nested function | 17swift | 3pfz2 |
const DIGITS: [char;62] = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
fn main() {
let nums_and_bases: [(i64,i... | 527Negative base numbers | 15rust | gn24o |
object NegativeBase {
val digits = ('0' to '9') ++ ('a' to 'z') ++ ('A' to 'Z')
def intToStr(n: Int, b: Int): String = {
def _fromInt(n: Int): List[Int] = {
if (n == 0) {
Nil
} else {
val r = n % b
val rp = if (r < 0) r + b else r
val m = -(n - rp)/b
rp :: _f... | 527Negative base numbers | 16scala | jt57i |
package main
import "fmt"
func mbius(to int) []int {
if to < 1 {
to = 1
}
mobs := make([]int, to+1) | 533Möbius function | 0go | n71i1 |
test_variable = [1, 9, 8, 3]
test_variable.sort
test_variable
test_variable.sort!
test_variable | 532Naming conventions | 14ruby | 2sflw |
Dim dblDistance as Double | 532Naming conventions | 15rust | v0t2t |
Dim dblDistance as Double | 532Naming conventions | 16scala | 4i650 |
class Array
def func_power_set
inject([[]]) { |ps,item|
ps +
ps.map { |e| e + [item] }
}
end
def non_continuous_subsequences
func_power_set.reject {|seq| continuous?(seq)}
end
def continuous?(seq)
seq.each_cons(2) {|a, b| return false if a.succ!= b}
... | 520Non-continuous subsequences | 14ruby | pmebh |
public static long backToTen(String num, int oldBase){
return Long.parseLong(num, oldBase); | 528Non-decimal radices/Convert | 9java | ogw8d |
var tokens = 12
while tokens!= 0 {
print("Tokens remaining: \(tokens)\nPlease enter a number between 1 and 3: ", terminator: "")
guard let input = readLine(), let n = Int(input), n >= 1 && n <= 3 else {
fatalError("Invalid input")
}
tokens -= n
if tokens == 0 {
print("You win!")
break
}
... | 524Nim game | 17swift | 05qs6 |
mpz_t power[10];
mpz_t dsum[MAX_LEN + 1];
int cnt[10], len;
void check_perm(void)
{
char s[MAX_LEN + 1];
int i, c, out[10] = { 0 };
mpz_get_str(s, 10, dsum[0]);
for (i = 0; s[i]; i++) {
c = s[i]-'0';
if (++out[c] > cnt[c]) return;
}
if (i == len)
gmp_printf(, dsum[0]);
}
void narc_(int pos, int d)
{
if... | 536Narcissistic decimal number | 5c | ogj80 |
typedef struct{
char str[3];
int key;
}note;
note sequence[] = {{,0},{,2},{,4},{,5},{,7},{,9},{,11},{,12}};
int main(void)
{
int i=0;
while(!kbhit())
{
printf(,sequence[i].str);
sound(261.63*pow(2,sequence[i].key/12.0));
delay(sequence[i].key%12==0?500:1000);
i = (i+1)%8;
i==0?printf():printf();
}
... | 537Musical scale | 5c | 1mcpj |
package main
import (
"fmt"
"log"
"math/big"
)
var (
primes []*big.Int
smallPrimes []int
) | 534N-smooth numbers | 0go | 5otul |
import Data.List (intercalate)
import Data.List.Split (chunksOf)
import Data.Vector.Unboxed (toList)
import Math.NumberTheory.ArithmeticFunctions.Moebius (Moebius(..),
sieveBlockMoebius)
import System.Environment (getArgs, getProgName)
import System.IO (hPutStrLn, s... | 533Möbius function | 8haskell | u8tv2 |
object NonContinuousSubSequences extends App {
private def seqR(s: String, c: String, i: Int, added: Int): Unit = {
if (i == s.length) {
if (c.trim.length > added) println(c)
} else {
seqR(s, c + s(i), i + 1, added + 1)
seqR(s, c + " ", i + 1, added)
}
}
seqR("1234", "", 0, 0)
} | 520Non-continuous subsequences | 16scala | w2ses |
k = 26
s = k.toString(16) | 528Non-decimal radices/Convert | 10javascript | tk8fm |
void hue_to_rgb(double hue, double sat, unsigned char *p)
{
double x;
int c = 255 * sat;
hue /= 60;
x = (1 - fabs(fmod(hue, 2) - 1)) * 255;
switch((int)hue) {
case 0: p[0] = c; p[1] = x; p[2] = 0; return;
case 1: p[0] = x; p[1] = c; p[2] = 0; return;
case 2: p[0] = 0; p[1] = c; p[2] = x; return;
case 3: p[0] ... | 538Munching squares | 5c | tkbf4 |
import Data.Numbers.Primes (primes)
import Text.Printf (printf)
merge :: Ord a => [a] -> [a] -> [a]
merge [] b = b
merge a@(x:xs) b@(y:ys) | x < y = x: merge xs b
| otherwise = y: merge a ys
nSmooth :: Integer -> [Integer]
nSmooth p = 1: foldr u [] factors
where
factors = takeWhile (<... | 534N-smooth numbers | 8haskell | x2gw4 |
public class MbiusFunction {
public static void main(String[] args) {
System.out.printf("First 199 terms of the mbius function are as follows:%n ");
for ( int n = 1 ; n < 200 ; n++ ) {
System.out.printf("%2d ", mbiusFunction(n));
if ( (n+1) % 20 == 0 ) {
... | 533Möbius function | 9java | me8ym |
use feature 'fc';
use Unicode::Normalize;
sub natural_sort {
my @items = map {
my $str = fc(NFKD($_));
$str =~ s/\s+/ /;
$str =~ s/|^(?:the|a|an) \b|\p{Nonspacing_Mark}| $//g;
my @fields = $str =~ /(?!\z) ([^0-9]*+) ([0-9]*+)/gx;
[$_, \@fields]
} @_;
return map { $_-... | 530Natural sorting | 2perl | 7flrh |
(use 'overtone.live)
(definst saw-wave [freq 440 attack 0.01 sustain 0.4 release 0.1 vol 0.4]
(* (env-gen (env-lin attack sustain release) 1 1 0 1 FREE)
(saw freq)
vol))
(defn play [note ms]
(saw-wave (midi->hz note))
(Thread/sleep ms))
(doseq [note (scale:c4:major)] (play note 500)) | 537Musical scale | 6clojure | qv5xt |
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
public class NSmoothNumbers {
public static void main(String[] args) {
System.out.printf("show the first 25 n-smooth numbers for n = 2 through n = 29%n");
int max = 25;
List<BigInteger> primes = new ArrayList<>... | 534N-smooth numbers | 9java | b6lk3 |
package main
import (
"fmt"
)
type params struct {x, y, z int}
func myFunc(p params) int {
return p.x + p.y + p.z
}
func main() {
r := myFunc(params{x: 1, y: 2, z: 3}) | 535Named parameters | 0go | v0n2m |
import kotlin.math.sqrt
fun main() {
println("First 199 terms of the mbius function are as follows:")
print(" ")
for (n in 1..199) {
print("%2d ".format(mobiusFunction(n)))
if ((n + 1) % 20 == 0) {
println()
}
}
}
private const val MU_MAX = 1000000
private var M... | 533Möbius function | 11kotlin | tkwf0 |
(ns narcissistic.core
(:require [clojure.math.numeric-tower:as math]))
(defn digits [n]
(->> n str (map (comp read-string str))))
(defn narcissistic? [n]
(let [d (digits n)
s (count d)]
(= n (reduce + (map #(math/expt % s) d)))))
(defn firstNnarc [n]
(take n (filter narcissistic? (range)))) | 536Narcissistic decimal number | 6clojure | tk1fv |
function isPrime(n){
var x = Math.floor(Math.sqrt(n)), i = 2
while ((i <= x) && (n % i != 0)) i++
return (x < i)
}
function smooth(n, s, k){
var p = []
for (let i = 2; i <= n; i++){
if (isPrime(i)){
p.push([BigInt(i), [1n], 0])
}
}
var res = []
for (let i ... | 534N-smooth numbers | 10javascript | wl4e2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.