code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
package main import ( "bufio" "bytes" "errors" "flag" "fmt" "io/ioutil" "net/smtp" "os" "strings" ) type Message struct { From string To []string Cc []string Subject string Content string } func (m Message) Bytes() (r []byte) { to := strings.Join(m.To, ",") cc := strings.Join(m.Cc, ",") ...
300Send email
0go
ldpcw
typedef unsigned char bool; void sieve(bool *sv) { int n = 0, s[8], a, b, c, d, e, f, g, h, i, j; for (a = 0; a < 2; ++a) { for (b = 0; b < 10; ++b) { s[0] = a + b; for (c = 0; c < 10; ++c) { s[1] = s[0] + c; for (d = 0; d < 10; ++d) { ...
302Self numbers
5c
vtp2o
int isPrime(unsigned int n) { unsigned int num; if ( n < 2||!(n & 1)) return n == 2; for (num = 3; num <= n/num; num += 2) if (!(n % num)) return 0; return 1; } int main() { unsigned int l,u,i,sum=0; printf(); scanf(,&l,&u); for(i=l;i<=u;i++){ if(isPrime(i)==1) { printf(,i); sum++; ...
303Sequence of primes by trial division
5c
uzpv4
<?php class Example { function foo($x) { return 42 + $x; } } $example = new Example(); $name = 'foo'; echo $example->$name(5), ; echo call_user_func(array($example, $name), 5), ; ?>
299Send an unknown method call
12php
uzwv5
import pyprimes def primorial_prime(_pmax=500): isprime = pyprimes.isprime n, primo = 0, 1 for prime in pyprimes.nprimes(_pmax): n, primo = n+1, primo * prime if isprime(primo-1) or isprime(primo+1): yield n if __name__ == '__main__': pyprimes.warn_probably = False ...
297Sequence of primorial primes
3python
degn1
divisorCount <- function(n) length(Filter(function(x) n %% x == 0, seq_len(n %/% 2))) + 1 smallestWithNDivisors <- function(n) { i <- 1 while(divisorCount(i) != n) i <- i + 1 i } print(sapply(1:15, smallestWithNDivisors))
296Sequence: smallest number with exactly n divisors
13r
txjfz
null
293Sequence: smallest number greater than previous term with exactly n divisors
17swift
2f0lj
sierpinski.triangle = function(n) { len <- 2^(n+1) b <- c(rep(FALSE,len/2),TRUE,rep(FALSE,len/2)) for (i in 1:(len/2)) { cat(paste(ifelse(b,"*"," "),collapse=""),"\n") n <- rep(FALSE,len+1) n[which(b)-1]<-TRUE n[which(b)+1]<-xor(n[which(b)+1],TRUE) b <- n } } sierpinski.triangle(5)
278Sierpinski triangle
13r
4y45y
import javax.mail.* import javax.mail.internet.* public static void simpleMail(String from, String password, String to, String subject, String body) throws Exception { String host = "smtp.gmail.com"; Properties props = System.getProperties(); props.put("mail.smtp.starttls.enable",true); props...
300Send email
7groovy
6073o
int semiprime(int n) { int p, f = 0; for (p = 2; f < 2 && p*p <= n; p++) while (0 == n % p) n /= p, f++; return f + (n > 1) == 2; } int main(void) { int i; for (i = 2; i < 100; i++) if (semiprime(i)) printf(, i); putchar('\n'); return 0; }
304Semiprime
5c
gya45
import java.util.Objects; import java.util.function.Predicate; public class RealNumberSet { public enum RangeType { CLOSED, BOTH_OPEN, LEFT_OPEN, RIGHT_OPEN, } public static class RealSet { private Double low; private Double high; private Predicate<D...
298Set of real numbers
9java
eg6a5
class Example(object): def foo(self, x): return 42 + x name = getattr(Example(), name)(5)
299Send an unknown method call
3python
0kcsq
require 'digest/sha2' puts Digest::SHA256.hexdigest('Rosetta code')
290SHA-256
14ruby
gyz4q
require 'digest' puts Digest::SHA1.hexdigest('Rosetta Code')
289SHA-1
14ruby
i1boh
static void reverse(char *s, int len) { int i, j; char tmp; for (i = 0, j = len - 1; i < len / 2; ++i, --j) tmp = s[i], s[i] = s[j], s[j] = tmp; } static int strsort(const void *s1, const void *s2) { return strcmp(*(char *const *) s1, *(char *const *) s2); } int main(void) { int i, c, ct...
305Semordnilap
5c
2fjlo
>>> def a(answer): print(% (answer, answer)) return answer >>> def b(answer): print(% (answer, answer)) return answer >>> for i in (False, True): for j in (False, True): print () x = a(i) and b(j) print () y = a(i) or b(j) Calculating: x = a(i) and b(j) Calculating: y = a(i) or b(j) Calcul...
284Short-circuit evaluation
3python
tx0fw
module Main (main) where import Network.Mail.SMTP ( Address(..) , htmlPart , plainTextPart , sendMailWithLogin' , simpleMail ) main:: IO () main = sendMailWithLogin' "smtp.example.com"...
300Send email
8haskell
15fps
function realSet(set1, set2, op, values) { const makeSet=(set0)=>{ let res = [] if(set0.rangeType===0){ for(let i=set0.low;i<=set0.high;i++) res.push(i); } else if (set0.rangeType===1) { for(let i=set0.low+1;i<set0.high;i++) res.push(i)...
298Set of real numbers
10javascript
0klsz
(ns test-p.core (:require [clojure.math.numeric-tower :as math])) (defn prime? [a] " Uses trial division to determine if number is prime " (or (= a 2) (and (> a 2) (> (mod a 2) 0) (not (some #(= 0 (mod a %)) (range 3 (inc (int (Math/ceil (math/sqrt a)))) 2)))))) ...
303Sequence of primes by trial division
6clojure
79xr0
class Example def foo 42 end def bar(arg1, arg2, &block) block.call arg1, arg2 end end symbol = :foo Example.new.send symbol Example.new.send( :bar, 1, 2 ) { |x,y| x+y } args = [1, 2] Example.new.send( , *args ) { |x,y| x+y }
299Send an unknown method call
14ruby
op28v
class Example { def foo(x: Int): Int = 42 + x } object Main extends App { val example = new Example val meth = example.getClass.getMethod("foo", classOf[Int]) assert(meth.invoke(example, 5.asInstanceOf[AnyRef]) == 47.asInstanceOf[AnyRef], "Not confirm expectation.") println(s"Successfully completed without...
299Send an unknown method call
16scala
fw4d4
require 'prime' require 'openssl' i, urutan, primorial_number = 1, 1, OpenSSL::BN.new(1) start = Time.now prime_array = Prime.first (500) until urutan > 20 primorial_number *= prime_array[i-1] if (primorial_number - 1).prime_fasttest? || (primorial_number + 1).prime_fasttest? puts urutan += 1 end ...
297Sequence of primorial primes
14ruby
tx7f2
require 'prime' def num_divisors(n) n.prime_division.inject(1){|prod, (_p,n)| prod *= (n + 1) } end def first_with_num_divs(n) (1..).detect{|i| num_divisors(i) == n } end p (1..15).map{|n| first_with_num_divs(n) }
296Sequence: smallest number with exactly n divisors
14ruby
9iamz
use sha2::{Digest, Sha256}; fn hex_string(input: &[u8]) -> String { input.as_ref().iter().map(|b| format!("{:x}", b)).collect() } fn main() {
290SHA-256
15rust
rm3g5
object RosettaSHA256 extends App { def MD5(s: String): String = {
290SHA-256
16scala
hlmja
use sha1::Sha1; fn main() { let mut hash_msg = Sha1::new(); hash_msg.update(b"Rosetta Code"); println!("{}", hash_msg.digest().to_string()); }
289SHA-1
15rust
napi4
my @c = ' @c = (map($_ x 3, @c), map($_.(' ' x length).$_, @c), map($_ x 3, @c)) for 1 .. 3; print join("\n", @c), "\n";
283Sierpinski carpet
2perl
i1xo3
a <- function(x) {cat("a called\n"); x} b <- function(x) {cat("b called\n"); x} tests <- expand.grid(op=list(quote(`||`), quote(`&&`)), x=c(1,0), y=c(1,0)) invisible(apply(tests, 1, function(row) { call <- substitute(op(a(x),b(y)), row) cat(deparse(call), "->", eval(call), "\n\n") }))
284Short-circuit evaluation
13r
i1wo5
import java.util.Properties; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.Message.RecipientType; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class Mail { protected Session session; public Mail(Str...
300Send email
9java
790rj
null
298Set of real numbers
11kotlin
k2dh3
int nonsqr(int n) { return n + (int)(0.5 + sqrt(n)); } int main() { int i; for (i = 1; i < 23; i++) printf(, nonsqr(i)); printf(); for (i = 1; i < 1000000; i++) { double j = sqrt(nonsqr(i)); assert(j != floor(j)); } return 0; }
306Sequence of non-squares
5c
nayi6
typedef unsigned int set_t; void show_set(set_t x, const char *name) { int i; printf(, name); for (i = 0; (1U << i) <= x; i++) if (x & (1U << i)) printf(, i); putchar('\n'); } int main(void) { int i; set_t a, b, c; a = 0; for (i = 0; i < 10; i += 3) a |= (1U << i); show_set(a, ); for (i = 0; i <...
307Set
5c
jca70
import Foundation class MyUglyClass: NSObject { @objc func myUglyFunction() { print("called myUglyFunction") } } let someObject: NSObject = MyUglyClass() someObject.perform(NSSelectorFromString("myUglyFunction"))
299Send an unknown method call
17swift
8bl0v
import BigInt import Foundation extension BinaryInteger { @inlinable public var isPrime: Bool { if self == 0 || self == 1 { return false } else if self == 2 { return true } let max = Self(ceil((Double(self).squareRoot()))) for i in stride(from: 2, through: max, by: 1) where self%...
297Sequence of primorial primes
17swift
fwrdk
use itertools::Itertools; const PRIMES: [u64; 15] = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]; const MAX_DIVISOR: usize = 64; struct DivisorSeq { max_number_of_divisors: u64, index: u64, } impl DivisorSeq { fn new(max_number_of_divisors: u64) -> DivisorSeq { DivisorSeq { ...
296Sequence: smallest number with exactly n divisors
15rust
cne9z
import java.nio._ case class Hash(message: List[Byte]) { val defaultHashes = List(0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0) val hash = { val padded = generatePadding(message) val chunks: List[List[Byte]] = messageToChunks(padded) toHashForm(hashesFromChunks(chunks)) } def genera...
289SHA-1
16scala
txefb
null
300Send email
11kotlin
uzevc
(ns example (:gen-class)) (defn semi-prime? [n] (loop [a 2 b 0 c n] (cond (> b 2) false (<= c 1) (= b 2) (= 0 (rem c a)) (recur a (inc b) (int (/ c a))) :else (recur (inc a) b c)))) (println (filter semi-prime? (range 1 100)))
304Semiprime
6clojure
k2shs
inline int self_desc(unsigned long long xx) { register unsigned int d, x; unsigned char cnt[10] = {0}, dig[10] = {0}; for (d = 0; xx > ~0U; xx /= 10) cnt[ dig[d++] = xx % 10 ]++; for (x = xx; x; x /= 10) cnt[ dig[d++] = x % 10 ]++; while(d-- && dig[x++] == cnt[d]); return d == -1; } int main() { int i; ...
308Self-describing numbers
5c
a4s11
function createSet(low,high,rt) local l,h = tonumber(low), tonumber(high) if l and h then local t = {low=l, high=h} if type(rt) == "string" then if rt == "open" then t.contains = function(d) return low< d and d< high end elseif rt == "closed" then ...
298Set of real numbers
1lua
bvfka
use strict; use English; use Smart::Comments; my @ex1 = consolidate( (['A', 'B'], ['C', 'D']) ); my @ex2 = consolidate( (['A', 'B'], ['B', 'D']) ); my @ex3 = consolidate( (['A', 'B'], ['C', 'D'], ['D', 'B']) ); my @ex4 = consolidate( (['H', 'I', 'K'], ['A', 'B'], ['C', 'D'], ['D', 'B'], ['F', 'G', 'H']) ); exit 0;...
295Set consolidation
2perl
bv3k4
null
296Sequence: smallest number with exactly n divisors
17swift
mo1yk
<?php function isSierpinskiCarpetPixelFilled($x, $y) { while (($x > 0) or ($y > 0)) { if (($x % 3 == 1) and ($y % 3 == 1)) { return false; } $x /= 3; $y /= 3; } return true; } function sierpinskiCarpet($order) { $size = pow(3, $order); for ($y = 0 ; $y <...
283Sierpinski carpet
12php
rm2ge
(ns rosettacode.semordnilaps (:require [clojure.string :as str]) [clojure.java.io:as io ])) (def dict-file (or (first *command-line-args*) "unixdict.txt")) (def dict (-> dict-file io/reader line-seq set)) (defn semordnilap? [word] (let [rev (str/reverse word)] (and (not= word rev) (dict rev))...
305Semordnilap
6clojure
gy14f
def a( bool ) puts bool end def b( bool ) puts bool end [true, false].each do |a_val| [true, false].each do |b_val| puts puts puts puts end end
284Short-circuit evaluation
14ruby
3soz7
package main import ( "fmt" "time" ) func sumDigits(n int) int { sum := 0 for n > 0 { sum += n % 10 n /= 10 } return sum } func max(x, y int) int { if x > y { return x } return y } func main() { st := time.Now() count := 0 var selfs []int i...
302Self numbers
0go
sh6qa
use charnames ':full'; binmode STDOUT, ':utf8'; sub glyph { my($n) = @_; if ($n < 33) { chr 0x2400 + $n } elsif ($n==124) { '<nowiki>|</nowiki>' } elsif ($n==127) { 'DEL' } else { chr $n } } print qq[{|class="wikitable" style="text-align:center;background-color:hsl(39, 90%, 95%)"\n]...
288Show ASCII table
2perl
wrge6
ruby -le'16.times{|y|print*(15-y),*(0..y).map{|x|~y&x>0?:}}'
278Sierpinski triangle
14ruby
kvkhg
fn a(foo: bool) -> bool { println!("a"); foo } fn b(foo: bool) -> bool { println!("b"); foo } fn main() { for i in vec![true, false] { for j in vec![true, false] { println!("{} and {} == {}", i, j, a(i) && b(j)); println!("{} or {} == {}", i, j, a(i) || b(j)); ...
284Short-circuit evaluation
15rust
60i3l
import Control.Monad (forM_) import Text.Printf selfs :: [Integer] selfs = sieve (sumFs [0..]) [0..] where sumFs = zipWith (+) [ a+b+c+d+e+f+g+h+i+j | a <- [0..9] , b <- [0..9] , c <- [0..9] , d <- [0..9] , e <- [0..9] , f <- [0..9] ...
302Self numbers
8haskell
9ijmo
(use 'clojure.contrib.math) (defn nonsqr [#^Integer n] (+ n (floor (+ 0.5 (Math/sqrt n))))) (defn square? [#^Double n] (let [r (floor (Math/sqrt n))] (= (* r r) n))) (doseq [n (range 1 23)] (printf "%s ->%s\n" n (nonsqr n))) (defn verify [] (not-any? square? (map nonsqr (range 1 1000000))) )
306Sequence of non-squares
6clojure
3s2zr
object ShortCircuit { def a(b:Boolean)={print("Called A=%5b".format(b));b} def b(b:Boolean)={print(" -> B=%5b".format(b));b} def main(args: Array[String]): Unit = { val boolVals=List(false,true) for(aa<-boolVals; bb<-boolVals){ print("\nTesting A=%5b AND B=%5b -> ".format(aa, bb)) ...
284Short-circuit evaluation
16scala
9ifm5
null
300Send email
1lua
53wu6
public class SelfNumbers { private static final int MC = 103 * 1000 * 10000 + 11 * 9 + 1; private static final boolean[] SV = new boolean[MC + 1]; private static void sieve() { int[] dS = new int[10_000]; for (int a = 9, i = 9999; a >= 0; a--) { for (int b = 9; b >= 0; b--) { ...
302Self numbers
9java
txuf9
use utf8; package BNum; use overload ( '""' => \&_str, '<=>' => \&_cmp, ); sub new { my $self = shift; bless [@_], ref $self || $self } sub flip { my @a = @{+shift}; $a[2] = !$a[2]; bless \@a } my $brackets = qw/ [ ( ) ] /; sub _str { my $v = sprintf "%.2f", $_[0][0]; $_[0][2] ? $v . ($_[0][1] == 1...
298Set of real numbers
2perl
3sjzs
(require 'clojure.set) (def a (set [1 2 3 4])) (def b #{4 5 6 7}) (a 10) (clojure.set/union a b) (clojure.set/intersection a b) (clojure.set/difference a b) (clojure.set/subset? a b)
307Set
6clojure
15spy
def consolidate(sets): setlist = [s for s in sets if s] for i, s1 in enumerate(setlist): if s1: for s2 in setlist[i+1:]: intersection = s1.intersection(s2) if intersection: s2.update(s1) s1.clear() s1...
295Set consolidation
3python
pu6bm
<?php echo '+' . str_repeat('----------+', 6), PHP_EOL; for ($j = 0 ; $j < 16 ; $j++) { for ($i = 0 ; $i < 6 ; $i++) { $val = 32 + $i * 16 + $j; switch ($val) { case 32: $chr = 'Spc'; break; case 127: $chr = 'Del'; break; default: $chr = chr($val) ; b...
288Show ASCII table
12php
ldncj
use std::iter::repeat; fn sierpinski(order: usize) { let mut triangle = vec!["*".to_string()]; for i in 0..order { let space = repeat(' ').take(2_usize.pow(i as u32)).collect::<String>();
278Sierpinski triangle
15rust
bubkx
private const val MC = 103 * 1000 * 10000 + 11 * 9 + 1 private val SV = BooleanArray(MC + 1) private fun sieve() { val dS = IntArray(10000) run { var a = 9 var i = 9999 while (a >= 0) { for (b in 9 downTo 0) { var c = 9 val s = a + b ...
302Self numbers
11kotlin
op98z
scala -e "for(y<-0 to 15){println(\" \"*(15-y)++(0 to y).map(x=>if((~y&x)>0)\" \"else\" *\")mkString)}"
278Sierpinski triangle
16scala
aga1n
use Net::SMTP; use Authen::SASL; sub send_email {my %o = (from => '', to => [], cc => [], subject => '', body => '', host => '', user => '', password => '', @_); ref $o{$_} or $o{$_} = [$o{$_}] foreach 'to', 'cc'; my $smtp = new Net::SMTP($o{host} ? $o{host} : ()) or die ...
300Send email
2perl
8bc0w
class Setr(): def __init__(self, lo, hi, includelo=True, includehi=False): self.eqn = % (lo, '=' if includelo else '', '=' if includehi else '', hi) def __contains__(self, X): retur...
298Set of real numbers
3python
60h3w
package main import ( "fmt" "strconv" "strings" )
308Self-describing numbers
0go
movyi
use strict; use warnings; use feature 'say'; use List::Util qw(max sum); my ($i, $pow, $digits, $offset, $lastSelf, @selfs) = ( 1, 10, 1, 9, 0, ); my $final = 50; while () { my $isSelf = 1; my $sum = my $start = sum split //, max(($i-$offset), 0); for ( my $j = $start; $j < $i; ...
302Self numbers
2perl
gyw4e
require 'set' tests = [[[:A,:B], [:C,:D]], [[:A,:B], [:B,:D]], [[:A,:B], [:C,:D], [:D,:B]], [[:H,:I,:K], [:A,:B], [:C,:D], [:D,:B], [:F,:G,:H]]] tests.map!{|sets| sets.map(&:to_set)} tests.each do |sets| until sets.combination(2).none?{|a,b| a.merge(b) && sets.delete(b) if a.intersect?(b)...
295Set consolidation
14ruby
a4m1s
mail('hello@world.net', 'My Subject', , );
300Send email
12php
46x5n
import Data.Char count :: Int -> [Int] -> Int count x = length . filter (x ==) isSelfDescribing :: Integer -> Bool isSelfDescribing n = nu == f where nu = digitToInt <$> show n f = (`count` nu) <$> [0 .. length nu - 1] main :: IO () main = do print $ isSelfDescribing <$> [1210, 2020, 21200, 32110...
308Self-describing numbers
8haskell
k2eh0
void main(){
307Set
18dart
uzjvs
DIM n AS Integer, k AS Integer, limit AS Integer INPUT "Enter number to search to: "; limit DIM flags(limit) AS Integer FOR n = 2 TO SQR(limit) IF flags(n) = 0 THEN FOR k = n*n TO limit STEP n flags(k) = 1 NEXT k END IF NEXT n ' Display the primes FOR n = 2 TO limit IF flags(n...
309Sieve of Eratosthenes
4bash
8bd0a
object SetConsolidation extends App { def consolidate[Type](sets: Set[Set[Type]]): Set[Set[Type]] = { var result = sets
295Set consolidation
16scala
qj2xw
for i in range(16): for j in range(32+i, 127+1, 16): if j == 32: k = 'Spc' elif j == 127: k = 'Del' else: k = chr(j) print(% (j,k), end=) print()
288Show ASCII table
3python
x7rwr
func a(v: Bool) -> Bool { print("a") return v } func b(v: Bool) -> Bool { print("b") return v } func test(i: Bool, j: Bool) { println("Testing a(\(i)) && b(\(j))") print("Trace: ") println("\nResult: \(a(i) && b(j))") println("Testing a(\(i)) || b(\(j))") print("Trace: ") println("\nResult: \(a...
284Short-circuit evaluation
17swift
zq8tu
package main import "fmt" func semiprime(n int) bool { nf := 0 for i := 2; i <= n; i++ { for n%i == 0 { if nf == 2 { return false } nf++ n /= i } } return nf == 2 } func main() { for v := 1675; v <= 1680; v++ { ...
304Semiprime
0go
i1mog
int sedol_weights[] = {1, 3, 1, 7, 3, 9}; const char *reject = ; int sedol_checksum(const char *sedol6) { int len = strlen(sedol6); int sum = 0, i; if ( len == 7 ) { fprintf(stderr, , sedol6); return sedol6[6] & 0x7f; } if ( (len > 7) || (len < 6) || ( strcspn(sedol6, reject) != 6 )) { fprintf(...
310SEDOLs
5c
vt42o
class DigitSumer: def __init__(self): sumdigit = lambda n: sum( map( int,str( n ))) self.t = [sumdigit( i ) for i in xrange( 10000 )] def __call__ ( self,n ): r = 0 while n >= 10000: n,q = divmod( n,10000 ) r += self.t[q] return r + self.t[n] d...
302Self numbers
3python
rmxgq
class Rset Set = Struct.new(:lo, :hi, :inc_lo, :inc_hi) do def include?(x) (inc_lo? lo<=x: lo<x) and (inc_hi? x<=hi: x<hi) end def length hi - lo end def to_s end end def initialize(lo=nil, hi=nil, inc_lo=false, inc_hi=false) if lo.nil? and hi.nil? @sets = [] ...
298Set of real numbers
14ruby
mobyj
package main import "fmt" func NumsFromBy(from int, by int, ch chan<- int) { for i := from; ; i+=by { ch <- i } } func Filter(in <-chan int, out chan<- int, prime int) { for { i := <-in if i%prime != 0 {
303Sequence of primes by trial division
0go
0k6sk
import Foundation
278Sierpinski triangle
17swift
h2hj0
import smtplib def sendemail(from_addr, to_addr_list, cc_addr_list, subject, message, login, password, smtpserver='smtp.gmail.com:587'): header = 'From:%s\n'% from_addr header += 'To:%s\n'% ','.join(to_addr_list) header += 'Cc:%s\n'% ','.join(cc_addr_list) hea...
300Send email
3python
opl81
library(RDCOMClient) send.mail <- function(to, title, body) { olMailItem <- 0 ol <- COMCreate("Outlook.Application") msg <- ol$CreateItem(olMailItem) msg[["To"]] <- to msg[["Subject"]] <- title msg[["Body"]] <- body msg$Send() ol$Quit() } send.mail("somebody@somewhere", "Title", "Hello")
300Send email
13r
qjyxs
isSemiprime :: Int -> Bool isSemiprime n = (length factors) == 2 && (product factors) == n || (length factors) == 1 && (head factors) ^ 2 == n where factors = primeFactors n
304Semiprime
8haskell
vtk2k
public class SelfDescribingNumbers{ public static boolean isSelfDescribing(int a){ String s = Integer.toString(a); for(int i = 0; i < s.length(); i++){ String s0 = s.charAt(i) + ""; int b = Integer.parseInt(s0);
308Self-describing numbers
9java
46h58
#[derive(Debug)] enum SetOperation { Union, Intersection, Difference, } #[derive(Debug, PartialEq)] enum RangeType { Inclusive, Exclusive, } #[derive(Debug)] struct CompositeSet<'a> { operation: SetOperation, a: &'a RealSet<'a>, b: &'a RealSet<'a>, } #[derive(Debug)] struct RangeSet {...
298Set of real numbers
15rust
9ipmm
[n | n <- [2..], []==[i | i <- [2..n-1], rem n i == 0]]
303Sequence of primes by trial division
8haskell
cnj94
def in_carpet(x, y): while True: if x == 0 or y == 0: return True elif x% 3 == 1 and y% 3 == 1: return False x /= 3 y /= 3 def carpet(n): for i in xrange(3 ** n): for j in xrange(3 ** n): if in_carpet(i, j): print '*',...
283Sierpinski carpet
3python
naqiz
import java.math.BigInteger; import java.util.ArrayList; import java.util.List; public class SemiPrime{ private static final BigInteger TWO = BigInteger.valueOf(2); public static List<BigInteger> primeDecomp(BigInteger a){
304Semiprime
9java
y846g
function is_self_describing(n) { var digits = Number(n).toString().split("").map(function(elem) {return Number(elem)}); var len = digits.length; var count = digits.map(function(x){return 0}); digits.forEach(function(digit, idx, ary) { if (digit >= count.length) return false ...
308Self-describing numbers
10javascript
hlajh
import java.util.stream.IntStream; public class Test { static IntStream getPrimes(int start, int end) { return IntStream.rangeClosed(start, end).filter(n -> isPrime(n)); } public static boolean isPrime(long x) { if (x < 3 || x % 2 == 0) return x == 2; long max = (long...
303Sequence of primes by trial division
9java
zqutq
chr <- function(n) { rawToChar(as.raw(n)) } idx <- 32 while (idx < 128) { for (i in 0:5) { num <- idx + i if (num<100) cat(" ") cat(num,": ") if (num == 32) { cat("Spc "); next } if (num == 127) { cat("Del "); next } cat(chr(num)," ") } idx <- idx + 6 cat("\n") }
288Show ASCII table
13r
15upn
(defn sedols [xs] (letfn [(sedol [ys] (let [weights [1 3 1 7 3 9] convtonum (map #(Character/getNumericValue %) ys) check (-> (reduce + (map * weights convtonum)) (rem 10) (->> (- 10)) (rem 10))] (str ys check)))] (map #(sedol %) xs))...
310SEDOLs
6clojure
rmhg2
null
303Sequence of primes by trial division
11kotlin
i19o4
package main import ( "fmt" "io/ioutil" "log" "strings" ) func main() {
305Semordnilap
0go
qjfxz
require 'base64' require 'net/smtp' require 'tmail' require 'mime/types' class Email def initialize(from, to, subject, body, options={}) @opts = {:attachments => [], :server => 'localhost'}.update(options) @msg = TMail::Mail.new @msg.from = from @msg.to = to @msg.subject = subject @ms...
300Send email
14ruby
navit
null
304Semiprime
11kotlin
fwldo
null
308Self-describing numbers
11kotlin
ld4cp
inSC <- function(x, y) { while(TRUE) { if(!x||!y) {return(1)} if(x%%3==1&&y%%3==1) {return(0)} x=x%/%3; y=y%/%3; } return(0); } pSierpinskiC <- function(ord, fn="", ttl="", clr="navy") { m=640; abbr="SCR"; dftt="Sierpinski carpet fractal"; n=3^ord-1; M <- matrix(c(0), ncol=n, nrow=n, byrow=TRUE); ...
283Sierpinski carpet
13r
0kasg
def semordnilapWords(source) { def words = [] as Set def semordnilaps = [] source.eachLine { word -> if (words.contains(word.reverse())) semordnilaps << word words << word } semordnilaps }
305Semordnilap
7groovy
158p6
import java.util.Properties import javax.mail.internet.{ InternetAddress, MimeMessage } import javax.mail.Message.RecipientType import javax.mail.{ Session, Transport } class Mail(host: String) { val session = Session.getDefaultInstance(new Properties() { put("mail.smtp.host", host) }) def send(from: String,...
300Send email
16scala
zqgtr
null
303Sequence of primes by trial division
1lua
naci8