code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
from collections import defaultdict from heapq import nlargest data = [('Employee Name', 'Employee ID', 'Salary', 'Department'), ('Tyler Bennett', 'E10297', 32000, 'D101'), ('John Rappl', 'E21437', 47000, 'D050'), ('George Woltman', 'E00127', 53500, 'D101'), ('Adam Smith', 'E63535', 180...
115Top rank per group
3python
p7lbm
Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win32 Type , or for more information. >>> from math import degrees, radians, sin, cos, tan, asin, acos, atan, pi >>> rad, deg = pi/4, 45.0 >>> print(, sin(rad), sin(radians(deg))) Sine: 0.7071067811865475 0.7071067811865475 >>> print(, cos(r...
111Trigonometric functions
3python
4ly5k
dfr <- read.csv(tc <- textConnection( "Employee Name,Employee ID,Salary,Department Tyler Bennett,E10297,32000,D101 John Rappl,E21437,47000,D050 George Woltman,E00127,53500,D101 Adam Smith,E63535,18000,D202 Claire Buckman,E39876,27800,D202 David McClellan,E04242,41500,D101 Rich Holcomb,E01234,49500,D202 Nathan Adams,E41...
115Top rank per group
13r
j5y78
deg <- function(radians) 180*radians/pi rad <- function(degrees) degrees*pi/180 sind <- function(ang) sin(rad(ang)) cosd <- function(ang) cos(rad(ang)) tand <- function(ang) tan(rad(ang)) asind <- function(v) deg(asin(v)) acosd <- function(v) deg(acos(v)) atand <- function(v) deg(atan(v)) r <- pi/3 rd <- deg(r) print...
111Trigonometric functions
13r
2ytlg
<?php $str = 'Hello,How,Are,You,Today'; echo implode('.', explode(',', $str)); ?>
116Tokenize a string
12php
1jlpq
module TicTacToe LINES = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]] class Game def initialize(player_1_class, player_2_class) @board = Array.new(10) @current_player_id = 0 @players = [player_1_class.new(self, ), player_2_class.new(self, )] puts end attr...
117Tic-tac-toe
14ruby
topf2
from collections import namedtuple Node = namedtuple('Node', 'data, left, right') tree = Node(1, Node(2, Node(4, Node(7, None, None), None), Node(5, None, None)), Node(3, Node(6, ...
113Tree traversal
3python
l6ncv
public void move(int n, int from, int to, int via) { if (n == 1) { System.out.println("Move disk from pole " + from + " to pole " + to); } else { move(n - 1, from, via, to); move(1, from, to, via); move(n - 1, via, to, from); } }
119Towers of Hanoi
9java
g2n4m
use GameState::{ComputerWin, Draw, PlayerWin, Playing}; use rand::prelude::*; #[derive(PartialEq, Debug)] enum GameState { PlayerWin, ComputerWin, Draw, Playing, } type Board = [[char; 3]; 3]; fn main() { let mut rng = StdRng::from_entropy(); let mut board: Board = [['1', '2', '3'], ['4', '...
117Tic-tac-toe
15rust
zi1to
function move(n, a, b, c) { if (n > 0) { move(n-1, a, c, b); console.log("Move disk from " + a + " to " + c); move(n-1, b, a, c); } } move(4, "A", "B", "C");
119Towers of Hanoi
10javascript
kg3hq
package object tictactoe { val Human = 'X' val Computer = 'O' val BaseBoard = ('1' to '9').toList val WinnerLines = List((0,1,2), (3,4,5), (6,7,8), (0,3,6), (1,4,7), (2,5,8), (0,4,8), (2,4,6)) val randomGen = new util.Random(System.currentTimeMillis) } package tictactoe { class Board(aBoard : List[Char] =...
117Tic-tac-toe
16scala
yfw63
require data = <<EOS Employee Name,Employee ID,Salary,Department Tyler Bennett,E10297,32000,D101 John Rappl,E21437,47000,D050 George Woltman,E00127,53500,D101 Adam Smith,E63535,18000,D202 Claire Buckman,E39876,27800,D202 David McClellan,E04242,41500,D101 Rich Holcomb,E01234,49500,D202 Nathan Adams,E41298,21900,D050 R...
115Top rank per group
14ruby
ahv1s
radians = Math::PI / 4 degrees = 45.0 def deg2rad(d) d * Math::PI / 180 end def rad2deg(r) r * 180 / Math::PI end puts puts puts arcsin = Math.asin(Math.sin(radians)) puts arccos = Math.acos(Math.cos(radians)) puts arctan = Math.atan(Math.tan(radians)) puts
111Trigonometric functions
14ruby
rv9gs
--Setup DROP TABLE IF EXISTS board; CREATE TABLE board (p CHAR, r INTEGER, c INTEGER); INSERT INTO board VALUES('.', 0, 0),('.', 0, 1),('.', 0, 2),('.', 1, 0),('.', 1, 1),('.', 1, 2),('.', 2, 0),('.', 2, 1),('.', 2, 2); -- Use a trigger for move events DROP TRIGGER IF EXISTS after_moved; CREATE TRIGGER after_moved af...
117Tic-tac-toe
19sql
c3s9p
text = tokens = text.split(',') print ('.'.join(tokens))
116Tokenize a string
3python
yfx6q
#[derive(Debug)] struct Employee<S> {
115Top rank per group
15rust
ekuaj
import Darwin enum Token: CustomStringConvertible { case cross, circle func matches(tokens: [Token?]) -> Bool { for token in tokens { guard let t = token, t == self else { return false } } return true } func emptyCell(in tokens: [Token?]) -> Int? { if tokens[0] == nil && tokens[1] == self ...
117Tic-tac-toe
17swift
f8bdk
null
111Trigonometric functions
15rust
7ucrc
import scala.io.Source import scala.language.implicitConversions import scala.language.reflectiveCalls import scala.collection.immutable.TreeMap object TopRank extends App { val topN = 3 val rawData = """Employee Name;Employee ID;Salary;Department |Tyler Bennett;E10297;32000;D101 |Jo...
115Top rank per group
16scala
q1gxw
import scala.math._ object Gonio extends App {
111Trigonometric functions
16scala
kgvhk
BinaryTreeNode = Struct.new(:value, :left, :right) do def self.from_array(nested_list) value, left, right = nested_list if value self.new(value, self.from_array(left), self.from_array(right)) end end def walk_nodes(order, &block) order.each do |node| case node when :left then ...
113Tree traversal
14ruby
vmf2n
text <- "Hello,How,Are,You,Today" junk <- strsplit(text, split=",") print(paste(unlist(junk), collapse="."))
116Tokenize a string
13r
to1fz
null
119Towers of Hanoi
11kotlin
2ysli
#![feature(box_syntax, box_patterns)] use std::collections::VecDeque; #[derive(Debug)] struct TreeNode<T> { value: T, left: Option<Box<TreeNode<T>>>, right: Option<Box<TreeNode<T>>>, } enum TraversalMethod { PreOrder, InOrder, PostOrder, LevelOrder, } impl<T> TreeNode<T> { pub fn new...
113Tree traversal
15rust
u9tvj
case class IntNode(value: Int, left: Option[IntNode] = None, right: Option[IntNode] = None) { def preorder(f: IntNode => Unit) { f(this) left.map(_.preorder(f))
113Tree traversal
16scala
g264i
CREATE TABLE EMP ( EMP_ID varchar2(6 CHAR), EMP_NAMEvarchar2(20 CHAR), DEPT_ID varchar2(4 CHAR), SALARY NUMBER(10,2) ); INSERT INTO EMP (EMP_ID, EMP_NAME, DEPT_ID, SALARY) VALUES ('E21437','John Rappl','D050',47000); INSERT INTO EMP (EMP_ID, EMP_NAME, DEPT_ID, SALARY) VALUES ('E10297','Tyler Bennett','D101',32000)...
115Top rank per group
19sql
8wj02
puts .split(',').join('.')
116Tokenize a string
14ruby
9zsmz
fn main() { let s = "Hello,How,Are,You,Today"; let tokens: Vec<&str> = s.split(",").collect(); println!("{}", tokens.join(".")); }
116Tokenize a string
15rust
c309z
struct Employee { var name: String var id: String var salary: Int var department: String } let employees = [ Employee(name: "Tyler Bennett", id: "E10297", salary: 32000, department: "D101"), Employee(name: "John Rappl", id: "E21437", salary: 47000, department: "D050"), Employee(name: "George Woltman", id...
115Top rank per group
17swift
1j2pt
println("Hello,How,Are,You,Today" split "," mkString ".")
116Tokenize a string
16scala
vmi2s
function move(n, src, dst, via) if n > 0 then move(n - 1, src, via, dst) print(src, 'to', dst) move(n - 1, via, dst, src) end end move(4, 1, 2, 3)
119Towers of Hanoi
1lua
vm02x
class TreeNode<T> { let value: T let left: TreeNode? let right: TreeNode? init(value: T, left: TreeNode? = nil, right: TreeNode? = nil) { self.value = value self.left = left self.right = right } func preOrder(function: (T) -> Void) { function(value) if l...
113Tree traversal
17swift
2ydlj
let text = "Hello,How,Are,You,Today" let tokens = text.components(separatedBy: ",")
116Tokenize a string
17swift
mtqyk
sub hanoi { my ($n, $from, $to, $via) = (@_, 1, 2, 3); if ($n == 1) { print "Move disk from pole $from to pole $to.\n"; } else { hanoi($n - 1, $from, $via, $to); hanoi(1, $from, $to, $via); hanoi($n - 1, $via, $to, $from); }; };
119Towers of Hanoi
2perl
sauq3
function move($n,$from,$to,$via) { if ($n === 1) { print(); } else { move($n-1,$from,$via,$to); move(1,$from,$to,$via); move($n-1,$via,$to,$from); } }
119Towers of Hanoi
12php
u98v5
def hanoi(ndisks, startPeg=1, endPeg=3): if ndisks: hanoi(ndisks-1, startPeg, 6-startPeg-endPeg) print % (ndisks, startPeg, endPeg) hanoi(ndisks-1, 6-startPeg-endPeg, endPeg) hanoi(ndisks=4)
119Towers of Hanoi
3python
0e5sq
hanoimove <- function(ndisks, from, to, via) { if (ndisks == 1) { cat("move disk from", from, "to", to, "\n") } else { hanoimove(ndisks - 1, from, via, to) hanoimove(1, from, to, via) hanoimove(ndisks - 1, via, to, from) } } hanoimove(4, 1, 2, 3)
119Towers of Hanoi
13r
wble5
def move(num_disks, start=0, target=1, using=2) if num_disks == 1 @towers[target] << @towers[start].pop puts else move(num_disks-1, start, using, target) move(1, start, target, using) move(num_disks-1, using, target, start) end end n = 5 @towers = [[*1..n].reverse, [], []] move(n)
119Towers of Hanoi
14ruby
oxg8v
fn move_(n: i32, from: i32, to: i32, via: i32) { if n > 0 { move_(n - 1, from, via, to); println!("Move disk from pole {} to pole {}", from, to); move_(n - 1, via, to, from); } } fn main() { move_(4, 1,2,3); }
119Towers of Hanoi
15rust
iqrod
def move(n: Int, from: Int, to: Int, via: Int) : Unit = { if (n == 1) { Console.println("Move disk from pole " + from + " to pole " + to) } else { move(n - 1, from, via, to) move(1, from, to, via) move(n - 1, via, to, from) } }
119Towers of Hanoi
16scala
f8hd4
func hanoi(n:Int, a:String, b:String, c:String) { if (n > 0) { hanoi(n - 1, a, c, b) println("Move disk from \(a) to \(c)") hanoi(n - 1, b, a, c) } } hanoi(4, "A", "B", "C")
119Towers of Hanoi
17swift
8w40v
int main(void) { int nprimes = 1000000; int nmax = ceil(nprimes*(log(nprimes)+log(log(nprimes))-0.9385)); int i, j, m, k; int *a; k = (nmax-2)/2; a = (int *)calloc(k + 1, sizeof(int)); for(i = 0; i <= k; i++)a[i] = 2*i+1; for (i = 1; (i+1)*i*2 <= k; i++) for (j ...
120The sieve of Sundaram
5c
xplwu
package main import ( "fmt" "math" "rcu" "time" ) func sos(n int) []int { if n < 3 { return []int{} } var primes []int k := (n-3)/2 + 1 marked := make([]bool, k)
120The sieve of Sundaram
0go
l6xcw
import Data.List (intercalate, transpose) import Data.List.Split (chunksOf) import qualified Data.Set as S import Text.Printf (printf) sundaram :: Integral a => a -> [a] sundaram n = [ succ (2 * x) | x <- [1 .. m], x `S.notMember` excluded ] where m = div (pred n) 2 excluded = S.fromLis...
120The sieve of Sundaram
8haskell
1jyps
(() => { "use strict";
120The sieve of Sundaram
10javascript
p76b7
use strict; use warnings; use feature 'say'; my @sieve; my $nth = 1_000_000; my $k = 2.4 * $nth * log($nth) / 2; $sieve[$k] = 0; for my $i (1 .. $k) { my $j = $i; while ((my $l = $i + $j + 2 * $i * $j) < $k) { $sieve[$l] = 1; $j++ } } $sieve[0] = 1; my @S = (grep { $_ } map { ! $sieve[$_]...
120The sieve of Sundaram
2perl
8w50w
from numpy import log def sieve_of_Sundaram(nth, print_all=True): assert nth > 0, k = int((2.4 * nth * log(nth)) integers_list = [True] * k for i in range(1, k): j = i while i + j + 2 * i * j < k: integers_list[i + j + 2 * i * j] = False j += 1 pcount ...
120The sieve of Sundaram
3python
ox481
def sieve_of_sundaram(upto) n = (2.4 * upto * Math.log(upto)) / 2 k = (n - 3) / 2 + 1 bools = [true] * k (0..(Integer.sqrt(n) - 3) / 2 + 1).each do |i| p = 2*i + 3 s = (p*p - 3) / 2 (s..k).step(p){|j| bools[j] = false} end bools.filter_map.each_with_index {|b, i| (i + 1) * 2 + 1 if b } end p si...
120The sieve of Sundaram
14ruby
nsrit
double xval[N], t_sin[N], t_cos[N], t_tan[N]; double r_sin[N2], r_cos[N2], r_tan[N2]; double rho(double *x, double *y, double *r, int i, int n) { if (n < 0) return 0; if (!n) return y[i]; int idx = (N - 1 - n) * (N - n) / 2 + i; if (r[idx] != r[idx]) r[idx] = (x[i] - x[i + n]) / (rho(x, y, r, i, n - 1)...
121Thiele's interpolation formula
5c
yfp6f
package main import ( "fmt" "math" ) func main() {
121Thiele's interpolation formula
0go
1j6p5
thiele :: [Double] -> [Double] -> Double -> Double thiele xs ys = f rho1 (tail xs) where f _ [] _ = 1 f r@(r0:r1:r2:rs) (x:xs) v = r2 - r0 + (v - x) / f (tail r) xs v rho1 = (!! 1) . (++ [0]) <$> rho rho = repeat 0: repeat 0: ys: rnext (tail rho) xs (tail xs) where rnext _ _ [] = [] ...
121Thiele's interpolation formula
8haskell
tojf7
import static java.lang.Math.*; public class Test { final static int N = 32; final static int N2 = (N * (N - 1) / 2); final static double STEP = 0.05; static double[] xval = new double[N]; static double[] t_sin = new double[N]; static double[] t_cos = new double[N]; static double[] t_tan =...
121Thiele's interpolation formula
9java
8wu06
null
121Thiele's interpolation formula
11kotlin
wb9ek
use strict; use warnings; use feature 'say'; use Math::Trig; use utf8; sub thiele { my($x, $y) = @_; my @; push @, [($$y[$_]) x (@$y-$_)] for 0 .. @$y-1; for my $i (0 .. @ - 2) { $[$i][1] = (($$x[$i] - $$x[$i+1]) / ($[$i][0] - $[$i+1][0])) } for my $i (2 .. @ - 2) { for my $j (...
121Thiele's interpolation formula
2perl
l6wc5
import math def thieleInterpolator(x, y): = [[yi]*(len(y)-i) for i, yi in enumerate(y)] for i in range(len()-1): [i][1] = (x[i] - x[i+1]) / ([i][0] - [i+1][0]) for i in range(2, len()): for j in range(len()-i): [j][i] = (x[j]-x[j+i]) / ([j][i-1]-[j+1][i-1]) + [j+1][i-2] 0 =...
121Thiele's interpolation formula
3python
2yxlz
void print_verse(const char *name) { char *x, *y; int b = 1, f = 1, m = 1, i = 1; x = strdup(name); x[0] = toupper(x[0]); for (; x[i]; ++i) x[i] = tolower(x[i]); if (strchr(, x[0])) { y = strdup(x); y[0] = tolower(y[0]); } else { y = x + 1; } ...
122The Name Game
5c
vmx2o
char text_char(char c) { switch (c) { case 'a': case 'b': case 'c': return '2'; case 'd': case 'e': case 'f': return '3'; case 'g': case 'h': case 'i': return '4'; case 'j': case 'k': case 'l': return '5'; case 'm': case 'n': case 'o': return '6'; case...
123Textonyms
5c
u9xv4
const N: usize = 32; const STEP: f64 = 0.05; fn main() { let x: Vec<f64> = (0..N).map(|i| i as f64 * STEP).collect(); let sin = x.iter().map(|x| x.sin()).collect::<Vec<_>>(); let cos = x.iter().map(|x| x.cos()).collect::<Vec<_>>(); let tan = x.iter().map(|x| x.tan()).collect::<Vec<_>>(); println!(...
121Thiele's interpolation formula
15rust
5c0uq
typedef struct { const char *s; int ln, bad; } rec_t; int cmp_rec(const void *aa, const void *bb) { const rec_t *a = aa, *b = bb; return a->s == b->s ? 0 : !a->s ? 1 : !b->s ? -1 : strncmp(a->s, b->s, 10); } int read_file(const char *fn) { int fd = open(fn, O_RDONLY); if (fd == -1) return 0; struct stat s; fsta...
124Text processing/2
5c
g2s45
let N = 32 let N2 = N * (N - 1) / 2 let step = 0.05 var xval = [Double](repeating: 0, count: N) var tsin = [Double](repeating: 0, count: N) var tcos = [Double](repeating: 0, count: N) var ttan = [Double](repeating: 0, count: N) var rsin = [Double](repeating: .nan, count: N2) var rcos = [Double](repeating: .nan, count:...
121Thiele's interpolation formula
17swift
vmq2r
(def table {\a 2 \b 2 \c 2 \A 2 \B 2 \C 2 \d 3 \e 3 \f 3 \D 3 \E 3 \F 3 \g 4 \h 4 \i 4 \G 4 \H 4 \I 4 \j 5 \k 5 \l 5 \J 5 \K 5 \L 5 \m 6 \n 6 \o 6 \M 6 \N 6 \O 6 \p 7 \q 7 \r 7 \s 7 \P 7 \Q 7 \R 7 \S 7 \t 8 \u 8 \v 8 \T 8 \U 8 \V 8 \w 9 \x 9 \y 9 \z 9 \W 9 \X...
123Textonyms
6clojure
7uor0
(defn parse-line [s] (let [[date & data-toks] (str/split s #"\s+") data-fields (map read-string data-toks) valid-date? (fn [s] (re-find #"\d{4}-\d{2}-\d{2}" s)) valid-line? (and (valid-date? date) (= 48 (count data-toks)) (every? number? data-f...
124Text processing/2
6clojure
kgnhs
package main import ( "bufio" "flag" "fmt" "io" "log" "os" "strings" "unicode" ) func main() { log.SetFlags(0) log.SetPrefix("textonyms: ") wordlist := flag.String("wordlist", "wordlist", "file containing the list of words to check") flag.Parse() if flag.NArg() != 0 { flag.Usage() os.Exit(2) } t ...
123Textonyms
0go
0elsk
import Data.Char (toUpper) import Data.Function (on) import Data.List (groupBy, sortBy) import Data.Maybe (fromMaybe, isJust, isNothing) toKey :: Char -> Maybe Char toKey ch | ch < 'A' = Nothing | ch < 'D' = Just '2' | ch < 'G' = Just '3' | ch < 'J' = Just '4' | ch < 'M' = Just '5' | ch < 'P' = Just '6' ...
123Textonyms
8haskell
c3194
package main import ( "fmt" "strings" ) func printVerse(name string) { x := strings.Title(strings.ToLower(name)) y := x[1:] if strings.Contains("AEIOU", x[:1]) { y = strings.ToLower(x) } b := "b" + y f := "f" + y m := "m" + y switch x[0] { case 'B': b = y ...
122The Name Game
0go
salqa
char inout[INOUT_LEN]; char time[TIME_LEN]; uint jobnum; char maxtime[MAX_MAXOUT][TIME_LEN]; int main(int argc, char **argv) { FILE *in = NULL; int l_out = 0, maxout=-1, maxcount=0; if ( argc > 1 ) { in = fopen(argv[1], ); if ( in == NULL ) { fprintf(stderr, , argv[1]); exit(1); } } e...
125Text processing/Max licenses in use
5c
2y1lo
import Data.Char isVowel :: Char -> Bool isVowel c | char == 'A' = True | char == 'E' = True | char == 'I' = True | char == 'O' = True | char == 'U' = True | otherwise = False where char = toUpper c isSpecial :: Char -> Bool isSpecial c | char == 'B' = True | char == 'F' = Tru...
122The Name Game
8haskell
9z1mo
import java.util.stream.Stream; public class NameGame { private static void printVerse(String name) { StringBuilder sb = new StringBuilder(name.toLowerCase()); sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); String x = sb.toString(); String y = "AEIOU".indexOf(x.charAt(0)) > -...
122The Name Game
9java
to7f9
import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.Vector; public class RTextonyms { private static fin...
123Textonyms
9java
zi7tq
function singNameGame(name) {
122The Name Game
10javascript
mtpyv
(defn delta [entry] (case (second (re-find #"\ (.*)\ @" entry)) "IN " -1 "OUT" 1 (throw (Exception. (str "Invalid entry:" entry))))) (defn t [entry] (second (re-find #"@\ (.*)\ f" entry))) (let [entries (clojure.string/split (slurp "mlijobs.txt") #"\n") in-use (reductions + (map delta entries)) ...
125Text processing/Max licenses in use
6clojure
g2q4f
null
122The Name Game
11kotlin
oxu8z
null
123Textonyms
11kotlin
iquo4
package main import ( "bufio" "fmt" "log" "os" "strconv" "strings" "time" ) const ( filename = "readings.txt" readings = 24
124Text processing/2
0go
iqvog
function printVerse(name) local sb = string.lower(name) sb = sb:gsub("^%l", string.upper) local x = sb local x0 = x:sub(1,1) local y if x0 == 'A' or x0 == 'E' or x0 == 'I' or x0 == 'O' or x0 == 'U' then y = string.lower(x) else y = x:sub(2) end local b = "b" .. y ...
122The Name Game
1lua
iq5ot
null
123Textonyms
1lua
ns5i8
import Data.List (nub, (\\)) data Record = Record {date :: String, recs :: [(Double, Int)]} duplicatedDates rs = rs \\ nub rs goodRecords = filter ((== 24) . length . filter ((>= 1) . snd) . recs) parseLine l = let ws = words l in Record (head ws) (mapRecords (tail ws)) mapRecords [] = [] mapRecords [_] = error "i...
124Text processing/2
8haskell
vme2k
my $src = 'unixdict.txt'; open $fh, "<", $src; @words = grep { /^[a-zA-Z]+$/ } <$fh>; map { tr/A-Z/a-z/ } @words; map { tr/abcdefghijklmnopqrstuvwxyz/22233344455566677778889999/ } @dials = @words; @dials = grep {!$h{$_}++} @dials; @textonyms = grep { $h{$_} > 1 } @dials; print "There are @{[scalar @words]} words...
123Textonyms
2perl
rv8gd
import java.util.*; import java.util.regex.*; import java.io.*; public class DataMunging2 { public static final Pattern e = Pattern.compile("\\s+"); public static void main(String[] args) { try { BufferedReader infile = new BufferedReader(new FileReader(args[0])); List<String>...
124Text processing/2
9java
yfh6g
sub printVerse { $x = ucfirst lc shift; $x0 = substr $x, 0, 1; $y = $x0 =~ /[AEIOU]/ ? lc $x : substr $x, 1; $b = $x0 eq 'B' ? $y : 'b' . $y; $f = $x0 eq 'F' ? $y : 'f' . $y; $m = $x0 eq 'M' ? $y : 'm' . $y; print "$x, $x, bo-$b\n" . "Banana-fana fo-$f\n" . "Fee-fi...
122The Name Game
2perl
g284e
null
124Text processing/2
10javascript
2yalr
from collections import defaultdict import urllib.request CH2NUM = {ch: str(num) for num, chars in enumerate('abc def ghi jkl mno pqrs tuv wxyz'.split(), 2) for ch in chars} URL = 'http: def getwords(url): return urllib.request.urlopen(url).read().decode().lower().split() def mapnum2words(words): number2words ...
123Textonyms
3python
7uorm
null
124Text processing/2
11kotlin
f84do
filename = "readings.txt" io.input( filename ) dates = {} duplicated, bad_format = {}, {} num_good_records, lines_total = 0, 0 while true do line = io.read( "*line" ) if line == nil then break end lines_total = lines_total + 1 date = string.match( line, "%d+%-%d+%-%d+" ) if dates[date] ~= nil th...
124Text processing/2
1lua
togfn
int main () { int i; char *str = getenv (); for (i = 0; str[i + 2] != 00; i++) { if ((str[i] == 'u' && str[i + 1] == 't' && str[i + 2] == 'f') || (str[i] == 'U' && str[i + 1] == 'T' && str[i + 2] == 'F')) { printf (); i = -1; break; } ...
126Terminal control/Unicode output
5c
ns2i6
def print_verse(n): l = ['b', 'f', 'm'] s = n[1:] if str.lower(n[0]) in l: l[l.index(str.lower(n[0]))] = '' elif n[0] in ['A', 'E', 'I', 'O', 'U']: s = str.lower(n) print('{0}, {0}, bo-{2}{1}\nBanana-fana fo-{3}{1}\nFee-fi-mo-{4}{1}\n{0}!\n'.format(n, s, *l)) for n in ['Gary', 'Ear...
122The Name Game
3python
rvogq
CHARS = NUMS = * 2 dict = textonyms = File.open(dict){|f| f.map(&:chomp).group_by {|word| word.tr(CHARS, NUMS) } } puts puts 25287876746242,
123Textonyms
14ruby
h4njx
use std::collections::HashMap; use std::fs::File; use std::io::{self, BufRead}; fn text_char(ch: char) -> Option<char> { match ch { 'a' | 'b' | 'c' => Some('2'), 'd' | 'e' | 'f' => Some('3'), 'g' | 'h' | 'i' => Some('4'), 'j' | 'k' | 'l' => Some('5'), 'm' | 'n' | 'o' => Some...
123Textonyms
15rust
kgdh5
(if-not (empty? (filter #(and (not (nil? %)) (.contains (.toUpperCase %) "UTF")) (map #(System/getenv %) ["LANG" "LC_ALL" "LC_CTYPE"]))) "Unicode is supported on this terminal and U+25B3 is: \u25b3" "Unicode is not supported on this terminal.")
126Terminal control/Unicode output
6clojure
3ngzr
package main import ( "fmt" "os" "strings" ) func main() { lang := strings.ToUpper(os.Getenv("LANG")) if strings.Contains(lang, "UTF") { fmt.Printf("This terminal supports unicode and U+25b3 is:%c\n", '\u25b3') } else { fmt.Println("This terminal does not support unicode") ...
126Terminal control/Unicode output
0go
rvqgm
import Foundation func textCharacter(_ ch: Character) -> Character? { switch (ch) { case "a", "b", "c": return "2" case "d", "e", "f": return "3" case "g", "h", "i": return "4" case "j", "k", "l": return "5" case "m", "n", "o": return "6" case "p", "q...
123Textonyms
17swift
j5i74
import System.Environment import Data.List import Data.Char import Data.Maybe main = do x <- mapM lookupEnv ["LANG", "LC_ALL", "LC_CTYPE"] if any (isInfixOf "UTF". map toUpper) $ catMaybes x then putStrLn "UTF supported: \x25b3" else putStrLn "UTF not supported"
126Terminal control/Unicode output
8haskell
0ems7
def print_verse(name) first_letter_and_consonants_re = /^.[^aeiyou]*/i full_name = name.capitalize suffixed = case full_name[0] when 'A','E','I','O','U' name.downcase else full_name.sub(first_letter_and_consonants_re, '') end b_name ...
122The Name Game
14ruby
j5n7x
package main import ( "bufio" "bytes" "fmt" "log" "os" ) const ( filename = "mlijobs.txt" inoutField = 1 timeField = 3 numFields = 7 ) func main() { file, err := os.Open(filename) if err != nil { log.Fatal(err) } defer file.Close() var ml, out int ...
125Text processing/Max licenses in use
0go
q1yxz
null
126Terminal control/Unicode output
11kotlin
h48j3
object NameGame extends App { private def printVerse(name: String): Unit = { val x = name.toLowerCase.capitalize val y = if ("AEIOU" contains x.head) x.toLowerCase else x.tail val (b, f, m) = x.head match { case 'B' => (y, "f" + y, "m" + y) case 'F' => ("b" + y, y, "m" + y) case 'M' =>...
122The Name Game
16scala
p7zbj
def max = 0 def dates = [] def licenses = [:] new File('licenseFile.txt').eachLine { line -> (line =~ /License (\w+)\s+@ ([\d\/_:]+) for job (\d+)/).each { matcher, action, date, job -> switch (action) { case 'IN': assert licenses[job] != null: "License has not been checked out for $job"...
125Text processing/Max licenses in use
7groovy
1jfp6
use List::MoreUtils 'natatime'; use constant FIELDS => 49; binmode STDIN, ':crlf'; my ($line, $good_records, %dates) = (0, 0); while (<>) {++$line; my @fs = split /\s+/; @fs == FIELDS or die "$line: Bad number of fields.\n"; for (shift @fs) {/\d{4}-\d{2}-\d{2}/ or die "$line: Bad date form...
124Text processing/2
2perl
h4ijl
import Data.List main = do f <- readFile "./../Puzzels/Rosetta/inout.txt" let (ioo,dt) = unzip. map ((\(_:io:_:t:_)-> (io,t)). words) . lines $ f cio = drop 1 . scanl (\c io -> if io == "IN" then pred c else succ c) 0 $ ioo mo = maximum cio putStrLn $ "Maximum simultaneous license use is " ++ show m...
125Text processing/Max licenses in use
8haskell
mthyf
die "Terminal can't handle UTF-8" unless $ENV{LC_ALL} =~ /utf-8/i or $ENV{LC_CTYPE} =~ /utf-8/i or $ENV{LANG} =~ /utf-8/i; print " \n";
126Terminal control/Unicode output
2perl
zi4tb