code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
function addsub( a, b ) return a+b, a-b end s, d = addsub( 7, 5 ) print( s, d )
348Return multiple values
1lua
q7qx0
user=> (distinct [1 3 2 9 1 2 3 8 8 1 0 2]) (1 3 2 9 8 0) user=>
362Remove duplicate elements
6clojure
5tnuz
recaman :: Int -> [Int] recaman n = fst <$> reverse (go n) where go 0 = [] go 1 = [(0, 1)] go x = let xs@((r, i):_) = go (pred x) back = r - i in ( if 0 < back && not (any ((back ==) . fst) xs) then back else r + i , succ i): ...
361Recaman's sequence
8haskell
p2cbt
M_E; M_PI; sqrt(x); log(x); exp(x); abs(x); fabs(x); floor(x); ceil(x); pow(x,y);
365Real constants and functions
5c
6qp32
(() => { 'use strict'; const main = () => {
358Rep-string
10javascript
okb86
import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; public class RecamanSequence { public static void main(String[] args) { List<Integer> a = new ArrayList<>(); a.add(0); Set<Integer> used = new HashSet<>(); used.add(0); Set<I...
361Recaman's sequence
9java
r6zg0
package main import ( "bytes" "errors" "fmt" "io/ioutil" "os" ) func main() { if err := removeLines("foobar.txt", 1, 2); err != nil { fmt.Println(err) } } func removeLines(fn string, start, n int) (err error) { if start < 1 { return errors.New("invalid request. line n...
360Remove lines from a file
0go
6qx3p
null
356Regular expressions
11kotlin
7ycr4
def repeat(f,n): for i in range(n): f(); def procedure(): print(); repeat(procedure,3);
352Repeat
3python
co39q
local lines = {} for line in (s .. "\n"):gmatch("(.-)\n") do local this = {} for word in line:gmatch("%S+") do table.insert(this, 1, word) end lines[#lines + 1] = table.concat(this, " ") end print(table.concat(lines, "\n"))
349Reverse words in a string
1lua
fandp
fn rot13(string: &str) -> String { string.chars().map(|c| { match c { 'a'..='m' | 'A'..='M' => ((c as u8) + 13) as char, 'n'..='z' | 'N'..='Z' => ((c as u8) - 13) as char, _ => c } }).collect() } fn main () { assert_eq!(rot13("abc"), "nop"); }
338Rot-13
15rust
hcsj2
(() => { const main = () => { console.log( 'First 15 Recaman:\n' + recamanUpto(i => 15 === i) ); console.log( '\n\nFirst duplicated Recaman:\n' + last(recamanUpto( (_, set, rs) => set.size !== rs.length )) ...
361Recaman's sequence
10javascript
bl9ki
static def removeLines(String filename, int startingLine, int lineCount) { def sourceFile = new File(filename).getAbsoluteFile() def outputFile = File.createTempFile("remove", ".tmp", sourceFile.getParentFile()) outputFile.withPrintWriter { outputWriter -> sourceFile.eachLine { line, lineNumber -> ...
360Remove lines from a file
7groovy
d1pn3
null
358Rep-string
11kotlin
p2vb6
(Math/E) (Math/PI) (Math/sqrt x) (Math/log x) (Math/exp x) (Math/abs x) (Math/floor x) (Math/ceil x) (Math/pow x y)
365Real constants and functions
6clojure
lixcb
import System.Environment (getArgs) main = getArgs >>= (\[a, b, c] -> do contents <- fmap lines $ readFile a let b1 = read b :: Int c1 = read c :: Int putStr $ unlines $ concat [take (b1 - 1) contents, drop c1 $ drop b1 contents] )
360Remove lines from a file
8haskell
jmy7g
test = "My name is Lua." pattern = ".*name is (%a*).*" if test:match(pattern) then print("Name found.") end sub, num_matches = test:gsub(pattern, "Hello,%1!") print(sub)
356Regular expressions
1lua
jml71
const char *sa = ; const char *su = ; int is_comb(wchar_t c) { if (c >= 0x300 && c <= 0x36f) return 1; if (c >= 0x1dc0 && c <= 0x1dff) return 1; if (c >= 0x20d0 && c <= 0x20ff) return 1; if (c >= 0xfe20 && c <= 0xfe2f) return 1; return 0; } wchar_t* mb_to_wchar(const char *s) { wchar_t *u; size_t len = mbstow...
366Reverse a string
5c
liwcy
f1 <- function(...){print("coucou")} f2 <-function(f,n){ lapply(seq_len(n),eval(f)) } f2(f1,4)
352Repeat
13r
6qd3e
Symbols = { 1=>'I', 5=>'V', 10=>'X', 50=>'L', 100=>'C', 500=>'D', 1000=>'M' } Subtractors = [ [1000, 100], [500, 100], [100, 10], [50, 10], [10, 1], [5, 1], [1, 0] ] def roman(num) return Symbols[num] if Symbols.has_key?(num) Subtractors.each do |cutPoint, subtractor| return roman(cutPoint) + roman(num - cut...
341Roman numerals/Encode
14ruby
7mari
null
361Recaman's sequence
11kotlin
vdi21
scala> def rot13(s: String) = s map { | case c if 'a' <= c.toLower && c.toLower <= 'm' => c + 13 toChar | case c if 'n' <= c.toLower && c.toLower <= 'z' => c - 13 toChar | case c => c | } rot13: (s: String)String scala> rot13("7 Cities of Gold.") res61: String = 7 Pvgvrf bs Tbyq. scala> rot1...
338Rot-13
16scala
pvobj
local a = {[0]=0} local used = {[0]=true} local used1000 = {[0]=true} local foundDup = false local n = 1 while n<=15 or not foundDup or #used1000<1001 do local nxt = a[n - 1] - n if nxt<1 or used[nxt] ~= nil then nxt = nxt + 2 * n end local alreadyUsed = used[nxt] ~= nil table.insert(a, nxt...
361Recaman's sequence
1lua
ufnvl
struct RomanNumeral { symbol: &'static str, value: u32 } const NUMERALS: [RomanNumeral; 13] = [ RomanNumeral {symbol: "M", value: 1000}, RomanNumeral {symbol: "CM", value: 900}, RomanNumeral {symbol: "D", value: 500}, RomanNumeral {symbol: "CD", value: 400}, RomanNumeral {symbol: "C", va...
341Roman numerals/Encode
15rust
j9e72
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; public class RemoveLines { public static void main(String[] args) {
360Remove lines from a file
9java
ufdvv
4.times{ puts } def repeat(proc,num) num.times{ proc.call } end repeat(->{ puts }, 4)
352Repeat
14ruby
2nylw
val romanDigits = Map( 1 -> "I", 5 -> "V", 10 -> "X", 50 -> "L", 100 -> "C", 500 -> "D", 1000 -> "M", 4 -> "IV", 9 -> "IX", 40 -> "XL", 90 -> "XC", 400 -> "CD", 900 -> "CM") val romanDigitsKeys = romanDigits.keysIterator.toList sortBy (x => -x) def toRoman(n: Int): String = romanDigitsKeys find (_ >...
341Roman numerals/Encode
16scala
b2qk6
fn repeat(f: impl FnMut(usize), n: usize) { (0..n).for_each(f); }
352Repeat
15rust
vdm2t
def repeat[A](n:Int)(f: => A)= ( 0 until n).foreach(_ => f) repeat(3) { println("Example") }
352Repeat
16scala
4zl50
package main import "fmt" type matrix [][]float64 func (m matrix) print() { for _, r := range m { fmt.Println(r) } fmt.Println("") } func main() { m := matrix{ { 1, 2, -1, -4}, { 2, 3, -1, -11}, {-2, 0, -3, 22}, } m.print() rref(m) m.print() } func ...
364Reduced row echelon form
0go
kc3hz
null
360Remove lines from a file
11kotlin
980mh
use File::Copy qw(move); use File::Spec::Functions qw(catfile rootdir); move 'input.txt', 'output.txt'; move 'docs', 'mydocs'; move (catfile rootdir, 'input.txt'), (catfile rootdir, 'output.txt'); move (catfile rootdir, 'docs'), (catfile rootdir, 'mydocs');
353Rename a file
2perl
kc4hc
sub foo { my ($a, $b) = @_; return $a + $b, $a * $b; }
348Return multiple values
2perl
2d2lf
use bignum; $max = 1000; $remaining += $_ for 1..$max; my @recamans = 0; my $previous = 0; while ($remaining > 0) { $term++; my $this = $previous - $term; $this = $previous + $term unless $this > 0 and !$seen{$this}; push @recamans, $this; $dup = $term if !$dup and defined $seen{$this}; $remaining ...
361Recaman's sequence
2perl
0jrs4
enum Pivoting { NONE({ i, it -> 1 }), PARTIAL({ i, it -> - (it[i].abs()) }), SCALED({ i, it -> - it[i].abs()/(it.inject(0) { sum, elt -> sum + elt.abs() } ) }); public final Closure comparer private Pivoting(Closure c) { comparer = c } } def isReducibleMatrix = { matrix -> def m =...
364Reduced row echelon form
7groovy
g3n46
(defn reverse-string [s] "Returns a string with all characters in reverse" (apply str (reduce conj '() s)))
366Reverse a string
6clojure
4z85o
function addsub($x, $y) { return array($x + $y, $x - $y); }
348Return multiple values
12php
sjsqs
import Data.List (find) rref :: Fractional a => [[a]] -> [[a]] rref m = f m 0 [0 .. rows - 1] where rows = length m cols = length $ head m f m _ [] = m f m lead (r: rs) | indices == Nothing = m | otherwise = f m' (lead' + 1) rs where...
364Reduced row echelon form
8haskell
np7ie
function remove( filename, starting_line, num_lines ) local fp = io.open( filename, "r" ) if fp == nil then return nil end content = {} i = 1; for line in fp:lines() do if i < starting_line or i >= starting_line + num_lines then content[#content+1] = line end i = i + 1 end i...
360Remove lines from a file
1lua
co892
foreach (qw(1001110011 1110111011 0010010010 1010101010 1111111111 0100101101 0100100 101 11 00 1)) { print "$_\n"; if (/^(.+)\1+(.*$)(?(?{ substr($1, 0, length $2) eq $2 })|(?!))/) { print ' ' x length $1, "$1\n\n"; } else { print " (no repeat)\n\n"; } }
358Rep-string
2perl
ys06u
func repeat(n: Int, f: () -> ()) { for _ in 0..<n { f() } } repeat(4) { println("Example") }
352Repeat
17swift
li6c2
<?php rename('input.txt', 'output.txt'); rename('docs', 'mydocs'); rename('/input.txt', '/output.txt'); rename('/docs', '/mydocs'); ?>
353Rename a file
12php
3xizq
<?php $a = array(); array_push($a, 0); $used = array(); array_push($used, 0); $used1000 = array(); array_push($used1000, 0); $foundDup = false; $n = 1; while($n <= 15 || !$foundDup || count($used1000) < 1001) { $next = $a[$n - 1] - $n; if ($next < 1 || in_array($next, $used)) { $next += 2 * $n; } $alreadyUsed...
361Recaman's sequence
12php
5tdus
import "io/ioutil" data, err := ioutil.ReadFile(filename) sv := string(data)
363Read entire file
0go
xgvwf
def fileContent = new File("c:\\file.txt").text
363Read entire file
7groovy
p2mbo
print join(" ", reverse split), "\n" for <DATA>; __DATA__ ---------- Ice and Fire ------------ fire, in end will world the say Some ice. in say Some desire of tasted I've what From fire. favor who those with hold I ... elided paragraph last ... Frost Robert -----------------------
349Reverse words in a string
2perl
jmr7f
import java.util.*; import java.lang.Math; import org.apache.commons.math.fraction.Fraction; import org.apache.commons.math.fraction.FractionConversionException; class Matrix { LinkedList<LinkedList<Fraction>> matrix; int numRows; int numCols; static class Coordinate { int row; int col; Coordinate(int r,...
364Reduced row echelon form
9java
qrvxa
do text <- readFile filepath
363Read entire file
8haskell
yse66
import os os.rename(, ) os.rename(, ) os.rename(os.sep + , os.sep + ) os.rename(os.sep + , os.sep + )
353Rename a file
3python
blgkr
<?php function strInv ($string) { $str_inv = '' ; for ($i=0,$s=count($string);$i<$s;$i++){ $str_inv .= implode(' ',array_reverse(explode(' ',$string[$i]))); $str_inv .= '<br>'; } return $str_inv; } $string[] = ; $string[] = ; $string[] = ; $string[] = ; $string[] = ; $string[] = ; $s...
349Reverse words in a string
12php
tedf1
SELECT translate( 'The quick brown fox jumps over the lazy dog.', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm' ) FROM dual;
338Rot-13
19sql
e4dau
fmt.Println(strings.Repeat("ha", 5))
359Repeat a string
0go
qrrxz
def addsub(x, y): return x + y, x - y
348Return multiple values
3python
vfv29
null
364Reduced row echelon form
10javascript
ibrol
print unless $. >= $from && $. <= $to;
360Remove lines from a file
2perl
w45e6
$string = "I am a string"; if ($string =~ /string$/) { print "Ends with 'string'\n"; } if ($string !~ /^You/) { print "Does not start with 'You'\n"; }
356Regular expressions
2perl
faxd7
println 'ha' * 5
359Repeat a string
7groovy
1vvp6
addsub <- function(x, y) list(add=(x + y), sub=(x - y))
348Return multiple values
13r
9o9mg
from itertools import islice class Recamans(): def __init__(self): self.a = None self.n = None def __call__(self): nxt = 0 a, n = {nxt}, 0 self.a = a self.n = n yield nxt while True: an1, n = nxt, n + 1 ...
361Recaman's sequence
3python
8h70o
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class ReadFile { public static void main(String[] args) throws IOException{ String fileContents = readEntireFile("./foo.txt"); } private static String readEntireFile(String filename) throws IOException { ...
363Read entire file
9java
d1hn9
def is_repeated(text): 'check if the first part of the string is repeated throughout the string' for x in range(len(text) if text.startswith(text[x:]): return x return 0 matchstr = for line in matchstr.split(): ln = is_repeated(line) print('%r has a repetition length of%i i.e.%s' ...
358Rep-string
3python
m08yh
func rot13char(c: UnicodeScalar) -> UnicodeScalar { switch c { case "A"..."M", "a"..."m": return UnicodeScalar(UInt32(c) + 13) case "N"..."Z", "n"..."z": return UnicodeScalar(UInt32(c) - 13) default: return c } } func rot13(str: String) -> String { return String(map(str.unicodeScalars){ c in Ch...
338Rot-13
17swift
7mxrq
visited <- vector('logical', 1e8) terms <- vector('numeric') in_a_interval <- function(v) { visited[[v+1]] } add_value <- function(v) { visited[[v+1]] <<- TRUE terms <<- append(terms, v) } add_value(0) step <- 1 value <- 0 founddup <- FALSE repeat { if ((value-step>0) && (!in_a_interval(value-step))) { val...
361Recaman's sequence
13r
xg5w2
null
364Reduced row echelon form
11kotlin
1vmpd
package main import ( "fmt" "math" "math/big" ) func main() {
365Real constants and functions
0go
p26bg
var fso=new ActiveXObject("Scripting.FileSystemObject"); var f=fso.OpenTextFile("c:\\myfile.txt",1); var s=f.ReadAll(); f.Close(); try{alert(s)}catch(e){WScript.Echo(s)}
363Read entire file
10javascript
6qa38
$string = 'I am a string'; if (preg_match('/string$/', $string)) { echo ; } $string = preg_replace('/\ba\b/', 'another', $string); echo ;
356Regular expressions
12php
h92jf
concat $ replicate 5 "ha"
359Repeat a string
8haskell
m00yf
function ToReducedRowEchelonForm ( M ) local lead = 1 local n_rows, n_cols = #M, #M[1] for r = 1, n_rows do if n_cols <= lead then break end local i = r while M[i][lead] == 0 do i = i + 1 if n_rows == i then i = r lead = lead ...
364Reduced row echelon form
1lua
au91v
println ((-22).abs())
365Real constants and functions
7groovy
7ydrz
exp 1 pi sqrt x log x exp x abs x floor x ceiling x x ** y x ^ y x ^^ y
365Real constants and functions
8haskell
fajd1
text = '''\ ---------- Ice and Fire ------------ fire, in end will world the say Some ice. in say Some desire of tasted I've what From fire. favor who those with hold I ... elided paragraph last ... Frost Robert -----------------------''' for line in text.split('\n'): print(' '.join(line.split()[::-1]))
349Reverse words in a string
3python
h97jw
-- -- This only works under Oracle and has the limitation of 1 to 3999 SQL> SELECT to_char(1666, 'RN') urcoman, to_char(1666, 'rn') lcroman FROM dual; URCOMAN LCROMAN --------------- --------------- MDCLXVI mdclxvi
341Roman numerals/Encode
19sql
a581t
import fileinput, sys fname, start, count = sys.argv[1:4] start, count = int(start), int(count) for line in fileinput.input(fname, inplace=1, backup='.orig'): if start <= fileinput.lineno() < start + count: pass else: print line.rstrip() fileinput.close()
360Remove lines from a file
3python
xg4wr
import java.io.File fun main(args: Array<String>) { println(File("unixdict.txt").readText(charset = Charsets.UTF_8)) }
363Read entire file
11kotlin
0j4sf
import re string = if re.search('string$', string): print() string = re.sub(, , string) print(string)
356Regular expressions
3python
teqfw
File.rename('input.txt', 'output.txt') File.rename('/input.txt', '/output.txt') File.rename('docs', 'mydocs') File.rename('/docs', '/mydocs')
353Rename a file
14ruby
1v7pw
whack <- function(s) { paste( rev( unlist(strsplit(s, " "))), collapse=' ' ) } poem <- unlist( strsplit( '------------ Eldorado ---------- ... here omitted lines ... Mountains the "Over Moon, the Of Shadow, the of Valley the Down ride," boldly Ride, replied,--- shade The Eldorado!" for seek you "If Poe Edgar ----...
349Reverse words in a string
13r
g3547
func ator(var n: Int) -> String { var result = "" for (value, letter) in [( 1000, "M"), ( 900, "CM"), ( 500, "D"), ( 400, "CD"), ( 100, "C"), ( 90, "XC"), ( 50, "L"), ( 40, "XL"), ( 10, "X"), ( ...
341Roman numerals/Encode
17swift
ry1gg
require 'set' a = [0] used = Set[0] used1000 = Set[0] foundDup = false n = 1 while n <= 15 or not foundDup or used1000.size < 1001 nxt = a[n - 1] - n if nxt < 1 or used === nxt then nxt = nxt + 2 * n end alreadyUsed = used === nxt a << nxt if not alreadyUsed then used << nxt ...
361Recaman's sequence
14ruby
ibhoh
ar = %w(1001110011 1110111011 0010010010 1010101010 1111111111 0100101101 0100100 101 11 00 1) ar.each do |str| rep_pos = (str.size/2).downto(1).find{|pos| str.start_with? str[pos..-1]} puts str, rep_pos? *rep_pos + str[0, rep_pos]: , ...
358Rep-string
14ruby
coi9k
pattern <- "string" text1 <- "this is a matching string" text2 <- "this does not match"
356Regular expressions
13r
ibao5
String reverse(String s) => new String.fromCharCodes(s.runes.toList().reversed);
366Reverse a string
18dart
3xkzz
use std::fs; fn main() { let err = "File move error"; fs::rename("input.txt", "output.txt").ok().expect(err); fs::rename("docs", "mydocs").ok().expect(err); fs::rename("/input.txt", "/output.txt").ok().expect(err); fs::rename("/docs", "/mydocs").ok().expect(err); }
353Rename a file
15rust
auj14
import scala.language.implicitConversions import java.io.File object Rename0 { def main(args: Array[String]) {
353Rename a file
16scala
xgbwg
def addsub(x, y) [x + y, x - y] end
348Return multiple values
14ruby
5z5uj
import scala.collection.mutable object RecamansSequence extends App { val (a, used) = (mutable.ArrayBuffer[Int](0), mutable.BitSet()) var (foundDup, hop, nUsed1000) = (false, 1, 0) while (nUsed1000 < 1000) { val _next = a(hop - 1) - hop val next = if (_next < 1 || used.contains(_next)) _next + 2 * hop e...
361Recaman's sequence
16scala
te1fb
Math.E;
365Real constants and functions
9java
0juse
fn main() { let strings = vec![ String::from("1001110011"), String::from("1110111011"), String::from("0010010010"), String::from("1010101010"), String::from("1111111111"), String::from("0100101101"), String::from("0100100"), String::from("101"), ...
358Rep-string
15rust
lincc
object RepString extends App { def repsOf(s: String) = s.trim match { case s if s.length < 2 => Nil case s => (1 to (s.length/2)).map(s take _) .filter(_ * s.length take s.length equals s) } val tests = Array( "1001110011", "1110111011", "0010010010", "1010101010", "1111111111...
358Rep-string
16scala
uftv8
public static String repeat(String str, int times) { StringBuilder sb = new StringBuilder(str.length() * times); for (int i = 0; i < times; i++) sb.append(str); return sb.toString(); } public static void main(String[] args) { System.out.println(repeat("ha", 5)); }
359Repeat a string
9java
faadv
fn multi_hello() -> (&'static str, i32) { ("Hello",42) } fn main() { let (str,num)=multi_hello(); println!("{},{}",str,num); }
348Return multiple values
15rust
4345u
package main import "fmt" func uniq(list []int) []int { unique_set := make(map[int]bool, len(list)) for _, x := range list { unique_set[x] = true } result := make([]int, 0, len(unique_set)) for x := range unique_set { result = append(result, x) } return result } func main() { fmt.Println(uniq([]int{1, 2,...
362Remove duplicate elements
0go
w4veg
Math.E Math.PI Math.sqrt(x) Math.log(x) Math.exp(x) Math.abs(x) Math.floor(x) Math.ceil(x) Math.pow(x,y)
365Real constants and functions
10javascript
d17nu
require 'tempfile' def remove_lines(filename, start, num) tmp = Tempfile.open(filename) do |fp| File.foreach(filename) do |line| if $. >= start and num > 0 num -= 1 else fp.puts line end end fp end puts if num > 0 FileUtils.copy(tmp.path, filename) tmp.unlink en...
360Remove lines from a file
14ruby
s7rqw
String.prototype.repeat = function(n) { return new Array(1 + (n || 0)).join(this); } console.log("ha".repeat(5));
359Repeat a string
10javascript
yss6r
def addSubMult(x: Int, y: Int) = (x + y, x - y, x * y)
348Return multiple values
16scala
7m7r9
def list = [1, 2, 3, 'a', 'b', 'c', 2, 3, 4, 'b', 'c', 'd'] assert list.size() == 12 println " Original List: ${list}"
362Remove duplicate elements
7groovy
blmky
extern crate rustc_serialize; extern crate docopt; use docopt::Docopt; use std::io::{BufReader,BufRead}; use std::fs::File; const USAGE: &'static str = " Usage: rosetta <start> <count> <file> "; #[derive(Debug, RustcDecodable)] struct Args { arg_start: usize, arg_count: usize, arg_file: String, } fn ma...
360Remove lines from a file
15rust
0j7sl
null
363Read entire file
1lua
8hg0e