code stringlengths 1 46.1k ⌀ | label class label 1.18k
classes | domain_label class label 21
classes | index stringlengths 4 5 |
|---|---|---|---|
(() => {
"use strict"; | 489Padovan sequence | 10javascript | quwx8 |
const addMissingZeros = date => (/^\d$/.test(date) ? `0${date}` : date);
const formatter = (date, readable) => {
const year = date.getFullYear();
const month = addMissingZeros(date.getMonth() + 1);
const day = addMissingZeros(date.getDate());
return readable ? `${year}-${month}-${day}` : `${year}${month}${da... | 488Palindrome dates | 10javascript | h6hjh |
use Thread 'async';
use Thread::Queue;
sub make_slices {
my ($n, @avail) = (shift, @{ +shift });
my ($q, @part, $gen);
$gen = sub {
my $pos = shift;
if (@part == $n) {
$q->enqueue(... | 487Ordered partitions | 2perl | p91b0 |
use Time::Piece;
my $d = Time::Piece->strptime("2020-02-02", "%Y-%m-%d");
for (my $k = 1 ; $k <= 15 ; $d += Time::Piece::ONE_DAY) {
my $s = $d->strftime("%Y%m%d");
if ($s eq reverse($s) and ++$k) {
print $d->strftime("%Y-%m-%d\n");
}
} | 488Palindrome dates | 2perl | q5qx6 |
use strict;
use warnings;
use feature <state say>;
use List::Lazy 'lazy_list';
my $p = 1.32471795724474602596;
my $s = 1.0453567932525329623;
my %rules = (A => 'B', B => 'C', C => 'AB');
my $pad_recur = lazy_list { state @p = (1, 1, 1, 2); push @p, $p[1]+$p[2]; shift @p };
sub pad_floor { int 1/2 + $p**($_<3 ? 1 : $... | 489Padovan sequence | 2perl | tbdfg |
from itertools import combinations
def partitions(*args):
def p(s, *args):
if not args: return [[]]
res = []
for c in combinations(s, args[0]):
s0 = [x for x in s if x not in c]
for r in p(s0, *args[1:]):
res.append([c] + r)
return res
s =... | 487Ordered partitions | 3python | 1capc |
pascalTriangle <- function(h) {
for(i in 0:(h-1)) {
s <- ""
for(k in 0:(h-i)) s <- paste(s, " ", sep="")
for(j in 0:i) {
s <- paste(s, sprintf("%3d ", choose(i, j)), sep="")
}
print(s)
}
} | 481Pascal's triangle | 13r | mx5y4 |
from math import floor
from collections import deque
from typing import Dict, Generator
def padovan_r() -> Generator[int, None, None]:
last = deque([1, 1, 1], 4)
while True:
last.append(last[-2] + last[-3])
yield last.popleft()
_p, _s = 1.324717957244746025960908854, 1.0453567932525329623
de... | 489Padovan sequence | 3python | zpftt |
'''Palindrome dates'''
from datetime import datetime
from itertools import chain
def palinDay(y):
'''A possibly empty list containing the palindromic
date for the given year, if such a date exists.
'''
s = str(y)
r = s[::-1]
iso = '-'.join([s, r[0:2], r[2:]])
try:
datetime.str... | 488Palindrome dates | 3python | s4sq9 |
function ispalindrome(s) return s == string.reverse(s) end | 483Palindrome detection | 1lua | nh3i8 |
int interactiveCompare(const void *x1, const void *x2)
{
const char *s1 = *(const char * const *)x1;
const char *s2 = *(const char * const *)x2;
static int count = 0;
printf(, ++count, s1, s2);
int response;
scanf(, &response);
return response;
}
void printOrder(const char *items[], int len)
{
printf()... | 490Order by pair comparisons | 5c | v8c2o |
def partition(mask)
return [[]] if mask.empty?
[*1..mask.inject(:+)].permutation.map {|perm|
mask.map {|num_elts| perm.shift(num_elts).sort }
}.uniq
end | 487Ordered partitions | 14ruby | e2wax |
use itertools::Itertools;
type NArray = Vec<Vec<Vec<usize>>>;
fn generate_partitions(args: &[usize]) -> NArray { | 487Ordered partitions | 15rust | wvxe4 |
padovan = Enumerator.new do |y|
ar = [1, 1, 1]
loop do
ar << ar.first(2).sum
y << ar.shift
end
end
P, S = 1.324717957244746025960908854, 1.0453567932525329623
def padovan_f(n) = (P**(n-1) / S + 0.5).floor
puts
puts
n = 63
bool = (0...n).map{|n| padovan_f(n)} == padovan.take(n)
puts
puts
def l_sys... | 489Padovan sequence | 14ruby | 6az3t |
require 'date'
palindate = Enumerator.new do |yielder|
(..).each do |y|
m, d = y.reverse.scan(/../)
strings = [y, m, d]
yielder << strings.join() if Date.valid_date?( *strings.map( &:to_i ) )
end
end
puts palindate.take(15) | 488Palindrome dates | 14ruby | 8r801 |
null | 488Palindrome dates | 15rust | o7o83 |
fn padovan_recur() -> impl std::iter::Iterator<Item = usize> {
let mut p = vec![1, 1, 1];
let mut n = 0;
std::iter::from_fn(move || {
let pn = if n < 3 { p[n] } else { p[0] + p[1] };
p[0] = p[1];
p[1] = p[2];
p[2] = pn;
n += 1;
Some(pn)
})
}
fn padovan_fl... | 489Padovan sequence | 15rust | ye368 |
import Foundation
class PadovanRecurrence: Sequence, IteratorProtocol {
private var p = [1, 1, 1]
private var n = 0
func next() -> Int? {
let pn = n < 3? p[n]: p[0] + p[1]
p[0] = p[1]
p[1] = p[2]
p[2] = pn
n += 1
return pn
}
}
class PadovanFloor: Sequen... | 489Padovan sequence | 17swift | 31tz2 |
import Foundation
func isPalindrome(_ string: String) -> Bool {
let chars = string.lazy
return chars.elementsEqual(chars.reversed())
}
let format = DateFormatter()
format.dateFormat = "yyyyMMdd"
let outputFormat = DateFormatter()
outputFormat.dateFormat = "yyyy-MM-dd"
var count = 0
let limit = 15
let calend... | 488Palindrome dates | 17swift | 0g0s6 |
package main
import (
"fmt"
"sort"
"strings"
)
var count int = 0
func interactiveCompare(s1, s2 string) bool {
count++
fmt.Printf("(%d) Is%s <%s? ", count, s1, s2)
var response string
_, err := fmt.Scanln(&response)
return err == nil && strings.HasPrefix(response, "y")
}
func main() ... | 490Order by pair comparisons | 0go | s5wqa |
def pascal(n)
raise ArgumentError, if n < 1
yield ar = [1]
(n-1).times do
ar.unshift(0).push(0)
yield ar = ar.each_cons(2).map(&:sum)
end
end
pascal(8){|row| puts row.join().center(20)} | 481Pascal's triangle | 14ruby | uihvz |
import Control.Monad
import Control.Monad.ListM (sortByM, insertByM, partitionM, minimumByM)
import Data.Bool (bool)
import Data.Monoid
import Data.List
isortM, msortM, tsortM :: Monad m => (a -> a -> m Ordering) -> [a] -> m [a]
msortM = sortByM
isortM cmp = foldM (flip (insertByM cmp)) []
tsortM cmp = go
whe... | 490Order by pair comparisons | 8haskell | 9x6mo |
import java.util.*;
public class SortComp1 {
public static void main(String[] args) {
List<String> items = Arrays.asList("violet", "red", "green", "indigo", "blue", "yellow", "orange");
List<String> sortedItems = new ArrayList<>();
Comparator<String> interactiveCompare = new Comparator<Stri... | 490Order by pair comparisons | 9java | tbnf9 |
typedef char TWord[MAXLEN];
typedef struct Node {
TWord word;
struct Node *next;
} Node;
int is_ordered_word(const TWord word) {
assert(word != NULL);
int i;
for (i = 0; word[i] != '\0'; i++)
if (word[i] > word[i + 1] && word[i + 1] != '\0')
return 0;
return 1;
}
Node... | 491Ordered words | 5c | 9x3m1 |
unsigned int * seq_len(const unsigned int START, const unsigned int END) {
unsigned start = (unsigned)START;
unsigned end = (unsigned)END;
if (START == END) {
unsigned int *restrict sequence = malloc( (end+1) * sizeof(unsigned int));
if (sequence == NULL) {
printf(, __FILE__, __LINE__);
perror();
exit(... | 492P-value correction | 5c | mwtys |
fn pascal_triangle(n: u64)
{
for i in 0..n {
let mut c = 1;
for _j in 1..2*(n-1-i)+1 {
print!(" ");
}
for k in 0..i+1 {
print!("{:2} ", c);
c = c * (i-k)/(k+1);
}
println!();
}
} | 481Pascal's triangle | 15rust | 5nkuq |
def tri(row: Int): List[Int] =
row match {
case 1 => List(1)
case n: Int => 1 +: ((tri(n - 1) zip tri(n - 1).tail) map { case (a, b) => a + b }) :+ 1
} | 481Pascal's triangle | 16scala | rt1gn |
use strict;
use warnings;
sub ask
{
while( 1 )
{
print "Compare $a to $b [<,=,>]: ";
<STDIN> =~ /[<=>]/ and return +{qw( < -1 = 0 > 1 )}->{$&};
}
}
my @sorted = sort ask qw( violet red green indigo blue yellow orange );
print "sorted: @sorted\n"; | 490Order by pair comparisons | 2perl | gdu4e |
(defn is-sorted? [coll]
(not-any? pos? (map compare coll (next coll))))
(defn take-while-eqcount [coll]
(let [n (count (first coll))]
(take-while #(== n (count %)) coll)))
(with-open [rdr (clojure.java.io/reader "unixdict.txt")]
(->> rdr
line-seq
(filter is-sorted?)
(sort-by count >)
... | 491Ordered words | 6clojure | uocvi |
def _insort_right(a, x, q):
lo, hi = 0, len(a)
while lo < hi:
mid = (lo+hi)
q += 1
less = input(f).strip().lower() == 'y'
if less: hi = mid
else: lo = mid+1
a.insert(lo, x)
return q
def order(items):
ordered, q = [], 0
for item in items:
q =... | 490Order by pair comparisons | 3python | rf5gq |
SAMPLES>write 18 / 2 * 3 + 7
34
SAMPLES>write 18 / (2 * 3) + 7
10 | 493Operator precedence | 5c | 4nc5t |
package main
import (
"fmt"
"log"
"math"
"os"
"sort"
"strconv"
"strings"
)
type pvalues = []float64
type iv1 struct {
index int
value float64
}
type iv2 struct{ index, value int }
type direction int
const (
up direction = iota
down
) | 492P-value correction | 0go | ach1f |
items = [, , , , , , ]
count = 0
sortedItems = []
items.each {|item|
puts
spotToInsert = sortedItems.bsearch_index{|x|
count += 1
print
gets.start_with?('y')
} || sortedItems.length
sortedItems.insert(spotToInsert, item)
}
p sortedItems | 490Order by pair comparisons | 14ruby | jzg7x |
: \? = ~ /! # $% & * + - < > @ ^ ` | , ' | 493Operator precedence | 6clojure | h35jr |
import java.util.Arrays;
import java.util.Comparator;
public class PValueCorrection {
private static int[] seqLen(int start, int end) {
int[] result;
if (start == end) {
result = new int[end + 1];
for (int i = 0; i < result.length; ++i) {
result[i] = i + 1;
... | 492P-value correction | 9java | orx8d |
typedef const char * String;
typedef struct sTable {
String * *rows;
int n_rows,n_cols;
} *Table;
typedef int (*CompareFctn)(String a, String b);
struct {
CompareFctn compare;
int column;
int reversed;
} sortSpec;
int CmprRows( const void *aa, const void *bb)
{
String *rA = *(String *co... | 494Optional parameters | 5c | 5imuk |
package main
import (
"fmt"
"strconv"
)
func ownCalcPass(password, nonce string) uint32 {
start := true
num1 := uint32(0)
num2 := num1
i, _ := strconv.Atoi(password)
pwd := uint32(i)
for _, c := range nonce {
if c != '0' {
if start {
num2 = pwd
... | 495OpenWebNet password | 0go | 20zl7 |
package main
import (
"time"
ole "github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
)
func main() {
ole.CoInitialize(0)
unknown, _ := oleutil.CreateObject("Word.Application")
word, _ := unknown.QueryInterface(ole.IID_IDispatch)
oleutil.PutProperty(word, "Visible", true)
docu... | 496OLE automation | 0go | byukh |
func pascal(n:Int)->[Int]{
if n==1{
let a=[1]
print(a)
return a
}
else{
var a=pascal(n:n-1)
var temp=a
for i in 0..<a.count{
if i+1==a.count{
temp.append(1)
break
}
temp[i+1] = a[i]+a[i+1]
... | 481Pascal's triangle | 17swift | voj2r |
package main
import (
"bufio"
"crypto/rand"
"fmt"
"io/ioutil"
"log"
"math/big"
"os"
"strconv"
"strings"
"unicode"
)
const (
charsPerLine = 48
chunkSize = 6
cols = 8
demo = true | 497One-time pad | 0go | njai1 |
function calcPass (pass, nonce) {
var flag = true;
var num1 = 0x0;
var num2 = 0x0;
var password = parseInt(pass, 10);
for (var c in nonce) {
c = nonce[c];
if (c!='0') {
if (flag) num2 = password;
flag = false;
}
switch (c) {
case '1':
num1 = num2 & 0xFFFFFF80;
num1 = num1 >>> 7;
num2 ... | 495OpenWebNet password | 10javascript | 19gp7 |
import win32com.client
from win32com.server.util import wrap, unwrap
from win32com.server.dispatcher import DefaultDebugDispatcher
from ctypes import *
import commands
import pythoncom
import winerror
from win32com.server.exception import Exception
clsid =
iid = pythoncom.MakeIID(clsid)
appid =
class VeryPermissive... | 496OLE automation | 3python | cqd9q |
null | 492P-value correction | 11kotlin | xvpws |
(defn sort [table & {:keys [ordering column reverse?]
:or {ordering:lex, column 1}}]
(println table ordering column reverse?))
(sort [1 8 3]:reverse? true)
[1 8 3]:lex 1 true | 494Optional parameters | 6clojure | jzv7m |
module OneTimePad (main) where
import Control.Monad
import Data.Char
import Data.Function (on)
import qualified Data.Text as T
import qualified Data.Text.IO as TI
import Data.Time
import System.Console.GetOpt
import System.Environ... | 497One-time pad | 8haskell | uozv2 |
null | 495OpenWebNet password | 11kotlin | 5iyua |
package main
import (
"fmt"
"sort"
"strings"
)
type indexSort struct {
val sort.Interface
ind []int
}
func (s indexSort) Len() int { return len(s.ind) }
func (s indexSort) Less(i, j int) bool { return s.ind[i] < s.ind[j] }
func (s indexSort) Swap(i, j int) {
s.val.Swap(s.ind[i], s.ind[j])
s.ind[i], ... | 498Order disjoint list items | 0go | 5izul |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class OneTimePad {
public static void main(String[] args) {
String... | 497One-time pad | 9java | mwoym |
use strict;
use warnings;
use feature 'say';
use integer;
sub own_password {
my($password, $nonce) = @_;
my $n1 = 0;
my $n2 = $password;
for my $d (split //, $nonce) {
if ($d == 1) {
$n1 = ($n2 & 0xFFFFFF80) >> 7;
$n2 <<= 25;
} elsif ($d == 2) {
... | 495OpenWebNet password | 2perl | ora8x |
void paint(void)
{
glClearColor(0.3,0.3,0.3,0.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glShadeModel(GL_SMOOTH);
glLoadIdentity();
glTranslatef(-15.0, -15.0, 0.0);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(0.0, 0.0);
glColor3f(0.0, 1.0, 0.0);
glVertex2f(30.0, 0.0);
... | 499OpenGL | 5c | s57q5 |
use strict;
use warnings FATAL => 'all';
use autodie ':all';
use List::Util 'min';
use feature 'say';
sub pmin {
my $array = shift;
my $x = 1;
my @pmin_array;
my $n = scalar @$array;
for (my $index = 0; $index < $n; $index++) {
$pmin_array[$index] = min(@$array[$index], $x);
}
@pmin_array
}
sub cummin {
my ... | 492P-value correction | 2perl | 20ylf |
import Data.List (mapAccumL, sort)
order
:: Ord a
=> [[a]] -> [a]
order [ms, ns] = snd . mapAccumL yu ls $ ks
where
ks = zip ms [(0 :: Int) ..]
ls = zip ns . sort . snd . foldl go (sort ns, []) . sort $ ks
yu ((u, v):us) (_, y)
| v == y = (us, u)
yu ys (x, _) = (ys, x)
go (u:us, ys) (x,... | 498Order disjoint list items | 8haskell | xvrw4 |
int list_cmp(int *a, int la, int *b, int lb)
{
int i, l = la;
if (l > lb) l = lb;
for (i = 0; i < l; i++) {
if (a[i] == b[i]) continue;
return (a[i] > b[i]) ? 1 : -1;
}
if (la == lb) return 0;
return la > lb ? 1 : -1;
} | 500Order two numerical lists | 5c | orh80 |
(expr) # grouping
{expr1;expr2;...} # compound
x(expr1,expr2,...) # process argument list
x{expr1,expr2,...} # process co-expression list
[expr1,expr2,...] # list
expr.F # fiel... | 493Operator precedence | 0go | orw8q |
(expr) # grouping
{expr1;expr2;...} # compound
x(expr1,expr2,...) # process argument list
x{expr1,expr2,...} # process co-expression list
[expr1,expr2,...] # list
expr.F # fiel... | 493Operator precedence | 8haskell | 206ll |
null | 481Pascal's triangle | 20typescript | e2oaq |
Julia Operators in Order of Preference
--------------------------------------------
Syntax .followed by::
Exponentiation ^
Fractions | 493Operator precedence | 9java | 6an3z |
Julia Operators in Order of Preference
--------------------------------------------
Syntax .followed by::
Exponentiation ^
Fractions | 493Operator precedence | 10javascript | ls3cf |
null | 497One-time pad | 11kotlin | tbxf0 |
function ownCalcPass($password, $nonce) {
$msr = 0x7FFFFFFF;
$m_1 = (int)0xFFFFFFFF;
$m_8 = (int)0xFFFFFFF8;
$m_16 = (int)0xFFFFFFF0;
$m_128 = (int)0xFFFFFF80;
$m_16777216 = (int)0xFF000000;
$flag = True;
$num1 = 0;
$num2 = 0;
foreach (str_split($nonce) as $c) {
$num1 = ... | 495OpenWebNet password | 12php | gd942 |
(use 'penumbra.opengl)
(require '[penumbra.app :as app])
(defn init [state]
(app/title! "Triangle")
(clear-color 0.3 0.3 0.3 0)
(shade-model :smooth)
state)
(defn reshape [[x y w h] state]
(ortho-view -30 30 -30 30 -30 30)
(load-identity)
(translate -15 -15)
state)
(defn display [[dt time] state]
(... | 499OpenGL | 6clojure | njpik |
from __future__ import division
import sys
def pminf(array):
x = 1
pmin_list = []
N = len(array)
for index in range(N):
if array[index] < x:
pmin_list.insert(index, array[index])
else:
pmin_list.insert(index, x)
return pmin_list
def cumminf(array):
cumm... | 492P-value correction | 3python | v8m29 |
import java.util.Arrays;
import java.util.BitSet;
import org.apache.commons.lang3.ArrayUtils;
public class OrderDisjointItems {
public static void main(String[] args) {
final String[][] MNs = {{"the cat sat on the mat", "mat cat"},
{"the cat sat on the mat", "cat mat"},
{"A B C A B C A B C... | 498Order disjoint list items | 9java | by2k3 |
As with Common Lisp and Scheme, Lambdatalk uses s-expressions so there is no need for operator precedence.
Such an expression "1+2*3+4" is written {+ 1 {* 2 3} 4} | 493Operator precedence | 11kotlin | dhsnz |
use strict;
use warnings;
use Crypt::OTP;
use Bytes::Random::Secure qw( random_bytes );
print "Message : ", my $message = "show me the monKey", "\n";
my $otp = random_bytes(length $message);
print "Ord(OTP) : ", ( map { ord($_).' ' } (split //, $otp) ) , "\n";
my $cipher = OTP( $otp, $message, 1 );
print "Or... | 497One-time pad | 2perl | k62hc |
def ownCalcPass (password, nonce, test=False):
start = True
num1 = 0
num2 = 0
password = int(password)
if test:
print(% (password))
for c in nonce:
if c != :
if start:
num2 = password
start = False
if test:
print(% (... | 495OpenWebNet password | 3python | i7eof |
p <- c(4.533744e-01, 7.296024e-01, 9.936026e-02, 9.079658e-02, 1.801962e-01,
8.752257e-01, 2.922222e-01, 9.115421e-01, 4.355806e-01, 5.324867e-01,
4.926798e-01, 5.802978e-01, 3.485442e-01, 7.883130e-01, 2.729308e-01,
8.502518e-01, 4.268138e-01, 6.442008e-01, 3.030266e-01, 5.001555e-02,
3.194... | 492P-value correction | 13r | 9xzmg |
(() => {
"use strict"; | 498Order disjoint list items | 10javascript | w2ge2 |
(defn lex? [a b]
(compare a b)) | 500Order two numerical lists | 6clojure | tbafv |
42:my-var
42 "my-var" define | 493Operator precedence | 1lua | fk0dp |
null | 498Order disjoint list items | 11kotlin | rfygo |
import argparse
import itertools
import pathlib
import re
import secrets
import sys
MAGIC =
def make_keys(n, size):
return (secrets.token_hex(size) for _ in range(n))
def make_pad(name, pad_size, key_size):
pad = [
MAGIC,
f,
f,
*make_keys(pad_size... | 497One-time pad | 3python | byvkr |
func openAuthenticationResponse(_password: String, operations: String) -> String? {
var num1 = UInt32(0)
var num2 = UInt32(0)
var start = true
let password = UInt32(_password)!
for c in operations {
if (c!= "0") {
if start {
num2 = password
}
... | 495OpenWebNet password | 17swift | njwil |
int main(int argC,char* argV[])
{
int i,reference;
char *units[UNITS_LENGTH] = {,,,,,,,,,,,,};
double factor, values[UNITS_LENGTH] = {1000.0,1.0,0.01,0.000254,0.00254,0.0254,0.04445,0.1778,0.3048,0.7112,2.1336,1066.8,7467.6};
if(argC!=3)
printf();
else{
for(i=0;argV[2][i]!=00;i++)
argV[2][i] = tolower(a... | 501Old Russian measure of length | 5c | 19lpj |
def pmin(array)
x = 1
pmin_array = []
array.each_index do |i|
pmin_array[i] = [array[i], x].min
abort if pmin_array[i] > 1
end
pmin_array
end
def cummin(array)
cumulative_min = array[0]
arr_cummin = []
array.each do |p|
cumulative_min = [p, cumulative_min].min
arr_cummin.push(cumulative... | 492P-value correction | 14ruby | 5icuj |
null | 498Order disjoint list items | 1lua | 7tmru |
inline int irand(int n)
{
int r, randmax = RAND_MAX/n * n;
while ((r = rand()) >= randmax);
return r / (randmax / n);
}
inline int one_of_n(int n)
{
int i, r = 0;
for (i = 1; i < n; i++) if (!irand(i + 1)) r = i;
return r;
}
int main(void)
{
int i, r[10] = {0};
for (i = 0; i < 1000000; i++, r[one_of_n(10)]++... | 502One of n lines in a file | 5c | tbpf4 |
use std::iter;
#[rustfmt::skip]
const PVALUES:[f64;50] = [
4.533_744e-01, 7.296_024e-01, 9.936_026e-02, 9.079_658e-02, 1.801_962e-01,
8.752_257e-01, 2.922_222e-01, 9.115_421e-01, 4.355_806e-01, 5.324_867e-01,
4.926_798e-01, 5.802_978e-01, 3.485_442e-01, 7.883_130e-01, 2.729_308e-01,
8.502_518e-01, 4.268_138e-01, 6.442... | 492P-value correction | 15rust | 4nl5u |
type cell string
type spec struct {
less func(cell, cell) bool
column int
reverse bool
}
func newSpec() (s spec) { | 494Optional parameters | 0go | 8ga0g |
def orderedSort(Collection table, column = 0, reverse = false, ordering = {x, y -> x <=> y } as Comparator) {
table.sort(false) { x, y -> (reverse ? -1: 1) * ordering.compare(x[column], y[column])}
} | 494Optional parameters | 7groovy | w2hel |
package main
import (
"fmt"
"math"
"math/big"
"strconv"
"strings"
)
type minmult struct {
min int
mult float64
}
var abbrevs = map[string]minmult{
"PAIRs": {4, 2}, "SCOres": {3, 20}, "DOZens": {3, 12},
"GRoss": {2, 144}, "GREATGRoss": {7, 1728}, "GOOGOLs": {6, 1e100},
}
var metr... | 503Numerical and alphabetical suffixes | 0go | quuxz |
sub dsort {
my ($m, $n) = @_;
my %h;
$h{$_}++ for @$n;
map $h{$_}-- > 0 ? shift @$n : $_, @$m;
}
for (split "\n", <<"IN")
the cat sat on the mat | mat cat
the cat sat on the mat | cat mat
A B C A B C A B C | C A C A
A B C A B D A B E | E A D... | 498Order disjoint list items | 2perl | dhanw |
data SorterArgs = SorterArgs { cmp :: String, col :: Int, rev :: Bool } deriving Show
defSortArgs = SorterArgs "lex" 0 False
sorter :: SorterArgs -> [[String]] -> [[String]]
sorter (SorterArgs{..}) = case cmp of
_ -> undefined
main = do
sorter defSortArgs{cmp = "foo", col=1, rev=True}... | 494Optional parameters | 8haskell | lszch |
q)3*2+1
9
q)(3*2)+1 / Brackets give the usual order of precedence
7
q)x:5
q)(x+5; x:20; x-5)
25 20 0 | 493Operator precedence | 2perl | jzu7f |
use strict;
use warnings;
my %suffix = qw( k 1e3 m 1e6 g 1e9 t 1e12 p 1e15 e 1e18 z 1e21 y 1e24 x 1e27
w 1e30 v 1e33 u 1e36 ki 2**10 mi 2**20 gi 2**30 ti 2**40 pi 2**50 ei 2**60
zi 2**70 yi 2**80 xi 2**90 wi 2**100 vi 2**110 ui 2**120 );
local $" = ' ';
print "numbers = ${_}results = @{[ map suffix($_), split ... | 503Numerical and alphabetical suffixes | 2perl | 4nn5d |
q)3*2+1
9
q)(3*2)+1 / Brackets give the usual order of precedence
7
q)x:5
q)(x+5; x:20; x-5)
25 20 0 | 493Operator precedence | 12php | tb8f1 |
(defn rand-seq-elem [sequence]
(let [f (fn [[k old] new]
[(inc k) (if (zero? (rand-int k)) new old)])]
(->> sequence (reduce f [1 nil]) second)))
(defn one-of-n [n]
(rand-seq-elem (range 1 (inc n))))
(let [countmap (frequencies (repeatedly 1000000 #(one-of-n 10)))]
(doseq [[n cnt] (sort countmap... | 502One of n lines in a file | 6clojure | mwxyq |
import java.util.*;
public class OptionalParams { | 494Optional parameters | 9java | 31ozg |
#!/usr/bin/env node
import { writeFileSync, existsSync, readFileSync, unlinkSync } from 'node:fs'; | 497One-time pad | 20typescript | fkwds |
from functools import reduce
from operator import mul
from decimal import *
getcontext().prec = MAX_PREC
def expand(num):
suffixes = [
('greatgross', 7, 12, 3),
('gross', 2, 12, 2),
('dozens', 3, 12, 1),
('pairs', 4, 2, 1),
('scores', 3, 20, 1),
('googols',... | 503Numerical and alphabetical suffixes | 3python | gdd4h |
package main
import (
gl "github.com/chsc/gogl/gl21"
"github.com/go-gl/glfw/v3.2/glfw"
"log"
"runtime"
) | 499OpenGL | 0go | v8d2m |
from __future__ import print_function
def order_disjoint_list_items(data, items):
itemindices = []
for item in set(items):
itemcount = items.count(item)
lastindex = [-1]
for i in range(itemcount):
lastindex.append(data.index(item, lastindex[-1] + 1))
it... | 498Order disjoint list items | 3python | fkede |
function sorter(table, options) {
opts = {}
opts.ordering = options.ordering || 'lexicographic';
opts.column = options.column || 0;
opts.reverse = options.reverse || false; | 494Optional parameters | 10javascript | cqt9j |
q)3*2+1
9
q)(3*2)+1 / Brackets give the usual order of precedence
7
q)x:5
q)(x+5; x:20; x-5)
25 20 0 | 493Operator precedence | 3python | h35jw |
package Palindrome;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT = qw(palindrome palindrome_c palindrome_r palindrome_e);
sub palindrome
{
my $s = (@_ ? shift : $_);
return $s eq reverse $s;
}
sub palindrome_c
{
my $s = (@_ ? shift : $_);
for my $i (0 .. length($s) >> 1)
{
... | 483Palindrome detection | 2perl | rtbgd |
static int
owp(int odd)
{
int ch, ret;
ch = getc(stdin);
if (!odd) {
putc(ch, stdout);
if (ch == EOF || ch == '.')
return EOF;
if (ispunct(ch))
return 0;
owp(odd);
ret... | 504Odd word problem | 5c | pmyby |
double Pi;
double lroots[N];
double weight[N];
double lcoef[N + 1][N + 1] = {{0}};
void lege_coef()
{
int n, i;
lcoef[0][0] = lcoef[1][1] = 1;
for (n = 2; n <= N; n++) {
lcoef[n][0] = -(n - 1) * lcoef[n - 2][0] / n;
for (i = 1; i <= n; i++)
lcoef[n][i] = ((2 * n - 1) * lcoef[n - 1][i - 1]
- (n - 1) * l... | 505Numerical integration/Gauss-Legendre Quadrature | 5c | w2cec |
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
main = do
getArgsAndInitialize
createWindow "Triangle"
displayCallback $= display
matrixMode $= Projection
loadIdentity
ortho2D 0 30 0 30
matrixMode $= Modelview 0
mainLoop
display = do
clear [ColorBuffer]
renderPrimitive Triangles $ do
... | 499OpenGL | 8haskell | el5ai |
package main
import "fmt" | 500Order two numerical lists | 0go | 4nt52 |
package main
import (
"bytes"
"fmt"
"io/ioutil"
)
func main() { | 491Ordered words | 0go | elba6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.