macro int random(int c) ml do "(Random.int ($c))" js do "(Math.floor(Math.random() * ($c)))" php do "mt_rand(0, $c - 1)" * do "$c" end macro int sqrt_(int c) ml do "(int_of_float (sqrt (float_of_int ( $c))))" js do "Math.floor(Math.sqrt($c))" csharp do "(int)Math.Sqrt($c)" fsharp do "(int (sqrt (float ($c))))" py do "math.floor(math.sqrt($c))" ruby do "Math.sqrt($c).to_i" pas do "Floor(Sqrt($c))" java do "(int)Math.sqrt($c)" groovy do "(int)Math.sqrt($c)" clisp do "(isqrt $c)" go do "int(math.Sqrt(float64($c)))" php do "intval(sqrt($c))" rkt do "integer-sqrt $c" pl do "int(sqrt($c))" c do "(int)sqrt($c)" cpp do "(int)sqrt($c)" objc do "(int)sqrt($c)" ada do "Integer(Float'Truncation(Ada.Numerics.Elementary_Functions.Sqrt(Float($c))))" vb do "Int(Math.Sqrt($c))" hs do "fmap (floor . sqrt . fromIntegral) ($c)" hs_pure do "(floor . sqrt . fromIntegral) $c" lua do "math.floor(math.sqrt($c))" scala do "math.sqrt($c).toInt" st do "(($c) sqrt floor)" fs do "$c s>f fsqrt f>s" * do "sqrt($c)" end tag macro_sqrt__pure def inline int isqrt(int c) tag use_math return sqrt_(c) end macro char char_of_int(int c) ml do "char_of_int ($c)" pas do "chr($c)" java do "(char)($c)" groovy do "(char)($c)" js do "String.fromCharCode($c)" csharp do "(char)($c)" php do "chr($c)" go do "(byte)($c)" clisp do "(code-char $c)" cpp do "(char)($c)" rkt do "integer->char $c" pl do "chr($c)" c do "(char)($c)" cpp do "(char)($c)" objc do "(char)($c)" ada do "Character'Val($c)" vb do "Chr($c)" hs do "fmap chr ($c)" hs_pure do "chr $c" scala do "($c).toChar" lua do "$c" ruby do "($c).chr" st do "(($c) asCharacter)" fsharp do "char ($c)" * do "$c" end tag macro_char_of_int_pure macro int int_of_char(char c) ml do "int_of_char ($c)" py do "ord($c)" clisp do "(char-code $c)" ruby do "$c.ord" pas do "ord($c)" php do "ord($c)" go do "(int)($c)" js do "$c.charCodeAt(0)" rkt do "char->integer $c" pl do "ord($c)" c do "(int)($c)" cpp do "(int)($c)" objc do "(int)($c)" ada do "Character'Pos($c)" vb do "Asc($c)" hs do "fmap ord ($c)" hs_pure do "ord $c" scala do "($c).toInt" lua do "$c" st do "(($c) asciiValue)" java do "(int)($c)" csharp do "(int)($c)" groovy do "(0+$c)" fsharp do "int ($c)" * do "$c" end tag macro_int_of_char_pure def bool is_number(char c) return int_of_char(c) <= int_of_char('9') && int_of_char(c) >= int_of_char('0') end macro int native_macro_abs(int n) ml do "abs ($n)" adb do "abs $n" js do "Math.abs($n)" java do "Math.abs($n)" vb do "Math.Abs($n)" php do "abs($n)" py do "abs($n)" lua do "math.abs($n)" hs do "(abs <$> ($n))" hs_pure do "abs $n" * do "abs($n)" end tag macro_native_macro_abs_pure def int abs_(int n) if n > 0 then return n else return -n end end def lexems macro_abs(lexems n) if current_language() == LANG_Java || current_language() == LANG_Js || current_language() == LANG_Php || current_language() == LANG_Vb || current_language() == LANG_Ml || current_language() == LANG_Fun_ml || current_language() == LANG_Py || current_language() == LANG_Lua || current_language() == LANG_Adb || current_language() == LANG_Hs then return { return native_macro_abs(${n}) } else return { return abs_(${n}) } end end def inline int abs(int n) ${ macro_abs( {n} ) } end macro int native_macro_max2(int a, int b) ml do "max ($a) ($b)" js do "Math.max($a, $b)" java do "Math.max($a, $b)" groovy do "Math.max($a, $b)" csharp do "Math.Max($a, $b)" vb do "Math.Max($a, $b)" php do "max($a, $b)" py do "max($a, $b)" pl do "max($a, $b)" rkt do "max $a $b" clisp do "(max $a $b)" ruby do "[$a, $b].max" lua do "math.max($a, $b)" pas do "Max($a, $b)" hs do "(max <$> ($a) <*> ($b))" hs_pure do "max $a $b" fs do "$a $b max" st do "(($a) max: ($b))" cpp do "std::max($a, $b)" * do "max($a, $b)" end tag macro_native_macro_max2_pure def int max2_(int a, int b) if a > b then return a else return b end end def lexems macro_max2(lexems a, lexems b) if current_language() == LANG_Java || current_language() == LANG_Groovy || current_language() == LANG_Js || current_language() == LANG_Php || current_language() == LANG_Cs || current_language() == LANG_Cc || current_language() == LANG_Cpp || current_language() == LANG_Vb || current_language() == LANG_Rkt || current_language() == LANG_Ml || current_language() == LANG_Fun_ml || current_language() == LANG_Py || current_language() == LANG_Pl || current_language() == LANG_Lua || current_language() == LANG_Pas || current_language() == LANG_Hs || current_language() == LANG_Rb || current_language() == LANG_St || current_language() == LANG_Fs then return { tag use_cpp_algorithm tag use_pascal_math tag perl_use_list_min return native_macro_max2( ${a}, ${b}) } else return { return max2_(${a}, ${b}) } end end def inline int max2(int a, int b) ${ macro_max2( {a}, {b} ) } end macro int native_macro_min2(int a, int b) ml do "min ($a) ($b)" js do "Math.min($a, $b)" java do "Math.min($a, $b)" groovy do "Math.min($a, $b)" csharp do "Math.Min($a, $b)" vb do "Math.Min($a, $b)" php do "min($a, $b)" py do "min($a, $b)" rkt do "min $a $b" clisp do "(min $a $b)" ruby do "[$a, $b].min" pl do "min($a, $b)" lua do "math.min($a, $b)" pas do "Min($a, $b)" hs do "(min <$> ($a) <*> ($b))" hs_pure do "min $a $b" fs do "$a $b min" st do "(($a) min: ($b))" cpp do "std::min($a, $b)" * do "min($a, $b)" end tag macro_native_macro_min2_pure macro int native_macro_min3(int a, int b, int c) js do "Math.min($a, $b, $c)" php do "min($a, $b, $c)" py do "min($a, $b, $c)" rkt do "min $a $b $c" clisp do "(min $a $b $c)" ruby do "[$a, $b, $c].min" pl do "min($a, $b, $c)" lua do "math.min($a, $b, $c)" cpp do "std::min({$a, $b, $c})" * do "min($a, $b, $c)" end macro int native_macro_min4(int a, int b, int c, int d) js do "Math.min($a, $b, $c, $d)" php do "min($a, $b, $c, $d)" py do "min($a, $b, $c, $d)" rkt do "min $a $b $c $d" clisp do "(min $a $b $c $d)" ruby do "[$a, $b, $c, $d].min" pl do "min($a, $b, $c, $d)" lua do "math.min($a, $b, $c, $d)" cpp do "std::min({$a, $b, $c, $d})" * do "min($a, $b, $c, $d)" end def int min2_(int a, int b) if a < b then return a else return b end end def lexems macro_min2(lexems a, lexems b) if current_language() == LANG_Java || current_language() == LANG_Groovy || current_language() == LANG_Js || current_language() == LANG_Php || current_language() == LANG_Cs || current_language() == LANG_Cc || current_language() == LANG_Cpp || current_language() == LANG_Vb || current_language() == LANG_Ml || current_language() == LANG_Fun_ml || current_language() == LANG_Py || current_language() == LANG_Rkt || current_language() == LANG_Cl || current_language() == LANG_Rb || current_language() == LANG_Fs || current_language() == LANG_Vb || current_language() == LANG_Pl || current_language() == LANG_Pas || current_language() == LANG_Lua || current_language() == LANG_St || current_language() == LANG_Hs then return { tag use_cpp_algorithm tag use_pascal_math tag perl_use_list_min return native_macro_min2( ${a}, ${b}) } else return { return min2_(${a}, ${b})} end end def inline int min2(int a, int b) ${ macro_min2( {a}, {b} ) } end def lexems macro_min3(lexems a, lexems b, lexems c) if current_language() == LANG_Js || current_language() == LANG_Php || current_language() == LANG_Py || current_language() == LANG_Rkt || current_language() == LANG_Cl || current_language() == LANG_Cc || current_language() == LANG_Cpp || current_language() == LANG_Rb || current_language() == LANG_Pl || current_language() == LANG_Pl || current_language() == LANG_Lua then return { tag use_cpp_algorithm tag perl_use_list_min return native_macro_min3( ${a}, ${b}, ${c}) } else return { return min2(min2( ${a}, ${b}), ${c}) } end end def inline int min3(int a, int b, int c) ${ macro_min3( {a}, {b}, {c} )} end def lexems macro_min4(lexems a, lexems b, lexems c, lexems d) if current_language() == LANG_Js || current_language() == LANG_Php || current_language() == LANG_Py || current_language() == LANG_Rkt || current_language() == LANG_Cl || current_language() == LANG_Cc || current_language() == LANG_Cpp || current_language() == LANG_Rb || current_language() == LANG_Pl || current_language() == LANG_Lua then return { tag use_cpp_algorithm tag perl_use_list_min return native_macro_min4( ${a}, ${b}, ${c}, ${d}) } else return { return min3(min2(a, b), c, d) } end end def inline int min4(int a, int b, int c, int d) ${ macro_min4( {a}, {b}, {c}, {d} )} end def int pgcd(int a, int b) def c = min2(a, b) def d = max2(a, b) def reste = d % c if reste == 0 then return c else return pgcd(c, reste) end end macro array
native_expand_read_int_line(int c) py do "list(map(int, input().split()))" php do "array_map(\"intval\", explode(\" \", fgets(STDIN)))" fsharp do "(Console.ReadLine ()).Split [|' '|] |> Array.map Int32.Parse" csharp do "new List
(Console.ReadLine().Split(\" \".ToCharArray())).ConvertAll(int.Parse).ToArray()" vb do "Array(Of String).ConvertAll(Of String, Integer)(Console.ReadLine().Split(\" \".ToCharArray()), New Converter(Of String, Integer)(AddressOf Integer.Parse))" rkt do "list->vector (map string->number (regexp-split \" \" (read-line)))" ruby do "STDIN.readline.split(\" \").map{ |x| x.to_i(10) }" pl do "[ map { int($_) } split(/\\s+/,
) ]" java do "read_int_line()" groovy do "read_int_line()" lua do "readintline()" hs do "join (newListArray . (,) 0 . subtract 1 <$> $c <*> fmap (map read . words) getLine)" scala do "readLine().split(\" \").map(_.toInt)" * do "E R R O R" end macro array
native_expand_read_char_line(int c) py do "list(input())" php do "fgets(STDIN)" csharp do "Console.ReadLine().ToCharArray()" fsharp do "(Console.ReadLine ()).ToCharArray ()" vb do "Console.ReadLine().ToCharArray()" cpp do "getline()" rkt do "list->vector (string->list (read-line))" ruby do "STDIN.readline.split(//)" pl do "[split(//,
)]" lua do "readcharline()" java do "scanner.nextLine().toCharArray()" groovy do "scanner.nextLine().toCharArray()" hs do "join (newListArray <$> (fmap (\\x -> (0, x-1)) ($c)) <*> getLine)" scala do "readLine().toCharArray()" * do "E R R O R" end macro array
> py_expand_read_int_matrix(int x, int y) py do "[list(map(int, input().split())) for i in range($y)]" ruby do "[*1..$y].map { |l| STDIN.readline.split(\" \").map{ |x| x.to_i(10) } }" cpp do "read_matrix
($y, $x)" * do "E R R O R" end macro array
> py_expand_read_char_matrix(int x, int y) cpp do "read_matrix
($y, $x)" * do "E R R O R" end macro int native_expand_read_int() py do "int(input())" php do "intval(trim(fgets(STDIN)))" csharp do "int.Parse(Console.ReadLine())" fsharp do "Console.ReadLine () |> Int32.Parse" vb do "Integer.Parse(Console.ReadLine())" ml do "Scanf.scanf \"%d \" (fun x -> x)" rkt do "string->number (read-line)" ruby do "STDIN.readline.to_i(10)" pl do "int(
)" lua do "tonumber(io.read('*l'))" java do "Integer.parseInt(scanner.nextLine())" groovy do "Integer.parseInt(scanner.nextLine())" hs do "fmap read getLine" scala do "readInt().toInt" st do "stdin nextLine asInteger" * do "E R R O R" end def lexems expand_read_int() if current_language() == LANG_Fun_ml then return { return native_expand_read_int() } elsif current_language() == LANG_Py || current_language() == LANG_Php || current_language() == LANG_Rkt || current_language() == LANG_Pl || current_language() == LANG_Cs || current_language() == LANG_Vb || current_language() == LANG_Fsscript || current_language() == LANG_Java || current_language() == LANG_Groovy || current_language() == LANG_Rb || current_language() == LANG_Lua || current_language() == LANG_Hs || current_language() == LANG_Scala then return { tag use_readline tag use_readmacros return native_expand_read_int() } else return { def inline read int out skip; return out } end end def inline int read_int() ${ expand_read_int() } end def lexems expand_read_int_line(lexems a) if current_language() == LANG_Py || current_language() == LANG_Php || current_language() == LANG_Cs || current_language() == LANG_Vb || current_language() == LANG_Fsscript || current_language() == LANG_Pl || current_language() == LANG_Rkt || current_language() == LANG_Java || current_language() == LANG_Groovy || current_language() == LANG_Rb || current_language() == LANG_Lua || current_language() == LANG_Scala || current_language() == LANG_Hs then return { tag use_readintline tag use_java_readline tag use_readmacros tag use_readline return native_expand_read_int_line(${a}) } else return { def inline array
tab[${a}] with i do def inline read int t skip return t end return tab } end end def inline array
read_int_line(int n) ${expand_read_int_line( {n} )} end def lexems expand_read_char_line(lexems a) if current_language() == LANG_Lua || current_language() == LANG_Cc || current_language() == LANG_Cpp then return { tag use_cc_readline tag use_readcharline return native_expand_read_char_line(${a}) } elsif current_language() == LANG_Py || current_language() == LANG_Php || current_language() == LANG_Rkt || current_language() == LANG_Pl || current_language() == LANG_Cs || current_language() == LANG_Vb || current_language() == LANG_Fsscript || current_language() == LANG_Java || current_language() == LANG_Groovy || current_language() == LANG_Rb || current_language() == LANG_Hs || current_language() == LANG_Scala then return { tag use_readline tag use_readmacros return native_expand_read_char_line(${a}) } else return { def inline array
tab[${a}] with i do def inline read char t; return t; end skip return tab } end end def inline array
read_char_line(int n) ${expand_read_char_line( {n} )} end def lexems expand_read_int_matrix(lexems x, lexems y) if current_language() == LANG_Py || current_language() == LANG_Rb || current_language() == LANG_Cpp then return { tag use_cpp_readmatrix return py_expand_read_int_matrix( ${ x }, ${ y } ) } else return { def inline array
> tab[${y}] with z do return read_int_line(x) end return tab } end end def inline array
> read_int_matrix(int x, int y) ${expand_read_int_matrix( {x}, {y} )} end def lexems expand_read_char_matrix(lexems x, lexems y) if current_language() == LANG_Cpp then return { tag use_cpp_readmatrix return py_expand_read_char_matrix( ${ x }, ${ y } ) } else return { def array
> tab[${y}] with z do return read_char_line(x) end return tab } end end def inline array
> read_char_matrix(int x, int y) ${expand_read_char_matrix( {x}, {y} )} end macro (int, int) native_expand_read_int_couple() py do "list(map(int, input().split()))" lua do "readintline()" php do "array_map(\"intval\", explode(\" \", fgets(STDIN)))" ruby do "STDIN.readline.split(\" \").map{ |x| x.to_i(10) }" pl do "[ map { int($_) } split(/\\s+/,
) ]" rkt do "map string->number (regexp-split \" \" (read-line))" hs do " (fmap read . head . reads) <$> getLine :: IO (Int, Int)" scala do "readf2(\"{0,number} {1,number}\").asInstanceOf[(Long, Long)] match { case x => (x._1.toInt, x._2.toInt) }" * do "E R R O R" end def lexems expand_read_int_couple() if current_language() == LANG_Vb || current_language() == LANG_Cs || current_language() == LANG_Fsscript || current_language() == LANG_Java || current_language() == LANG_Groovy then return { def array
l = read_int_line(2) return (l[0], l[1]) } elsif current_language() == LANG_Py || current_language() == LANG_Php || current_language() == LANG_Rb || current_language() == LANG_Rkt || current_language() == LANG_Pl || current_language() == LANG_Lua || current_language() == LANG_Hs || current_language() == LANG_Scala then return { tag use_readintline tag use_readtuple return native_expand_read_int_couple() } else return { def inline read int a skip def inline read int b skip return (a, b) } end end def inline (int, int) read_int_couple() ${ expand_read_int_couple() } end macro (int, int, int) native_expand_read_3ints() py do "list(map(int, input().split()))" lua do "readintline()" php do "array_map(\"intval\", explode(\" \", fgets(STDIN)))" ruby do "STDIN.readline.split(\" \").map{ |x| x.to_i(10) }" pl do "[ map { int($_) } split(/\\s+/,
) ]" rkt do "map string->number (regexp-split \" \" (read-line))" scala do "readf3(\"{0,number} {1,number} {2,number}\").asInstanceOf[(Long, Long, Long)] match { case x => (x._1.toInt, x._2.toInt, x._3.toInt) }" * do "E R R O R" end def lexems expand_read_3ints() if current_language() == LANG_Vb || current_language() == LANG_Cs || current_language() == LANG_Fsscript || current_language() == LANG_Hs || current_language() == LANG_Groovy || current_language() == LANG_Java then return { def array
l = read_int_line(3) return (l[0], l[1], l[2]) } elsif current_language() == LANG_Py || current_language() == LANG_Php || current_language() == LANG_Rb || current_language() == LANG_Lua || current_language() == LANG_Rkt || current_language() == LANG_Scala || current_language() == LANG_Pl then return { tag use_readtuple tag use_readintline return native_expand_read_3ints() } else return { def inline read int a skip def inline read int b skip def inline read int c skip return (a, b, c) } end end def inline (int, int, int) read_3ints() ${ expand_read_3ints() } end
Métalang
Code source
main print int 10 end
Compiler
Ada
C
C++
Common lisp
C++ (prologin variant)
C#
Forth
F#
Ocaml fonctionnel
Go
Groovy
Haskell
Java
Javascript
Lua
Objective-C
ocaml
Pascal
Php
Perl
Python
Ruby
Scala
Smalltalk
Visual Basic
stderr