From 1e05ecd7eee8e023e476a2078acf42f46bd9bfa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingy=20d=C3=B6t=20Net?= Date: Mon, 8 Apr 2013 13:02:41 -0700 Subject: [PATCH] First commit of partial RosettaCode contents. Pushing this for testing purposes. Lots of work still needed. --- .gitignore | 2 + Conf/lang.yaml | 54 ++++++ Conf/rosettacode.yaml | 1 + Conf/task.yaml | 21 +++ Lang/4D/0DESCRIPTION | 3 + Lang/4D/Comments | 1 + Lang/AWK/0DESCRIPTION | 20 +++ Lang/AWK/99_Bottles_of_Beer | 1 + Lang/AWK/Anagrams | 1 + Lang/AWK/Comments | 1 + Lang/AWK/FizzBuzz | 1 + Lang/AWK/Infinity | 1 + Lang/AWK/Knuth_shuffle | 1 + Lang/AWK/Ordered_words | 1 + Lang/AWK/Search_a_list | 1 + Lang/BASIC/0DESCRIPTION | 15 ++ Lang/BASIC/99_Bottles_of_Beer | 1 + Lang/BASIC/Bulls_and_cows | 1 + Lang/BASIC/FizzBuzz | 1 + Lang/BASIC/Knuth_shuffle | 1 + Lang/BASIC/Quine | 1 + Lang/BASIC/Search_a_list | 1 + Lang/Befunge/0DESCRIPTION | 13 ++ Lang/Befunge/99_Bottles_of_Beer | 1 + Lang/Befunge/Comments | 1 + Lang/Befunge/FizzBuzz | 1 + Lang/Befunge/Quine | 1 + Lang/C/0DESCRIPTION | 30 ++++ Lang/C/99_Bottles_of_Beer | 1 + Lang/C/Anagrams | 1 + Lang/C/Bulls_and_cows | 1 + Lang/C/Comments | 1 + Lang/C/Death_Star | 1 + Lang/C/FizzBuzz | 1 + Lang/C/Infinity | 1 + Lang/C/JSON | 1 + Lang/C/Knuth_shuffle | 1 + Lang/C/Narcissist | 1 + Lang/C/Ordered_words | 1 + Lang/C/Pi | 1 + Lang/C/Quine | 1 + Lang/C/Search_a_list | 1 + Lang/Clojure/0DESCRIPTION | 18 ++ Lang/Clojure/99_Bottles_of_Beer | 1 + Lang/Clojure/Anagrams | 1 + Lang/Clojure/Bulls_and_cows | 1 + Lang/Clojure/Comments | 1 + Lang/Clojure/FizzBuzz | 1 + Lang/Clojure/JSON | 1 + Lang/Clojure/Knuth_shuffle | 1 + Lang/Clojure/Quine | 1 + Lang/Clojure/Search_a_list | 1 + Lang/CoffeeScript/0DESCRIPTION | 56 ++++++ Lang/CoffeeScript/99_Bottles_of_Beer | 1 + Lang/CoffeeScript/Anagrams | 1 + Lang/CoffeeScript/Comments | 1 + Lang/CoffeeScript/FizzBuzz | 1 + Lang/CoffeeScript/Infinity | 1 + Lang/CoffeeScript/JSON | 1 + Lang/CoffeeScript/Knuth_shuffle | 1 + Lang/CoffeeScript/Ordered_words | 1 + Lang/CoffeeScript/Quine | 1 + Lang/Erlang/0DESCRIPTION | 15 ++ Lang/Erlang/99_Bottles_of_Beer | 1 + Lang/Erlang/Anagrams | 1 + Lang/Erlang/Bulls_and_cows | 1 + Lang/Erlang/Comments | 1 + Lang/Erlang/FizzBuzz | 1 + Lang/Erlang/Quine | 1 + Lang/Erlang/Search_a_list | 1 + Lang/Forth/0DESCRIPTION | 13 ++ Lang/Forth/99_Bottles_of_Beer | 1 + Lang/Forth/Bulls_and_cows | 1 + Lang/Forth/Comments | 1 + Lang/Forth/FizzBuzz | 1 + Lang/Forth/Infinity | 1 + Lang/Forth/Knuth_shuffle | 1 + Lang/Forth/Narcissist | 1 + Lang/Forth/Ordered_words | 1 + Lang/Forth/Quine | 1 + Lang/Forth/Search_a_list | 1 + Lang/Fortran/0DESCRIPTION | 15 ++ Lang/Fortran/99_Bottles_of_Beer | 1 + Lang/Fortran/Bulls_and_cows | 1 + Lang/Fortran/Comments | 1 + Lang/Fortran/FizzBuzz | 1 + Lang/Fortran/Infinity | 1 + Lang/Fortran/Knuth_shuffle | 1 + Lang/Fortran/Ordered_words | 1 + Lang/Fortran/Quine | 1 + Lang/Fortran/Search_a_list | 1 + Lang/Go/0DESCRIPTION | 26 +++ Lang/Go/99_Bottles_of_Beer | 1 + Lang/Go/Anagrams | 1 + Lang/Go/Bulls_and_cows | 1 + Lang/Go/Comments | 1 + Lang/Go/Death_Star | 1 + Lang/Go/FizzBuzz | 1 + Lang/Go/Infinity | 1 + Lang/Go/JSON | 1 + Lang/Go/Knuth_shuffle | 1 + Lang/Go/Narcissist | 1 + Lang/Go/Ordered_words | 1 + Lang/Go/Pi | 1 + Lang/Go/Quine | 1 + Lang/Go/Search_a_list | 1 + Lang/Haskell/0DESCRIPTION | 17 ++ Lang/Haskell/99_Bottles_of_Beer | 1 + Lang/Haskell/Bulls_and_cows | 1 + Lang/Haskell/Comments | 1 + Lang/Haskell/Entropy | 1 + Lang/Haskell/FizzBuzz | 1 + Lang/Haskell/Infinity | 1 + Lang/Haskell/JSON | 1 + Lang/Haskell/Knuth_shuffle | 1 + Lang/Haskell/Ordered_words | 1 + Lang/Haskell/Pi | 1 + Lang/Haskell/Quine | 1 + Lang/Haskell/Search_a_list | 1 + Lang/Java/0DESCRIPTION | 39 +++++ Lang/Java/99_Bottles_of_Beer | 1 + Lang/Java/Anagrams | 1 + Lang/Java/Bulls_and_cows | 1 + Lang/Java/Comments | 1 + Lang/Java/FizzBuzz | 1 + Lang/Java/Infinity | 1 + Lang/Java/JSON | 1 + Lang/Java/Knuth_shuffle | 1 + Lang/Java/Ordered_words | 1 + Lang/Java/Pi | 1 + Lang/Java/Quine | 1 + Lang/Java/Search_a_list | 1 + Lang/JavaScript/0DESCRIPTION | 21 +++ Lang/JavaScript/99_Bottles_of_Beer | 1 + Lang/JavaScript/Anagrams | 1 + Lang/JavaScript/Bulls_and_cows | 1 + Lang/JavaScript/FizzBuzz | 1 + Lang/JavaScript/Infinity | 1 + Lang/JavaScript/JSON | 1 + Lang/JavaScript/Knuth_shuffle | 1 + Lang/JavaScript/Narcissist | 1 + Lang/JavaScript/Ordered_words | 1 + Lang/JavaScript/Quine | 1 + Lang/JavaScript/Search_a_list | 1 + Lang/LaTeX/0DESCRIPTION | 4 + Lang/LaTeX/99_Bottles_of_Beer | 1 + Lang/LaTeX/Comments | 1 + Lang/Lua/0DESCRIPTION | 17 ++ Lang/Lua/99_Bottles_of_Beer | 1 + Lang/Lua/Anagrams | 1 + Lang/Lua/Bulls_and_cows | 1 + Lang/Lua/Comments | 1 + Lang/Lua/FizzBuzz | 1 + Lang/Lua/Infinity | 1 + Lang/Lua/Knuth_shuffle | 1 + Lang/Lua/Ordered_words | 1 + Lang/Lua/Quine | 1 + Lang/Lua/Search_a_list | 1 + Lang/PHP/0DESCRIPTION | 16 ++ Lang/PHP/99_Bottles_of_Beer | 1 + Lang/PHP/Anagrams | 1 + Lang/PHP/Bulls_and_cows | 1 + Lang/PHP/Comments | 1 + Lang/PHP/FizzBuzz | 1 + Lang/PHP/Infinity | 1 + Lang/PHP/JSON | 1 + Lang/PHP/Knuth_shuffle | 1 + Lang/PHP/Quine | 1 + Lang/PHP/Search_a_list | 1 + Lang/PIR/0DESCRIPTION | 5 + Lang/PIR/99_Bottles_of_Beer | 1 + Lang/PIR/FizzBuzz | 1 + Lang/Perl/0DESCRIPTION | 25 +++ Lang/Perl/99_Bottles_of_Beer | 1 + Lang/Perl/Anagrams | 1 + Lang/Perl/Bulls_and_cows | 1 + Lang/Perl/Comments | 1 + Lang/Perl/Death_Star | 1 + Lang/Perl/Entropy | 1 + Lang/Perl/FizzBuzz | 1 + Lang/Perl/Infinity | 1 + Lang/Perl/JSON | 1 + Lang/Perl/Knuth_shuffle | 1 + Lang/Perl/Narcissist | 1 + Lang/Perl/Ordered_words | 1 + Lang/Perl/Pi | 1 + Lang/Perl/Quine | 1 + Lang/Perl/Search_a_list | 1 + Lang/PicoLisp/0DESCRIPTION | 21 +++ Lang/PicoLisp/99_Bottles_of_Beer | 1 + Lang/PicoLisp/Anagrams | 1 + Lang/PicoLisp/Bulls_and_cows | 1 + Lang/PicoLisp/Comments | 1 + Lang/PicoLisp/FizzBuzz | 1 + Lang/PicoLisp/Infinity | 1 + Lang/PicoLisp/JSON | 1 + Lang/PicoLisp/Knuth_shuffle | 1 + Lang/PicoLisp/Narcissist | 1 + Lang/PicoLisp/Ordered_words | 1 + Lang/PicoLisp/Pi | 1 + Lang/PicoLisp/Quine | 1 + Lang/PicoLisp/Search_a_list | 1 + Lang/Python/0DESCRIPTION | 31 ++++ Lang/Python/99_Bottles_of_Beer | 1 + Lang/Python/Anagrams | 1 + Lang/Python/Bulls_and_cows | 1 + Lang/Python/Comments | 1 + Lang/Python/Death_Star | 1 + Lang/Python/Entropy | 1 + Lang/Python/FizzBuzz | 1 + Lang/Python/Infinity | 1 + Lang/Python/JSON | 1 + Lang/Python/Knuth_shuffle | 1 + Lang/Python/Narcissist | 1 + Lang/Python/Ordered_words | 1 + Lang/Python/Pi | 1 + Lang/Python/Quine | 1 + Lang/Python/Search_a_list | 1 + Lang/REXX/0DESCRIPTION | 61 +++++++ Lang/REXX/99_Bottles_of_Beer | 1 + Lang/REXX/Anagrams | 1 + Lang/REXX/Bulls_and_cows | 1 + Lang/REXX/Comments | 1 + Lang/REXX/Death_Star | 1 + Lang/REXX/Entropy | 1 + Lang/REXX/FizzBuzz | 1 + Lang/REXX/Knuth_shuffle | 1 + Lang/REXX/Narcissist | 1 + Lang/REXX/Ordered_words | 1 + Lang/REXX/Pi | 1 + Lang/REXX/Quine | 1 + Lang/REXX/Search_a_list | 1 + Lang/Ruby/0DESCRIPTION | 31 ++++ Lang/Ruby/99_Bottles_of_Beer | 1 + Lang/Ruby/Anagrams | 1 + Lang/Ruby/Bulls_and_cows | 1 + Lang/Ruby/Comments | 1 + Lang/Ruby/Entropy | 1 + Lang/Ruby/FizzBuzz | 1 + Lang/Ruby/Infinity | 1 + Lang/Ruby/JSON | 1 + Lang/Ruby/Knuth_shuffle | 1 + Lang/Ruby/Narcissist | 1 + Lang/Ruby/Ordered_words | 1 + Lang/Ruby/Pi | 1 + Lang/Ruby/Quine | 1 + Lang/Ruby/Search_a_list | 1 + Lang/SNUSP/0DESCRIPTION | 9 + Lang/SNUSP/99_Bottles_of_Beer | 1 + Lang/SNUSP/FizzBuzz | 1 + Lang/Scala/0DESCRIPTION | 12 ++ Lang/Scala/Anagrams | 1 + Lang/Scala/Bulls_and_cows | 1 + Lang/Scala/Comments | 1 + Lang/Scala/Entropy | 1 + Lang/Scala/FizzBuzz | 1 + Lang/Scala/Infinity | 1 + Lang/Scala/JSON | 1 + Lang/Scala/Knuth_shuffle | 1 + Lang/Scala/Pi | 1 + Lang/Scala/Quine | 1 + Lang/Scala/Search_a_list | 1 + Lang/Tcl/0DESCRIPTION | 140 +++++++++++++++ Lang/Tcl/99_Bottles_of_Beer | 1 + Lang/Tcl/Anagrams | 1 + Lang/Tcl/Bulls_and_cows | 1 + Lang/Tcl/Comments | 1 + Lang/Tcl/Death_Star | 1 + Lang/Tcl/Entropy | 1 + Lang/Tcl/FizzBuzz | 1 + Lang/Tcl/Infinity | 1 + Lang/Tcl/JSON | 1 + Lang/Tcl/Knuth_shuffle | 1 + Lang/Tcl/Narcissist | 1 + Lang/Tcl/Ordered_words | 1 + Lang/Tcl/Pi | 1 + Lang/Tcl/Quine | 1 + Lang/Tcl/Search_a_list | 1 + Lang/Turing/0DESCRIPTION | 7 + Lang/Turing/FizzBuzz | 1 + Meta/SNUSP.yaml | 3 + README.md | 39 +++++ Task/99_Bottles_of_Beer/0DESCRIPTION | 13 ++ .../AWK/99_bottles_of_beer.awk | 7 + .../BASIC/99_bottles_of_beer-2.bas | 7 + .../BASIC/99_bottles_of_beer.bas | 12 ++ .../Befunge/99_bottles_of_beer.bf | 11 ++ .../C/99_bottles_of_beer-2.c | 5 + .../C/99_bottles_of_beer-3.c | 30 ++++ .../C/99_bottles_of_beer-4.c | 35 ++++ .../99_Bottles_of_Beer/C/99_bottles_of_beer.c | 15 ++ .../Clojure/99_bottles_of_beer.clj | 14 ++ .../CoffeeScript/99_bottles_of_beer-2.coffee | 4 + .../CoffeeScript/99_bottles_of_beer-3.coffee | 1 + .../CoffeeScript/99_bottles_of_beer-4.coffee | 1 + .../CoffeeScript/99_bottles_of_beer.coffee | 9 + .../Erlang/99_bottles_of_beer.erl | 39 +++++ .../Forth/99_bottles_of_beer.fth | 14 ++ .../Fortran/99_bottles_of_beer.f | 24 +++ .../Go/99_bottles_of_beer.go | 18 ++ .../Haskell/99_bottles_of_beer-2.hs | 16 ++ .../Haskell/99_bottles_of_beer-3.hs | 28 +++ .../Haskell/99_bottles_of_beer.hs | 7 + .../Java/99_bottles_of_beer-2.java | 16 ++ .../Java/99_bottles_of_beer-3.java | 40 +++++ .../Java/99_bottles_of_beer.java | 20 +++ .../JavaScript/99_bottles_of_beer-2.js | 2 + .../JavaScript/99_bottles_of_beer-3.js | 21 +++ .../JavaScript/99_bottles_of_beer-4.js | 18 ++ .../JavaScript/99_bottles_of_beer.js | 10 ++ .../LaTeX/99_bottles_of_beer-2.tex | 23 +++ .../LaTeX/99_bottles_of_beer.tex | 20 +++ .../Lua/99_bottles_of_beer.lua | 11 ++ .../PHP/99_bottles_of_beer-2.php | 13 ++ .../PHP/99_bottles_of_beer-3.php | 18 ++ .../PHP/99_bottles_of_beer-4.php | 7 + .../PHP/99_bottles_of_beer.php | 15 ++ .../PIR/99_bottles_of_beer.pir | 31 ++++ .../Perl/99_bottles_of_beer-2.pl | 6 + .../Perl/99_bottles_of_beer-3.pl | 14 ++ .../Perl/99_bottles_of_beer-4.pl | 16 ++ .../Perl/99_bottles_of_beer.pl | 18 ++ .../PicoLisp/99_bottles_of_beer.l | 12 ++ .../Python/99_bottles_of_beer-2.py | 9 + .../Python/99_bottles_of_beer-3.py | 9 + .../Python/99_bottles_of_beer-4.py | 2 + .../Python/99_bottles_of_beer-5.py | 2 + .../Python/99_bottles_of_beer-6.py | 14 ++ .../Python/99_bottles_of_beer-7.py | 39 +++++ .../Python/99_bottles_of_beer-8.py | 7 + .../Python/99_bottles_of_beer.py | 14 ++ .../REXX/99_bottles_of_beer.rexx | 19 +++ .../Ruby/99_bottles_of_beer-2.rb | 12 ++ .../Ruby/99_bottles_of_beer-3.rb | 15 ++ .../Ruby/99_bottles_of_beer-4.rb | 14 ++ .../Ruby/99_bottles_of_beer.rb | 13 ++ .../SNUSP/99_bottles_of_beer.snusp | 19 +++ .../Tcl/99_bottles_of_beer-2.tcl | 28 +++ .../Tcl/99_bottles_of_beer.tcl | 10 ++ Task/Anagrams/0DESCRIPTION | 1 + Task/Anagrams/1META.yaml | 2 + Task/Anagrams/AWK/anagrams.awk | 26 +++ Task/Anagrams/C/anagrams-2.c | 101 +++++++++++ Task/Anagrams/C/anagrams.c | 160 ++++++++++++++++++ Task/Anagrams/Clojure/anagrams.clj | 10 ++ Task/Anagrams/CoffeeScript/anagrams-2.coffee | 7 + Task/Anagrams/CoffeeScript/anagrams.coffee | 31 ++++ Task/Anagrams/Erlang/anagrams.erl | 29 ++++ Task/Anagrams/Go/anagrams-2.go | 5 + Task/Anagrams/Go/anagrams-3.go | 10 ++ Task/Anagrams/Go/anagrams-4.go | 7 + Task/Anagrams/Go/anagrams.go | 39 +++++ Task/Anagrams/Java/anagrams.java | 30 ++++ Task/Anagrams/JavaScript/anagrams.js | 20 +++ Task/Anagrams/Lua/anagrams.lua | 73 ++++++++ Task/Anagrams/PHP/anagrams.php | 13 ++ Task/Anagrams/Perl/anagrams-2.pl | 7 + Task/Anagrams/Perl/anagrams.pl | 15 ++ Task/Anagrams/PicoLisp/anagrams-2.l | 8 + Task/Anagrams/PicoLisp/anagrams.l | 4 + Task/Anagrams/Python/anagrams-2.py | 14 ++ Task/Anagrams/Python/anagrams-3.py | 25 +++ Task/Anagrams/Python/anagrams-4.py | 22 +++ Task/Anagrams/Python/anagrams.py | 12 ++ Task/Anagrams/REXX/anagrams.rexx | 33 ++++ Task/Anagrams/Ruby/anagrams-2.rb | 14 ++ Task/Anagrams/Ruby/anagrams.rb | 17 ++ Task/Anagrams/Scala/anagrams-2.scala | 6 + Task/Anagrams/Scala/anagrams.scala | 4 + Task/Anagrams/Tcl/anagrams.tcl | 24 +++ Task/Bulls_and_cows/0DESCRIPTION | 14 ++ Task/Bulls_and_cows/1META.yaml | 2 + Task/Bulls_and_cows/BASIC/bulls_and_cows.bas | 41 +++++ Task/Bulls_and_cows/C/bulls_and_cows-2.c | 85 ++++++++++ Task/Bulls_and_cows/C/bulls_and_cows.c | 60 +++++++ .../Bulls_and_cows/Clojure/bulls_and_cows.clj | 38 +++++ .../Erlang/bulls_and_cows-2.erl | 3 + Task/Bulls_and_cows/Erlang/bulls_and_cows.erl | 45 +++++ Task/Bulls_and_cows/Forth/bulls_and_cows.fth | 37 ++++ Task/Bulls_and_cows/Fortran/bulls_and_cows.f | 84 +++++++++ Task/Bulls_and_cows/Go/bulls_and_cows-2.go | 117 +++++++++++++ Task/Bulls_and_cows/Go/bulls_and_cows.go | 68 ++++++++ Task/Bulls_and_cows/Haskell/bulls_and_cows.hs | 50 ++++++ Task/Bulls_and_cows/Java/bulls_and_cows.java | 52 ++++++ .../JavaScript/bulls_and_cows.js | 88 ++++++++++ Task/Bulls_and_cows/Lua/bulls_and_cows.lua | 101 +++++++++++ Task/Bulls_and_cows/PHP/bulls_and_cows.php | 40 +++++ Task/Bulls_and_cows/Perl/bulls_and_cows.pl | 39 +++++ Task/Bulls_and_cows/PicoLisp/bulls_and_cows.l | 20 +++ Task/Bulls_and_cows/Python/bulls_and_cows.py | 33 ++++ .../Bulls_and_cows/REXX/bulls_and_cows-2.rexx | 101 +++++++++++ Task/Bulls_and_cows/REXX/bulls_and_cows.rexx | 43 +++++ Task/Bulls_and_cows/Ruby/bulls_and_cows.rb | 44 +++++ .../Bulls_and_cows/Scala/bulls_and_cows.scala | 42 +++++ Task/Bulls_and_cows/Tcl/bulls_and_cows.tcl | 85 ++++++++++ Task/Comments/0DESCRIPTION | 4 + Task/Comments/1META.yaml | 2 + Task/Comments/4D/comments.4d | 1 + Task/Comments/AWK/comments.awk | 3 + Task/Comments/Befunge/comments-2.bf | 6 + Task/Comments/Befunge/comments.bf | 2 + Task/Comments/C/comments-2.c | 2 + Task/Comments/C/comments-3.c | 1 + Task/Comments/C/comments-4.c | 3 + Task/Comments/C/comments-5.c | 7 + Task/Comments/C/comments-6.c | 3 + Task/Comments/C/comments-7.c | 1 + Task/Comments/C/comments.c | 4 + Task/Comments/Clojure/comments-2.clj | 1 + Task/Comments/Clojure/comments-3.clj | 2 + Task/Comments/Clojure/comments.clj | 3 + Task/Comments/CoffeeScript/comments.coffee | 5 + Task/Comments/Erlang/comments.erl | 1 + Task/Comments/Forth/comments-2.fth | 1 + Task/Comments/Forth/comments-3.fth | 2 + Task/Comments/Forth/comments-4.fth | 11 ++ Task/Comments/Forth/comments.fth | 2 + Task/Comments/Fortran/comments-2.f | 2 + Task/Comments/Fortran/comments-3.f | 1 + Task/Comments/Fortran/comments-4.f | 7 + Task/Comments/Fortran/comments.f | 2 + Task/Comments/Go/comments.go | 5 + Task/Comments/Haskell/comments.hs | 15 ++ Task/Comments/Java/comments-2.java | 5 + Task/Comments/Java/comments-3.java | 1 + Task/Comments/Java/comments-4.java | 1 + Task/Comments/Java/comments-5.java | 5 + Task/Comments/Java/comments.java | 1 + Task/Comments/LaTeX/comments-2.tex | 7 + Task/Comments/LaTeX/comments.tex | 1 + Task/Comments/Lua/comments-2.lua | 2 + Task/Comments/Lua/comments.lua | 4 + Task/Comments/PHP/comments-2.php | 2 + Task/Comments/PHP/comments-3.php | 4 + Task/Comments/PHP/comments-4.php | 4 + Task/Comments/PHP/comments.php | 2 + Task/Comments/Perl/comments-2.pl | 1 + Task/Comments/Perl/comments-3.pl | 6 + Task/Comments/Perl/comments-4.pl | 4 + Task/Comments/Perl/comments.pl | 1 + Task/Comments/PicoLisp/comments.l | 12 ++ Task/Comments/Python/comments-2.py | 17 ++ Task/Comments/Python/comments.py | 9 + Task/Comments/REXX/comments-2.rexx | 3 + Task/Comments/REXX/comments.rexx | 42 +++++ Task/Comments/Ruby/comments.rb | 5 + Task/Comments/Scala/comments.scala | 4 + Task/Comments/Tcl/comments-2.tcl | 4 + Task/Comments/Tcl/comments-3.tcl | 3 + Task/Comments/Tcl/comments.tcl | 3 + Task/Death_Star/0DESCRIPTION | 3 + Task/Death_Star/1META.yaml | 6 + Task/Death_Star/C/death_star.c | 112 ++++++++++++ Task/Death_Star/Go/death_star.go | 103 +++++++++++ Task/Death_Star/Perl/death_star.pl | 75 ++++++++ Task/Death_Star/Python/death_star.py | 67 ++++++++ Task/Death_Star/REXX/death_star.rexx | 75 ++++++++ Task/Death_Star/Tcl/death_star-2.tcl | 18 ++ Task/Death_Star/Tcl/death_star.tcl | 115 +++++++++++++ Task/Entropy/0DESCRIPTION | 7 + Task/Entropy/1META.yaml | 2 + Task/Entropy/Haskell/entropy.hs | 8 + Task/Entropy/Perl/entropy.pl | 9 + Task/Entropy/Python/entropy.py | 34 ++++ Task/Entropy/REXX/entropy-2.rexx | 30 ++++ Task/Entropy/REXX/entropy.rexx | 84 +++++++++ Task/Entropy/Ruby/entropy-2.rb | 3 + Task/Entropy/Ruby/entropy.rb | 9 + Task/Entropy/Scala/entropy.scala | 12 ++ Task/Entropy/Tcl/entropy-2.tcl | 2 + Task/Entropy/Tcl/entropy.tcl | 10 ++ Task/FizzBuzz/0DESCRIPTION | 3 + Task/FizzBuzz/1META.yaml | 5 + Task/FizzBuzz/AWK/fizzbuzz-2.awk | 7 + Task/FizzBuzz/AWK/fizzbuzz-3.awk | 1 + Task/FizzBuzz/AWK/fizzbuzz.awk | 11 ++ Task/FizzBuzz/BASIC/fizzbuzz-2.bas | 17 ++ Task/FizzBuzz/BASIC/fizzbuzz-3.bas | 8 + Task/FizzBuzz/BASIC/fizzbuzz.bas | 11 ++ Task/FizzBuzz/Befunge/fizzbuzz.bf | 9 + Task/FizzBuzz/C/fizzbuzz-2.c | 16 ++ Task/FizzBuzz/C/fizzbuzz-3.c | 3 + Task/FizzBuzz/C/fizzbuzz-4.c | 11 ++ Task/FizzBuzz/C/fizzbuzz.c | 20 +++ Task/FizzBuzz/Clojure/fizzbuzz-2.clj | 1 + Task/FizzBuzz/Clojure/fizzbuzz-3.clj | 6 + Task/FizzBuzz/Clojure/fizzbuzz-4.clj | 13 ++ Task/FizzBuzz/Clojure/fizzbuzz-5.clj | 6 + Task/FizzBuzz/Clojure/fizzbuzz-6.clj | 4 + Task/FizzBuzz/Clojure/fizzbuzz.clj | 5 + Task/FizzBuzz/CoffeeScript/fizzbuzz-2.coffee | 2 + Task/FizzBuzz/CoffeeScript/fizzbuzz.coffee | 9 + Task/FizzBuzz/Erlang/fizzbuzz.erl | 7 + Task/FizzBuzz/Forth/fizzbuzz-2.fth | 9 + Task/FizzBuzz/Forth/fizzbuzz-3.fth | 9 + Task/FizzBuzz/Forth/fizzbuzz.fth | 11 ++ Task/FizzBuzz/Fortran/fizzbuzz-2.f | 12 ++ Task/FizzBuzz/Fortran/fizzbuzz.f | 11 ++ Task/FizzBuzz/Go/fizzbuzz.go | 17 ++ Task/FizzBuzz/Haskell/fizzbuzz-2.hs | 5 + Task/FizzBuzz/Haskell/fizzbuzz-3.hs | 12 ++ Task/FizzBuzz/Haskell/fizzbuzz-4.hs | 6 + Task/FizzBuzz/Haskell/fizzbuzz.hs | 7 + Task/FizzBuzz/Java/fizzbuzz-2.java | 11 ++ Task/FizzBuzz/Java/fizzbuzz-3.java | 8 + Task/FizzBuzz/Java/fizzbuzz-4.java | 12 ++ Task/FizzBuzz/Java/fizzbuzz-5.java | 5 + Task/FizzBuzz/Java/fizzbuzz-6.java | 7 + Task/FizzBuzz/Java/fizzbuzz.java | 15 ++ Task/FizzBuzz/JavaScript/fizzbuzz-2.js | 1 + Task/FizzBuzz/JavaScript/fizzbuzz-3.js | 1 + Task/FizzBuzz/JavaScript/fizzbuzz-4.js | 8 + Task/FizzBuzz/JavaScript/fizzbuzz-5.js | 25 +++ Task/FizzBuzz/JavaScript/fizzbuzz.js | 32 ++++ Task/FizzBuzz/Lua/fizzbuzz-2.lua | 13 ++ Task/FizzBuzz/Lua/fizzbuzz-3.lua | 5 + Task/FizzBuzz/Lua/fizzbuzz.lua | 11 ++ Task/FizzBuzz/PHP/fizzbuzz-2.php | 17 ++ Task/FizzBuzz/PHP/fizzbuzz-3.php | 3 + Task/FizzBuzz/PHP/fizzbuzz.php | 13 ++ Task/FizzBuzz/PIR/fizzbuzz.pir | 34 ++++ Task/FizzBuzz/Perl/fizzbuzz-2.pl | 1 + Task/FizzBuzz/Perl/fizzbuzz-3.pl | 1 + Task/FizzBuzz/Perl/fizzbuzz-4.pl | 1 + Task/FizzBuzz/Perl/fizzbuzz.pl | 14 ++ Task/FizzBuzz/PicoLisp/fizzbuzz-2.l | 7 + Task/FizzBuzz/PicoLisp/fizzbuzz.l | 3 + Task/FizzBuzz/Python/fizzbuzz-2.py | 3 + Task/FizzBuzz/Python/fizzbuzz-3.py | 4 + Task/FizzBuzz/Python/fizzbuzz-4.py | 2 + Task/FizzBuzz/Python/fizzbuzz-5.py | 6 + Task/FizzBuzz/Python/fizzbuzz-6.py | 14 ++ Task/FizzBuzz/Python/fizzbuzz-7.py | 6 + Task/FizzBuzz/Python/fizzbuzz-8.py | 13 ++ Task/FizzBuzz/Python/fizzbuzz.py | 9 + Task/FizzBuzz/REXX/fizzbuzz-2.rexx | 11 ++ Task/FizzBuzz/REXX/fizzbuzz-3.rexx | 8 + Task/FizzBuzz/REXX/fizzbuzz.rexx | 9 + Task/FizzBuzz/Ruby/fizzbuzz-2.rb | 11 ++ Task/FizzBuzz/Ruby/fizzbuzz-3.rb | 4 + Task/FizzBuzz/Ruby/fizzbuzz-4.rb | 1 + Task/FizzBuzz/Ruby/fizzbuzz-5.rb | 7 + Task/FizzBuzz/Ruby/fizzbuzz-6.rb | 1 + Task/FizzBuzz/Ruby/fizzbuzz-7.rb | 8 + Task/FizzBuzz/Ruby/fizzbuzz.rb | 6 + Task/FizzBuzz/SNUSP/fizzbuzz.snusp | 35 ++++ Task/FizzBuzz/Scala/fizzbuzz-2.scala | 6 + Task/FizzBuzz/Scala/fizzbuzz-3.scala | 8 + Task/FizzBuzz/Scala/fizzbuzz-4.scala | 2 + Task/FizzBuzz/Scala/fizzbuzz.scala | 6 + Task/FizzBuzz/Tcl/fizzbuzz-2.tcl | 4 + Task/FizzBuzz/Tcl/fizzbuzz.tcl | 9 + Task/FizzBuzz/Turing/fizzbuzz.turing | 13 ++ Task/Go_Fish/0DESCRIPTION | 13 ++ Task/Go_Fish/1META.yaml | 2 + Task/Infinity/0DESCRIPTION | 5 + Task/Infinity/1META.yaml | 4 + Task/Infinity/AWK/infinity.awk | 6 + Task/Infinity/C/infinity-2.c | 9 + Task/Infinity/C/infinity.c | 11 ++ Task/Infinity/CoffeeScript/infinity-2.coffee | 2 + Task/Infinity/CoffeeScript/infinity-3.coffee | 1 + Task/Infinity/CoffeeScript/infinity.coffee | 1 + Task/Infinity/Forth/infinity.fth | 7 + Task/Infinity/Fortran/infinity-2.f | 2 + Task/Infinity/Fortran/infinity.f | 18 ++ Task/Infinity/Go/infinity.go | 19 +++ Task/Infinity/Haskell/infinity-2.hs | 4 + Task/Infinity/Haskell/infinity-3.hs | 4 + Task/Infinity/Haskell/infinity-4.hs | 4 + Task/Infinity/Haskell/infinity.hs | 8 + Task/Infinity/Java/infinity-2.java | 3 + Task/Infinity/Java/infinity-3.java | 1 + Task/Infinity/Java/infinity.java | 2 + Task/Infinity/JavaScript/infinity-2.js | 2 + Task/Infinity/JavaScript/infinity-3.js | 1 + Task/Infinity/JavaScript/infinity.js | 1 + Task/Infinity/Lua/infinity.lua | 3 + Task/Infinity/PHP/infinity.php | 1 + Task/Infinity/Perl/infinity-2.pl | 2 + Task/Infinity/Perl/infinity-3.pl | 1 + Task/Infinity/Perl/infinity-4.pl | 1 + Task/Infinity/Perl/infinity-5.pl | 1 + Task/Infinity/Perl/infinity-6.pl | 3 + Task/Infinity/Perl/infinity-7.pl | 3 + Task/Infinity/Perl/infinity.pl | 2 + Task/Infinity/PicoLisp/infinity.l | 4 + Task/Infinity/Python/infinity-2.py | 4 + Task/Infinity/Python/infinity.py | 2 + Task/Infinity/Ruby/infinity-2.rb | 1 + Task/Infinity/Ruby/infinity.rb | 10 ++ Task/Infinity/Scala/infinity.scala | 11 ++ Task/Infinity/Tcl/infinity-2.tcl | 11 ++ Task/Infinity/Tcl/infinity.tcl | 6 + Task/JSON/0DESCRIPTION | 2 + Task/JSON/C/json.c | 120 +++++++++++++ Task/JSON/Clojure/json.clj | 10 ++ Task/JSON/CoffeeScript/json.coffee | 9 + Task/JSON/Go/json-2.go | 59 +++++++ Task/JSON/Go/json.go | 25 +++ Task/JSON/Haskell/json.hs | 24 +++ Task/JSON/Java/json.java | 43 +++++ Task/JSON/JavaScript/json-2.js | 1 + Task/JSON/JavaScript/json.js | 4 + Task/JSON/PHP/json.php | 7 + Task/JSON/Perl/json.pl | 6 + Task/JSON/PicoLisp/json.l | 49 ++++++ Task/JSON/Python/json-2.py | 4 + Task/JSON/Python/json.py | 10 ++ Task/JSON/Ruby/json.rb | 7 + Task/JSON/Scala/json.scala | 8 + Task/JSON/Tcl/json-2.tcl | 56 ++++++ Task/JSON/Tcl/json-3.tcl | 2 + Task/JSON/Tcl/json.tcl | 5 + Task/Knuth_shuffle/0DESCRIPTION | 1 + Task/Knuth_shuffle/1META.yaml | 2 + Task/Knuth_shuffle/AWK/knuth_shuffle.awk | 21 +++ Task/Knuth_shuffle/BASIC/knuth_shuffle.bas | 21 +++ Task/Knuth_shuffle/C/knuth_shuffle-2.c | 52 ++++++ Task/Knuth_shuffle/C/knuth_shuffle.c | 21 +++ Task/Knuth_shuffle/Clojure/knuth_shuffle.clj | 4 + .../CoffeeScript/knuth_shuffle.coffee | 21 +++ Task/Knuth_shuffle/Forth/knuth_shuffle.fth | 15 ++ Task/Knuth_shuffle/Fortran/knuth_shuffle.f | 33 ++++ Task/Knuth_shuffle/Go/knuth_shuffle-2.go | 48 ++++++ Task/Knuth_shuffle/Go/knuth_shuffle.go | 22 +++ Task/Knuth_shuffle/Haskell/knuth_shuffle-2.hs | 3 + Task/Knuth_shuffle/Haskell/knuth_shuffle-3.hs | 21 +++ Task/Knuth_shuffle/Haskell/knuth_shuffle.hs | 17 ++ Task/Knuth_shuffle/Java/knuth_shuffle.java | 24 +++ .../Knuth_shuffle/JavaScript/knuth_shuffle.js | 28 +++ Task/Knuth_shuffle/Lua/knuth_shuffle.lua | 14 ++ Task/Knuth_shuffle/PHP/knuth_shuffle.php | 18 ++ Task/Knuth_shuffle/Perl/knuth_shuffle.pl | 8 + Task/Knuth_shuffle/PicoLisp/knuth_shuffle.l | 7 + Task/Knuth_shuffle/Python/knuth_shuffle.py | 10 ++ Task/Knuth_shuffle/REXX/knuth_shuffle.rexx | 37 ++++ Task/Knuth_shuffle/Ruby/knuth_shuffle-2.rb | 9 + Task/Knuth_shuffle/Ruby/knuth_shuffle.rb | 21 +++ Task/Knuth_shuffle/Scala/knuth_shuffle.scala | 9 + Task/Knuth_shuffle/Tcl/knuth_shuffle-2.tcl | 11 ++ Task/Knuth_shuffle/Tcl/knuth_shuffle.tcl | 17 ++ Task/Narcissist/0DESCRIPTION | 9 + Task/Narcissist/C/narcissist.c | 1 + Task/Narcissist/Forth/narcissist.fth | 1 + Task/Narcissist/Go/narcissist-2.go | 39 +++++ Task/Narcissist/Go/narcissist.go | 1 + Task/Narcissist/JavaScript/narcissist.js | 1 + Task/Narcissist/Perl/narcissist-2.pl | 1 + Task/Narcissist/Perl/narcissist.pl | 2 + Task/Narcissist/PicoLisp/narcissist.l | 2 + Task/Narcissist/Python/narcissist.py | 7 + Task/Narcissist/REXX/narcissist-2.rexx | 1 + Task/Narcissist/REXX/narcissist.rexx | 1 + Task/Narcissist/Ruby/narcissist.rb | 1 + Task/Narcissist/Tcl/narcissist-2.tcl | 1 + Task/Narcissist/Tcl/narcissist.tcl | 1 + Task/Ordered_words/0DESCRIPTION | 3 + Task/Ordered_words/1META.yaml | 2 + Task/Ordered_words/AWK/ordered_words.awk | 36 ++++ Task/Ordered_words/C/ordered_words-2.c | 87 ++++++++++ Task/Ordered_words/C/ordered_words-3.c | 54 ++++++ Task/Ordered_words/C/ordered_words.c | 83 +++++++++ .../CoffeeScript/ordered_words-2.coffee | 18 ++ .../CoffeeScript/ordered_words.coffee | 21 +++ Task/Ordered_words/Forth/ordered_words.fth | 44 +++++ Task/Ordered_words/Fortran/ordered_words.f | 113 +++++++++++++ Task/Ordered_words/Go/ordered_words.go | 57 +++++++ Task/Ordered_words/Haskell/ordered_words-2.hs | 16 ++ Task/Ordered_words/Haskell/ordered_words-3.hs | 11 ++ Task/Ordered_words/Haskell/ordered_words.hs | 21 +++ Task/Ordered_words/Java/ordered_words.java | 43 +++++ .../JavaScript/ordered_words-2.js | 26 +++ .../Ordered_words/JavaScript/ordered_words.js | 11 ++ Task/Ordered_words/Lua/ordered_words.lua | 29 ++++ Task/Ordered_words/Perl/ordered_words.pl | 12 ++ Task/Ordered_words/PicoLisp/ordered_words.l | 6 + Task/Ordered_words/Python/ordered_words-2.py | 11 ++ Task/Ordered_words/Python/ordered_words-3.py | 3 + Task/Ordered_words/Python/ordered_words.py | 8 + Task/Ordered_words/REXX/ordered_words.rexx | 28 +++ Task/Ordered_words/Ruby/ordered_words.rb | 8 + Task/Ordered_words/Tcl/ordered_words.tcl | 25 +++ Task/Pi/0DESCRIPTION | 4 + Task/Pi/1META.yaml | 2 + Task/Pi/C/pi.c | 68 ++++++++ Task/Pi/Go/pi.go | 83 +++++++++ Task/Pi/Haskell/pi.hs | 5 + Task/Pi/Java/pi.java | 45 +++++ Task/Pi/Perl/pi.pl | 55 ++++++ Task/Pi/PicoLisp/pi.l | 21 +++ Task/Pi/Python/pi.py | 26 +++ Task/Pi/REXX/pi.rexx | 24 +++ Task/Pi/Ruby/pi-2.rb | 28 +++ Task/Pi/Ruby/pi.rb | 20 +++ Task/Pi/Scala/pi.scala | 35 ++++ Task/Pi/Tcl/pi-2.tcl | 5 + Task/Pi/Tcl/pi.tcl | 31 ++++ Task/Quine/0DESCRIPTION | 17 ++ Task/Quine/BASIC/quine-2.bas | 25 +++ Task/Quine/BASIC/quine.bas | 1 + Task/Quine/Befunge/quine.bf | 1 + Task/Quine/C/quine.c | 10 ++ Task/Quine/Clojure/quine.clj | 1 + Task/Quine/CoffeeScript/quine.coffee | 1 + Task/Quine/Erlang/quine.erl | 6 + Task/Quine/Forth/quine.fth | 1 + Task/Quine/Fortran/quine.f | 1 + Task/Quine/Go/quine.go | 8 + Task/Quine/Haskell/quine-2.hs | 1 + Task/Quine/Haskell/quine-3.hs | 1 + Task/Quine/Haskell/quine-4.hs | 2 + Task/Quine/Haskell/quine-5.hs | 1 + Task/Quine/Haskell/quine.hs | 1 + Task/Quine/Java/quine-2.java | 1 + Task/Quine/Java/quine.java | 1 + Task/Quine/JavaScript/quine-2.js | 1 + Task/Quine/JavaScript/quine.js | 1 + Task/Quine/Lua/quine.lua | 1 + Task/Quine/PHP/quine.php | 2 + Task/Quine/Perl/quine-2.pl | 3 + Task/Quine/Perl/quine-3.pl | 1 + Task/Quine/Perl/quine-4.pl | 1 + Task/Quine/Perl/quine-5.pl | 47 +++++ Task/Quine/Perl/quine.pl | 2 + Task/Quine/PicoLisp/quine-2.l | 1 + Task/Quine/PicoLisp/quine.l | 1 + Task/Quine/Python/quine-2.py | 1 + Task/Quine/Python/quine-3.py | 1 + Task/Quine/Python/quine-4.py | 1 + Task/Quine/Python/quine-5.py | 2 + Task/Quine/Python/quine.py | 2 + Task/Quine/REXX/quine-2.rexx | 4 + Task/Quine/REXX/quine-3.rexx | 52 ++++++ Task/Quine/REXX/quine.rexx | 1 + Task/Quine/Ruby/quine-2.rb | 3 + Task/Quine/Ruby/quine-3.rb | 1 + Task/Quine/Ruby/quine.rb | 1 + Task/Quine/Scala/quine-2.scala | 13 ++ Task/Quine/Scala/quine.scala | 6 + Task/Quine/Tcl/quine-2.tcl | 2 + Task/Quine/Tcl/quine-3.tcl | 2 + Task/Quine/Tcl/quine-4.tcl | 34 ++++ Task/Quine/Tcl/quine.tcl | 2 + Task/Search_a_list/0DESCRIPTION | 4 + Task/Search_a_list/1META.yaml | 2 + Task/Search_a_list/AWK/search_a_list.awk | 21 +++ Task/Search_a_list/BASIC/search_a_list.bas | 29 ++++ Task/Search_a_list/C/search_a_list.c | 40 +++++ Task/Search_a_list/Clojure/search_a_list.clj | 5 + Task/Search_a_list/Erlang/search_a_list.erl | 15 ++ Task/Search_a_list/Forth/search_a_list.fth | 11 ++ Task/Search_a_list/Fortran/search_a_list.f | 35 ++++ Task/Search_a_list/Go/search_a_list.go | 79 +++++++++ Task/Search_a_list/Haskell/search_a_list-2.hs | 2 + Task/Search_a_list/Haskell/search_a_list-3.hs | 2 + Task/Search_a_list/Haskell/search_a_list-4.hs | 5 + Task/Search_a_list/Haskell/search_a_list.hs | 4 + Task/Search_a_list/Java/search_a_list-2.java | 11 ++ Task/Search_a_list/Java/search_a_list.java | 12 ++ .../JavaScript/search_a_list-2.js | 18 ++ .../Search_a_list/JavaScript/search_a_list.js | 16 ++ Task/Search_a_list/Lua/search_a_list.lua | 7 + Task/Search_a_list/PHP/search_a_list.php | 9 + Task/Search_a_list/Perl/search_a_list-2.pl | 13 ++ Task/Search_a_list/Perl/search_a_list-3.pl | 13 ++ Task/Search_a_list/Perl/search_a_list.pl | 13 ++ Task/Search_a_list/PicoLisp/search_a_list.l | 10 ++ Task/Search_a_list/Python/search_a_list-2.py | 9 + Task/Search_a_list/Python/search_a_list-3.py | 13 ++ Task/Search_a_list/Python/search_a_list.py | 7 + Task/Search_a_list/REXX/search_a_list-2.rexx | 44 +++++ Task/Search_a_list/REXX/search_a_list-3.rexx | 29 ++++ Task/Search_a_list/REXX/search_a_list-4.rexx | 24 +++ Task/Search_a_list/REXX/search_a_list.rexx | 30 ++++ Task/Search_a_list/Ruby/search_a_list-2.rb | 7 + Task/Search_a_list/Ruby/search_a_list-3.rb | 3 + Task/Search_a_list/Ruby/search_a_list.rb | 9 + Task/Search_a_list/Scala/search_a_list.scala | 3 + Task/Search_a_list/Tcl/search_a_list-2.tcl | 9 + Task/Search_a_list/Tcl/search_a_list.tcl | 8 + 781 files changed, 9080 insertions(+) create mode 100644 .gitignore create mode 100644 Conf/lang.yaml create mode 100644 Conf/rosettacode.yaml create mode 100644 Conf/task.yaml create mode 100644 Lang/4D/0DESCRIPTION create mode 120000 Lang/4D/Comments create mode 100644 Lang/AWK/0DESCRIPTION create mode 120000 Lang/AWK/99_Bottles_of_Beer create mode 120000 Lang/AWK/Anagrams create mode 120000 Lang/AWK/Comments create mode 120000 Lang/AWK/FizzBuzz create mode 120000 Lang/AWK/Infinity create mode 120000 Lang/AWK/Knuth_shuffle create mode 120000 Lang/AWK/Ordered_words create mode 120000 Lang/AWK/Search_a_list create mode 100644 Lang/BASIC/0DESCRIPTION create mode 120000 Lang/BASIC/99_Bottles_of_Beer create mode 120000 Lang/BASIC/Bulls_and_cows create mode 120000 Lang/BASIC/FizzBuzz create mode 120000 Lang/BASIC/Knuth_shuffle create mode 120000 Lang/BASIC/Quine create mode 120000 Lang/BASIC/Search_a_list create mode 100644 Lang/Befunge/0DESCRIPTION create mode 120000 Lang/Befunge/99_Bottles_of_Beer create mode 120000 Lang/Befunge/Comments create mode 120000 Lang/Befunge/FizzBuzz create mode 120000 Lang/Befunge/Quine create mode 100644 Lang/C/0DESCRIPTION create mode 120000 Lang/C/99_Bottles_of_Beer create mode 120000 Lang/C/Anagrams create mode 120000 Lang/C/Bulls_and_cows create mode 120000 Lang/C/Comments create mode 120000 Lang/C/Death_Star create mode 120000 Lang/C/FizzBuzz create mode 120000 Lang/C/Infinity create mode 120000 Lang/C/JSON create mode 120000 Lang/C/Knuth_shuffle create mode 120000 Lang/C/Narcissist create mode 120000 Lang/C/Ordered_words create mode 120000 Lang/C/Pi create mode 120000 Lang/C/Quine create mode 120000 Lang/C/Search_a_list create mode 100644 Lang/Clojure/0DESCRIPTION create mode 120000 Lang/Clojure/99_Bottles_of_Beer create mode 120000 Lang/Clojure/Anagrams create mode 120000 Lang/Clojure/Bulls_and_cows create mode 120000 Lang/Clojure/Comments create mode 120000 Lang/Clojure/FizzBuzz create mode 120000 Lang/Clojure/JSON create mode 120000 Lang/Clojure/Knuth_shuffle create mode 120000 Lang/Clojure/Quine create mode 120000 Lang/Clojure/Search_a_list create mode 100644 Lang/CoffeeScript/0DESCRIPTION create mode 120000 Lang/CoffeeScript/99_Bottles_of_Beer create mode 120000 Lang/CoffeeScript/Anagrams create mode 120000 Lang/CoffeeScript/Comments create mode 120000 Lang/CoffeeScript/FizzBuzz create mode 120000 Lang/CoffeeScript/Infinity create mode 120000 Lang/CoffeeScript/JSON create mode 120000 Lang/CoffeeScript/Knuth_shuffle create mode 120000 Lang/CoffeeScript/Ordered_words create mode 120000 Lang/CoffeeScript/Quine create mode 100644 Lang/Erlang/0DESCRIPTION create mode 120000 Lang/Erlang/99_Bottles_of_Beer create mode 120000 Lang/Erlang/Anagrams create mode 120000 Lang/Erlang/Bulls_and_cows create mode 120000 Lang/Erlang/Comments create mode 120000 Lang/Erlang/FizzBuzz create mode 120000 Lang/Erlang/Quine create mode 120000 Lang/Erlang/Search_a_list create mode 100644 Lang/Forth/0DESCRIPTION create mode 120000 Lang/Forth/99_Bottles_of_Beer create mode 120000 Lang/Forth/Bulls_and_cows create mode 120000 Lang/Forth/Comments create mode 120000 Lang/Forth/FizzBuzz create mode 120000 Lang/Forth/Infinity create mode 120000 Lang/Forth/Knuth_shuffle create mode 120000 Lang/Forth/Narcissist create mode 120000 Lang/Forth/Ordered_words create mode 120000 Lang/Forth/Quine create mode 120000 Lang/Forth/Search_a_list create mode 100644 Lang/Fortran/0DESCRIPTION create mode 120000 Lang/Fortran/99_Bottles_of_Beer create mode 120000 Lang/Fortran/Bulls_and_cows create mode 120000 Lang/Fortran/Comments create mode 120000 Lang/Fortran/FizzBuzz create mode 120000 Lang/Fortran/Infinity create mode 120000 Lang/Fortran/Knuth_shuffle create mode 120000 Lang/Fortran/Ordered_words create mode 120000 Lang/Fortran/Quine create mode 120000 Lang/Fortran/Search_a_list create mode 100644 Lang/Go/0DESCRIPTION create mode 120000 Lang/Go/99_Bottles_of_Beer create mode 120000 Lang/Go/Anagrams create mode 120000 Lang/Go/Bulls_and_cows create mode 120000 Lang/Go/Comments create mode 120000 Lang/Go/Death_Star create mode 120000 Lang/Go/FizzBuzz create mode 120000 Lang/Go/Infinity create mode 120000 Lang/Go/JSON create mode 120000 Lang/Go/Knuth_shuffle create mode 120000 Lang/Go/Narcissist create mode 120000 Lang/Go/Ordered_words create mode 120000 Lang/Go/Pi create mode 120000 Lang/Go/Quine create mode 120000 Lang/Go/Search_a_list create mode 100644 Lang/Haskell/0DESCRIPTION create mode 120000 Lang/Haskell/99_Bottles_of_Beer create mode 120000 Lang/Haskell/Bulls_and_cows create mode 120000 Lang/Haskell/Comments create mode 120000 Lang/Haskell/Entropy create mode 120000 Lang/Haskell/FizzBuzz create mode 120000 Lang/Haskell/Infinity create mode 120000 Lang/Haskell/JSON create mode 120000 Lang/Haskell/Knuth_shuffle create mode 120000 Lang/Haskell/Ordered_words create mode 120000 Lang/Haskell/Pi create mode 120000 Lang/Haskell/Quine create mode 120000 Lang/Haskell/Search_a_list create mode 100644 Lang/Java/0DESCRIPTION create mode 120000 Lang/Java/99_Bottles_of_Beer create mode 120000 Lang/Java/Anagrams create mode 120000 Lang/Java/Bulls_and_cows create mode 120000 Lang/Java/Comments create mode 120000 Lang/Java/FizzBuzz create mode 120000 Lang/Java/Infinity create mode 120000 Lang/Java/JSON create mode 120000 Lang/Java/Knuth_shuffle create mode 120000 Lang/Java/Ordered_words create mode 120000 Lang/Java/Pi create mode 120000 Lang/Java/Quine create mode 120000 Lang/Java/Search_a_list create mode 100644 Lang/JavaScript/0DESCRIPTION create mode 120000 Lang/JavaScript/99_Bottles_of_Beer create mode 120000 Lang/JavaScript/Anagrams create mode 120000 Lang/JavaScript/Bulls_and_cows create mode 120000 Lang/JavaScript/FizzBuzz create mode 120000 Lang/JavaScript/Infinity create mode 120000 Lang/JavaScript/JSON create mode 120000 Lang/JavaScript/Knuth_shuffle create mode 120000 Lang/JavaScript/Narcissist create mode 120000 Lang/JavaScript/Ordered_words create mode 120000 Lang/JavaScript/Quine create mode 120000 Lang/JavaScript/Search_a_list create mode 100644 Lang/LaTeX/0DESCRIPTION create mode 120000 Lang/LaTeX/99_Bottles_of_Beer create mode 120000 Lang/LaTeX/Comments create mode 100644 Lang/Lua/0DESCRIPTION create mode 120000 Lang/Lua/99_Bottles_of_Beer create mode 120000 Lang/Lua/Anagrams create mode 120000 Lang/Lua/Bulls_and_cows create mode 120000 Lang/Lua/Comments create mode 120000 Lang/Lua/FizzBuzz create mode 120000 Lang/Lua/Infinity create mode 120000 Lang/Lua/Knuth_shuffle create mode 120000 Lang/Lua/Ordered_words create mode 120000 Lang/Lua/Quine create mode 120000 Lang/Lua/Search_a_list create mode 100644 Lang/PHP/0DESCRIPTION create mode 120000 Lang/PHP/99_Bottles_of_Beer create mode 120000 Lang/PHP/Anagrams create mode 120000 Lang/PHP/Bulls_and_cows create mode 120000 Lang/PHP/Comments create mode 120000 Lang/PHP/FizzBuzz create mode 120000 Lang/PHP/Infinity create mode 120000 Lang/PHP/JSON create mode 120000 Lang/PHP/Knuth_shuffle create mode 120000 Lang/PHP/Quine create mode 120000 Lang/PHP/Search_a_list create mode 100644 Lang/PIR/0DESCRIPTION create mode 120000 Lang/PIR/99_Bottles_of_Beer create mode 120000 Lang/PIR/FizzBuzz create mode 100644 Lang/Perl/0DESCRIPTION create mode 120000 Lang/Perl/99_Bottles_of_Beer create mode 120000 Lang/Perl/Anagrams create mode 120000 Lang/Perl/Bulls_and_cows create mode 120000 Lang/Perl/Comments create mode 120000 Lang/Perl/Death_Star create mode 120000 Lang/Perl/Entropy create mode 120000 Lang/Perl/FizzBuzz create mode 120000 Lang/Perl/Infinity create mode 120000 Lang/Perl/JSON create mode 120000 Lang/Perl/Knuth_shuffle create mode 120000 Lang/Perl/Narcissist create mode 120000 Lang/Perl/Ordered_words create mode 120000 Lang/Perl/Pi create mode 120000 Lang/Perl/Quine create mode 120000 Lang/Perl/Search_a_list create mode 100644 Lang/PicoLisp/0DESCRIPTION create mode 120000 Lang/PicoLisp/99_Bottles_of_Beer create mode 120000 Lang/PicoLisp/Anagrams create mode 120000 Lang/PicoLisp/Bulls_and_cows create mode 120000 Lang/PicoLisp/Comments create mode 120000 Lang/PicoLisp/FizzBuzz create mode 120000 Lang/PicoLisp/Infinity create mode 120000 Lang/PicoLisp/JSON create mode 120000 Lang/PicoLisp/Knuth_shuffle create mode 120000 Lang/PicoLisp/Narcissist create mode 120000 Lang/PicoLisp/Ordered_words create mode 120000 Lang/PicoLisp/Pi create mode 120000 Lang/PicoLisp/Quine create mode 120000 Lang/PicoLisp/Search_a_list create mode 100644 Lang/Python/0DESCRIPTION create mode 120000 Lang/Python/99_Bottles_of_Beer create mode 120000 Lang/Python/Anagrams create mode 120000 Lang/Python/Bulls_and_cows create mode 120000 Lang/Python/Comments create mode 120000 Lang/Python/Death_Star create mode 120000 Lang/Python/Entropy create mode 120000 Lang/Python/FizzBuzz create mode 120000 Lang/Python/Infinity create mode 120000 Lang/Python/JSON create mode 120000 Lang/Python/Knuth_shuffle create mode 120000 Lang/Python/Narcissist create mode 120000 Lang/Python/Ordered_words create mode 120000 Lang/Python/Pi create mode 120000 Lang/Python/Quine create mode 120000 Lang/Python/Search_a_list create mode 100644 Lang/REXX/0DESCRIPTION create mode 120000 Lang/REXX/99_Bottles_of_Beer create mode 120000 Lang/REXX/Anagrams create mode 120000 Lang/REXX/Bulls_and_cows create mode 120000 Lang/REXX/Comments create mode 120000 Lang/REXX/Death_Star create mode 120000 Lang/REXX/Entropy create mode 120000 Lang/REXX/FizzBuzz create mode 120000 Lang/REXX/Knuth_shuffle create mode 120000 Lang/REXX/Narcissist create mode 120000 Lang/REXX/Ordered_words create mode 120000 Lang/REXX/Pi create mode 120000 Lang/REXX/Quine create mode 120000 Lang/REXX/Search_a_list create mode 100644 Lang/Ruby/0DESCRIPTION create mode 120000 Lang/Ruby/99_Bottles_of_Beer create mode 120000 Lang/Ruby/Anagrams create mode 120000 Lang/Ruby/Bulls_and_cows create mode 120000 Lang/Ruby/Comments create mode 120000 Lang/Ruby/Entropy create mode 120000 Lang/Ruby/FizzBuzz create mode 120000 Lang/Ruby/Infinity create mode 120000 Lang/Ruby/JSON create mode 120000 Lang/Ruby/Knuth_shuffle create mode 120000 Lang/Ruby/Narcissist create mode 120000 Lang/Ruby/Ordered_words create mode 120000 Lang/Ruby/Pi create mode 120000 Lang/Ruby/Quine create mode 120000 Lang/Ruby/Search_a_list create mode 100644 Lang/SNUSP/0DESCRIPTION create mode 120000 Lang/SNUSP/99_Bottles_of_Beer create mode 120000 Lang/SNUSP/FizzBuzz create mode 100644 Lang/Scala/0DESCRIPTION create mode 120000 Lang/Scala/Anagrams create mode 120000 Lang/Scala/Bulls_and_cows create mode 120000 Lang/Scala/Comments create mode 120000 Lang/Scala/Entropy create mode 120000 Lang/Scala/FizzBuzz create mode 120000 Lang/Scala/Infinity create mode 120000 Lang/Scala/JSON create mode 120000 Lang/Scala/Knuth_shuffle create mode 120000 Lang/Scala/Pi create mode 120000 Lang/Scala/Quine create mode 120000 Lang/Scala/Search_a_list create mode 100644 Lang/Tcl/0DESCRIPTION create mode 120000 Lang/Tcl/99_Bottles_of_Beer create mode 120000 Lang/Tcl/Anagrams create mode 120000 Lang/Tcl/Bulls_and_cows create mode 120000 Lang/Tcl/Comments create mode 120000 Lang/Tcl/Death_Star create mode 120000 Lang/Tcl/Entropy create mode 120000 Lang/Tcl/FizzBuzz create mode 120000 Lang/Tcl/Infinity create mode 120000 Lang/Tcl/JSON create mode 120000 Lang/Tcl/Knuth_shuffle create mode 120000 Lang/Tcl/Narcissist create mode 120000 Lang/Tcl/Ordered_words create mode 120000 Lang/Tcl/Pi create mode 120000 Lang/Tcl/Quine create mode 120000 Lang/Tcl/Search_a_list create mode 100644 Lang/Turing/0DESCRIPTION create mode 120000 Lang/Turing/FizzBuzz create mode 100644 Meta/SNUSP.yaml create mode 100644 README.md create mode 100644 Task/99_Bottles_of_Beer/0DESCRIPTION create mode 100644 Task/99_Bottles_of_Beer/AWK/99_bottles_of_beer.awk create mode 100644 Task/99_Bottles_of_Beer/BASIC/99_bottles_of_beer-2.bas create mode 100644 Task/99_Bottles_of_Beer/BASIC/99_bottles_of_beer.bas create mode 100644 Task/99_Bottles_of_Beer/Befunge/99_bottles_of_beer.bf create mode 100644 Task/99_Bottles_of_Beer/C/99_bottles_of_beer-2.c create mode 100644 Task/99_Bottles_of_Beer/C/99_bottles_of_beer-3.c create mode 100644 Task/99_Bottles_of_Beer/C/99_bottles_of_beer-4.c create mode 100644 Task/99_Bottles_of_Beer/C/99_bottles_of_beer.c create mode 100644 Task/99_Bottles_of_Beer/Clojure/99_bottles_of_beer.clj create mode 100644 Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer-2.coffee create mode 100644 Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer-3.coffee create mode 100644 Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer-4.coffee create mode 100644 Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer.coffee create mode 100644 Task/99_Bottles_of_Beer/Erlang/99_bottles_of_beer.erl create mode 100644 Task/99_Bottles_of_Beer/Forth/99_bottles_of_beer.fth create mode 100644 Task/99_Bottles_of_Beer/Fortran/99_bottles_of_beer.f create mode 100644 Task/99_Bottles_of_Beer/Go/99_bottles_of_beer.go create mode 100644 Task/99_Bottles_of_Beer/Haskell/99_bottles_of_beer-2.hs create mode 100644 Task/99_Bottles_of_Beer/Haskell/99_bottles_of_beer-3.hs create mode 100644 Task/99_Bottles_of_Beer/Haskell/99_bottles_of_beer.hs create mode 100644 Task/99_Bottles_of_Beer/Java/99_bottles_of_beer-2.java create mode 100644 Task/99_Bottles_of_Beer/Java/99_bottles_of_beer-3.java create mode 100644 Task/99_Bottles_of_Beer/Java/99_bottles_of_beer.java create mode 100644 Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer-2.js create mode 100644 Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer-3.js create mode 100644 Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer-4.js create mode 100644 Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer.js create mode 100644 Task/99_Bottles_of_Beer/LaTeX/99_bottles_of_beer-2.tex create mode 100644 Task/99_Bottles_of_Beer/LaTeX/99_bottles_of_beer.tex create mode 100644 Task/99_Bottles_of_Beer/Lua/99_bottles_of_beer.lua create mode 100644 Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer-2.php create mode 100644 Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer-3.php create mode 100644 Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer-4.php create mode 100644 Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer.php create mode 100644 Task/99_Bottles_of_Beer/PIR/99_bottles_of_beer.pir create mode 100644 Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer-2.pl create mode 100644 Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer-3.pl create mode 100644 Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer-4.pl create mode 100644 Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer.pl create mode 100644 Task/99_Bottles_of_Beer/PicoLisp/99_bottles_of_beer.l create mode 100644 Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-2.py create mode 100644 Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-3.py create mode 100644 Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-4.py create mode 100644 Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-5.py create mode 100644 Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-6.py create mode 100644 Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-7.py create mode 100644 Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-8.py create mode 100644 Task/99_Bottles_of_Beer/Python/99_bottles_of_beer.py create mode 100644 Task/99_Bottles_of_Beer/REXX/99_bottles_of_beer.rexx create mode 100644 Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer-2.rb create mode 100644 Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer-3.rb create mode 100644 Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer-4.rb create mode 100644 Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer.rb create mode 100644 Task/99_Bottles_of_Beer/SNUSP/99_bottles_of_beer.snusp create mode 100644 Task/99_Bottles_of_Beer/Tcl/99_bottles_of_beer-2.tcl create mode 100644 Task/99_Bottles_of_Beer/Tcl/99_bottles_of_beer.tcl create mode 100644 Task/Anagrams/0DESCRIPTION create mode 100644 Task/Anagrams/1META.yaml create mode 100644 Task/Anagrams/AWK/anagrams.awk create mode 100644 Task/Anagrams/C/anagrams-2.c create mode 100644 Task/Anagrams/C/anagrams.c create mode 100644 Task/Anagrams/Clojure/anagrams.clj create mode 100644 Task/Anagrams/CoffeeScript/anagrams-2.coffee create mode 100644 Task/Anagrams/CoffeeScript/anagrams.coffee create mode 100644 Task/Anagrams/Erlang/anagrams.erl create mode 100644 Task/Anagrams/Go/anagrams-2.go create mode 100644 Task/Anagrams/Go/anagrams-3.go create mode 100644 Task/Anagrams/Go/anagrams-4.go create mode 100644 Task/Anagrams/Go/anagrams.go create mode 100644 Task/Anagrams/Java/anagrams.java create mode 100644 Task/Anagrams/JavaScript/anagrams.js create mode 100644 Task/Anagrams/Lua/anagrams.lua create mode 100644 Task/Anagrams/PHP/anagrams.php create mode 100644 Task/Anagrams/Perl/anagrams-2.pl create mode 100644 Task/Anagrams/Perl/anagrams.pl create mode 100644 Task/Anagrams/PicoLisp/anagrams-2.l create mode 100644 Task/Anagrams/PicoLisp/anagrams.l create mode 100644 Task/Anagrams/Python/anagrams-2.py create mode 100644 Task/Anagrams/Python/anagrams-3.py create mode 100644 Task/Anagrams/Python/anagrams-4.py create mode 100644 Task/Anagrams/Python/anagrams.py create mode 100644 Task/Anagrams/REXX/anagrams.rexx create mode 100644 Task/Anagrams/Ruby/anagrams-2.rb create mode 100644 Task/Anagrams/Ruby/anagrams.rb create mode 100644 Task/Anagrams/Scala/anagrams-2.scala create mode 100644 Task/Anagrams/Scala/anagrams.scala create mode 100644 Task/Anagrams/Tcl/anagrams.tcl create mode 100644 Task/Bulls_and_cows/0DESCRIPTION create mode 100644 Task/Bulls_and_cows/1META.yaml create mode 100644 Task/Bulls_and_cows/BASIC/bulls_and_cows.bas create mode 100644 Task/Bulls_and_cows/C/bulls_and_cows-2.c create mode 100644 Task/Bulls_and_cows/C/bulls_and_cows.c create mode 100644 Task/Bulls_and_cows/Clojure/bulls_and_cows.clj create mode 100644 Task/Bulls_and_cows/Erlang/bulls_and_cows-2.erl create mode 100644 Task/Bulls_and_cows/Erlang/bulls_and_cows.erl create mode 100644 Task/Bulls_and_cows/Forth/bulls_and_cows.fth create mode 100644 Task/Bulls_and_cows/Fortran/bulls_and_cows.f create mode 100644 Task/Bulls_and_cows/Go/bulls_and_cows-2.go create mode 100644 Task/Bulls_and_cows/Go/bulls_and_cows.go create mode 100644 Task/Bulls_and_cows/Haskell/bulls_and_cows.hs create mode 100644 Task/Bulls_and_cows/Java/bulls_and_cows.java create mode 100644 Task/Bulls_and_cows/JavaScript/bulls_and_cows.js create mode 100644 Task/Bulls_and_cows/Lua/bulls_and_cows.lua create mode 100644 Task/Bulls_and_cows/PHP/bulls_and_cows.php create mode 100644 Task/Bulls_and_cows/Perl/bulls_and_cows.pl create mode 100644 Task/Bulls_and_cows/PicoLisp/bulls_and_cows.l create mode 100644 Task/Bulls_and_cows/Python/bulls_and_cows.py create mode 100644 Task/Bulls_and_cows/REXX/bulls_and_cows-2.rexx create mode 100644 Task/Bulls_and_cows/REXX/bulls_and_cows.rexx create mode 100644 Task/Bulls_and_cows/Ruby/bulls_and_cows.rb create mode 100644 Task/Bulls_and_cows/Scala/bulls_and_cows.scala create mode 100644 Task/Bulls_and_cows/Tcl/bulls_and_cows.tcl create mode 100644 Task/Comments/0DESCRIPTION create mode 100644 Task/Comments/1META.yaml create mode 100644 Task/Comments/4D/comments.4d create mode 100644 Task/Comments/AWK/comments.awk create mode 100644 Task/Comments/Befunge/comments-2.bf create mode 100644 Task/Comments/Befunge/comments.bf create mode 100644 Task/Comments/C/comments-2.c create mode 100644 Task/Comments/C/comments-3.c create mode 100644 Task/Comments/C/comments-4.c create mode 100644 Task/Comments/C/comments-5.c create mode 100644 Task/Comments/C/comments-6.c create mode 100644 Task/Comments/C/comments-7.c create mode 100644 Task/Comments/C/comments.c create mode 100644 Task/Comments/Clojure/comments-2.clj create mode 100644 Task/Comments/Clojure/comments-3.clj create mode 100644 Task/Comments/Clojure/comments.clj create mode 100644 Task/Comments/CoffeeScript/comments.coffee create mode 100644 Task/Comments/Erlang/comments.erl create mode 100644 Task/Comments/Forth/comments-2.fth create mode 100644 Task/Comments/Forth/comments-3.fth create mode 100644 Task/Comments/Forth/comments-4.fth create mode 100644 Task/Comments/Forth/comments.fth create mode 100644 Task/Comments/Fortran/comments-2.f create mode 100644 Task/Comments/Fortran/comments-3.f create mode 100644 Task/Comments/Fortran/comments-4.f create mode 100644 Task/Comments/Fortran/comments.f create mode 100644 Task/Comments/Go/comments.go create mode 100644 Task/Comments/Haskell/comments.hs create mode 100644 Task/Comments/Java/comments-2.java create mode 100644 Task/Comments/Java/comments-3.java create mode 100644 Task/Comments/Java/comments-4.java create mode 100644 Task/Comments/Java/comments-5.java create mode 100644 Task/Comments/Java/comments.java create mode 100644 Task/Comments/LaTeX/comments-2.tex create mode 100644 Task/Comments/LaTeX/comments.tex create mode 100644 Task/Comments/Lua/comments-2.lua create mode 100644 Task/Comments/Lua/comments.lua create mode 100644 Task/Comments/PHP/comments-2.php create mode 100644 Task/Comments/PHP/comments-3.php create mode 100644 Task/Comments/PHP/comments-4.php create mode 100644 Task/Comments/PHP/comments.php create mode 100644 Task/Comments/Perl/comments-2.pl create mode 100644 Task/Comments/Perl/comments-3.pl create mode 100644 Task/Comments/Perl/comments-4.pl create mode 100644 Task/Comments/Perl/comments.pl create mode 100644 Task/Comments/PicoLisp/comments.l create mode 100644 Task/Comments/Python/comments-2.py create mode 100644 Task/Comments/Python/comments.py create mode 100644 Task/Comments/REXX/comments-2.rexx create mode 100644 Task/Comments/REXX/comments.rexx create mode 100644 Task/Comments/Ruby/comments.rb create mode 100644 Task/Comments/Scala/comments.scala create mode 100644 Task/Comments/Tcl/comments-2.tcl create mode 100644 Task/Comments/Tcl/comments-3.tcl create mode 100644 Task/Comments/Tcl/comments.tcl create mode 100644 Task/Death_Star/0DESCRIPTION create mode 100644 Task/Death_Star/1META.yaml create mode 100644 Task/Death_Star/C/death_star.c create mode 100644 Task/Death_Star/Go/death_star.go create mode 100644 Task/Death_Star/Perl/death_star.pl create mode 100644 Task/Death_Star/Python/death_star.py create mode 100644 Task/Death_Star/REXX/death_star.rexx create mode 100644 Task/Death_Star/Tcl/death_star-2.tcl create mode 100644 Task/Death_Star/Tcl/death_star.tcl create mode 100644 Task/Entropy/0DESCRIPTION create mode 100644 Task/Entropy/1META.yaml create mode 100644 Task/Entropy/Haskell/entropy.hs create mode 100644 Task/Entropy/Perl/entropy.pl create mode 100644 Task/Entropy/Python/entropy.py create mode 100644 Task/Entropy/REXX/entropy-2.rexx create mode 100644 Task/Entropy/REXX/entropy.rexx create mode 100644 Task/Entropy/Ruby/entropy-2.rb create mode 100644 Task/Entropy/Ruby/entropy.rb create mode 100644 Task/Entropy/Scala/entropy.scala create mode 100644 Task/Entropy/Tcl/entropy-2.tcl create mode 100644 Task/Entropy/Tcl/entropy.tcl create mode 100644 Task/FizzBuzz/0DESCRIPTION create mode 100644 Task/FizzBuzz/1META.yaml create mode 100644 Task/FizzBuzz/AWK/fizzbuzz-2.awk create mode 100644 Task/FizzBuzz/AWK/fizzbuzz-3.awk create mode 100644 Task/FizzBuzz/AWK/fizzbuzz.awk create mode 100644 Task/FizzBuzz/BASIC/fizzbuzz-2.bas create mode 100644 Task/FizzBuzz/BASIC/fizzbuzz-3.bas create mode 100644 Task/FizzBuzz/BASIC/fizzbuzz.bas create mode 100644 Task/FizzBuzz/Befunge/fizzbuzz.bf create mode 100644 Task/FizzBuzz/C/fizzbuzz-2.c create mode 100644 Task/FizzBuzz/C/fizzbuzz-3.c create mode 100644 Task/FizzBuzz/C/fizzbuzz-4.c create mode 100644 Task/FizzBuzz/C/fizzbuzz.c create mode 100644 Task/FizzBuzz/Clojure/fizzbuzz-2.clj create mode 100644 Task/FizzBuzz/Clojure/fizzbuzz-3.clj create mode 100644 Task/FizzBuzz/Clojure/fizzbuzz-4.clj create mode 100644 Task/FizzBuzz/Clojure/fizzbuzz-5.clj create mode 100644 Task/FizzBuzz/Clojure/fizzbuzz-6.clj create mode 100644 Task/FizzBuzz/Clojure/fizzbuzz.clj create mode 100644 Task/FizzBuzz/CoffeeScript/fizzbuzz-2.coffee create mode 100644 Task/FizzBuzz/CoffeeScript/fizzbuzz.coffee create mode 100644 Task/FizzBuzz/Erlang/fizzbuzz.erl create mode 100644 Task/FizzBuzz/Forth/fizzbuzz-2.fth create mode 100644 Task/FizzBuzz/Forth/fizzbuzz-3.fth create mode 100644 Task/FizzBuzz/Forth/fizzbuzz.fth create mode 100644 Task/FizzBuzz/Fortran/fizzbuzz-2.f create mode 100644 Task/FizzBuzz/Fortran/fizzbuzz.f create mode 100644 Task/FizzBuzz/Go/fizzbuzz.go create mode 100644 Task/FizzBuzz/Haskell/fizzbuzz-2.hs create mode 100644 Task/FizzBuzz/Haskell/fizzbuzz-3.hs create mode 100644 Task/FizzBuzz/Haskell/fizzbuzz-4.hs create mode 100644 Task/FizzBuzz/Haskell/fizzbuzz.hs create mode 100644 Task/FizzBuzz/Java/fizzbuzz-2.java create mode 100644 Task/FizzBuzz/Java/fizzbuzz-3.java create mode 100644 Task/FizzBuzz/Java/fizzbuzz-4.java create mode 100644 Task/FizzBuzz/Java/fizzbuzz-5.java create mode 100644 Task/FizzBuzz/Java/fizzbuzz-6.java create mode 100644 Task/FizzBuzz/Java/fizzbuzz.java create mode 100644 Task/FizzBuzz/JavaScript/fizzbuzz-2.js create mode 100644 Task/FizzBuzz/JavaScript/fizzbuzz-3.js create mode 100644 Task/FizzBuzz/JavaScript/fizzbuzz-4.js create mode 100644 Task/FizzBuzz/JavaScript/fizzbuzz-5.js create mode 100644 Task/FizzBuzz/JavaScript/fizzbuzz.js create mode 100644 Task/FizzBuzz/Lua/fizzbuzz-2.lua create mode 100644 Task/FizzBuzz/Lua/fizzbuzz-3.lua create mode 100644 Task/FizzBuzz/Lua/fizzbuzz.lua create mode 100644 Task/FizzBuzz/PHP/fizzbuzz-2.php create mode 100644 Task/FizzBuzz/PHP/fizzbuzz-3.php create mode 100644 Task/FizzBuzz/PHP/fizzbuzz.php create mode 100644 Task/FizzBuzz/PIR/fizzbuzz.pir create mode 100644 Task/FizzBuzz/Perl/fizzbuzz-2.pl create mode 100644 Task/FizzBuzz/Perl/fizzbuzz-3.pl create mode 100644 Task/FizzBuzz/Perl/fizzbuzz-4.pl create mode 100644 Task/FizzBuzz/Perl/fizzbuzz.pl create mode 100644 Task/FizzBuzz/PicoLisp/fizzbuzz-2.l create mode 100644 Task/FizzBuzz/PicoLisp/fizzbuzz.l create mode 100644 Task/FizzBuzz/Python/fizzbuzz-2.py create mode 100644 Task/FizzBuzz/Python/fizzbuzz-3.py create mode 100644 Task/FizzBuzz/Python/fizzbuzz-4.py create mode 100644 Task/FizzBuzz/Python/fizzbuzz-5.py create mode 100644 Task/FizzBuzz/Python/fizzbuzz-6.py create mode 100644 Task/FizzBuzz/Python/fizzbuzz-7.py create mode 100644 Task/FizzBuzz/Python/fizzbuzz-8.py create mode 100644 Task/FizzBuzz/Python/fizzbuzz.py create mode 100644 Task/FizzBuzz/REXX/fizzbuzz-2.rexx create mode 100644 Task/FizzBuzz/REXX/fizzbuzz-3.rexx create mode 100644 Task/FizzBuzz/REXX/fizzbuzz.rexx create mode 100644 Task/FizzBuzz/Ruby/fizzbuzz-2.rb create mode 100644 Task/FizzBuzz/Ruby/fizzbuzz-3.rb create mode 100644 Task/FizzBuzz/Ruby/fizzbuzz-4.rb create mode 100644 Task/FizzBuzz/Ruby/fizzbuzz-5.rb create mode 100644 Task/FizzBuzz/Ruby/fizzbuzz-6.rb create mode 100644 Task/FizzBuzz/Ruby/fizzbuzz-7.rb create mode 100644 Task/FizzBuzz/Ruby/fizzbuzz.rb create mode 100644 Task/FizzBuzz/SNUSP/fizzbuzz.snusp create mode 100644 Task/FizzBuzz/Scala/fizzbuzz-2.scala create mode 100644 Task/FizzBuzz/Scala/fizzbuzz-3.scala create mode 100644 Task/FizzBuzz/Scala/fizzbuzz-4.scala create mode 100644 Task/FizzBuzz/Scala/fizzbuzz.scala create mode 100644 Task/FizzBuzz/Tcl/fizzbuzz-2.tcl create mode 100644 Task/FizzBuzz/Tcl/fizzbuzz.tcl create mode 100644 Task/FizzBuzz/Turing/fizzbuzz.turing create mode 100644 Task/Go_Fish/0DESCRIPTION create mode 100644 Task/Go_Fish/1META.yaml create mode 100644 Task/Infinity/0DESCRIPTION create mode 100644 Task/Infinity/1META.yaml create mode 100644 Task/Infinity/AWK/infinity.awk create mode 100644 Task/Infinity/C/infinity-2.c create mode 100644 Task/Infinity/C/infinity.c create mode 100644 Task/Infinity/CoffeeScript/infinity-2.coffee create mode 100644 Task/Infinity/CoffeeScript/infinity-3.coffee create mode 100644 Task/Infinity/CoffeeScript/infinity.coffee create mode 100644 Task/Infinity/Forth/infinity.fth create mode 100644 Task/Infinity/Fortran/infinity-2.f create mode 100644 Task/Infinity/Fortran/infinity.f create mode 100644 Task/Infinity/Go/infinity.go create mode 100644 Task/Infinity/Haskell/infinity-2.hs create mode 100644 Task/Infinity/Haskell/infinity-3.hs create mode 100644 Task/Infinity/Haskell/infinity-4.hs create mode 100644 Task/Infinity/Haskell/infinity.hs create mode 100644 Task/Infinity/Java/infinity-2.java create mode 100644 Task/Infinity/Java/infinity-3.java create mode 100644 Task/Infinity/Java/infinity.java create mode 100644 Task/Infinity/JavaScript/infinity-2.js create mode 100644 Task/Infinity/JavaScript/infinity-3.js create mode 100644 Task/Infinity/JavaScript/infinity.js create mode 100644 Task/Infinity/Lua/infinity.lua create mode 100644 Task/Infinity/PHP/infinity.php create mode 100644 Task/Infinity/Perl/infinity-2.pl create mode 100644 Task/Infinity/Perl/infinity-3.pl create mode 100644 Task/Infinity/Perl/infinity-4.pl create mode 100644 Task/Infinity/Perl/infinity-5.pl create mode 100644 Task/Infinity/Perl/infinity-6.pl create mode 100644 Task/Infinity/Perl/infinity-7.pl create mode 100644 Task/Infinity/Perl/infinity.pl create mode 100644 Task/Infinity/PicoLisp/infinity.l create mode 100644 Task/Infinity/Python/infinity-2.py create mode 100644 Task/Infinity/Python/infinity.py create mode 100644 Task/Infinity/Ruby/infinity-2.rb create mode 100644 Task/Infinity/Ruby/infinity.rb create mode 100644 Task/Infinity/Scala/infinity.scala create mode 100644 Task/Infinity/Tcl/infinity-2.tcl create mode 100644 Task/Infinity/Tcl/infinity.tcl create mode 100644 Task/JSON/0DESCRIPTION create mode 100644 Task/JSON/C/json.c create mode 100644 Task/JSON/Clojure/json.clj create mode 100644 Task/JSON/CoffeeScript/json.coffee create mode 100644 Task/JSON/Go/json-2.go create mode 100644 Task/JSON/Go/json.go create mode 100644 Task/JSON/Haskell/json.hs create mode 100644 Task/JSON/Java/json.java create mode 100644 Task/JSON/JavaScript/json-2.js create mode 100644 Task/JSON/JavaScript/json.js create mode 100644 Task/JSON/PHP/json.php create mode 100644 Task/JSON/Perl/json.pl create mode 100644 Task/JSON/PicoLisp/json.l create mode 100644 Task/JSON/Python/json-2.py create mode 100644 Task/JSON/Python/json.py create mode 100644 Task/JSON/Ruby/json.rb create mode 100644 Task/JSON/Scala/json.scala create mode 100644 Task/JSON/Tcl/json-2.tcl create mode 100644 Task/JSON/Tcl/json-3.tcl create mode 100644 Task/JSON/Tcl/json.tcl create mode 100644 Task/Knuth_shuffle/0DESCRIPTION create mode 100644 Task/Knuth_shuffle/1META.yaml create mode 100644 Task/Knuth_shuffle/AWK/knuth_shuffle.awk create mode 100644 Task/Knuth_shuffle/BASIC/knuth_shuffle.bas create mode 100644 Task/Knuth_shuffle/C/knuth_shuffle-2.c create mode 100644 Task/Knuth_shuffle/C/knuth_shuffle.c create mode 100644 Task/Knuth_shuffle/Clojure/knuth_shuffle.clj create mode 100644 Task/Knuth_shuffle/CoffeeScript/knuth_shuffle.coffee create mode 100644 Task/Knuth_shuffle/Forth/knuth_shuffle.fth create mode 100644 Task/Knuth_shuffle/Fortran/knuth_shuffle.f create mode 100644 Task/Knuth_shuffle/Go/knuth_shuffle-2.go create mode 100644 Task/Knuth_shuffle/Go/knuth_shuffle.go create mode 100644 Task/Knuth_shuffle/Haskell/knuth_shuffle-2.hs create mode 100644 Task/Knuth_shuffle/Haskell/knuth_shuffle-3.hs create mode 100644 Task/Knuth_shuffle/Haskell/knuth_shuffle.hs create mode 100644 Task/Knuth_shuffle/Java/knuth_shuffle.java create mode 100644 Task/Knuth_shuffle/JavaScript/knuth_shuffle.js create mode 100644 Task/Knuth_shuffle/Lua/knuth_shuffle.lua create mode 100644 Task/Knuth_shuffle/PHP/knuth_shuffle.php create mode 100644 Task/Knuth_shuffle/Perl/knuth_shuffle.pl create mode 100644 Task/Knuth_shuffle/PicoLisp/knuth_shuffle.l create mode 100644 Task/Knuth_shuffle/Python/knuth_shuffle.py create mode 100644 Task/Knuth_shuffle/REXX/knuth_shuffle.rexx create mode 100644 Task/Knuth_shuffle/Ruby/knuth_shuffle-2.rb create mode 100644 Task/Knuth_shuffle/Ruby/knuth_shuffle.rb create mode 100644 Task/Knuth_shuffle/Scala/knuth_shuffle.scala create mode 100644 Task/Knuth_shuffle/Tcl/knuth_shuffle-2.tcl create mode 100644 Task/Knuth_shuffle/Tcl/knuth_shuffle.tcl create mode 100644 Task/Narcissist/0DESCRIPTION create mode 100644 Task/Narcissist/C/narcissist.c create mode 100644 Task/Narcissist/Forth/narcissist.fth create mode 100644 Task/Narcissist/Go/narcissist-2.go create mode 100644 Task/Narcissist/Go/narcissist.go create mode 100644 Task/Narcissist/JavaScript/narcissist.js create mode 100644 Task/Narcissist/Perl/narcissist-2.pl create mode 100644 Task/Narcissist/Perl/narcissist.pl create mode 100644 Task/Narcissist/PicoLisp/narcissist.l create mode 100644 Task/Narcissist/Python/narcissist.py create mode 100644 Task/Narcissist/REXX/narcissist-2.rexx create mode 100644 Task/Narcissist/REXX/narcissist.rexx create mode 100644 Task/Narcissist/Ruby/narcissist.rb create mode 100644 Task/Narcissist/Tcl/narcissist-2.tcl create mode 100644 Task/Narcissist/Tcl/narcissist.tcl create mode 100644 Task/Ordered_words/0DESCRIPTION create mode 100644 Task/Ordered_words/1META.yaml create mode 100644 Task/Ordered_words/AWK/ordered_words.awk create mode 100644 Task/Ordered_words/C/ordered_words-2.c create mode 100644 Task/Ordered_words/C/ordered_words-3.c create mode 100644 Task/Ordered_words/C/ordered_words.c create mode 100644 Task/Ordered_words/CoffeeScript/ordered_words-2.coffee create mode 100644 Task/Ordered_words/CoffeeScript/ordered_words.coffee create mode 100644 Task/Ordered_words/Forth/ordered_words.fth create mode 100644 Task/Ordered_words/Fortran/ordered_words.f create mode 100644 Task/Ordered_words/Go/ordered_words.go create mode 100644 Task/Ordered_words/Haskell/ordered_words-2.hs create mode 100644 Task/Ordered_words/Haskell/ordered_words-3.hs create mode 100644 Task/Ordered_words/Haskell/ordered_words.hs create mode 100644 Task/Ordered_words/Java/ordered_words.java create mode 100644 Task/Ordered_words/JavaScript/ordered_words-2.js create mode 100644 Task/Ordered_words/JavaScript/ordered_words.js create mode 100644 Task/Ordered_words/Lua/ordered_words.lua create mode 100644 Task/Ordered_words/Perl/ordered_words.pl create mode 100644 Task/Ordered_words/PicoLisp/ordered_words.l create mode 100644 Task/Ordered_words/Python/ordered_words-2.py create mode 100644 Task/Ordered_words/Python/ordered_words-3.py create mode 100644 Task/Ordered_words/Python/ordered_words.py create mode 100644 Task/Ordered_words/REXX/ordered_words.rexx create mode 100644 Task/Ordered_words/Ruby/ordered_words.rb create mode 100644 Task/Ordered_words/Tcl/ordered_words.tcl create mode 100644 Task/Pi/0DESCRIPTION create mode 100644 Task/Pi/1META.yaml create mode 100644 Task/Pi/C/pi.c create mode 100644 Task/Pi/Go/pi.go create mode 100644 Task/Pi/Haskell/pi.hs create mode 100644 Task/Pi/Java/pi.java create mode 100644 Task/Pi/Perl/pi.pl create mode 100644 Task/Pi/PicoLisp/pi.l create mode 100644 Task/Pi/Python/pi.py create mode 100644 Task/Pi/REXX/pi.rexx create mode 100644 Task/Pi/Ruby/pi-2.rb create mode 100644 Task/Pi/Ruby/pi.rb create mode 100644 Task/Pi/Scala/pi.scala create mode 100644 Task/Pi/Tcl/pi-2.tcl create mode 100644 Task/Pi/Tcl/pi.tcl create mode 100644 Task/Quine/0DESCRIPTION create mode 100644 Task/Quine/BASIC/quine-2.bas create mode 100644 Task/Quine/BASIC/quine.bas create mode 100644 Task/Quine/Befunge/quine.bf create mode 100644 Task/Quine/C/quine.c create mode 100644 Task/Quine/Clojure/quine.clj create mode 100644 Task/Quine/CoffeeScript/quine.coffee create mode 100644 Task/Quine/Erlang/quine.erl create mode 100644 Task/Quine/Forth/quine.fth create mode 100644 Task/Quine/Fortran/quine.f create mode 100644 Task/Quine/Go/quine.go create mode 100644 Task/Quine/Haskell/quine-2.hs create mode 100644 Task/Quine/Haskell/quine-3.hs create mode 100644 Task/Quine/Haskell/quine-4.hs create mode 100644 Task/Quine/Haskell/quine-5.hs create mode 100644 Task/Quine/Haskell/quine.hs create mode 100644 Task/Quine/Java/quine-2.java create mode 100644 Task/Quine/Java/quine.java create mode 100644 Task/Quine/JavaScript/quine-2.js create mode 100644 Task/Quine/JavaScript/quine.js create mode 100644 Task/Quine/Lua/quine.lua create mode 100644 Task/Quine/PHP/quine.php create mode 100644 Task/Quine/Perl/quine-2.pl create mode 100644 Task/Quine/Perl/quine-3.pl create mode 100644 Task/Quine/Perl/quine-4.pl create mode 100644 Task/Quine/Perl/quine-5.pl create mode 100644 Task/Quine/Perl/quine.pl create mode 100644 Task/Quine/PicoLisp/quine-2.l create mode 100644 Task/Quine/PicoLisp/quine.l create mode 100644 Task/Quine/Python/quine-2.py create mode 100644 Task/Quine/Python/quine-3.py create mode 100644 Task/Quine/Python/quine-4.py create mode 100644 Task/Quine/Python/quine-5.py create mode 100644 Task/Quine/Python/quine.py create mode 100644 Task/Quine/REXX/quine-2.rexx create mode 100644 Task/Quine/REXX/quine-3.rexx create mode 100644 Task/Quine/REXX/quine.rexx create mode 100644 Task/Quine/Ruby/quine-2.rb create mode 100644 Task/Quine/Ruby/quine-3.rb create mode 100644 Task/Quine/Ruby/quine.rb create mode 100644 Task/Quine/Scala/quine-2.scala create mode 100644 Task/Quine/Scala/quine.scala create mode 100644 Task/Quine/Tcl/quine-2.tcl create mode 100644 Task/Quine/Tcl/quine-3.tcl create mode 100644 Task/Quine/Tcl/quine-4.tcl create mode 100644 Task/Quine/Tcl/quine.tcl create mode 100644 Task/Search_a_list/0DESCRIPTION create mode 100644 Task/Search_a_list/1META.yaml create mode 100644 Task/Search_a_list/AWK/search_a_list.awk create mode 100644 Task/Search_a_list/BASIC/search_a_list.bas create mode 100644 Task/Search_a_list/C/search_a_list.c create mode 100644 Task/Search_a_list/Clojure/search_a_list.clj create mode 100644 Task/Search_a_list/Erlang/search_a_list.erl create mode 100644 Task/Search_a_list/Forth/search_a_list.fth create mode 100644 Task/Search_a_list/Fortran/search_a_list.f create mode 100644 Task/Search_a_list/Go/search_a_list.go create mode 100644 Task/Search_a_list/Haskell/search_a_list-2.hs create mode 100644 Task/Search_a_list/Haskell/search_a_list-3.hs create mode 100644 Task/Search_a_list/Haskell/search_a_list-4.hs create mode 100644 Task/Search_a_list/Haskell/search_a_list.hs create mode 100644 Task/Search_a_list/Java/search_a_list-2.java create mode 100644 Task/Search_a_list/Java/search_a_list.java create mode 100644 Task/Search_a_list/JavaScript/search_a_list-2.js create mode 100644 Task/Search_a_list/JavaScript/search_a_list.js create mode 100644 Task/Search_a_list/Lua/search_a_list.lua create mode 100644 Task/Search_a_list/PHP/search_a_list.php create mode 100644 Task/Search_a_list/Perl/search_a_list-2.pl create mode 100644 Task/Search_a_list/Perl/search_a_list-3.pl create mode 100644 Task/Search_a_list/Perl/search_a_list.pl create mode 100644 Task/Search_a_list/PicoLisp/search_a_list.l create mode 100644 Task/Search_a_list/Python/search_a_list-2.py create mode 100644 Task/Search_a_list/Python/search_a_list-3.py create mode 100644 Task/Search_a_list/Python/search_a_list.py create mode 100644 Task/Search_a_list/REXX/search_a_list-2.rexx create mode 100644 Task/Search_a_list/REXX/search_a_list-3.rexx create mode 100644 Task/Search_a_list/REXX/search_a_list-4.rexx create mode 100644 Task/Search_a_list/REXX/search_a_list.rexx create mode 100644 Task/Search_a_list/Ruby/search_a_list-2.rb create mode 100644 Task/Search_a_list/Ruby/search_a_list-3.rb create mode 100644 Task/Search_a_list/Ruby/search_a_list.rb create mode 100644 Task/Search_a_list/Scala/search_a_list.scala create mode 100644 Task/Search_a_list/Tcl/search_a_list-2.tcl create mode 100644 Task/Search_a_list/Tcl/search_a_list.tcl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..d1899d9e0b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Cache +ToDo diff --git a/Conf/lang.yaml b/Conf/lang.yaml new file mode 100644 index 0000000000..d04bbba4c9 --- /dev/null +++ b/Conf/lang.yaml @@ -0,0 +1,54 @@ +4D: + ext: 4d +AWK: + ext: awk +BASIC: + ext: bas +Befunge: + ext: bf +C: + ext: c +Clojure: + ext: clj +CoffeeScript: + ext: coffee +Erlang: + ext: erl +Forth: + ext: fth +Fortran: + ext: f +Go: + ext: go +Haskell: + ext: hs +Java: + ext: java +JavaScript: + ext: js +LaTeX: + ext: tex +Lua: + ext: lua +Perl: + ext: pl +PHP: + ext: php +PicoLisp: + ext: l +PIR: + ext: pir +Python: + ext: py +REXX: + ext: rexx +Ruby: + ext: rb +Scala: + ext: scala +SNUSP: + ext: snusp +Tcl: + ext: tcl +Turing: + ext: turing diff --git a/Conf/rosettacode.yaml b/Conf/rosettacode.yaml new file mode 100644 index 0000000000..dd27d63f7e --- /dev/null +++ b/Conf/rosettacode.yaml @@ -0,0 +1 @@ +api_url: http://rosettacode.org/mw/api.php diff --git a/Conf/task.yaml b/Conf/task.yaml new file mode 100644 index 0000000000..39a158239f --- /dev/null +++ b/Conf/task.yaml @@ -0,0 +1,21 @@ +99 Bottles of Beer: {} +Anagrams: {} +Bulls and cows: {} +Comments: {} +Death Star: {} +Entropy: {} +FizzBuzz: {} +Go Fish: {} +# Happy numbers: {} +Infinity: {} +JSON: {} +Knuth shuffle: {} +# Leap year: {} +# Mandlbrot set: {} +Narcissist: {} +Ordered words: {} +Pi: {} +Quine: {} +# ROT-13: {} +Search a list: {} + diff --git a/Lang/4D/0DESCRIPTION b/Lang/4D/0DESCRIPTION new file mode 100644 index 0000000000..8cd174cb58 --- /dev/null +++ b/Lang/4D/0DESCRIPTION @@ -0,0 +1,3 @@ +{{stub}}{{language|4D}}{{IDE}}'''4D''' (or '''4th Dimension''') is a database management system and [[:Category:Integrated Development Environments|integrated development environment]] authored by Laurent Ribardière in 1984. +==Citations== +*[[wp:4th_Dimension_%28Software%29|Wikipedia:4th Dimension (Software)]] \ No newline at end of file diff --git a/Lang/4D/Comments b/Lang/4D/Comments new file mode 120000 index 0000000000..7434ed42cc --- /dev/null +++ b/Lang/4D/Comments @@ -0,0 +1 @@ +../../Task/Comments/4D \ No newline at end of file diff --git a/Lang/AWK/0DESCRIPTION b/Lang/AWK/0DESCRIPTION new file mode 100644 index 0000000000..fd026d3abd --- /dev/null +++ b/Lang/AWK/0DESCRIPTION @@ -0,0 +1,20 @@ +{{language +|exec=interpreted +|tag=awk +}} +AWK is a small but powerful programming language that can process and convert text files. AWK is part of every [[Unix]]-derived system. + +Each AWK program consists of pattern-action statements. The program reads each input line, checks lines against patterns, and runs matching actions. For programs that never read input lines, the entire program can be one BEGIN { ... } block. + +* ''List users who have /bin/ksh as a shell.''$ awk -F: '$7 == "/bin/ksh" { print $1 }' /etc/passwd + +AWK has only three types of variables: they are strings, floating-point numbers, and associative arrays (where every array index is a string). Conversion between strings and numbers is automatic. AWK also has regular expressions, which appear in many AWK programs. There are a few built-in functions, like cos() and sprintf(). + +* ''Find average line length.''$ awk '{ cnt += length($0) } END { print cnt / NR }' /etc/rc + +The name "AWK" comes from the initials of Alfred Aho, Peter Weinberger and Brian Kernighan: they invented AWK during the 1970s. A few decades later, Kernighan continues to maintain the [[nawk|reference implementation]] of AWK. + +==Links== +*[http://leaf.dragonflybsd.org/cgi/web-man?command=awk§ion=1 awk(1) manual page], short and brief +*[[wp:AWK (programming language)|AWK in Wikipedia]] +*[http://awk.info AWK Community Portal] \ No newline at end of file diff --git a/Lang/AWK/99_Bottles_of_Beer b/Lang/AWK/99_Bottles_of_Beer new file mode 120000 index 0000000000..eb2cbb9b00 --- /dev/null +++ b/Lang/AWK/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/AWK \ No newline at end of file diff --git a/Lang/AWK/Anagrams b/Lang/AWK/Anagrams new file mode 120000 index 0000000000..07c1a16a7d --- /dev/null +++ b/Lang/AWK/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/AWK \ No newline at end of file diff --git a/Lang/AWK/Comments b/Lang/AWK/Comments new file mode 120000 index 0000000000..e07cfa5bd9 --- /dev/null +++ b/Lang/AWK/Comments @@ -0,0 +1 @@ +../../Task/Comments/AWK \ No newline at end of file diff --git a/Lang/AWK/FizzBuzz b/Lang/AWK/FizzBuzz new file mode 120000 index 0000000000..bc077ca36a --- /dev/null +++ b/Lang/AWK/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/AWK \ No newline at end of file diff --git a/Lang/AWK/Infinity b/Lang/AWK/Infinity new file mode 120000 index 0000000000..8368a1208c --- /dev/null +++ b/Lang/AWK/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/AWK \ No newline at end of file diff --git a/Lang/AWK/Knuth_shuffle b/Lang/AWK/Knuth_shuffle new file mode 120000 index 0000000000..12a98143f4 --- /dev/null +++ b/Lang/AWK/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/AWK \ No newline at end of file diff --git a/Lang/AWK/Ordered_words b/Lang/AWK/Ordered_words new file mode 120000 index 0000000000..c12eea123c --- /dev/null +++ b/Lang/AWK/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/AWK \ No newline at end of file diff --git a/Lang/AWK/Search_a_list b/Lang/AWK/Search_a_list new file mode 120000 index 0000000000..129810dee8 --- /dev/null +++ b/Lang/AWK/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/AWK \ No newline at end of file diff --git a/Lang/BASIC/0DESCRIPTION b/Lang/BASIC/0DESCRIPTION new file mode 100644 index 0000000000..d275a4d959 --- /dev/null +++ b/Lang/BASIC/0DESCRIPTION @@ -0,0 +1,15 @@ +{{language +|tags=qbasic, freebasic, thinbasic +|hopl id=176 +|LCT=yes +}} +'''BASIC''' is the ''Beginner's All-purpose Symbolic Instruction Code''. John G. Kemeny and Thomas E. Kurtz invented BASIC at Dartmouth College during 1963 and 1964. (Their implementation evolved into [[True BASIC]].) + +BASIC became popular, with many different implementations for various computers. As the decades passed, the many dialects of BASIC diverged from the original language. Though an ANSI standard exists for BASIC, it is irrelevant to most BASIC programmers, who only target one implementation of BASIC. + +[[:Category:BASIC Implementations]] lists the many implementations of BASIC in Rosetta Code. + +==Links== +*[[wp:BASIC|Wikipedia:BASIC]] + +{{language programming paradigm|Procedural}} \ No newline at end of file diff --git a/Lang/BASIC/99_Bottles_of_Beer b/Lang/BASIC/99_Bottles_of_Beer new file mode 120000 index 0000000000..06ed979469 --- /dev/null +++ b/Lang/BASIC/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/BASIC \ No newline at end of file diff --git a/Lang/BASIC/Bulls_and_cows b/Lang/BASIC/Bulls_and_cows new file mode 120000 index 0000000000..02a049c550 --- /dev/null +++ b/Lang/BASIC/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/BASIC \ No newline at end of file diff --git a/Lang/BASIC/FizzBuzz b/Lang/BASIC/FizzBuzz new file mode 120000 index 0000000000..306c9d57c0 --- /dev/null +++ b/Lang/BASIC/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/BASIC \ No newline at end of file diff --git a/Lang/BASIC/Knuth_shuffle b/Lang/BASIC/Knuth_shuffle new file mode 120000 index 0000000000..555d4a885b --- /dev/null +++ b/Lang/BASIC/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/BASIC \ No newline at end of file diff --git a/Lang/BASIC/Quine b/Lang/BASIC/Quine new file mode 120000 index 0000000000..a4454b37ec --- /dev/null +++ b/Lang/BASIC/Quine @@ -0,0 +1 @@ +../../Task/Quine/BASIC \ No newline at end of file diff --git a/Lang/BASIC/Search_a_list b/Lang/BASIC/Search_a_list new file mode 120000 index 0000000000..9f13c6b758 --- /dev/null +++ b/Lang/BASIC/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/BASIC \ No newline at end of file diff --git a/Lang/Befunge/0DESCRIPTION b/Lang/Befunge/0DESCRIPTION new file mode 100644 index 0000000000..3a3f1ea033 --- /dev/null +++ b/Lang/Befunge/0DESCRIPTION @@ -0,0 +1,13 @@ +{{language|Befunge}} +'''Befunge''' is an esoteric programming language invented by Chris Pressey in 1993. It is unusual for having a two-dimensional toroidal code space. Commands are single characters. The instruction pointer can move up, down, left, and right across the source. The original specification is known as Befunge-93, which was later updated with additional features as Befunge-98. + +Befunge was the first of a family of languages referred to as "Funges". In addition to the "normal" 2-dimensional layout, there is a 1-dimension variant called '''Unefunge''', a 3-dimensional variant called '''Trefunge''', and an ''N''-dimensional variant called '''Nefunge'''. + +==See also== +* [[wp:Esoteric programming language#Funges|Funges on Wikipedia]] +* [[eso:Befunge|Befunge on Esolangs]] +* [http://catseye.tc/projects/befunge93/doc/befunge93.html Befunge-93 Documentation] (broken in some browsers) +** [http://web.archive.org/web/20080625030023/http://catseye.tc/projects/befunge93/doc/befunge93.html Web Archive copy of the above] +* [http://quadium.net/funge/spec98.html Funge-98 Final Specification] + +[[Category:Esoteric Languages]] \ No newline at end of file diff --git a/Lang/Befunge/99_Bottles_of_Beer b/Lang/Befunge/99_Bottles_of_Beer new file mode 120000 index 0000000000..78b8d11d05 --- /dev/null +++ b/Lang/Befunge/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/Befunge \ No newline at end of file diff --git a/Lang/Befunge/Comments b/Lang/Befunge/Comments new file mode 120000 index 0000000000..263e6ecfb8 --- /dev/null +++ b/Lang/Befunge/Comments @@ -0,0 +1 @@ +../../Task/Comments/Befunge \ No newline at end of file diff --git a/Lang/Befunge/FizzBuzz b/Lang/Befunge/FizzBuzz new file mode 120000 index 0000000000..766937e42e --- /dev/null +++ b/Lang/Befunge/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Befunge \ No newline at end of file diff --git a/Lang/Befunge/Quine b/Lang/Befunge/Quine new file mode 120000 index 0000000000..04426d26e3 --- /dev/null +++ b/Lang/Befunge/Quine @@ -0,0 +1 @@ +../../Task/Quine/Befunge \ No newline at end of file diff --git a/Lang/C/0DESCRIPTION b/Lang/C/0DESCRIPTION new file mode 100644 index 0000000000..ccc5e68a4b --- /dev/null +++ b/Lang/C/0DESCRIPTION @@ -0,0 +1,30 @@ +
Due to technical limitations, the link [[C sharp|C#]] points to here in some articles. To correct this issue, replace [[C#]] with [[C sharp|C#]].
+{{language +|exec=machine +|gc=no +|safety=unsafe +|parampass=value +|checking=static +|compat=nominative +|express=explicit +|strength=weak +|tags=c +|hopl id=577 +|LCT=yes +|bnf=http://c.comsci.us/syntax/index.html +}}{{language programming paradigm|Imperative}}{{Codepad}} +'''C''' is a general-purpose, [[procedural programming|procedural]], [[imperative programming|imperative]] computer programming language developed in 1972 by Dennis Ritchie at the [[Bell Labs|Bell Telephone Laboratories]] for use with the [[UNIX]] operating system. C evolved from its predecessor, [[derived from::B]]. + +C has since spread to many other [[:Category:Platforms|platforms]], and is now one of the most widely used programming languages. C has also greatly influenced many other popular languages, such as [[C++]] and [[Objective-C]], which were originally designed as enhancements to C. People are so familiar with its syntax that many other languages such as [[AWK]], [[PHP]], [[Java]], [[JavaScript]], [[D]], and [[C Sharp|C#]] deliberately used its "look and feel". C is the most commonly used programming language for writing system software, though it is also widely used for writing applications. [[C]] is the ''lingua franca'' of the [[open source]] community. + +==Versions== +* '''K&R C''' was the first widely-used form of C. It was originally documented in ''The C Programming Language'', published in 1978. It is named for the authors, Brian Kernighan and Dennis Ritchie (also the language's creator). Code in this style is virtually nonexistent today. +* '''C89''' (often called '''[[ANSI]] C''') is the version of C standardized by ANSI in 1989. It is the most commonly used and supported version of the language. The term "C" usually refers to C89 or C90. +* '''C90''' (often called '''[[ISO]] C''') is a minor improvement to C89, standardized by ISO in 1990. Most C compilers support it by default. +* '''C99''' is a significant improvement, adopting many features of [[C++]] and standardizing common compiler extensions. It was standardized by ISO in 1999, and by ANSI in 2000. It is not completely supported by many, if any, compilers, but most of its features are available in [[GCC]]. [http://gcc.gnu.org/c99status.html] +* '''C11''' is the current standard, published in December 2011. Some of its features are available in GCC. [http://gcc.gnu.org/gcc-4.6/changes.html#c] + +==Citation== +*[[wp:C_%28programming_language%29|Wikipedia:C (programming language)]] + +{{language programming paradigm|Imperative}} \ No newline at end of file diff --git a/Lang/C/99_Bottles_of_Beer b/Lang/C/99_Bottles_of_Beer new file mode 120000 index 0000000000..13c7cf22e7 --- /dev/null +++ b/Lang/C/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/C \ No newline at end of file diff --git a/Lang/C/Anagrams b/Lang/C/Anagrams new file mode 120000 index 0000000000..982b8bd7e8 --- /dev/null +++ b/Lang/C/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/C \ No newline at end of file diff --git a/Lang/C/Bulls_and_cows b/Lang/C/Bulls_and_cows new file mode 120000 index 0000000000..dd1eef7747 --- /dev/null +++ b/Lang/C/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/C \ No newline at end of file diff --git a/Lang/C/Comments b/Lang/C/Comments new file mode 120000 index 0000000000..762786b862 --- /dev/null +++ b/Lang/C/Comments @@ -0,0 +1 @@ +../../Task/Comments/C \ No newline at end of file diff --git a/Lang/C/Death_Star b/Lang/C/Death_Star new file mode 120000 index 0000000000..b0ae329f85 --- /dev/null +++ b/Lang/C/Death_Star @@ -0,0 +1 @@ +../../Task/Death_Star/C \ No newline at end of file diff --git a/Lang/C/FizzBuzz b/Lang/C/FizzBuzz new file mode 120000 index 0000000000..2a3a1a2663 --- /dev/null +++ b/Lang/C/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/C \ No newline at end of file diff --git a/Lang/C/Infinity b/Lang/C/Infinity new file mode 120000 index 0000000000..616ef92f04 --- /dev/null +++ b/Lang/C/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/C \ No newline at end of file diff --git a/Lang/C/JSON b/Lang/C/JSON new file mode 120000 index 0000000000..df1bf4999b --- /dev/null +++ b/Lang/C/JSON @@ -0,0 +1 @@ +../../Task/JSON/C \ No newline at end of file diff --git a/Lang/C/Knuth_shuffle b/Lang/C/Knuth_shuffle new file mode 120000 index 0000000000..ee085e5411 --- /dev/null +++ b/Lang/C/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/C \ No newline at end of file diff --git a/Lang/C/Narcissist b/Lang/C/Narcissist new file mode 120000 index 0000000000..6f2ea4523a --- /dev/null +++ b/Lang/C/Narcissist @@ -0,0 +1 @@ +../../Task/Narcissist/C \ No newline at end of file diff --git a/Lang/C/Ordered_words b/Lang/C/Ordered_words new file mode 120000 index 0000000000..8a7f5ee991 --- /dev/null +++ b/Lang/C/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/C \ No newline at end of file diff --git a/Lang/C/Pi b/Lang/C/Pi new file mode 120000 index 0000000000..824d45f489 --- /dev/null +++ b/Lang/C/Pi @@ -0,0 +1 @@ +../../Task/Pi/C \ No newline at end of file diff --git a/Lang/C/Quine b/Lang/C/Quine new file mode 120000 index 0000000000..25016c2fa6 --- /dev/null +++ b/Lang/C/Quine @@ -0,0 +1 @@ +../../Task/Quine/C \ No newline at end of file diff --git a/Lang/C/Search_a_list b/Lang/C/Search_a_list new file mode 120000 index 0000000000..06f12fc0d6 --- /dev/null +++ b/Lang/C/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/C \ No newline at end of file diff --git a/Lang/Clojure/0DESCRIPTION b/Lang/Clojure/0DESCRIPTION new file mode 100644 index 0000000000..58007a8a2b --- /dev/null +++ b/Lang/Clojure/0DESCRIPTION @@ -0,0 +1,18 @@ +{{language|Clojure +|site=http://clojure.org/ +|exec=bytecode +|gc=yes +|safety=safe +|checking=both +|strength=strong +|LCT=yes}} +{{language programming paradigm|functional}} +{{language programming paradigm|concurrent}} +{{implementation|Lisp}} +Clojure is a dynamic programming language that targets the [[runs on vm::Java Virtual Machine]]. It is designed to be a general-purpose language, combining the approachability and interactive development of a scripting language with an efficient and robust infrastructure for multithreaded programming. Clojure is a compiled language - it compiles directly to JVM [[bytecode]], yet remains completely dynamic. Every feature supported by Clojure is supported at runtime. Clojure provides easy access to the [[Java]] frameworks, with optional type hints and type inference, to ensure that calls to Java can avoid reflection. + +Clojure is a dialect of [[Lisp]], and shares with Lisp the code-as-data philosophy and a powerful macro system. Clojure is predominantly a functional programming language, and features a rich set of immutable, persistent data structures. When mutable state is needed, Clojure offers a software transactional memory system and reactive Agent system that ensure clean, correct, multithreaded designs. + +==See Also== + +* [http://richhickey.github.com/clojure-contrib/ clojure-contrib] -- Clojure's contrib library \ No newline at end of file diff --git a/Lang/Clojure/99_Bottles_of_Beer b/Lang/Clojure/99_Bottles_of_Beer new file mode 120000 index 0000000000..bb0fafd6b0 --- /dev/null +++ b/Lang/Clojure/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/Clojure \ No newline at end of file diff --git a/Lang/Clojure/Anagrams b/Lang/Clojure/Anagrams new file mode 120000 index 0000000000..da754fcd8e --- /dev/null +++ b/Lang/Clojure/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/Clojure \ No newline at end of file diff --git a/Lang/Clojure/Bulls_and_cows b/Lang/Clojure/Bulls_and_cows new file mode 120000 index 0000000000..ccfc63e934 --- /dev/null +++ b/Lang/Clojure/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/Clojure \ No newline at end of file diff --git a/Lang/Clojure/Comments b/Lang/Clojure/Comments new file mode 120000 index 0000000000..8e8a769b03 --- /dev/null +++ b/Lang/Clojure/Comments @@ -0,0 +1 @@ +../../Task/Comments/Clojure \ No newline at end of file diff --git a/Lang/Clojure/FizzBuzz b/Lang/Clojure/FizzBuzz new file mode 120000 index 0000000000..c9b9c78816 --- /dev/null +++ b/Lang/Clojure/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Clojure \ No newline at end of file diff --git a/Lang/Clojure/JSON b/Lang/Clojure/JSON new file mode 120000 index 0000000000..e969ebeba1 --- /dev/null +++ b/Lang/Clojure/JSON @@ -0,0 +1 @@ +../../Task/JSON/Clojure \ No newline at end of file diff --git a/Lang/Clojure/Knuth_shuffle b/Lang/Clojure/Knuth_shuffle new file mode 120000 index 0000000000..276f50bbfb --- /dev/null +++ b/Lang/Clojure/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/Clojure \ No newline at end of file diff --git a/Lang/Clojure/Quine b/Lang/Clojure/Quine new file mode 120000 index 0000000000..9b5a99ea0f --- /dev/null +++ b/Lang/Clojure/Quine @@ -0,0 +1 @@ +../../Task/Quine/Clojure \ No newline at end of file diff --git a/Lang/Clojure/Search_a_list b/Lang/Clojure/Search_a_list new file mode 120000 index 0000000000..235dd3611f --- /dev/null +++ b/Lang/Clojure/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/Clojure \ No newline at end of file diff --git a/Lang/CoffeeScript/0DESCRIPTION b/Lang/CoffeeScript/0DESCRIPTION new file mode 100644 index 0000000000..089c6fa792 --- /dev/null +++ b/Lang/CoffeeScript/0DESCRIPTION @@ -0,0 +1,56 @@ +{{language}}{{wikipedia|CoffeeScript}}'''CoffeeScript''' is a programming language that compiles to [[:Category:JavaScript|JavaScript]]. The language adds syntactic sugar inspired by [[:Category:Ruby|Ruby]] and [[:Category:Python|Python]] to enhance JavaScript's brevity and readability, as well as adding more sophisticated features like array comprehension and pattern matching. + +With 4000+ watchers and 300+ forks (as of December 2011), CoffeeScript is ranked as one of the "most interesting" projects on Github. [http://github.com/repositories] The language has a relatively large following in the Ruby community, and has been used in production by [http://thinkvitamin.com/mobile/new-rails-like-framework-from-37signals-for-html5-mobile-apps/ 37signals]. Ruby on Rails began to include CoffeeScript in its asset pipeline in Rails version 3.1 (see [http://www.rubyinside.com/rails-3-1-adopts-coffeescript-jquery-sass-and-controversy-4669.html]). + +== History == +On December 13, 2009, Jeremy Ashkenas made the first git commit of CoffeeScript with the comment: "Initial commit of the mystery language." The compiler was written in Ruby. On December 24th, he made the first tagged and documented release, 0.1.0. On February 21, 2010, he committed version 0.5, which replaced the Ruby compiler with one written in pure CoffeeScript. By that time the project had attracted several other contributors on Github, and was receiving over 300 page hits per day. + +On December 24, 2010, Ashkenas announced the release of stable 1.0.0. + +== Examples == + +A common JavaScript snippet using the jQuery library is + + +$(document).ready(function() { + // Initialization code goes here +}); + +or even shorter, + +$(function() { + // Initialization code goes here +}); + + +In CoffeeScript, the function keyword is replaced by the -> symbol, and indentation is used instead of curly braces (except when defining an [[associative array]]), as in Python. Also, parentheses can usually be omitted. Thus, the CoffeeScript equivalent of the snippet above is + + + +$(document).ready -> + # Initialization code goes here + +or + +$ -> + # Initialization code goes here + + +== Compiling == + +The CoffeeScript compiler has been written in CoffeeScript since version 0.5, and can be run either in the browser or through Node.js. The official site at CoffeeScript.org has a "Try CoffeeScript" button in the menu bar; clicking it opens a modal window in which you can enter CoffeeScript, see the JavaScript output, and run it directly in the browser. + +== Citations == + +# Github. "[http://github.com/repositories Interesting Repositories]", Github, Nov 10, 2010. +# Carson, Ryan. "[http://thinkvitamin.com/mobile/new-rails-like-framework-from-37signals-for-html5-mobile-apps/ New Rails-like Framework from 37signals for HTML5 Mobile Apps]", Think Vitamin blog, Nov 8, 2010. +# Hagenburger, Nico. "[http://www.hagenburger.net/TALKS/rails-3.1-frontend-performance.html Rails 3.1 – A Sneak Preview]", presentation for [http://railscamp-hamburg.de/ Railscamp Hamburg] on Oct 23, 2010. +# Ashkenas, Jeremy. "[http://github.com/jashkenas/coffee-script/issues/830 The Plan for 1.0]", Github issue tracker, Nov 4, 2010. + +== External links == +* [http://coffeescript.org CoffeeScript.org] - Official site] +* [http://github.com/jashkenas/coffee-script/ GitHub repository] +* [http://twitter.com/coffeescript @CoffeeScript] - Twitter feed +* [[wp:coffeescript|Wikipedia Entry]] + +[[Category:JavaScript programming language family]] \ No newline at end of file diff --git a/Lang/CoffeeScript/99_Bottles_of_Beer b/Lang/CoffeeScript/99_Bottles_of_Beer new file mode 120000 index 0000000000..7bbd784bfc --- /dev/null +++ b/Lang/CoffeeScript/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/CoffeeScript \ No newline at end of file diff --git a/Lang/CoffeeScript/Anagrams b/Lang/CoffeeScript/Anagrams new file mode 120000 index 0000000000..35126df126 --- /dev/null +++ b/Lang/CoffeeScript/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/CoffeeScript \ No newline at end of file diff --git a/Lang/CoffeeScript/Comments b/Lang/CoffeeScript/Comments new file mode 120000 index 0000000000..0f23ca231d --- /dev/null +++ b/Lang/CoffeeScript/Comments @@ -0,0 +1 @@ +../../Task/Comments/CoffeeScript \ No newline at end of file diff --git a/Lang/CoffeeScript/FizzBuzz b/Lang/CoffeeScript/FizzBuzz new file mode 120000 index 0000000000..d6b622792c --- /dev/null +++ b/Lang/CoffeeScript/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/CoffeeScript \ No newline at end of file diff --git a/Lang/CoffeeScript/Infinity b/Lang/CoffeeScript/Infinity new file mode 120000 index 0000000000..eab895b523 --- /dev/null +++ b/Lang/CoffeeScript/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/CoffeeScript \ No newline at end of file diff --git a/Lang/CoffeeScript/JSON b/Lang/CoffeeScript/JSON new file mode 120000 index 0000000000..031b1f524b --- /dev/null +++ b/Lang/CoffeeScript/JSON @@ -0,0 +1 @@ +../../Task/JSON/CoffeeScript \ No newline at end of file diff --git a/Lang/CoffeeScript/Knuth_shuffle b/Lang/CoffeeScript/Knuth_shuffle new file mode 120000 index 0000000000..02240661bc --- /dev/null +++ b/Lang/CoffeeScript/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/CoffeeScript \ No newline at end of file diff --git a/Lang/CoffeeScript/Ordered_words b/Lang/CoffeeScript/Ordered_words new file mode 120000 index 0000000000..dbbe3b998e --- /dev/null +++ b/Lang/CoffeeScript/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/CoffeeScript \ No newline at end of file diff --git a/Lang/CoffeeScript/Quine b/Lang/CoffeeScript/Quine new file mode 120000 index 0000000000..1d99f517be --- /dev/null +++ b/Lang/CoffeeScript/Quine @@ -0,0 +1 @@ +../../Task/Quine/CoffeeScript \ No newline at end of file diff --git a/Lang/Erlang/0DESCRIPTION b/Lang/Erlang/0DESCRIPTION new file mode 100644 index 0000000000..037fd71f00 --- /dev/null +++ b/Lang/Erlang/0DESCRIPTION @@ -0,0 +1,15 @@ +{{language|Erlang +|exec=bytecode +|strength=strong +|safety=safe +|express=implicit +|checking=dynamic +|gc=yes +|LCT=yes}} +{{language programming paradigm|functional}} +{{language programming paradigm|concurrent}} +{{language programming paradigm|distributed}} +{{language programming paradigm|declarative}} +{{language programming paradigm|imperative}} + +Erlang is a programming language which has many features more commonly associated with an [[OS|operating system]] than with a programming language: concurrent [[process|processes]], scheduling, [[garbage collection|memory management]], distribution, networking, etc. \ No newline at end of file diff --git a/Lang/Erlang/99_Bottles_of_Beer b/Lang/Erlang/99_Bottles_of_Beer new file mode 120000 index 0000000000..e317659dfb --- /dev/null +++ b/Lang/Erlang/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/Erlang \ No newline at end of file diff --git a/Lang/Erlang/Anagrams b/Lang/Erlang/Anagrams new file mode 120000 index 0000000000..3f4474a1cd --- /dev/null +++ b/Lang/Erlang/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/Erlang \ No newline at end of file diff --git a/Lang/Erlang/Bulls_and_cows b/Lang/Erlang/Bulls_and_cows new file mode 120000 index 0000000000..7b7132db3e --- /dev/null +++ b/Lang/Erlang/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/Erlang \ No newline at end of file diff --git a/Lang/Erlang/Comments b/Lang/Erlang/Comments new file mode 120000 index 0000000000..79b34235d4 --- /dev/null +++ b/Lang/Erlang/Comments @@ -0,0 +1 @@ +../../Task/Comments/Erlang \ No newline at end of file diff --git a/Lang/Erlang/FizzBuzz b/Lang/Erlang/FizzBuzz new file mode 120000 index 0000000000..ec6eae4081 --- /dev/null +++ b/Lang/Erlang/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Erlang \ No newline at end of file diff --git a/Lang/Erlang/Quine b/Lang/Erlang/Quine new file mode 120000 index 0000000000..00a3371beb --- /dev/null +++ b/Lang/Erlang/Quine @@ -0,0 +1 @@ +../../Task/Quine/Erlang \ No newline at end of file diff --git a/Lang/Erlang/Search_a_list b/Lang/Erlang/Search_a_list new file mode 120000 index 0000000000..adaf29da84 --- /dev/null +++ b/Lang/Erlang/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/Erlang \ No newline at end of file diff --git a/Lang/Forth/0DESCRIPTION b/Lang/Forth/0DESCRIPTION new file mode 100644 index 0000000000..5411b5384c --- /dev/null +++ b/Lang/Forth/0DESCRIPTION @@ -0,0 +1,13 @@ +{{language|Forth +|gc=no +|untyped=yes +|LCT=yes}} +{{language programming paradigm|concatenative}} +{{language programming paradigm|imperative}} +'''Forth''', a [[procedural programming|procedural]], [[stack]]-oriented and [[reflective programming]] language without type checking, Forth features both interactive execution of commands (making it suitable as a shell for systems that lack a more formal [[:Category:Operating_Systems|operating system]]) and the ability to compile sequences of commands for later execution. Some Forth versions (especially early ones) compile threaded code, but many implementations today generate optimized machine code like other language compilers. + +Where not otherwise specified, examples conform to the 1994 [[ANSI]] Standard, also known as '''ANS Forth'''. Most Forth implementations now conform to this standard, often with system-specific extensions and convenience libraries. Some examples use words that are not in the standard, but which have become accepted as [[Forth common practice|common practice]] since 1994. Standard words should be uppercase, but most Forth systems are case-insensitive. + +==Citations== +* [[wp:Forth_%28programming_language%29|Wikipedia:Forth (programming language)]] +* [http://www.forthfreak.net/dpans/dpansf.htm Index to the ANS Forth words] \ No newline at end of file diff --git a/Lang/Forth/99_Bottles_of_Beer b/Lang/Forth/99_Bottles_of_Beer new file mode 120000 index 0000000000..9f9257e484 --- /dev/null +++ b/Lang/Forth/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/Forth \ No newline at end of file diff --git a/Lang/Forth/Bulls_and_cows b/Lang/Forth/Bulls_and_cows new file mode 120000 index 0000000000..2c3ba1633b --- /dev/null +++ b/Lang/Forth/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/Forth \ No newline at end of file diff --git a/Lang/Forth/Comments b/Lang/Forth/Comments new file mode 120000 index 0000000000..6fd4b95b6a --- /dev/null +++ b/Lang/Forth/Comments @@ -0,0 +1 @@ +../../Task/Comments/Forth \ No newline at end of file diff --git a/Lang/Forth/FizzBuzz b/Lang/Forth/FizzBuzz new file mode 120000 index 0000000000..628c27bca4 --- /dev/null +++ b/Lang/Forth/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Forth \ No newline at end of file diff --git a/Lang/Forth/Infinity b/Lang/Forth/Infinity new file mode 120000 index 0000000000..0cb51a53d7 --- /dev/null +++ b/Lang/Forth/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/Forth \ No newline at end of file diff --git a/Lang/Forth/Knuth_shuffle b/Lang/Forth/Knuth_shuffle new file mode 120000 index 0000000000..6d9f45d930 --- /dev/null +++ b/Lang/Forth/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/Forth \ No newline at end of file diff --git a/Lang/Forth/Narcissist b/Lang/Forth/Narcissist new file mode 120000 index 0000000000..9ac7c3fb38 --- /dev/null +++ b/Lang/Forth/Narcissist @@ -0,0 +1 @@ +../../Task/Narcissist/Forth \ No newline at end of file diff --git a/Lang/Forth/Ordered_words b/Lang/Forth/Ordered_words new file mode 120000 index 0000000000..e311ae53f1 --- /dev/null +++ b/Lang/Forth/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/Forth \ No newline at end of file diff --git a/Lang/Forth/Quine b/Lang/Forth/Quine new file mode 120000 index 0000000000..3fd5333888 --- /dev/null +++ b/Lang/Forth/Quine @@ -0,0 +1 @@ +../../Task/Quine/Forth \ No newline at end of file diff --git a/Lang/Forth/Search_a_list b/Lang/Forth/Search_a_list new file mode 120000 index 0000000000..e82926230b --- /dev/null +++ b/Lang/Forth/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/Forth \ No newline at end of file diff --git a/Lang/Fortran/0DESCRIPTION b/Lang/Fortran/0DESCRIPTION new file mode 100644 index 0000000000..31b9973756 --- /dev/null +++ b/Lang/Fortran/0DESCRIPTION @@ -0,0 +1,15 @@ +{{language|Fortran +|strength=strong +|safety=safe +|compat=nominative +|checking=static +|gc=no +|LCT=yes +|bnf=http://fortran.comsci.us/syntax/statement/index.html}}{{language programming paradigm|Imperative}} +Fortran is the oldest programming language still in widespread use. It was given substantial rework in the Fortran 90 standard. By convention, versions before Fortran 90 are spelled with all uppercase letters (e.g. FORTRAN 66, FORTRAN 77), while starting with Fortran 90, the mixed case spelling is used (i.e. Fortran 90, Fortran 95 etc.). + +FORTRAN 77, being quite old, lacks almost everything one expects from a modern programming language. It uses a fixed-length line and column oriented line format which was motivated by punch cards. Due to its age, and since FORTRAN compilers generally gave very good performance for numerical code, a lot of code, especially scientific code, was written in FORTRAN. Also, for quite a while there was no free Fortran 90 compiler, which also caused a lot of FORTRAN 77 code to be written even quite some time after Fortran 90 was standardized. Because of the big body of code written in FORTRAN 77 it's still relevant. Indeed, every Fortran compiler still has to accept the old format. + +Fortran 90 was a major step in the development of Fortran. It introduced a new free-form source code format, modern programming language features like modules, pointers and user-defined types, an improved type system for built-in types and superiour built-in array handling. + +Newer Fortran standards (Fortran 2003 and 2008) added further modern features, like support for object oriented programming, inheritance, and polymorphism. \ No newline at end of file diff --git a/Lang/Fortran/99_Bottles_of_Beer b/Lang/Fortran/99_Bottles_of_Beer new file mode 120000 index 0000000000..273e2aeff1 --- /dev/null +++ b/Lang/Fortran/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/Fortran \ No newline at end of file diff --git a/Lang/Fortran/Bulls_and_cows b/Lang/Fortran/Bulls_and_cows new file mode 120000 index 0000000000..ace0e874eb --- /dev/null +++ b/Lang/Fortran/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/Fortran \ No newline at end of file diff --git a/Lang/Fortran/Comments b/Lang/Fortran/Comments new file mode 120000 index 0000000000..a924f70887 --- /dev/null +++ b/Lang/Fortran/Comments @@ -0,0 +1 @@ +../../Task/Comments/Fortran \ No newline at end of file diff --git a/Lang/Fortran/FizzBuzz b/Lang/Fortran/FizzBuzz new file mode 120000 index 0000000000..1755220b1c --- /dev/null +++ b/Lang/Fortran/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Fortran \ No newline at end of file diff --git a/Lang/Fortran/Infinity b/Lang/Fortran/Infinity new file mode 120000 index 0000000000..2138d646c8 --- /dev/null +++ b/Lang/Fortran/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/Fortran \ No newline at end of file diff --git a/Lang/Fortran/Knuth_shuffle b/Lang/Fortran/Knuth_shuffle new file mode 120000 index 0000000000..4ed00296c4 --- /dev/null +++ b/Lang/Fortran/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/Fortran \ No newline at end of file diff --git a/Lang/Fortran/Ordered_words b/Lang/Fortran/Ordered_words new file mode 120000 index 0000000000..43f41176d9 --- /dev/null +++ b/Lang/Fortran/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/Fortran \ No newline at end of file diff --git a/Lang/Fortran/Quine b/Lang/Fortran/Quine new file mode 120000 index 0000000000..ac1b91b5a3 --- /dev/null +++ b/Lang/Fortran/Quine @@ -0,0 +1 @@ +../../Task/Quine/Fortran \ No newline at end of file diff --git a/Lang/Fortran/Search_a_list b/Lang/Fortran/Search_a_list new file mode 120000 index 0000000000..8262771e2f --- /dev/null +++ b/Lang/Fortran/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/Fortran \ No newline at end of file diff --git a/Lang/Go/0DESCRIPTION b/Lang/Go/0DESCRIPTION new file mode 100644 index 0000000000..2ab6130ff6 --- /dev/null +++ b/Lang/Go/0DESCRIPTION @@ -0,0 +1,26 @@ +{{language|Go +|exec=machine +|safety=safe +|strength=strong +|express=explicit +|checking=static +|parampass=value +|gc=yes +|LCT=yes +|site=http://golang.org/}} +{{language programming paradigm|concurrent}} +'''Go''' is a new programing language created by Robert Griesemer, Rob Pike and Ken Thompson at Google. + +Not to be confused with [[:Category:Go!|Go!]] + +==Links== +* [http://go-lang.cat-v.org/ Go Language Resources] +* [http://tour.golang.org/ Go Tutorial] + +;Stable version +* [http://golang.org/doc/go1.html Go 1 Release Notes] +* [http://golang.org/ref/spec Go language specification] +* [http://golang.org/pkg/ Go standard library documentation] +;Weekly version +* [http://weekly.golang.org/ref/spec Go language specification] +* [http://weekly.golang.org/pkg/ Go standard library documentation] \ No newline at end of file diff --git a/Lang/Go/99_Bottles_of_Beer b/Lang/Go/99_Bottles_of_Beer new file mode 120000 index 0000000000..96e89dc618 --- /dev/null +++ b/Lang/Go/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/Go \ No newline at end of file diff --git a/Lang/Go/Anagrams b/Lang/Go/Anagrams new file mode 120000 index 0000000000..bcff1b7ee6 --- /dev/null +++ b/Lang/Go/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/Go \ No newline at end of file diff --git a/Lang/Go/Bulls_and_cows b/Lang/Go/Bulls_and_cows new file mode 120000 index 0000000000..086259cf3a --- /dev/null +++ b/Lang/Go/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/Go \ No newline at end of file diff --git a/Lang/Go/Comments b/Lang/Go/Comments new file mode 120000 index 0000000000..c81e2baac1 --- /dev/null +++ b/Lang/Go/Comments @@ -0,0 +1 @@ +../../Task/Comments/Go \ No newline at end of file diff --git a/Lang/Go/Death_Star b/Lang/Go/Death_Star new file mode 120000 index 0000000000..c61938d884 --- /dev/null +++ b/Lang/Go/Death_Star @@ -0,0 +1 @@ +../../Task/Death_Star/Go \ No newline at end of file diff --git a/Lang/Go/FizzBuzz b/Lang/Go/FizzBuzz new file mode 120000 index 0000000000..65e975072e --- /dev/null +++ b/Lang/Go/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Go \ No newline at end of file diff --git a/Lang/Go/Infinity b/Lang/Go/Infinity new file mode 120000 index 0000000000..961b5d8ff2 --- /dev/null +++ b/Lang/Go/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/Go \ No newline at end of file diff --git a/Lang/Go/JSON b/Lang/Go/JSON new file mode 120000 index 0000000000..39d50a184c --- /dev/null +++ b/Lang/Go/JSON @@ -0,0 +1 @@ +../../Task/JSON/Go \ No newline at end of file diff --git a/Lang/Go/Knuth_shuffle b/Lang/Go/Knuth_shuffle new file mode 120000 index 0000000000..1904a72b47 --- /dev/null +++ b/Lang/Go/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/Go \ No newline at end of file diff --git a/Lang/Go/Narcissist b/Lang/Go/Narcissist new file mode 120000 index 0000000000..a1b2dfa4f7 --- /dev/null +++ b/Lang/Go/Narcissist @@ -0,0 +1 @@ +../../Task/Narcissist/Go \ No newline at end of file diff --git a/Lang/Go/Ordered_words b/Lang/Go/Ordered_words new file mode 120000 index 0000000000..019c840432 --- /dev/null +++ b/Lang/Go/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/Go \ No newline at end of file diff --git a/Lang/Go/Pi b/Lang/Go/Pi new file mode 120000 index 0000000000..703a94eede --- /dev/null +++ b/Lang/Go/Pi @@ -0,0 +1 @@ +../../Task/Pi/Go \ No newline at end of file diff --git a/Lang/Go/Quine b/Lang/Go/Quine new file mode 120000 index 0000000000..68cfb3ad8c --- /dev/null +++ b/Lang/Go/Quine @@ -0,0 +1 @@ +../../Task/Quine/Go \ No newline at end of file diff --git a/Lang/Go/Search_a_list b/Lang/Go/Search_a_list new file mode 120000 index 0000000000..666a4ff80b --- /dev/null +++ b/Lang/Go/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/Go \ No newline at end of file diff --git a/Lang/Haskell/0DESCRIPTION b/Lang/Haskell/0DESCRIPTION new file mode 100644 index 0000000000..b4906ce73f --- /dev/null +++ b/Lang/Haskell/0DESCRIPTION @@ -0,0 +1,17 @@ +{{language|Haskell +|strength=strong +|safety=safe +|compat=structural +|checking=static +|gc=yes +|LCT=yes +|site=http://haskell.org +|bnf=http://haskell.org/onlinereport/index.html}}{{codepad}} +{{language programming paradigm|Declarative}} +{{language programming paradigm|functional}} +'''Haskell''' is a standardized purely [[functional programming]] language with non-strict semantics, named after the logician Haskell Curry. It is one of the more popular functional languages, and the [[lazy evaluation|lazy]] functional language on which the most research is being performed. + +Although Haskell has a comparatively small user community, its strengths have been well applied to a few projects. Audrey Tang's Pugs is an implementation for the forthcoming [[Perl 6]] language with an [[interpreter]] and [[compiler|compilers]] that proved useful already after just a few months of its writing. Darcs is a revision control system, with several innovative features. Linspire GNU/[[Linux]] chose Haskell for system tools development. + +==Citations== +* [[wp:Haskell_%28programming_language%29|Wikipedia:Haskell (programming language)]] \ No newline at end of file diff --git a/Lang/Haskell/99_Bottles_of_Beer b/Lang/Haskell/99_Bottles_of_Beer new file mode 120000 index 0000000000..d9e66c1ecb --- /dev/null +++ b/Lang/Haskell/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/Haskell \ No newline at end of file diff --git a/Lang/Haskell/Bulls_and_cows b/Lang/Haskell/Bulls_and_cows new file mode 120000 index 0000000000..0c0407a9c9 --- /dev/null +++ b/Lang/Haskell/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/Haskell \ No newline at end of file diff --git a/Lang/Haskell/Comments b/Lang/Haskell/Comments new file mode 120000 index 0000000000..f06b664a37 --- /dev/null +++ b/Lang/Haskell/Comments @@ -0,0 +1 @@ +../../Task/Comments/Haskell \ No newline at end of file diff --git a/Lang/Haskell/Entropy b/Lang/Haskell/Entropy new file mode 120000 index 0000000000..0b3476b0aa --- /dev/null +++ b/Lang/Haskell/Entropy @@ -0,0 +1 @@ +../../Task/Entropy/Haskell \ No newline at end of file diff --git a/Lang/Haskell/FizzBuzz b/Lang/Haskell/FizzBuzz new file mode 120000 index 0000000000..696c16de2b --- /dev/null +++ b/Lang/Haskell/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Haskell \ No newline at end of file diff --git a/Lang/Haskell/Infinity b/Lang/Haskell/Infinity new file mode 120000 index 0000000000..a4c0ca2430 --- /dev/null +++ b/Lang/Haskell/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/Haskell \ No newline at end of file diff --git a/Lang/Haskell/JSON b/Lang/Haskell/JSON new file mode 120000 index 0000000000..a2df6528d6 --- /dev/null +++ b/Lang/Haskell/JSON @@ -0,0 +1 @@ +../../Task/JSON/Haskell \ No newline at end of file diff --git a/Lang/Haskell/Knuth_shuffle b/Lang/Haskell/Knuth_shuffle new file mode 120000 index 0000000000..ae72ab4715 --- /dev/null +++ b/Lang/Haskell/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/Haskell \ No newline at end of file diff --git a/Lang/Haskell/Ordered_words b/Lang/Haskell/Ordered_words new file mode 120000 index 0000000000..6f9d552a3c --- /dev/null +++ b/Lang/Haskell/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/Haskell \ No newline at end of file diff --git a/Lang/Haskell/Pi b/Lang/Haskell/Pi new file mode 120000 index 0000000000..9fce1a3f23 --- /dev/null +++ b/Lang/Haskell/Pi @@ -0,0 +1 @@ +../../Task/Pi/Haskell \ No newline at end of file diff --git a/Lang/Haskell/Quine b/Lang/Haskell/Quine new file mode 120000 index 0000000000..ba9b18b313 --- /dev/null +++ b/Lang/Haskell/Quine @@ -0,0 +1 @@ +../../Task/Quine/Haskell \ No newline at end of file diff --git a/Lang/Haskell/Search_a_list b/Lang/Haskell/Search_a_list new file mode 120000 index 0000000000..ba2ec18bd1 --- /dev/null +++ b/Lang/Haskell/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/Haskell \ No newline at end of file diff --git a/Lang/Java/0DESCRIPTION b/Lang/Java/0DESCRIPTION new file mode 100644 index 0000000000..e04c0dcdf7 --- /dev/null +++ b/Lang/Java/0DESCRIPTION @@ -0,0 +1,39 @@ +{{language +|exec=bytecode +|site=http://www.oracle.com/technetwork/java/ +|gc=yes +|parampass=value +|safety=safe +|express=explicit +|compat=nominative +|checking=static +|strength=strong +|tags=java, java5 +|hopl id=2131 +|LCT=yes +|bnf=http://www.cui.unige.ch/db-research/Enseignement/analyseinfo/JAVA/BNFindex.html}} +{{language programming paradigm|Object-oriented}} +{{language programming paradigm|Imperative}} +{{language programming paradigm|generic}} +{{language programming paradigm|reflective}}[[runs on vm::java virtual machine| ]] +The '''Java''' programming language, developed by [[Sun Microsystems]], is a language aimed at allowing "high-performance", virtual application development. + +Java source files (.java files) are typically [[Compiler|compiled]] to an intermediate [[bytecode]] language (.class files) and executed by a [[Java Virtual Machine]]. Most modern JVMs further compile the bytecode into your processor's native machine code during execution. This native code translation is done via a [[Just-In-Time|JIT]] compiler that is built in to the JVM. Some Java compilers (such as [[GCJ]]) can compile Java code to native machine code ahead-of-time rather than just-in-time. + +The primary benefits of Java are: +* Cross-[[platform]] (Write Once, Run Anywhere (if all of the libraries are ported)) +* Comprehensive class library (which is thoroughly [http://www.oracle.com/technetwork/java/javase/documentation/index.html documented]) +* [[garbage collection|Automatic memory management]] +* Large user community +* Well supported by the [[open source]] community and commercial industry ([[Sun Microsystems|Sun]], [[IBM]], [[Oracle]], HP, BEA, [[Apple Inc]], etc.) + +Java is used in a variety of environments including desktop applications, embedded device (PDA and wireless phone) applications, server-side web page serving applications (as [[Java Server Pages|JSP]]), and applets embedded in web pages. + +There are a variety of arguments regarding Java's performance compared to other popular languages like [[C++]]. Some come to the conclusion that the programmer's choices make a bigger difference on performance in each language. Most show that each language is better than the other at specific types of operations (i.e. Java for memory allocation, C++ for numerical operations). An extensive summary of comparisons between Java and C++ can be found [[wp:Comparison of Java and C++|on Wikipedia]]. + +According to some [http://www.tiobe.com/tpci.htm sources], Java is currently one of the most popular programming languages in the world. + +Useful Java links: +* [http://www.java.com java.com] +* [http://www.java.net java.net] +* [http://openjdk.java.net OpenJDK] \ No newline at end of file diff --git a/Lang/Java/99_Bottles_of_Beer b/Lang/Java/99_Bottles_of_Beer new file mode 120000 index 0000000000..d920438d6b --- /dev/null +++ b/Lang/Java/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/Java \ No newline at end of file diff --git a/Lang/Java/Anagrams b/Lang/Java/Anagrams new file mode 120000 index 0000000000..41269f0f54 --- /dev/null +++ b/Lang/Java/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/Java \ No newline at end of file diff --git a/Lang/Java/Bulls_and_cows b/Lang/Java/Bulls_and_cows new file mode 120000 index 0000000000..f4b46d6777 --- /dev/null +++ b/Lang/Java/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/Java \ No newline at end of file diff --git a/Lang/Java/Comments b/Lang/Java/Comments new file mode 120000 index 0000000000..15e2d84036 --- /dev/null +++ b/Lang/Java/Comments @@ -0,0 +1 @@ +../../Task/Comments/Java \ No newline at end of file diff --git a/Lang/Java/FizzBuzz b/Lang/Java/FizzBuzz new file mode 120000 index 0000000000..b7e778d9be --- /dev/null +++ b/Lang/Java/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Java \ No newline at end of file diff --git a/Lang/Java/Infinity b/Lang/Java/Infinity new file mode 120000 index 0000000000..626032959a --- /dev/null +++ b/Lang/Java/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/Java \ No newline at end of file diff --git a/Lang/Java/JSON b/Lang/Java/JSON new file mode 120000 index 0000000000..3165bae25a --- /dev/null +++ b/Lang/Java/JSON @@ -0,0 +1 @@ +../../Task/JSON/Java \ No newline at end of file diff --git a/Lang/Java/Knuth_shuffle b/Lang/Java/Knuth_shuffle new file mode 120000 index 0000000000..0b95ff9705 --- /dev/null +++ b/Lang/Java/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/Java \ No newline at end of file diff --git a/Lang/Java/Ordered_words b/Lang/Java/Ordered_words new file mode 120000 index 0000000000..a34ddc9c34 --- /dev/null +++ b/Lang/Java/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/Java \ No newline at end of file diff --git a/Lang/Java/Pi b/Lang/Java/Pi new file mode 120000 index 0000000000..fce925d8ce --- /dev/null +++ b/Lang/Java/Pi @@ -0,0 +1 @@ +../../Task/Pi/Java \ No newline at end of file diff --git a/Lang/Java/Quine b/Lang/Java/Quine new file mode 120000 index 0000000000..32069494d1 --- /dev/null +++ b/Lang/Java/Quine @@ -0,0 +1 @@ +../../Task/Quine/Java \ No newline at end of file diff --git a/Lang/Java/Search_a_list b/Lang/Java/Search_a_list new file mode 120000 index 0000000000..6ff9feb819 --- /dev/null +++ b/Lang/Java/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/Java \ No newline at end of file diff --git a/Lang/JavaScript/0DESCRIPTION b/Lang/JavaScript/0DESCRIPTION new file mode 100644 index 0000000000..1e359df8ea --- /dev/null +++ b/Lang/JavaScript/0DESCRIPTION @@ -0,0 +1,21 @@ +{{language|JavaScript +|strength=weak +|express=implicit +|checking=dynamic +|gc=yes +|parampass=value +|LCT=yes +|bnf=http://javascript.comsci.us/syntax/statement/bnf.html}}{{language programming paradigm|Object-oriented}}{{language programming paradigm|functional}} +'''JavaScript''' is the name of Netscape Communications Corporation's implementation of the [[ECMAScript standard]], a scripting language based on the concept of prototype-based programming. The language is best known for its use in websites (as client-side JavaScript), but is also used to enable scripting access to objects embedded in other applications. + +Despite the name, JavaScript is only distantly related to the [[Java]] programming language, the main similarity being their common debt to the [[C]] syntax. Semantically, JavaScript syntax has far more in common with the [[Self]] [[programming language]]. + +JavaScript is a registered trademark of [[Sun Microsystems]], Inc. It was used under license for technology invented and implemented by Netscape Communications and current entities such as the Mozilla Foundation. + +JavaScript has been born again, now that [[AJAX]] has come up. The meaning of this is simply that [[AJAX]] has shown that JavaScript is really still useful in a lot of domains and that (most) web pages that use it can be given a whole new life. + +There's a nice table on Wikipedia that shows which version of JavaScript is release in which version of a browser: [[wp:JavaScript#Versions]] + +==Citations== +* [[wp:Javascript|Wikipedia:Javascript]] +* [http://www.squarefree.com/shell/ JavaScript shell], can run many of the JavaScript examples here \ No newline at end of file diff --git a/Lang/JavaScript/99_Bottles_of_Beer b/Lang/JavaScript/99_Bottles_of_Beer new file mode 120000 index 0000000000..19970ee49e --- /dev/null +++ b/Lang/JavaScript/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/JavaScript \ No newline at end of file diff --git a/Lang/JavaScript/Anagrams b/Lang/JavaScript/Anagrams new file mode 120000 index 0000000000..1eb0217323 --- /dev/null +++ b/Lang/JavaScript/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/JavaScript \ No newline at end of file diff --git a/Lang/JavaScript/Bulls_and_cows b/Lang/JavaScript/Bulls_and_cows new file mode 120000 index 0000000000..02b3adc51a --- /dev/null +++ b/Lang/JavaScript/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/JavaScript \ No newline at end of file diff --git a/Lang/JavaScript/FizzBuzz b/Lang/JavaScript/FizzBuzz new file mode 120000 index 0000000000..3a8be997c5 --- /dev/null +++ b/Lang/JavaScript/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/JavaScript \ No newline at end of file diff --git a/Lang/JavaScript/Infinity b/Lang/JavaScript/Infinity new file mode 120000 index 0000000000..9861cae0a4 --- /dev/null +++ b/Lang/JavaScript/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/JavaScript \ No newline at end of file diff --git a/Lang/JavaScript/JSON b/Lang/JavaScript/JSON new file mode 120000 index 0000000000..1fa8416a5e --- /dev/null +++ b/Lang/JavaScript/JSON @@ -0,0 +1 @@ +../../Task/JSON/JavaScript \ No newline at end of file diff --git a/Lang/JavaScript/Knuth_shuffle b/Lang/JavaScript/Knuth_shuffle new file mode 120000 index 0000000000..2ab480d7c5 --- /dev/null +++ b/Lang/JavaScript/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/JavaScript \ No newline at end of file diff --git a/Lang/JavaScript/Narcissist b/Lang/JavaScript/Narcissist new file mode 120000 index 0000000000..a8871cd7fa --- /dev/null +++ b/Lang/JavaScript/Narcissist @@ -0,0 +1 @@ +../../Task/Narcissist/JavaScript \ No newline at end of file diff --git a/Lang/JavaScript/Ordered_words b/Lang/JavaScript/Ordered_words new file mode 120000 index 0000000000..938f0cca91 --- /dev/null +++ b/Lang/JavaScript/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/JavaScript \ No newline at end of file diff --git a/Lang/JavaScript/Quine b/Lang/JavaScript/Quine new file mode 120000 index 0000000000..105c17f4c7 --- /dev/null +++ b/Lang/JavaScript/Quine @@ -0,0 +1 @@ +../../Task/Quine/JavaScript \ No newline at end of file diff --git a/Lang/JavaScript/Search_a_list b/Lang/JavaScript/Search_a_list new file mode 120000 index 0000000000..9271efdcf5 --- /dev/null +++ b/Lang/JavaScript/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/JavaScript \ No newline at end of file diff --git a/Lang/LaTeX/0DESCRIPTION b/Lang/LaTeX/0DESCRIPTION new file mode 100644 index 0000000000..80b612767b --- /dev/null +++ b/Lang/LaTeX/0DESCRIPTION @@ -0,0 +1,4 @@ +{{language|LaTeX}}'''LaTeX''' is a document preparation language (markup language) written by Lamport (1985, 1994) to allow authors to create documents to be typeset using the [[TeX]] typesetting language (Knuth: 1978, 1982), without having to know the internal details of TeX. For further details please see the links below. + +==See Also== +* [http://www.tug.org TeX Users Group] \ No newline at end of file diff --git a/Lang/LaTeX/99_Bottles_of_Beer b/Lang/LaTeX/99_Bottles_of_Beer new file mode 120000 index 0000000000..99e29f8b72 --- /dev/null +++ b/Lang/LaTeX/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/LaTeX \ No newline at end of file diff --git a/Lang/LaTeX/Comments b/Lang/LaTeX/Comments new file mode 120000 index 0000000000..46bd1fa280 --- /dev/null +++ b/Lang/LaTeX/Comments @@ -0,0 +1 @@ +../../Task/Comments/LaTeX \ No newline at end of file diff --git a/Lang/Lua/0DESCRIPTION b/Lang/Lua/0DESCRIPTION new file mode 100644 index 0000000000..84fed430d2 --- /dev/null +++ b/Lang/Lua/0DESCRIPTION @@ -0,0 +1,17 @@ +{{language|Lua +|exec=JIT +|strength=strong +|safety=safe +|express=implicit +|checking=dynamic +|gc=yes +|site=http://www.lua.org +|LCT=yes +|bnf=http://www.lua.org/manual/5.1/manual.html}}{{Codepad}}{{language programming paradigm|Object-oriented}}The Lua (pronounced LOO-ah) [[programming language]] is a lightweight, [[reflective programming|reflective]], [[imperative programming|imperative]] and [[procedural programming|procedural]] language, designed as a scripting language with extensible semantics as a primary goal. The name is derived from the Portuguese word for moon. + +Lua is commonly described as a "multi-[[:Category:Programming Paradigms|paradigm]]" language, providing a small set of general features that can be extended to fit different problem types, rather than providing a more complex and rigid specification to match a single paradigm. Lua, for instance, does not contain explicit support for inheritance, but allows it to be implemented relatively easily with metatables. Similarly, Lua allows programmers to implement namespaces, classes, and other related features using its single table implementation; first class functions allow the employment of many powerful techniques from functional programming; and full lexical scoping allows fine-grained information hiding to enforce the principle of least privilege. + +In general, Lua strives to provide flexible meta-features that can be extended as needed, rather than supply a feature-set specific to one programming paradigm. As a result, the base language is light—in fact, the full reference interpreter is only about 150KB compiled—and easily adaptable to a broad range of applications. + +==Citations== +* [[wp:Lua_%28programming_language%29|Wikipedia:Lua (programming language)]] \ No newline at end of file diff --git a/Lang/Lua/99_Bottles_of_Beer b/Lang/Lua/99_Bottles_of_Beer new file mode 120000 index 0000000000..e141062f63 --- /dev/null +++ b/Lang/Lua/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/Lua \ No newline at end of file diff --git a/Lang/Lua/Anagrams b/Lang/Lua/Anagrams new file mode 120000 index 0000000000..1530e85893 --- /dev/null +++ b/Lang/Lua/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/Lua \ No newline at end of file diff --git a/Lang/Lua/Bulls_and_cows b/Lang/Lua/Bulls_and_cows new file mode 120000 index 0000000000..2df7b7c083 --- /dev/null +++ b/Lang/Lua/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/Lua \ No newline at end of file diff --git a/Lang/Lua/Comments b/Lang/Lua/Comments new file mode 120000 index 0000000000..189334f64c --- /dev/null +++ b/Lang/Lua/Comments @@ -0,0 +1 @@ +../../Task/Comments/Lua \ No newline at end of file diff --git a/Lang/Lua/FizzBuzz b/Lang/Lua/FizzBuzz new file mode 120000 index 0000000000..09d8d89bb0 --- /dev/null +++ b/Lang/Lua/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Lua \ No newline at end of file diff --git a/Lang/Lua/Infinity b/Lang/Lua/Infinity new file mode 120000 index 0000000000..7bd4f6b0eb --- /dev/null +++ b/Lang/Lua/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/Lua \ No newline at end of file diff --git a/Lang/Lua/Knuth_shuffle b/Lang/Lua/Knuth_shuffle new file mode 120000 index 0000000000..52312d4119 --- /dev/null +++ b/Lang/Lua/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/Lua \ No newline at end of file diff --git a/Lang/Lua/Ordered_words b/Lang/Lua/Ordered_words new file mode 120000 index 0000000000..60f16f6aab --- /dev/null +++ b/Lang/Lua/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/Lua \ No newline at end of file diff --git a/Lang/Lua/Quine b/Lang/Lua/Quine new file mode 120000 index 0000000000..ca46492742 --- /dev/null +++ b/Lang/Lua/Quine @@ -0,0 +1 @@ +../../Task/Quine/Lua \ No newline at end of file diff --git a/Lang/Lua/Search_a_list b/Lang/Lua/Search_a_list new file mode 120000 index 0000000000..b42b56d5de --- /dev/null +++ b/Lang/Lua/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/Lua \ No newline at end of file diff --git a/Lang/PHP/0DESCRIPTION b/Lang/PHP/0DESCRIPTION new file mode 100644 index 0000000000..ad1d2b043d --- /dev/null +++ b/Lang/PHP/0DESCRIPTION @@ -0,0 +1,16 @@ +{{language|PHP +|exec=bytecode +|strength=weak +|checking=dynamic +|parampass=both +|gc=yes +|site=http://www.php.net/ +|LCT=yes +|bnf=http://php.comsci.us/syntax/statement/index.html}} +{{language programming paradigm|Object-oriented}} +{{language programming paradigm|imperative}} +{{language programming paradigm|reflective}}{{Codepad}} +'''PHP''' (PHP: Hypertext Preprocessor) is a [[reflective programming]] language originally designed for producing dynamic Web pages. PHP is used mainly in server-side application software, but can be used from a command line interface or in standalone graphical applications. + +==Citations== +* [[wp:PHP|Wikipedia:PHP]] \ No newline at end of file diff --git a/Lang/PHP/99_Bottles_of_Beer b/Lang/PHP/99_Bottles_of_Beer new file mode 120000 index 0000000000..d96aa7d46f --- /dev/null +++ b/Lang/PHP/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/PHP \ No newline at end of file diff --git a/Lang/PHP/Anagrams b/Lang/PHP/Anagrams new file mode 120000 index 0000000000..31ace70c0f --- /dev/null +++ b/Lang/PHP/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/PHP \ No newline at end of file diff --git a/Lang/PHP/Bulls_and_cows b/Lang/PHP/Bulls_and_cows new file mode 120000 index 0000000000..b66993d8d2 --- /dev/null +++ b/Lang/PHP/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/PHP \ No newline at end of file diff --git a/Lang/PHP/Comments b/Lang/PHP/Comments new file mode 120000 index 0000000000..e6980955ef --- /dev/null +++ b/Lang/PHP/Comments @@ -0,0 +1 @@ +../../Task/Comments/PHP \ No newline at end of file diff --git a/Lang/PHP/FizzBuzz b/Lang/PHP/FizzBuzz new file mode 120000 index 0000000000..cc5cf7249e --- /dev/null +++ b/Lang/PHP/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/PHP \ No newline at end of file diff --git a/Lang/PHP/Infinity b/Lang/PHP/Infinity new file mode 120000 index 0000000000..d3f1060282 --- /dev/null +++ b/Lang/PHP/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/PHP \ No newline at end of file diff --git a/Lang/PHP/JSON b/Lang/PHP/JSON new file mode 120000 index 0000000000..adfd48cde2 --- /dev/null +++ b/Lang/PHP/JSON @@ -0,0 +1 @@ +../../Task/JSON/PHP \ No newline at end of file diff --git a/Lang/PHP/Knuth_shuffle b/Lang/PHP/Knuth_shuffle new file mode 120000 index 0000000000..25ce913d80 --- /dev/null +++ b/Lang/PHP/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/PHP \ No newline at end of file diff --git a/Lang/PHP/Quine b/Lang/PHP/Quine new file mode 120000 index 0000000000..9d278c4fdc --- /dev/null +++ b/Lang/PHP/Quine @@ -0,0 +1 @@ +../../Task/Quine/PHP \ No newline at end of file diff --git a/Lang/PHP/Search_a_list b/Lang/PHP/Search_a_list new file mode 120000 index 0000000000..2d4244a188 --- /dev/null +++ b/Lang/PHP/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/PHP \ No newline at end of file diff --git a/Lang/PIR/0DESCRIPTION b/Lang/PIR/0DESCRIPTION new file mode 100644 index 0000000000..b89df667e7 --- /dev/null +++ b/Lang/PIR/0DESCRIPTION @@ -0,0 +1,5 @@ +{{language +|site=http://www.parrot.org/dev/examples/pir +}} +Parrot Intermediate Representation is a high-level assembly language to program the [[runs on vm::Parrot]] virtual machine. PIR extends [[PASM]] with syntactic sugar. +{{stub}} \ No newline at end of file diff --git a/Lang/PIR/99_Bottles_of_Beer b/Lang/PIR/99_Bottles_of_Beer new file mode 120000 index 0000000000..91647c02c2 --- /dev/null +++ b/Lang/PIR/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/PIR \ No newline at end of file diff --git a/Lang/PIR/FizzBuzz b/Lang/PIR/FizzBuzz new file mode 120000 index 0000000000..9bc9dd68dd --- /dev/null +++ b/Lang/PIR/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/PIR \ No newline at end of file diff --git a/Lang/Perl/0DESCRIPTION b/Lang/Perl/0DESCRIPTION new file mode 100644 index 0000000000..3e976e8802 --- /dev/null +++ b/Lang/Perl/0DESCRIPTION @@ -0,0 +1,25 @@ +{{language +|exec=bytecode +|strength=weak +|express=implicit +|checking=both +|parampass=reference +|gc=no +|tags=perl +|LCT=yes +|bnf=http://perl.comsci.us/syntax/statement/index.html}} +{{language programming paradigm|Dynamic}} +{{language programming paradigm|imperative}} +{{language programming paradigm|procedural}} +{{language programming paradigm|reflective}} +{{language programming paradigm|functional}} +{{language programming paradigm|object-oriented}} +{{language programming paradigm|generic}} +{{codepad}}'''Perl''' is both the name of a programming language and the name of the primary implementation of that language. + +As a language, it takes the best from other programming languages such as [[derived from::BASIC]], [[derived from::Lisp]], [[derived from::C]] and the [[Unix]] tools [[derived from::sed]], [[derived from::AWK]] and [[derived from::UNIX Shell| the UNIX shell]]. It is particularly suited for Unix systems programming, [[:Category:Text processing|text processing]] and [[Data Munging|gluing heterogeneous programs together]]. Its interpreter is called perl. Perl has seen five major revisions, and [[Perl 6|a sixth]] is currently being worked on. + +The implementation known as Perl is available on a wide variety of mostly UNIX-based operating systems. + +==Citations== +* [[wp:Perl|Wikipedia:Perl]] \ No newline at end of file diff --git a/Lang/Perl/99_Bottles_of_Beer b/Lang/Perl/99_Bottles_of_Beer new file mode 120000 index 0000000000..feec02fa24 --- /dev/null +++ b/Lang/Perl/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/Perl \ No newline at end of file diff --git a/Lang/Perl/Anagrams b/Lang/Perl/Anagrams new file mode 120000 index 0000000000..046d601351 --- /dev/null +++ b/Lang/Perl/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/Perl \ No newline at end of file diff --git a/Lang/Perl/Bulls_and_cows b/Lang/Perl/Bulls_and_cows new file mode 120000 index 0000000000..94a0e43431 --- /dev/null +++ b/Lang/Perl/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/Perl \ No newline at end of file diff --git a/Lang/Perl/Comments b/Lang/Perl/Comments new file mode 120000 index 0000000000..ea38ccca94 --- /dev/null +++ b/Lang/Perl/Comments @@ -0,0 +1 @@ +../../Task/Comments/Perl \ No newline at end of file diff --git a/Lang/Perl/Death_Star b/Lang/Perl/Death_Star new file mode 120000 index 0000000000..b9780bec67 --- /dev/null +++ b/Lang/Perl/Death_Star @@ -0,0 +1 @@ +../../Task/Death_Star/Perl \ No newline at end of file diff --git a/Lang/Perl/Entropy b/Lang/Perl/Entropy new file mode 120000 index 0000000000..e2450e5bb2 --- /dev/null +++ b/Lang/Perl/Entropy @@ -0,0 +1 @@ +../../Task/Entropy/Perl \ No newline at end of file diff --git a/Lang/Perl/FizzBuzz b/Lang/Perl/FizzBuzz new file mode 120000 index 0000000000..fffbcf58eb --- /dev/null +++ b/Lang/Perl/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Perl \ No newline at end of file diff --git a/Lang/Perl/Infinity b/Lang/Perl/Infinity new file mode 120000 index 0000000000..efb9a76b8e --- /dev/null +++ b/Lang/Perl/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/Perl \ No newline at end of file diff --git a/Lang/Perl/JSON b/Lang/Perl/JSON new file mode 120000 index 0000000000..91c5a86628 --- /dev/null +++ b/Lang/Perl/JSON @@ -0,0 +1 @@ +../../Task/JSON/Perl \ No newline at end of file diff --git a/Lang/Perl/Knuth_shuffle b/Lang/Perl/Knuth_shuffle new file mode 120000 index 0000000000..f7382a4e8a --- /dev/null +++ b/Lang/Perl/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/Perl \ No newline at end of file diff --git a/Lang/Perl/Narcissist b/Lang/Perl/Narcissist new file mode 120000 index 0000000000..70e04d3374 --- /dev/null +++ b/Lang/Perl/Narcissist @@ -0,0 +1 @@ +../../Task/Narcissist/Perl \ No newline at end of file diff --git a/Lang/Perl/Ordered_words b/Lang/Perl/Ordered_words new file mode 120000 index 0000000000..6aeb45f10b --- /dev/null +++ b/Lang/Perl/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/Perl \ No newline at end of file diff --git a/Lang/Perl/Pi b/Lang/Perl/Pi new file mode 120000 index 0000000000..5fb7bf1f59 --- /dev/null +++ b/Lang/Perl/Pi @@ -0,0 +1 @@ +../../Task/Pi/Perl \ No newline at end of file diff --git a/Lang/Perl/Quine b/Lang/Perl/Quine new file mode 120000 index 0000000000..7e2bea3532 --- /dev/null +++ b/Lang/Perl/Quine @@ -0,0 +1 @@ +../../Task/Quine/Perl \ No newline at end of file diff --git a/Lang/Perl/Search_a_list b/Lang/Perl/Search_a_list new file mode 120000 index 0000000000..1b5c16892d --- /dev/null +++ b/Lang/Perl/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/Perl \ No newline at end of file diff --git a/Lang/PicoLisp/0DESCRIPTION b/Lang/PicoLisp/0DESCRIPTION new file mode 100644 index 0000000000..58c104f5f9 --- /dev/null +++ b/Lang/PicoLisp/0DESCRIPTION @@ -0,0 +1,21 @@ +{{language +|exec=interpreted +|checking=dynamic +|gc=yes +|site=http://home.picolisp.com}}[[Category:Lisp Implementations]] + +'''PicoLisp''' is a small and fast interpreted [[Lisp]] dialect. It runs on [[Linux]] and other [[POSIX]]-compliant systems, and - in a reduced version - on [[JVM]]. + +Its most prominent feature is "simplicity". It is built on top of a single internal data type (the cell), without giving up flexibility and expressive power. On the language level, it supports just three data types (numbers, symbols and lists), constructed from internal cells. + +PicoLisp programs are often more succinct - and at the same time faster - than those of other interpreted languages. A special feature is the intrinsic database functionality: Persistent symbols are first-class objects, and applications are written using a class hierarchy of entities and relations. + +Other features include a [[Prolog]] engine for logic programming and database queries, distributed databases, inlining of [[C]]/asm functions and native C/asm function calls, child process management, interprocess communication, Browser GUI, Internationalization and localization. + +To try the RosettaCode tasks, download [http://software-lab.de/picoLisp.tgz picoLisp.tgz], unpack it, and follow the instructions in README and INSTALL. Unless stated otherwise, the examples assume that the interpreter was started with the command $ pil + +: +(i.e. with a '+' for "debug mode", as recommended in the documentation. Note: Do not call just the 'picolisp' binary, this is only the bare kernel of PicoLisp) + +==See Also== +* [http://software-lab.de/doc/ref.html Reference Manual] +* [http://software-lab.de/doc/faq.html Frequently asked questions] \ No newline at end of file diff --git a/Lang/PicoLisp/99_Bottles_of_Beer b/Lang/PicoLisp/99_Bottles_of_Beer new file mode 120000 index 0000000000..94783a5377 --- /dev/null +++ b/Lang/PicoLisp/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/PicoLisp \ No newline at end of file diff --git a/Lang/PicoLisp/Anagrams b/Lang/PicoLisp/Anagrams new file mode 120000 index 0000000000..1c51eab1a6 --- /dev/null +++ b/Lang/PicoLisp/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/PicoLisp \ No newline at end of file diff --git a/Lang/PicoLisp/Bulls_and_cows b/Lang/PicoLisp/Bulls_and_cows new file mode 120000 index 0000000000..772426a71e --- /dev/null +++ b/Lang/PicoLisp/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/PicoLisp \ No newline at end of file diff --git a/Lang/PicoLisp/Comments b/Lang/PicoLisp/Comments new file mode 120000 index 0000000000..73a13cec66 --- /dev/null +++ b/Lang/PicoLisp/Comments @@ -0,0 +1 @@ +../../Task/Comments/PicoLisp \ No newline at end of file diff --git a/Lang/PicoLisp/FizzBuzz b/Lang/PicoLisp/FizzBuzz new file mode 120000 index 0000000000..ffb6116ebb --- /dev/null +++ b/Lang/PicoLisp/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/PicoLisp \ No newline at end of file diff --git a/Lang/PicoLisp/Infinity b/Lang/PicoLisp/Infinity new file mode 120000 index 0000000000..b99cbfe109 --- /dev/null +++ b/Lang/PicoLisp/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/PicoLisp \ No newline at end of file diff --git a/Lang/PicoLisp/JSON b/Lang/PicoLisp/JSON new file mode 120000 index 0000000000..d612282bb5 --- /dev/null +++ b/Lang/PicoLisp/JSON @@ -0,0 +1 @@ +../../Task/JSON/PicoLisp \ No newline at end of file diff --git a/Lang/PicoLisp/Knuth_shuffle b/Lang/PicoLisp/Knuth_shuffle new file mode 120000 index 0000000000..b1824ab781 --- /dev/null +++ b/Lang/PicoLisp/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/PicoLisp \ No newline at end of file diff --git a/Lang/PicoLisp/Narcissist b/Lang/PicoLisp/Narcissist new file mode 120000 index 0000000000..5dc79cacf6 --- /dev/null +++ b/Lang/PicoLisp/Narcissist @@ -0,0 +1 @@ +../../Task/Narcissist/PicoLisp \ No newline at end of file diff --git a/Lang/PicoLisp/Ordered_words b/Lang/PicoLisp/Ordered_words new file mode 120000 index 0000000000..bd7393a23c --- /dev/null +++ b/Lang/PicoLisp/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/PicoLisp \ No newline at end of file diff --git a/Lang/PicoLisp/Pi b/Lang/PicoLisp/Pi new file mode 120000 index 0000000000..e7216a0243 --- /dev/null +++ b/Lang/PicoLisp/Pi @@ -0,0 +1 @@ +../../Task/Pi/PicoLisp \ No newline at end of file diff --git a/Lang/PicoLisp/Quine b/Lang/PicoLisp/Quine new file mode 120000 index 0000000000..a780a753a8 --- /dev/null +++ b/Lang/PicoLisp/Quine @@ -0,0 +1 @@ +../../Task/Quine/PicoLisp \ No newline at end of file diff --git a/Lang/PicoLisp/Search_a_list b/Lang/PicoLisp/Search_a_list new file mode 120000 index 0000000000..d52621040a --- /dev/null +++ b/Lang/PicoLisp/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/PicoLisp \ No newline at end of file diff --git a/Lang/Python/0DESCRIPTION b/Lang/Python/0DESCRIPTION new file mode 100644 index 0000000000..8f8dcbf7f7 --- /dev/null +++ b/Lang/Python/0DESCRIPTION @@ -0,0 +1,31 @@ +{{language +|exec=interpreted +|site=http://www.python.org +|strength=strong +|safety=safe +|express=implicit +|checking=dynamic +|parampass=value +|gc=yes +|LCT=yes +|bnf=http://docs.python.org/py3k/reference/grammar.html}}{{language programming paradigm|Dynamic}}{{language programming paradigm|Object-oriented}}{{codepad}}From the official [http://www.python.org Python] website: "Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs." + +It is easy to create clean bug-free programs in Python due to the motto: "Errors should never pass silently." Python is an [[wp:Interpreter (computing)|interpreter]]. Python source files (.py files) are typically compiled to an intermediate [[bytecode]] language (.pyc files) and executed by a Python Virtual Machine. + +===Notes=== +Because Python uses whitespace for structure, do not format long code examples with leading whitespace, instead use
tags, or, preferably, tags. This will make it easier to copy code into and out of the wiki. Example: +:print 'this line must not have leading indentation!' +if True: + print 'example: ', foo(3), len(bar) + +Some Python examples may deviate from idiomatic Python because they may be written to work in Python 3.X as well as Python 2.X environments. This includes doing things like: +* Using brackets in print statements/functions of one expression. +* Using zip and not izip; keys(), values(), items() and not their iter- forms. +* Checking for raw_input and setting raw_input to input if not found. +* Conditionally importing reduce if it is not found. +This style is not a requirement for Python code on RC, but it may be in use and should not necessarily be 'corrected' if found in examples. + +The command line is often used in Python for short pieces of code, and so, again; examples showing such use are not incorrect and may be left. + +==See Also== +* [[wp:python_(programming_language)|Wikipedia: Python]] \ No newline at end of file diff --git a/Lang/Python/99_Bottles_of_Beer b/Lang/Python/99_Bottles_of_Beer new file mode 120000 index 0000000000..f609aeaf91 --- /dev/null +++ b/Lang/Python/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/Python \ No newline at end of file diff --git a/Lang/Python/Anagrams b/Lang/Python/Anagrams new file mode 120000 index 0000000000..dce19a5f49 --- /dev/null +++ b/Lang/Python/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/Python \ No newline at end of file diff --git a/Lang/Python/Bulls_and_cows b/Lang/Python/Bulls_and_cows new file mode 120000 index 0000000000..910c2ffe7c --- /dev/null +++ b/Lang/Python/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/Python \ No newline at end of file diff --git a/Lang/Python/Comments b/Lang/Python/Comments new file mode 120000 index 0000000000..034f470f4e --- /dev/null +++ b/Lang/Python/Comments @@ -0,0 +1 @@ +../../Task/Comments/Python \ No newline at end of file diff --git a/Lang/Python/Death_Star b/Lang/Python/Death_Star new file mode 120000 index 0000000000..79d34adafa --- /dev/null +++ b/Lang/Python/Death_Star @@ -0,0 +1 @@ +../../Task/Death_Star/Python \ No newline at end of file diff --git a/Lang/Python/Entropy b/Lang/Python/Entropy new file mode 120000 index 0000000000..9cf0f7de79 --- /dev/null +++ b/Lang/Python/Entropy @@ -0,0 +1 @@ +../../Task/Entropy/Python \ No newline at end of file diff --git a/Lang/Python/FizzBuzz b/Lang/Python/FizzBuzz new file mode 120000 index 0000000000..eeb9ad2275 --- /dev/null +++ b/Lang/Python/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Python \ No newline at end of file diff --git a/Lang/Python/Infinity b/Lang/Python/Infinity new file mode 120000 index 0000000000..95bc6cb6d2 --- /dev/null +++ b/Lang/Python/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/Python \ No newline at end of file diff --git a/Lang/Python/JSON b/Lang/Python/JSON new file mode 120000 index 0000000000..49b8094760 --- /dev/null +++ b/Lang/Python/JSON @@ -0,0 +1 @@ +../../Task/JSON/Python \ No newline at end of file diff --git a/Lang/Python/Knuth_shuffle b/Lang/Python/Knuth_shuffle new file mode 120000 index 0000000000..029e5f3cf4 --- /dev/null +++ b/Lang/Python/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/Python \ No newline at end of file diff --git a/Lang/Python/Narcissist b/Lang/Python/Narcissist new file mode 120000 index 0000000000..a5a4620956 --- /dev/null +++ b/Lang/Python/Narcissist @@ -0,0 +1 @@ +../../Task/Narcissist/Python \ No newline at end of file diff --git a/Lang/Python/Ordered_words b/Lang/Python/Ordered_words new file mode 120000 index 0000000000..be7a24d785 --- /dev/null +++ b/Lang/Python/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/Python \ No newline at end of file diff --git a/Lang/Python/Pi b/Lang/Python/Pi new file mode 120000 index 0000000000..c01e2b45c0 --- /dev/null +++ b/Lang/Python/Pi @@ -0,0 +1 @@ +../../Task/Pi/Python \ No newline at end of file diff --git a/Lang/Python/Quine b/Lang/Python/Quine new file mode 120000 index 0000000000..55c408d5c5 --- /dev/null +++ b/Lang/Python/Quine @@ -0,0 +1 @@ +../../Task/Quine/Python \ No newline at end of file diff --git a/Lang/Python/Search_a_list b/Lang/Python/Search_a_list new file mode 120000 index 0000000000..a300e71ef3 --- /dev/null +++ b/Lang/Python/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/Python \ No newline at end of file diff --git a/Lang/REXX/0DESCRIPTION b/Lang/REXX/0DESCRIPTION new file mode 100644 index 0000000000..15af1e6251 --- /dev/null +++ b/Lang/REXX/0DESCRIPTION @@ -0,0 +1,61 @@ +{{language|REXX}} +{{Wikipedia|REXX}} +REXX (REstructured eXtended eXecutor) is an interpreted programming language which was developed at IBM. It is a structured high-level programming language which was designed to be both easy to learn and easy to read. Both proprietary and open source interpreters for REXX are available on a wide range of computing platforms, and compilers are available for IBM mainframes. + +* '''[[wp:AREXX|AREXX]]''' is a classic REXX implementation (with extensions) for the AmigaOS, given in bundle since AmigaOS 2. (Regina REXX has specific support for the extended functions that were introduced in AREXX.) ARexx was written in 1987 by William S. Hawes. + +* '''[[Brexx]]''' a classic REXX written by Vassilis N. Vlachoudis, it is free and it's open source and available under the GNU General Public License. + +* '''[[CRX REXX]]''' (Compact REXX) is a classic REXX first written by Dr. Brian Marks. + +* '''[[CTC REXX]]''' is a classic REXX that is bundled with PC/SPF and written by Command Technology Corporation, a license is required to use this product. REXX can only under PC/SPF and it's panels. + +* '''[[KEXX]]''' is a subset of REXX that is bundled with KEDIT and written by Mansfield Software Group, Inc., a license is required to use this product. KEXX only executes under the KEDIT licensed product. + +* '''[[MVS/TSO REXX]]''' is IBM's implementation of classic REXX, a license is required to use the operating system, '''MVS''' and '''TSO''' are used here as generic references. + +* '''[[MVS/TSO REXX compiler]]''' is an IBM implementation of classic REXX, a license is required to use this product as well as the operating system it runs under. + +* '''[[NetRexx|NetRexx]]''' is IBM's variant of the REXX programming language to run on the Java virtual machine. It supports a classic REXX syntax, with no reserved keywords, along with considerable additions to support Object-oriented programming in a manner compatible with Java's object model, yet can be used as both a compiled and an interpreted language, with an option of using only data types native to the JVM or the NetRexx runtime package. The syntax and object model of NetRexx differ from Object REXX. + +* '''[[ooRexx|ooRexx]]''' (Open Object Rexx) is an implementation of [[wp:Object REXX|Object REXX]], which is REXX with OO features (some REXX programs are compatible). + +* '''[[OS/2 REXX]]''' is a classic REXX that is an IBM implementation of classic REXX, a license is required to use this product as well as the operating system it runs under. + +* '''[[OS/400 REXX]]''' is an IBM implementation of classic REXX, a license is required to use this product as well as the operating system it runs under. + +* '''[[PC/REXX]]''' is the first classic REXX implented outside of IBM mainframes, intended for IBM DOS and MS DOS. Written by Mansfield Software Group, Inc., REXX was bundled with KEDIT, a license is required to use this product. + +* '''[[Personal REXX]]''' is a classic REXX that is intended for IBM DOS and MS DOS, written by a Quercus Systems, a license is required to use this product. + +* '''[[Regina REXX]]''' is an implementation first created by Anders Christensen and now maintained by others, notably Mark Hessling. Regina REXX runs on more different platforms than any other REXX, too many to name here. + +* '''[[Reginald REXX]]''' is a REXX developed by Jeff Glatt. It can be downloaded freely. + +* '''[[REXX/imc]]''' a classic REXX developed by Ian M. Collier (imc) for Linux/Unix. + +* '''[[ROO oo-REXX]]''' an object-oriented REXX delveloped by Keith Watts of Kilowatt Software, Inc. It can be downloaded freely. '''ROO''' is also known as '''ROO!'''. + +* '''[[R4 REXX]]''' a classic REXX developed by Kieth Watts of Kilowatt Software, Inc. It was also known as Portable REXX. It can be downloaded freely. + +* '''[[VM/CMS REXX]]''' is an IBM implementation of classic REXX that was first implemented in the early 1980s. A license is required to use this product as well as the operating system that it runs under. This was the original implementation of REXX written by Mike Cowlishaw of IBM (circa 1979). + +* '''[[VM/CMS REXX compiler]]''' is an IBM implementation of classic REXX written by Lundin and Woodruff, a license is required to use this product as well as the operating system it runs under. + +
[Most of the entries were entered mostly from memory and apologies are offered for not knowing more about what wording should be used; the IBM operating systems or Program Products that run REXX are numerous and varied. Their complete (official) names would fill a pagefull. Some of the REXXes are no longer sold nor available for downloading or purchase, others are no longer maintained. Naming of names is being avoided (especially those licensed products for sale), and it is hoped that this is seen that no products nor vendors are being endorsed, appraised, or critiqued.] -- [[User:Gerard Schildberger|Gerard Schildberger]] 09:28, 1 July 2012 (UTC) + +===External Links=== +* [http://sourceforge.net/projects/brexx/ Brexx interpreter] +* [http://www.oorexx.org/ Open Object Rexx - www.oorexx.org] +* [http://www.netrexx.org The NetRexx Programming Language - www.netrexx.org] +* [http://www.rexxla.org The Rexx Language Association - www.rexxla.org] +* [http://regina-rexx.sourceforge.net/index.html Regina Rexx Interpreter] +* [http://www.kedit.com/ Mansfield Software Group, Inc. (KEDIT)] +* [http://www.quercus-sys.com/ Personal REXX, Quercus Systems] +* [http://www.commandtechnology.com/ CTC Command Technology] +* [http://www.rexxla.org/ CRX Open Source (right column side)] +* [http://www.kilowattsoftware.com/r4Page.htm R4, Kilowatt Software] +* [http://www.kilowattsoftware.com/rooPage.htm ROO, Kilowatt Software] +* [http://publib.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/HCSE2C00/CCONTENTS?SHELF=hcsh2ab0&DN=SC24-6221-00&DT=20090724140455 z/VM V6R1 REXX/VM Reference] +* [http://publib.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/HCSB3C00/CCONTENTS?SHELF=hcsh2ab0&DN=SC24-6222-00&DT=20090724131829 z/VM V6R1 REXX/VM User's Guide] +* [http://www.rexxinfo.org/html/rexxinfo1.html#Rexx-Manuals {many references to REXX manuals}] \ No newline at end of file diff --git a/Lang/REXX/99_Bottles_of_Beer b/Lang/REXX/99_Bottles_of_Beer new file mode 120000 index 0000000000..6b84303515 --- /dev/null +++ b/Lang/REXX/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/REXX \ No newline at end of file diff --git a/Lang/REXX/Anagrams b/Lang/REXX/Anagrams new file mode 120000 index 0000000000..72319b721c --- /dev/null +++ b/Lang/REXX/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/REXX \ No newline at end of file diff --git a/Lang/REXX/Bulls_and_cows b/Lang/REXX/Bulls_and_cows new file mode 120000 index 0000000000..b95a21cde4 --- /dev/null +++ b/Lang/REXX/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/REXX \ No newline at end of file diff --git a/Lang/REXX/Comments b/Lang/REXX/Comments new file mode 120000 index 0000000000..8ea6780a03 --- /dev/null +++ b/Lang/REXX/Comments @@ -0,0 +1 @@ +../../Task/Comments/REXX \ No newline at end of file diff --git a/Lang/REXX/Death_Star b/Lang/REXX/Death_Star new file mode 120000 index 0000000000..8e762db023 --- /dev/null +++ b/Lang/REXX/Death_Star @@ -0,0 +1 @@ +../../Task/Death_Star/REXX \ No newline at end of file diff --git a/Lang/REXX/Entropy b/Lang/REXX/Entropy new file mode 120000 index 0000000000..5e4842e036 --- /dev/null +++ b/Lang/REXX/Entropy @@ -0,0 +1 @@ +../../Task/Entropy/REXX \ No newline at end of file diff --git a/Lang/REXX/FizzBuzz b/Lang/REXX/FizzBuzz new file mode 120000 index 0000000000..366ca218d9 --- /dev/null +++ b/Lang/REXX/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/REXX \ No newline at end of file diff --git a/Lang/REXX/Knuth_shuffle b/Lang/REXX/Knuth_shuffle new file mode 120000 index 0000000000..08e9b42fb8 --- /dev/null +++ b/Lang/REXX/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/REXX \ No newline at end of file diff --git a/Lang/REXX/Narcissist b/Lang/REXX/Narcissist new file mode 120000 index 0000000000..8c847ee95b --- /dev/null +++ b/Lang/REXX/Narcissist @@ -0,0 +1 @@ +../../Task/Narcissist/REXX \ No newline at end of file diff --git a/Lang/REXX/Ordered_words b/Lang/REXX/Ordered_words new file mode 120000 index 0000000000..2132b90717 --- /dev/null +++ b/Lang/REXX/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/REXX \ No newline at end of file diff --git a/Lang/REXX/Pi b/Lang/REXX/Pi new file mode 120000 index 0000000000..8189ba3922 --- /dev/null +++ b/Lang/REXX/Pi @@ -0,0 +1 @@ +../../Task/Pi/REXX \ No newline at end of file diff --git a/Lang/REXX/Quine b/Lang/REXX/Quine new file mode 120000 index 0000000000..a649884954 --- /dev/null +++ b/Lang/REXX/Quine @@ -0,0 +1 @@ +../../Task/Quine/REXX \ No newline at end of file diff --git a/Lang/REXX/Search_a_list b/Lang/REXX/Search_a_list new file mode 120000 index 0000000000..20602114d4 --- /dev/null +++ b/Lang/REXX/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/REXX \ No newline at end of file diff --git a/Lang/Ruby/0DESCRIPTION b/Lang/Ruby/0DESCRIPTION new file mode 100644 index 0000000000..8d11ec4aa5 --- /dev/null +++ b/Lang/Ruby/0DESCRIPTION @@ -0,0 +1,31 @@ +{{language +|exec=interpreted +|strength=strong +|express=implicit +|checking=dynamic +|parampass=value +|gc=yes +|tags=ruby +|site=http://www.ruby-lang.org +|hopl id=2458 +|LCT=yes +|bnf=http://web.njit.edu/all_topics/Prog_Lang_Docs/html/ruby/yacc.html}}{{language programming paradigm|Dynamic}} +{{language programming paradigm|Object-oriented}} +{{language programming paradigm|Imperative}} +{{language programming paradigm|Functional}} +{{language programming paradigm|Reflective}} +{{codepad}}Ruby is an interpreted language written by Yukihiro "matz" Matsumoto that originates from Japan. + +It is a language that combines +* Joy of programming +* Powerful [[object-oriented]] style +* Flexibility and extensibility +* [[Platform]] independence + +Ruby is a language of careful balance. Its creator blended parts of his favorite languages ([[Perl]], [[Smalltalk]], [[Eiffel]], [[Ada]], and [[Lisp]]) to form a new language that balances [[functional programming]] with [[imperative programming]]. + +He has often said that he is “trying to make Ruby natural, not simple,” in a way that mirrors life. + +Since its public release in 1995, Ruby has drawn devoted coders worldwide. In 2006, Ruby achieved mass acceptance. The [http://www.tiobe.com/tpci.htm TIOBE] index, which measures the growth of programming languages, ranks Ruby as #11 among programming languages worldwide. Much of the growth is attributed to the popularity of software written in Ruby, particularly the Rails web framework. + +An interactive tutorial is available in the form of an [http://tryruby.org/ Interactive Console] inside of your Web Browser. \ No newline at end of file diff --git a/Lang/Ruby/99_Bottles_of_Beer b/Lang/Ruby/99_Bottles_of_Beer new file mode 120000 index 0000000000..443cd8a1aa --- /dev/null +++ b/Lang/Ruby/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Anagrams b/Lang/Ruby/Anagrams new file mode 120000 index 0000000000..420b72457c --- /dev/null +++ b/Lang/Ruby/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Bulls_and_cows b/Lang/Ruby/Bulls_and_cows new file mode 120000 index 0000000000..87a84d89ec --- /dev/null +++ b/Lang/Ruby/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Comments b/Lang/Ruby/Comments new file mode 120000 index 0000000000..5cce41f81c --- /dev/null +++ b/Lang/Ruby/Comments @@ -0,0 +1 @@ +../../Task/Comments/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Entropy b/Lang/Ruby/Entropy new file mode 120000 index 0000000000..ea474f54a7 --- /dev/null +++ b/Lang/Ruby/Entropy @@ -0,0 +1 @@ +../../Task/Entropy/Ruby \ No newline at end of file diff --git a/Lang/Ruby/FizzBuzz b/Lang/Ruby/FizzBuzz new file mode 120000 index 0000000000..72c9b5bf91 --- /dev/null +++ b/Lang/Ruby/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Infinity b/Lang/Ruby/Infinity new file mode 120000 index 0000000000..69e85ca84a --- /dev/null +++ b/Lang/Ruby/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/Ruby \ No newline at end of file diff --git a/Lang/Ruby/JSON b/Lang/Ruby/JSON new file mode 120000 index 0000000000..71f3fca4bc --- /dev/null +++ b/Lang/Ruby/JSON @@ -0,0 +1 @@ +../../Task/JSON/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Knuth_shuffle b/Lang/Ruby/Knuth_shuffle new file mode 120000 index 0000000000..b1e85530ac --- /dev/null +++ b/Lang/Ruby/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Narcissist b/Lang/Ruby/Narcissist new file mode 120000 index 0000000000..0d77661ddb --- /dev/null +++ b/Lang/Ruby/Narcissist @@ -0,0 +1 @@ +../../Task/Narcissist/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Ordered_words b/Lang/Ruby/Ordered_words new file mode 120000 index 0000000000..b35aa5a3f0 --- /dev/null +++ b/Lang/Ruby/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Pi b/Lang/Ruby/Pi new file mode 120000 index 0000000000..f97e4d8e9c --- /dev/null +++ b/Lang/Ruby/Pi @@ -0,0 +1 @@ +../../Task/Pi/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Quine b/Lang/Ruby/Quine new file mode 120000 index 0000000000..a74c5e6e9f --- /dev/null +++ b/Lang/Ruby/Quine @@ -0,0 +1 @@ +../../Task/Quine/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Search_a_list b/Lang/Ruby/Search_a_list new file mode 120000 index 0000000000..df8f849c8a --- /dev/null +++ b/Lang/Ruby/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/Ruby \ No newline at end of file diff --git a/Lang/SNUSP/0DESCRIPTION b/Lang/SNUSP/0DESCRIPTION new file mode 100644 index 0000000000..ecc6b35961 --- /dev/null +++ b/Lang/SNUSP/0DESCRIPTION @@ -0,0 +1,9 @@ +{{language|SNUSP| +exec=interpreted}}'''SNUSP''' is an esoteric language that is a mix of [[Brainf***]] and [[Befunge]], with a call stack and optional concurrency thrown in. It uses all of the basic Brainf*** commands except the loop commands ('[' and ']'). There is a code pointer which moves through the two-dimensional code space in one of four directions like in Befunge, and it "bounces off" of two "mirrors" ('/' and '\'). For instance, if the code pointer is moving to the right and hits a '\', it starts to move down starting with the character below the mirror. The two other flow control commands are '?' (skip the next character if the element at the memory pointer is 0), and '!' (unconditional skip). This is how SNUSP can get away without Brainf***'s loop commands. The optional '$' (start the code pointer here) rounds out '''Core SNUSP'''. There are two additional language layers: '''Modular SNUSP''' adds '@', and '#' for call and return from subroutine. '''Bloated SNUSP''' adds '&' for thread-split, a two-dimensional memory space (':' and ';'), and random numbers ('%'). + +==See also== +* [[eso:SNUSP|Esolangs]] +* http://c2.com/cgi/wiki?SnuspLanguage +* http://www.quirkster.com/iano/snusp/ + +[[Category:Esoteric Languages]] \ No newline at end of file diff --git a/Lang/SNUSP/99_Bottles_of_Beer b/Lang/SNUSP/99_Bottles_of_Beer new file mode 120000 index 0000000000..6f98773fc9 --- /dev/null +++ b/Lang/SNUSP/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/SNUSP \ No newline at end of file diff --git a/Lang/SNUSP/FizzBuzz b/Lang/SNUSP/FizzBuzz new file mode 120000 index 0000000000..fd33a28a02 --- /dev/null +++ b/Lang/SNUSP/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/SNUSP \ No newline at end of file diff --git a/Lang/Scala/0DESCRIPTION b/Lang/Scala/0DESCRIPTION new file mode 100644 index 0000000000..e26d614ed1 --- /dev/null +++ b/Lang/Scala/0DESCRIPTION @@ -0,0 +1,12 @@ +{{language| +|strength=strong +|express=partially implicit +|checking=static +|gc=yes +|site=http://scala-lang.org +|tags=scala +|LCT=yes +|bnf=http://www.scala-lang.org/docu/files/ScalaReference.pdf}} +{{language programming paradigm|functional}} +{{language programming paradigm|object-oriented}} +{{language programming paradigm|generic}}Scala is a hybrid [[functional programming|Functional]]/[[object-oriented|OO]] language developed by Martin Odersky and his team at [http://lamp.epfl.ch/ LAMP]. Scala compiles to [[runs on vm::Java Virtual Machine|JVM]] [[bytecode]], and can interoperate with [[Java]] code. \ No newline at end of file diff --git a/Lang/Scala/Anagrams b/Lang/Scala/Anagrams new file mode 120000 index 0000000000..5cc1c26b2b --- /dev/null +++ b/Lang/Scala/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/Scala \ No newline at end of file diff --git a/Lang/Scala/Bulls_and_cows b/Lang/Scala/Bulls_and_cows new file mode 120000 index 0000000000..d6d452cec7 --- /dev/null +++ b/Lang/Scala/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/Scala \ No newline at end of file diff --git a/Lang/Scala/Comments b/Lang/Scala/Comments new file mode 120000 index 0000000000..11afb54c82 --- /dev/null +++ b/Lang/Scala/Comments @@ -0,0 +1 @@ +../../Task/Comments/Scala \ No newline at end of file diff --git a/Lang/Scala/Entropy b/Lang/Scala/Entropy new file mode 120000 index 0000000000..deefa6217e --- /dev/null +++ b/Lang/Scala/Entropy @@ -0,0 +1 @@ +../../Task/Entropy/Scala \ No newline at end of file diff --git a/Lang/Scala/FizzBuzz b/Lang/Scala/FizzBuzz new file mode 120000 index 0000000000..98f059ebc9 --- /dev/null +++ b/Lang/Scala/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Scala \ No newline at end of file diff --git a/Lang/Scala/Infinity b/Lang/Scala/Infinity new file mode 120000 index 0000000000..c60570dd64 --- /dev/null +++ b/Lang/Scala/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/Scala \ No newline at end of file diff --git a/Lang/Scala/JSON b/Lang/Scala/JSON new file mode 120000 index 0000000000..adcdd7e740 --- /dev/null +++ b/Lang/Scala/JSON @@ -0,0 +1 @@ +../../Task/JSON/Scala \ No newline at end of file diff --git a/Lang/Scala/Knuth_shuffle b/Lang/Scala/Knuth_shuffle new file mode 120000 index 0000000000..94ff758356 --- /dev/null +++ b/Lang/Scala/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/Scala \ No newline at end of file diff --git a/Lang/Scala/Pi b/Lang/Scala/Pi new file mode 120000 index 0000000000..dc56fff53a --- /dev/null +++ b/Lang/Scala/Pi @@ -0,0 +1 @@ +../../Task/Pi/Scala \ No newline at end of file diff --git a/Lang/Scala/Quine b/Lang/Scala/Quine new file mode 120000 index 0000000000..2aaf0209b6 --- /dev/null +++ b/Lang/Scala/Quine @@ -0,0 +1 @@ +../../Task/Quine/Scala \ No newline at end of file diff --git a/Lang/Scala/Search_a_list b/Lang/Scala/Search_a_list new file mode 120000 index 0000000000..f95d044bcd --- /dev/null +++ b/Lang/Scala/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/Scala \ No newline at end of file diff --git a/Lang/Tcl/0DESCRIPTION b/Lang/Tcl/0DESCRIPTION new file mode 100644 index 0000000000..cb57f02c29 --- /dev/null +++ b/Lang/Tcl/0DESCRIPTION @@ -0,0 +1,140 @@ +{{language|Tcl +|site=http://www.tcl.tk/ +|exec=bytecode +|express=implicit +|compat=duck +|checking=dynamic +|parampass=value +|safety=safe +|strength=weak +|gc=yes +|tags=tcl +|LCT=yes +|bnf=http://rosettacode.org/wiki/Category:Tcl#Grammar}} +{{language programming paradigm|Concurrent}} +{{language programming paradigm|Dynamic}} +{{language programming paradigm|Event-driven}} +{{language programming paradigm|Imperative}} +{{language programming paradigm|Object-oriented}} +{{language programming paradigm|Procedural}} +{{language programming paradigm|Reflective}} +{{Codepad}} + +'''Tcl''' (short for '''T'''ool '''C'''ommand '''L'''anguage) is a scripting language with very simple syntax, dynamic typing, automatic storage allocation and [[garbage collection]] and native Unicode support. '''Tcl''' is often combined with the [[Tk]] library. As a result, it is often referred to as '''Tcl/Tk'''. + +Tcl is known to be supported under a variety of popular operating systems, including [[UNIX]], [[Linux]], [[BSD]], [[Windows]], [[WinCE]], [[PocketPC]], [[Mac OS X]] and [[BeOS]]. Tcl is distributed under the [[wp:BSD licenses|BSD License]]. + +The Tcl language has been implemented in multiple lower-level languages. The most common one is '''[[libtcl]]''', written in [[C]], which is the engine used to power [[tclsh]] and [[wish]], but others exist. Notably, these include [[Jacl]] and [[Eagle]], which implement Tcl in [[Java]] and [[C sharp|C#]] respectively. + +Its creator, John Ousterhout, wrote about it: +:''“I got the idea for Tcl while on sabbatical leave at DEC's Western Research Laboratory in the fall of 1987. I started actually implementing it when I got back to Berkeley in the spring of 1988; by summer of that year it was in use in some internal applications of ours, but there was no Tk. The first external releases of Tcl were in 1989, I believe. I started implementing Tk in 1989, and the first release of Tk was in 1991.”'' + +The principal pre-built distributions of Tcl are all based on [[libtcl]]; the main ones are [[ActiveTcl]] from ActiveState, and [[tclkit]] from Equi4 Software ''et al''. Older versions of the language are distributed as part of Apple's OSX and all Linux distributions. + +==Language Syntax== +===Grammar=== +Note that this is a simplified language grammar, and it is normal to think of the language at a higher level where these differences don't show. +
+ script '''::=''' command'''? ((''' “''\n''” '''|''' “'';''” ''')''' script ''')''' + command '''::=''' “''#''” characters “''\n''” /* comment */ + '''|''' word '''(''' space word ''')*''' /* sequence of space-separated words; + * first is command name */ + '''|''' /* empty */ + word '''::=''' “''{*}''”'''?''' “''{''” characters “''}''” /* braces must be balanced */ + '''|''' “''{*}''”'''?''' “''"''” charSubsts “''"''” /* double-quotes must be balanced */ + '''|''' “''{*}''”'''?''' charSubsts + charSubsts '''::=''' “''[''” script “'']''” charSubsts'''?''' /* brackets must be balanced */ + '''|''' “''$''” varName charSubsts'''?''' + '''|''' “''${''” varName “''}''” charSubsts'''?''' + '''|''' “''\\''” escapeSequence charSubsts''?'' + '''|''' ordinaryChar charSubsts''?'' + +The syntax of the language is defined more exactly in the [http://www.tcl.tk/man/tcl8.5/TclCmd/Tcl.htm Tcl(n)] manual page. +===Conceptual Command Syntax=== +Though formally not part of the language syntax, the syntactic style of the language's standard commands mostly follow a few basic syntactic principles: +* Commands are variadic, and frequently accept arbitrary numbers of arguments. +* Commands that take options will prefix the option name with a single ASCII hyphen, “-”, and if a value parameter to the option is required, that parameter will be in a subsequent argument to the option name. +* Option names are not single character long strings after removing the hyphen (except in rare cases) and getopt-style argument combination is never supported. +* Commands perform callbacks by evaluating a caller-provided Tcl script. +** During-execution callback scripts are evaluated in the context of their caller. +** After-execution callback scripts are evaluated in the global scope. +* Commands cannot discover how their arguments were quoted. +===Key Commands=== +The following commands are simply normal commands, and can be renamed, deleted, traced, etc., just like any other command, but they are also used in virtually all Tcl scripts and so overriding their behavior is typically an indication of code that is likely to fail. (People do that anyway, but they are almost always careful to ensure that the existing semantics of the commands with these names are still supported.) + +'''set''' ''varName'' ?''value''? +:Sets a named variable to a value and returns the current value of the variable. If ''value'' is omitted, reads from the variable. +'''expr''' ''arg''... +:Concatenates the ''arg''uments and evaluates them as an expression. +'''if''' ''expr'' ?'''then'''? ''script'' ?'''elseif''' ''expr'' ?'''then'''? ''script'' ...? ?'''else'''? ?''script''? +:Evaluates expressions in order until one of them yields a true value, and then evaluate the associated script, or evaluate the script from the '''else''' clause otherwise. The '''then''' and '''else''' keyword-arguments are both optional, but it is conventional to always include the '''else''' for readability ('''then''' only tends to be used with multiline conditions). Arbitrarily many '''elseif''' clauses are allowed. +'''switch''' ?''options''? ''value'' ''body''
'''switch''' ?''options''? ''value'' ''val1'' ''script'' ?''val2'' ''script'' ...? +:Finds the first ''val''n that matches ''value'' (the default matching rule is exact equality, this is overrideable using the ''options'') and evaluate its script. The final ''val'' can be '''default''' to supply a catch-all case, and if a ''script'' is a '''-''' then the ''script'' from the following clause is used. If a single ''body'' is supplied, it is interpreted as a list of clauses. +'''while''' ''expr script'' +:While the expression evaluates to true, evaluate the ''script''. +'''for''' ''init expr incr script'' +:Evaluate the ''init'' script, and then while the expression evaluates to true, evaluate the ''script'', evaluating the ''incr'' script after each iteration. This is very similar to [[C]]'s for keyword. +'''foreach''' ''varName list script''
+'''foreach''' ''varNameList list'' ?''varNameList list'' ...? ''script'' +:Evaluate the ''script'' for each value in ''list'', setting ''varName'' to that value. In the more general case, there is more than one ''list'' and there are multiple variable names per list allowing striding. +'''break''' +:Make the current loop finish executing early. +'''continue''' +:Make the next iteration of the current loop start early. +'''error''' ''message'' ... +:Generate an error exception. The additional optional arguments allow finer control over the exception. +'''eval''' ''arg''... +:Concatenate the arguments and evaluate the resulting string as a script. Note that from Tcl 8.5 onwards, this should only be used very rarely; the expansion syntax covers the vast majority of previous uses for '''eval'''. +'''list''' ''arg''... +:Create a list out of the arguments and return it. The resulting list is also guaranteed to be a well-formed script that will evaluate the sequence of arguments as a command and arguments without further substitution, making the '''list''' command useful for predictable code synthesis. +'''proc''' ''name formalArgs body'' +:Define a new command called ''name'' that pushes a new stack frame, accepts arguments and binds them to the list of local variable names given in ''formalArgs'' and then evaluates ''body''. +'''return''' ?''options''? ?''value''? +:Return from the current stack frame with the given ''value'' (or the empty string if that's omitted). The ''options'' allow for greater control of the underlying exception semantics used. +'''catch''' ''body'' ?''varName''? ?''optVarName''? +:Evaluate the ''body'' script, and return the exception status produced (e.g., 0 for no exception). If ''varName'' is given, the result or error message is stored in it. If ''optVarName'' is present (from Tcl 8.5 onwards) then a dictionary characterizing the exception status is stored in it. +'''upvar''' ?''level''? ''otherVarName localVarName'' ?''otherVarName localVarName'' ...? +:Bind each of the ''otherVarName'' variables (as looked up at stack level ''level'', or the parent stack frame of the current procedure if that is omitted) to the corresponding ''localVarName''. Following this, the two refer to the same variable until the termination of the current stack frame. +'''uplevel''' ?''level''? ''arg''... +:Concatenate the arguments and evaluate them as a script in the stack frame given by ''level'' (or the stack frame that called the current procedure if that is omitted). Due to syntactic ambiguities, it is recommended that the ''level'' always be specified explicitly. +==== From Tcl 8.5 ==== +'''apply''' ''lambdaTerm arg…'' +:Applies a lambda term to zero or more arguments. Lambda terms are two- or three-element tuples, the first element being the formal parameter description, the second being the script that implements the lambda (just as with '''proc''') and the optional third being the context namespace (with the default being the global namespace). +'''dict''' ''subcommand'' … +:Manipulates dictionaries, values that describe a (sparse) mapping from arbitrary keys to arbitrary values (well, so long as both are themselves values). +==== From Tcl 8.6 ==== +'''coroutine''' ''name command arg…'' +:Create a coroutine called ''name'', which is implemented by the execution of ''command'' together with any supplied arguments. The ''name'' is the name of a command that will be used to resume the coroutine. +'''yield''' ?''value''? +:Yield from a coroutine, with optional value (empty if not supplied). Result will be the optional resumption argument to the coroutine's command. +'''tailcall''' ''command arg…'' +:Stops the execution of the current context and replaces it with a call to the given ''command'' with any arguments. +'''oo::class create''' ''name body'' +:Creates a class called ''name'' with definition ''body''. Instances of ''name'' are created with “''name'' '''new''' ''arg…''” and “''name'' '''create''' ''instanceName arg…''”. (Note that the syntax for '''oo::class''' is a consequence of this.) + +==Language Semantics== +===Value Model=== +Tcl's value model operates on two levels. +* Classically, it is defined purely on unmodifiable strings over a language of unencoded [[UNICODE]] characters. +* Practically, values are polymorphic and hold a cache of the last type-interpretation that they were used with, together with an optional [[UTF-8]] string representation. They are reference-counted and are not modifiable (unless the code in question holds the only reference, which is a significant efficiency gain; if the value is shared, it is shallow-copied upon modification). Although only reference-counted, they are effectively garbage-collected since circular data structures cannot be constructed (performing such construction requires holding two references to the same object, which forces a copy to be taken and breaks the reference loop). The net effect of this is just like the UNICODE string classical model, except much faster. +The language supports the following basic types, together with many defined by extension packages: +* Unicode strings +* Binary strings +* Integers of unbounded width +* Double-precision [[IEEE]] floats +* Booleans +* Lists of values +* Dictionaries mapping values to values +* Assorted "cache" types used to boost performance: +** Command handles (several types) +** Variable handles (several types) +** Compiled regular expressions +** Compiled scripts (several types) +** etc. +Note that all variables can hold values of ''any'' type; the language does not impose type constraints on variables at all. However, it is possible to use variable traces to enforce a type constraint if so desired. + +==External Links== +*[http://www.tcl.tk/man/ Tcl Documentation] +*[http://wiki.tcl.tk Tcl Wiki] +*[http://en.wikipedia.org/wiki/Tcl Wikipedia article] +*[http://en.wikibooks.org/wiki/Programming:Tcl Wikibook] \ No newline at end of file diff --git a/Lang/Tcl/99_Bottles_of_Beer b/Lang/Tcl/99_Bottles_of_Beer new file mode 120000 index 0000000000..e81bdc60e9 --- /dev/null +++ b/Lang/Tcl/99_Bottles_of_Beer @@ -0,0 +1 @@ +../../Task/99_Bottles_of_Beer/Tcl \ No newline at end of file diff --git a/Lang/Tcl/Anagrams b/Lang/Tcl/Anagrams new file mode 120000 index 0000000000..0eceb25e30 --- /dev/null +++ b/Lang/Tcl/Anagrams @@ -0,0 +1 @@ +../../Task/Anagrams/Tcl \ No newline at end of file diff --git a/Lang/Tcl/Bulls_and_cows b/Lang/Tcl/Bulls_and_cows new file mode 120000 index 0000000000..0b8ebcf862 --- /dev/null +++ b/Lang/Tcl/Bulls_and_cows @@ -0,0 +1 @@ +../../Task/Bulls_and_cows/Tcl \ No newline at end of file diff --git a/Lang/Tcl/Comments b/Lang/Tcl/Comments new file mode 120000 index 0000000000..5f7a40b760 --- /dev/null +++ b/Lang/Tcl/Comments @@ -0,0 +1 @@ +../../Task/Comments/Tcl \ No newline at end of file diff --git a/Lang/Tcl/Death_Star b/Lang/Tcl/Death_Star new file mode 120000 index 0000000000..6911869649 --- /dev/null +++ b/Lang/Tcl/Death_Star @@ -0,0 +1 @@ +../../Task/Death_Star/Tcl \ No newline at end of file diff --git a/Lang/Tcl/Entropy b/Lang/Tcl/Entropy new file mode 120000 index 0000000000..6cc0fdf7c8 --- /dev/null +++ b/Lang/Tcl/Entropy @@ -0,0 +1 @@ +../../Task/Entropy/Tcl \ No newline at end of file diff --git a/Lang/Tcl/FizzBuzz b/Lang/Tcl/FizzBuzz new file mode 120000 index 0000000000..aa47bae607 --- /dev/null +++ b/Lang/Tcl/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Tcl \ No newline at end of file diff --git a/Lang/Tcl/Infinity b/Lang/Tcl/Infinity new file mode 120000 index 0000000000..a0dd54e8fe --- /dev/null +++ b/Lang/Tcl/Infinity @@ -0,0 +1 @@ +../../Task/Infinity/Tcl \ No newline at end of file diff --git a/Lang/Tcl/JSON b/Lang/Tcl/JSON new file mode 120000 index 0000000000..dd2db824ee --- /dev/null +++ b/Lang/Tcl/JSON @@ -0,0 +1 @@ +../../Task/JSON/Tcl \ No newline at end of file diff --git a/Lang/Tcl/Knuth_shuffle b/Lang/Tcl/Knuth_shuffle new file mode 120000 index 0000000000..0fa6364cda --- /dev/null +++ b/Lang/Tcl/Knuth_shuffle @@ -0,0 +1 @@ +../../Task/Knuth_shuffle/Tcl \ No newline at end of file diff --git a/Lang/Tcl/Narcissist b/Lang/Tcl/Narcissist new file mode 120000 index 0000000000..9787378eae --- /dev/null +++ b/Lang/Tcl/Narcissist @@ -0,0 +1 @@ +../../Task/Narcissist/Tcl \ No newline at end of file diff --git a/Lang/Tcl/Ordered_words b/Lang/Tcl/Ordered_words new file mode 120000 index 0000000000..8b69b4a0b1 --- /dev/null +++ b/Lang/Tcl/Ordered_words @@ -0,0 +1 @@ +../../Task/Ordered_words/Tcl \ No newline at end of file diff --git a/Lang/Tcl/Pi b/Lang/Tcl/Pi new file mode 120000 index 0000000000..c9cde81d74 --- /dev/null +++ b/Lang/Tcl/Pi @@ -0,0 +1 @@ +../../Task/Pi/Tcl \ No newline at end of file diff --git a/Lang/Tcl/Quine b/Lang/Tcl/Quine new file mode 120000 index 0000000000..1d3ee88e51 --- /dev/null +++ b/Lang/Tcl/Quine @@ -0,0 +1 @@ +../../Task/Quine/Tcl \ No newline at end of file diff --git a/Lang/Tcl/Search_a_list b/Lang/Tcl/Search_a_list new file mode 120000 index 0000000000..c388106156 --- /dev/null +++ b/Lang/Tcl/Search_a_list @@ -0,0 +1 @@ +../../Task/Search_a_list/Tcl \ No newline at end of file diff --git a/Lang/Turing/0DESCRIPTION b/Lang/Turing/0DESCRIPTION new file mode 100644 index 0000000000..209f11644e --- /dev/null +++ b/Lang/Turing/0DESCRIPTION @@ -0,0 +1,7 @@ +{{language +|checking=static +|express=explicit}} +{{language programming paradigm|object-oriented}} +From the [[wp:Turing_(programming_language)|Wikipedia page]]: + +:Turing is a [[Pascal]]-like programming language developed in 1982 by Ric Holt and James Cordy, then of University of Toronto, Canada. Turing is a descendant of Euclid, Pascal and SP/k that features a clean syntax and precise machine-independent semantics. \ No newline at end of file diff --git a/Lang/Turing/FizzBuzz b/Lang/Turing/FizzBuzz new file mode 120000 index 0000000000..572bc03c6e --- /dev/null +++ b/Lang/Turing/FizzBuzz @@ -0,0 +1 @@ +../../Task/FizzBuzz/Turing \ No newline at end of file diff --git a/Meta/SNUSP.yaml b/Meta/SNUSP.yaml new file mode 100644 index 0000000000..4139a4ef80 --- /dev/null +++ b/Meta/SNUSP.yaml @@ -0,0 +1,3 @@ +--- +runtime: + cpan: Language::SNUSP diff --git a/README.md b/README.md new file mode 100644 index 0000000000..78097d43c7 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +## RosettaCode GitHub Mirror + +This Git Repository will eventually be a mirror of all the code samples +available on http://rosettacode.org, along with instructions and supplemental +tools to help get them running on your local machine. + +## Goals + +The primary goal here is to get the codes into the most easily usable format, +so that more programmers are exposed to them and actually run them. + +* Extract all (or most) of the code samples from RosettaCode. +* Give proper reference to their sources and authors. +* Provide automation for installing languages on common OSes. +* Provide automation for running the code samples. (Testing) + +If the primary goals are successful, consider pushing code back to the wiki +from the Git repository. This could make it easier for people to contribute +content via Pull Requests and such. + +## Implementation + +The mirroring of RosettaCode.org is being perform by a program whose repository +is here: + + https://github.com/ingydotnet/rosettacode-pm + http://search.cpan.org/dist/RosettaCode + +The tool accesses the RosettaCode wiki via the MediaWiki REST API, using the +CPAN module: MediaWiki::Bot. + +## About the Author and Project + +Ingy döt Net is an Acmeist (http://acmeism.org) hacker who likes programming +his ideas equivalently in multiple Open Source languages. His works are +available at https://github.com/ingydotnet/. + +Ingy has been communicating with Mike Mol, the proprietor of RosettaCode, +regarding this mirroring attempt. diff --git a/Task/99_Bottles_of_Beer/0DESCRIPTION b/Task/99_Bottles_of_Beer/0DESCRIPTION new file mode 100644 index 0000000000..a30be4d290 --- /dev/null +++ b/Task/99_Bottles_of_Beer/0DESCRIPTION @@ -0,0 +1,13 @@ +In this puzzle, write code to print out the entire "99 bottles of beer on the wall" song. For those who do not know the song, the lyrics follow this form: + X bottles of beer on the wall + X bottles of beer + Take one down, pass it around + X-1 bottles of beer on the wall + + X-1 bottles of beer on the wall + ... + Take one down, pass it around + 0 bottles of beer on the wall +Where X and X-1 are replaced by numbers of course. Grammatical support for "1 bottle of beer" is optional. As with any puzzle, try to do it in as creative/concise/comical a way as possible (simple, obvious solutions allowed, too). + +See also: http://99-bottles-of-beer.net/ diff --git a/Task/99_Bottles_of_Beer/AWK/99_bottles_of_beer.awk b/Task/99_Bottles_of_Beer/AWK/99_bottles_of_beer.awk new file mode 100644 index 0000000000..07b781bb05 --- /dev/null +++ b/Task/99_Bottles_of_Beer/AWK/99_bottles_of_beer.awk @@ -0,0 +1,7 @@ +{ i = 99 +while (i > 0) + {print i, " bottles of beer on the wall," + print i, " bottles of beer." + print "Take one down, pass it around," + i-- + print i, " bottles of beer on the wall\n"}} diff --git a/Task/99_Bottles_of_Beer/BASIC/99_bottles_of_beer-2.bas b/Task/99_Bottles_of_Beer/BASIC/99_bottles_of_beer-2.bas new file mode 100644 index 0000000000..3dd875c8d6 --- /dev/null +++ b/Task/99_Bottles_of_Beer/BASIC/99_bottles_of_beer-2.bas @@ -0,0 +1,7 @@ +FOR x = 99 TO 1 STEP -1 + PRINT x; "bottles of beer on the wall" + PRINT x; "bottles of beer" + PRINT "Take one down, pass it around" + PRINT x-1; "bottles of beer on the wall" + PRINT +NEXT x diff --git a/Task/99_Bottles_of_Beer/BASIC/99_bottles_of_beer.bas b/Task/99_Bottles_of_Beer/BASIC/99_bottles_of_beer.bas new file mode 100644 index 0000000000..cefa889e54 --- /dev/null +++ b/Task/99_Bottles_of_Beer/BASIC/99_bottles_of_beer.bas @@ -0,0 +1,12 @@ +PLAY "<" +FOR x = 99 TO 0 STEP -1 + PRINT x; "bottles of beer on the wall" + PRINT x; "bottles of beer" + PRINT "Take one down, pass it around" + PRINT x-1; "bottles of beer on the wall" + PRINT + PLAY "e-8e-8e-8e-8e-8e-8e-4"'X bottles of beer on the wall + PLAY "f8f8f8c8c8c8f4"'X bottles of beer + PLAY "d4d8d8 N0 d8d8d8d4"'take one down, pass it around + PLAY "c8c8d8d+8d+8d+8d+4"'X-1 bottles of beer on the wall +NEXT x diff --git a/Task/99_Bottles_of_Beer/Befunge/99_bottles_of_beer.bf b/Task/99_Bottles_of_Beer/Befunge/99_bottles_of_beer.bf new file mode 100644 index 0000000000..9366f05bfa --- /dev/null +++ b/Task/99_Bottles_of_Beer/Befunge/99_bottles_of_beer.bf @@ -0,0 +1,11 @@ +:,| + :,| + :,| + >01g1-:01p v +v <.g10" bottles of beer on the wall"+*4310< +>:,| + >134*+0` | + @ diff --git a/Task/99_Bottles_of_Beer/C/99_bottles_of_beer-2.c b/Task/99_Bottles_of_Beer/C/99_bottles_of_beer-2.c new file mode 100644 index 0000000000..7cd63889af --- /dev/null +++ b/Task/99_Bottles_of_Beer/C/99_bottles_of_beer-2.c @@ -0,0 +1,5 @@ +#include +main(){_=100;while(--_)printf("%i bottle%s of beer in the wall,\n%i bottle%" +"s of beer.\nTake one down, pass it round,\n%s%s\n\n",_,_-1?"s":"",_,_-1?"s" +:"",_-1?(char[]){(_-1)/10?(_-1)/10+48:(_-1)%10+48,(_-1)/10?(_-1)%10+48:2+30, +(_-1)/10?32:0,0}:"",_-1?"bottles of beer in the wall":"No more beers");} diff --git a/Task/99_Bottles_of_Beer/C/99_bottles_of_beer-3.c b/Task/99_Bottles_of_Beer/C/99_bottles_of_beer-3.c new file mode 100644 index 0000000000..d484ea9641 --- /dev/null +++ b/Task/99_Bottles_of_Beer/C/99_bottles_of_beer-3.c @@ -0,0 +1,30 @@ +#include +#include + +#define BOTTLE(nstr) nstr " bottles of beer" + +#define WALL(nstr) BOTTLE(nstr) " on the wall" + +#define PART1(nstr) WALL(nstr) "\n" BOTTLE(nstr) \ + "\nTake one down, pass it around\n" + +#define PART2(nstr) WALL(nstr) "\n\n" + +#define MIDDLE(nstr) PART2(nstr) PART1(nstr) + +#define SONG PART1("100") CD2 PART2("0") + +#define CD2 CD3("9") CD3("8") CD3("7") CD3("6") CD3("5") \ + CD3("4") CD3("3") CD3("2") CD3("1") CD4("") + +#define CD3(pre) CD4(pre) MIDDLE(pre "0") + +#define CD4(pre) MIDDLE(pre "9") MIDDLE(pre "8") MIDDLE(pre "7") \ + MIDDLE(pre "6") MIDDLE(pre "5") MIDDLE(pre "4") MIDDLE(pre "3") \ + MIDDLE(pre "2") MIDDLE(pre "1") + +int main(void) +{ + (void) printf(SONG); + return EXIT_SUCCESS; +} diff --git a/Task/99_Bottles_of_Beer/C/99_bottles_of_beer-4.c b/Task/99_Bottles_of_Beer/C/99_bottles_of_beer-4.c new file mode 100644 index 0000000000..f4bde51887 --- /dev/null +++ b/Task/99_Bottles_of_Beer/C/99_bottles_of_beer-4.c @@ -0,0 +1,35 @@ + int b =99,u =1; + #include + char *d[16],y[] + = "#:ottle/ of" + ":eer_ a_Goy\x20some6" + "_Take8;down4p" + "a=1rou7_17 _<" + "h;_ m?_nd_ on" + "_085wal" "l_ " + "b_e _ t_ss it" + "_?4bu_ore_9, " + "\060.""@, 9$"; + # define x c ^= + #include + #define or(t,z) else\ + if(c==t && !(c = 0) &&\ + (c =! z)); int p(char *t) +{ char *s = t; int c; for ( +d[c = 0] = y; !t && (d[c +1 +]= strchr(s = d[c], '_'));* +(d[++c]++) = 0); for(t = s? +s:t;(c= *s++); c && putchar +(c)) { if (!((( x 48)& ~0xf +) && ( x 48)) ) p(d[c]), c= +0 ; or('$', p(b - 99?".\n": +"." ) && p(b - 99? t : "")) +or ('\x40', c && p( d[!!b-- ++ 2])) or('/', c && p( b^1? +"s": "")) or ('\043', b++ ? +p("So6" + --b):!printf("%d" +, b ? --b : (b += 99))) or( +'S',!(++u % 3) * 32+ 78) or +('.', puts("."))}return c;} + int main() {return p(0);} diff --git a/Task/99_Bottles_of_Beer/C/99_bottles_of_beer.c b/Task/99_Bottles_of_Beer/C/99_bottles_of_beer.c new file mode 100644 index 0000000000..40042b3568 --- /dev/null +++ b/Task/99_Bottles_of_Beer/C/99_bottles_of_beer.c @@ -0,0 +1,15 @@ +#include +#include + +int main(void) +{ + unsigned int bottles = 99; + do + { + printf("%u bottles of beer on the wall\n", bottles); + printf("%u bottles of beer\n", bottles); + printf("Take one down, pass it around\n"); + printf("%u bottles of beer on the wall\n\n", --bottles); + } while(bottles > 0); + return EXIT_SUCCESS; +} diff --git a/Task/99_Bottles_of_Beer/Clojure/99_bottles_of_beer.clj b/Task/99_Bottles_of_Beer/Clojure/99_bottles_of_beer.clj new file mode 100644 index 0000000000..15d05694a8 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Clojure/99_bottles_of_beer.clj @@ -0,0 +1,14 @@ +(defn verse + [n] + (printf "%d bottles of beer on the wall, +%d bottles of beer, +Take one down, pass it around, +%d bottles of beer on the wall.\n\n" + n + n + (dec n))) + +(defn sing + [start] + (doseq [n (range start 0 -1)] + (verse n))) diff --git a/Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer-2.coffee b/Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer-2.coffee new file mode 100644 index 0000000000..5d1cb3a77b --- /dev/null +++ b/Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer-2.coffee @@ -0,0 +1,4 @@ +for j in [99..1] + x='' + x += [j,j-1,'\nTake one down, pass it around\n'," bottles of beer",' on the wall\n'][i] for i in [0,3,4,0,3,2,1,3,4] + console.log x.replace /(1.+)s/g, '$1' diff --git a/Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer-3.coffee b/Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer-3.coffee new file mode 100644 index 0000000000..e6f32d0481 --- /dev/null +++ b/Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer-3.coffee @@ -0,0 +1 @@ +console.log( if (j+2)%4 then (x=Math.round j/4)+" bottle#{if x-1 then 's' else ''} of beer#{if (j+1)%4 then ' on the wall' else ''}" else "Take one down, pass it around" ) for j in [396..1] diff --git a/Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer-4.coffee b/Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer-4.coffee new file mode 100644 index 0000000000..0fbf558351 --- /dev/null +++ b/Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer-4.coffee @@ -0,0 +1 @@ +((console.log if i is 2 then "Take one down, pass it around" else "#{b-!(i-1%4)} bottle#{if 4*b+i<10 and b-i then '' else 's'} of beer#{if i%3 then ' on the wall' else ''}") for i in [4..1]) for b in [99..1] diff --git a/Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer.coffee b/Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer.coffee new file mode 100644 index 0000000000..d1b09dc2e9 --- /dev/null +++ b/Task/99_Bottles_of_Beer/CoffeeScript/99_bottles_of_beer.coffee @@ -0,0 +1,9 @@ +bottlesOfBeer = (n) -> + "#{n} bottle#{if n is 1 then '' else 's'} of beer" + +console.log """ + #{bottlesOfBeer n} on the wall + #{bottlesOfBeer n} + Take one down, pass it around + #{bottlesOfBeer n - 1} on the wall + \n""" for n in [99..1] diff --git a/Task/99_Bottles_of_Beer/Erlang/99_bottles_of_beer.erl b/Task/99_Bottles_of_Beer/Erlang/99_bottles_of_beer.erl new file mode 100644 index 0000000000..3331149e18 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Erlang/99_bottles_of_beer.erl @@ -0,0 +1,39 @@ +-module(beersong). +-export([sing/0]). +-define(TEMPLATE_0, "~s of beer on the wall, ~s of beer.~nGo to the store and buy some more, 99 +bottles of beer on the wall.~n"). +-define(TEMPLATE_N, "~s of beer on the wall, ~s of beer.~nTake one down and pass it around, ~s of +beer on the wall.~n~n"). + +create_verse(0) -> {0, io_lib:format(?TEMPLATE_0, phrase(0))}; +create_verse(Bottle) -> {Bottle, io_lib:format(?TEMPLATE_N, phrase(Bottle))}. + +phrase(0) -> ["No more bottles", "no more bottles"]; +phrase(1) -> ["1 bottle", "1 bottle", "no more bottles"]; +phrase(2) -> ["2 bottles", "2 bottles", "1 bottle"]; +phrase(Bottle) -> lists:duplicate(2, integer_to_list(Bottle) ++ " bottles") ++ +[integer_to_list(Bottle-1) ++ " bottles"]. + +bottles() -> lists:reverse(lists:seq(0,99)). + +sing() -> + lists:foreach(fun spawn_singer/1, bottles()), + sing_verse(99). + +spawn_singer(Bottle) -> + Pid = self(), + spawn(fun() -> Pid ! create_verse(Bottle) end). + +sing_verse(Bottle) -> + receive + {_, Verse} when Bottle == 0 -> + io:format(Verse); + {N, Verse} when Bottle == N -> + io:format(Verse), + sing_verse(Bottle-1) + after + 3000 -> + io:format("Verse not received - re-starting singer~n"), + spawn_singer(Bottle), + sing_verse(Bottle) + end. diff --git a/Task/99_Bottles_of_Beer/Forth/99_bottles_of_beer.fth b/Task/99_Bottles_of_Beer/Forth/99_bottles_of_beer.fth new file mode 100644 index 0000000000..be6b3cc20f --- /dev/null +++ b/Task/99_Bottles_of_Beer/Forth/99_bottles_of_beer.fth @@ -0,0 +1,14 @@ +:noname dup . ." bottles" ; +:noname ." 1 bottle" ; +:noname ." no more bottles" ; +create bottles , , , + +: .bottles dup 2 min cells bottles + @ execute ; +: .beer .bottles ." of beer" ; +: .wall .beer ." on the wall" ; +: .take ." Take one down, pass it around" ; +: .verse .wall cr .beer cr + 1- .take cr .wall cr ; +: verses begin cr .verse ?dup 0= until ; + +99 verses diff --git a/Task/99_Bottles_of_Beer/Fortran/99_bottles_of_beer.f b/Task/99_Bottles_of_Beer/Fortran/99_bottles_of_beer.f new file mode 100644 index 0000000000..69ad0d2a9c --- /dev/null +++ b/Task/99_Bottles_of_Beer/Fortran/99_bottles_of_beer.f @@ -0,0 +1,24 @@ +program bottlestest + + implicit none + + integer :: i + + character(len=*), parameter :: bwall = " on the wall", & + bottles = "bottles of beer", & + bottle = "bottle of beer", & + take = "Take one down, pass it around", & + form = "(I0, ' ', A)" + + do i = 99,0,-1 + if ( i /= 1 ) then + write (*,form) i, bottles // bwall + if ( i > 0 ) write (*,form) i, bottles + else + write (*,form) i, bottle // bwall + write (*,form) i, bottle + end if + if ( i > 0 ) write (*,*) take + end do + +end program bottlestest diff --git a/Task/99_Bottles_of_Beer/Go/99_bottles_of_beer.go b/Task/99_Bottles_of_Beer/Go/99_bottles_of_beer.go new file mode 100644 index 0000000000..ac31ac13b1 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Go/99_bottles_of_beer.go @@ -0,0 +1,18 @@ +package main + +import "fmt" + +func main() { + cardinality := func (i int) string { + if i!=1 { + return "s" + } + return "" + } + for i := 99; i > 0; i-- { + fmt.Printf("%d bottle%s of beer on the wall\n", i, cardinality(i)) + fmt.Printf("%d bottle%s of beer\n", i, cardinality(i)) + fmt.Printf("Take one down, pass it around\n") + fmt.Printf("%d bottle%s of beer on the wall\n", i-1, cardinality(i-1)) + } +} diff --git a/Task/99_Bottles_of_Beer/Haskell/99_bottles_of_beer-2.hs b/Task/99_Bottles_of_Beer/Haskell/99_bottles_of_beer-2.hs new file mode 100644 index 0000000000..b72cbda87c --- /dev/null +++ b/Task/99_Bottles_of_Beer/Haskell/99_bottles_of_beer-2.hs @@ -0,0 +1,16 @@ +import qualified Char + +main = putStr $ concat + [up (bob n) ++ wall ++ ", " ++ bob n ++ ".\n" ++ + pass n ++ bob (n - 1) ++ wall ++ ".\n\n" | + n <- [99, 98 .. 0]] + where bob n = (num n) ++ " bottle" ++ (s n) ++ " of beer" + wall = " on the wall" + pass 0 = "Go to the store and buy some more, " + pass _ = "Take one down and pass it around, " + up (x : xs) = Char.toUpper x : xs + num (-1) = "99" + num 0 = "no more" + num n = show n + s 1 = "" + s _ = "s" diff --git a/Task/99_Bottles_of_Beer/Haskell/99_bottles_of_beer-3.hs b/Task/99_Bottles_of_Beer/Haskell/99_bottles_of_beer-3.hs new file mode 100644 index 0000000000..af6eb0ed23 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Haskell/99_bottles_of_beer-3.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE TemplateHaskell #-} +-- build with "ghc --make beer.hs" +module Main where +import Language.Haskell.TH +import Control.Monad.Writer + +-- This is calculated at compile time, and is equivalent to +-- songString = "99 bottles of beer on the wall\n99 bottles..." +songString = + $(let + sing = tell -- we can't sing very well... + + someBottles 1 = "1 bottle of beer " + someBottles n = show n ++ " bottles of beer " + + bottlesOfBeer n = (someBottles n ++) + + verse n = do + sing $ n `bottlesOfBeer` "on the wall\n" + sing $ n `bottlesOfBeer` "\n" + sing $ "Take one down, pass it around\n" + sing $ (n - 1) `bottlesOfBeer` "on the wall\n\n" + + song = execWriter $ mapM_ verse [99,98..1] + + in return $ LitE $ StringL $ song) + +main = putStr songString diff --git a/Task/99_Bottles_of_Beer/Haskell/99_bottles_of_beer.hs b/Task/99_Bottles_of_Beer/Haskell/99_bottles_of_beer.hs new file mode 100644 index 0000000000..b58d89c01e --- /dev/null +++ b/Task/99_Bottles_of_Beer/Haskell/99_bottles_of_beer.hs @@ -0,0 +1,7 @@ +main = mapM_ (putStrLn . beer) [99, 98 .. 0] +beer 1 = "1 bottle of beer on the wall\n1 bottle of beer\nTake one down, pass it around" +beer 0 = "better go to the store and buy some more." +beer v = show v ++ " bottles of beer on the wall\n" + ++ show v + ++" bottles of beer\nTake one down, pass it around\n" + ++ head (lines $ beer $ v-1) ++ "\n" diff --git a/Task/99_Bottles_of_Beer/Java/99_bottles_of_beer-2.java b/Task/99_Bottles_of_Beer/Java/99_bottles_of_beer-2.java new file mode 100644 index 0000000000..b89dcc149f --- /dev/null +++ b/Task/99_Bottles_of_Beer/Java/99_bottles_of_beer-2.java @@ -0,0 +1,16 @@ +public class Beer +{ + public static void main(final String[] args) + { + int beer = 99; + StringBuilder sb = new StringBuilder(); + String data[] = new String[] { " bottles of beer on the wall\n", + " bottles of beer.\nTake one down, pass it around,\n", + "Better go to the store and buy some more." }; + + while (beer > 0) + sb.append(beer).append(data[0]).append(beer).append(data[1]).append(--beer).append(data[0]).append("\n"); + + System.out.println(sb.append(data[2]).toString()); + } +} diff --git a/Task/99_Bottles_of_Beer/Java/99_bottles_of_beer-3.java b/Task/99_Bottles_of_Beer/Java/99_bottles_of_beer-3.java new file mode 100644 index 0000000000..ca5c43b61a --- /dev/null +++ b/Task/99_Bottles_of_Beer/Java/99_bottles_of_beer-3.java @@ -0,0 +1,40 @@ +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JTextArea; +public class Beer extends JFrame implements ActionListener{ + private int x; + private JButton take; + private JTextArea text; + public static void main(String[] args){ + new Beer();//build and show the GUI + } + + public Beer(){ + x= 99; + take= new JButton("Take one down, pass it around"); + text= new JTextArea(4,30);//size the area to 4 lines, 30 chars each + text.setText(x + " bottles of beer on the wall\n" + x + " bottles of beer"); + text.setEditable(false);//so they can't change the text after it's displayed + take.addActionListener(this);//listen to the button + setLayout(new BorderLayout());//handle placement of components + add(text, BorderLayout.CENTER);//put the text area in the largest section + add(take, BorderLayout.SOUTH);//put the button underneath it + pack();//auto-size the window + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//exit on "X" (I hate System.exit...) + setVisible(true);//show it + } + + public void actionPerformed(ActionEvent arg0){ + if(arg0.getSource() == take){//if they clicked the button + JOptionPane.showMessageDialog(null, --x + " bottles of beer on the wall");//show a popup message + text.setText(x + " bottles of beer on the wall\n" + x + " bottles of beer");//change the text + } + if(x == 0){//if it's the end + dispose();//end + } + } +} diff --git a/Task/99_Bottles_of_Beer/Java/99_bottles_of_beer.java b/Task/99_Bottles_of_Beer/Java/99_bottles_of_beer.java new file mode 100644 index 0000000000..805e0b3e6c --- /dev/null +++ b/Task/99_Bottles_of_Beer/Java/99_bottles_of_beer.java @@ -0,0 +1,20 @@ +import java.text.MessageFormat; +public class Beer +{ + static String bottles(final int n) + { + return MessageFormat.format("{0,choice,0#No more bottles|1#One bottle|2#{0} bottles} of beer", n); + } + public static void main(final String[] args) + { + String byob = bottles(99); + for (int x = 99; x > 0;) + { + System.out.println(byob + " on the wall"); + System.out.println(byob); + System.out.println("Take one down, pass it around"); + byob = bottles(--x); + System.out.println(byob + " on the wall\n"); + } + } +} diff --git a/Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer-2.js b/Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer-2.js new file mode 100644 index 0000000000..8c8b4a2fca --- /dev/null +++ b/Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer-2.js @@ -0,0 +1,2 @@ +// Line breaks are in HTML +var beer; while ((beer = typeof beer === "undefined" ? 99 : beer) > 0) document.write( beer + " bottle" + (beer != 1 ? "s" : "") + " of beer on the wall
" + beer + " bottle" + (beer != 1 ? "s" : "") + " of beer
Take one down, pass it around
" + (--beer) + " bottle" + (beer != 1 ? "s" : "") + " of beer on the wall
" ); diff --git a/Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer-3.js b/Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer-3.js new file mode 100644 index 0000000000..9b1ded8bdc --- /dev/null +++ b/Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer-3.js @@ -0,0 +1,21 @@ +// Line breaks are in HTML +function Bottles(count){ + this.count = (!!count)?count:99; + this.knock = function(){ + var c = document.createElement('div'); + c.id="bottle-"+this.count; + c.innerHTML = "

"+this.count+" bottles of beer on the wall

" + +"

"+this.count+" bottles of beer!

" + +"

Take one down,
Pass it around

" + +"

"+(--this.count)+" bottles of beer on the wall


"; + document.body.appendChild(c); + } + this.sing = function(){ + while (this.count>0) { this.knock(); } + } +} + +(function(){ + var bar = new Bottles(99); + bar.sing(); +})(); diff --git a/Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer-4.js b/Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer-4.js new file mode 100644 index 0000000000..036d7f4de0 --- /dev/null +++ b/Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer-4.js @@ -0,0 +1,18 @@ +function bottleSong(n) { + if (!isFinite(Number(n)) || n == 0) n = 100; + var a = '%% bottles of beer', + b = ' on the wall', + c = 'Take one down, pass it around', + r = '
' + p = document.createElement('p'), + s = [], + re = /%%/g; + + while(n) { + s.push((a+b+r+a+r+c+r).replace(re, n) + (a+b).replace(re, --n)); + } + p.innerHTML = s.join(r+r); + document.body.appendChild(p); +} + +window.onload = bottleSong; diff --git a/Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer.js b/Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer.js new file mode 100644 index 0000000000..b877df7843 --- /dev/null +++ b/Task/99_Bottles_of_Beer/JavaScript/99_bottles_of_beer.js @@ -0,0 +1,10 @@ +// Line breaks are in HTML +var beer = 99; +while (beer > 0) +{ + document.write( beer + " bottles of beer on the wall
" ); + document.write( beer + " bottles of beer
" ); + document.write( "Take one down, pass it around
" ); + document.write( (beer - 1) + " bottles of beer on the wall
" ); + beer--; +} diff --git a/Task/99_Bottles_of_Beer/LaTeX/99_bottles_of_beer-2.tex b/Task/99_Bottles_of_Beer/LaTeX/99_bottles_of_beer-2.tex new file mode 100644 index 0000000000..661df6bc25 --- /dev/null +++ b/Task/99_Bottles_of_Beer/LaTeX/99_bottles_of_beer-2.tex @@ -0,0 +1,23 @@ +\documentclass{article} + +\newcounter{beer} +\newcounter{showC} + +\newcommand{\verses}[1]{ + \setcounter{beer}{#1} + \loop + \par\noindent + \Roman{beer} bottles of beer on the wall,\\ + \Roman{beer} bottles of beer!\\ + Take one down, pass it around---\\ + \addtocounter{beer}{-1} +% Romans didn't know how to write zero ;-) + \ifnum\value{beer}=0 ZERO \else\Roman{beer} \fi + bottles of beer on the wall!\\ + \ifnum\value{beer}>0 + \repeat +} + +\begin{document} +\verses{99} +\end{document} diff --git a/Task/99_Bottles_of_Beer/LaTeX/99_bottles_of_beer.tex b/Task/99_Bottles_of_Beer/LaTeX/99_bottles_of_beer.tex new file mode 100644 index 0000000000..edc0aacb18 --- /dev/null +++ b/Task/99_Bottles_of_Beer/LaTeX/99_bottles_of_beer.tex @@ -0,0 +1,20 @@ +\documentclass{article} + +\newcounter{beer} + +\newcommand{\verses}[1]{ + \setcounter{beer}{#1} + \par\noindent + \arabic{beer} bottles of beer on the wall,\\ + \arabic{beer} bottles of beer!\\ + Take one down, pass it around---\\ + \addtocounter{beer}{-1} + \arabic{beer} bottles of beer on the wall!\\ + \ifnum#1>0 + \verses{\value{beer}} + \fi +} + +\begin{document} +\verses{99} +\end{document} diff --git a/Task/99_Bottles_of_Beer/Lua/99_bottles_of_beer.lua b/Task/99_Bottles_of_Beer/Lua/99_bottles_of_beer.lua new file mode 100644 index 0000000000..8c355162de --- /dev/null +++ b/Task/99_Bottles_of_Beer/Lua/99_bottles_of_beer.lua @@ -0,0 +1,11 @@ +local bottles = 99 + +local function plural (bottles) if bottles == 1 then return '' end return 's' end +while bottles > 0 do + print (bottles..' bottle'..plural(bottles)..' of beer on the wall') + print (bottles..' bottle'..plural(bottles)..' of beer') + print ('Take one down, pass it around') + bottles = bottles - 1 + print (bottles..' bottle'..plural(bottles)..' of beer on the wall') + print () +end diff --git a/Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer-2.php b/Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer-2.php new file mode 100644 index 0000000000..ef5231cd9e --- /dev/null +++ b/Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer-2.php @@ -0,0 +1,13 @@ +1)?"s":""; + echo <<< EOV +$i bottle$p of beer on the wall +$i bottle$p of beer +Take one down, pass it around + + +EOV; +} +echo "No more Bottles of beer on the wall"; +?> diff --git a/Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer-3.php b/Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer-3.php new file mode 100644 index 0000000000..07e20f3c46 --- /dev/null +++ b/Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer-3.php @@ -0,0 +1,18 @@ + diff --git a/Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer-4.php b/Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer-4.php new file mode 100644 index 0000000000..2154592a21 --- /dev/null +++ b/Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer-4.php @@ -0,0 +1,7 @@ +0;$i--){ + $p2=$i." bottle".(($i>1)?"s":"")." of beer"; + $p1=$p2." on the wall\n"; + $p3="Take one down, pass it around\n"; + echo (($i<100)?$p1."\n":"").$p1.$p2."\n".$p3.(($i<2)?($i-1).substr($p1,1,28):""); + } diff --git a/Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer.php b/Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer.php new file mode 100644 index 0000000000..4131be3fd0 --- /dev/null +++ b/Task/99_Bottles_of_Beer/PHP/99_bottles_of_beer.php @@ -0,0 +1,15 @@ + 1) + echo ($i - 1) . " bottle$plural of beer on the wall!\n\n"; + else + echo "No more bottles of beer on the wall!\n"; +} +?> diff --git a/Task/99_Bottles_of_Beer/PIR/99_bottles_of_beer.pir b/Task/99_Bottles_of_Beer/PIR/99_bottles_of_beer.pir new file mode 100644 index 0000000000..6d53050492 --- /dev/null +++ b/Task/99_Bottles_of_Beer/PIR/99_bottles_of_beer.pir @@ -0,0 +1,31 @@ +.sub sounding_smart_is_hard_after_drinking_this_many + .param int b + if b == 1 goto ONE + .return(" bottles ") +ONE: + .return(" bottle ") + end +.end + +.sub main :main + .local int bottles + .local string b + bottles = 99 +LUSH: + if bottles == 0 goto DRUNK + b = sounding_smart_is_hard_after_drinking_this_many( bottles ) + print bottles + print b + print "of beer on the wall\n" + print bottles + print b + print "of beer\nTake one down, pass it around\n" + dec bottles + b = sounding_smart_is_hard_after_drinking_this_many( bottles ) + print bottles + print b + print "of beer on the wall\n\n" + goto LUSH +DRUNK: + end +.end diff --git a/Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer-2.pl b/Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer-2.pl new file mode 100644 index 0000000000..2ac7e5045f --- /dev/null +++ b/Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer-2.pl @@ -0,0 +1,6 @@ +for $n (reverse(0..99)) +{ + $bottles = sprintf("%s bottle%s of beer on the wall\n",(($n==0)?"No":$n), (($n==1)?"":"s")); + print( (($n==99)?"":"$bottles\n") . + (($n==0)?"":(substr(${bottles}x2,0,-12) . "\nTake one down, pass it around\n")) ); +} diff --git a/Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer-3.pl b/Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer-3.pl new file mode 100644 index 0000000000..b7e539c8d5 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer-3.pl @@ -0,0 +1,14 @@ +use 5.10.0; + +$num = 99; +while ($num > 0) { + my $s = "s" unless ($num == 1); + say "$num bottle$s of beer on the wall, $num bottle$s of beer"; + $num--; + my $s = "s" unless ($num == 1); + $num = "No more" if ($num == 0); + say "Take one down, pass it around, $num bottle$s of beer on the wall\n" +} + +say "No more bottles of beer on the wall, no more bottles of beer."; +say "Go to the store and buy some more, 99 bottles of beer on the wall."; diff --git a/Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer-4.pl b/Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer-4.pl new file mode 100644 index 0000000000..b0b0f3f214 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer-4.pl @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +sub bottles() { sprintf qq{%s bottle%s of beer} + , $_ || 'No' + , $_==1 ? '' : 's'; + } +sub store() { $_=99; qq{Go to the store, buy some more...\n}; } +sub wall() { qq{ on the wall\n} } +sub take() { $_-- ? qq{Take one down, pass it around\n} : store } +do { print bottles, wall + , bottles, qq{\n} + , take + , bottles, qq{\n\n} + } for reverse 0..99; diff --git a/Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer.pl b/Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer.pl new file mode 100644 index 0000000000..92dcb0f34c --- /dev/null +++ b/Task/99_Bottles_of_Beer/Perl/99_bottles_of_beer.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl -w + +my $verse = <<"VERSE"; +100 bottles of beer on the wall, +100 bottles of beer! +Take one down, pass it around! +99 bottles of beer on the wall! + +VERSE + +{ + $verse =~ s/(\d+)/$1-1/ge; + $verse =~ s/\b1 bottles/1 bottle/g; + my $done = $verse =~ s/\b0 bottle/No bottles/g; # if we make this replacement, we're also done. + + print $verse; + redo unless $done; +} diff --git a/Task/99_Bottles_of_Beer/PicoLisp/99_bottles_of_beer.l b/Task/99_Bottles_of_Beer/PicoLisp/99_bottles_of_beer.l new file mode 100644 index 0000000000..3c1a50cec9 --- /dev/null +++ b/Task/99_Bottles_of_Beer/PicoLisp/99_bottles_of_beer.l @@ -0,0 +1,12 @@ +(de bottles (N) + (case N + (0 "No more beer") + (1 "One bottle of beer") + (T (cons N " bottles of beer")) ) ) + +(for (N 99 (gt0 N)) + (prinl (bottles N) " on the wall,") + (prinl (bottles N) ".") + (prinl "Take one down, pass it around,") + (prinl (bottles (dec 'N)) " on the wall.") + (prinl) ) diff --git a/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-2.py b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-2.py new file mode 100644 index 0000000000..0b8ed8e4c9 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-2.py @@ -0,0 +1,9 @@ +verse = '''\ +%i bottles of beer on the wall +%i bottles of beer +Take one down, pass it around +%i bottles of beer on the wall +''' + +for bottles in range(99,0,-1): + print verse % (bottles, bottles, bottles-1) diff --git a/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-3.py b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-3.py new file mode 100644 index 0000000000..e3844fad8d --- /dev/null +++ b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-3.py @@ -0,0 +1,9 @@ +verse = '''\ +{some} bottles of beer on the wall +{some} bottles of beer +Take one down, pass it around +{less} bottles of beer on the wall +''' + +for bottles in range(99,0,-1): + print verse.format(some=bottles, less=bottles-1) diff --git a/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-4.py b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-4.py new file mode 100644 index 0000000000..7d5e47be3f --- /dev/null +++ b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-4.py @@ -0,0 +1,2 @@ +a, b, c, s = " bottles of beer", " on the wall\n", "Take one down, pass it around\n", str +print "\n".join(s(x)+a+b+s(x)+a+"\n"+c+s(x-1)+a+b for x in xrange(99, 0, -1)) diff --git a/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-5.py b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-5.py new file mode 100644 index 0000000000..8324e1645a --- /dev/null +++ b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-5.py @@ -0,0 +1,2 @@ +a = lambda n: "%u bottle%s of beer on the wall\n" % (n, "s"[n==1:]) +print "\n".join(a(x)+a(x)[:-13]+"\nTake one down, pass it around\n"+a(x-1) for x in xrange(99, 0, -1)) diff --git a/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-6.py b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-6.py new file mode 100644 index 0000000000..3cd3b209d1 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-6.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +"""\ +{0} {2} of beer on the wall +{0} {2} of beer +Take one down, pass it around +{1} {3} of beer on the wall +""" +print("\n".join( + __doc__.format( + i, i - 1, + "bottle" if i == 1 else "bottles", + "bottle" if i - 1 == 1 else "bottles" + ) for i in range(99, 0, -1) +), end="") diff --git a/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-7.py b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-7.py new file mode 100644 index 0000000000..614f67c2e8 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-7.py @@ -0,0 +1,39 @@ +ones = ( +'', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine' +) +prefixes = ('thir', 'four', 'fif', 'six', 'seven', 'eigh', 'nine') +tens = ['', '', 'twenty' ] +teens = ['ten', 'eleven', 'twelve'] +for prefix in prefixes: + tens.append(prefix + 'ty') + teens.append(prefix +'teen') +tens[4] = 'forty' + +def number(num): + "get the wordy version of a number" + ten, one = divmod(num, 10) + if ten == 0 and one == 0: + return 'no' + elif ten == 0: + return ones[one] + elif ten == 1: + return teens[one] + elif one == 0: + return tens[ten] + else: + return "%s-%s" % (tens[ten], ones[one]) + +def bottles(beer): + "our rephrase" + return "%s bottle%s of beer" % ( + number(beer).capitalize(), 's' if beer > 1 else '' + ) + +onthewall = 'on the wall' +takeonedown = 'Take one down, pass it around' +for beer in range(99, 0, -1): + print bottles(beer), onthewall + print bottles(beer) + print takeonedown + print bottles(beer-1), onthewall + print diff --git a/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-8.py b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-8.py new file mode 100644 index 0000000000..930169b060 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer-8.py @@ -0,0 +1,7 @@ +for n in xrange(99, 0, -1): + ## The formatting performs a conditional check on the variable. + ## If it formats the first open for False, and the second for True + print n, 'bottle%s of beer on the the wall.' % ('s', '')[n == 1] + print n, 'bottle%s of beer.' % ('s', '')[n == 1] + print 'Take one down, pass it around.' + print n - 1, 'bottle%s of beer on the wall.\n' % ('s', '')[n - 1 == 1] diff --git a/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer.py b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer.py new file mode 100644 index 0000000000..de0103c5aa --- /dev/null +++ b/Task/99_Bottles_of_Beer/Python/99_bottles_of_beer.py @@ -0,0 +1,14 @@ +def plural(word, amount): # Correctly pluralize a word. + if amount == 1: + return word + else: + return word + 's' + +def sing(b, end): # Sing a phrase of the song, for b bottles, ending in end + print b or 'No more', plural('bottle', b), end + +for i in range(99, 0, -1): + sing(i, 'of beer on the wall,') + sing(i, 'of beer,') + print 'Take one down, pass it around,' + sing(i-1, 'of beer on the wall.\n') diff --git a/Task/99_Bottles_of_Beer/REXX/99_bottles_of_beer.rexx b/Task/99_Bottles_of_Beer/REXX/99_bottles_of_beer.rexx new file mode 100644 index 0000000000..0e6673ae71 --- /dev/null +++ b/Task/99_Bottles_of_Beer/REXX/99_bottles_of_beer.rexx @@ -0,0 +1,19 @@ +/*REXX pgm displays words to the song "99 Bottles of Beer on the Wall". */ + + do j=99 by -1 to 1 /*start countdown | singdown*/ + say j 'bottle's(j) "of beer on the wall," /*sing the #bottles of beer.*/ + say j 'bottle's(j) "of beer." /* ... and the refrain. */ + say 'Take one down, pass it around,' /*get a bottle and share it.*/ + n=j-1 /*N is #bottles we have now.*/ + if n==0 then n='no' /*use "no" instead of 0. */ + say n 'bottle's(n) "of beer on the wall." /*sing beer bottle inventory*/ + say /*blank line between verses.*/ + end /*j*/ + +say 'No more bottles of beer on the wall,' /*Finally! The last verse.*/ +say 'no more bottles of beer.' /*so sad ... */ +say 'Go to the store and buy some more,' /*replenishment of the beer.*/ +say '99 bottles of beer on the wall.' /*All is well in the tavern.*/ +exit /*we're done & also sloshed.*/ +/*───────────────────────────────────S subroutine───────────────────────*/ +s: if arg(1)=1 then return ''; return 's' /*a simple pluralizer funct.*/ diff --git a/Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer-2.rb b/Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer-2.rb new file mode 100644 index 0000000000..855400814d --- /dev/null +++ b/Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer-2.rb @@ -0,0 +1,12 @@ +trace_var :$bottle_num do |val| + $bottles = %Q{#{val == 0 ? 'No more' : val.to_s} bottle#{val == 1 ? '' : 's'}} +end + +($bottle_num = 99).times do + puts "#{$bottles} of beer on the wall" + puts "#{$bottles} of beer" + puts "Take one down, pass it around" + $bottle_num -= 1 + puts "#{$bottles} of beer on the wall" + puts "" +end diff --git a/Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer-3.rb b/Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer-3.rb new file mode 100644 index 0000000000..1b2e9bdda7 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer-3.rb @@ -0,0 +1,15 @@ +def bottles(of_beer, ending) + puts "#{of_beer} bottle#{ending} of beer on the wall," + puts "#{of_beer} bottle#{ending} of beer" + puts "Take one down, pass it around!" +end + +99.downto(0) do |left| + if left > 1 + bottles(left, "s") + elsif left == 1 + bottles(left, "") + else + puts "No more bottles of beer on the wall!" + end +end diff --git a/Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer-4.rb b/Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer-4.rb new file mode 100644 index 0000000000..04a2d53e2c --- /dev/null +++ b/Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer-4.rb @@ -0,0 +1,14 @@ +def bottles(beer, wall = false) + "#{beer>0 ? beer : "no more"} bottle#{"s" if beer!=1} of beer#{" on the wall" if wall}" +end + +99.downto(0) do |remaining| + puts "#{bottles(remaining,true).capitalize}, #{bottles(remaining)}." + if remaining==0 + print "Go to the store and buy some more" + remaining=100 + else + print "Take one down, pass it around" + end + puts ", #{bottles(remaining-1,true)}.\n\n" +end diff --git a/Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer.rb b/Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer.rb new file mode 100644 index 0000000000..d6dc5973d5 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Ruby/99_bottles_of_beer.rb @@ -0,0 +1,13 @@ +plural = 's' +99.downto(1) do |i| + puts "#{i} bottle#{plural} of beer on the wall," + puts "#{i} bottle#{plural} of beer" + puts "Take one down, pass it around!" + plural = '' if i - 1 == 1 + if i > 1 + puts "#{i-1} bottle#{plural} of beer on the wall!" + puts + else + puts "No more bottles of beer on the wall!" + end +end diff --git a/Task/99_Bottles_of_Beer/SNUSP/99_bottles_of_beer.snusp b/Task/99_Bottles_of_Beer/SNUSP/99_bottles_of_beer.snusp new file mode 100644 index 0000000000..67356a27ff --- /dev/null +++ b/Task/99_Bottles_of_Beer/SNUSP/99_bottles_of_beer.snusp @@ -0,0 +1,19 @@ + /=!/===========!/==+++++++++# +9 + | | /=!/=====@/==@@@+@+++++# +48 (itoa) + | | | | /==!/==@@@@=++++# +32 (space) + | | | | | \==@@++\!+++++++++++++\!+++++\ + 9 9 '9 9' space 'b' 'o' 't' + $@/>@/>@/>@/>@/>========@/>============@/>====@/>++++++++++ \n setup +/====================================loop=====>\!=>\!<<<<<<<< / +\@\@\>cr.@\< ?\<->+++++++++>->+++++++++\ | | + ! | | \===-========>=>-==BCD==!\< @\< ?/< ?/# no more beer! + /=|=====|================================/ + | | \<++t.<<----a.>----k.<++++e.<_.>>++++o.-n.< e.<_.>-d.>+o.>+++w.<-n.<<_.\ + | | / / + | | \>---a.>n.<+++d.<_.>>++p.<---a.>>----s.s.<<<_.>>-------i.>+t.<<<_.\ + | | / / + | | \>a.>>--r.<++++++o.>+++u.<-n.<+++d.>>>cr.<-T<+O<--B<<<# + | ! + \@\<<<_.>>o.-n.<<_.>>>++t.<<+++h.---e.<_.>>>+++w.<<----a.>--l.l.>>CR.<---T<+++O<+B<<<# + | + \9.>9.>_.>B.>O.>T.t.<---l.<+++e.>>-s.<<<_.>>+++O.<+f.<_.>----b.+++e.E.>>-R.# diff --git a/Task/99_Bottles_of_Beer/Tcl/99_bottles_of_beer-2.tcl b/Task/99_Bottles_of_Beer/Tcl/99_bottles_of_beer-2.tcl new file mode 100644 index 0000000000..1bf1a247c2 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Tcl/99_bottles_of_beer-2.tcl @@ -0,0 +1,28 @@ +proc 0-19 {n} { + lindex {"no more" one two three four five six seven eight nine ten eleven + twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen} $n +} + +proc TENS {n} { + lindex {twenty thirty fourty fifty sixty seventy eighty ninety} [expr {$n - 2}] +} + +proc num2words {n} { + if {$n < 20} {return [0-19 $n]} + set tens [expr {$n / 10}] + set ones [expr {$n % 10}] + if {$ones == 0} {return [TENS $tens]} + return "[TENS $tens]-[0-19 $ones]" +} + +proc get_words {n} { + return "[num2words $n] bottle[expr {$n != 1 ? "s" : ""}] of beer" +} + +for {set i 99} {$i > 0} {incr i -1} { + puts [string totitle "[get_words $i] on the wall, [get_words $i]."] + puts "Take one down and pass it around, [get_words [expr {$i - 1}]] on the wall.\n" +} + +puts "No more bottles of beer on the wall, no more bottles of beer." +puts "Go to the store and buy some more, 99 bottles of beer on the wall." diff --git a/Task/99_Bottles_of_Beer/Tcl/99_bottles_of_beer.tcl b/Task/99_Bottles_of_Beer/Tcl/99_bottles_of_beer.tcl new file mode 100644 index 0000000000..f6ccf91bd9 --- /dev/null +++ b/Task/99_Bottles_of_Beer/Tcl/99_bottles_of_beer.tcl @@ -0,0 +1,10 @@ +set s "s"; set ob "of beer"; set otw "on the wall"; set more "Take one down and pass it around" +for {set n 100} {$n ne "No more"} {} { + switch -- [incr n -1] { + 1 {set s ""} + 0 {set s "s"; set n "No more"; set more "Go to the store and buy some more"} + } + lappend verse ". $n bottle$s $ob $otw.\n" + lappend verse "\n$n bottle$s $ob $otw, [string tolower $n] bottle$s $ob.\n$more" +} +puts -nonewline [join [lreplace $verse 0 0] ""][lindex $verse 0] diff --git a/Task/Anagrams/0DESCRIPTION b/Task/Anagrams/0DESCRIPTION new file mode 100644 index 0000000000..5911259915 --- /dev/null +++ b/Task/Anagrams/0DESCRIPTION @@ -0,0 +1 @@ +Two or more words can be composed of the same characters, but in a different order. Using the word list at http://www.puzzlers.org/pub/wordlists/unixdict.txt, find the sets of words that share the same characters that contain the most words in them. diff --git a/Task/Anagrams/1META.yaml b/Task/Anagrams/1META.yaml new file mode 100644 index 0000000000..88eb5468ca --- /dev/null +++ b/Task/Anagrams/1META.yaml @@ -0,0 +1,2 @@ +--- +note: Text processing diff --git a/Task/Anagrams/AWK/anagrams.awk b/Task/Anagrams/AWK/anagrams.awk new file mode 100644 index 0000000000..deb36cc1fb --- /dev/null +++ b/Task/Anagrams/AWK/anagrams.awk @@ -0,0 +1,26 @@ +# JUMBLEA.AWK - words with the most duplicate spellings +# syntax: GAWK -f JUMBLEA.AWK UNIXDICT.TXT +{ for (i=1; i<=NF; i++) { + w = sortstr(toupper($i)) + arr[w] = arr[w] $i " " + n = gsub(/ /,"&",arr[w]) + if (max_n < n) { max_n = n } + } +} +END { + for (w in arr) { + if (gsub(/ /,"&",arr[w]) == max_n) { + printf("%s\t%s\n",w,arr[w]) + } + } + exit(0) +} +function sortstr(str, i,j,leng) { + leng = length(str) + for (i=2; i<=leng; i++) { + for (j=i; j>1 && substr(str,j-1,1) > substr(str,j,1); j--) { + str = substr(str,1,j-2) substr(str,j,1) substr(str,j-1,1) substr(str,j+1) + } + } + return(str) +} diff --git a/Task/Anagrams/C/anagrams-2.c b/Task/Anagrams/C/anagrams-2.c new file mode 100644 index 0000000000..c953b66d64 --- /dev/null +++ b/Task/Anagrams/C/anagrams-2.c @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include +#include +#include + +typedef struct { const char *key, *word; int cnt; } kw_t; + +int lst_cmp(const void *a, const void *b) +{ + return strcmp(((const kw_t*)a)->key, ((const kw_t*)b)->key); +} + +/* Bubble sort. Faster than stock qsort(), believe it or not */ +void sort_letters(char *s) +{ + int i, j; + char t; + for (i = 0; s[i] != '\0'; i++) { + for (j = i + 1; s[j] != '\0'; j++) + if (s[j] < s[i]) { + t = s[j]; s[j] = s[i]; s[i] = t; + } + } +} + +int main() +{ + struct stat s; + char *words, *keys; + size_t i, j, k, longest, offset; + int n_word = 0; + kw_t *list; + + int fd = open("unixdict.txt", O_RDONLY); + if (fd == -1) return 1; + fstat(fd, &s); + words = malloc(s.st_size * 2); + keys = words + s.st_size; + + read(fd, words, s.st_size); + memcpy(keys, words, s.st_size); + + /* change newline to null for easy use; sort letters in keys */ + for (i = j = 0; i < s.st_size; i++) { + if (words[i] == '\n') { + words[i] = keys[i] = '\0'; + sort_letters(keys + j); + j = i + 1; + n_word ++; + } + } + + list = calloc(n_word, sizeof(kw_t)); + + /* make key/word pointer pairs for sorting */ + for (i = j = k = 0; i < s.st_size; i++) { + if (words[i] == '\0') { + list[j].key = keys + k; + list[j].word = words + k; + k = i + 1; + j++; + } + } + + qsort(list, n_word, sizeof(kw_t), lst_cmp); + + /* count each key's repetition */ + for (i = j = k = offset = longest = 0; i < n_word; i++) { + if (!strcmp(list[i].key, list[j].key)) { + ++k; + continue; + } + + /* move current longest to begining of array */ + if (k < longest) { + k = 0; + j = i; + continue; + } + + if (k > longest) offset = 0; + + while (j < i) list[offset++] = list[j++]; + longest = k; + k = 0; + } + + /* show the longest */ + for (i = 0; i < offset; i++) { + printf("%s ", list[i].word); + if (i < n_word - 1 && strcmp(list[i].key, list[i+1].key)) + printf("\n"); + } + + /* free(list); free(words); */ + close(fd); + return 0; +} diff --git a/Task/Anagrams/C/anagrams.c b/Task/Anagrams/C/anagrams.c new file mode 100644 index 0000000000..e67ae03b51 --- /dev/null +++ b/Task/Anagrams/C/anagrams.c @@ -0,0 +1,160 @@ +#include +#include +#include +#include +#include + +char *sortedWord(const char *word, char *wbuf) +{ + char *p1, *p2, *endwrd; + char t; + int swaps; + + strcpy(wbuf, word); + endwrd = wbuf+strlen(wbuf); + do { + swaps = 0; + p1 = wbuf; p2 = endwrd-1; + while (p1 *p1) { + t = *p2; *p2 = *p1; *p1 = t; + swaps = 1; + } + p1++; p2--; + } + p1 = wbuf; p2 = p1+1; + while(p2 < endwrd) { + if (*p2 > *p1) { + t = *p2; *p2 = *p1; *p1 = t; + swaps = 1; + } + p1++; p2++; + } + } while (swaps); + return wbuf; +} + +static +short cxmap[] = { + 0x06, 0x1f, 0x4d, 0x0c, 0x5c, 0x28, 0x5d, 0x0e, 0x09, 0x33, 0x31, 0x56, + 0x52, 0x19, 0x29, 0x53, 0x32, 0x48, 0x35, 0x55, 0x5e, 0x14, 0x27, 0x24, + 0x02, 0x3e, 0x18, 0x4a, 0x3f, 0x4c, 0x45, 0x30, 0x08, 0x2c, 0x1a, 0x03, + 0x0b, 0x0d, 0x4f, 0x07, 0x20, 0x1d, 0x51, 0x3b, 0x11, 0x58, 0x00, 0x49, + 0x15, 0x2d, 0x41, 0x17, 0x5f, 0x39, 0x16, 0x42, 0x37, 0x22, 0x1c, 0x0f, + 0x43, 0x5b, 0x46, 0x4b, 0x0a, 0x26, 0x2e, 0x40, 0x12, 0x21, 0x3c, 0x36, + 0x38, 0x1e, 0x01, 0x1b, 0x05, 0x4e, 0x44, 0x3d, 0x04, 0x10, 0x5a, 0x2a, + 0x23, 0x34, 0x25, 0x2f, 0x2b, 0x50, 0x3a, 0x54, 0x47, 0x59, 0x13, 0x57, + }; +#define CXMAP_SIZE (sizeof(cxmap)/sizeof(short)) + + +int Str_Hash( const char *key, int ix_max ) +{ + const char *cp; + short mash; + int hash = 33501551; + for (cp = key; *cp; cp++) { + mash = cxmap[*cp % CXMAP_SIZE]; + hash = (hash >>4) ^ 0x5C5CF5C ^ ((hash<<1) + (mash<<5)); + hash &= 0x3FFFFFFF; + } + return hash % ix_max; +} + +typedef struct sDictWord *DictWord; +struct sDictWord { + const char *word; + DictWord next; +}; + +typedef struct sHashEntry *HashEntry; +struct sHashEntry { + const char *key; + HashEntry next; + DictWord words; + HashEntry link; + short wordCount; +}; + +#define HT_SIZE 8192 + +HashEntry hashTable[HT_SIZE]; + +HashEntry mostPerms = NULL; + +int buildAnagrams( FILE *fin ) +{ + char buffer[40]; + char bufr2[40]; + char *hkey; + int hix; + HashEntry he, *hep; + DictWord we; + int maxPC = 2; + int numWords = 0; + + while ( fgets(buffer, 40, fin)) { + for(hkey = buffer; *hkey && (*hkey!='\n'); hkey++); + *hkey = 0; + hkey = sortedWord(buffer, bufr2); + hix = Str_Hash(hkey, HT_SIZE); + he = hashTable[hix]; hep = &hashTable[hix]; + while( he && strcmp(he->key , hkey) ) { + hep = &he->next; + he = he->next; + } + if ( ! he ) { + he = malloc(sizeof(struct sHashEntry)); + he->next = NULL; + he->key = strdup(hkey); + he->wordCount = 0; + he->words = NULL; + he->link = NULL; + *hep = he; + } + we = malloc(sizeof(struct sDictWord)); + we->word = strdup(buffer); + we->next = he->words; + he->words = we; + he->wordCount++; + if ( maxPC < he->wordCount) { + maxPC = he->wordCount; + mostPerms = he; + he->link = NULL; + } + else if (maxPC == he->wordCount) { + he->link = mostPerms; + mostPerms = he; + } + + numWords++; + } + printf("%d words in dictionary max ana=%d\n", numWords, maxPC); + return maxPC; +} + + +int main( ) +{ + HashEntry he; + DictWord we; + FILE *f1; + + f1 = fopen("unixdict.txt","r"); + buildAnagrams(f1); + fclose(f1); + + f1 = fopen("anaout.txt","w"); +// f1 = stdout; + + for (he = mostPerms; he; he = he->link) { + fprintf(f1,"%d:", he->wordCount); + for(we = he->words; we; we = we->next) { + fprintf(f1,"%s, ", we->word); + } + fprintf(f1, "\n"); + } + + fclose(f1); + return 0; +} diff --git a/Task/Anagrams/Clojure/anagrams.clj b/Task/Anagrams/Clojure/anagrams.clj new file mode 100644 index 0000000000..b72065f746 --- /dev/null +++ b/Task/Anagrams/Clojure/anagrams.clj @@ -0,0 +1,10 @@ +(require '[clojure.java.io :as io]) + +(def groups + (with-open [r (io/reader wordfile)] + (group-by sort (line-seq r))) + +(let [wordlists (sort-by (comp - count) (vals groups) + maxlength (count (first wordlists))] + (doseq [wordlist (take-while #(= (count %) maxlength) wordlists)] + (println wordlist)) diff --git a/Task/Anagrams/CoffeeScript/anagrams-2.coffee b/Task/Anagrams/CoffeeScript/anagrams-2.coffee new file mode 100644 index 0000000000..caf76befd6 --- /dev/null +++ b/Task/Anagrams/CoffeeScript/anagrams-2.coffee @@ -0,0 +1,7 @@ +> coffee anagrams.coffee +[ 'abel', 'able', 'bale', 'bela', 'elba' ] +[ 'alger', 'glare', 'lager', 'large', 'regal' ] +[ 'angel', 'angle', 'galen', 'glean', 'lange' ] +[ 'caret', 'carte', 'cater', 'crate', 'trace' ] +[ 'elan', 'lane', 'lean', 'lena', 'neal' ] +[ 'evil', 'levi', 'live', 'veil', 'vile' ] diff --git a/Task/Anagrams/CoffeeScript/anagrams.coffee b/Task/Anagrams/CoffeeScript/anagrams.coffee new file mode 100644 index 0000000000..5e93433fae --- /dev/null +++ b/Task/Anagrams/CoffeeScript/anagrams.coffee @@ -0,0 +1,31 @@ +http = require 'http' + +show_large_anagram_sets = (word_lst) -> + anagrams = {} + max_size = 0 + + for word in word_lst + key = word.split('').sort().join('') + anagrams[key] ?= [] + anagrams[key].push word + size = anagrams[key].length + max_size = size if size > max_size + + for key, variations of anagrams + if variations.length == max_size + console.log variations.join ' ' + +get_word_list = (process) -> + options = + host: "www.puzzlers.org" + path: "/pub/wordlists/unixdict.txt" + + req = http.request options, (res) -> + s = '' + res.on 'data', (chunk) -> + s += chunk + res.on 'end', -> + process s.split '\n' + req.end() + +get_word_list show_large_anagram_sets diff --git a/Task/Anagrams/Erlang/anagrams.erl b/Task/Anagrams/Erlang/anagrams.erl new file mode 100644 index 0000000000..51ecbbd3d2 --- /dev/null +++ b/Task/Anagrams/Erlang/anagrams.erl @@ -0,0 +1,29 @@ +-module(anagrams). +-compile(export_all). + +play() -> + {ok, P} = file:read_file('unixdict.txt'), + D = dict:new(), + E=fetch(string:tokens(binary_to_list(P), "\n"), D), + get_value(dict:fetch_keys(E), E). + +fetch([H|T], D) -> + fetch(T, dict:append(lists:sort(H), H, D)); +fetch([], D) -> + D. + +get_value(L, D) -> get_value(L,D,1,[]). +get_value([H|T], D, N, L) -> + Var = dict:fetch(H,D), + Len = length(Var), + if + Len > N -> + get_value(T, D, Len, [Var]); + Len == N -> + get_value(T, D, Len, [Var | L]); + Len < N -> + get_value(T, D, N, L) + end; + +get_value([], _, _, L) -> + L. diff --git a/Task/Anagrams/Go/anagrams-2.go b/Task/Anagrams/Go/anagrams-2.go new file mode 100644 index 0000000000..55618fcaee --- /dev/null +++ b/Task/Anagrams/Go/anagrams-2.go @@ -0,0 +1,5 @@ +def words = new URL('http://www.puzzlers.org/pub/wordlists/unixdict.txt').text.readLines() +def groups = words.groupBy{ it.toList().sort() } +def bigGroupSize = groups.collect{ it.value.size() }.max() +def isBigAnagram = { it.value.size() == bigGroupSize } +println groups.findAll(isBigAnagram).collect{ it.value }.collect{ it.join(' ') }.join('\n') diff --git a/Task/Anagrams/Go/anagrams-3.go b/Task/Anagrams/Go/anagrams-3.go new file mode 100644 index 0000000000..02f9bfb6b1 --- /dev/null +++ b/Task/Anagrams/Go/anagrams-3.go @@ -0,0 +1,10 @@ +import Data.List + +groupon f x y = f x == f y + +main = do + f <- readFile "./../Puzzels/Rosetta/unixdict.txt" + let words = lines f + wix = groupBy (groupon fst) . sort $ zip (map sort words) words + mxl = maximum $ map length wix + mapM_ (print . map snd) . filter ((==mxl).length) $ wix diff --git a/Task/Anagrams/Go/anagrams-4.go b/Task/Anagrams/Go/anagrams-4.go new file mode 100644 index 0000000000..2b6993493f --- /dev/null +++ b/Task/Anagrams/Go/anagrams-4.go @@ -0,0 +1,7 @@ +*Main> main +["abel","able","bale","bela","elba"] +["caret","carte","cater","crate","trace"] +["angel","angle","galen","glean","lange"] +["alger","glare","lager","large","regal"] +["elan","lane","lean","lena","neal"] +["evil","levi","live","veil","vile"] diff --git a/Task/Anagrams/Go/anagrams.go b/Task/Anagrams/Go/anagrams.go new file mode 100644 index 0000000000..e26b0ab87a --- /dev/null +++ b/Task/Anagrams/Go/anagrams.go @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "io/ioutil" + "sort" + "strings" +) + +func main() { + b, err := ioutil.ReadFile("unixdict.txt") + if err != nil { + fmt.Println(err) + return + } + var ma int + m := make(map[string][]string) + for _, word := range strings.Split(string(b), "\n") { + bs := byteSlice(word) + sort.Sort(bs) + k := string(bs) + a := append(m[k], word) + if len(a) > ma { + ma = len(a) + } + m[k] = a + } + for _, a := range m { + if len(a) == ma { + fmt.Println(a) + } + } +} + +type byteSlice []byte + +func (b byteSlice) Len() int { return len(b) } +func (b byteSlice) Swap(i, j int) { b[i], b[j] = b[j], b[i] } +func (b byteSlice) Less(i, j int) bool { return b[i] < b[j] } diff --git a/Task/Anagrams/Java/anagrams.java b/Task/Anagrams/Java/anagrams.java new file mode 100644 index 0000000000..603b714186 --- /dev/null +++ b/Task/Anagrams/Java/anagrams.java @@ -0,0 +1,30 @@ +import java.net.*; +import java.io.*; +import java.util.*; + +public class WordsOfEqChars { + public static void main(String[] args) throws IOException { + URL url = new URL("http://www.puzzlers.org/pub/wordlists/unixdict.txt"); + InputStreamReader isr = new InputStreamReader(url.openStream()); + BufferedReader reader = new BufferedReader(isr); + + Map> anagrams = new HashMap>(); + String word; + int count = 0; + while ((word = reader.readLine()) != null) { + char[] chars = word.toCharArray(); + Arrays.sort(chars); + String key = new String(chars); + if (!anagrams.containsKey(key)) + anagrams.put(key, new ArrayList()); + anagrams.get(key).add(word); + count = Math.max(count, anagrams.get(key).size()); + } + + reader.close(); + + for (Collection ana : anagrams.values()) + if (ana.size() >= count) + System.out.println(ana); + } +} diff --git a/Task/Anagrams/JavaScript/anagrams.js b/Task/Anagrams/JavaScript/anagrams.js new file mode 100644 index 0000000000..c05f247839 --- /dev/null +++ b/Task/Anagrams/JavaScript/anagrams.js @@ -0,0 +1,20 @@ +#!/usr/bin/env js + +var anas = {}; +var words = read('unixdict.txt').split(/\n/g); + +for (var w in words) { + var key = words[w].split("").sort().join(''); + if (!(key in anas)) { + anas[key] = []; + } + anas[key].push(words[w]); +} + +for (var a in anas) { + if (anas[a].length >= 2) { + print(anas[a]); + } +} + +quit(); diff --git a/Task/Anagrams/Lua/anagrams.lua b/Task/Anagrams/Lua/anagrams.lua new file mode 100644 index 0000000000..92f556dd75 --- /dev/null +++ b/Task/Anagrams/Lua/anagrams.lua @@ -0,0 +1,73 @@ +-- Build the word set +local set = {} +local file = io.open("unixdict.txt") +local str = file:read() +while str do + table.insert(set,str) + str = file:read() +end + +-- Build the anagram tree +local tree = {} +for i,word in next,set do + -- Sort a string from lowest char to highest + local function sortString(str) + if #str <= 1 then + return str + end + local less = '' + local greater = '' + local pivot = str:byte(1) + for i = 2, #str do + if str:byte(i) <= pivot then + less = less..(str:sub(i,i)) + else + greater = greater..(str:sub(i,i)) + end + end + return sortString(less)..str:sub(1,1)..sortString(greater) + end + local sortchar = sortString(word) + if not tree[#word] then tree[#word] = {} end + local node = tree[#word] + for i = 1,#word do + if not node[sortchar:byte(i)] then + node[sortchar:byte(i)] = {} + end + node = node[sortchar:byte(i)] + end + table.insert(node,word) +end + +-- Gather largest groups by gathering all groups of current max size and droping gathered groups and increasing max when a new largest group is found +local max = 0 +local set = {} +local function recurse (tree) + local num = 0 + for i,node in next,tree do + if type(node) == 'string' then + num = num + 1 + end + end + if num > max then + set = {} + max = num + end + if num == max then + local newset = {} + for i,node in next,tree do + if type(node) == 'string' then + table.insert(newset,node) + end + end + table.insert(set,newset) + end + for i,node in next,tree do + if type(node) == 'table' then + recurse(node) + end + end +end + +recurse (tree) +for i,v in next,set do io.write (i..':\t')for j,u in next,v do io.write (u..' ') end print() end diff --git a/Task/Anagrams/PHP/anagrams.php b/Task/Anagrams/PHP/anagrams.php new file mode 100644 index 0000000000..a87048da7b --- /dev/null +++ b/Task/Anagrams/PHP/anagrams.php @@ -0,0 +1,13 @@ + diff --git a/Task/Anagrams/Perl/anagrams-2.pl b/Task/Anagrams/Perl/anagrams-2.pl new file mode 100644 index 0000000000..b13e1a79eb --- /dev/null +++ b/Task/Anagrams/Perl/anagrams-2.pl @@ -0,0 +1,7 @@ +use LWP::Simple; + +for (split ' ' => get 'http://www.puzzlers.org/pub/wordlists/unixdict.txt') + {push @{$anagram{ join '' => sort split // }}, $_} + +$max > @$_ or $max = @$_ for values %anagram; +@$_ >= $max and print "@$_\n" for values %anagram; diff --git a/Task/Anagrams/Perl/anagrams.pl b/Task/Anagrams/Perl/anagrams.pl new file mode 100644 index 0000000000..7dbf4662aa --- /dev/null +++ b/Task/Anagrams/Perl/anagrams.pl @@ -0,0 +1,15 @@ +use LWP::Simple; +use List::Util qw(max); + +my @words = split(' ', get('http://www.puzzlers.org/pub/wordlists/unixdict.txt')); +my %anagram; +foreach my $word (@words) { + push @{ $anagram{join('', sort(split(//, $word)))} }, $word; +} + +my $count = max(map {scalar @$_} values %anagram); +foreach my $ana (values %anagram) { + if (@$ana >= $count) { + print "@$ana\n"; + } +} diff --git a/Task/Anagrams/PicoLisp/anagrams-2.l b/Task/Anagrams/PicoLisp/anagrams-2.l new file mode 100644 index 0000000000..ad076f4686 --- /dev/null +++ b/Task/Anagrams/PicoLisp/anagrams-2.l @@ -0,0 +1,8 @@ +(let Words NIL + (in "unixdict.txt" + (while (line) + (let (Word (pack @) Key (pack (sort @))) + (if (idx 'Words Key T) + (push (car @) Word) + (set Key (list Word)) ) ) ) ) + (flip (by length sort (mapcar val (idx 'Words)))) ) diff --git a/Task/Anagrams/PicoLisp/anagrams.l b/Task/Anagrams/PicoLisp/anagrams.l new file mode 100644 index 0000000000..9214020b26 --- /dev/null +++ b/Task/Anagrams/PicoLisp/anagrams.l @@ -0,0 +1,4 @@ +(flip + (by length sort + (by '((L) (sort (copy L))) group + (in "unixdict.txt" (make (while (line) (link @)))) ) ) ) diff --git a/Task/Anagrams/Python/anagrams-2.py b/Task/Anagrams/Python/anagrams-2.py new file mode 100644 index 0000000000..ce3e8422c7 --- /dev/null +++ b/Task/Anagrams/Python/anagrams-2.py @@ -0,0 +1,14 @@ +import urllib.request, itertools +import time +words = urllib.request.urlopen('http://www.puzzlers.org/pub/wordlists/unixdict.txt').read().split() +print('Words ready') +t0 = time.clock() +anagrams = [list(g) for k,g in itertools.groupby(sorted(words, key=sorted), key=sorted)] +anagrams.sort(key=len, reverse=True) +count = len(anagrams[0]) +for ana in anagrams: + if len(ana) < count: + break + print(ana) +t0 -= time.clock() +print('Finished in %f s' % -t0) diff --git a/Task/Anagrams/Python/anagrams-3.py b/Task/Anagrams/Python/anagrams-3.py new file mode 100644 index 0000000000..0a7705f4f0 --- /dev/null +++ b/Task/Anagrams/Python/anagrams-3.py @@ -0,0 +1,25 @@ +>>> import urllib +>>> from collections import defaultdict +>>> words = urllib.urlopen('http://www.puzzlers.org/pub/wordlists/unixdict.txt').read().split() +>>> len(words) +25104 +>>> anagram = defaultdict(list) # map sorted chars to anagrams +>>> for word in words: + anagram[tuple(sorted(word))].append( word ) + + +>>> count = max(len(ana) for ana in anagram.itervalues()) +>>> for ana in anagram.itervalues(): + if len(ana) >= count: + print ana + + +['angel', 'angle', 'galen', 'glean', 'lange'] +['alger', 'glare', 'lager', 'large', 'regal'] +['caret', 'carte', 'cater', 'crate', 'trace'] +['evil', 'levi', 'live', 'veil', 'vile'] +['elan', 'lane', 'lean', 'lena', 'neal'] +['abel', 'able', 'bale', 'bela', 'elba'] +>>> count +5 +>>> diff --git a/Task/Anagrams/Python/anagrams-4.py b/Task/Anagrams/Python/anagrams-4.py new file mode 100644 index 0000000000..fc284a8617 --- /dev/null +++ b/Task/Anagrams/Python/anagrams-4.py @@ -0,0 +1,22 @@ +>>> import urllib, itertools +>>> words = urllib.urlopen('http://www.puzzlers.org/pub/wordlists/unixdict.txt').read().split() +>>> len(words) +25104 +>>> anagrams = [list(g) for k,g in itertools.groupby(sorted(words, key=sorted), key=sorted)] + + +>>> count = max(len(ana) for ana in anagrams) +>>> for ana in anagrams: + if len(ana) >= count: + print ana + + +['abel', 'able', 'bale', 'bela', 'elba'] +['caret', 'carte', 'cater', 'crate', 'trace'] +['angel', 'angle', 'galen', 'glean', 'lange'] +['alger', 'glare', 'lager', 'large', 'regal'] +['elan', 'lane', 'lean', 'lena', 'neal'] +['evil', 'levi', 'live', 'veil', 'vile'] +>>> count +5 +>>> diff --git a/Task/Anagrams/Python/anagrams.py b/Task/Anagrams/Python/anagrams.py new file mode 100644 index 0000000000..8db99dec25 --- /dev/null +++ b/Task/Anagrams/Python/anagrams.py @@ -0,0 +1,12 @@ +>>> import urllib.request +>>> from collections import defaultdict +>>> words = urllib.request.urlopen('http://www.puzzlers.org/pub/wordlists/unixdict.txt').read().split() +>>> anagram = defaultdict(list) # map sorted chars to anagrams +>>> for word in words: + anagram[tuple(sorted(word))].append( word ) + + +>>> count = max(len(ana) for ana in anagram.values()) +>>> for ana in anagram.values(): + if len(ana) >= count: + print ([x.decode() for x in ana]) diff --git a/Task/Anagrams/REXX/anagrams.rexx b/Task/Anagrams/REXX/anagrams.rexx new file mode 100644 index 0000000000..4f049d026e --- /dev/null +++ b/Task/Anagrams/REXX/anagrams.rexx @@ -0,0 +1,33 @@ +/*REXX program finds words with the largest set of anagrams (same size).*/ +ifid='unixdict.txt'; words=0 /*input file identifier, # words.*/ +wL.=0 /*number of words of length L. */ + do j=1 while lines(ifid)\==0 /*read each word in file (word=X)*/ + x=space(linein(ifid),0) /*pick off a word from the input.*/ + L=length(x); if L<3 then iterate /*onesies and twosies can't win. */ + words=words+1 /*count of (useable) words. */ + @.words=x /*save the word in an array. */ + wL.L=wL.L+1; _=wL.L /*counter of words of length L. */ + @@.L._=x /*array of words of length L. */ + /*sort the letters*/ do ja=1 for L; !.ja=substr(x,ja,1); end + !.0=L; call esort;z=; do jb=1 for L; z=z || !.jb; end + @@s.L._=z /*store the sorted word (letters)*/ + @s.words=@@s.L._ /*and also, sorted length L vers.*/ + end /*j*/ +a.= /*all the anagrams for word X. */ +say copies('─',30) words 'words in the dictionary file: ' ifid +n.=0 /*number of anagrams for word X. */ + do j=1 for words /*process the usable words found.*/ + x=@.j; Lx=length(x); xs=@s.j /*get some vital statistics for X*/ + do k=1 for wL.Lx /*process all the words of len L.*/ + if xs\==@@s.Lx.k then iterate /*is this a true anagram of X ? */ + if x==@@.Lx.k then iterate /*skip doing anagram on itself. */ + n.j=n.j+1; a.j=a.j @@.Lx.k /*bump counter, add ──► anagrams.*/ + end /*k*/ + end /*j*/ +m=n.1 /*assume first (len=1) is largest*/ + do j=2 to words; m=max(m,n.j); end /*find the maximum anagram count.*/ + do k=1 for words; if n.k==m then if word(a.k,1)>@.k then say @.k a.k; end +exit /*stick a fork in it, we're done.*/ +/*──────────────────────────────────ESORT───────────────────────────────*/ +esort:procedure expose !.;h=!.0;do while h>1;h=h%2;do i=1 for !.0-h;j=i;k=h+i +do while !.k=j then leave;j=j-h;k=k-h;end;end;end;return diff --git a/Task/Anagrams/Ruby/anagrams-2.rb b/Task/Anagrams/Ruby/anagrams-2.rb new file mode 100644 index 0000000000..5157076227 --- /dev/null +++ b/Task/Anagrams/Ruby/anagrams-2.rb @@ -0,0 +1,14 @@ +require 'open-uri' + +anagram = nil + +open('http://www.puzzlers.org/pub/wordlists/unixdict.txt') do |f| + anagram = f.read.split.group_by {|s| s.each_char.sort} +end + +count = anagram.each_value.map {|ana| ana.length}.max +anagram.each_value do |ana| + if ana.length >= count + p ana + end +end diff --git a/Task/Anagrams/Ruby/anagrams.rb b/Task/Anagrams/Ruby/anagrams.rb new file mode 100644 index 0000000000..af3ba231c1 --- /dev/null +++ b/Task/Anagrams/Ruby/anagrams.rb @@ -0,0 +1,17 @@ +require 'open-uri' + +anagram = Hash.new {|hash, key| hash[key] = []} # map sorted chars to anagrams + +open('http://www.puzzlers.org/pub/wordlists/unixdict.txt') do |f| + words = f.read.split + for word in words + anagram[word.split('').sort] << word + end +end + +count = anagram.values.map {|ana| ana.length}.max +anagram.each_value do |ana| + if ana.length >= count + p ana + end +end diff --git a/Task/Anagrams/Scala/anagrams-2.scala b/Task/Anagrams/Scala/anagrams-2.scala new file mode 100644 index 0000000000..0f6520d1ef --- /dev/null +++ b/Task/Anagrams/Scala/anagrams-2.scala @@ -0,0 +1,6 @@ +Source + .fromURL("http://www.puzzlers.org/pub/wordlists/unixdict.txt").getLines.toList + .groupBy(_.sorted).values + .groupBy(_.size).maxBy(_._1)._2 + .map(_.mkString("\t")) + .foreach(println) diff --git a/Task/Anagrams/Scala/anagrams.scala b/Task/Anagrams/Scala/anagrams.scala new file mode 100644 index 0000000000..580e0b4d89 --- /dev/null +++ b/Task/Anagrams/Scala/anagrams.scala @@ -0,0 +1,4 @@ +val src = io.Source fromURL "http://www.puzzlers.org/pub/wordlists/unixdict.txt" +val vls = src.getLines.toList.groupBy(_.sorted).values +val max = vls.map(_.size).max +vls filter (_.size == max) map (_ mkString " ") mkString "\n" diff --git a/Task/Anagrams/Tcl/anagrams.tcl b/Task/Anagrams/Tcl/anagrams.tcl new file mode 100644 index 0000000000..aca6f55177 --- /dev/null +++ b/Task/Anagrams/Tcl/anagrams.tcl @@ -0,0 +1,24 @@ +package require Tcl 8.5 +package require http + +set url http://www.puzzlers.org/pub/wordlists/unixdict.txt +set response [http::geturl $url] +set data [http::data $response] +http::cleanup $response + +set max 0 +array set anagrams {} + +foreach line [split $data \n] { + foreach word [split $line] { + set anagram [join [lsort [split $word ""]] ""] + lappend anagrams($anagram) $word + set max [::tcl::mathfunc::max $max [llength $anagrams($anagram)]] + } +} + +foreach key [array names anagrams] { + if {[llength $anagrams($key)] == $max} { + puts $anagrams($key) + } +} diff --git a/Task/Bulls_and_cows/0DESCRIPTION b/Task/Bulls_and_cows/0DESCRIPTION new file mode 100644 index 0000000000..5799e899ea --- /dev/null +++ b/Task/Bulls_and_cows/0DESCRIPTION @@ -0,0 +1,14 @@ +[[wp:Bulls and Cows|This]] is an old game played with pencil and paper that was later implemented on computer. + +The task is for the program to create a four digit random number from the digits 1 to 9, without duplication. +The program should ask for guesses to this number, reject guesses that are malformed, then print the score for the guess. + +The score is computed as: +# The player wins if the guess is the same as the randomly chosen number, and the program ends. +# A score of one '''bull''' is accumulated for each digit in the guess that equals the corresponding digit in the randomly chosen initial number. +# A score of one '''cow''' is accumulated for each digit in the guess that also appears in the randomly chosen number, but in the wrong position. + +;Cf, +* [[Bulls and cows/Player]] +* [[Guess the number]] +* [[Guess the number/With Feedback]] diff --git a/Task/Bulls_and_cows/1META.yaml b/Task/Bulls_and_cows/1META.yaml new file mode 100644 index 0000000000..a2413d963b --- /dev/null +++ b/Task/Bulls_and_cows/1META.yaml @@ -0,0 +1,2 @@ +--- +note: Games diff --git a/Task/Bulls_and_cows/BASIC/bulls_and_cows.bas b/Task/Bulls_and_cows/BASIC/bulls_and_cows.bas new file mode 100644 index 0000000000..e21a3f870a --- /dev/null +++ b/Task/Bulls_and_cows/BASIC/bulls_and_cows.bas @@ -0,0 +1,41 @@ +DEFINT A-Z + +DIM secret AS STRING +DIM guess AS STRING +DIM c AS STRING +DIM bulls, cows, guesses, i + +RANDOMIZE TIMER +DO WHILE LEN(secret) < 4 + c = CHR$(INT(RND * 10) + 48) + IF INSTR(secret, c) = 0 THEN secret = secret + c +LOOP + +guesses = 0 +DO + INPUT "Guess a 4-digit number with no duplicate digits: "; guess + guess = LTRIM$(RTRIM$(guess)) + IF LEN(guess) = 0 THEN EXIT DO + + IF LEN(guess) <> 4 OR VAL(guess) = 0 THEN + PRINT "** You should enter 4 numeric digits!" + GOTO looper + END IF + + bulls = 0: cows = 0: guesses = guesses + 1 + FOR i = 1 TO 4 + c = MID$(secret, i, 1) + IF MID$(guess, i, 1) = c THEN + bulls = bulls + 1 + ELSEIF INSTR(guess, c) THEN + cows = cows + 1 + END IF + NEXT i + PRINT bulls; " bulls, "; cows; " cows" + + IF guess = secret THEN + PRINT "You won after "; guesses; " guesses!" + EXIT DO + END IF +looper: +LOOP diff --git a/Task/Bulls_and_cows/C/bulls_and_cows-2.c b/Task/Bulls_and_cows/C/bulls_and_cows-2.c new file mode 100644 index 0000000000..e69c882ffd --- /dev/null +++ b/Task/Bulls_and_cows/C/bulls_and_cows-2.c @@ -0,0 +1,85 @@ +bool take_it_or_not() +{ + int i; + int cows=0, bulls=0; + + for(i=0; i < 4; i++) { + if ( number[i] == guess[i] ) { + bulls++; + } else if ( strchr(number, guess[i]) != NULL ) { + cows++; + } + } + move(yp, xp); + addstr(guess); addch(' '); + if ( bulls == 4 ) { yp++; return true; } + if ( (cows==0) && (bulls==0) ) addch('-'); + while( cows-- > 0 ) addstr("O"); + while( bulls-- > 0 ) addstr("X"); + yp++; + if ( yp > LAST_LINE ) { + yp = LINE_BEGIN; + xp += 10; + } + return false; +} + +bool ask_play_again() +{ + int i; + + while(yp-- >= LINE_BEGIN) { + move(yp, 0); clrtoeol(); + } + yp = LINE_BEGIN; xp = 0; + + move(21,0); clrtoeol(); + addstr("Do you want to play again? [y/n]"); + while(true) { + int a = getch(); + switch(a) { + case 'y': + case 'Y': + return true; + case 'n': + case 'N': + return false; + } + } +} + + +int main() +{ + bool bingo, again; + int tries = 0; + + initscr(); cbreak(); noecho(); + clear(); + + number[4] = guess[4] = 0; + + mvaddstr(0,0, "I choose a number made of 4 digits (from 1 to 9) without repetitions\n" + "You enter a number of 4 digits, and I say you how many of them are\n" + "in my secret number but in wrong position (cows or O), and how many\n" + "are in the right position (bulls or X)"); + do { + move(20,0); clrtoeol(); move(21, 0); clrtoeol(); + srand(time(NULL)); + choose_the_number(); + do { + ask_for_a_number(); + bingo = take_it_or_not(); + tries++; + } while(!bingo && (tries < MAX_NUM_TRIES)); + if ( bingo ) + mvaddstrf(20, 0, "You guessed %s correctly in %d attempts!", number, tries); + else + mvaddstrf(20,0, "Sorry, you had only %d tries...; the number was %s", + MAX_NUM_TRIES, number); + again = ask_play_again(); + tries = 0; + } while(again); + nocbreak(); echo(); endwin(); + return EXIT_SUCCESS; +} diff --git a/Task/Bulls_and_cows/C/bulls_and_cows.c b/Task/Bulls_and_cows/C/bulls_and_cows.c new file mode 100644 index 0000000000..8affa9b80e --- /dev/null +++ b/Task/Bulls_and_cows/C/bulls_and_cows.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include + +#define MAX_NUM_TRIES 72 +#define LINE_BEGIN 7 +#define LAST_LINE 18 + +int yp=LINE_BEGIN, xp=0; + +char number[5]; +char guess[5]; + +#define MAX_STR 256 +void mvaddstrf(int y, int x, const char *fmt, ...) +{ + va_list args; + char buf[MAX_STR]; + + va_start(args, fmt); + vsprintf(buf, fmt, args); + move(y, x); + clrtoeol(); + addstr(buf); + va_end(args); +} + +void ask_for_a_number() +{ + int i=0; + char symbols[] = "123456789"; + + move(5,0); clrtoeol(); + addstr("Enter four digits: "); + while(i<4) { + int c = getch(); + if ( (c >= '1') && (c <= '9') && (symbols[c-'1']!=0) ) { + addch(c); + symbols[c-'1'] = 0; + guess[i++] = c; + } + } +} + +void choose_the_number() +{ + int i=0, j; + char symbols[] = "123456789"; + + while(i<4) { + j = rand() % 9; + if ( symbols[j] != 0 ) { + number[i++] = symbols[j]; + symbols[j] = 0; + } + } +} diff --git a/Task/Bulls_and_cows/Clojure/bulls_and_cows.clj b/Task/Bulls_and_cows/Clojure/bulls_and_cows.clj new file mode 100644 index 0000000000..0e85f77c1b --- /dev/null +++ b/Task/Bulls_and_cows/Clojure/bulls_and_cows.clj @@ -0,0 +1,38 @@ +(ns bulls-and-cows) + +(defn bulls [guess solution] + (count (filter true? (map = guess solution)))) + +(defn cows [guess solution] + (- + (count (filter (set solution) guess)) + (bulls guess solution))) + +(defn valid-input? + "checks whether the string is a 4 digit number with unique digits" + [user-input] + (if (re-seq #"^(?!.*(\d).*\1)\d{4}$" user-input) + true + false)) + +(defn enter-guess [] + "Let the user enter a guess. Verify the input. Repeat until valid. +returns a list of digits enters by the user (# # # #)" + (println "Enter your guess: ") + (let [guess (read-line)] + (if (valid-input? guess) + (map #(Character/digit % 10) guess) + (recur)))) + +(defn bulls-and-cows [] + "generate a random 4 digit number from the list of (1 ... 9): no repeating digits +player tries to guess the number with bull and cows rules gameplay" + (let [solution ( take 4 (shuffle (range 1 10)))] + (println "lets play some bulls and cows!") + (loop [guess (enter-guess)] + (println (bulls guess solution) " bulls and " (cows guess solution) " cows.") + (if (not= guess solution) + (recur (enter-guess)) + (println "You have won!"))))) + +(bulls-and-cows) diff --git a/Task/Bulls_and_cows/Erlang/bulls_and_cows-2.erl b/Task/Bulls_and_cows/Erlang/bulls_and_cows-2.erl new file mode 100644 index 0000000000..741984f471 --- /dev/null +++ b/Task/Bulls_and_cows/Erlang/bulls_and_cows-2.erl @@ -0,0 +1,3 @@ +#!/usr/bin/escript +% Play Bulls and Cows +main(_) -> random:seed(now()), bulls_and_cows:play(). diff --git a/Task/Bulls_and_cows/Erlang/bulls_and_cows.erl b/Task/Bulls_and_cows/Erlang/bulls_and_cows.erl new file mode 100644 index 0000000000..556ab3ff9f --- /dev/null +++ b/Task/Bulls_and_cows/Erlang/bulls_and_cows.erl @@ -0,0 +1,45 @@ +-module(bulls_and_cows). +-export([generate_secret/0, score_guess/2, play/0]). + +% generate the secret code +generate_secret() -> generate_secret([], 4, lists:seq(1,9)). +generate_secret(Secret, 0, _) -> Secret; +generate_secret(Secret, N, Digits) -> + Next = lists:nth(random:uniform(length(Digits)), Digits), + generate_secret(Secret ++ [Next], N - 1, Digits -- [Next]). + +% evaluate a guess +score_guess(Secret, Guess) + when length(Secret) =/= length(Guess) -> throw(badguess); +score_guess(Secret, Guess) -> + Bulls = count_bulls(Secret,Guess), + Cows = count_cows(Secret, Guess, Bulls), + [Bulls, Cows]. + +% count bulls (exact matches) +count_bulls(Secret, Guess) -> + length(lists:filter(fun(I) -> lists:nth(I,Secret) == lists:nth(I,Guess) end, + lists:seq(1, length(Secret)))). + +% count cows (digits present but out of place) +count_cows(Secret, Guess, Bulls) -> + length(lists:filter(fun(I) -> lists:member(I, Guess) end, Secret)) - Bulls. + +% play a game +play() -> play_round(generate_secret()). + +play_round(Secret) -> play_round(Secret, read_guess()). + +play_round(Secret, Guess) -> + play_round(Secret, Guess, score_guess(Secret,Guess)). + +play_round(_, _, [4,0]) -> + io:put_chars("Correct!\n"); + +play_round(Secret, _, Score) -> + io:put_chars("\tbulls:"), io:write(hd(Score)), io:put_chars(", cows:"), + io:write(hd(tl(Score))), io:put_chars("\n"), play_round(Secret). + +read_guess() -> + lists:map(fun(D)->D-48 end, + lists:sublist(io:get_line("Enter your 4-digit guess: "), 4)). diff --git a/Task/Bulls_and_cows/Forth/bulls_and_cows.fth b/Task/Bulls_and_cows/Forth/bulls_and_cows.fth new file mode 100644 index 0000000000..832085c7d5 --- /dev/null +++ b/Task/Bulls_and_cows/Forth/bulls_and_cows.fth @@ -0,0 +1,37 @@ +include random.fs + +create hidden 4 allot + +: ok? ( str -- ? ) + dup 4 <> if 2drop false exit then + 1 9 lshift 1- -rot + bounds do + i c@ '1 - + dup 0 9 within 0= if 2drop false leave then + 1 swap lshift over and + dup 0= if nip leave then + xor + loop 0<> ; + +: init + begin + hidden 4 bounds do 9 random '1 + i c! loop + hidden 4 ok? + until ; + +: check? ( addr -- solved? ) + 0 + 4 0 do + over i + c@ + 4 0 do + dup hidden i + c@ = if swap + i j = if 8 else 1 then + swap + then + loop drop + loop nip + 8 /mod tuck . ." bulls, " . ." cows" + 4 = ; + +: guess: ( "1234" -- ) + bl parse 2dup ok? 0= if 2drop ." Bad guess! (4 unique digits, 1-9)" exit then + drop check? if cr ." You guessed it!" then ; diff --git a/Task/Bulls_and_cows/Fortran/bulls_and_cows.f b/Task/Bulls_and_cows/Fortran/bulls_and_cows.f new file mode 100644 index 0000000000..f2d10f6c9e --- /dev/null +++ b/Task/Bulls_and_cows/Fortran/bulls_and_cows.f @@ -0,0 +1,84 @@ +module bac + implicit none + +contains + + subroutine Gennum(n) + integer, intent(out) :: n(4) + integer :: i, j + real :: r + + call random_number(r) + n(1) = int(r * 9.0) + 1 + i = 2 + +outer: do while (i <= 4) + call random_number(r) + n(i) = int(r * 9.0) + 1 +inner: do j = i-1 , 1, -1 + if (n(j) == n(i)) cycle outer + end do inner + i = i + 1 + end do outer + + end subroutine Gennum + + subroutine Score(n, guess, b, c) + character(*), intent(in) :: guess + integer, intent(in) :: n(0:3) + integer, intent(out) :: b, c + integer :: digit, i, j, ind + + b = 0; c = 0 + do i = 1, 4 + read(guess(i:i), "(i1)") digit + if (digit == n(i-1)) then + b = b + 1 + else + do j = i, i+2 + ind = mod(j, 4) + if (digit == n(ind)) then + c = c + 1 + exit + end if + end do + end if + end do + + end subroutine Score + +end module bac + +program Bulls_and_Cows + use bac + implicit none + + integer :: n(4) + integer :: bulls=0, cows=0, tries=0 + character(4) :: guess + + call random_seed + call Gennum(n) + + write(*,*) "I have selected a number made up of 4 digits (1-9) without repetitions." + write(*,*) "You attempt to guess this number." + write(*,*) "Every digit in your guess that is in the correct position scores 1 Bull" + write(*,*) "Every digit in your guess that is in an incorrect position scores 1 Cow" + write(*,*) + + do while (bulls /= 4) + write(*,*) "Enter a 4 digit number" + read*, guess + if (verify(guess, "123456789") /= 0) then + write(*,*) "That is an invalid entry. Please try again." + cycle + end if + tries = tries + 1 + call Score (n, guess, bulls, cows) + write(*, "(a, i1, a, i1, a)") "You scored ", bulls, " bulls and ", cows, " cows" + write(*,*) + end do + + write(*,"(a,i0,a)") "Congratulations! You correctly guessed the correct number in ", tries, " attempts" + +end program Bulls_and_Cows diff --git a/Task/Bulls_and_cows/Go/bulls_and_cows-2.go b/Task/Bulls_and_cows/Go/bulls_and_cows-2.go new file mode 100644 index 0000000000..7af3905e62 --- /dev/null +++ b/Task/Bulls_and_cows/Go/bulls_and_cows-2.go @@ -0,0 +1,117 @@ +package main + +import ( + . "fmt" + "rand" + "time" + "os" + "bufio" + "strconv" + "strings" +) + +func generateTarget() int { + rand.Seed(time.Nanoseconds()) + // loop until we find a number that doesn't have dupes + for { + target := rand.Intn(9000) + 1000 + if !hasDupes(target) { + return target + } + } + panic("Crap.") +} + +func hasDupes(num int) bool { + digs := make([]bool, 10) + for num > 0 { + if digs[num%10] { + return true + } + digs[num%10] = true + num /= 10 + } + return false +} + +func askForNumber() (int, os.Error) { + in := bufio.NewReader(os.Stdin) + + for { + Print("Give me a number: ") + line, err := in.ReadString('\n') + + if err != nil { + return -1, err + } + + // Strip off the \n + line = line[0 : len(line)-1] + number, err := strconv.Atoi(line) + + switch { + case err != nil: + Println("Give me a number fule!") + case number < 1000: + Println("Number not long enough") + case number > 9999: + Println("Number is to big") + case hasDupes(number): + Println("I said no dupes!") + default: + return number, nil + } + // Keep Asking + } + panic("Crap.") +} + +func bullsAndCows(number int, guess int) (bulls int, cows int) { + bulls, cows = 0, 0 + numberstr := strconv.Itoa(number) + guessstr := strconv.Itoa(guess) + + for i := range guessstr { + s := string(guessstr[i]) + switch { + case guessstr[i] == numberstr[i]: + bulls++ + case strings.Index(numberstr, s) >= 0: + cows++ + } + } + return; +} + +func main() { + attempts := 0 + + Print("I choose a number made of 4 digits (from 1 to 9) without repetitions\n" + "You enter a number of 4 digits, and I say you how many of them are\n" + "in my secret number but in wrong position (cows or O), and how many\n" + "are in the right position (bulls or X)\n\n") + + target := generateTarget() + + for { + guess, err := askForNumber() + attempts++ + + // Handle err + if err != nil && err != os.EOF { + Print(err) + } else if err == os.EOF { + return + } + + // Check if target matches guess + if guess == target { + Printf("Congratulations you guessed correctly in %d attempts\n", attempts) + return + } + + bulls, cows := bullsAndCows(target, guess) + Printf("%d Bulls, %d Cows\n", bulls, cows) + } + +} diff --git a/Task/Bulls_and_cows/Go/bulls_and_cows.go b/Task/Bulls_and_cows/Go/bulls_and_cows.go new file mode 100644 index 0000000000..a4b59f82ad --- /dev/null +++ b/Task/Bulls_and_cows/Go/bulls_and_cows.go @@ -0,0 +1,68 @@ +package main + +import ( + "bufio" + "bytes" + "fmt" + "math/rand" + "os" + "strings" + "time" +) + +func main() { + fmt.Println(`Cows and Bulls +Guess four digit number of unique digits in the range 1 to 9. +A correct digit but not in the correct place is a cow. +A correct digit in the correct place is a bull.`) + // generate pattern + pat := make([]byte, 4) + rand.Seed(time.Now().Unix()) + r := rand.Perm(9) + for i := range pat { + pat[i] = '1' + byte(r[i]) + } + + // accept and score guesses + valid := []byte("123456789") +guess: + for in := bufio.NewReader(os.Stdin); ; { + fmt.Print("Guess: ") + guess, err := in.ReadString('\n') + if err != nil { + fmt.Println("\nSo, bye.") + return + } + guess = strings.TrimSpace(guess) + if len(guess) != 4 { + // malformed: not four characters + fmt.Println("Please guess a four digit number.") + continue + } + var cows, bulls int + for ig, cg := range guess { + if strings.IndexRune(guess[:ig], cg) >= 0 { + // malformed: repeated digit + fmt.Printf("Repeated digit: %c\n", cg) + continue guess + } + switch bytes.IndexByte(pat, byte(cg)) { + case -1: + if bytes.IndexByte(valid, byte(cg)) == -1 { + // malformed: not a digit + fmt.Printf("Invalid digit: %c\n", cg) + continue guess + } + default: // I just think cows should go first + cows++ + case ig: + bulls++ + } + } + fmt.Printf("Cows: %d, bulls: %d\n", cows, bulls) + if bulls == 4 { + fmt.Println("You got it.") + return + } + } +} diff --git a/Task/Bulls_and_cows/Haskell/bulls_and_cows.hs b/Task/Bulls_and_cows/Haskell/bulls_and_cows.hs new file mode 100644 index 0000000000..f1bd9b99ba --- /dev/null +++ b/Task/Bulls_and_cows/Haskell/bulls_and_cows.hs @@ -0,0 +1,50 @@ +import Data.List (partition, intersect, nub) +import Control.Monad +import System.Random (StdGen, getStdRandom, randomR) +import Text.Printf + +numberOfDigits = 4 :: Int + +main = bullsAndCows + +bullsAndCows :: IO () +bullsAndCows = do + digits <- getStdRandom $ pick numberOfDigits ['1' .. '9'] + putStrLn "Guess away!" + loop digits + + where loop digits = do + input <- getLine + if okay input + then + let (bulls, cows) = score digits input in + if bulls == numberOfDigits then + putStrLn "You win!" + else do + printf "%d bulls, %d cows.\n" bulls cows + loop digits + else do + putStrLn "Malformed guess; try again." + loop digits + + okay :: String -> Bool + okay input = + length input == numberOfDigits && + input == nub input && + all legalchar input + where legalchar c = '1' <= c && c <= '9' + + score :: String -> String -> (Int, Int) + score secret guess = (length bulls, cows) + where (bulls, nonbulls) = partition (uncurry (==)) $ + zip secret guess + cows = length $ uncurry intersect $ unzip nonbulls + +pick :: Int -> [a] -> StdGen -> ([a], StdGen) +{- Randomly selects items from a list without replacement. -} +pick n l g = f n l g (length l - 1) [] + where f 0 _ g _ ps = (ps, g) + f n l g max ps = + f (n - 1) (left ++ right) g' (max - 1) (picked : ps) + where (i, g') = randomR (0, max) g + (left, picked : right) = splitAt i l diff --git a/Task/Bulls_and_cows/Java/bulls_and_cows.java b/Task/Bulls_and_cows/Java/bulls_and_cows.java new file mode 100644 index 0000000000..73343ba591 --- /dev/null +++ b/Task/Bulls_and_cows/Java/bulls_and_cows.java @@ -0,0 +1,52 @@ +import java.util.InputMismatchException; +import java.util.Random; +import java.util.Scanner; + +public class BullsAndCows{ + public static void main(String[] args){ + Random gen= new Random(); + int target= 0; + while(hasDupes(target= (gen.nextInt(9000) + 1000))); + String targetStr = target +""; + boolean guessed = false; + Scanner input = new Scanner(System.in); + int guesses = 0; + do{ + int bulls = 0; + int cows = 0; + System.out.print("Guess a 4-digit number with no duplicate digits: "); + int guess; + try{ + guess = input.nextInt(); + if(hasDupes(guess) || guess < 1000) continue; + }catch(InputMismatchException e){ + continue; + } + guesses++; + String guessStr = guess + ""; + for(int i= 0;i < 4;i++){ + if(guessStr.charAt(i) == targetStr.charAt(i)){ + bulls++; + }else if(targetStr.contains(guessStr.charAt(i)+"")){ + cows++; + } + } + if(bulls == 4){ + guessed = true; + }else{ + System.out.println(cows+" Cows and "+bulls+" Bulls."); + } + }while(!guessed); + System.out.println("You won after "+guesses+" guesses!"); + } + + public static boolean hasDupes(int num){ + boolean[] digs = new boolean[10]; + while(num > 0){ + if(digs[num%10]) return true; + digs[num%10] = true; + num/= 10; + } + return false; + } +} diff --git a/Task/Bulls_and_cows/JavaScript/bulls_and_cows.js b/Task/Bulls_and_cows/JavaScript/bulls_and_cows.js new file mode 100644 index 0000000000..8d2e618a10 --- /dev/null +++ b/Task/Bulls_and_cows/JavaScript/bulls_and_cows.js @@ -0,0 +1,88 @@ +#!/usr/bin/env js + +function main() { + var len = 4; + playBullsAndCows(len); +} + +function playBullsAndCows(len) { + var num = pickNum(len); + // print('The secret number is:\n ' + num.join('\n ')); + showInstructions(len); + var nGuesses = 0; + while (true) { + nGuesses++; + var guess = getGuess(nGuesses, len); + var census = countBovine(num, guess); + showScore(census.bulls, census.cows); + if (census.bulls == len) { + showFinalResult(nGuesses); + return; + } + } +} + +function showScore(nBulls, nCows) { + print(' Bulls: ' + nBulls + ', cows: ' + nCows); +} + +function showFinalResult(guesses) { + print('You win!!! Guesses needed: ' + guesses); +} + +function countBovine(num, guess) { + var count = {bulls:0, cows:0}; + var g = guess.join(''); + for (var i = 0; i < num.length; i++) { + var digPresent = g.search(num[i]) != -1; + if (num[i] == guess[i]) count.bulls++; + else if (digPresent) count.cows++; + } + return count; +} + +function getGuess(nGuesses, len) { + while (true) { + putstr('Your guess #' + nGuesses + ': '); + var guess = readline(); + guess = String(parseInt(guess)).split(''); + if (guess.length != len) { + print(' You must enter a ' + len + ' digit number.'); + continue; + } + if (hasDups(guess)) { + print(' No digits can be duplicated.'); + continue; + } + return guess; + } +} + +function hasDups(ary) { + var t = ary.concat().sort(); + for (var i = 1; i < t.length; i++) { + if (t[i] == t[i-1]) return true; + } + return false; +} + +function showInstructions(len) { + print(); + print('Bulls and Cows Game'); + print('-------------------'); + print(' You must guess the ' + len + ' digit number I am thinking of.'); + print(' The number is composed of the digits 1-9.'); + print(' No digit appears more than once.'); + print(' After each of your guesses, I will tell you:'); + print(' The number of bulls (digits in right place)'); + print(' The number of cows (correct digits, but in the wrong place)'); + print(); +} + +function pickNum(len) { + var nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + nums.sort(function(){return Math.random() - 0.5}); + return nums.slice(0, len); +} + +main(); diff --git a/Task/Bulls_and_cows/Lua/bulls_and_cows.lua b/Task/Bulls_and_cows/Lua/bulls_and_cows.lua new file mode 100644 index 0000000000..6e3da09235 --- /dev/null +++ b/Task/Bulls_and_cows/Lua/bulls_and_cows.lua @@ -0,0 +1,101 @@ +function ShuffleArray(array) + for i=1,#array-1 do + local t = math.random(i, #array) + array[i], array[t] = array[t], array[i] + end +end + +function GenerateNumber() + local digits = {1,2,3,4,5,6,7,8,9} + + ShuffleArray(digits) + + return digits[1] * 1000 + + digits[2] * 100 + + digits[3] * 10 + + digits[4] +end + +function IsMalformed(input) + local malformed = false + + if #input == 4 then + local already_used = {} + for i=1,4 do + local digit = input:byte(i) - string.byte('0') + if digit < 1 or digit > 9 or already_used[digit] then + malformed = true + break + end + already_used[digit] = true + end + else + malformed = true + end + + return malformed +end + +math.randomseed(os.time()) +math.randomseed(math.random(2^31-1)) -- since os.time() only returns seconds + +print("\nWelcome to Bulls and Cows!") +print("") +print("The object of this game is to guess the random 4-digit number that the") +print("computer has chosen. The number is generated using only the digits 1-9,") +print("with no repeated digits. Each time you enter a guess, you will score one") +print("\"bull\" for each digit in your guess that matches the corresponding digit") +print("in the computer-generated number, and you will score one \"cow\" for each") +print("digit in your guess that appears in the computer-generated number, but is") +print("in the wrong position. Use this information to refine your guesses. When") +print("you guess the correct number, you win."); +print("") + +quit = false + +repeat + magic_number = GenerateNumber() + magic_string = tostring(magic_number) -- Easier to do scoring with a string + repeat + io.write("\nEnter your guess (or 'Q' to quit): ") + user_input = io.read() + if user_input == 'Q' or user_input == 'q' then + quit = true + break + end + + if not IsMalformed(user_input) then + if user_input == magic_string then + print("YOU WIN!!!") + else + local bulls, cows = 0, 0 + for i=1,#user_input do + local find_result = magic_string:find(user_input:sub(i,i)) + + if find_result and find_result == i then + bulls = bulls + 1 + elseif find_result then + cows = cows + 1 + end + end + print(string.format("You scored %d bulls, %d cows", bulls, cows)) + end + else + print("Malformed input. You must enter a 4-digit number with") + print("no repeated digits, using only the digits 1-9.") + end + + until user_input == magic_string + + if not quit then + io.write("\nPress to play again or 'Q' to quit: ") + user_input = io.read() + if user_input == 'Q' or user_input == 'q' then + quit = true + end + end + + if quit then + print("\nGoodbye!") + end +until quit diff --git a/Task/Bulls_and_cows/PHP/bulls_and_cows.php b/Task/Bulls_and_cows/PHP/bulls_and_cows.php new file mode 100644 index 0000000000..062f5d4f43 --- /dev/null +++ b/Task/Bulls_and_cows/PHP/bulls_and_cows.php @@ -0,0 +1,40 @@ + diff --git a/Task/Bulls_and_cows/Perl/bulls_and_cows.pl b/Task/Bulls_and_cows/Perl/bulls_and_cows.pl new file mode 100644 index 0000000000..3013aac343 --- /dev/null +++ b/Task/Bulls_and_cows/Perl/bulls_and_cows.pl @@ -0,0 +1,39 @@ +use Data::Random qw(rand_set); +use List::MoreUtils qw(uniq); + +my $size = 4; +my $chosen = join "", rand_set set => ["1".."9"], size => $size; + +print "I've chosen a number from $size unique digits from 1 to 9; you need +to input $size unique digits to guess my number\n"; + +for ( my $guesses = 1; ; $guesses++ ) { + my $guess; + while (1) { + print "\nNext guess [$guesses]: "; + $guess = ; + chomp $guess; + checkguess($guess) and last; + print "$size digits, no repetition, no 0... retry\n"; + } + if ( $guess eq $chosen ) { + print "You did it in $guesses attempts!\n"; + last; + } + my $bulls = 0; + my $cows = 0; + for my $i (0 .. $size-1) { + if ( substr($guess, $i, 1) eq substr($chosen, $i, 1) ) { + $bulls++; + } elsif ( index($chosen, substr($guess, $i, 1)) >= 0 ) { + $cows++; + } + } + print "$cows cows, $bulls bulls\n"; +} + +sub checkguess +{ + my $g = shift; + return uniq(split //, $g) == $size && $g =~ /^[1-9]{$size}$/; +} diff --git a/Task/Bulls_and_cows/PicoLisp/bulls_and_cows.l b/Task/Bulls_and_cows/PicoLisp/bulls_and_cows.l new file mode 100644 index 0000000000..07a22dc71e --- /dev/null +++ b/Task/Bulls_and_cows/PicoLisp/bulls_and_cows.l @@ -0,0 +1,20 @@ +(de ok? (N) + (let D (mapcar 'format (chop N)) + (and (num? N) + (not (member 0 D)) + (= 4 (length D)) + (= D (uniq D)) + D )) ) + +(de init-cows () + (until (setq *Hidden (ok? (rand 1234 9876)))) ) + +(de guess (N) + (let D (ok? N) + (if D + (let Bulls (cnt '= D *Hidden) + (if (= 4 Bulls) + " You guessed it!" + (let Cows (- (cnt '((N) (member N *Hidden)) D) Bulls) + (pack Bulls " bulls, " Cows " cows") ) ) ) + " Bad guess! (4 unique digits, 1-9)" ) ) ) diff --git a/Task/Bulls_and_cows/Python/bulls_and_cows.py b/Task/Bulls_and_cows/Python/bulls_and_cows.py new file mode 100644 index 0000000000..e5f2850c15 --- /dev/null +++ b/Task/Bulls_and_cows/Python/bulls_and_cows.py @@ -0,0 +1,33 @@ +''' + Bulls and cows. A game pre-dating, and similar to, Mastermind. +''' + +import random + +digits = '123456789' +size = 4 +chosen = ''.join(random.sample(digits,size)) +#print chosen # Debug +print '''I have chosen a number from %s unique digits from 1 to 9 arranged in a random order. +You need to input a %i digit, unique digit number as a guess at what I have chosen''' % (size, size) +guesses = 0 +while True: + guesses += 1 + while True: + # get a good guess + guess = raw_input('\nNext guess [%i]: ' % guesses).strip() + if len(guess) == size and \ + all(char in digits for char in guess) \ + and len(set(guess)) == size: + break + print "Problem, try again. You need to enter %i unique digits from 1 to 9" % size + if guess == chosen: + print '\nCongratulations you guessed correctly in',guesses,'attempts' + break + bulls = cows = 0 + for i in range(size): + if guess[i] == chosen[i]: + bulls += 1 + elif guess[i] in chosen: + cows += 1 + print ' %i Bulls\n %i Cows' % (bulls, cows) diff --git a/Task/Bulls_and_cows/REXX/bulls_and_cows-2.rexx b/Task/Bulls_and_cows/REXX/bulls_and_cows-2.rexx new file mode 100644 index 0000000000..6218e0bfe5 --- /dev/null +++ b/Task/Bulls_and_cows/REXX/bulls_and_cows-2.rexx @@ -0,0 +1,101 @@ +/*REXX program to play the game of "Bulls & Cows". ******************* +* Changes from Version 1: +* ?= -> qq='' (righthandside mandatory and I never use ? as symbol - +* although it is available on all Rexxes) +* implemented singular/plural distinction differently +* change getRand to avoid invalid digit rejection +* check user's input for multiple digits +* add feature MM to ease guessing (MM=Mastermind - a similar game) +* add feature ? to see the solution (for the impatient player) +* program runs as is on ooRexx and on TSO (after changing | to !) +* Made source and output more compact +* formatted source 'my way' 2 July 2012 Walter Pachl +**********************************************************************/ +ask=' Please enter a four-digit guess (or QUIT):' + +b.='bulls'; b.1='bull' +c.='cows'; c.1='cow' +qq=getRand() +mm=0 +Do Forever + If get_guess()==qq Then leave + Call scorer + Say "You got" bulls b.bulls "and" cows c.cows"." + If mm Then + Say mms + End /*forever*/ +Say " *******************************************" +Say " * *" +Say " * Congratulations, you've guessed it !! *" +Say " * *" +Say " *******************************************" +Exit + +get_guess: /*get a guess from the guesser. */ + +do forever + Say ask + Parse Pull guessi + guess=translate(guessi) + bc=verify(guess,987654321) + Select + When guess='?' Then Say qq 'is the correct sequence' + When guess='QUIT' Then Exit + When guess='MM' Then Do + Say 'Mastermind output enabled' + mm=1 + End + When guess='' Then Call ser 'no argument specified.' + When words(guess)>1 Then Call ser 'too many arguments specified.' + When verify(0,guess)=0 Then Call ser 'illegal digit: 0' + When bc>0 Then Call ser 'illegal character:' substr(guessi,bc,1) + When length(guess)<4 Then Call ser 'not enough digits' + When length(guess)>4 Then Call ser 'too many digits' + When dups(guess) Then Call ser '4 DIFFERENT digits, please' + Otherwise Do + /********** Say guess ************/ + Return guess + End + End + End + +getRand: +digits='123456789' +qq='' +Do i=1 To 4 + d=random(1,length(digits)) + d=substr(digits,d,1) + qq=qq||d + digits=space(translate(digits,' ',d),0) + /************ Say qq digits ************/ + End +Return qq + +scorer: g=qq +mms='----' +bulls=0 +Do j=1 for 4 + If substr(guess,j,1)=substr(qq,j,1) Then Do + bulls=bulls+1 + guess=overlay(' ',guess,j) + mms=overlay('+',mms,j) + End + End +cows=0 +Do j=1 To 4 + If pos(substr(guess,j,1),qq)>0 Then Do + cows=cows+1 + mms=overlay('.',mms,j) + End + End +Return + +dups: Procedure +Parse Arg s +Do i=1 To 3 + If pos(substr(s,i,1),substr(s,i+1))>0 Then + Return 1 + End +Return 0 + +ser: Say '*** error ***' arg(1); Return diff --git a/Task/Bulls_and_cows/REXX/bulls_and_cows.rexx b/Task/Bulls_and_cows/REXX/bulls_and_cows.rexx new file mode 100644 index 0000000000..331dd637c4 --- /dev/null +++ b/Task/Bulls_and_cows/REXX/bulls_and_cows.rexx @@ -0,0 +1,43 @@ +/*REXX pgm interactively plays a game of "Bulls & Cows" with CBLs. */ +/* [CBLs = Carbon Based Lifeforms.] */ +/* */ +/* This game is also known as: Cows and Bulls */ +/* Pigs and Bulls */ +/* Bulls and Cleots */ +/* MasterMind (or Master Mind) */ +/*══════════════════════════════════════════════════════════════════════*/ +?=''; do until length(?)==4 /*generate unique 4-digit number.*/ + r=random(1,9) /*change 1──►0 to allow a 0 dig*/ + if pos(r,?)\==0 then iterate /*don't allow a repeated digit. */ + ?=? || r + end /*until*/ + +prompt='[Bulls & Cows game] ', /*build the prompt text string. */ + "Please enter a 4-digit guess (with no zeroes) [or Quit]:" + + do until bulls==4 /*play until guessed |enters QUIT*/ + say prompt; pull n; n=space(n,0); if n=='' then iterate + if abbrev('QUIT',n,1) then exit /*Does the user want to quit now?*/ + g=?; L=length(n); bulls=0; cows=0 + /*bull count─────────────────────*/ + do j=1 for L; if substr(n,j,1)\==substr(g,j,1) then iterate + bulls=bulls+1 /*bump the bull count. */ + g=overlay(' ',g,j) /*disallow this for a cow count. */ + end /*j*/ + /*cow count─────────────────────*/ + do k=1 for L; x=substr(n,k,1); if pos(x,g)==0 then iterate + cows=cows+1 /*bump the cow count. */ + g=translate(g,,x) /*this allows for rule variants. */ + end /*k*/ + + if bulls\==4 then say "───── You got" bulls 'bull's(bulls) "and" cows 'cow's(cows)"." + end /*until bulls==4*/ + +say; say " ┌─────────────────────────────────────────┐" + say " │ │" + say " │ Congratulations, you've guessed it !! │" + say " │ │" + say " └─────────────────────────────────────────┘"; say +exit +/*──────────────────────────────────S subroutine────────────────────────*/ +s: if arg(1)==1 then return ''; return 's' diff --git a/Task/Bulls_and_cows/Ruby/bulls_and_cows.rb b/Task/Bulls_and_cows/Ruby/bulls_and_cows.rb new file mode 100644 index 0000000000..f8bc7a4452 --- /dev/null +++ b/Task/Bulls_and_cows/Ruby/bulls_and_cows.rb @@ -0,0 +1,44 @@ +def generate_word(len) + ([1, 2, 3, 4, 5, 6, 7, 8, 9].shuffle)[0,len].join("") +end + +def get_guess(len) + while true + print "Enter a guess: " + guess = gets.strip + err = case + when guess.match(/\D/) : "digits only" + when guess.length != len : "exactly #{len} digits" + when guess.split("").uniq.length != len: "digits must be unique " + else nil + end + break if err.nil? + puts "the word must be #{len} unique digits between 1 and 9 (#{err}). Try again." + end + guess +end + +def score(word, guess) + bulls = cows = 0 + guess.bytes.each_with_index do |byte, idx| + if word[idx] == byte + bulls += 1 + elsif word.include? byte + cows += 1 + end + end + [bulls, cows] +end + +srand +word_length = 4 +puts "I have chosen a number with #{word_length} unique digits from 1 to 9." +word = generate_word(word_length) +count = 0 +while true + guess = get_guess(word_length) + count += 1 + break if word == guess + puts "that guess has %d bulls and %d cows" % score(word, guess) +end +puts "you guessed correctly in #{count} tries." diff --git a/Task/Bulls_and_cows/Scala/bulls_and_cows.scala b/Task/Bulls_and_cows/Scala/bulls_and_cows.scala new file mode 100644 index 0000000000..d0d2da6e50 --- /dev/null +++ b/Task/Bulls_and_cows/Scala/bulls_and_cows.scala @@ -0,0 +1,42 @@ +import scala.util.Random + +object BullCow { + def main(args: Array[String]): Unit = { + val number=chooseNumber + var guessed=false + var guesses=0 + + while(!guessed){ + Console.print("Guess a 4-digit number with no duplicate digits: ") + val input=Console.readInt + val digits=input.toString.map(_.asDigit).toList + if(input>=1111 && input<=9999 && !hasDups(digits)){ + guesses+=1 + var bulls, cows=0 + for(i <- 0 to 3) + if(number(i)==digits(i)) + bulls+=1 + else if(number.contains(digits(i))) + cows+=1 + + if(bulls==4) + guessed=true + else + println("%d Cows and %d Bulls.".format(cows, bulls)) + } + } + println("You won after "+guesses+" guesses!"); + } + + def chooseNumber={ + var digits=List[Int]() + while(digits.size<4){ + val d=Random.nextInt(9)+1 + if (!digits.contains(d)) + digits=digits:+d + } + digits + } + + def hasDups(input:List[Int])=input.size!=input.distinct.size +} diff --git a/Task/Bulls_and_cows/Tcl/bulls_and_cows.tcl b/Task/Bulls_and_cows/Tcl/bulls_and_cows.tcl new file mode 100644 index 0000000000..8003af180c --- /dev/null +++ b/Task/Bulls_and_cows/Tcl/bulls_and_cows.tcl @@ -0,0 +1,85 @@ +proc main {} { + fconfigure stdout -buffering none + set length 4 + + puts "I have chosen a number from $length unique digits from 1 to 9 arranged in a random order. +You need to input a $length digit, unique digit number as a guess at what I have chosen + " + + while true { + set word [generateWord $length] + set count 1 + while {[set guess [getGuess $length]] ne $word} { + printScore $length $word $guess + incr count + } + puts "You guessed correctly in $count tries." + if {[yn "Play again?"] eq "n"} break + } +} + +proc generateWord {length} { + set chars 123456789 + for {set i 1} {$i <= $length} {incr i} { + set idx [expr {int(rand() * [string length $chars])}] + append word [string index $chars $idx] + set chars [string replace $chars $idx $idx] + } + return $word + + # here's another way to generate word with no duplications + set word "" + while {[string length $word] < $length} { + set char [expr {int(1 + 9*rand())}] + if {[string first $char $word] == -1} { + append word $char + } + } +} + +proc getGuess {length} { + puts -nonewline "Enter your guess: " + while true { + gets stdin guess + if {[string match [string repeat {[1-9]} $length] $guess]} { + return $guess + } + if {[string tolower [string trim $guess]] eq "quit"} { + puts Bye + exit + } + puts "The word must be $length digits between 1 and 9 inclusive. Try again." + } +} + +proc printScore {length word guess} { + set bulls 0 + set cows 0 + for {set i 0} {$i < $length} {incr i} { + if {[string index $word $i] eq [string index $guess $i]} { + incr bulls + set word [string replace $word $i $i +] + } + } + puts " $bulls bulls" + for {set i 0} {$i < $length} {incr i} { + if {[set j [string first [string index $guess $i] $word]] != -1} { + incr cows + set word [string replace $word $j $j -] + } + } + puts " $cows cows" +} + +proc yn {msg} { + while true { + puts -nonewline "$msg \[y/n] " + gets stdin ans + set char [string tolower [string index [string trim $ans] 0]] + if {$char eq "y" || $char eq "n"} { + return $char + } + } +} + +main diff --git a/Task/Comments/0DESCRIPTION b/Task/Comments/0DESCRIPTION new file mode 100644 index 0000000000..44bd57d71d --- /dev/null +++ b/Task/Comments/0DESCRIPTION @@ -0,0 +1,4 @@ +Demonstrate all ways to include text in a language source file which is completely ignored by the compiler or interpreter. + +'''See Also:'''
+* [http://xkcd.com/156 xkcd] (Humor: hand gesture denoting // for "commenting out" people). diff --git a/Task/Comments/1META.yaml b/Task/Comments/1META.yaml new file mode 100644 index 0000000000..659c8686af --- /dev/null +++ b/Task/Comments/1META.yaml @@ -0,0 +1,2 @@ +--- +note: Basic language learning diff --git a/Task/Comments/4D/comments.4d b/Task/Comments/4D/comments.4d new file mode 100644 index 0000000000..31151ddee3 --- /dev/null +++ b/Task/Comments/4D/comments.4d @@ -0,0 +1 @@ +`Comments in 4th Dimension begin with the accent character and extend to the end of the line. diff --git a/Task/Comments/AWK/comments.awk b/Task/Comments/AWK/comments.awk new file mode 100644 index 0000000000..4203f46d4d --- /dev/null +++ b/Task/Comments/AWK/comments.awk @@ -0,0 +1,3 @@ +BEGIN { # this code does something + # do something +} diff --git a/Task/Comments/Befunge/comments-2.bf b/Task/Comments/Befunge/comments-2.bf new file mode 100644 index 0000000000..8bcdd8b8c3 --- /dev/null +++ b/Task/Comments/Befunge/comments-2.bf @@ -0,0 +1,6 @@ +&;read a number;2+;add two;.@;display result and exit; + ^- inline comments -^ <-^- other comments +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;completely isolated comment block for the paranoid; +;(almost - you can still skip into it.) ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/Task/Comments/Befunge/comments.bf b/Task/Comments/Befunge/comments.bf new file mode 100644 index 0000000000..1093ad850a --- /dev/null +++ b/Task/Comments/Befunge/comments.bf @@ -0,0 +1,2 @@ +& read a number 2+ add two .@ display result and exit + ^- inline comments -^ <-^- other comments diff --git a/Task/Comments/C/comments-2.c b/Task/Comments/C/comments-2.c new file mode 100644 index 0000000000..a0c57171eb --- /dev/null +++ b/Task/Comments/C/comments-2.c @@ -0,0 +1,2 @@ +struct charisma {}; +void f(char/* comment */isma) {} diff --git a/Task/Comments/C/comments-3.c b/Task/Comments/C/comments-3.c new file mode 100644 index 0000000000..6905cab980 --- /dev/null +++ b/Task/Comments/C/comments-3.c @@ -0,0 +1 @@ +/* some comment /* trying to nest some other comment */ inside */ diff --git a/Task/Comments/C/comments-4.c b/Task/Comments/C/comments-4.c new file mode 100644 index 0000000000..1c9fe8e2fc --- /dev/null +++ b/Task/Comments/C/comments-4.c @@ -0,0 +1,3 @@ +#if 0 +While technically not a comment, this is also ignored by the compiler +#endif diff --git a/Task/Comments/C/comments-5.c b/Task/Comments/C/comments-5.c new file mode 100644 index 0000000000..ab7c6f11b0 --- /dev/null +++ b/Task/Comments/C/comments-5.c @@ -0,0 +1,7 @@ +#ifdef UNDEFINED +This is not compiled. +#if 0 +Nor is this. +#endif +And this still is not compiled. +#endif diff --git a/Task/Comments/C/comments-6.c b/Task/Comments/C/comments-6.c new file mode 100644 index 0000000000..557854afed --- /dev/null +++ b/Task/Comments/C/comments-6.c @@ -0,0 +1,3 @@ +#if 0 +This isn't valid. +#endif diff --git a/Task/Comments/C/comments-7.c b/Task/Comments/C/comments-7.c new file mode 100644 index 0000000000..8037831e30 --- /dev/null +++ b/Task/Comments/C/comments-7.c @@ -0,0 +1 @@ +// C++ single-line comments were adopted in the C99 standard. diff --git a/Task/Comments/C/comments.c b/Task/Comments/C/comments.c new file mode 100644 index 0000000000..53d4557b7c --- /dev/null +++ b/Task/Comments/C/comments.c @@ -0,0 +1,4 @@ +/* This is a comment. */ +/* So is this + multiline comment. + */ diff --git a/Task/Comments/Clojure/comments-2.clj b/Task/Comments/Clojure/comments-2.clj new file mode 100644 index 0000000000..041235479e --- /dev/null +++ b/Task/Comments/Clojure/comments-2.clj @@ -0,0 +1 @@ +(comment (println (foo)) "bar" :baz 123 (System/exit 0)) ;; does nothing, returns nil diff --git a/Task/Comments/Clojure/comments-3.clj b/Task/Comments/Clojure/comments-3.clj new file mode 100644 index 0000000000..5916824bf4 --- /dev/null +++ b/Task/Comments/Clojure/comments-3.clj @@ -0,0 +1,2 @@ +(+ 1 (comment "foo") 3) ;; Throws an exception, because it tries to add nil to an integer +(+ 1 #_"foo" 3) ;; Returns 4 diff --git a/Task/Comments/Clojure/comments.clj b/Task/Comments/Clojure/comments.clj new file mode 100644 index 0000000000..9ede8de331 --- /dev/null +++ b/Task/Comments/Clojure/comments.clj @@ -0,0 +1,3 @@ +;; This is a comment +(defn foo [] + 123) ; also a comment diff --git a/Task/Comments/CoffeeScript/comments.coffee b/Task/Comments/CoffeeScript/comments.coffee new file mode 100644 index 0000000000..3668ad6603 --- /dev/null +++ b/Task/Comments/CoffeeScript/comments.coffee @@ -0,0 +1,5 @@ +# one line comment + +### multi +line +comment ### diff --git a/Task/Comments/Erlang/comments.erl b/Task/Comments/Erlang/comments.erl new file mode 100644 index 0000000000..36b1c08156 --- /dev/null +++ b/Task/Comments/Erlang/comments.erl @@ -0,0 +1 @@ +% Erlang comments begin with "%" and extend to the end of the line. diff --git a/Task/Comments/Forth/comments-2.fth b/Task/Comments/Forth/comments-2.fth new file mode 100644 index 0000000000..953c62b615 --- /dev/null +++ b/Task/Comments/Forth/comments-2.fth @@ -0,0 +1 @@ +: myword ( a b -- c ) ... diff --git a/Task/Comments/Forth/comments-3.fth b/Task/Comments/Forth/comments-3.fth new file mode 100644 index 0000000000..d1ed337bf4 --- /dev/null +++ b/Task/Comments/Forth/comments-3.fth @@ -0,0 +1,2 @@ +: add'em ( a b -- a+b ) + ; +: strlen ( addr -- len ) count nip ; diff --git a/Task/Comments/Forth/comments-4.fth b/Task/Comments/Forth/comments-4.fth new file mode 100644 index 0000000000..938a5a8b46 --- /dev/null +++ b/Task/Comments/Forth/comments-4.fth @@ -0,0 +1,11 @@ +\s skips all remaining text in the file +(( skips until the next double-paren, + stretching across multiple lines )) +comment: + Ignore all text in this section +comment; +doc + Another comment block +enddoc +/* C-style comment */ +(* Pascal-style comment *) diff --git a/Task/Comments/Forth/comments.fth b/Task/Comments/Forth/comments.fth new file mode 100644 index 0000000000..ca6ea27d69 --- /dev/null +++ b/Task/Comments/Forth/comments.fth @@ -0,0 +1,2 @@ +\ The backslash skips everything else on the line +( The left paren skips everything up to the next right paren on the same line) diff --git a/Task/Comments/Fortran/comments-2.f b/Task/Comments/Fortran/comments-2.f new file mode 100644 index 0000000000..f05620592e --- /dev/null +++ b/Task/Comments/Fortran/comments-2.f @@ -0,0 +1,2 @@ +C If compiled in debugging mode, print the current value of I +D PRINT *, I diff --git a/Task/Comments/Fortran/comments-3.f b/Task/Comments/Fortran/comments-3.f new file mode 100644 index 0000000000..640dcf5098 --- /dev/null +++ b/Task/Comments/Fortran/comments-3.f @@ -0,0 +1 @@ +real :: a = 0.0 ! initialize A to be zero diff --git a/Task/Comments/Fortran/comments-4.f b/Task/Comments/Fortran/comments-4.f new file mode 100644 index 0000000000..0e816bd2ee --- /dev/null +++ b/Task/Comments/Fortran/comments-4.f @@ -0,0 +1,7 @@ +?? if (.false.) then +do while (oh_no) + a = bad_news() + b = big_mistake() + c = gigo() +end do +?? end if diff --git a/Task/Comments/Fortran/comments.f b/Task/Comments/Fortran/comments.f new file mode 100644 index 0000000000..674c995170 --- /dev/null +++ b/Task/Comments/Fortran/comments.f @@ -0,0 +1,2 @@ +C This would be some kind of comment +C Usually one would avoid columns 2-6 even in a comment. diff --git a/Task/Comments/Go/comments.go b/Task/Comments/Go/comments.go new file mode 100644 index 0000000000..04f1d1718b --- /dev/null +++ b/Task/Comments/Go/comments.go @@ -0,0 +1,5 @@ +// this is a single line comment +/* this is + a multi-line + block comment. +/* It does not nest */ diff --git a/Task/Comments/Haskell/comments.hs b/Task/Comments/Haskell/comments.hs new file mode 100644 index 0000000000..d30c7f020f --- /dev/null +++ b/Task/Comments/Haskell/comments.hs @@ -0,0 +1,15 @@ +i code = True -- I am a comment. + +{- I am also + a comment. {-comments can be nested-} + let u x = x x (this code not compiled) + Are you? -} + +-- |This is a Haddock documentation comment for the following code +i code = True +-- ^This is a Haddock documentation comment for the preceding code + +{-| + This is a Haddock documentation block comment +-} +i code = True diff --git a/Task/Comments/Java/comments-2.java b/Task/Comments/Java/comments-2.java new file mode 100644 index 0000000000..0f96007463 --- /dev/null +++ b/Task/Comments/Java/comments-2.java @@ -0,0 +1,5 @@ +/* + * This is + * a multiple + * line comment. + */ diff --git a/Task/Comments/Java/comments-3.java b/Task/Comments/Java/comments-3.java new file mode 100644 index 0000000000..35915f268d --- /dev/null +++ b/Task/Comments/Java/comments-3.java @@ -0,0 +1 @@ +// This is a comment diff --git a/Task/Comments/Java/comments-4.java b/Task/Comments/Java/comments-4.java new file mode 100644 index 0000000000..f6759219ce --- /dev/null +++ b/Task/Comments/Java/comments-4.java @@ -0,0 +1 @@ +/** This is a Javadoc comment */ diff --git a/Task/Comments/Java/comments-5.java b/Task/Comments/Java/comments-5.java new file mode 100644 index 0000000000..cb08e54e22 --- /dev/null +++ b/Task/Comments/Java/comments-5.java @@ -0,0 +1,5 @@ +/** + * This is + * a multiple + * line Javadoc comment + */ diff --git a/Task/Comments/Java/comments.java b/Task/Comments/Java/comments.java new file mode 100644 index 0000000000..af7b13120b --- /dev/null +++ b/Task/Comments/Java/comments.java @@ -0,0 +1 @@ +/* This is a comment */ diff --git a/Task/Comments/LaTeX/comments-2.tex b/Task/Comments/LaTeX/comments-2.tex new file mode 100644 index 0000000000..f40cc029ae --- /dev/null +++ b/Task/Comments/LaTeX/comments-2.tex @@ -0,0 +1,7 @@ +\newcommand{\firstpart}{understand} +\newcommand{\secondpart}{able} +\newcommand{\complete}{% +\firstpart% +\secondpart} + +\complete diff --git a/Task/Comments/LaTeX/comments.tex b/Task/Comments/LaTeX/comments.tex new file mode 100644 index 0000000000..d64a88343a --- /dev/null +++ b/Task/Comments/LaTeX/comments.tex @@ -0,0 +1 @@ +% This is a comment diff --git a/Task/Comments/Lua/comments-2.lua b/Task/Comments/Lua/comments-2.lua new file mode 100644 index 0000000000..cccec59e05 --- /dev/null +++ b/Task/Comments/Lua/comments-2.lua @@ -0,0 +1,2 @@ +--[====[ A multi-line comment that can contain [[ many square brackets ]] +]====] diff --git a/Task/Comments/Lua/comments.lua b/Task/Comments/Lua/comments.lua new file mode 100644 index 0000000000..7cc093cb7a --- /dev/null +++ b/Task/Comments/Lua/comments.lua @@ -0,0 +1,4 @@ +-- A single line comment + +--[[A multi-line + comment --]] diff --git a/Task/Comments/PHP/comments-2.php b/Task/Comments/PHP/comments-2.php new file mode 100644 index 0000000000..6eb0ec57a2 --- /dev/null +++ b/Task/Comments/PHP/comments-2.php @@ -0,0 +1,2 @@ +$var = 1; # this is the comment part +$var = 1; // this is the comment part diff --git a/Task/Comments/PHP/comments-3.php b/Task/Comments/PHP/comments-3.php new file mode 100644 index 0000000000..7124682b5c --- /dev/null +++ b/Task/Comments/PHP/comments-3.php @@ -0,0 +1,4 @@ +/* +Here are my comments +this is multi-line +*/ diff --git a/Task/Comments/PHP/comments-4.php b/Task/Comments/PHP/comments-4.php new file mode 100644 index 0000000000..99a724e812 --- /dev/null +++ b/Task/Comments/PHP/comments-4.php @@ -0,0 +1,4 @@ +/** + * phpdoc Comments + * @todo this is a todo stub + */ diff --git a/Task/Comments/PHP/comments.php b/Task/Comments/PHP/comments.php new file mode 100644 index 0000000000..aac4c5c56e --- /dev/null +++ b/Task/Comments/PHP/comments.php @@ -0,0 +1,2 @@ +# this is commented +// this is commented diff --git a/Task/Comments/Perl/comments-2.pl b/Task/Comments/Perl/comments-2.pl new file mode 100644 index 0000000000..7d5994e9e2 --- /dev/null +++ b/Task/Comments/Perl/comments-2.pl @@ -0,0 +1 @@ +my $var = 1; # this is the comment part diff --git a/Task/Comments/Perl/comments-3.pl b/Task/Comments/Perl/comments-3.pl new file mode 100644 index 0000000000..f7fc6af91f --- /dev/null +++ b/Task/Comments/Perl/comments-3.pl @@ -0,0 +1,6 @@ +=pod + +Here are my comments +this is multi-line + +=cut diff --git a/Task/Comments/Perl/comments-4.pl b/Task/Comments/Perl/comments-4.pl new file mode 100644 index 0000000000..521838a991 --- /dev/null +++ b/Task/Comments/Perl/comments-4.pl @@ -0,0 +1,4 @@ +=head1 +=head4 +=over 4 +=Any Old String diff --git a/Task/Comments/Perl/comments.pl b/Task/Comments/Perl/comments.pl new file mode 100644 index 0000000000..2369670383 --- /dev/null +++ b/Task/Comments/Perl/comments.pl @@ -0,0 +1 @@ +# this is commented diff --git a/Task/Comments/PicoLisp/comments.l b/Task/Comments/PicoLisp/comments.l new file mode 100644 index 0000000000..9856e393b5 --- /dev/null +++ b/Task/Comments/PicoLisp/comments.l @@ -0,0 +1,12 @@ +# The rest of the line is ignored +#{ + This is a + multiline comment +}# +NIL +Immediately stop reading this file. Because all text in the input file following +a top-level 'NIL' is ignored. + +This is typically used conditionally, with a read-macro expression like +`*Dbg +so that this text is only read if in debugging mode. diff --git a/Task/Comments/Python/comments-2.py b/Task/Comments/Python/comments-2.py new file mode 100644 index 0000000000..2c51601155 --- /dev/null +++ b/Task/Comments/Python/comments-2.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# Example of using doc strings +"""My Doc-string example""" + +class Foo: + '''Some documentation for the Foo class''' + def __init__(self): + "Foo's initialization method's documentation" + +def bar(): + """documentation for the bar function""" + +if __name__ == "__main__": + print (__doc__) + print (Foo.__doc__) + print (Foo.__init__.__doc__) + print (bar.__doc__) diff --git a/Task/Comments/Python/comments.py b/Task/Comments/Python/comments.py new file mode 100644 index 0000000000..910d8dddba --- /dev/null +++ b/Task/Comments/Python/comments.py @@ -0,0 +1,9 @@ +"""Un-assigned strings in triple-quotes might be used + as multi-line comments +""" + +''' + "triple quoted strings" can be delimited by either 'single' or "double" quote marks; and they can contain mixtures + of other quote marks without any need to \escape\ them using any special characters. They also may span multiple + lines without special escape characters. +''' diff --git a/Task/Comments/REXX/comments-2.rexx b/Task/Comments/REXX/comments-2.rexx new file mode 100644 index 0000000000..9e04aabdf0 --- /dev/null +++ b/Task/Comments/REXX/comments-2.rexx @@ -0,0 +1,3 @@ +-- A REXX line comment + +say "something" -- another line comment diff --git a/Task/Comments/REXX/comments.rexx b/Task/Comments/REXX/comments.rexx new file mode 100644 index 0000000000..eca01fd685 --- /dev/null +++ b/Task/Comments/REXX/comments.rexx @@ -0,0 +1,42 @@ +/*REXX program to demonstrate various uses and types of comments. */ + +/* everything between a "climbstar" and a "starclimb" (exclusive of literals) is + a comment. + climbstar = /* [slash-asterisk] + starclimb = */ [asterisk-slash] + + /* this is a nested comment, by gum! */ + /*so is this*/ + +Also, REXX comments can span multiple records. + +There can be no intervening character between the slash and asterisk (or +the asterisk and slash). These two joined characters cannot be separated +via a continued line, as in the manner of: + + say 'If I were two─faced,' , + 'would I be wearing this one?' , + ' --- Abraham Lincoln' + +Here come's the thingy that ends this REXX comment. ───┐ + │ + │ + ↓ + + */ + + hour = 12 /*high noon */ +midnight = 00 /*first hour of the day */ + suits = 1234 /*card suits: ♥ ♦ ♣ ♠ */ + +hutchHdr = '/*' +hutchEnd = "*/" + + /* the previous two "hutch" assignments aren't + the start nor the end of a REXX comment. */ + + x=1000000 ** /*¡big power!*/ 1000 + +/*not a real good place for a comment (above), + but essentially, a REXX comment can be + anywhere whitespace is allowed. */ diff --git a/Task/Comments/Ruby/comments.rb b/Task/Comments/Ruby/comments.rb new file mode 100644 index 0000000000..72ed87b2bc --- /dev/null +++ b/Task/Comments/Ruby/comments.rb @@ -0,0 +1,5 @@ +x = "code" # I am a comment + +=begin hello +I a POD documentation comment like Perl +=end puts "code" diff --git a/Task/Comments/Scala/comments.scala b/Task/Comments/Scala/comments.scala new file mode 100644 index 0000000000..6dec14795f --- /dev/null +++ b/Task/Comments/Scala/comments.scala @@ -0,0 +1,4 @@ +// A single line comment + +/* A multi-line + comment */ diff --git a/Task/Comments/Tcl/comments-2.tcl b/Task/Comments/Tcl/comments-2.tcl new file mode 100644 index 0000000000..3c1da6b9c9 --- /dev/null +++ b/Task/Comments/Tcl/comments-2.tcl @@ -0,0 +1,4 @@ +set aList {foo} +lappend aList # bar +puts $aList ;# ==> prints "foo # bar" +puts [llength $aList] ;# ==> 3 diff --git a/Task/Comments/Tcl/comments-3.tcl b/Task/Comments/Tcl/comments-3.tcl new file mode 100644 index 0000000000..bee4fc44db --- /dev/null +++ b/Task/Comments/Tcl/comments-3.tcl @@ -0,0 +1,3 @@ +if 0 { + Comments... +} diff --git a/Task/Comments/Tcl/comments.tcl b/Task/Comments/Tcl/comments.tcl new file mode 100644 index 0000000000..69917fc2ad --- /dev/null +++ b/Task/Comments/Tcl/comments.tcl @@ -0,0 +1,3 @@ +# comment on a line by itself. The next is a command by itself: +set var1 $value1 +set var2 $value2 ; # comment that follows a line of code diff --git a/Task/Death_Star/0DESCRIPTION b/Task/Death_Star/0DESCRIPTION new file mode 100644 index 0000000000..8af42b60ea --- /dev/null +++ b/Task/Death_Star/0DESCRIPTION @@ -0,0 +1,3 @@ +Death Star is a task to display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".) + +See also: [[Draw a sphere]]. diff --git a/Task/Death_Star/1META.yaml b/Task/Death_Star/1META.yaml new file mode 100644 index 0000000000..791c0eb3c9 --- /dev/null +++ b/Task/Death_Star/1META.yaml @@ -0,0 +1,6 @@ +--- +category: +- Geometric Subtraction +note: Constructive Solid Geometry +requires: +- Graphics diff --git a/Task/Death_Star/C/death_star.c b/Task/Death_Star/C/death_star.c new file mode 100644 index 0000000000..e7b1f1ac04 --- /dev/null +++ b/Task/Death_Star/C/death_star.c @@ -0,0 +1,112 @@ +#include +#include +#include + +const char *shades = ".:!*oe&#%@"; + +double light[3] = { -50, 0, 50 }; +void normalize(double * v) +{ + double len = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); + v[0] /= len; v[1] /= len; v[2] /= len; +} + +double dot(double *x, double *y) +{ + double d = x[0]*y[0] + x[1]*y[1] + x[2]*y[2]; + return d < 0 ? -d : 0; +} + +typedef struct { double cx, cy, cz, r; } sphere_t; + +/* positive shpere and negative sphere */ +sphere_t pos = { 20, 20, 0, 20 }, neg = { 1, 1, -6, 20 }; + +/* check if a ray (x,y, -inf)->(x, y, inf) hits a sphere; if so, return + the intersecting z values. z1 is closer to the eye */ +int hit_sphere(sphere_t *sph, double x, double y, double *z1, double *z2) +{ + double zsq; + x -= sph->cx; + y -= sph->cy; + zsq = sph->r * sph->r - (x * x + y * y); + if (zsq < 0) return 0; + zsq = sqrt(zsq); + *z1 = sph->cz - zsq; + *z2 = sph->cz + zsq; + return 1; +} + +void draw_sphere(double k, double ambient) +{ + int i, j, intensity, hit_result; + double b; + double vec[3], x, y, zb1, zb2, zs1, zs2; + for (i = floor(pos.cy - pos.r); i <= ceil(pos.cy + pos.r); i++) { + y = i + .5; + for (j = floor(pos.cx - 2 * pos.r); j <= ceil(pos.cx + 2 * pos.r); j++) { + x = (j - pos.cx) / 2. + .5 + pos.cx; + + /* ray lands in blank space, draw bg */ + if (!hit_sphere(&pos, x, y, &zb1, &zb2)) + hit_result = 0; + + /* ray hits pos sphere but not neg, draw pos sphere surface */ + else if (!hit_sphere(&neg, x, y, &zs1, &zs2)) + hit_result = 1; + + /* ray hits both, but pos front surface is closer */ + else if (zs1 > zb1) hit_result = 1; + + /* pos sphere surface is inside neg sphere, show bg */ + else if (zs2 > zb2) hit_result = 0; + + /* back surface on neg sphere is inside pos sphere, + the only place where neg sphere surface will be shown */ + else if (zs2 > zb1) hit_result = 2; + else hit_result = 1; + + switch(hit_result) { + case 0: + putchar('+'); + continue; + case 1: + vec[0] = x - pos.cx; + vec[1] = y - pos.cy; + vec[2] = zb1 - pos.cz; + break; + default: + vec[0] = neg.cx - x; + vec[1] = neg.cy - y; + vec[2] = neg.cz - zs2; + } + + normalize(vec); + b = pow(dot(light, vec), k) + ambient; + intensity = (1 - b) * (sizeof(shades) - 1); + if (intensity < 0) intensity = 0; + if (intensity >= sizeof(shades) - 1) + intensity = sizeof(shades) - 2; + putchar(shades[intensity]); + } + putchar('\n'); + } +} + +int main() +{ + double ang = 0; + + while (1) { + printf("\033[H"); + light[1] = cos(ang * 2); + light[2] = cos(ang); + light[0] = sin(ang); + normalize(light); + ang += .05; + + draw_sphere(2, .3); + usleep(100000); + } + return 0; +} diff --git a/Task/Death_Star/Go/death_star.go b/Task/Death_Star/Go/death_star.go new file mode 100644 index 0000000000..b4a72191f9 --- /dev/null +++ b/Task/Death_Star/Go/death_star.go @@ -0,0 +1,103 @@ +package main + +import ( + "fmt" + "image" + "image/color" + "image/png" + "math" + "os" +) + +type vector [3]float64 + +func (v *vector) normalize() { + invLen := 1 / math.Sqrt(dot(v, v)) + v[0] *= invLen + v[1] *= invLen + v[2] *= invLen +} + +func dot(x, y *vector) float64 { + return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] +} + +type sphere struct { + cx, cy, cz int + r int +} + +func (s *sphere) hit(x, y int) (z1, z2 float64, hit bool) { + x -= s.cx + y -= s.cy + if zsq := s.r*s.r - (x*x + y*y); zsq >= 0 { + zsqrt := math.Sqrt(float64(zsq)) + return float64(s.cz) - zsqrt, float64(s.cz) + zsqrt, true + } + return 0, 0, false +} + +func deathStar(pos, neg *sphere, k, amb float64, dir *vector) *image.Gray { + w, h := pos.r*4, pos.r*3 + bounds := image.Rect(pos.cx-w/2, pos.cy-h/2, pos.cx+w/2, pos.cy+h/2) + img := image.NewGray(bounds) + vec := new(vector) + for y, yMax := pos.cy-pos.r, pos.cy+pos.r; y <= yMax; y++ { + for x, xMax := pos.cx-pos.r, pos.cx+pos.r; x <= xMax; x++ { + zb1, zb2, hit := pos.hit(x, y) + if !hit { + continue + } + zs1, zs2, hit := neg.hit(x, y) + if hit { + if zs1 > zb1 { + hit = false + } else if zs2 > zb2 { + continue + } + } + if hit { + vec[0] = float64(neg.cx - x) + vec[1] = float64(neg.cy - y) + vec[2] = float64(neg.cz) - zs2 + } else { + vec[0] = float64(x - pos.cx) + vec[1] = float64(y - pos.cy) + vec[2] = zb1 - float64(pos.cz) + } + vec.normalize() + s := dot(dir, vec) + if s < 0 { + s = 0 + } + lum := 255 * (math.Pow(s, k) + amb) / (1 + amb) + if lum < 0 { + lum = 0 + } else if lum > 255 { + lum = 255 + } + img.SetGray(x, y, color.Gray{uint8(lum)}) + } + } + return img +} + +func main() { + dir := &vector{20, -40, -10} + dir.normalize() + pos := &sphere{0, 0, 0, 120} + neg := &sphere{-90, -90, -30, 100} + + img := deathStar(pos, neg, 1.5, .2, dir) + f, err := os.Create("dstar.png") + if err != nil { + fmt.Println(err) + return + } + if err = png.Encode(f, img); err != nil { + fmt.Println(err) + } + if err = f.Close(); err != nil { + fmt.Println(err) + } +} diff --git a/Task/Death_Star/Perl/death_star.pl b/Task/Death_Star/Perl/death_star.pl new file mode 100644 index 0000000000..34c04d12fb --- /dev/null +++ b/Task/Death_Star/Perl/death_star.pl @@ -0,0 +1,75 @@ +use strict; + +sub sq { + my $s = 0; + $s += $_ ** 2 for @_; + $s; +} + +sub hit { + my ($sph, $x, $y) = @_; + $x -= $sph->[0]; + $y -= $sph->[1]; + + my $z = sq($sph->[3]) - sq($x, $y); + return if $z < 0; + + $z = sqrt $z; + return $sph->[2] - $z, $sph->[2] + $z; +} + +sub normalize { + my $v = shift; + my $n = sqrt sq(@$v); + $_ /= $n for @$v; + $v; +} + +sub dot { + my ($x, $y) = @_; + my $s = $x->[0] * $y->[0] + $x->[1] * $y->[1] + $x->[2] * $y->[2]; + $s > 0 ? $s : 0; +} + +my $pos = [ 120, 120, 0, 120 ]; +my $neg = [ -77, -33, -100, 190 ]; +my $light = normalize([ -12, 13, -10 ]); +sub draw { + my ($k, $amb) = @_; + binmode STDOUT, ":raw"; + print "P5\n", $pos->[0] * 2 + 3, " ", $pos->[1] * 2 + 3, "\n255\n"; + for my $y (($pos->[1] - $pos->[3] - 1) .. ($pos->[1] + $pos->[3] + 1)) { + my @row = (); + for my $x (($pos->[0] - $pos->[3] - 1) .. ($pos->[0] + $pos->[3] + 1)) { + my ($hit, @hs) = 0; + my @h = hit($pos, $x, $y); + + if (!@h) { $hit = 0 } + elsif (!(@hs = hit($neg, $x, $y))) { $hit = 1 } + elsif ($hs[0] > $h[0]) { $hit = 1 } + elsif ($hs[1] > $h[0]) { $hit = $hs[1] > $h[1] ? 0 : 2 } + else { $hit = 1 } + + my ($val, $v); + if ($hit == 0) { $val = 0 } + elsif ($hit == 1) { + $v = [ $x - $pos->[0], + $y - $pos->[1], + $h[0] - $pos->[2] ]; + } else { + $v = [ $neg->[0] - $x, + $neg->[1] - $y, + $neg->[2] - $hs[1] ]; + } + if ($v) { + normalize($v); + $val = int((dot($v, $light) ** $k + $amb) * 255); + $val = ($val > 255) ? 255 : ($val < 0) ? 0 : $val; + } + push @row, $val; + } + print pack("C*", @row); + } +} + +draw(2, 0.2); diff --git a/Task/Death_Star/Python/death_star.py b/Task/Death_Star/Python/death_star.py new file mode 100644 index 0000000000..f122e6d06b --- /dev/null +++ b/Task/Death_Star/Python/death_star.py @@ -0,0 +1,67 @@ +import sys, math, collections + +Sphere = collections.namedtuple("Sphere", "cx cy cz r") +V3 = collections.namedtuple("V3", "x y z") + +def normalize((x, y, z)): + len = math.sqrt(x**2 + y**2 + z**2) + return V3(x / len, y / len, z / len) + +def dot(v1, v2): + d = v1.x*v2.x + v1.y*v2.y + v1.z*v2.z + return -d if d < 0 else 0.0 + +def hit_sphere(sph, x0, y0): + x = x0 - sph.cx + y = y0 - sph.cy + zsq = sph.r ** 2 - (x ** 2 + y ** 2) + if zsq < 0: + return (False, 0, 0) + szsq = math.sqrt(zsq) + return (True, sph.cz - szsq, sph.cz + szsq) + +def draw_sphere(k, ambient, light): + shades = ".:!*oe&#%@" + pos = Sphere(20.0, 20.0, 0.0, 20.0) + neg = Sphere(1.0, 1.0, -6.0, 20.0) + + for i in xrange(int(math.floor(pos.cy - pos.r)), + int(math.ceil(pos.cy + pos.r) + 1)): + y = i + 0.5 + for j in xrange(int(math.floor(pos.cx - 2 * pos.r)), + int(math.ceil(pos.cx + 2 * pos.r) + 1)): + x = (j - pos.cx) / 2.0 + 0.5 + pos.cx + + (h, zb1, zb2) = hit_sphere(pos, x, y) + if not h: + hit_result = 0 + else: + (h, zs1, zs2) = hit_sphere(neg, x, y) + if not h: + hit_result = 1 + elif zs1 > zb1: + hit_result = 1 + elif zs2 > zb2: + hit_result = 0 + elif zs2 > zb1: + hit_result = 2 + else: + hit_result = 1 + + if hit_result == 0: + sys.stdout.write(' ') + continue + elif hit_result == 1: + vec = V3(x - pos.cx, y - pos.cy, zb1 - pos.cz) + elif hit_result == 2: + vec = V3(neg.cx-x, neg.cy-y, neg.cz-zs2) + vec = normalize(vec) + + b = dot(light, vec) ** k + ambient + intensity = int((1 - b) * len(shades)) + intensity = min(len(shades), max(0, intensity)) + sys.stdout.write(shades[intensity]) + print + +light = normalize(V3(-50, 30, 50)) +draw_sphere(2, 0.5, light) diff --git a/Task/Death_Star/REXX/death_star.rexx b/Task/Death_Star/REXX/death_star.rexx new file mode 100644 index 0000000000..72d159e9d0 --- /dev/null +++ b/Task/Death_Star/REXX/death_star.rexx @@ -0,0 +1,75 @@ +/*REXX program to draw a "deathstar", a sphere with another subtracted. */ +signal on syntax; signal on novalue /*handle REXX program errors. */ +numeric digits 20 /*use a fair amount of precision.*/ + lightSource = norm('-50 30 50') +call drawSphereM 2, .5, lightSource +exit /*stick a fork in it, we're done.*/ +/*──────────────────────────────────drawSphereM subroutine──────────────*/ +drawSphereM: procedure; parse arg k,ambient,lightSource +z1=0; z2=0 +parse var lightSource s1 s2 s3 /*break-apart the light source. */ + + shading='·:!ºoe@░▒▓' /*shading chars for ASCI machines*/ +if 1=='f1'x then shading='.:!*oe&#%@' /*shading chars for EBCDIC machs.*/ + +shadesLength=length(shading) +shades.=' '; do i=1 for shadesLength + shades.i=substr(shading,i,1) + end /*i*/ + +ship= 20 20 0 20 ; parse var ship ship.cx ship.cy ship.cz ship.radius +hole=' 1 1 -6 20'; parse var hole hole.cx hole.cy hole.cz hole.radius + + do i=floor(ship.cy-ship.radius) to ceil(ship.cy+ship.radius)+1; y=i+.5; aLine= + do j=trunc(floor(ship.cx - 2*ship.radius) ) to, + trunc( ceil(ship.cx + 2*ship.radius) +1) + x=.5*(j-ship.cx) + .5 + ship.cx; !bg=0; !pos=0; !neg=0; z1=0; z2=0 + ?=hitSphere(ship, x, y); zb1=z1; zb2=z2 + + if \? then !bg=1 /*ray lands in blank space, draw the background. */ + else do + ?=hitsphere(hole, x, y); zs1=z1; zs2=z2 + if \? then !pos=1 /*ray hits ship but not the hole, draw ship surface. */ + else if zs1>zb1 then !pos=1 /*ray hits both, but ship front surface is closer. */ + else if zs2>zb2 then !bg=1 /*ship surface is inside hole, show background. */ + else if zs2>zb1 then !neg=1 /*back surface in hole is inside ship, the only place hole surface will be shown.*/ + else !pos=1 + end + select + when !bg then do; aLine=aLine' '; iterate j; end + when !pos then vec_=V3(x-ship.cx y-ship.cy zb1-ship.cz) + when !neg then vec_=V3(hole.cx-x hole.cy-y hole.cz-zs2) + end /*select*/ + + nvec=norm(vec_) + b=dot.(lightSource,nvec)**k + ambient + intensity=trunc((1-b) * shadesLength) + intensity=min(shadesLength, max(0, intensity)) + 1 + aLine=aLine || shades.intensity + end /*j*/ + + if aline\='' then say strip(aLine,'T') + end /*i*/ + +return +/*──────────────────────────────────hitSphere subroutine────────────────*/ +hitSphere: procedure expose z1 z2; parse arg $.cx $.cy $.cz $.radius, x0, y0 + x=x0-$.cx + y=y0-$.cy + zsq=$.radius**2 - (x**2 + y**2); if zsq<0 then return 0 + _=sqrt(zsq) + z1=$.cz-_ + z2=$.cz+_ + return 1 +/*──────────────────────────────────"1-liner" subroutines───────────────*/ +V3: procedure; parse arg v; return norm(v) +dot.: procedure; parse arg x,y; d=dot(x,y); if d<0 then return -d; return 0 +dot: procedure; parse arg x,y; s=0; do j=1 for words(x); s=s+word(x,j)*word(y,j); end; return s +err: say; say; say center(' error! ',max(40,linesize()%2),"*"); say; do j=1 for arg(); say arg(j); say; end; say; exit 13 +novalue: syntax: call err 'REXX program' condition('C') "error", condition('D'),'REXX source statement (line' sigl"):",sourceline(sigl) +ceil: procedure; parse arg x; _=trunc(x); return _ + (x>0) * (x\=_) +floor: procedure; parse arg x; _=trunc(x); return _ - (x<0) * (x\=_) +norm: parse arg _1 _2 _3; _=sqrt(_1**2+_2**2+_3**2); return _1/_ _2/_ _3/_ +sqrt: procedure; parse arg x; if x=0 then return 0; return .sqrt(x)/1 +.sqrt: d=digits();numeric digits 11;g=.sqrtG();do j=0 while p>9;m.j=p;p=p%2+1;end;do k=j+5 by -1 to 0;if m.k>11 then numeric digits m.k;g=.5*(g+x/g);end;return g +.sqrtG: numeric form; m.=11; p=d+d%4+2; v=format(x,2,1,,0) 'E0'; parse var v g 'E' _ .; return g*.5'E'_%2 diff --git a/Task/Death_Star/Tcl/death_star-2.tcl b/Task/Death_Star/Tcl/death_star-2.tcl new file mode 100644 index 0000000000..c6faa78117 --- /dev/null +++ b/Task/Death_Star/Tcl/death_star-2.tcl @@ -0,0 +1,18 @@ +# Render as a picture (with many hard-coded settings) +package require Tk +proc guiDeathStar {photo diff spec lightBrightness ambient} { + set row 0 + for {set i 255} {$i>=0} {incr i -1} { + lappend shades [format "#%02x%02x%02x" $i $i $i] + } + raytraceEngine [list $diff $lightBrightness] \ + [list $spec $lightBrightness] $ambient intersectDeathStar \ + $shades {apply {l { + upvar 2 photo photo row row + $photo put [list $l] -to 0 $row + incr row + update + }}} 0 40 0.0625 0 40 0.0625 +} +pack [label .l -image [image create photo ds]] +guiDeathStar ds 3 10 0.7 0.3 diff --git a/Task/Death_Star/Tcl/death_star.tcl b/Task/Death_Star/Tcl/death_star.tcl new file mode 100644 index 0000000000..c3c1504726 --- /dev/null +++ b/Task/Death_Star/Tcl/death_star.tcl @@ -0,0 +1,115 @@ +package require Tcl 8.5 + +proc normalize vec { + upvar 1 $vec v + lassign $v x y z + set len [expr {sqrt($x**2 + $y**2 + $z**2)}] + set v [list [expr {$x/$len}] [expr {$y/$len}] [expr {$z/$len}]] + return +} + +proc dot {a b} { + lassign $a ax ay az + lassign $b bx by bz + return [expr {-($ax*$bx + $ay*$by + $az*$bz)}] +} + +# Intersection code; assumes that the vector is parallel to the Z-axis +proc hitSphere {sphere x y z1 z2} { + dict with sphere { + set x [expr {$x - $cx}] + set y [expr {$y - $cy}] + set zsq [expr {$r**2 - $x**2 - $y**2}] + if {$zsq < 0} {return 0} + upvar 1 $z1 _1 $z2 _2 + set zsq [expr {sqrt($zsq)}] + set _1 [expr {$cz - $zsq}] + set _2 [expr {$cz + $zsq}] + return 1 + } +} + +# How to do the intersection with our scene +proc intersectDeathStar {x y vecName} { + global big small + if {![hitSphere $big $x $y zb1 zb2]} { + # ray lands in blank space + return 0 + } + upvar 1 $vecName vec + # ray hits big sphere; check if it hit the small one first + set vec [if { + ![hitSphere $small $x $y zs1 zs2] || $zs1 > $zb1 || $zs2 <= $zb1 + } then { + dict with big { + list [expr {$x - $cx}] [expr {$y - $cy}] [expr {$zb1 - $cz}] + } + } else { + dict with small { + list [expr {$cx - $x}] [expr {$cy - $y}] [expr {$cz - $zs2}] + } + }] + normalize vec + return 1 +} + +# Intensity calculators for different lighting components +proc diffuse {k intensity L N} { + expr {[dot $L $N] ** $k * $intensity} +} +proc specular {k intensity L N S} { + # Calculate reflection vector + set r [expr {2 * [dot $L $N]}] + foreach l $L n $N {lappend R [expr {$l-$r*$n}]} + normalize R + # Calculate the specular reflection term + return [expr {[dot $R $S] ** $k * $intensity}] +} + +# Simple raytracing engine that uses parallel rays +proc raytraceEngine {diffparms specparms ambient intersector shades renderer fx tx sx fy ty sy} { + global light + for {set y $fy} {$y <= $ty} {set y [expr {$y + $sy}]} { + set line {} + for {set x $fx} {$x <= $tx} {set x [expr {$x + $sx}]} { + if {![$intersector $x $y vec]} { + # ray lands in blank space + set intensity end + } else { + # ray hits something; we've got the normalized vector + set b [expr { + [diffuse {*}$diffparms $light $vec] + + [specular {*}$specparms $light $vec {0 0 -1}] + + $ambient + }] + set intensity [expr {int((1-$b) * ([llength $shades]-1))}] + if {$intensity < 0} { + set intensity 0 + } elseif {$intensity >= [llength $shades]-1} { + set intensity end-1 + } + } + lappend line [lindex $shades $intensity] + } + {*}$renderer $line + } +} + +# The general scene settings +set light {-50 30 50} +set big {cx 20 cy 20 cz 0 r 20} +set small {cx 7 cy 7 cz -10 r 15} +normalize light + +# Render as text +proc textDeathStar {diff spec lightBrightness ambient} { + global big + dict with big { + raytraceEngine [list $diff $lightBrightness] \ + [list $spec $lightBrightness] $ambient intersectDeathStar \ + [split ".:!*oe&#%@ " {}] {apply {l {puts [join $l ""]}}} \ + [expr {$cx+floor(-$r)}] [expr {$cx+ceil($r)+0.5}] 0.5 \ + [expr {$cy+floor(-$r)+0.5}] [expr {$cy+ceil($r)+0.5}] 1 + } +} +textDeathStar 3 10 0.7 0.3 diff --git a/Task/Entropy/0DESCRIPTION b/Task/Entropy/0DESCRIPTION new file mode 100644 index 0000000000..5830ee3680 --- /dev/null +++ b/Task/Entropy/0DESCRIPTION @@ -0,0 +1,7 @@ +Calculate the [[wp:Entropy (information theory)|information entropy]] (Shannon entropy) of a given input string. + +Entropy is the [[wp:Expected value|expected value]] of the measure of [[wp:Self-information|information]] content in a system. In general, the Shannon entropy of a variable X is defined as: +:H(X) = \sum_{x\in\Omega} P(x) I(x) +where the information content I(x) = -\log_{b} P(x). If the base of the logarithm b = 2, the result is expressed in ''bits'', a [[wp:Units of information|unit of information]]. Therefore, given a string S of length n where P(s_i) is the relative frequency of each character, the entropy of a string in bits is: +:H(S) = -\sum_{i=0}^n P(s_i) \log_2 (P(s_i)) +For this task, use "1223334444" as an example. The result should be around 1.84644 bits. diff --git a/Task/Entropy/1META.yaml b/Task/Entropy/1META.yaml new file mode 100644 index 0000000000..aed8ff126a --- /dev/null +++ b/Task/Entropy/1META.yaml @@ -0,0 +1,2 @@ +--- +note: Mathematics diff --git a/Task/Entropy/Haskell/entropy.hs b/Task/Entropy/Haskell/entropy.hs new file mode 100644 index 0000000000..dd24f6b75e --- /dev/null +++ b/Task/Entropy/Haskell/entropy.hs @@ -0,0 +1,8 @@ +import Data.List + +main = print $ entropy "1223334444" + +entropy s = + sum . map lg' . fq' . map (fromIntegral.length) . group . sort $ s + where lg' c = (c * ) . logBase 2 $ 1.0 / c + fq' c = map (\x -> x / (sum c)) c diff --git a/Task/Entropy/Perl/entropy.pl b/Task/Entropy/Perl/entropy.pl new file mode 100644 index 0000000000..1ab3b6b839 --- /dev/null +++ b/Task/Entropy/Perl/entropy.pl @@ -0,0 +1,9 @@ +sub entropy { + my %count; $count{$_}++ for @_; + my @p = map $_/@_, values %count; + my $entropy = 0; + $entropy += - $_ * log $_ for @p; + $entropy / log 2 +} + +print entropy split //, "1223334444"; diff --git a/Task/Entropy/Python/entropy.py b/Task/Entropy/Python/entropy.py new file mode 100644 index 0000000000..8cba757d03 --- /dev/null +++ b/Task/Entropy/Python/entropy.py @@ -0,0 +1,34 @@ +from __future__ import division +import math + +def hist(source): + hist = {}; l = 0; + for e in source: + l += 1 + if e not in hist: + hist[e] = 0 + hist[e] += 1 + return (l,hist) + +def entropy(hist,l): + elist = [] + for v in hist.values(): + c = v / l + elist.append(-c * math.log(c ,2)) + return sum(elist) + +def printHist(h): + flip = lambda (k,v) : (v,k) + h = sorted(h.iteritems(), key = flip) + print 'Sym\thi\tfi\tInf' + for (k,v) in h: + print '%s\t%f\t%f\t%f'%(k,v,v/l,-math.log(v/l, 2)) + + + +source = "1223334444" +(l,h) = hist(source); +print '.[Results].' +print 'Length',l +print 'Entropy:', entropy(h, l) +printHist(h) diff --git a/Task/Entropy/REXX/entropy-2.rexx b/Task/Entropy/REXX/entropy-2.rexx new file mode 100644 index 0000000000..699ef567d0 --- /dev/null +++ b/Task/Entropy/REXX/entropy-2.rexx @@ -0,0 +1,30 @@ +/*REXX program calculates the information entropy for a given char str.*/ +numeric digits 30 /*use thirty digits for precision*/ +parse arg $; if $=='' then $=1223334444 /*obtain optional input*/ +n=0; @.=0; L=length($); $$= + + do j=1 for L; _=substr($,j,1) /*process each character in $ str*/ + if @._==0 then do; n=n+1 /*if unique, bump char counter. */ + $$=$$ || _ /*add this character to the list.*/ + end + @._ = @._+1 /*keep track of this char count. */ + end /*j*/ +sum=0 /*calc info entropy for each char*/ + do i=1 for n; _=substr($$,i,1) /*obtain a char from unique list.*/ + sum=sum - @._/L * log2(@._/L) /*add (negatively) the entropies.*/ + end /*i*/ + +say ' input string: ' $ +say 'string length: ' L +say ' unique chars: ' n ; say +say 'the information entropy of the string ──► ' format(sum,,12) " bits." +exit /*stick a fork in it, we're done.*/ +/*──────────────────────────────────LOG2 subroutine─────────────────────*/ +log2: procedure; parse arg x 1 xx; ig= x>1.5; is=1-2*(ig\==1); ii=0 +numeric digits digits()+5 /* [↓] precision of E must be > digits().*/ +e=2.7182818284590452353602874713526624977572470936999595749669676277240766303535 + do while ig & xx>1.5 | \ig&xx<.5; _=e; do k=-1; iz=xx* _**-is + if k>=0 & (ig & iz<1 | \ig&iz>.5) then leave; _=_*_; izz=iz; end + xx=izz; ii=ii+is*2**k; end; x=x* e**-ii-1; z=0; _=-1; p=z + do k=1; _=-_*x; z=z+_/k; if z=p then leave; p=z; end /*k*/ + r=z+ii; if arg()==2 then return r; return r/log2(2,0) diff --git a/Task/Entropy/REXX/entropy.rexx b/Task/Entropy/REXX/entropy.rexx new file mode 100644 index 0000000000..41984d2ef0 --- /dev/null +++ b/Task/Entropy/REXX/entropy.rexx @@ -0,0 +1,84 @@ +/* Rexx *************************************************************** +* 28.02.2013 Walter Pachl +* 12.03.2013 Walter Pachl typo in log corrected. thanx for testing +**********************************************************************/ +s="1223334444" +occ.=0 +n=0 +Do i=1 To length(s) + c=substr(s,i,1) + occ.c=occ.c+1 + n=n+1 + End +do c=1 To 4 + p.c=occ.c/n + say c p.c + End +e=0 +Do c=1 To 4 + e=e+p.c*log(p.c,,2) + End +Say 'Entropy of' s 'is' (-e) +Exit + +log: Procedure +/*********************************************************************** +* Return log(x) -- with specified precision and a specified base +* Three different series are used for the ranges 0 to 0.5 +* 0.5 to 1.5 +* 1.5 to infinity +* 03.09.1992 Walter Pachl +***********************************************************************/ + Parse Arg x,prec,b + If prec='' Then prec=9 + Numeric Digits (2*prec) + Numeric Fuzz 3 + Select + When x<=0 Then r='*** invalid argument ***' + When x<0.5 Then Do + z=(x-1)/(x+1) + o=z + r=z + k=1 + Do i=3 By 2 + ra=r + k=k+1 + o=o*z*z + r=r+o/i + If r=ra Then Leave + End + r=2*r + End + When x<1.5 Then Do + z=(x-1) + o=z + r=z + k=1 + Do i=2 By 1 + ra=r + k=k+1 + o=-o*z + r=r+o/i + If r=ra Then Leave + End + End + Otherwise /* 1.5<=x */ Do + z=(x+1)/(x-1) + o=1/z + r=o + k=1 + Do i=3 By 2 + ra=r + k=k+1 + o=o/(z*z) + r=r+o/i + If r=ra Then Leave + End + r=2*r + End + End + If b<>'' Then + r=r/log(b) + Numeric Digits (prec) + r=r+0 + Return r diff --git a/Task/Entropy/Ruby/entropy-2.rb b/Task/Entropy/Ruby/entropy-2.rb new file mode 100644 index 0000000000..82aae3c36a --- /dev/null +++ b/Task/Entropy/Ruby/entropy-2.rb @@ -0,0 +1,3 @@ +def entropy2(s) + s.each_char.group_by(&:to_s).values.map { |x| x.length / s.length.to_f }.reduce(0) { |e, x| e - x*Math.log2(x) } +end diff --git a/Task/Entropy/Ruby/entropy.rb b/Task/Entropy/Ruby/entropy.rb new file mode 100644 index 0000000000..91cf2a7a3c --- /dev/null +++ b/Task/Entropy/Ruby/entropy.rb @@ -0,0 +1,9 @@ +def entropy(s) + counts = Hash.new(0) + s.each_char { |c| counts[c] += 1 } + + counts.values.reduce(0) do |entropy, count| + freq = count / s.length.to_f + entropy - freq * Math.log2(freq) + end +end diff --git a/Task/Entropy/Scala/entropy.scala b/Task/Entropy/Scala/entropy.scala new file mode 100644 index 0000000000..d3a4327e9a --- /dev/null +++ b/Task/Entropy/Scala/entropy.scala @@ -0,0 +1,12 @@ +import scala.math._ + +def entropy( v:String ) = { v + .groupBy (a => a) + .values + .map( i => i.length.toDouble / v.length ) + .map( p => -p * log10(p) / log10(2)) + .sum +} + +// Confirm that "1223334444" has an entropy of about 1.84644 +assert( math.round( entropy("1223334444") * 100000 ) * 0.00001 == 1.84644 ) diff --git a/Task/Entropy/Tcl/entropy-2.tcl b/Task/Entropy/Tcl/entropy-2.tcl new file mode 100644 index 0000000000..737b0a66ee --- /dev/null +++ b/Task/Entropy/Tcl/entropy-2.tcl @@ -0,0 +1,2 @@ +puts [format "entropy = %.5f" [entropy "1223334444"]] +puts [format "entropy = %.5f" [entropy "Rosetta Code"]] diff --git a/Task/Entropy/Tcl/entropy.tcl b/Task/Entropy/Tcl/entropy.tcl new file mode 100644 index 0000000000..82c4392222 --- /dev/null +++ b/Task/Entropy/Tcl/entropy.tcl @@ -0,0 +1,10 @@ +proc entropy {str} { + set log2 [expr log(2)] + foreach char [split $str ""] {dict incr counts $char} + set entropy 0.0 + foreach count [dict values $counts] { + set freq [expr {$count / double([string length $str])}] + set entropy [expr {$entropy - $freq * log($freq)/$log2}] + } + return $entropy +} diff --git a/Task/FizzBuzz/0DESCRIPTION b/Task/FizzBuzz/0DESCRIPTION new file mode 100644 index 0000000000..ba52dad10f --- /dev/null +++ b/Task/FizzBuzz/0DESCRIPTION @@ -0,0 +1,3 @@ +Write a program that prints the integers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". [http://weblog.raganwald.com/2007/01/dont-overthink-fizzbuzz.html] + +FizzBuzz was presented as the lowest level of comprehension required to illustrate adequacy. [http://www.codinghorror.com/blog/archives/000804.html] diff --git a/Task/FizzBuzz/1META.yaml b/Task/FizzBuzz/1META.yaml new file mode 100644 index 0000000000..71d70b5414 --- /dev/null +++ b/Task/FizzBuzz/1META.yaml @@ -0,0 +1,5 @@ +--- +category: +- Iteration +- Recursion +note: Classic CS problems and programs diff --git a/Task/FizzBuzz/AWK/fizzbuzz-2.awk b/Task/FizzBuzz/AWK/fizzbuzz-2.awk new file mode 100644 index 0000000000..8fbaccfadf --- /dev/null +++ b/Task/FizzBuzz/AWK/fizzbuzz-2.awk @@ -0,0 +1,7 @@ +echo {1..100} | awk ' +BEGIN{RS=" "} +$1 % 15 == 0 {print "FizzBuzz"} +$1 % 5 == 0 {print "Buzz"} +$1 % 3 == 0 {print "Fizz"} +{print} +' diff --git a/Task/FizzBuzz/AWK/fizzbuzz-3.awk b/Task/FizzBuzz/AWK/fizzbuzz-3.awk new file mode 100644 index 0000000000..b8c6edaa8d --- /dev/null +++ b/Task/FizzBuzz/AWK/fizzbuzz-3.awk @@ -0,0 +1 @@ +seq 100 | awk '$0=NR%15?NR%5?NR%3?$0:"Fizz":"Buzz":"FizzBuzz"' diff --git a/Task/FizzBuzz/AWK/fizzbuzz.awk b/Task/FizzBuzz/AWK/fizzbuzz.awk new file mode 100644 index 0000000000..47de5c3719 --- /dev/null +++ b/Task/FizzBuzz/AWK/fizzbuzz.awk @@ -0,0 +1,11 @@ +BEGIN { + for (NUM=1; NUM<=100; NUM++) + if (NUM % 15 == 0) + {print "FizzBuzz"} + else if (NUM % 3 == 0) + {print "Fizz"} + else if (NUM % 5 == 0) + {print "Buzz"} + else + {print NUM} +} diff --git a/Task/FizzBuzz/BASIC/fizzbuzz-2.bas b/Task/FizzBuzz/BASIC/fizzbuzz-2.bas new file mode 100644 index 0000000000..5c45404ca3 --- /dev/null +++ b/Task/FizzBuzz/BASIC/fizzbuzz-2.bas @@ -0,0 +1,17 @@ +FOR A = 1 TO 100 + OUT$ = "" + + IF A MOD 3 = 0 THEN + OUT$ = "Fizz" + END IF + + IF A MOD 5 = 0 THEN + OUT$ = OUT$ + "Buzz" + END IF + + IF OUT$ = "" THEN + OUT$ = STR$(A) + END IF + + PRINT OUT$ +NEXT A diff --git a/Task/FizzBuzz/BASIC/fizzbuzz-3.bas b/Task/FizzBuzz/BASIC/fizzbuzz-3.bas new file mode 100644 index 0000000000..96de6a181a --- /dev/null +++ b/Task/FizzBuzz/BASIC/fizzbuzz-3.bas @@ -0,0 +1,8 @@ +10 DEF FN M(N) = ((A / N) - INT (A / N)) * N +20 FOR A = 1 TO 100 +30 LET O$ = "" +40 IF FN M(3) = 0 THEN O$ = "FIZZ" +50 IF FN M(5) = 0 THEN O$ = O$ + "BUZZ" +60 IF O$ = "" THEN O$ = STR$ (A) +70 PRINT O$ +80 NEXT A diff --git a/Task/FizzBuzz/BASIC/fizzbuzz.bas b/Task/FizzBuzz/BASIC/fizzbuzz.bas new file mode 100644 index 0000000000..5706ae5dcc --- /dev/null +++ b/Task/FizzBuzz/BASIC/fizzbuzz.bas @@ -0,0 +1,11 @@ +FOR A = 1 TO 100 + IF A MOD 15 = 0 THEN + PRINT "FizzBuzz" + ELSE IF A MOD 3 = 0 THEN + PRINT "Fizz" + ELSE IF A MOD 5 = 0 THEN + PRINT "Buzz" + ELSE + PRINT A + END IF +NEXT A diff --git a/Task/FizzBuzz/Befunge/fizzbuzz.bf b/Task/FizzBuzz/Befunge/fizzbuzz.bf new file mode 100644 index 0000000000..5de7a0e33c --- /dev/null +++ b/Task/FizzBuzz/Befunge/fizzbuzz.bf @@ -0,0 +1,9 @@ +55*4*v _ v +v <>:1-:^ + |:<$ < ,*48 < + @>0"zzif">:#,_$ v +>:3%!| >0"zzub">:#,_$^ + >:5%!| +v "buzz"0<>:. ^ + |!%5: < +>:#,_ $> ^ diff --git a/Task/FizzBuzz/C/fizzbuzz-2.c b/Task/FizzBuzz/C/fizzbuzz-2.c new file mode 100644 index 0000000000..10d5072f99 --- /dev/null +++ b/Task/FizzBuzz/C/fizzbuzz-2.c @@ -0,0 +1,16 @@ +#include + +main() { + int i = 1; + while(i <= 100) { + if(i % 15 == 0) + puts("FizzBuzz"); + else if(i % 3 == 0) + puts("Fizz"); + else if(i % 5 == 0) + puts("Buzz"); + else + printf("%d\n", i); + i++; + } +} diff --git a/Task/FizzBuzz/C/fizzbuzz-3.c b/Task/FizzBuzz/C/fizzbuzz-3.c new file mode 100644 index 0000000000..daa85416cc --- /dev/null +++ b/Task/FizzBuzz/C/fizzbuzz-3.c @@ -0,0 +1,3 @@ +#include +#define F(x,y) printf("%s",i%x?"":#y"zz") +int main(int i){for(--i;i++^100;puts(""))F(3,Fi)|F(5,Bu)||printf("%i",i);return 0;} diff --git a/Task/FizzBuzz/C/fizzbuzz-4.c b/Task/FizzBuzz/C/fizzbuzz-4.c new file mode 100644 index 0000000000..de8671632b --- /dev/null +++ b/Task/FizzBuzz/C/fizzbuzz-4.c @@ -0,0 +1,11 @@ +#include + +int main () +{ + int i; + const char *s[] = { "%d\n", "Fizz\n", s[3] + 4, "FizzBuzz\n" }; + for (i = 1; i <= 100; i++) + printf(s[!(i % 3) + 2 * !(i % 5)], i); + + return 0; +} diff --git a/Task/FizzBuzz/C/fizzbuzz.c b/Task/FizzBuzz/C/fizzbuzz.c new file mode 100644 index 0000000000..b6e087e7ae --- /dev/null +++ b/Task/FizzBuzz/C/fizzbuzz.c @@ -0,0 +1,20 @@ +#include + +int main (void) +{ + int i; + for (i = 1; i <= 100; i++) + { + if (!(i % 15)) + printf ("FizzBuzz"); + else if (!(i % 3)) + printf ("Fizz"); + else if (!(i % 5)) + printf ("Buzz"); + else + printf ("%d", i); + + printf("\n"); + } + return 0; +} diff --git a/Task/FizzBuzz/Clojure/fizzbuzz-2.clj b/Task/FizzBuzz/Clojure/fizzbuzz-2.clj new file mode 100644 index 0000000000..5e8e028b11 --- /dev/null +++ b/Task/FizzBuzz/Clojure/fizzbuzz-2.clj @@ -0,0 +1 @@ +(map #(let [s (str (if (zero? (mod % 3)) "Fizz") (if (zero? (mod % 5)) "Buzz"))] (if (empty? s) % s)) (range 1 101)) diff --git a/Task/FizzBuzz/Clojure/fizzbuzz-3.clj b/Task/FizzBuzz/Clojure/fizzbuzz-3.clj new file mode 100644 index 0000000000..6d98cfeb9a --- /dev/null +++ b/Task/FizzBuzz/Clojure/fizzbuzz-3.clj @@ -0,0 +1,6 @@ +(def fizzbuzz (lazy-seq (map + #(cond (zero? (mod % 15)) "FizzBuzz" + (zero? (mod % 5)) "Buzz" + (zero? (mod % 3)) "Fizz" + :else %) + (iterate inc 1)))) diff --git a/Task/FizzBuzz/Clojure/fizzbuzz-4.clj b/Task/FizzBuzz/Clojure/fizzbuzz-4.clj new file mode 100644 index 0000000000..d104442437 --- /dev/null +++ b/Task/FizzBuzz/Clojure/fizzbuzz-4.clj @@ -0,0 +1,13 @@ +(defn fizz-buzz + ([] (fizz-buzz (range 1 101))) + ([lst] + (letfn [(fizz? [n] (zero? (mod n 3))) + (buzz? [n] (zero? (mod n 5)))] + (let [f "Fizz" + b "Buzz" + items (map (fn [n] + (cond (and (fizz? n) (buzz? n)) (str f b) + (fizz? n) f + (buzz? n) b + :else n)) + lst)] items)))) diff --git a/Task/FizzBuzz/Clojure/fizzbuzz-5.clj b/Task/FizzBuzz/Clojure/fizzbuzz-5.clj new file mode 100644 index 0000000000..95073f3e20 --- /dev/null +++ b/Task/FizzBuzz/Clojure/fizzbuzz-5.clj @@ -0,0 +1,6 @@ +(map (fn [n] + (if-let [fb (seq (concat (when (zero? (mod n 3)) "Fizz") + (when (zero? (mod n 5)) "Buzz")))] + (apply str fb) + n)) + (range 1 101)) diff --git a/Task/FizzBuzz/Clojure/fizzbuzz-6.clj b/Task/FizzBuzz/Clojure/fizzbuzz-6.clj new file mode 100644 index 0000000000..b637918e95 --- /dev/null +++ b/Task/FizzBuzz/Clojure/fizzbuzz-6.clj @@ -0,0 +1,4 @@ +(take 100 (map #(let [s (str %2 %3) ] (if (seq s) s (inc %)) ) + (range) + (cycle [ "" "" "Fizz" ]) + (cycle [ "" "" "" "" "Buzz" ]))) diff --git a/Task/FizzBuzz/Clojure/fizzbuzz.clj b/Task/FizzBuzz/Clojure/fizzbuzz.clj new file mode 100644 index 0000000000..086b301e3c --- /dev/null +++ b/Task/FizzBuzz/Clojure/fizzbuzz.clj @@ -0,0 +1,5 @@ +(map (fn [x] (cond (zero? (mod x 15)) "FizzBuzz" + (zero? (mod x 5)) "Buzz" + (zero? (mod x 3)) "Fizz" + :else x)) + (range 1 101)) diff --git a/Task/FizzBuzz/CoffeeScript/fizzbuzz-2.coffee b/Task/FizzBuzz/CoffeeScript/fizzbuzz-2.coffee new file mode 100644 index 0000000000..c85b29af26 --- /dev/null +++ b/Task/FizzBuzz/CoffeeScript/fizzbuzz-2.coffee @@ -0,0 +1,2 @@ +for i in [1..100] + console.log(['Fizz' if i % 3 is 0] + ['Buzz' if i % 5 is 0] or i) diff --git a/Task/FizzBuzz/CoffeeScript/fizzbuzz.coffee b/Task/FizzBuzz/CoffeeScript/fizzbuzz.coffee new file mode 100644 index 0000000000..a2af876510 --- /dev/null +++ b/Task/FizzBuzz/CoffeeScript/fizzbuzz.coffee @@ -0,0 +1,9 @@ +for i in [1..100] + if i % 15 is 0 + console.log "FizzBuzz" + else if i % 3 is 0 + console.log "Fizz" + else if i % 5 is 0 + console.log "Buzz" + else + console.log i diff --git a/Task/FizzBuzz/Erlang/fizzbuzz.erl b/Task/FizzBuzz/Erlang/fizzbuzz.erl new file mode 100644 index 0000000000..fa64317f37 --- /dev/null +++ b/Task/FizzBuzz/Erlang/fizzbuzz.erl @@ -0,0 +1,7 @@ +fizzbuzz() -> + F = fun(N) when N rem 15 == 0 -> "FizzBuzz"; + (N) when N rem 3 == 0 -> "Fizz"; + (N) when N rem 5 == 0 -> "Buzz"; + (N) -> integer_to_list(N) + end, + [F(N)++"\n" || N <- lists:seq(1,100)]. diff --git a/Task/FizzBuzz/Forth/fizzbuzz-2.fth b/Task/FizzBuzz/Forth/fizzbuzz-2.fth new file mode 100644 index 0000000000..ce937cffb6 --- /dev/null +++ b/Task/FizzBuzz/Forth/fizzbuzz-2.fth @@ -0,0 +1,9 @@ +: .fizzbuzz ( n -- ) + 0 pad c! + dup 3 mod 0= if s" Fizz" pad place then + dup 5 mod 0= if s" Buzz" pad +place then + pad c@ if drop pad count type else . then ; + +: zz ( n -- ) + 1+ 1 do i .fizzbuzz cr loop ; +100 zz diff --git a/Task/FizzBuzz/Forth/fizzbuzz-3.fth b/Task/FizzBuzz/Forth/fizzbuzz-3.fth new file mode 100644 index 0000000000..e5a5b1bc89 --- /dev/null +++ b/Task/FizzBuzz/Forth/fizzbuzz-3.fth @@ -0,0 +1,9 @@ +SYNONYM NOT INVERT \ Bitwise boolean not + +: Fizz? ( n -- ? ) 3 MOD 0= DUP IF ." Fizz" THEN ; +: Buzz? ( n -- ? ) 5 MOD 0= DUP IF ." Buzz" THEN ; +: ?print ( n ? -- ) IF . THEN ; +: FizzBuzz ( -- ) + 101 1 DO CR I DUP Fizz? OVER Buzz? OR NOT ?print LOOP ; + +FizzBuzz diff --git a/Task/FizzBuzz/Forth/fizzbuzz.fth b/Task/FizzBuzz/Forth/fizzbuzz.fth new file mode 100644 index 0000000000..a3ceeda5a5 --- /dev/null +++ b/Task/FizzBuzz/Forth/fizzbuzz.fth @@ -0,0 +1,11 @@ +: fizz ( n -- ) drop ." Fizz" ; +: buzz ( n -- ) drop ." Buzz" ; +: fb ( n -- ) drop ." FizzBuzz" ; +: vector create does> ( n -- ) + over 15 mod cells + @ execute ; +vector .fizzbuzz + ' fb , ' . , ' . , + ' fizz , ' . , ' buzz , + ' fizz , ' . , ' . , + ' fizz , ' buzz , ' . , + ' fizz , ' . , ' . , diff --git a/Task/FizzBuzz/Fortran/fizzbuzz-2.f b/Task/FizzBuzz/Fortran/fizzbuzz-2.f new file mode 100644 index 0000000000..9bead5b406 --- /dev/null +++ b/Task/FizzBuzz/Fortran/fizzbuzz-2.f @@ -0,0 +1,12 @@ +program fizzbuzz_select + integer :: i + + do i = 1, 100 + select case (mod(i,15)) + case 0; print *, 'FizzBuzz' + case 3,6,9,12; print *, 'Fizz' + case 5,10; print *, 'Buzz' + case default; print *, i + end select + end do + end program fizzbuzz_select diff --git a/Task/FizzBuzz/Fortran/fizzbuzz.f b/Task/FizzBuzz/Fortran/fizzbuzz.f new file mode 100644 index 0000000000..30939c9336 --- /dev/null +++ b/Task/FizzBuzz/Fortran/fizzbuzz.f @@ -0,0 +1,11 @@ +program fizzbuzz_if + integer :: i + + do i = 1, 100 + if (mod(i,15) == 0) then; print *, 'FizzBuzz' + else if (mod(i,3) == 0) then; print *, 'Fizz' + else if (mod(i,5) == 0) then; print *, 'Buzz' + else; print *, i + end if + end do +end program fizzbuzz_if diff --git a/Task/FizzBuzz/Go/fizzbuzz.go b/Task/FizzBuzz/Go/fizzbuzz.go new file mode 100644 index 0000000000..8b074d1dc8 --- /dev/null +++ b/Task/FizzBuzz/Go/fizzbuzz.go @@ -0,0 +1,17 @@ +package main +import "fmt" + +func main() { + for i := 1; i <= 100; i++ { + switch { + case (i%3==0) && (i%5==0): + fmt.Println("FizzBuzz") + case i%3==0: + fmt.Println("Fizz") + case i%5==0: + fmt.Println("Buzz") + default: + fmt.Println(i) + } + } +} diff --git a/Task/FizzBuzz/Haskell/fizzbuzz-2.hs b/Task/FizzBuzz/Haskell/fizzbuzz-2.hs new file mode 100644 index 0000000000..f2f7ed7559 --- /dev/null +++ b/Task/FizzBuzz/Haskell/fizzbuzz-2.hs @@ -0,0 +1,5 @@ +main = mapM_ putStrLn $ take 100 fizzbuzz + +fizzbuzz = zipWith (\x y -> if null y then show x else y) [1..] fbs + +fbs = zipWith (++) (cycle ["","","Fizz"]) (cycle ["","","","","Buzz"]) diff --git a/Task/FizzBuzz/Haskell/fizzbuzz-3.hs b/Task/FizzBuzz/Haskell/fizzbuzz-3.hs new file mode 100644 index 0000000000..264b9302d1 --- /dev/null +++ b/Task/FizzBuzz/Haskell/fizzbuzz-3.hs @@ -0,0 +1,12 @@ +import Control.Monad.State +import Control.Monad.Trans +import Control.Monad.Writer + +main = putStr $ execWriter $ mapM_ (flip execStateT True . fizzbuzz) [1..100] + +fizzbuzz :: Int -> StateT Bool (Writer String) () +fizzbuzz x = do + when (x `mod` 3 == 0) $ tell "Fizz" >> put False + when (x `mod` 5 == 0) $ tell "Buzz" >> put False + get >>= (flip when $ tell $ show x) + tell "\n" diff --git a/Task/FizzBuzz/Haskell/fizzbuzz-4.hs b/Task/FizzBuzz/Haskell/fizzbuzz-4.hs new file mode 100644 index 0000000000..0d0dab61aa --- /dev/null +++ b/Task/FizzBuzz/Haskell/fizzbuzz-4.hs @@ -0,0 +1,6 @@ +fizzBuzz :: Int -> String +fizzBuzz x + | x `mod` 5 == 0 && x `mod` 3 == 0 = "FizzBuzz" + | x `mod` 5 == 0 = "Buzz" + | x `mod` 3 == 0 = "Fizz" + | otherwise = show x diff --git a/Task/FizzBuzz/Haskell/fizzbuzz.hs b/Task/FizzBuzz/Haskell/fizzbuzz.hs new file mode 100644 index 0000000000..6930938df1 --- /dev/null +++ b/Task/FizzBuzz/Haskell/fizzbuzz.hs @@ -0,0 +1,7 @@ +main = mapM_ (putStrLn . fizzbuzz) [1..100] + +fizzbuzz x + | x `mod` 15 == 0 = "FizzBuzz" + | x `mod` 3 == 0 = "Fizz" + | x `mod` 5 == 0 = "Buzz" + | otherwise = show x diff --git a/Task/FizzBuzz/Java/fizzbuzz-2.java b/Task/FizzBuzz/Java/fizzbuzz-2.java new file mode 100644 index 0000000000..f5113e4fb8 --- /dev/null +++ b/Task/FizzBuzz/Java/fizzbuzz-2.java @@ -0,0 +1,11 @@ +public class FizzBuzz{ + public static void main(String[] args){ + for(int i= 1; i <= 100; i++){ + String output = ""; + if(i % 3 == 0) output += "Fizz"; + if(i % 5 == 0) output += "Buzz"; + if(output.equals("")) output += i; + System.out.println(output); + } + } +} diff --git a/Task/FizzBuzz/Java/fizzbuzz-3.java b/Task/FizzBuzz/Java/fizzbuzz-3.java new file mode 100644 index 0000000000..d6e99c199f --- /dev/null +++ b/Task/FizzBuzz/Java/fizzbuzz-3.java @@ -0,0 +1,8 @@ +public class FizzBuzz{ + public static void main(String[] args){ + for(int i= 1; i <= 100; i++){ + System.out.println(i % 15 != 0 ? i % 5 != 0 ? i % 3 != 0 ? + i : "Fizz" : "Buzz" : "FizzBuzz"); + } + } +} diff --git a/Task/FizzBuzz/Java/fizzbuzz-4.java b/Task/FizzBuzz/Java/fizzbuzz-4.java new file mode 100644 index 0000000000..676d8c6410 --- /dev/null +++ b/Task/FizzBuzz/Java/fizzbuzz-4.java @@ -0,0 +1,12 @@ +public String fizzBuzz(int n){ + String s = ""; + if (n == 0) + return s; + if((n % 5) == 0) + s = "Buzz" + s; + if((n % 3) == 0) + s = "Fizz" + s; + if (s.equals("")) + s = n + ""; + return fizzBuzz(n-1) + s; +} diff --git a/Task/FizzBuzz/Java/fizzbuzz-5.java b/Task/FizzBuzz/Java/fizzbuzz-5.java new file mode 100644 index 0000000000..767a3fa569 --- /dev/null +++ b/Task/FizzBuzz/Java/fizzbuzz-5.java @@ -0,0 +1,5 @@ +public String fizzBuzz(int n){ + return (n>0) ? fizzBuzz(n-1) + + (n % 15 != 0? n % 5 != 0? n % 3 != 0? (n+"") :"Fizz" : "Buzz" : "FizzBuzz") + : ""; +} diff --git a/Task/FizzBuzz/Java/fizzbuzz-6.java b/Task/FizzBuzz/Java/fizzbuzz-6.java new file mode 100644 index 0000000000..80ab9dd867 --- /dev/null +++ b/Task/FizzBuzz/Java/fizzbuzz-6.java @@ -0,0 +1,7 @@ +class FizzBuzz { + public static void main( String [] args ) { + for( int i = 1 ; i <= 100 ; i++ ) { + System.out.println( new String[]{ i+"", "Fizz", "Buzz", "FizzBuzz" }[ ( i%3==0?1:0 ) + ( i%5==0?2:0 ) ]); + } + } +} diff --git a/Task/FizzBuzz/Java/fizzbuzz.java b/Task/FizzBuzz/Java/fizzbuzz.java new file mode 100644 index 0000000000..96990a8f58 --- /dev/null +++ b/Task/FizzBuzz/Java/fizzbuzz.java @@ -0,0 +1,15 @@ +public class FizzBuzz{ + public static void main(String[] args){ + for(int i= 1; i <= 100; i++){ + if(i % 15 == 0){ + System.out.println("FizzBuzz"); + }else if(i % 3 == 0){ + System.out.println("Fizz"); + }else if(i % 5 == 0){ + System.out.println("Buzz"); + }else{ + System.out.println(i); + } + } + } +} diff --git a/Task/FizzBuzz/JavaScript/fizzbuzz-2.js b/Task/FizzBuzz/JavaScript/fizzbuzz-2.js new file mode 100644 index 0000000000..821c624692 --- /dev/null +++ b/Task/FizzBuzz/JavaScript/fizzbuzz-2.js @@ -0,0 +1 @@ +for (var i=1; i<=100; i++) console.log( (i % 3 === 0 ? 'Fizz' : '') + (i % 5 === 0 ? 'Buzz' : '') || i ); diff --git a/Task/FizzBuzz/JavaScript/fizzbuzz-3.js b/Task/FizzBuzz/JavaScript/fizzbuzz-3.js new file mode 100644 index 0000000000..cba8766afa --- /dev/null +++ b/Task/FizzBuzz/JavaScript/fizzbuzz-3.js @@ -0,0 +1 @@ +for(var i=1; i<=100; console.log((i%3?'':'Fizz')+(i%5?'':'Buzz')||i), i++); diff --git a/Task/FizzBuzz/JavaScript/fizzbuzz-4.js b/Task/FizzBuzz/JavaScript/fizzbuzz-4.js new file mode 100644 index 0000000000..8179b5aff3 --- /dev/null +++ b/Task/FizzBuzz/JavaScript/fizzbuzz-4.js @@ -0,0 +1,8 @@ +(function() { + var i; + + for (i = 1; i <= 100; i++) { + console.log([i % 3 === 0 ? 'Fizz' : void 0] + [i % 5 === 0 ? 'Buzz' : void 0] || i); + } + +}).call(this); diff --git a/Task/FizzBuzz/JavaScript/fizzbuzz-5.js b/Task/FizzBuzz/JavaScript/fizzbuzz-5.js new file mode 100644 index 0000000000..6d37d23951 --- /dev/null +++ b/Task/FizzBuzz/JavaScript/fizzbuzz-5.js @@ -0,0 +1,25 @@ +var divs = [15, 3, 5]; +var says = ['FizzBuzz', 'Fizz', 'Buzz']; + +function fizzBuzz(first, last) { + for (var n = first; n <= last; n++) { + print(getFizzBuzz(n)); + } +} + +function getFizzBuzz(n) { + var sayWhat = n; + for (var d = 0; d < divs.length; d++) { + if (isMultOf(n, divs[d])) { + sayWhat = says[d]; + break; + } + } + return sayWhat; +} + +function isMultOf(n, d) { + return n % d == 0; +} + +fizzBuzz(1, 100); diff --git a/Task/FizzBuzz/JavaScript/fizzbuzz.js b/Task/FizzBuzz/JavaScript/fizzbuzz.js new file mode 100644 index 0000000000..be188cff9c --- /dev/null +++ b/Task/FizzBuzz/JavaScript/fizzbuzz.js @@ -0,0 +1,32 @@ +for (var i = 1; i <= 100; i++) { + if (i % 15 == 0) { + console.log("FizzBuzz"); + } else if (i % 3 == 0) { + console.log("Fizz"); + } else if (i % 5 == 0) { + console.log("Buzz"); + } else { + console.log(i); + } +} + +// ------------------ +// functional version +// ------------------ +(function (n) { + var r = []; + + while (n--) { + r.push(n + 1); + } + + return r.reverse(); + })(100).map(function (n) { + return !(n % 15) ? + 'FizzBuzz' : + !(n % 3) ? + 'Fizz' : + !(n % 5) ? + 'Buzz' : + n; + }).join('\r\n'); diff --git a/Task/FizzBuzz/Lua/fizzbuzz-2.lua b/Task/FizzBuzz/Lua/fizzbuzz-2.lua new file mode 100644 index 0000000000..0709733a31 --- /dev/null +++ b/Task/FizzBuzz/Lua/fizzbuzz-2.lua @@ -0,0 +1,13 @@ +for i = 1, 100 do + output = "" + if i % 3 == 0 then + output = output.."Fizz" + end + if i % 5 == 0 then + output = output.."Buzz" + end + if(output == "") then + output = output..i + end + print(output) +end diff --git a/Task/FizzBuzz/Lua/fizzbuzz-3.lua b/Task/FizzBuzz/Lua/fizzbuzz-3.lua new file mode 100644 index 0000000000..2b9f976991 --- /dev/null +++ b/Task/FizzBuzz/Lua/fizzbuzz-3.lua @@ -0,0 +1,5 @@ +word = {"Fizz", "Buzz", "FizzBuzz"} + +for i = 1, 100 do + print(word[(i % 3 == 0 and 1 or 0) + (i % 5 == 0 and 2 or 0)] or i) +end diff --git a/Task/FizzBuzz/Lua/fizzbuzz.lua b/Task/FizzBuzz/Lua/fizzbuzz.lua new file mode 100644 index 0000000000..e7414f1fc4 --- /dev/null +++ b/Task/FizzBuzz/Lua/fizzbuzz.lua @@ -0,0 +1,11 @@ +for i = 1, 100 do + if i % 15 == 0 then + print("FizzBuzz") + elseif i % 3 == 0 then + print("Fizz") + elseif i % 5 == 0 then + print("Buzz") + else + print(i) + end +end diff --git a/Task/FizzBuzz/PHP/fizzbuzz-2.php b/Task/FizzBuzz/PHP/fizzbuzz-2.php new file mode 100644 index 0000000000..0acff963a7 --- /dev/null +++ b/Task/FizzBuzz/PHP/fizzbuzz-2.php @@ -0,0 +1,17 @@ + diff --git a/Task/FizzBuzz/PHP/fizzbuzz-3.php b/Task/FizzBuzz/PHP/fizzbuzz-3.php new file mode 100644 index 0000000000..2bfdc1f360 --- /dev/null +++ b/Task/FizzBuzz/PHP/fizzbuzz-3.php @@ -0,0 +1,3 @@ + diff --git a/Task/FizzBuzz/PHP/fizzbuzz.php b/Task/FizzBuzz/PHP/fizzbuzz.php new file mode 100644 index 0000000000..39b3faacb7 --- /dev/null +++ b/Task/FizzBuzz/PHP/fizzbuzz.php @@ -0,0 +1,13 @@ + diff --git a/Task/FizzBuzz/PIR/fizzbuzz.pir b/Task/FizzBuzz/PIR/fizzbuzz.pir new file mode 100644 index 0000000000..933fe60793 --- /dev/null +++ b/Task/FizzBuzz/PIR/fizzbuzz.pir @@ -0,0 +1,34 @@ +.sub main :main + .local int f + .local int mf + .local int skipnum + f = 1 +LOOP: + if f > 100 goto DONE + skipnum = 0 + mf = f % 3 + if mf == 0 goto FIZZ +FIZZRET: + mf = f % 5 + if mf == 0 goto BUZZ +BUZZRET: + if skipnum > 0 goto SKIPNUM + print f +SKIPNUM: + print "\n" + inc f + goto LOOP + end +FIZZ: + print "Fizz" + inc skipnum + goto FIZZRET + end +BUZZ: + print "Buzz" + inc skipnum + goto BUZZRET + end +DONE: + end +.end diff --git a/Task/FizzBuzz/Perl/fizzbuzz-2.pl b/Task/FizzBuzz/Perl/fizzbuzz-2.pl new file mode 100644 index 0000000000..17c880fb60 --- /dev/null +++ b/Task/FizzBuzz/Perl/fizzbuzz-2.pl @@ -0,0 +1 @@ +print 'Fizz'x!($_ % 3) . 'Buzz'x!($_ % 5) || $_, "\n" for 1 .. 100; diff --git a/Task/FizzBuzz/Perl/fizzbuzz-3.pl b/Task/FizzBuzz/Perl/fizzbuzz-3.pl new file mode 100644 index 0000000000..2556b4c276 --- /dev/null +++ b/Task/FizzBuzz/Perl/fizzbuzz-3.pl @@ -0,0 +1 @@ +print+(Fizz)[$_%3].(Buzz)[$_%5]||$_,$/for 1..1e2 diff --git a/Task/FizzBuzz/Perl/fizzbuzz-4.pl b/Task/FizzBuzz/Perl/fizzbuzz-4.pl new file mode 100644 index 0000000000..986ecbe115 --- /dev/null +++ b/Task/FizzBuzz/Perl/fizzbuzz-4.pl @@ -0,0 +1 @@ +map((Fizz)[$_%3].(Buzz)[$_%5]||$_,1..100); diff --git a/Task/FizzBuzz/Perl/fizzbuzz.pl b/Task/FizzBuzz/Perl/fizzbuzz.pl new file mode 100644 index 0000000000..3765b7e368 --- /dev/null +++ b/Task/FizzBuzz/Perl/fizzbuzz.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use feature qw/say/; + +foreach my $i (1 .. 100) { + say + (0 == $i % 15) ? "FizzBuzz" + : (0 == $i % 3) ? "Fizz" + : (0 == $i % 5) ? "Buzz" + : $i + ; +} diff --git a/Task/FizzBuzz/PicoLisp/fizzbuzz-2.l b/Task/FizzBuzz/PicoLisp/fizzbuzz-2.l new file mode 100644 index 0000000000..32362d2089 --- /dev/null +++ b/Task/FizzBuzz/PicoLisp/fizzbuzz-2.l @@ -0,0 +1,7 @@ +(for N 100 + (prinl + (cond + ((=0 (% N 15)) "FizzBuzz") + ((=0 (% N 3)) "Fizz") + ((=0 (% N 5)) "Buzz") + (T N) ) ) ) diff --git a/Task/FizzBuzz/PicoLisp/fizzbuzz.l b/Task/FizzBuzz/PicoLisp/fizzbuzz.l new file mode 100644 index 0000000000..a2981ec674 --- /dev/null +++ b/Task/FizzBuzz/PicoLisp/fizzbuzz.l @@ -0,0 +1,3 @@ +(for N 100 + (prinl + (or (pack (at (0 . 3) "Fizz") (at (0 . 5) "Buzz")) N) ) ) diff --git a/Task/FizzBuzz/Python/fizzbuzz-2.py b/Task/FizzBuzz/Python/fizzbuzz-2.py new file mode 100644 index 0000000000..9e12c84b82 --- /dev/null +++ b/Task/FizzBuzz/Python/fizzbuzz-2.py @@ -0,0 +1,3 @@ +for i in range(1, 101): + words = [word for n, word in ((3, 'Fizz'), (5, 'Buzz')) if not i % n] + print ''.join(words) or i diff --git a/Task/FizzBuzz/Python/fizzbuzz-3.py b/Task/FizzBuzz/Python/fizzbuzz-3.py new file mode 100644 index 0000000000..6d89ba54cb --- /dev/null +++ b/Task/FizzBuzz/Python/fizzbuzz-3.py @@ -0,0 +1,4 @@ +print ('\n'.join(''.join(''.join(['' if i%3 else 'Fizz', + '' if i%5 else 'Buzz']) + or str(i)) + for i in range(1,101))) diff --git a/Task/FizzBuzz/Python/fizzbuzz-4.py b/Task/FizzBuzz/Python/fizzbuzz-4.py new file mode 100644 index 0000000000..ad3bf57d31 --- /dev/null +++ b/Task/FizzBuzz/Python/fizzbuzz-4.py @@ -0,0 +1,2 @@ +for i in range(1, 101): + print 'Fizz'*(not(i%3))+'Buzz'*(not(i%5)) or i diff --git a/Task/FizzBuzz/Python/fizzbuzz-5.py b/Task/FizzBuzz/Python/fizzbuzz-5.py new file mode 100644 index 0000000000..77a5ab5a81 --- /dev/null +++ b/Task/FizzBuzz/Python/fizzbuzz-5.py @@ -0,0 +1,6 @@ +messages = [None, "Fizz", "Buzz", "FizzBuzz"] +acc = 810092048 +for i in xrange(1, 101): + c = acc & 3 + print messages[c] if c else i + acc = acc >> 2 | c << 28 diff --git a/Task/FizzBuzz/Python/fizzbuzz-6.py b/Task/FizzBuzz/Python/fizzbuzz-6.py new file mode 100644 index 0000000000..6c7b67d446 --- /dev/null +++ b/Task/FizzBuzz/Python/fizzbuzz-6.py @@ -0,0 +1,14 @@ +>>> ' '.join(''.join(''.join(['' if i%3 else 'F', + '' if i%5 else 'B']) + or str('00')) + for i in range(1,16)) +'00 00 F 00 B F 00 00 F B 00 F 00 00 FB' +>>> _ +'00 00 F 00 B F 00 00 F B 00 F 00 00 FB' +>>> _.replace('FB','11').replace('F','01').replace('B','10').split()[::-1] +['11', '00', '00', '01', '00', '10', '01', '00', '00', '01', '10', '00', '01', '00', '00'] +>>> '0b' + ''.join(_) +'0b110000010010010000011000010000' +>>> eval(_) +810092048 +>>> diff --git a/Task/FizzBuzz/Python/fizzbuzz-7.py b/Task/FizzBuzz/Python/fizzbuzz-7.py new file mode 100644 index 0000000000..a86ce7860c --- /dev/null +++ b/Task/FizzBuzz/Python/fizzbuzz-7.py @@ -0,0 +1,6 @@ +import random + +for i in range(0, 100): + if not i % 15: + random.seed(1178741599) + print [i+1, "Fizz", "Buzz", "FizzBuzz"][random.randint(0,3)] diff --git a/Task/FizzBuzz/Python/fizzbuzz-8.py b/Task/FizzBuzz/Python/fizzbuzz-8.py new file mode 100644 index 0000000000..b29ebd9a54 --- /dev/null +++ b/Task/FizzBuzz/Python/fizzbuzz-8.py @@ -0,0 +1,13 @@ +from itertools import cycle, izip, count, islice + +fizzes = cycle([""] * 2 + ["Fizz"]) +buzzes = cycle([""] * 4 + ["Buzz"]) +both = (f + b for f, b in izip(fizzes, buzzes)) + +# if the string is "", yield the number +# otherwise yield the string +fizzbuzz = (word or n for word, n in izip(both, count(1))) + +# print the first 100 +for i in islice(fizzbuzz, 100): + print i diff --git a/Task/FizzBuzz/Python/fizzbuzz.py b/Task/FizzBuzz/Python/fizzbuzz.py new file mode 100644 index 0000000000..c36adf9ec8 --- /dev/null +++ b/Task/FizzBuzz/Python/fizzbuzz.py @@ -0,0 +1,9 @@ +for i in xrange(1, 101): + if i % 15 == 0: + print "FizzBuzz" + elif i % 3 == 0: + print "Fizz" + elif i % 5 == 0: + print "Buzz" + else: + print i diff --git a/Task/FizzBuzz/REXX/fizzbuzz-2.rexx b/Task/FizzBuzz/REXX/fizzbuzz-2.rexx new file mode 100644 index 0000000000..634af4a23e --- /dev/null +++ b/Task/FizzBuzz/REXX/fizzbuzz-2.rexx @@ -0,0 +1,11 @@ +/*REXX program displays numbers 1 ──► 100 for the FizzBuzz problem. */ + + do n=1 for 100 + select + when n//15==0 then say 'FizzBuzz' + when n//5 ==0 then say ' Buzz' + when n//3 ==0 then say ' Fizz' + otherwise say right(n,8) + end /*select*/ + end /*n*/ + /*stick a fork in it, we're done.*/ diff --git a/Task/FizzBuzz/REXX/fizzbuzz-3.rexx b/Task/FizzBuzz/REXX/fizzbuzz-3.rexx new file mode 100644 index 0000000000..e32bc77b08 --- /dev/null +++ b/Task/FizzBuzz/REXX/fizzbuzz-3.rexx @@ -0,0 +1,8 @@ +/*REXX program displays numbers 1 ──► 100 for the FizzBuzz problem. */ + + do n=1 for 100; _= + if n//3 ==0 then _= 'Fizz' + if n//5 ==0 then _=_'Buzz' + say right(word(_ n,1),8) + end /*n*/ + /*stick a fork in it, we're done.*/ diff --git a/Task/FizzBuzz/REXX/fizzbuzz.rexx b/Task/FizzBuzz/REXX/fizzbuzz.rexx new file mode 100644 index 0000000000..5582f09226 --- /dev/null +++ b/Task/FizzBuzz/REXX/fizzbuzz.rexx @@ -0,0 +1,9 @@ +/*REXX program displays numbers 1 ──► 100 for the FizzBuzz problem. */ + + do j=1 to 100; z=j + if j//3 ==0 then z='Fizz' + if j//5 ==0 then z='Buzz' + if j//(3*5)==0 then z='FizzBuzz' + say right(z,8) + end /*j*/ + /*stick a fork in it, we're done.*/ diff --git a/Task/FizzBuzz/Ruby/fizzbuzz-2.rb b/Task/FizzBuzz/Ruby/fizzbuzz-2.rb new file mode 100644 index 0000000000..8318b4c788 --- /dev/null +++ b/Task/FizzBuzz/Ruby/fizzbuzz-2.rb @@ -0,0 +1,11 @@ +1.upto(100) do |n| + if (n % 15).zero? + puts "FizzBuzz" + elsif (n % 5).zero? + puts "Buzz" + elsif (n % 3).zero? + puts "Fizz" + else + puts n + end +end diff --git a/Task/FizzBuzz/Ruby/fizzbuzz-3.rb b/Task/FizzBuzz/Ruby/fizzbuzz-3.rb new file mode 100644 index 0000000000..dd398a91cf --- /dev/null +++ b/Task/FizzBuzz/Ruby/fizzbuzz-3.rb @@ -0,0 +1,4 @@ +(1..100).each do |n| + v = "#{"Fizz" if n % 3 == 0}#{"Buzz" if n % 5 == 0}" + puts v.empty? ? n : v +end diff --git a/Task/FizzBuzz/Ruby/fizzbuzz-4.rb b/Task/FizzBuzz/Ruby/fizzbuzz-4.rb new file mode 100644 index 0000000000..08c5db805d --- /dev/null +++ b/Task/FizzBuzz/Ruby/fizzbuzz-4.rb @@ -0,0 +1 @@ +1.upto(100) { |n| puts "#{'Fizz' if n % 3 == 0}#{'Buzz' if n % 5 == 0}#{n if n % 3 != 0 && n % 5 != 0}" } diff --git a/Task/FizzBuzz/Ruby/fizzbuzz-5.rb b/Task/FizzBuzz/Ruby/fizzbuzz-5.rb new file mode 100644 index 0000000000..d87121444e --- /dev/null +++ b/Task/FizzBuzz/Ruby/fizzbuzz-5.rb @@ -0,0 +1,7 @@ +1.upto 100 do |n| + r = '' + r << 'Fizz' if n % 3 == 0 + r << 'Buzz' if n % 5 == 0 + r << n.to_s if r.empty? + puts r +end diff --git a/Task/FizzBuzz/Ruby/fizzbuzz-6.rb b/Task/FizzBuzz/Ruby/fizzbuzz-6.rb new file mode 100644 index 0000000000..d0d167d009 --- /dev/null +++ b/Task/FizzBuzz/Ruby/fizzbuzz-6.rb @@ -0,0 +1 @@ +1.upto(100) { |i| p "#{[:Fizz][i%3]}#{[:Buzz][i%5]}"[/.+/m] || i } diff --git a/Task/FizzBuzz/Ruby/fizzbuzz-7.rb b/Task/FizzBuzz/Ruby/fizzbuzz-7.rb new file mode 100644 index 0000000000..18ccc56ae3 --- /dev/null +++ b/Task/FizzBuzz/Ruby/fizzbuzz-7.rb @@ -0,0 +1,8 @@ +class Integer + def fizzbuzz + v = "#{"Fizz" if self % 3 == 0}#{"Buzz" if self % 5 == 0}" + v.empty? ? self : v + end +end + +puts *(1..100).map(&:fizzbuzz) diff --git a/Task/FizzBuzz/Ruby/fizzbuzz.rb b/Task/FizzBuzz/Ruby/fizzbuzz.rb new file mode 100644 index 0000000000..86a1e61158 --- /dev/null +++ b/Task/FizzBuzz/Ruby/fizzbuzz.rb @@ -0,0 +1,6 @@ +1.upto(100) do |n| + print "Fizz" if a = (n % 3).zero? + print "Buzz" if b = (n % 5).zero? + print n unless (a || b) + print "\n" +end diff --git a/Task/FizzBuzz/SNUSP/fizzbuzz.snusp b/Task/FizzBuzz/SNUSP/fizzbuzz.snusp new file mode 100644 index 0000000000..f12abdc99e --- /dev/null +++ b/Task/FizzBuzz/SNUSP/fizzbuzz.snusp @@ -0,0 +1,35 @@ + / 'B' @=@@=@@++++# + // / 'u' @@@@@=@+++++# + // // / 'z' @=@@@@+@++++# + // // // / 'i' @@@@@@=+++++# + // // // // / 'F' @@@=@@+++++# + // // // // // / LF ++++++++++# + // // // // // // / 100 @@@=@@@=++++# +$@/>@/>@/>@/>@/>@/>@/\ 0 +/ / +! /======= Fizz <<<.<.<..>>># +/ | \ +\?!#->+ @\.>?!#->+ @\.>?!#->+@/.>\ | +/ ! ! ! / | +\?!#->+ @\.>?!#->+@\ .>?!#->+@/.>\ | +/ ! \!===\! ! / | +\?!#->+ @\.>?!#->+ @\.>?!#->+@/.>\ | +/ ! ! | ! / | +\?!#->+@\ .>?!#->+ @\.>?!#->+@/.>\ | +/ \!==========!===\! ! / | +\?!#->+ @\.>?!#->+ @\.>?!#->+@/>>@\.>/ + ! | | | + /==========/ \========!\=== Buzz <<<<<<<.>.>..>>># + | + \!/=dup==?\>>@\+>-/ | \>+<- / + | +/======================/ +| +| /recurse\ #/?\ zero +\print=!\@\>?!\@/<@\.!\-/ + | \=/ \=itoa=@@@+@+++++# + ! /+ !/+ !/+ !/+ \ mod10 + /<+> -\!?-\!?-\!?-\!?-\! + \?!\-?!\-?!\-?!\-?!\-?/\ div10 + # +/! +/! +/! +/! +/ diff --git a/Task/FizzBuzz/Scala/fizzbuzz-2.scala b/Task/FizzBuzz/Scala/fizzbuzz-2.scala new file mode 100644 index 0000000000..b8e56783f0 --- /dev/null +++ b/Task/FizzBuzz/Scala/fizzbuzz-2.scala @@ -0,0 +1,6 @@ +(1 to 100) map ( x => (x % 3, x % 5) match{ + case (0,0) => "FizzBuzz" + case (0,_) => "Fizz" + case (_,0) => "Buzz" + case _ => x +}) foreach println diff --git a/Task/FizzBuzz/Scala/fizzbuzz-3.scala b/Task/FizzBuzz/Scala/fizzbuzz-3.scala new file mode 100644 index 0000000000..07dd694dd5 --- /dev/null +++ b/Task/FizzBuzz/Scala/fizzbuzz-3.scala @@ -0,0 +1,8 @@ +def replaceMultiples(x: Int, rs: (Int, String)*) = + rs map {case (n, s) => Either cond (x % n == 0, s, x)} reduceLeft ((a, b) => + a fold ((_ => b), (s => b fold ((_ => a), (t => Right(s + t)))))) + +def fizzbuzz(n: Int) = + replaceMultiples(n, 3 -> "Fizz", 5 -> "Buzz") fold ((_ toString), identity) + +1 to 100 map fizzbuzz foreach println diff --git a/Task/FizzBuzz/Scala/fizzbuzz-4.scala b/Task/FizzBuzz/Scala/fizzbuzz-4.scala new file mode 100644 index 0000000000..fd15578a3e --- /dev/null +++ b/Task/FizzBuzz/Scala/fizzbuzz-4.scala @@ -0,0 +1,2 @@ +def f(a:Int,b:Int,c:String, d:String):String = if(a % b == 0) c else d +for(i <- 1 to 100) println(f(i,15,"FizzBuzz", f(i,3,"Fizz", f(i,5,"Buzz", i.toString)))) diff --git a/Task/FizzBuzz/Scala/fizzbuzz.scala b/Task/FizzBuzz/Scala/fizzbuzz.scala new file mode 100644 index 0000000000..b4e2b69952 --- /dev/null +++ b/Task/FizzBuzz/Scala/fizzbuzz.scala @@ -0,0 +1,6 @@ +(1 to 100) foreach { + case x if (x % 15 == 0) => println("FizzBuzz") + case x if (x % 3 == 0) => println("Fizz") + case x if (x % 5 == 0) => println("Buzz") + case x => println(x) +} diff --git a/Task/FizzBuzz/Tcl/fizzbuzz-2.tcl b/Task/FizzBuzz/Tcl/fizzbuzz-2.tcl new file mode 100644 index 0000000000..e3e4f73a2a --- /dev/null +++ b/Task/FizzBuzz/Tcl/fizzbuzz-2.tcl @@ -0,0 +1,4 @@ +while {[incr i] < 101} { + set fb [if {$i % 3 == 0} {list Fizz}][if {$i % 5 == 0} {list Buzz}] + if {$fb ne ""} {puts $fb} {puts $i} +} diff --git a/Task/FizzBuzz/Tcl/fizzbuzz.tcl b/Task/FizzBuzz/Tcl/fizzbuzz.tcl new file mode 100644 index 0000000000..0572449b66 --- /dev/null +++ b/Task/FizzBuzz/Tcl/fizzbuzz.tcl @@ -0,0 +1,9 @@ +proc fizzbuzz {n {m1 3} {m2 5}} { + for {set i 1} {$i <= $n} {incr i} { + set ans "" + if {$i % $m1 == 0} {append ans Fizz} + if {$i % $m2 == 0} {append ans Buzz} + puts [expr {$ans eq "" ? $i : $ans}] + } +} +fizzbuzz 100 diff --git a/Task/FizzBuzz/Turing/fizzbuzz.turing b/Task/FizzBuzz/Turing/fizzbuzz.turing new file mode 100644 index 0000000000..6e77eeb0d9 --- /dev/null +++ b/Task/FizzBuzz/Turing/fizzbuzz.turing @@ -0,0 +1,13 @@ +setscreen("nocursor,noecho") + +for i : 1 .. 100 + if i mod 15 = 0 then + put "Fizzbuzz" .. + elsif i mod 5 = 0 then + put "Buzz" .. + elsif i mod 3 = 0 then + put "Fizz" .. + else + put i .. + end if +end for diff --git a/Task/Go_Fish/0DESCRIPTION b/Task/Go_Fish/0DESCRIPTION new file mode 100644 index 0000000000..80273bb73b --- /dev/null +++ b/Task/Go_Fish/0DESCRIPTION @@ -0,0 +1,13 @@ +Write a program to let the user play [[wp:Go Fish|Go Fish]] against a computer opponent. Use the following rules: + +* Each player is dealt nine cards to start with. +* On their turn, a player asks their opponent for a given rank (such as threes or kings). A player must already have at least one card of a given rank to ask for more. +** If the opponent has any cards of the named rank, they must hand over all such cards, and the requester can ask again. +** If the opponent has no cards of the named rank, the requester draws a card and ends their turn. +* A ''book'' is a collection of every card of a given rank. Whenever a player completes a book, they may remove it from their hand. +* If at any time a player's hand is empty, they may immediately draw a new card, so long as any new cards remain in the deck. +* The game ends when every book is complete. The player with the most books wins. + +The game's AI need not be terribly smart, but it should use at least some strategy. That is, it shouldn't choose legal moves entirely at random. + +You may want to use code from [[Playing Cards]]. diff --git a/Task/Go_Fish/1META.yaml b/Task/Go_Fish/1META.yaml new file mode 100644 index 0000000000..a2413d963b --- /dev/null +++ b/Task/Go_Fish/1META.yaml @@ -0,0 +1,2 @@ +--- +note: Games diff --git a/Task/Infinity/0DESCRIPTION b/Task/Infinity/0DESCRIPTION new file mode 100644 index 0000000000..50dcf49773 --- /dev/null +++ b/Task/Infinity/0DESCRIPTION @@ -0,0 +1,5 @@ +Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding [[IEEE]] numbers), and if so, returns positive infinity. Otherwise, return the largest possible positive floating point number. + +For languages with several floating point types, use the type of the literal constant 1.5 as floating point type. + +C.F. [[Extreme floating point values]] diff --git a/Task/Infinity/1META.yaml b/Task/Infinity/1META.yaml new file mode 100644 index 0000000000..c134699d16 --- /dev/null +++ b/Task/Infinity/1META.yaml @@ -0,0 +1,4 @@ +--- +category: +- Discrete math +note: Basic language learning diff --git a/Task/Infinity/AWK/infinity.awk b/Task/Infinity/AWK/infinity.awk new file mode 100644 index 0000000000..c5256d31e5 --- /dev/null +++ b/Task/Infinity/AWK/infinity.awk @@ -0,0 +1,6 @@ + BEGIN { + k=1; + while (2^(k-1) < 2^k) k++; + INF = 2^k; + print INF; + } diff --git a/Task/Infinity/C/infinity-2.c b/Task/Infinity/C/infinity-2.c new file mode 100644 index 0000000000..a42bfe53c1 --- /dev/null +++ b/Task/Infinity/C/infinity-2.c @@ -0,0 +1,9 @@ +#define _ISOC99_SOURCE + +#include +#include + +int main() { + printf("%g\n", INFINITY); + return 0; +} diff --git a/Task/Infinity/C/infinity.c b/Task/Infinity/C/infinity.c new file mode 100644 index 0000000000..e556a1c5e3 --- /dev/null +++ b/Task/Infinity/C/infinity.c @@ -0,0 +1,11 @@ +#include /* HUGE_VAL */ +#include /* printf() */ + +double inf(void) { + return HUGE_VAL; +} + +int main() { + printf("%g\n", inf()); + return 0; +} diff --git a/Task/Infinity/CoffeeScript/infinity-2.coffee b/Task/Infinity/CoffeeScript/infinity-2.coffee new file mode 100644 index 0000000000..b0ceae9d1f --- /dev/null +++ b/Task/Infinity/CoffeeScript/infinity-2.coffee @@ -0,0 +1,2 @@ +Number.POSITIVE_INFINITY +Number.NEGATIVE_INFINITY diff --git a/Task/Infinity/CoffeeScript/infinity-3.coffee b/Task/Infinity/CoffeeScript/infinity-3.coffee new file mode 100644 index 0000000000..00ec5bef02 --- /dev/null +++ b/Task/Infinity/CoffeeScript/infinity-3.coffee @@ -0,0 +1 @@ +isFinite x diff --git a/Task/Infinity/CoffeeScript/infinity.coffee b/Task/Infinity/CoffeeScript/infinity.coffee new file mode 100644 index 0000000000..3c62151db7 --- /dev/null +++ b/Task/Infinity/CoffeeScript/infinity.coffee @@ -0,0 +1 @@ +Infinity diff --git a/Task/Infinity/Forth/infinity.fth b/Task/Infinity/Forth/infinity.fth new file mode 100644 index 0000000000..a544c8b60d --- /dev/null +++ b/Task/Infinity/Forth/infinity.fth @@ -0,0 +1,7 @@ +: inf ( -- f ) 1e 0e f/ ; +inf f. \ implementation specific. GNU Forth will output "inf" + +: inf? ( f -- ? ) s" MAX-FLOAT" environment? drop f> ; +\ IEEE infinity is the only value for which this will return true + +: has-inf ( -- ? ) ['] inf catch if false else inf? then ; diff --git a/Task/Infinity/Fortran/infinity-2.f b/Task/Infinity/Fortran/infinity-2.f new file mode 100644 index 0000000000..0d47917bd8 --- /dev/null +++ b/Task/Infinity/Fortran/infinity-2.f @@ -0,0 +1,2 @@ +real :: x +real :: huge_real = huge(x) diff --git a/Task/Infinity/Fortran/infinity.f b/Task/Infinity/Fortran/infinity.f new file mode 100644 index 0000000000..49e41b8bcf --- /dev/null +++ b/Task/Infinity/Fortran/infinity.f @@ -0,0 +1,18 @@ +program to_f_the_ineffable + use, intrinsic :: ieee_arithmetic + integer :: i + real dimension(2) :: y, x = (/ 30, ieee_value(y,ieee_positive_inf) /) + + do i = 1, 2 + if (ieee_support_datatype(x(i))) then + if (ieee_is_finite(x(i))) then + print *, 'x(',i,') is finite' + else + print *, 'x(',i,') is infinite' + end if + + else + print *, 'x(',i,') is not in an IEEE-supported format' + end if + end do +end program to_f_the_ineffable diff --git a/Task/Infinity/Go/infinity.go b/Task/Infinity/Go/infinity.go new file mode 100644 index 0000000000..039b26ad77 --- /dev/null +++ b/Task/Infinity/Go/infinity.go @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "math" +) + +// function called for by task +func posInf() float64 { + return math.Inf(1) // argument specifies positive infinity +} + +func main() { + x := 1.5 // type of x determined by literal + // that this compiles demonstrates that PosInf returns same type as x, + // the type specified by the task. + x = posInf() // test function + fmt.Println(x, math.IsInf(x, 1)) // demonstrate result +} diff --git a/Task/Infinity/Haskell/infinity-2.hs b/Task/Infinity/Haskell/infinity-2.hs new file mode 100644 index 0000000000..7ba9e3b04b --- /dev/null +++ b/Task/Infinity/Haskell/infinity-2.hs @@ -0,0 +1,4 @@ +*Main> infinity :: Float +Infinity +*Main> infinity :: Double +Infinity diff --git a/Task/Infinity/Haskell/infinity-3.hs b/Task/Infinity/Haskell/infinity-3.hs new file mode 100644 index 0000000000..61ac36066e --- /dev/null +++ b/Task/Infinity/Haskell/infinity-3.hs @@ -0,0 +1,4 @@ +Prelude> 1 / 0 :: Float +Infinity +Prelude> 1 / 0 :: Double +Infinity diff --git a/Task/Infinity/Haskell/infinity-4.hs b/Task/Infinity/Haskell/infinity-4.hs new file mode 100644 index 0000000000..b09e2b96c0 --- /dev/null +++ b/Task/Infinity/Haskell/infinity-4.hs @@ -0,0 +1,4 @@ +Prelude> read "Infinity" :: Float +Infinity +Prelude> read "Infinity" :: Double +Infinity diff --git a/Task/Infinity/Haskell/infinity.hs b/Task/Infinity/Haskell/infinity.hs new file mode 100644 index 0000000000..bf790bf3a6 --- /dev/null +++ b/Task/Infinity/Haskell/infinity.hs @@ -0,0 +1,8 @@ +maxRealFloat :: RealFloat a => a -> a +maxRealFloat x = encodeFloat b (e-1) `asTypeOf` x where + b = floatRadix x - 1 + (_,e) = floatRange x + +infinity :: RealFloat a => a +infinity = if isInfinite inf then inf else maxRealFloat 1.0 where + inf = 1/0 diff --git a/Task/Infinity/Java/infinity-2.java b/Task/Infinity/Java/infinity-2.java new file mode 100644 index 0000000000..36d599f6b2 --- /dev/null +++ b/Task/Infinity/Java/infinity-2.java @@ -0,0 +1,3 @@ +public static double getInf(){ + return Double.POSITIVE_INFINITY; +} diff --git a/Task/Infinity/Java/infinity-3.java b/Task/Infinity/Java/infinity-3.java new file mode 100644 index 0000000000..079e60458d --- /dev/null +++ b/Task/Infinity/Java/infinity-3.java @@ -0,0 +1 @@ +double biggestNumber = Double.MAX_VALUE; diff --git a/Task/Infinity/Java/infinity.java b/Task/Infinity/Java/infinity.java new file mode 100644 index 0000000000..95bf97fd15 --- /dev/null +++ b/Task/Infinity/Java/infinity.java @@ -0,0 +1,2 @@ +double infinity = Double.POSITIVE_INFINITY; //defined as 1.0/0.0 +Double.isInfinite(infinity); //true diff --git a/Task/Infinity/JavaScript/infinity-2.js b/Task/Infinity/JavaScript/infinity-2.js new file mode 100644 index 0000000000..b0ceae9d1f --- /dev/null +++ b/Task/Infinity/JavaScript/infinity-2.js @@ -0,0 +1,2 @@ +Number.POSITIVE_INFINITY +Number.NEGATIVE_INFINITY diff --git a/Task/Infinity/JavaScript/infinity-3.js b/Task/Infinity/JavaScript/infinity-3.js new file mode 100644 index 0000000000..b9525f7ab4 --- /dev/null +++ b/Task/Infinity/JavaScript/infinity-3.js @@ -0,0 +1 @@ +isFinite(x) diff --git a/Task/Infinity/JavaScript/infinity.js b/Task/Infinity/JavaScript/infinity.js new file mode 100644 index 0000000000..3c62151db7 --- /dev/null +++ b/Task/Infinity/JavaScript/infinity.js @@ -0,0 +1 @@ +Infinity diff --git a/Task/Infinity/Lua/infinity.lua b/Task/Infinity/Lua/infinity.lua new file mode 100644 index 0000000000..b36ff6fff8 --- /dev/null +++ b/Task/Infinity/Lua/infinity.lua @@ -0,0 +1,3 @@ +function infinity() + return 1/0 --lua uses unboxed C floats for all numbers +end diff --git a/Task/Infinity/PHP/infinity.php b/Task/Infinity/PHP/infinity.php new file mode 100644 index 0000000000..771404d0bc --- /dev/null +++ b/Task/Infinity/PHP/infinity.php @@ -0,0 +1 @@ +INF diff --git a/Task/Infinity/Perl/infinity-2.pl b/Task/Infinity/Perl/infinity-2.pl new file mode 100644 index 0000000000..859944103c --- /dev/null +++ b/Task/Infinity/Perl/infinity-2.pl @@ -0,0 +1,2 @@ +my $x = 0 - "inf"; +my $y = 0 + "-inf"; diff --git a/Task/Infinity/Perl/infinity-3.pl b/Task/Infinity/Perl/infinity-3.pl new file mode 100644 index 0000000000..ac265d2b5a --- /dev/null +++ b/Task/Infinity/Perl/infinity-3.pl @@ -0,0 +1 @@ +my $x = "inf"; diff --git a/Task/Infinity/Perl/infinity-4.pl b/Task/Infinity/Perl/infinity-4.pl new file mode 100644 index 0000000000..534306d257 --- /dev/null +++ b/Task/Infinity/Perl/infinity-4.pl @@ -0,0 +1 @@ +my $x = 1e1000; diff --git a/Task/Infinity/Perl/infinity-5.pl b/Task/Infinity/Perl/infinity-5.pl new file mode 100644 index 0000000000..10ec1bfa94 --- /dev/null +++ b/Task/Infinity/Perl/infinity-5.pl @@ -0,0 +1 @@ +my $y = 10**10**10; diff --git a/Task/Infinity/Perl/infinity-6.pl b/Task/Infinity/Perl/infinity-6.pl new file mode 100644 index 0000000000..b1e36a9650 --- /dev/null +++ b/Task/Infinity/Perl/infinity-6.pl @@ -0,0 +1,3 @@ +use bigint; +my $x = 1e1000; +my $y = 10**10**10; diff --git a/Task/Infinity/Perl/infinity-7.pl b/Task/Infinity/Perl/infinity-7.pl new file mode 100644 index 0000000000..9fb8f3fd02 --- /dev/null +++ b/Task/Infinity/Perl/infinity-7.pl @@ -0,0 +1,3 @@ +use bigint; +my $x = inf; +my $y = -inf; diff --git a/Task/Infinity/Perl/infinity.pl b/Task/Infinity/Perl/infinity.pl new file mode 100644 index 0000000000..0717c7c76a --- /dev/null +++ b/Task/Infinity/Perl/infinity.pl @@ -0,0 +1,2 @@ +my $x = 0 + "inf"; +my $y = 0 + "+inf"; diff --git a/Task/Infinity/PicoLisp/infinity.l b/Task/Infinity/PicoLisp/infinity.l new file mode 100644 index 0000000000..0a732013b3 --- /dev/null +++ b/Task/Infinity/PicoLisp/infinity.l @@ -0,0 +1,4 @@ +(load "@lib/math.l") + +: (exp 1000.0) +-> T diff --git a/Task/Infinity/Python/infinity-2.py b/Task/Infinity/Python/infinity-2.py new file mode 100644 index 0000000000..c13366eda3 --- /dev/null +++ b/Task/Infinity/Python/infinity-2.py @@ -0,0 +1,4 @@ +>>> 1.0 / 0.0 +Traceback (most recent call last): + File "", line 1, in +ZeroDivisionError: float division diff --git a/Task/Infinity/Python/infinity.py b/Task/Infinity/Python/infinity.py new file mode 100644 index 0000000000..474264f5ce --- /dev/null +++ b/Task/Infinity/Python/infinity.py @@ -0,0 +1,2 @@ +>>> float('infinity') +inf diff --git a/Task/Infinity/Ruby/infinity-2.rb b/Task/Infinity/Ruby/infinity-2.rb new file mode 100644 index 0000000000..620a64e88f --- /dev/null +++ b/Task/Infinity/Ruby/infinity-2.rb @@ -0,0 +1 @@ +a = Float::INFINITY # => Infinity diff --git a/Task/Infinity/Ruby/infinity.rb b/Task/Infinity/Ruby/infinity.rb new file mode 100644 index 0000000000..45f1534eb8 --- /dev/null +++ b/Task/Infinity/Ruby/infinity.rb @@ -0,0 +1,10 @@ +a = 1.0/0 # => Infinity +a.finite? # => false +a.infinite? # => 1 + +a = -1/0.0 # => -Infinity +a.infinite? # => -1 + +a = Float::MAX # => 1.79769313486232e+308 +a.finite? # => true +a.infinite? # => nil diff --git a/Task/Infinity/Scala/infinity.scala b/Task/Infinity/Scala/infinity.scala new file mode 100644 index 0000000000..71b6dcbea1 --- /dev/null +++ b/Task/Infinity/Scala/infinity.scala @@ -0,0 +1,11 @@ +scala> 1 / 0. +res2: Double = Infinity + +scala> -1 / 0. +res3: Double = -Infinity + +scala> 1 / Double.PositiveInfinity +res4: Double = 0.0 + +scala> 1 / Double.NegativeInfinity +res5: Double = -0.0 diff --git a/Task/Infinity/Tcl/infinity-2.tcl b/Task/Infinity/Tcl/infinity-2.tcl new file mode 100644 index 0000000000..77d21526ee --- /dev/null +++ b/Task/Infinity/Tcl/infinity-2.tcl @@ -0,0 +1,11 @@ +% format %lx -1 ;# all bits set +ffffffffffffffff + +% regsub f 0x[format %lx -1] 7 ;# unset the sign bit for positive +0x7fffffffffffffff + +% set ii [expr [regsub f 0x[format %lx -1] 7]] ;# show as decimal +9223372036854775807 + +% incr ii +9223372036854775808 ;# silently upgrade to unbounded integer, still positive diff --git a/Task/Infinity/Tcl/infinity.tcl b/Task/Infinity/Tcl/infinity.tcl new file mode 100644 index 0000000000..a9f41d7b13 --- /dev/null +++ b/Task/Infinity/Tcl/infinity.tcl @@ -0,0 +1,6 @@ +package require Tcl 8.5 + +expr {1.0 / 0} ;# ==> Inf +expr {-1.0 / 0} ;# ==> -Inf +expr {inf} ;# ==> Inf +expr {1 / 0} ;# ==> "divide by zero" error; Inf not part of range of integer division diff --git a/Task/JSON/0DESCRIPTION b/Task/JSON/0DESCRIPTION new file mode 100644 index 0000000000..1ed462ca48 --- /dev/null +++ b/Task/JSON/0DESCRIPTION @@ -0,0 +1,2 @@ +Load a [[wp:JSON|JSON]] string into a data structure. Also create a new data structure and serialize it into JSON. +Use objects and arrays (as appropriate for your language) and make sure your JSON is valid (http://www.jsonlint.com/). diff --git a/Task/JSON/C/json.c b/Task/JSON/C/json.c new file mode 100644 index 0000000000..a6229b2b15 --- /dev/null +++ b/Task/JSON/C/json.c @@ -0,0 +1,120 @@ +#include +#include +#include +#include +#include + +static void print_callback (void *ctx, const char *str, size_t len) +{ + FILE *f = (FILE *) ctx; + fwrite (str, 1, len, f); +} + +static void check_status (yajl_gen_status status) +{ + if (status != yajl_gen_status_ok) + { + fprintf (stderr, "yajl_gen_status was %d\n", (int) status); + exit (EXIT_FAILURE); + } +} + +static void serialize_value (yajl_gen gen, yajl_val val, int parse_numbers) +{ + size_t i; + + switch (val->type) + { + case yajl_t_string: + check_status (yajl_gen_string (gen, + (const unsigned char *) val->u.string, + strlen (val->u.string))); + break; + case yajl_t_number: + if (parse_numbers && YAJL_IS_INTEGER (val)) + check_status (yajl_gen_integer (gen, YAJL_GET_INTEGER (val))); + else if (parse_numbers && YAJL_IS_DOUBLE (val)) + check_status (yajl_gen_double (gen, YAJL_GET_DOUBLE (val))); + else + check_status (yajl_gen_number (gen, YAJL_GET_NUMBER (val), + strlen (YAJL_GET_NUMBER (val)))); + break; + case yajl_t_object: + check_status (yajl_gen_map_open (gen)); + for (i = 0 ; i < val->u.object.len ; i++) + { + check_status (yajl_gen_string (gen, + (const unsigned char *) val->u.object.keys[i], + strlen (val->u.object.keys[i]))); + serialize_value (gen, val->u.object.values[i], parse_numbers); + } + check_status (yajl_gen_map_close (gen)); + break; + case yajl_t_array: + check_status (yajl_gen_array_open (gen)); + for (i = 0 ; i < val->u.array.len ; i++) + serialize_value (gen, val->u.array.values[i], parse_numbers); + check_status (yajl_gen_array_close (gen)); + break; + case yajl_t_true: + check_status (yajl_gen_bool (gen, 1)); + break; + case yajl_t_false: + check_status (yajl_gen_bool (gen, 0)); + break; + case yajl_t_null: + check_status (yajl_gen_null (gen)); + break; + default: + fprintf (stderr, "unexpectedly got type %d\n", (int) val->type); + exit (EXIT_FAILURE); + } +} + +static void print_tree (FILE *f, yajl_val tree, int parse_numbers) +{ + yajl_gen gen; + + gen = yajl_gen_alloc (NULL); + if (! gen) + { + fprintf (stderr, "yajl_gen_alloc failed\n"); + exit (EXIT_FAILURE); + } + + if (0 == yajl_gen_config (gen, yajl_gen_beautify, 1) || + 0 == yajl_gen_config (gen, yajl_gen_validate_utf8, 1) || + 0 == yajl_gen_config (gen, yajl_gen_print_callback, print_callback, f)) + { + fprintf (stderr, "yajl_gen_config failed\n"); + exit (EXIT_FAILURE); + } + + serialize_value (gen, tree, parse_numbers); + yajl_gen_free (gen); +} + +int main (int argc, char **argv) +{ + char err_buf[200]; + const char *json = + "{\"pi\": 3.14, \"large number\": 123456789123456789123456789, " + "\"an array\": [-1, true, false, null, \"foo\"]}"; + yajl_val tree; + + tree = yajl_tree_parse (json, err_buf, sizeof (err_buf)); + if (! tree) + { + fprintf (stderr, "parsing failed because: %s\n", err_buf); + return EXIT_FAILURE; + } + + printf ("Treating numbers as strings...\n"); + print_tree (stdout, tree, 0); + printf ("Parsing numbers to long long or double...\n"); + print_tree (stdout, tree, 1); + + yajl_tree_free (tree); + + return EXIT_SUCCESS; +} diff --git a/Task/JSON/Clojure/json.clj b/Task/JSON/Clojure/json.clj new file mode 100644 index 0000000000..5f6c4b0da6 --- /dev/null +++ b/Task/JSON/Clojure/json.clj @@ -0,0 +1,10 @@ +(use 'clojure.data.json) + + ; Load as Clojure data structures and bind the resulting structure to 'json-map'. +(def json-map (read-json "{ \"foo\": 1, \"bar\": [10, \"apples\"] }")) + +; Use pr-str to print out the Clojure representation of the JSON created by read-json. +(pr-str json-map) + +; Pretty-print the Clojure representation of JSON. We've come full circle. +(pprint-json json-map) diff --git a/Task/JSON/CoffeeScript/json.coffee b/Task/JSON/CoffeeScript/json.coffee new file mode 100644 index 0000000000..650d3e60ce --- /dev/null +++ b/Task/JSON/CoffeeScript/json.coffee @@ -0,0 +1,9 @@ +sample = + blue: [1, 2] + ocean: 'water' + +json_string = JSON.stringify sample +json_obj = JSON.parse json_string + +console.log json_string +console.log json_obj diff --git a/Task/JSON/Go/json-2.go b/Task/JSON/Go/json-2.go new file mode 100644 index 0000000000..9f6b92c4b6 --- /dev/null +++ b/Task/JSON/Go/json-2.go @@ -0,0 +1,59 @@ +package main + +import "encoding/json" +import "fmt" + +type Person struct { + Name string `json:"name"` + Age int `json:"age,omitempty"` + Addr *Address `json:"address,omitempty"` + Ph []string `json:"phone,omitempty"` +} + +type Address struct { + Street string `json:"street"` + City string `json:"city"` + State string `json:"state"` + Zip string `json:"zip"` +} + +func main() { + // compare with output, note apt field ignored, missing fields + // have zero values. + jData := []byte(`{ + "name": "Smith", + "address": { + "street": "21 2nd Street", + "apt": "507", + "city": "New York", + "state": "NY", + "zip": "10021" + } + }`) + var p Person + err := json.Unmarshal(jData, &p) + if err != nil { + fmt.Println(err) + } else { + fmt.Printf("%+v\n %+v\n\n", p, p.Addr) + } + + // compare with output, note empty fields omitted. + pList := []Person{ + { + Name: "Jones", + Age: 21, + }, + { + Name: "Smith", + Addr: &Address{"21 2nd Street", "New York", "NY", "10021"}, + Ph: []string{"212 555-1234", "646 555-4567"}, + }, + } + jData, err = json.MarshalIndent(pList, "", " ") + if err != nil { + fmt.Println(err) + } else { + fmt.Println(string(jData)) + } +} diff --git a/Task/JSON/Go/json.go b/Task/JSON/Go/json.go new file mode 100644 index 0000000000..e4133fc81c --- /dev/null +++ b/Task/JSON/Go/json.go @@ -0,0 +1,25 @@ +package main + +import "encoding/json" +import "fmt" + +func main() { + var data interface{} + err := json.Unmarshal([]byte(`{"foo":1, "bar":[10, "apples"]}`), &data) + if err == nil { + fmt.Println(data) + } else { + fmt.Println(err) + } + + sample := map[string]interface{}{ + "blue": []interface{}{1, 2}, + "ocean": "water", + } + json_string, err := json.Marshal(sample) + if err == nil { + fmt.Println(string(json_string)) + } else { + fmt.Println(err) + } +} diff --git a/Task/JSON/Haskell/json.hs b/Task/JSON/Haskell/json.hs new file mode 100644 index 0000000000..fc34901038 --- /dev/null +++ b/Task/JSON/Haskell/json.hs @@ -0,0 +1,24 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Data.Aeson +import Data.Attoparsec (parseOnly) +import Data.Text +import qualified Data.ByteString.Lazy.Char8 as B +import qualified Data.ByteString.Char8 as S + +testdoc = object [ + "foo" .= (1 :: Int), + "bar" .= ([1.3, 1.6, 1.9] :: [Double]), + "baz" .= ("some string" :: Text), + "other" .= object [ + "yes" .= ("sir" :: Text) + ] + ] + +main = do + let out = encode testdoc + B.putStrLn out + case parseOnly json (S.concat $ B.toChunks out) of + Left e -> error $ "strange error re-parsing json: " ++ (show e) + Right v | v /= testdoc -> error "documents not equal!" + Right v | otherwise -> print v diff --git a/Task/JSON/Java/json.java b/Task/JSON/Java/json.java new file mode 100644 index 0000000000..07d76538ba --- /dev/null +++ b/Task/JSON/Java/json.java @@ -0,0 +1,43 @@ +import com.google.gson.Gson; + +public class JsonExample { + + public static void main(String[] args) { + Gson gson = new Gson(); + String json = "{ \"foo\": 1, \"bar\": [ \"10\", \"apples\"] }"; + + MyJsonObject obj = gson.fromJson(json, MyJsonObject.class); + + System.out.println(obj.getFoo()); + + for(String bar : obj.getBar()) { + System.out.println(bar); + } + + obj = new MyJsonObject(2, new String[] { "20", "oranges" }); + json = gson.toJson(obj); + + System.out.println(json); + } + +} + +class MyJsonObject { + + private int foo; + private String[] bar; + + public MyJsonObject(int foo, String[] bar) { + this.foo = foo; + this.bar = bar; + } + + public int getFoo() { + return foo; + } + + public String[] getBar() { + return bar; + } + +} diff --git a/Task/JSON/JavaScript/json-2.js b/Task/JSON/JavaScript/json-2.js new file mode 100644 index 0000000000..12bfc25cde --- /dev/null +++ b/Task/JSON/JavaScript/json-2.js @@ -0,0 +1 @@ +var data = eval('(' + '{ "foo": 1, "bar": [10, "apples"] }' + ')'); diff --git a/Task/JSON/JavaScript/json.js b/Task/JSON/JavaScript/json.js new file mode 100644 index 0000000000..8f09e91936 --- /dev/null +++ b/Task/JSON/JavaScript/json.js @@ -0,0 +1,4 @@ +var data = JSON.parse('{ "foo": 1, "bar": [10, "apples"] }'); + +var sample = { "blue": [1,2], "ocean": "water" }; +var json_string = JSON.stringify(sample); diff --git a/Task/JSON/PHP/json.php b/Task/JSON/PHP/json.php new file mode 100644 index 0000000000..6035c758c1 --- /dev/null +++ b/Task/JSON/PHP/json.php @@ -0,0 +1,7 @@ + array(1,2), "ocean" => "water" ); +$json_string = json_encode($sample); +?> diff --git a/Task/JSON/Perl/json.pl b/Task/JSON/Perl/json.pl new file mode 100644 index 0000000000..81ebb630a2 --- /dev/null +++ b/Task/JSON/Perl/json.pl @@ -0,0 +1,6 @@ +use JSON; + +my $data = decode_json('{ "foo": 1, "bar": [10, "apples"] }'); + +my $sample = { blue => [1,2], ocean => "water" }; +my $json_string = encode_json($sample); diff --git a/Task/JSON/PicoLisp/json.l b/Task/JSON/PicoLisp/json.l new file mode 100644 index 0000000000..b1c1273fe6 --- /dev/null +++ b/Task/JSON/PicoLisp/json.l @@ -0,0 +1,49 @@ +(de checkJson (X Item) + (unless (= X Item) + (quit "Bad JSON" Item) ) ) + +(de readJson () + (case (read "_") + ("{" + (make + (for (X (readJson) (not (= "}" X)) (readJson)) + (checkJson ":" (readJson)) + (link (cons X (readJson))) + (T (= "}" (setq X (readJson)))) + (checkJson "," X) ) ) ) + ("[" + (make + (link T) # Array marker + (for (X (readJson) (not (= "]" X)) (readJson)) + (link X) + (T (= "]" (setq X (readJson)))) + (checkJson "," X) ) ) ) + (T + (let X @ + (cond + ((pair X) (pack X)) + ((and (= "-" X) (format (peek))) + (- (read)) ) + (T X) ) ) ) ) ) + +(de printJson (Item) # For simplicity, without indentation + (cond + ((atom Item) (if Item (print @) (prin "{}"))) + ((=T (car Item)) + (prin "[") + (map + '((X) + (printJson (car X)) + (and (cdr X) (prin ", ")) ) + (cdr Item) ) + (prin "]") ) + (T + (prin "{") + (map + '((X) + (print (caar X)) + (prin ": ") + (printJson (cdar X)) + (and (cdr X) (prin ", ")) ) + Item ) + (prin "}") ) ) ) diff --git a/Task/JSON/Python/json-2.py b/Task/JSON/Python/json-2.py new file mode 100644 index 0000000000..f7fd43dd07 --- /dev/null +++ b/Task/JSON/Python/json-2.py @@ -0,0 +1,4 @@ +>>> true = True; false = False; null = None +>>> data = eval('{ "foo": 1, "bar": [10, "apples"] }') +>>> data +{'foo': 1, 'bar': [10, 'apples']} diff --git a/Task/JSON/Python/json.py b/Task/JSON/Python/json.py new file mode 100644 index 0000000000..59b796e40b --- /dev/null +++ b/Task/JSON/Python/json.py @@ -0,0 +1,10 @@ +>>> import json +>>> data = json.loads('{ "foo": 1, "bar": [10, "apples"] }') +>>> sample = { "blue": [1,2], "ocean": "water" } +>>> json_string = json.dumps(sample) +>>> json_string +'{"blue": [1, 2], "ocean": "water"}' +>>> sample +{'blue': [1, 2], 'ocean': 'water'} +>>> data +{'foo': 1, 'bar': [10, 'apples']} diff --git a/Task/JSON/Ruby/json.rb b/Task/JSON/Ruby/json.rb new file mode 100644 index 0000000000..6cec45a5ba --- /dev/null +++ b/Task/JSON/Ruby/json.rb @@ -0,0 +1,7 @@ +require 'json' +ruby_obj = JSON.parse('{"blue": [1, 2], "ocean": "water"}') +p ruby_obj +puts ruby_obj.class +puts ruby_obj["blue"].class +ruby_obj["ocean"] = {"water" => %w{fishy salty}} +puts JSON.generate(ruby_obj) diff --git a/Task/JSON/Scala/json.scala b/Task/JSON/Scala/json.scala new file mode 100644 index 0000000000..5a421216ab --- /dev/null +++ b/Task/JSON/Scala/json.scala @@ -0,0 +1,8 @@ +scala> import scala.util.parsing.json.{JSON, JSONObject} +import scala.util.parsing.json.{JSON, JSONObject} + +scala> JSON.parseFull("""{"foo": "bar"}""") +res0: Option[Any] = Some(Map(foo -> bar)) + +scala> JSONObject(Map("foo" -> "bar")).toString() +res1: String = {"foo" : "bar"} diff --git a/Task/JSON/Tcl/json-2.tcl b/Task/JSON/Tcl/json-2.tcl new file mode 100644 index 0000000000..ea3c147562 --- /dev/null +++ b/Task/JSON/Tcl/json-2.tcl @@ -0,0 +1,56 @@ +package require Tcl 8.6 + +proc tcl2json value { + # Guess the type of the value; deep *UNSUPPORTED* magic! + regexp {^value is a (.*?) with a refcount} \ + [::tcl::unsupported::representation $value] -> type + + switch $type { + string { + # Skip to the mapping code at the bottom + } + dict { + set result "{" + set pfx "" + dict for {k v} $value { + append result $pfx [tcl2json $k] ": " [tcl2json $v] + set pfx ", " + } + return [append result "}"] + } + list { + set result "\[" + set pfx "" + foreach v $value { + append result $pfx [tcl2json $v] + set pfx ", " + } + return [append result "\]"] + } + int - double { + return [expr {$value}] + } + booleanString { + return [expr {$value ? "true" : "false"}] + } + default { + # Some other type; do some guessing... + if {$value eq "null"} { + # Tcl has *no* null value at all; empty strings are semantically + # different and absent variables aren't values. So cheat! + return $value + } elseif {[string is integer -strict $value]} { + return [expr {$value}] + } elseif {[string is double -strict $value]} { + return [expr {$value}] + } elseif {[string is boolean -strict $value]} { + return [expr {$value ? "true" : "false"}] + } + } + } + + # For simplicity, all "bad" characters are mapped to \u... substitutions + set mapped [subst -novariables [regsub -all {[][\u0000-\u001f\\""]} \ + $value {[format "\\\\u%04x" [scan {& } %c]]}]] + return "\"$mapped\"" +} diff --git a/Task/JSON/Tcl/json-3.tcl b/Task/JSON/Tcl/json-3.tcl new file mode 100644 index 0000000000..140f94410e --- /dev/null +++ b/Task/JSON/Tcl/json-3.tcl @@ -0,0 +1,2 @@ +set d [dict create blue [list 1 2] ocean water] +puts [tcl2json $d] diff --git a/Task/JSON/Tcl/json.tcl b/Task/JSON/Tcl/json.tcl new file mode 100644 index 0000000000..bc10d588e7 --- /dev/null +++ b/Task/JSON/Tcl/json.tcl @@ -0,0 +1,5 @@ +package require json +set sample {{ "foo": 1, "bar": [10, "apples"] }} + +set parsed [json::json2dict $sample] +puts $parsed diff --git a/Task/Knuth_shuffle/0DESCRIPTION b/Task/Knuth_shuffle/0DESCRIPTION new file mode 100644 index 0000000000..144434b6e7 --- /dev/null +++ b/Task/Knuth_shuffle/0DESCRIPTION @@ -0,0 +1 @@ +Implement the [[wp:Knuth shuffle|Knuth shuffle]] (a.k.a. the Fisher-Yates shuffle) for an integer array (or, if possible, an array of any type). The Knuth shuffle is used to create a random permutation of an array. diff --git a/Task/Knuth_shuffle/1META.yaml b/Task/Knuth_shuffle/1META.yaml new file mode 100644 index 0000000000..f407ff9d83 --- /dev/null +++ b/Task/Knuth_shuffle/1META.yaml @@ -0,0 +1,2 @@ +--- +note: Classic CS problems and programs diff --git a/Task/Knuth_shuffle/AWK/knuth_shuffle.awk b/Task/Knuth_shuffle/AWK/knuth_shuffle.awk new file mode 100644 index 0000000000..f1d2564b7a --- /dev/null +++ b/Task/Knuth_shuffle/AWK/knuth_shuffle.awk @@ -0,0 +1,21 @@ +# Shuffle an _array_ with indexes from 1 to _len_. +function shuffle(array, len, i, j, t) { + for (i = len; i > 1; i--) { + # j = random integer from 1 to i + j = int(i * rand()) + 1 + + # swap array[i], array[j] + t = array[i] + array[i] = array[j] + array[j] = t + } +} + +# Test program. +BEGIN { + len = split("11 22 33 44 55 66 77 88 99 110", array) + shuffle(array, len) + + for (i = 1; i < len; i++) printf "%s ", array[i] + printf "%s\n", array[len] +} diff --git a/Task/Knuth_shuffle/BASIC/knuth_shuffle.bas b/Task/Knuth_shuffle/BASIC/knuth_shuffle.bas new file mode 100644 index 0000000000..4349d8a606 --- /dev/null +++ b/Task/Knuth_shuffle/BASIC/knuth_shuffle.bas @@ -0,0 +1,21 @@ +RANDOMIZE TIMER + +DIM cards(51) AS INTEGER +DIM L0 AS LONG, card AS LONG + +PRINT "before:" +FOR L0 = 0 TO 51 + cards(L0) = L0 + PRINT LTRIM$(STR$(cards(L0))); " "; +NEXT + +FOR L0 = 51 TO 0 STEP -1 + card = INT(RND * (L0 + 1)) + IF card <> L0 THEN SWAP cards(card), cards(L0) +NEXT + +PRINT : PRINT "after:" +FOR L0 = 0 TO 51 + PRINT LTRIM$(STR$(cards(L0))); " "; +NEXT +PRINT diff --git a/Task/Knuth_shuffle/C/knuth_shuffle-2.c b/Task/Knuth_shuffle/C/knuth_shuffle-2.c new file mode 100644 index 0000000000..3b23a0297e --- /dev/null +++ b/Task/Knuth_shuffle/C/knuth_shuffle-2.c @@ -0,0 +1,52 @@ +#include +#include + +/* define a shuffle function. e.g. decl_shuffle(double). + * advantage: compiler is free to optimize the swap operation without + * indirection with pointers, which could be much faster. + * disadvantage: each datatype needs a separate instance of the function. + * for a small funciton like this, it's not very big a deal. + */ +#define decl_shuffle(type) \ +void shuffle_##type(type *list, size_t len) { \ + int j; \ + type tmp; \ + while(len) { \ + j = irand(len); \ + if (j != len - 1) { \ + tmp = list[j]; \ + list[j] = list[len - 1]; \ + list[len - 1] = tmp; \ + } \ + len--; \ + } \ +} \ + +/* random integer from 0 to n-1 */ +int irand(int n) +{ + int r, rand_max = RAND_MAX - (RAND_MAX % n); + /* reroll until r falls in a range that can be evenly + * distributed in n bins. Unless n is comparable to + * to RAND_MAX, it's not *that* important really. */ + while ((r = rand()) >= rand_max); + return r / (rand_max / n); +} + +/* declare and define int type shuffle function from macro */ +decl_shuffle(int); + +int main() +{ + int i, x[20]; + + for (i = 0; i < 20; i++) x[i] = i; + for (printf("before:"), i = 0; i < 20 || !printf("\n"); i++) + printf(" %d", x[i]); + + shuffle_int(x, 20); + + for (printf("after: "), i = 0; i < 20 || !printf("\n"); i++) + printf(" %d", x[i]); + return 0; +} diff --git a/Task/Knuth_shuffle/C/knuth_shuffle.c b/Task/Knuth_shuffle/C/knuth_shuffle.c new file mode 100644 index 0000000000..8d986e5f4f --- /dev/null +++ b/Task/Knuth_shuffle/C/knuth_shuffle.c @@ -0,0 +1,21 @@ +#include +#include + +int rrand(int m) +{ + return (int)((double)m * ( rand() / (RAND_MAX+1.0) )); +} + +#define BYTE(X) ((unsigned char *)(X)) +void shuffle(void *obj, size_t nmemb, size_t size) +{ + void *temp = malloc(size); + size_t n = nmemb; + while ( n > 1 ) { + size_t k = rrand(n--); + memcpy(temp, BYTE(obj) + n*size, size); + memcpy(BYTE(obj) + n*size, BYTE(obj) + k*size, size); + memcpy(BYTE(obj) + k*size, temp, size); + } + free(temp); +} diff --git a/Task/Knuth_shuffle/Clojure/knuth_shuffle.clj b/Task/Knuth_shuffle/Clojure/knuth_shuffle.clj new file mode 100644 index 0000000000..dbfa4a4c5c --- /dev/null +++ b/Task/Knuth_shuffle/Clojure/knuth_shuffle.clj @@ -0,0 +1,4 @@ +(defn shuffle [vect] + (reduce (fn [v i] (let [r (rand-int i)] + (assoc v i (v r) r (v i))) + vect (range (dec (count vect)) 1 -1))) diff --git a/Task/Knuth_shuffle/CoffeeScript/knuth_shuffle.coffee b/Task/Knuth_shuffle/CoffeeScript/knuth_shuffle.coffee new file mode 100644 index 0000000000..77ff7de9b8 --- /dev/null +++ b/Task/Knuth_shuffle/CoffeeScript/knuth_shuffle.coffee @@ -0,0 +1,21 @@ +knuth_shuffle = (a) -> + n = a.length + while n > 1 + r = Math.floor(n * Math.random()) + n -= 1 + [a[n], a[r]] = [a[r], a[n]] + a + +counts = + "1,2,3": 0 + "1,3,2": 0 + "2,1,3": 0 + "2,3,1": 0 + "3,1,2": 0 + "3,2,1": 0 + +for i in [1..100000] + counts[knuth_shuffle([ 1, 2, 3 ]).join(",")] += 1 + +for key, val of counts + console.log "#{key}: #{val}" diff --git a/Task/Knuth_shuffle/Forth/knuth_shuffle.fth b/Task/Knuth_shuffle/Forth/knuth_shuffle.fth new file mode 100644 index 0000000000..2afa0c3047 --- /dev/null +++ b/Task/Knuth_shuffle/Forth/knuth_shuffle.fth @@ -0,0 +1,15 @@ +include random.fs + +: shuffle ( deck size -- ) + 2 swap do + dup i random cells + + over @ over @ swap + rot ! over ! + cell+ + -1 +loop drop ; + +: .array 0 do dup @ . cell+ loop drop ; + +create deck 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , + +deck 10 2dup shuffle .array diff --git a/Task/Knuth_shuffle/Fortran/knuth_shuffle.f b/Task/Knuth_shuffle/Fortran/knuth_shuffle.f new file mode 100644 index 0000000000..cd937ffba0 --- /dev/null +++ b/Task/Knuth_shuffle/Fortran/knuth_shuffle.f @@ -0,0 +1,33 @@ +program Knuth_Shuffle + implicit none + + integer, parameter :: reps = 1000000 + integer :: i, n + integer, dimension(10) :: a, bins = 0, initial = (/ (n, n=1,10) /) + + do i = 1, reps + a = initial + call Shuffle(a) + where (a == initial) bins = bins + 1 ! skew tester + end do + write(*, "(10(i8))") bins +! prints 100382 100007 99783 100231 100507 99921 99941 100270 100290 100442 + +contains + +subroutine Shuffle(a) + integer, intent(inout) :: a(:) + integer :: i, randpos, temp + real :: r + + do i = size(a), 2, -1 + call random_number(r) + randpos = int(r * i) + 1 + temp = a(randpos) + a(randpos) = a(i) + a(i) = temp + end do + +end subroutine Shuffle + +end program Knuth_Shuffle diff --git a/Task/Knuth_shuffle/Go/knuth_shuffle-2.go b/Task/Knuth_shuffle/Go/knuth_shuffle-2.go new file mode 100644 index 0000000000..23dbef3916 --- /dev/null +++ b/Task/Knuth_shuffle/Go/knuth_shuffle-2.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" + "math/rand" + "time" +) + +// Generic Knuth Shuffle algorithm. In Go, this is done with interface +// types. The parameter s of function shuffle is an interface type. +// Any type satisfying the interface "shuffler" can be shuffled with +// this function. Since the shuffle function uses the random number +// generator, it's nice to seed the generator at program load time. +func init() { + rand.Seed(time.Now().UnixNano()) +} +func shuffle(s shuffler) { + for i := s.Len() - 1; i >= 1; i-- { + j := rand.Intn(i + 1) + s.Swap(i, j) + } +} + +// Conceptually, a shuffler is an indexed collection of things. +// It requires just two simple methods. +type shuffler interface { + Len() int // number of things in the collection + Swap(i, j int) // swap the two things indexed by i and j +} + +// ints is an example of a concrete type implementing the shuffler +// interface. +type ints []int + +func (s ints) Len() int { return len(s) } +func (s ints) Swap(i, j int) { s[i], s[j] = s[j], s[i] } + +// Example program. Make an ints collection, fill with sequential numbers, +// print, shuffle, print. +func main() { + a := make(ints, 20) + for i := range a { + a[i] = i + } + fmt.Println(a) + shuffle(a) + fmt.Println(a) +} diff --git a/Task/Knuth_shuffle/Go/knuth_shuffle.go b/Task/Knuth_shuffle/Go/knuth_shuffle.go new file mode 100644 index 0000000000..d254e4dc75 --- /dev/null +++ b/Task/Knuth_shuffle/Go/knuth_shuffle.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + "math/rand" + "time" +) + +func main() { + var a [20]int + for i := range a { + a[i] = i + } + fmt.Println(a) + + rand.Seed(time.Now().UnixNano()) + for i := len(a) - 1; i >= 1; i-- { + j := rand.Intn(i + 1) + a[i], a[j] = a[j], a[i] + } + fmt.Println(a) +} diff --git a/Task/Knuth_shuffle/Haskell/knuth_shuffle-2.hs b/Task/Knuth_shuffle/Haskell/knuth_shuffle-2.hs new file mode 100644 index 0000000000..bd14b8fb3a --- /dev/null +++ b/Task/Knuth_shuffle/Haskell/knuth_shuffle-2.hs @@ -0,0 +1,3 @@ +knuthShuffleProcess :: (Show a) => [a] -> IO () +knuthShuffleProcess = + (mapM_ print. reverse =<<). ap (fmap. (. zip [1..]). scanr swapElems) (mkRands. length) diff --git a/Task/Knuth_shuffle/Haskell/knuth_shuffle-3.hs b/Task/Knuth_shuffle/Haskell/knuth_shuffle-3.hs new file mode 100644 index 0000000000..5576690d2a --- /dev/null +++ b/Task/Knuth_shuffle/Haskell/knuth_shuffle-3.hs @@ -0,0 +1,21 @@ +import Data.Array.ST +import Data.STRef +import Control.Monad +import Control.Monad.ST +import Control.Arrow +import System.Random + +shuffle :: RandomGen g => [a] -> g -> ([a], g) +shuffle list g = runST $ do + r <- newSTRef g + let rand range = liftM (randomR range) (readSTRef r) >>= + runKleisli (second (Kleisli $ writeSTRef r) >>> arr fst) + a <- newAry (1, len) list + forM_ [len, len - 1 .. 2] $ \n -> do + k <- rand (1, n) + liftM2 (,) (readArray a k) (readArray a n) >>= + runKleisli (Kleisli (writeArray a n) *** Kleisli (writeArray a k)) + liftM2 (,) (getElems a) (readSTRef r) + where len = length list + newAry :: (Int, Int) -> [a] -> ST s (STArray s Int a) + newAry = newListArray diff --git a/Task/Knuth_shuffle/Haskell/knuth_shuffle.hs b/Task/Knuth_shuffle/Haskell/knuth_shuffle.hs new file mode 100644 index 0000000000..b2a80bc637 --- /dev/null +++ b/Task/Knuth_shuffle/Haskell/knuth_shuffle.hs @@ -0,0 +1,17 @@ +import System.Random +import Data.List +import Control.Monad +import Control.Arrow + +mkRands = mapM (randomRIO.(,)0 ). enumFromTo 1. pred + +replaceAt :: Int -> a -> [a] -> [a] +replaceAt i c = let (a,b) = splitAt i l in a++x:(drop 1 b) + +swapElems :: (Int, Int) -> [a] -> [a] +swapElems (i,j) xs | i==j = xs + | otherwise = replaceAt j (xs!!i) $ replaceAt i (xs!!j) xs + +knuthShuffle :: [a] -> IO [a] +knuthShuffle xs = + liftM (foldr swapElems xs. zip [1..]) (mkRands (length xs)) diff --git a/Task/Knuth_shuffle/Java/knuth_shuffle.java b/Task/Knuth_shuffle/Java/knuth_shuffle.java new file mode 100644 index 0000000000..390a6936a1 --- /dev/null +++ b/Task/Knuth_shuffle/Java/knuth_shuffle.java @@ -0,0 +1,24 @@ +import java.util.Random; + +public static final Random gen = new Random(); + +// version for array of ints +public static void shuffle (int[] array) { + int n = array.length; + while (n > 1) { + int k = gen.nextInt(n--); //decrements after using the value + int temp = array[n]; + array[n] = array[k]; + array[k] = temp; + } +} +// version for array of references +public static void shuffle (Object[] array) { + int n = array.length; + while (n > 1) { + int k = gen.nextInt(n--); //decrements after using the value + Object temp = array[n]; + array[n] = array[k]; + array[k] = temp; + } +} diff --git a/Task/Knuth_shuffle/JavaScript/knuth_shuffle.js b/Task/Knuth_shuffle/JavaScript/knuth_shuffle.js new file mode 100644 index 0000000000..7de9e0b8cc --- /dev/null +++ b/Task/Knuth_shuffle/JavaScript/knuth_shuffle.js @@ -0,0 +1,28 @@ +function knuth_shuffle(a) { + var n = a.length, + r, + temp; + while (n > 1) { + r = Math.floor(n * Math.random()); + n -= 1; + temp = a[n]; + a[n] = a[r]; + a[r] = temp; + } + return a; +} + +var res, i, key; + +res = { + '1,2,3': 0, '1,3,2': 0, + '2,1,3': 0, '2,3,1': 0, + '3,1,2': 0, '3,2,1': 0 +}; + +for (i = 0; i < 100000; i++) { + res[knuth_shuffle([1,2,3]).join(',')] += 1; +} +for (key in res) { + print(key + "\t" + res[key]); +} diff --git a/Task/Knuth_shuffle/Lua/knuth_shuffle.lua b/Task/Knuth_shuffle/Lua/knuth_shuffle.lua new file mode 100644 index 0000000000..4e0b7324aa --- /dev/null +++ b/Task/Knuth_shuffle/Lua/knuth_shuffle.lua @@ -0,0 +1,14 @@ +function table.shuffle(t) + local n = #t + while n > 1 do + local k = math.random(n) + t[n], t[k] = t[k], t[n] + n = n - 1 + end + + return t +end +math.randomseed( os.time() ) +a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} +table.shuffle(a) +for i,v in ipairs(a) do print(i,v) end diff --git a/Task/Knuth_shuffle/PHP/knuth_shuffle.php b/Task/Knuth_shuffle/PHP/knuth_shuffle.php new file mode 100644 index 0000000000..53e15245f8 --- /dev/null +++ b/Task/Knuth_shuffle/PHP/knuth_shuffle.php @@ -0,0 +1,18 @@ +//The Fisher-Yates original Method +function yates_shuffle($arr){ + $shuffled = Array(); + while($arr){ + $rnd = array_rand($arr); + $shuffled[] = $arr[$rnd]; + array_splice($arr, $rnd, 1); + } + return $shuffled; +} + +//The modern Durstenfeld-Knuth algorithm +function knuth_shuffle(&$arr){ + for($i=count($arr)-1;$i>0;$i--){ + $rnd = mt_rand(0,$i); + list($arr[$i], $arr[$rnd]) = array($arr[$rnd], $arr[$i]); + } +} diff --git a/Task/Knuth_shuffle/Perl/knuth_shuffle.pl b/Task/Knuth_shuffle/Perl/knuth_shuffle.pl new file mode 100644 index 0000000000..d01495e01a --- /dev/null +++ b/Task/Knuth_shuffle/Perl/knuth_shuffle.pl @@ -0,0 +1,8 @@ +sub shuffle { + my @a = @_; + foreach my $n (1 .. $#a) { + my $k = int rand $n + 1; + $k == $n or @a[$k, $n] = @a[$n, $k]; + } + return @a; +} diff --git a/Task/Knuth_shuffle/PicoLisp/knuth_shuffle.l b/Task/Knuth_shuffle/PicoLisp/knuth_shuffle.l new file mode 100644 index 0000000000..9ee26eb142 --- /dev/null +++ b/Task/Knuth_shuffle/PicoLisp/knuth_shuffle.l @@ -0,0 +1,7 @@ +(de shuffle (Lst) + (make + (for (N (length Lst) (gt0 N)) + (setq Lst + (conc + (cut (rand 0 (dec 'N)) 'Lst) + (prog (link (car Lst)) (cdr Lst)) ) ) ) ) ) diff --git a/Task/Knuth_shuffle/Python/knuth_shuffle.py b/Task/Knuth_shuffle/Python/knuth_shuffle.py new file mode 100644 index 0000000000..35b6ed0943 --- /dev/null +++ b/Task/Knuth_shuffle/Python/knuth_shuffle.py @@ -0,0 +1,10 @@ +from random import randrange + +def knuth_shuffle(x): + for i in range(len(x)-1, 0, -1): + j = randrange(i + 1) + x[i], x[j] = x[j], x[i] + +x = list(range(10)) +knuth_shuffle(x) +print("shuffled:", x) diff --git a/Task/Knuth_shuffle/REXX/knuth_shuffle.rexx b/Task/Knuth_shuffle/REXX/knuth_shuffle.rexx new file mode 100644 index 0000000000..e0d41a9587 --- /dev/null +++ b/Task/Knuth_shuffle/REXX/knuth_shuffle.rexx @@ -0,0 +1,37 @@ +/*REXX program shuffles a deck of playing cards using the Knuth shuffle.*/ +rank='ace duece trey 4 5 6 7 8 9 10 jack queen king' +suit='club spade diamond heart' +say '────────────────── getting a new deck out of the box...' +deck.1=' color joker' /*good decks have a color joker, */ +deck.2=' b&w joker' /*∙∙∙ and a black & white joker. */ +cards=2 /*now, two cards are in the deck.*/ + do j =1 for words(suit) + do k=1 for words(rank) + cards=cards+1 + deck.cards=right(word(suit,j),7) word(rank,k) + end /*k*/ + end /*j*/ + +call showDeck 'ace' /*inserts blank when ACE is found*/ +say '────────────────── shuffling' cards "cards..." + + do s=cards by -1 to 1; rand=random(1,s) + if rand\==s then do /*swap two cards in the card deck*/ + _=deck.rand + deck.rand=deck.s + deck.s=_ + end + end /*s*/ + +call showDeck +say '────────────────── ready to play schafkopf (take out jokers first).' +exit /*stick a fork in it, we're done.*/ + +/*──────────────────────────────────SHOWDECK subroutine─────────────────*/ +showDeck: parse arg break; say + do m=1 for cards + if pos(break,deck.m)\==0 then say /*blank, easier to read cards*/ + say 'card' right(m,2) '───►' deck.m + end /*m*/ +say +return diff --git a/Task/Knuth_shuffle/Ruby/knuth_shuffle-2.rb b/Task/Knuth_shuffle/Ruby/knuth_shuffle-2.rb new file mode 100644 index 0000000000..00744e0383 --- /dev/null +++ b/Task/Knuth_shuffle/Ruby/knuth_shuffle-2.rb @@ -0,0 +1,9 @@ +class Array + def knuth_shuffle! + (length - 1).downto(1) do |i| + j = rand(i + 1) + self[i], self[j] = self[j], self[i] + end + self + end +end diff --git a/Task/Knuth_shuffle/Ruby/knuth_shuffle.rb b/Task/Knuth_shuffle/Ruby/knuth_shuffle.rb new file mode 100644 index 0000000000..31d09263c2 --- /dev/null +++ b/Task/Knuth_shuffle/Ruby/knuth_shuffle.rb @@ -0,0 +1,21 @@ +class Array + def knuth_shuffle! + j = length + i = 0 + while j > 1 + r = i + rand(j) + self[i], self[r] = self[r], self[i] + i += 1 + j -= 1 + end + self + end +end + +r = Hash.new(0) +100_000.times do |i| + a = [1,2,3].knuth_shuffle! + r[a] += 1 +end + +r.keys.sort.each {|a| puts "#{a.inspect} => #{r[a]}"} diff --git a/Task/Knuth_shuffle/Scala/knuth_shuffle.scala b/Task/Knuth_shuffle/Scala/knuth_shuffle.scala new file mode 100644 index 0000000000..f3c1202bf6 --- /dev/null +++ b/Task/Knuth_shuffle/Scala/knuth_shuffle.scala @@ -0,0 +1,9 @@ +def shuffle[T](a: Array[T]) = { + for (i <- 1 until a.size reverse) { + val j = util.Random nextInt (i + 1) + val t = a(i) + a(i) = a(j) + a(j) = t + } + a +} diff --git a/Task/Knuth_shuffle/Tcl/knuth_shuffle-2.tcl b/Task/Knuth_shuffle/Tcl/knuth_shuffle-2.tcl new file mode 100644 index 0000000000..82da48c54f --- /dev/null +++ b/Task/Knuth_shuffle/Tcl/knuth_shuffle-2.tcl @@ -0,0 +1,11 @@ +% for {set i 0} {$i<100000} {incr i} { + foreach val [knuth_shuffle {1 2 3 4 5}] pos {pos0 pos1 pos2 pos3 pos4} { + incr tots($pos) $val + } +} +% parray tots +tots(pos0) = 300006 +tots(pos1) = 300223 +tots(pos2) = 299701 +tots(pos3) = 299830 +tots(pos4) = 300240 diff --git a/Task/Knuth_shuffle/Tcl/knuth_shuffle.tcl b/Task/Knuth_shuffle/Tcl/knuth_shuffle.tcl new file mode 100644 index 0000000000..7e208bb012 --- /dev/null +++ b/Task/Knuth_shuffle/Tcl/knuth_shuffle.tcl @@ -0,0 +1,17 @@ +proc knuth_shuffle lst { + set j [llength $lst] + for {set i 0} {$j > 1} {incr i;incr j -1} { + set r [expr {$i+int(rand()*$j)}] + set t [lindex $lst $i] + lset lst $i [lindex $lst $r] + lset lst $r $t + } + return $lst +} + +% knuth_shuffle {1 2 3 4 5} +2 1 3 5 4 +% knuth_shuffle {1 2 3 4 5} +5 2 1 4 3 +% knuth_shuffle {tom dick harry peter paul mary} +tom paul mary harry peter dick diff --git a/Task/Narcissist/0DESCRIPTION b/Task/Narcissist/0DESCRIPTION new file mode 100644 index 0000000000..433655a0e9 --- /dev/null +++ b/Task/Narcissist/0DESCRIPTION @@ -0,0 +1,9 @@ +Quoting from the [http://esolangs.org/wiki/Narcissist Esolangs wiki page]: + +
+A '''narcissist''' (or '''Narcissus program''') is the decision-problem version of a [[quine]]. +
+A quine, when run, takes no input, but produces a copy of its own source code at its output. In contrast, a narcissist reads a string of symbols from its input, and produces no output except a "1" or "accept" if that string matches its own source code, or a "0" or "reject" if it does not. +
+ +For concreteness, in this task we shall assume that symbol = character. The narcissist should be able to cope with any finite input, whatever its length. Any form of output is allowed, as long as the program always halts, and "accept", "reject" and "not yet finished" are distinguishable. diff --git a/Task/Narcissist/C/narcissist.c b/Task/Narcissist/C/narcissist.c new file mode 100644 index 0000000000..83db180a8b --- /dev/null +++ b/Task/Narcissist/C/narcissist.c @@ -0,0 +1 @@ +extern void*stdin;main(){ char*p = "extern void*stdin;main(){ char*p = %c%s%c,a[300],b[300];sprintf(a,p,34,p,34);fgets(b,300,stdin);putchar(48+!strcmp(a,b)); }",a[300],b[300];sprintf(a,p,34,p,34);fgets(b,300,stdin);putchar(48+!strcmp(a,b)); } diff --git a/Task/Narcissist/Forth/narcissist.fth b/Task/Narcissist/Forth/narcissist.fth new file mode 100644 index 0000000000..50a281bcbd --- /dev/null +++ b/Task/Narcissist/Forth/narcissist.fth @@ -0,0 +1 @@ +: narcissist [ source ] sliteral compare 0= ; diff --git a/Task/Narcissist/Go/narcissist-2.go b/Task/Narcissist/Go/narcissist-2.go new file mode 100644 index 0000000000..77bd5402c4 --- /dev/null +++ b/Task/Narcissist/Go/narcissist-2.go @@ -0,0 +1,39 @@ +package main + +import ( + "bytes" + "fmt" + "io/ioutil" + "os" +) + +func main() { + s := fmt.Sprintf("%s%c%s%c\n", x, 0x60, x, 0x60) + in, _ := ioutil.ReadAll(os.Stdin) + if bytes.Equal(in, []byte(s)) { + fmt.Println("Accept") + } else { + fmt.Println("Reject") + } +} + +var x = `package main + +import ( + "bytes" + "fmt" + "io/ioutil" + "os" +) + +func main() { + s := fmt.Sprintf("%s%c%s%c\n", x, 0x60, x, 0x60) + in, _ := ioutil.ReadAll(os.Stdin) + if bytes.Equal(in, []byte(s)) { + fmt.Println("Accept") + } else { + fmt.Println("Reject") + } +} + +var x = ` diff --git a/Task/Narcissist/Go/narcissist.go b/Task/Narcissist/Go/narcissist.go new file mode 100644 index 0000000000..6ecbd85927 --- /dev/null +++ b/Task/Narcissist/Go/narcissist.go @@ -0,0 +1 @@ +package main; import "os"; import "fmt"; import "bytes"; import "io/ioutil"; func main() {ios := "os"; ifmt := "fmt"; ibytes := "bytes"; iioutil := "io/ioutil"; zero := "Reject"; one := "Accept"; x := "package main; import %q; import %q; import %q; import %q; func main() {ios := %q; ifmt := %q; ibytes := %q; iioutil := %q; zero := %q; one := %q; x := %q; s := fmt.Sprintf(x, ios, ifmt, ibytes, iioutil, ios, ifmt, ibytes, iioutil, zero, one, x); in, _ := ioutil.ReadAll(os.Stdin); if bytes.Equal(in, []byte(s)) {fmt.Println(one);} else {fmt.Println(zero);};}\n"; s := fmt.Sprintf(x, ios, ifmt, ibytes, iioutil, ios, ifmt, ibytes, iioutil, zero, one, x); in, _ := ioutil.ReadAll(os.Stdin); if bytes.Equal(in, []byte(s)) {fmt.Println(one);} else {fmt.Println(zero);};} diff --git a/Task/Narcissist/JavaScript/narcissist.js b/Task/Narcissist/JavaScript/narcissist.js new file mode 100644 index 0000000000..ba92829df3 --- /dev/null +++ b/Task/Narcissist/JavaScript/narcissist.js @@ -0,0 +1 @@ +var code='var q=String.fromCharCode(39);print("var code=" + q + code + q + "; eval(code)" == readline())'; eval(code) diff --git a/Task/Narcissist/Perl/narcissist-2.pl b/Task/Narcissist/Perl/narcissist-2.pl new file mode 100644 index 0000000000..9003510ddd --- /dev/null +++ b/Task/Narcissist/Perl/narcissist-2.pl @@ -0,0 +1 @@ +perl narc.pl < narc.pl diff --git a/Task/Narcissist/Perl/narcissist.pl b/Task/Narcissist/Perl/narcissist.pl new file mode 100644 index 0000000000..d984aa5c2b --- /dev/null +++ b/Task/Narcissist/Perl/narcissist.pl @@ -0,0 +1,2 @@ +# this is file narc.pl +print do { local $/; open 0, $0 or die $!; <0> } eq <> ? "accept" : "reject" diff --git a/Task/Narcissist/PicoLisp/narcissist.l b/Task/Narcissist/PicoLisp/narcissist.l new file mode 100644 index 0000000000..463c9107ad --- /dev/null +++ b/Task/Narcissist/PicoLisp/narcissist.l @@ -0,0 +1,2 @@ +(de narcissist (Str) + (= Str (str narcissist)) ) diff --git a/Task/Narcissist/Python/narcissist.py b/Task/Narcissist/Python/narcissist.py new file mode 100644 index 0000000000..f3286c965c --- /dev/null +++ b/Task/Narcissist/Python/narcissist.py @@ -0,0 +1,7 @@ +import sys +with open(sys.argv[0]) as quine: + code = raw_input("Enter source code: ") + if code == quine.read(): + print("Accept") + else: + print("Reject") diff --git a/Task/Narcissist/REXX/narcissist-2.rexx b/Task/Narcissist/REXX/narcissist-2.rexx new file mode 100644 index 0000000000..a150942f80 --- /dev/null +++ b/Task/Narcissist/REXX/narcissist-2.rexx @@ -0,0 +1 @@ +/*REXX*/ say word('reject accept',1+(arg(1)=sourceline(1))) diff --git a/Task/Narcissist/REXX/narcissist.rexx b/Task/Narcissist/REXX/narcissist.rexx new file mode 100644 index 0000000000..1fa0b6365f --- /dev/null +++ b/Task/Narcissist/REXX/narcissist.rexx @@ -0,0 +1 @@ +/*REXX*/ say arg(1)=sourceline(1) diff --git a/Task/Narcissist/Ruby/narcissist.rb b/Task/Narcissist/Ruby/narcissist.rb new file mode 100644 index 0000000000..e5f6f5e1ba --- /dev/null +++ b/Task/Narcissist/Ruby/narcissist.rb @@ -0,0 +1 @@ +s = "s = %s%s%s; puts(gets.chomp == (s %% [34.chr, s, 34.chr]) ? 'accept' : 'reject')"; puts(gets.chomp == (s % [34.chr, s, 34.chr]) ? 'accept' : 'reject') diff --git a/Task/Narcissist/Tcl/narcissist-2.tcl b/Task/Narcissist/Tcl/narcissist-2.tcl new file mode 100644 index 0000000000..91e90a3741 --- /dev/null +++ b/Task/Narcissist/Tcl/narcissist-2.tcl @@ -0,0 +1 @@ +apply {s {puts [expr {[gets stdin]eq[list {*}$s $s]}]}} {apply {s {puts [expr {[gets stdin]eq[list {*}$s $s]}]}}} diff --git a/Task/Narcissist/Tcl/narcissist.tcl b/Task/Narcissist/Tcl/narcissist.tcl new file mode 100644 index 0000000000..cd947c8c50 --- /dev/null +++ b/Task/Narcissist/Tcl/narcissist.tcl @@ -0,0 +1 @@ +apply {{} {puts [expr {[gets stdin] eq [info level 0]}]}} diff --git a/Task/Ordered_words/0DESCRIPTION b/Task/Ordered_words/0DESCRIPTION new file mode 100644 index 0000000000..47f3b6df13 --- /dev/null +++ b/Task/Ordered_words/0DESCRIPTION @@ -0,0 +1,3 @@ +Define an ordered word as a word in which the letters of the word appear in alphabetic order. Examples include 'abbey' and 'dirt'. + +The task is to find ''and display'' all the ordered words in this [http://www.puzzlers.org/pub/wordlists/unixdict.txt dictionary] that have the longest word length. (Examples that access the dictionary file locally assume that you have downloaded this file yourself.) The display needs to be shown on this page. diff --git a/Task/Ordered_words/1META.yaml b/Task/Ordered_words/1META.yaml new file mode 100644 index 0000000000..35429e6214 --- /dev/null +++ b/Task/Ordered_words/1META.yaml @@ -0,0 +1,2 @@ +--- +note: text processing diff --git a/Task/Ordered_words/AWK/ordered_words.awk b/Task/Ordered_words/AWK/ordered_words.awk new file mode 100644 index 0000000000..fc25ce217e --- /dev/null +++ b/Task/Ordered_words/AWK/ordered_words.awk @@ -0,0 +1,36 @@ +BEGIN { + abc = "abcdefghijklmnopqrstuvwxyz" +} + +{ + # Check if this line is an ordered word. + ordered = 1 # true + left = -1 + for (i = 1; i <= length($0); i++) { + right = index(abc, substr($0, i, 1)) + if (right == 0 || left > right) { + ordered = 0 # false + break + } + left = right + } + + if (ordered) { + score = length($0) + if (score > best["score"]) { + # Reset the list of best ordered words. + best["score"] = score + best["count"] = 1 + best[1] = $0 + } else if (score == best["score"]) { + # Add this word to the list. + best[++best["count"]] = $0 + } + } +} + +END { + # Print the list of best ordered words. + for (i = 1; i <= best["count"]; i++) + print best[i] +} diff --git a/Task/Ordered_words/C/ordered_words-2.c b/Task/Ordered_words/C/ordered_words-2.c new file mode 100644 index 0000000000..e81142d230 --- /dev/null +++ b/Task/Ordered_words/C/ordered_words-2.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include + + +#define MAXLEN 100 +typedef char TWord[MAXLEN]; + + +typedef struct WordsArray { + TWord *words; + size_t len; +} WordsArray; + + +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; +} + + +void array_append(WordsArray *words_array, const TWord new_word) { + assert(words_array != NULL); + assert(new_word != NULL); + assert((words_array->len == 0) == (words_array->words == NULL)); + + words_array->len++; + words_array->words = realloc(words_array->words, + words_array->len * sizeof(words_array->words[0])); + if (words_array->words == NULL) + exit(EXIT_FAILURE); + strcpy(words_array->words[words_array->len-1], new_word); +} + + +void array_free(WordsArray *words_array) { + assert(words_array != NULL); + free(words_array->words); + words_array->words = NULL; + words_array->len = 0; +} + + +void list_print(WordsArray *words_array) { + assert(words_array != NULL); + size_t i; + for (i = 0; i < words_array->len; i++) + printf("\n%s", words_array->words[i]); +} + + +int main() { + FILE *fp = fopen("unixdict.txt", "r"); + if (fp == NULL) + return EXIT_FAILURE; + + WordsArray words; + words.len = 0; + words.words = NULL; + + TWord line; + line[0] = '\0'; + unsigned int max_len = 0; + + while (fscanf(fp, "%99s\n", line) != EOF) { // 99 = MAXLEN - 1 + if (strlen(line) > max_len && is_ordered_word(line)) { + max_len = strlen(line); + array_free(&words); + array_append(&words, line); + } else if (strlen(line) == max_len && is_ordered_word(line)) { + array_append(&words, line); + } + } + + fclose(fp); + list_print(&words); + array_free(&words); + + return EXIT_SUCCESS; +} diff --git a/Task/Ordered_words/C/ordered_words-3.c b/Task/Ordered_words/C/ordered_words-3.c new file mode 100644 index 0000000000..9c44cd507c --- /dev/null +++ b/Task/Ordered_words/C/ordered_words-3.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int ordered(char *s, char **end) +{ + int r = 1; + while (*++s != '\n' && *s != '\r' && *s != '\0') + if (s[0] < s[-1]) r = 0; + + *end = s; + return r; +} + +int main() +{ + char *buf, *word, *end, *tail; + struct stat st; + int longest = 0, len, fd; + + if ((fd = open("unixdict.txt", O_RDONLY)) == -1) err(1, "read error"); + + fstat(fd, &st); + if (!(buf = mmap(0, st.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0))) + err(1, "mmap"); + + for (word = end = buf; end < buf + st.st_size; word = end) { + while (*word == '\r' || *word == '\n') word++; + if (!ordered(word, &end)) continue; + if ((len = end - word + 1) < longest) continue; + if (len > longest) { + tail = buf; /* longer words found; reset out buffer */ + longest = len; + } + /* use the same mmap'd region to store output. because of MAP_PRIVATE, + * change will not go back to file. mmap is copy on write, and we are using + * only the head space to store output, so kernel doesn't need to copy more + * than the words we saved--in this case, one page tops. + */ + memcpy(tail, word, len); + tail += len; + *tail = '\0'; + } + printf(buf); + + munmap(buf, st.st_size); + close(fd); + return 0; +} diff --git a/Task/Ordered_words/C/ordered_words.c b/Task/Ordered_words/C/ordered_words.c new file mode 100644 index 0000000000..81693068d7 --- /dev/null +++ b/Task/Ordered_words/C/ordered_words.c @@ -0,0 +1,83 @@ +#include +#include +#include +#include + + +#define MAXLEN 100 +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* list_prepend(Node* words_list, const TWord new_word) { + assert(new_word != NULL); + Node *new_node = malloc(sizeof(Node)); + if (new_node == NULL) + exit(EXIT_FAILURE); + + strcpy(new_node->word, new_word); + new_node->next = words_list; + return new_node; +} + + +Node* list_destroy(Node *words_list) { + while (words_list != NULL) { + Node *temp = words_list; + words_list = words_list->next; + free(temp); + } + + return words_list; +} + + +void list_print(Node *words_list) { + while (words_list != NULL) { + printf("\n%s", words_list->word); + words_list = words_list->next; + } +} + + +int main() { + FILE *fp = fopen("unixdict.txt", "r"); + if (fp == NULL) + return EXIT_FAILURE; + + Node *words = NULL; + TWord line; + unsigned int max_len = 0; + + while (fscanf(fp, "%99s\n", line) != EOF) { + if (strlen(line) > max_len && is_ordered_word(line)) { + max_len = strlen(line); + words = list_destroy(words); + words = list_prepend(words, line); + } else if (strlen(line) == max_len && is_ordered_word(line)) { + words = list_prepend(words, line); + } + } + + fclose(fp); + list_print(words); + + return EXIT_SUCCESS; +} diff --git a/Task/Ordered_words/CoffeeScript/ordered_words-2.coffee b/Task/Ordered_words/CoffeeScript/ordered_words-2.coffee new file mode 100644 index 0000000000..a1cc9c0a1e --- /dev/null +++ b/Task/Ordered_words/CoffeeScript/ordered_words-2.coffee @@ -0,0 +1,18 @@ +> coffee ordered_words.coffee +Longest Ordered Words (source=unixdict.txt): +abbott +accent +accept +access +accost +almost +bellow +billow +biopsy +chilly +choosy +choppy +effort +floppy +glossy +knotty diff --git a/Task/Ordered_words/CoffeeScript/ordered_words.coffee b/Task/Ordered_words/CoffeeScript/ordered_words.coffee new file mode 100644 index 0000000000..206918f1cc --- /dev/null +++ b/Task/Ordered_words/CoffeeScript/ordered_words.coffee @@ -0,0 +1,21 @@ +ordered_word = (word) -> + for i in [0...word.length - 1] + return false unless word[i] <= word[i+1] + true + +show_longest_ordered_words = (candidates, dict_file_name) -> + words = [''] + for word in candidates + continue if word.length < words[0].length + if ordered_word word + words = [] if word.length > words[0].length + words.push word + return if words[0] == '' # we came up empty + console.log "Longest Ordered Words (source=#{dict_file_name}):" + for word in words + console.log word + +dict_file_name = 'unixdict.txt' +file_content = require('fs').readFileSync dict_file_name +dict_words = file_content.toString().split '\n' +show_longest_ordered_words dict_words, dict_file_name diff --git a/Task/Ordered_words/Forth/ordered_words.fth b/Task/Ordered_words/Forth/ordered_words.fth new file mode 100644 index 0000000000..dd604eae20 --- /dev/null +++ b/Task/Ordered_words/Forth/ordered_words.fth @@ -0,0 +1,44 @@ +include lib/stmstack.4th \ include string stack library + +: check-word ( a n -- a n f) + 2dup bl >r \ start off with a space + begin + dup \ when not end of word + while + over c@ r@ >= \ check character + while + r> drop over c@ >r chop \ chop character off + repeat r> drop nip 0= \ cleanup and set flag +; + +: open-file ( -- h) + 1 dup argn = abort" Usage: ordered infile" + args input open error? abort" Cannot open file" + dup use \ return and use the handle +; + +: read-file ( --) + 0 >r \ begin with zero length + begin + refill \ EOF detected? + while + 0 parse dup r@ >= \ equal or longer string length? + if \ check the word and adjust length + check-word if r> drop dup >r >s else 2drop then + else \ if it checks out, put on the stack + 2drop \ otherwise drop the word + then + repeat r> drop \ clean it up +; + +: read-back ( --) + s> dup >r type cr \ longest string is on top of stack + begin s> dup r@ >= while type cr repeat + 2drop r> drop \ keep printing until shorter word +; \ has been found + +: ordered ( --) + open-file s.clear read-file read-back close +; \ open file, clear the stack, read file + \ read it back and close the file +ordered diff --git a/Task/Ordered_words/Fortran/ordered_words.f b/Task/Ordered_words/Fortran/ordered_words.f new file mode 100644 index 0000000000..ff6255335c --- /dev/null +++ b/Task/Ordered_words/Fortran/ordered_words.f @@ -0,0 +1,113 @@ +!*************************************************************************************** + module ordered_module +!*************************************************************************************** + implicit none + + !the dictionary file: + integer,parameter :: file_unit = 1000 + character(len=*),parameter :: filename = 'unixdict.txt' + + !maximum number of characters in a word: + integer,parameter :: max_chars = 50 + + type word + character(len=max_chars) :: str !the word from the dictionary + integer :: n = 0 !length of this word + logical :: ordered = .false. !if it is an ordered word + end type word + + !the dictionary structure: + type(word),dimension(:),allocatable :: dict + + contains +!*************************************************************************************** + + !****************************************************************************** + function count_lines_in_file(fid) result(n_lines) + !****************************************************************************** + implicit none + + integer :: n_lines + integer,intent(in) :: fid + character(len=1) :: tmp + integer :: i + integer :: ios + + !the file is assumed to be open already. + + rewind(fid) !rewind to beginning of the file + + n_lines = 0 + do !read each line until the end of the file. + read(fid,'(A1)',iostat=ios) tmp + if (ios < 0) exit !End of file + n_lines = n_lines + 1 !row counter + end do + + rewind(fid) !rewind to beginning of the file + + !****************************************************************************** + end function count_lines_in_file + !****************************************************************************** + + !****************************************************************************** + pure elemental function ordered_word(word) result(yn) + !****************************************************************************** + ! turns true if word is an ordered word, false if it is not. + !****************************************************************************** + + implicit none + character(len=*),intent(in) :: word + logical :: yn + + integer :: i + + yn = .true. + do i=1,len_trim(word)-1 + if (ichar(word(i+1:i+1)) longest { + longest = len(bs) + list = list[:0] + } + list = append(list, bs) + break + } + // check next letter + b := bs[i] + if b < 'a' || b > 'z' { + continue // not a letter. ignore. + } + if b < lastLetter { + break // word not ordered. + } + // letter passes test + lastLetter = b + } + } + // print result + for _, bs := range list { + fmt.Println(string(bs)) + } +} diff --git a/Task/Ordered_words/Haskell/ordered_words-2.hs b/Task/Ordered_words/Haskell/ordered_words-2.hs new file mode 100644 index 0000000000..4b73a7d5ab --- /dev/null +++ b/Task/Ordered_words/Haskell/ordered_words-2.hs @@ -0,0 +1,16 @@ +abbott +accent +accept +access +accost +almost +bellow +billow +biopsy +chilly +choosy +choppy +effort +floppy +glossy +knotty diff --git a/Task/Ordered_words/Haskell/ordered_words-3.hs b/Task/Ordered_words/Haskell/ordered_words-3.hs new file mode 100644 index 0000000000..34b066a1e7 --- /dev/null +++ b/Task/Ordered_words/Haskell/ordered_words-3.hs @@ -0,0 +1,11 @@ +import Control.Monad (liftM) + +isSorted wws@(_ : ws) = and $ zipWith (<=) wws ws + +getLines = liftM lines . readFile + +main = do + ls <- getLines "unixdict.txt" + let ow = filter isSorted ls + let maxl = foldr max 0 (map length ow) + print $ filter (\w -> (length w) == maxl) ow diff --git a/Task/Ordered_words/Haskell/ordered_words.hs b/Task/Ordered_words/Haskell/ordered_words.hs new file mode 100644 index 0000000000..9ea03dc4b4 --- /dev/null +++ b/Task/Ordered_words/Haskell/ordered_words.hs @@ -0,0 +1,21 @@ +-- Words are read from the standard input. We keep in memory only the current +-- set of longest, ordered words. +-- +-- Limitation: the locale's collation order is not take into consideration. + +isOrdered wws@(_:ws) = and $ zipWith (<=) wws ws + +keepLongest _ acc [] = acc +keepLongest max acc (w:ws) = + let len = length w in + case compare len max of + LT -> keepLongest max acc ws + EQ -> keepLongest max (w:acc) ws + GT -> keepLongest len [w] ws + +longestOrderedWords = reverse . keepLongest 0 [] . filter isOrdered + +main = do + str <- getContents + let ws = longestOrderedWords $ words str + mapM_ putStrLn ws diff --git a/Task/Ordered_words/Java/ordered_words.java b/Task/Ordered_words/Java/ordered_words.java new file mode 100644 index 0000000000..a96c558398 --- /dev/null +++ b/Task/Ordered_words/Java/ordered_words.java @@ -0,0 +1,43 @@ +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; + +public class Ordered { + + private static boolean isOrderedWord(String word){ + char[] sortedWord = word.toCharArray(); + Arrays.sort(sortedWord); + return word.equals(new String(sortedWord)); + } + + public static void main(String[] args) throws IOException{ + List orderedWords = new LinkedList(); + BufferedReader in = new BufferedReader(new FileReader(args[0])); + while(in.ready()){ + String word = in.readLine(); + if(isOrderedWord(word)) orderedWords.add(word); + } + in.close(); + + Collections.sort(orderedWords, new Comparator() { + @Override + public int compare(String o1, String o2) { + return new Integer(o2.length()).compareTo(o1.length()); + } + }); + + int maxLen = orderedWords.get(0).length(); + for(String word: orderedWords){ + if(word.length() == maxLen){ + System.out.println(word); + }else{ + break; + } + } + } +} diff --git a/Task/Ordered_words/JavaScript/ordered_words-2.js b/Task/Ordered_words/JavaScript/ordered_words-2.js new file mode 100644 index 0000000000..828dfcdc00 --- /dev/null +++ b/Task/Ordered_words/JavaScript/ordered_words-2.js @@ -0,0 +1,26 @@ +var http = require('http'); + +http.get({ + host: 'www.puzzlers.org', + path: '/pub/wordlists/unixdict.txt' +}, function(res) { + var data = ''; + res.on('data', function(chunk) { + data += chunk; + }); + res.on('end', function() { + var words = data.split('\n'); + var max = 0; + var ordered = []; + words.forEach(function(word) { + if (word.split('').sort().join('') != word) return; + if (word.length == max) { + ordered.push(word); + } else if (word.length > max) { + ordered = [word]; + max = word.length; + } + }); + console.log(ordered.join(', ')); + }); +}); diff --git a/Task/Ordered_words/JavaScript/ordered_words.js b/Task/Ordered_words/JavaScript/ordered_words.js new file mode 100644 index 0000000000..7a8d268edd --- /dev/null +++ b/Task/Ordered_words/JavaScript/ordered_words.js @@ -0,0 +1,11 @@ +var fs = require('fs'), print = require('sys').print; +fs.readFile('./unixdict.txt', 'ascii', function (err, data) { + var is_ordered = function(word){return word.split('').sort().join('') === word;}, + ordered_words = data.split('\n').filter(is_ordered).sort(function(a, b){return a.length - b.length}).reverse(), + longest = [], curr = len = ordered_words[0].length, lcv = 0; + while (curr === len){ + longest.push(ordered_words[lcv]); + curr = ordered_words[++lcv].length; + }; + print(longest.sort().join(', ') + '\n'); +}); diff --git a/Task/Ordered_words/Lua/ordered_words.lua b/Task/Ordered_words/Lua/ordered_words.lua new file mode 100644 index 0000000000..c8dec7cadd --- /dev/null +++ b/Task/Ordered_words/Lua/ordered_words.lua @@ -0,0 +1,29 @@ +fp = io.open( "dictionary.txt" ) + +maxlen = 0 +list = {} + +for w in fp:lines() do + ordered = true + for l = 2, string.len(w) do + if string.byte( w, l-1 ) > string.byte( w, l ) then + ordered = false + break + end + end + if ordered then + if string.len(w) > maxlen then + list = {} + list[1] = w + maxlen = string.len(w) + elseif string.len(w) == maxlen then + list[#list+1] = w + end + end +end + +for _, w in pairs(list) do + print( w ) +end + +fp:close() diff --git a/Task/Ordered_words/Perl/ordered_words.pl b/Task/Ordered_words/Perl/ordered_words.pl new file mode 100644 index 0000000000..e435f0bbfa --- /dev/null +++ b/Task/Ordered_words/Perl/ordered_words.pl @@ -0,0 +1,12 @@ +#!/usr/bin/perl +use strict; +use warnings; + +open(FH, "<", "unixdict.txt") or die "Can't open file!\n"; +my @words; +while () { + chomp; + push @{$words[length]}, $_ if $_ eq join("", sort split(//)); +} +close FH; +print "@{$words[-1]}\n"; diff --git a/Task/Ordered_words/PicoLisp/ordered_words.l b/Task/Ordered_words/PicoLisp/ordered_words.l new file mode 100644 index 0000000000..01cb6c201d --- /dev/null +++ b/Task/Ordered_words/PicoLisp/ordered_words.l @@ -0,0 +1,6 @@ +(in "unixdict.txt" + (mapc prinl + (maxi '((L) (length (car L))) + (by length group + (filter '((S) (apply <= S)) + (make (while (line) (link @))) ) ) ) ) ) diff --git a/Task/Ordered_words/Python/ordered_words-2.py b/Task/Ordered_words/Python/ordered_words-2.py new file mode 100644 index 0000000000..0897f419b4 --- /dev/null +++ b/Task/Ordered_words/Python/ordered_words-2.py @@ -0,0 +1,11 @@ +import urllib.request + +mx, url = 0, 'http://www.puzzlers.org/pub/wordlists/unixdict.txt' + +for word in urllib.request.urlopen(url).read().decode("utf-8").split(): + lenword = len(word) + if lenword >= mx and word==''.join(sorted(word)): + if lenword > mx: + words, mx = [], lenword + words.append(word) +print(' '.join(words)) diff --git a/Task/Ordered_words/Python/ordered_words-3.py b/Task/Ordered_words/Python/ordered_words-3.py new file mode 100644 index 0000000000..a018f09879 --- /dev/null +++ b/Task/Ordered_words/Python/ordered_words-3.py @@ -0,0 +1,3 @@ +from itertools import groupby +o = (w for w in map(str.strip, open("unixdict.txt")) if sorted(w)==list(w)) +print list(next(groupby(sorted(o, key=len, reverse=True), key=len))[1]) diff --git a/Task/Ordered_words/Python/ordered_words.py b/Task/Ordered_words/Python/ordered_words.py new file mode 100644 index 0000000000..b2254189d9 --- /dev/null +++ b/Task/Ordered_words/Python/ordered_words.py @@ -0,0 +1,8 @@ +import urllib.request + +url = 'http://www.puzzlers.org/pub/wordlists/unixdict.txt' +words = urllib.request.urlopen(url).read().decode("utf-8").split() +ordered = [word for word in words if word==''.join(sorted(word))] +maxlen = len(max(ordered, key=len)) +maxorderedwords = [word for word in ordered if len(word) == maxlen] +print(' '.join(maxorderedwords)) diff --git a/Task/Ordered_words/REXX/ordered_words.rexx b/Task/Ordered_words/REXX/ordered_words.rexx new file mode 100644 index 0000000000..b5d1fa3b48 --- /dev/null +++ b/Task/Ordered_words/REXX/ordered_words.rexx @@ -0,0 +1,28 @@ +/*REXX program lists (longest) ordered words from a supplied dictionary.*/ +ifid = 'UNIXDICT.TXT' /*filename of the word dictionary*/ +@.= /*placeholder for list of words. */ +mL=0 /*maximum length of ordered words*/ +call linein ifid,1,0 /*point to the first word in dict*/ + /*(above)───in case file is open.*/ + do j=1 while lines(ifid)\==0 /*keep reading until exhausted. */ + x=linein(ifid); w=length(x) /*get a word and also its length.*/ + if w $len} { + set len [string length $word] + set orderedOfMaxLen {} + } + if {[string length $word] == $len} { + lappend orderedOfMaxLen $word + } + } + } + return $orderedOfMaxLen +} + +# Get the dictionary and print the ordered words from it +set t [http::geturl "http://www.puzzlers.org/pub/wordlists/unixdict.txt"] +puts [chooseOrderedWords [http::data $t]] +http::cleanup $t diff --git a/Task/Pi/0DESCRIPTION b/Task/Pi/0DESCRIPTION new file mode 100644 index 0000000000..922d89a77d --- /dev/null +++ b/Task/Pi/0DESCRIPTION @@ -0,0 +1,4 @@ +Create a program to continually calculate and output the next digit of \pi (pi). The program should continue forever (until it is aborted by the user) calculating and outputting each digit in succession. The output should be a decimal sequence beginning 3.14159265 ... + + +Note: this task is about calculating pi. For information on built-in pi constants see [[Real constants and functions]]. diff --git a/Task/Pi/1META.yaml b/Task/Pi/1META.yaml new file mode 100644 index 0000000000..c4d6b8a07d --- /dev/null +++ b/Task/Pi/1META.yaml @@ -0,0 +1,2 @@ +--- +note: Irrational numbers diff --git a/Task/Pi/C/pi.c b/Task/Pi/C/pi.c new file mode 100644 index 0000000000..1775051336 --- /dev/null +++ b/Task/Pi/C/pi.c @@ -0,0 +1,68 @@ +#include +#include +#include + +mpz_t tmp1, tmp2, t5, t239, pows; +void actan(mpz_t res, unsigned long base, mpz_t pows) +{ + int i, neg = 1; + mpz_tdiv_q_ui(res, pows, base); + mpz_set(tmp1, res); + for (i = 3; ; i += 2) { + mpz_tdiv_q_ui(tmp1, tmp1, base * base); + mpz_tdiv_q_ui(tmp2, tmp1, i); + if (mpz_cmp_ui(tmp2, 0) == 0) break; + if (neg) mpz_sub(res, res, tmp2); + else mpz_add(res, res, tmp2); + neg = !neg; + } +} + +char * get_digits(int n, size_t* len) +{ + mpz_ui_pow_ui(pows, 10, n + 20); + + actan(t5, 5, pows); + mpz_mul_ui(t5, t5, 16); + + actan(t239, 239, pows); + mpz_mul_ui(t239, t239, 4); + + mpz_sub(t5, t5, t239); + mpz_ui_pow_ui(pows, 10, 20); + mpz_tdiv_q(t5, t5, pows); + + *len = mpz_sizeinbase(t5, 10); + return mpz_get_str(0, 0, t5); +} + +int main(int c, char **v) +{ + unsigned long accu = 16384, done = 0; + size_t got; + char *s; + + mpz_init(tmp1); + mpz_init(tmp2); + mpz_init(t5); + mpz_init(t239); + mpz_init(pows); + + while (1) { + s = get_digits(accu, &got); + + /* write out digits up to the last one not preceding a 0 or 9*/ + got -= 2; /* -2: length estimate may be longer than actual */ + while (s[got] == '0' || s[got] == '9') got--; + + printf("%.*s", (int)(got - done), s + done); + free(s); + + done = got; + + /* double the desired digits; slows down at least cubically */ + accu *= 2; + } + + return 0; +} diff --git a/Task/Pi/Go/pi.go b/Task/Pi/Go/pi.go new file mode 100644 index 0000000000..a019fc8048 --- /dev/null +++ b/Task/Pi/Go/pi.go @@ -0,0 +1,83 @@ +package main + +import ( + "fmt" + "math/big" +) + +type lft struct { + q,r,s,t big.Int +} + +func (t *lft) extr(x *big.Int) *big.Rat { + var n, d big.Int + var r big.Rat + return r.SetFrac( + n.Add(n.Mul(&t.q, x), &t.r), + d.Add(d.Mul(&t.s, x), &t.t)) +} + +var three = big.NewInt(3) +var four = big.NewInt(4) + +func (t *lft) next() *big.Int { + r := t.extr(three) + var f big.Int + return f.Div(r.Num(), r.Denom()) +} + +func (t *lft) safe(n *big.Int) bool { + r := t.extr(four) + var f big.Int + if n.Cmp(f.Div(r.Num(), r.Denom())) == 0 { + return true + } + return false +} + +func (t *lft) comp(u *lft) *lft { + var r lft + var a, b big.Int + r.q.Add(a.Mul(&t.q, &u.q), b.Mul(&t.r, &u.s)) + r.r.Add(a.Mul(&t.q, &u.r), b.Mul(&t.r, &u.t)) + r.s.Add(a.Mul(&t.s, &u.q), b.Mul(&t.t, &u.s)) + r.t.Add(a.Mul(&t.s, &u.r), b.Mul(&t.t, &u.t)) + return &r +} + +func (t *lft) prod(n *big.Int) *lft { + var r lft + r.q.SetInt64(10) + r.r.Mul(r.r.SetInt64(-10), n) + r.t.SetInt64(1) + return r.comp(t) +} + +func main() { + // init z to unit + z := new(lft) + z.q.SetInt64(1) + z.t.SetInt64(1) + + // lfts generator + var k int64 + lfts := func() *lft { + k++ + r := new(lft) + r.q.SetInt64(k) + r.r.SetInt64(4*k+2) + r.t.SetInt64(2*k+1) + return r + } + + // stream + for { + y := z.next() + if z.safe(y) { + fmt.Print(y) + z = z.prod(y) + } else { + z = z.comp(lfts()) + } + } +} diff --git a/Task/Pi/Haskell/pi.hs b/Task/Pi/Haskell/pi.hs new file mode 100644 index 0000000000..9bd5c10c39 --- /dev/null +++ b/Task/Pi/Haskell/pi.hs @@ -0,0 +1,5 @@ +pi_ = g(1,0,1,1,3,3) where + g (q,r,t,k,n,l) = + if 4*q+r-t < n*t + then n : g (10*q, 10*(r-n*t), t, k, div (10*(3*q+r)) t - 10*n, l) + else g (q*k, (2*q+r)*l, t*l, k+1, div (q*(7*k+2)+r*l) (t*l), l+2) diff --git a/Task/Pi/Java/pi.java b/Task/Pi/Java/pi.java new file mode 100644 index 0000000000..7050e0610f --- /dev/null +++ b/Task/Pi/Java/pi.java @@ -0,0 +1,45 @@ +import java.math.BigInteger ; + +public class Pi { + final BigInteger TWO = BigInteger.valueOf(2) ; + final BigInteger THREE = BigInteger.valueOf(3) ; + final BigInteger FOUR = BigInteger.valueOf(4) ; + final BigInteger SEVEN = BigInteger.valueOf(7) ; + + BigInteger q = BigInteger.ONE ; + BigInteger r = BigInteger.ZERO ; + BigInteger t = BigInteger.ONE ; + BigInteger k = BigInteger.ONE ; + BigInteger n = BigInteger.valueOf(3) ; + BigInteger l = BigInteger.valueOf(3) ; + + public void calcPiDigits(){ + BigInteger nn, nr ; + boolean first = true ; + while(true){ + if(FOUR.multiply(q).add(r).subtract(t).compareTo(n.multiply(t)) == -1){ + System.out.print(n) ; + if(first){System.out.print(".") ; first = false ;} + nr = BigInteger.TEN.multiply(r.subtract(n.multiply(t))) ; + n = BigInteger.TEN.multiply(THREE.multiply(q).add(r)).divide(t).subtract(BigInteger.TEN.multiply(n)) ; + q = q.multiply(BigInteger.TEN) ; + r = nr ; + System.out.flush() ; + }else{ + nr = TWO.multiply(q).add(r).multiply(l) ; + nn = q.multiply((SEVEN.multiply(k))).add(TWO).add(r.multiply(l)).divide(t.multiply(l)) ; + q = q.multiply(k) ; + t = t.multiply(l) ; + l = l.add(TWO) ; + k = k.add(BigInteger.ONE) ; + n = nn ; + r = nr ; + } + } + } + + public static void main(String[] args) { + Pi p = new Pi() ; + p.calcPiDigits() ; + } +} diff --git a/Task/Pi/Perl/pi.pl b/Task/Pi/Perl/pi.pl new file mode 100644 index 0000000000..e70eb209e5 --- /dev/null +++ b/Task/Pi/Perl/pi.pl @@ -0,0 +1,55 @@ +use Math::BigInt; +use bigint; + +# Pi/4 = 4 arctan 1/5 - arctan 1/239 +# expanding it with Taylor series with what's probably the dumbest method + +my ($ds, $ns) = (1, 0); +my ($n5, $d5) = (16 * (25 * 3 - 1), 3 * 5**3); +my ($n2, $d2) = (4 * (239 * 239 * 3 - 1), 3 * 239**3); + +sub next_term { + my ($coef, $p) = @_[1, 2]; + $_[0] /= ($p - 4) * ($p - 2); + $_[0] *= $p * ($p + 2) * $coef**4; +} + +my $p2 = 5; +my $pow = 1; + +$| = 1; +for (my $x = 5; ; $x += 4) { + ($ns, $ds) = ($ns * $d5 + $n5 * $pow * $ds, $ds * $d5); + + next_term($d5, 5, $x); + $n5 = 16 * (5 * 5 * ($x + 2) - $x); + + while ($d5 > $d2) { + ($ns, $ds) = ($ns * $d2 - $n2 * $pow * $ds, $ds * $d2); + $n2 = 4 * (239 * 239 * ($p2 + 2) - $p2); + next_term($d2, 239, $p2); + $p2 += 4; + } + + my $ppow = 1; + while ($pow * $n5 * 5**4 < $d5 && $pow * $n2 * $n2 * 239**4 < $d2) { + $pow *= 10; + $ppow *= 10; + } + + if ($ppow > 1) { + $ns *= $ppow; + #FIX? my $out = $ns->bdiv($ds); # bugged? + my $out = $ns / $ds; + $ns %= $ds; + + $out = ("0" x (length($ppow) - length($out) - 1)) . $out; + print $out; + } + + if ( $p2 % 20 == 1) { + my $g = Math::BigInt::bgcd($ds, $ns); + $ds /= $g; + $ns /= $g; + } +} diff --git a/Task/Pi/PicoLisp/pi.l b/Task/Pi/PicoLisp/pi.l new file mode 100644 index 0000000000..1142c44d2b --- /dev/null +++ b/Task/Pi/PicoLisp/pi.l @@ -0,0 +1,21 @@ +#!/usr/bin/picolisp /usr/lib/picolisp/lib.l + +(de piDigit () + (job '((Q . 1) (R . 0) (S . 1) (K . 1) (N . 3) (L . 3)) + (while (>= (- (+ R (* 4 Q)) S) (* N S)) + (mapc set '(Q R S K N L) + (list + (* Q K) + (* L (+ R (* 2 Q))) + (* S L) + (inc K) + (/ (+ (* Q (+ 2 (* 7 K))) (* R L)) (* S L)) + (+ 2 L) ) ) ) + (prog1 N + (let M (- (/ (* 10 (+ R (* 3 Q))) S) (* 10 N)) + (setq Q (* 10 Q) R (* 10 (- R (* N S))) N M) ) ) ) ) + +(prin (piDigit) ".") +(loop + (prin (piDigit)) + (flush) ) diff --git a/Task/Pi/Python/pi.py b/Task/Pi/Python/pi.py new file mode 100644 index 0000000000..e9f5dcb0ac --- /dev/null +++ b/Task/Pi/Python/pi.py @@ -0,0 +1,26 @@ +def calcPi(): + q, r, t, k, n, l = 1, 0, 1, 1, 3, 3 + while True: + if 4*q+r-t < n*t: + yield n + nr = 10*(r-n*t) + n = ((10*(3*q+r))//t)-10*n + q *= 10 + r = nr + else: + nr = (2*q+r)*l + nn = (q*(7*k)+2+(r*l))//(t*l) + q *= k + t *= l + l += 2 + k += 1 + n = nn + r = nr + +import sys +pi_digits = calcPi() +i = 0 +for d in pi_digits: + sys.stdout.write(str(d)) + i += 1 + if i == 40: print(""); i = 0 diff --git a/Task/Pi/REXX/pi.rexx b/Task/Pi/REXX/pi.rexx new file mode 100644 index 0000000000..0b74476a36 --- /dev/null +++ b/Task/Pi/REXX/pi.rexx @@ -0,0 +1,24 @@ +/*REXX program to spit out pi digits (few at a time) until Ctrl-Break. */ + +arg digs .; if digs=='' then digs=1e6 /*allow the specification of digs*/ +fn='PI_DIGITS.OUT' /*file that can be written to. */ +numeric digits digs /*big digs, the slower the spits.*/ +pi=0; s=16; r=4; v=5; vs=v*v; g=239; gs=g*g; old=; spewed=0; j=1 +call time 'E' + +/*─────────────────────────────────────John Machin's formula for pi. */ + do n=1 by 2 + pi=pi + s/(n*v) - r/(n*g) + if pi==old then leave /*no further with current DIGITS.*/ + s=-s; r=-r; v=v*vs; g=g*gs + if n\==1 then do j=spewed+1 to compare(pi,old) + spit=substr(pi,j,1) + call charout ,spit /*spit out 1 digit of pi.*/ + call charout fn,spit /* ...and also to a file.*/ + end + spewed=j-1 + old=pi + end /*n*/ + +say; say n%2+1 'iterations took' format(time("E"),,2) 'seconds.' + /*stick a fork in it, we're done.*/ diff --git a/Task/Pi/Ruby/pi-2.rb b/Task/Pi/Ruby/pi-2.rb new file mode 100644 index 0000000000..be243ea97d --- /dev/null +++ b/Task/Pi/Ruby/pi-2.rb @@ -0,0 +1,28 @@ +def pi + q, r, t, k, n, l = 1, 0, 1, 1, 3, 3 + dot = nil + loop do + if 4*q+r-t < n*t + yield n + if dot.nil? + yield '.' + dot = '.' + end + nr = 10*(r-n*t) + n = ((10*(3*q+r)) / t) - 10*n + q *= 10 + r = nr + else + nr = (2*q+r) * l + nn = (q*(7*k+2)+r*l) / (t*l) + q *= k + t *= l + l += 2 + k += 1 + n = nn + r = nr + end + end +end + +pi {|digit| print digit; $stdout.flush} diff --git a/Task/Pi/Ruby/pi.rb b/Task/Pi/Ruby/pi.rb new file mode 100644 index 0000000000..ae9e30ba4c --- /dev/null +++ b/Task/Pi/Ruby/pi.rb @@ -0,0 +1,20 @@ +# Calculate Pi using the Arithmetic Geometric Mean of 1 and 1/sqrt(2) +# +# +# Nigel_Galloway +# March 8th., 2012. +# +require 'flt' +Flt::BinNum.Context.precision = 8192 +a = n = 1 +g = 1 / Flt::BinNum(2).sqrt +z = 0.25 +(0..17).each{ + x = [(a + g) * 0.5, (a * g).sqrt] + var = x[0] - a + z -= var * var * n + n += n + a = x[0] + g = x[1] +} +puts a * a / z diff --git a/Task/Pi/Scala/pi.scala b/Task/Pi/Scala/pi.scala new file mode 100644 index 0000000000..0d1f5acf57 --- /dev/null +++ b/Task/Pi/Scala/pi.scala @@ -0,0 +1,35 @@ +object Pi { + class PiIterator extends Iterable[BigInt]{ + var r:BigInt=0 + var q, t, k:BigInt=1 + var n, l:BigInt=3 + var nr, nn:BigInt=0 + + def iterator: Iterator[BigInt]=new Iterator[BigInt]{ + def hasNext=true + def next():BigInt={ + while((4*q+r-t) >= (n*t)) { + nr = (2*q+r)*l + nn = (q*(7*k)+2+(r*l))/(t*l) + q = q * k + t = t * l + l = l + 2 + k = k + 1 + n = nn + r = nr + } + val ret=n + nr = 10*(r-n*t) + n = ((10*(3*q+r))/t)-(10*n) + q = q * 10 + r = nr + ret + } + } + } + + def main(args: Array[String]): Unit = { + val it=new PiIterator + println((it head) + "." + (it take 300 mkString)) + } +} diff --git a/Task/Pi/Tcl/pi-2.tcl b/Task/Pi/Tcl/pi-2.tcl new file mode 100644 index 0000000000..6a63593d19 --- /dev/null +++ b/Task/Pi/Tcl/pi-2.tcl @@ -0,0 +1,5 @@ +coroutine piDigit piDigitsBySpigot 10000 +fconfigure stdout -buffering none +while 1 { + puts -nonewline [piDigit] +} diff --git a/Task/Pi/Tcl/pi.tcl b/Task/Pi/Tcl/pi.tcl new file mode 100644 index 0000000000..f0e67d89bb --- /dev/null +++ b/Task/Pi/Tcl/pi.tcl @@ -0,0 +1,31 @@ +package require Tcl 8.6 + +# http://www.cut-the-knot.org/Curriculum/Algorithms/SpigotForPi.shtml +# http://www.mathpropress.com/stan/bibliography/spigot.pdf +proc piDigitsBySpigot n { + yield [info coroutine] + set A [lrepeat [expr {int(floor(10*$n/3.)+1)}] 2] + set Alen [llength $A] + set predigits {} + while 1 { + set carry 0 + for {set i $Alen} {[incr i -1] > 0} {} { + lset A $i [expr { + [set val [expr {[lindex $A $i] * 10 + $carry}]] + % [set modulo [expr {2*$i + 1}]] + }] + set carry [expr {$val / $modulo * $i}] + } + lset A 0 [expr {[set val [expr {[lindex $A 0]*10 + $carry}]] % 10}] + set predigit [expr {$val / 10}] + if {$predigit < 9} { + foreach p $predigits {yield $p} + set predigits [list $predigit] + } elseif {$predigit == 9} { + lappend predigits $predigit + } else { + foreach p $predigits {yield [incr p]} + set predigits [list 0] + } + } +} diff --git a/Task/Quine/0DESCRIPTION b/Task/Quine/0DESCRIPTION new file mode 100644 index 0000000000..26b1de7af6 --- /dev/null +++ b/Task/Quine/0DESCRIPTION @@ -0,0 +1,17 @@ +A [[wp:Quine_%28computing%29|Quine]] is a self-referential program that can, without any external access, output its own source. It is named after the [[wp:Willard_Van_Orman_Quine|philosopher and logician]] who studied self-reference and quoting in natural language, as for example in the paradox "'Yields falsehood when preceded by its quotation' yields falsehood when preceded by its quotation." + +"Source" has one of two meanings. It can refer to the text-based program source. For languages in which program source is represented as a data structure, "source" may refer to the data structure: quines in these languages fall into two categories: programs which print a textual representation of themselves, or expressions which evaluate to a data structure which is equivalent to that expression. + +The usual way to code a Quine works similarly to this paradox: The program consists of two identical parts, once as plain code and once ''quoted'' in some way (for example, as a character string, or a literal data structure). The plain code then accesses the quoted code and prints it out twice, once unquoted and once with the proper quotation marks added. Often, the plain code and the quoted code have to be nested. + +Write a program that outputs its own source code in this way. If the language allows it, you may add a variant that accesses the code directly. You are not allowed to read any external files with the source code. The program should also contain some sort of self-reference, so constant expressions which return their own value which some top-level interpreter will print out. Empty programs producing no output are not allowed. + +There are several difficulties that one runs into when writing a quine, mostly dealing with quoting: +* Part of the code usually needs to be stored as a string or structural literal in the language, which needs to be quoted somehow. However, including quotation marks in the string literal itself would be troublesome because it requires them to be escaped, which then necessitates the escaping character (e.g. a backslash) in the string, which itself usually needs to be escaped, and so on. +** Some languages have a function for getting the "source code representation" of a string (i.e. adds quotation marks, etc.); in these languages, this can be used to circumvent the quoting problem. +** Another solution is to construct the quote character from its [[character code]], without having to write the quote character itself. Then the character is inserted into the string at the appropriate places. The ASCII code for double-quote is 34, and for single-quote is 39. +* Newlines in the program may have to be reproduced as newlines in the string, which usually requires some kind of escape sequence (e.g. "\n"). This causes the same problem as above, where the escaping character needs to itself be escaped, etc. +** If the language has a way of getting the "source code representation", it usually handles the escaping of characters, so this is not a problem. +** Some languages allow you to have a string literal that spans multiple lines, which embeds the newlines into the string without escaping. +** Write the entire program on one line, for free-form languages (as you can see for some of the solutions here, they run off the edge of the screen), thus removing the need for newlines. However, this may be unacceptable as some languages require a newline at the end of the file; and otherwise it is still generally good style to have a newline at the end of a file. (The task is not clear on whether a newline is required at the end of the file.) Some languages have a print statement that appends a newline; which solves the newline-at-the-end issue; but others do not. +
See the nostalgia note under Fortran. diff --git a/Task/Quine/BASIC/quine-2.bas b/Task/Quine/BASIC/quine-2.bas new file mode 100644 index 0000000000..aa655226e1 --- /dev/null +++ b/Task/Quine/BASIC/quine-2.bas @@ -0,0 +1,25 @@ +READ d$ +DO + READ x$ + PRINT x$ +LOOP UNTIL LEN(x$) < 1 +RESTORE +DO + READ x$ + PRINT d$; CHR$(34); x$; CHR$(34) +LOOP UNTIL LEN(x$) < 1 +END + +DATA "DATA " +DATA "READ d$" +DATA "DO" +DATA " READ x$" +DATA " PRINT x$" +DATA "LOOP UNTIL LEN(x$) < 1" +DATA "RESTORE" +DATA "DO" +DATA " READ x$" +DATA " PRINT d$; CHR$(34); x$; CHR$(34)" +DATA "LOOP UNTIL LEN(x$) < 1" +DATA "END" +DATA "" diff --git a/Task/Quine/BASIC/quine.bas b/Task/Quine/BASIC/quine.bas new file mode 100644 index 0000000000..1b05437302 --- /dev/null +++ b/Task/Quine/BASIC/quine.bas @@ -0,0 +1 @@ +10 LIST diff --git a/Task/Quine/Befunge/quine.bf b/Task/Quine/Befunge/quine.bf new file mode 100644 index 0000000000..ae018bd5bd --- /dev/null +++ b/Task/Quine/Befunge/quine.bf @@ -0,0 +1 @@ +:0g,:66+`#@_1+ diff --git a/Task/Quine/C/quine.c b/Task/Quine/C/quine.c new file mode 100644 index 0000000000..b83a1279c8 --- /dev/null +++ b/Task/Quine/C/quine.c @@ -0,0 +1,10 @@ +#include + +static char sym[] = "\n\t\\\""; + +int main(void) { + const char *code = "#include %c%cstatic char sym[] = %c%cn%ct%c%c%c%c%c;%c%cint main(void) {%c%cconst char *code = %c%s%c;%c%cprintf(code, sym[0], sym[0], sym[3], sym[2], sym[2], sym[2], sym[2], sym[2], sym[3], sym[3], sym[0], sym[0], sym[0], sym[1], sym[3], code, sym[3], sym[0], sym[1], sym[0], sym[0], sym[1], sym[0], sym[0]);%c%c%creturn 0;%c}%c"; + printf(code, sym[0], sym[0], sym[3], sym[2], sym[2], sym[2], sym[2], sym[2], sym[3], sym[3], sym[0], sym[0], sym[0], sym[1], sym[3], code, sym[3], sym[0], sym[1], sym[0], sym[0], sym[1], sym[0], sym[0]); + + return 0; +} diff --git a/Task/Quine/Clojure/quine.clj b/Task/Quine/Clojure/quine.clj new file mode 100644 index 0000000000..3954637c0e --- /dev/null +++ b/Task/Quine/Clojure/quine.clj @@ -0,0 +1 @@ +((fn [x] (list x (list (quote quote) x))) (quote (fn [x] (list x (list (quote quote) x))))) diff --git a/Task/Quine/CoffeeScript/quine.coffee b/Task/Quine/CoffeeScript/quine.coffee new file mode 100644 index 0000000000..1c7e0c0cd5 --- /dev/null +++ b/Task/Quine/CoffeeScript/quine.coffee @@ -0,0 +1 @@ +s="s=#&# ;alert s.replace(/&/,s).replace /#(?=[^&;'(]|';;$)/g, '#';;" ;alert s.replace(/&/,s).replace /#(?=[^&;'(]|';;$)/g, '"';; diff --git a/Task/Quine/Erlang/quine.erl b/Task/Quine/Erlang/quine.erl new file mode 100644 index 0000000000..7f061addb4 --- /dev/null +++ b/Task/Quine/Erlang/quine.erl @@ -0,0 +1,6 @@ +-module(quine). +-export([do/0]). + +do() -> Txt=txt(), io:format("~s~ntxt() ->~n~w.~n",[Txt,Txt]), halt(). +txt() -> +[45,109,111,100,117,108,101,40,113,117,105,110,101,41,46,10,45,101,120,112,111,114,116,40,91,100,111,47,48,93,41,46,10,10,100,111,40,41,32,45,62,32,84,120,116,61,116,120,116,40,41,44,32,105,111,58,102,111,114,109,97,116,40,34,126,115,126,110,116,120,116,40,41,32,45,62,126,110,126,119,46,126,110,34,44,91,84,120,116,44,84,120,116,93,41,44,32,104,97,108,116,40,41,46]. diff --git a/Task/Quine/Forth/quine.fth b/Task/Quine/Forth/quine.fth new file mode 100644 index 0000000000..21f0e5c4c3 --- /dev/null +++ b/Task/Quine/Forth/quine.fth @@ -0,0 +1 @@ +SOURCE TYPE diff --git a/Task/Quine/Fortran/quine.f b/Task/Quine/Fortran/quine.f new file mode 100644 index 0000000000..2e68804776 --- /dev/null +++ b/Task/Quine/Fortran/quine.f @@ -0,0 +1 @@ +character*46::s='("character*46::s=",3a,";print s,39,s,39;end")';print s,39,s,39;end diff --git a/Task/Quine/Go/quine.go b/Task/Quine/Go/quine.go new file mode 100644 index 0000000000..deb34d1f86 --- /dev/null +++ b/Task/Quine/Go/quine.go @@ -0,0 +1,8 @@ +package main + +import "fmt" + +func main() { + a := "package main\n\nimport \"fmt\"\n\nfunc main() {\n\ta := %q\n\tfmt.Printf(a, a)\n}\n" + fmt.Printf(a, a) +} diff --git a/Task/Quine/Haskell/quine-2.hs b/Task/Quine/Haskell/quine-2.hs new file mode 100644 index 0000000000..762c9bf9a6 --- /dev/null +++ b/Task/Quine/Haskell/quine-2.hs @@ -0,0 +1 @@ +(\s -> putStrLn (s ++ show s)) "(\\s -> putStrLn (s ++ show s)) " diff --git a/Task/Quine/Haskell/quine-3.hs b/Task/Quine/Haskell/quine-3.hs new file mode 100644 index 0000000000..51f02ccf05 --- /dev/null +++ b/Task/Quine/Haskell/quine-3.hs @@ -0,0 +1 @@ +(putStrLn . \s -> s ++ show s) "(putStrLn . \\s -> s ++ show s) " diff --git a/Task/Quine/Haskell/quine-4.hs b/Task/Quine/Haskell/quine-4.hs new file mode 100644 index 0000000000..92fba4794b --- /dev/null +++ b/Task/Quine/Haskell/quine-4.hs @@ -0,0 +1,2 @@ +import Control.Monad.Reader +(putStrLn . ap (++) show) "(putStrLn . ap (++) show) " diff --git a/Task/Quine/Haskell/quine-5.hs b/Task/Quine/Haskell/quine-5.hs new file mode 100644 index 0000000000..59d11f19ec --- /dev/null +++ b/Task/Quine/Haskell/quine-5.hs @@ -0,0 +1 @@ +ap(++)show"ap(++)show" diff --git a/Task/Quine/Haskell/quine.hs b/Task/Quine/Haskell/quine.hs new file mode 100644 index 0000000000..dfbb4500c3 --- /dev/null +++ b/Task/Quine/Haskell/quine.hs @@ -0,0 +1 @@ +let q s = putStrLn (s ++ show s) in q "let q s = putStrLn (s ++ show s) in q " diff --git a/Task/Quine/Java/quine-2.java b/Task/Quine/Java/quine-2.java new file mode 100644 index 0000000000..1a2536865c --- /dev/null +++ b/Task/Quine/Java/quine-2.java @@ -0,0 +1 @@ +class S{public static void main(String[]a){String p="class S{public static void main(String[]a){String p=%c%s%1$c;System.out.printf(p,34,p);}}";System.out.printf(p,34,p);}} diff --git a/Task/Quine/Java/quine.java b/Task/Quine/Java/quine.java new file mode 100644 index 0000000000..d2d5f0ab57 --- /dev/null +++ b/Task/Quine/Java/quine.java @@ -0,0 +1 @@ +class S{public static void main(String[]a){String s="class S{public static void main(String[]a){String s=;char c=34;System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}}";char c=34;System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}} diff --git a/Task/Quine/JavaScript/quine-2.js b/Task/Quine/JavaScript/quine-2.js new file mode 100644 index 0000000000..9e64f3886f --- /dev/null +++ b/Task/Quine/JavaScript/quine-2.js @@ -0,0 +1 @@ +var code='var q=String.fromCharCode(39);print("var code="+q+code+q+";eval(code)")';eval(code) diff --git a/Task/Quine/JavaScript/quine.js b/Task/Quine/JavaScript/quine.js new file mode 100644 index 0000000000..c9044923a0 --- /dev/null +++ b/Task/Quine/JavaScript/quine.js @@ -0,0 +1 @@ +(function(){print("("+arguments.callee.toString().replace(/\s/g,'')+")()");})() diff --git a/Task/Quine/Lua/quine.lua b/Task/Quine/Lua/quine.lua new file mode 100644 index 0000000000..e4777408b0 --- /dev/null +++ b/Task/Quine/Lua/quine.lua @@ -0,0 +1 @@ +s=[[io.write('s=[','[',s,']','];',s)]];io.write('s=[','[',s,']','];',s) diff --git a/Task/Quine/PHP/quine.php b/Task/Quine/PHP/quine.php new file mode 100644 index 0000000000..cffdae4ddd --- /dev/null +++ b/Task/Quine/PHP/quine.php @@ -0,0 +1,2 @@ + +'; printf($p,39,$p,39); ?> diff --git a/Task/Quine/Perl/quine-2.pl b/Task/Quine/Perl/quine-2.pl new file mode 100644 index 0000000000..3daafc1e98 --- /dev/null +++ b/Task/Quine/Perl/quine-2.pl @@ -0,0 +1,3 @@ +seek(DATA, 0, 0); +print +__DATA__ diff --git a/Task/Quine/Perl/quine-3.pl b/Task/Quine/Perl/quine-3.pl new file mode 100644 index 0000000000..b9bc621d4f --- /dev/null +++ b/Task/Quine/Perl/quine-3.pl @@ -0,0 +1 @@ +open ME, $0 and print ; diff --git a/Task/Quine/Perl/quine-4.pl b/Task/Quine/Perl/quine-4.pl new file mode 100644 index 0000000000..d0cddc2027 --- /dev/null +++ b/Task/Quine/Perl/quine-4.pl @@ -0,0 +1 @@ +$_=q{print"\$_=q{$_};eval"};eval diff --git a/Task/Quine/Perl/quine-5.pl b/Task/Quine/Perl/quine-5.pl new file mode 100644 index 0000000000..8ce57b5f62 --- /dev/null +++ b/Task/Quine/Perl/quine-5.pl @@ -0,0 +1,47 @@ +{local$_=q{ +{ + package Quine; + use strict; + use warnings; + our $VERSION = sprintf "%d.%02d", q$Revision: 0.2 $ =~ /(\d+)/g; + my $head = '{local$_=q' . "\x7B\n"; + my $tail = 'print"{local\$_=q{$_};eval}\n"' . "\x7D;eval}\n"; + + sub new { + my $class = shift; + my $quine = $head . shift; + my $ret = shift || 1; + my $ln = ( $quine =~ tr/\n/\n/ ); + $ln++; + $quine .= "return $ret if caller(1)or(caller)[2]!=$ln;$tail"; + bless \$quine, $class; + } + + sub from_file { + my ( $class, $fn, $ret ) = @_; + local $/; + open my $fh, '<', $fn or die "$fn : $!"; + my $src = <$fh>; + close $fh; + $class->new( $src, $ret ); + } + + sub quine { ${ $_[0] } } + +=head1 NAME + +Quine - turn your perl modules/apps into a true quine! + +=head1 VERSION + +$Id: Quine.pm,v 0.2 2010/09/15 20:23:53 dankogai Exp dankogai $ + +=head1 SYNOPSIS + + use Quine; + print Quine->from_file("woot.pl")->quine; + print Quine->from_file("moot.psgi", '$app')->quine; + +=cut +} +return 1 if caller(1);print"{local\$_=q{$_};eval}\n"};eval} diff --git a/Task/Quine/Perl/quine.pl b/Task/Quine/Perl/quine.pl new file mode 100644 index 0000000000..687d077471 --- /dev/null +++ b/Task/Quine/Perl/quine.pl @@ -0,0 +1,2 @@ +$s = q($s = q(%s); printf($s, $s); +); printf($s, $s); diff --git a/Task/Quine/PicoLisp/quine-2.l b/Task/Quine/PicoLisp/quine-2.l new file mode 100644 index 0000000000..3784b406f9 --- /dev/null +++ b/Task/Quine/PicoLisp/quine-2.l @@ -0,0 +1 @@ +(let X '(list 'let 'X (lit X) X) (list 'let 'X (lit X) X)) diff --git a/Task/Quine/PicoLisp/quine.l b/Task/Quine/PicoLisp/quine.l new file mode 100644 index 0000000000..1d42df25fb --- /dev/null +++ b/Task/Quine/PicoLisp/quine.l @@ -0,0 +1 @@ +('((X) (list (lit X) (lit X))) '((X) (list (lit X) (lit X)))) diff --git a/Task/Quine/Python/quine-2.py b/Task/Quine/Python/quine-2.py new file mode 100644 index 0000000000..95a21aac0f --- /dev/null +++ b/Task/Quine/Python/quine-2.py @@ -0,0 +1 @@ +x = 'x = {!r};print(x.format(x))';print(x.format(x)) diff --git a/Task/Quine/Python/quine-3.py b/Task/Quine/Python/quine-3.py new file mode 100644 index 0000000000..187d55351d --- /dev/null +++ b/Task/Quine/Python/quine-3.py @@ -0,0 +1 @@ +import sys; sys.stdout.write(open(sys.argv[0]).read()) diff --git a/Task/Quine/Python/quine-4.py b/Task/Quine/Python/quine-4.py new file mode 100644 index 0000000000..1acb041803 --- /dev/null +++ b/Task/Quine/Python/quine-4.py @@ -0,0 +1 @@ +print(__file__[:-3]) diff --git a/Task/Quine/Python/quine-5.py b/Task/Quine/Python/quine-5.py new file mode 100644 index 0000000000..2a666e4872 --- /dev/null +++ b/Task/Quine/Python/quine-5.py @@ -0,0 +1,2 @@ +$ python print\(__file__\[\:-3\]\).py +print(__file__[:-3]) diff --git a/Task/Quine/Python/quine.py b/Task/Quine/Python/quine.py new file mode 100644 index 0000000000..bac879bf30 --- /dev/null +++ b/Task/Quine/Python/quine.py @@ -0,0 +1,2 @@ +x = 'x = %r\nprint(x %% x)' +print(x % x) diff --git a/Task/Quine/REXX/quine-2.rexx b/Task/Quine/REXX/quine-2.rexx new file mode 100644 index 0000000000..89cb7ee1de --- /dev/null +++ b/Task/Quine/REXX/quine-2.rexx @@ -0,0 +1,4 @@ +/*REXX program outputs its own source including comments and blank lines.*/ + do k=1 for sourceline() + say sourceline(k) + end /*k*/ diff --git a/Task/Quine/REXX/quine-3.rexx b/Task/Quine/REXX/quine-3.rexx new file mode 100644 index 0000000000..5290d3d736 --- /dev/null +++ b/Task/Quine/REXX/quine-3.rexx @@ -0,0 +1,52 @@ +/* Rexx */ + +Q = "'" +Queue '/* Rexx */' +Queue '' +Queue 'Q = "$"' +Queue '&QQQ' +Queue '' +Queue 'X = 0' +Queue 'Do while Queued() \= 0' +Queue ' Parse pull code' +Queue ' X = X + 1; codel.0 = X; codel.X = code' +Queue ' End' +Queue '' +Queue 'Do x_ = 1 for codel.0' +Queue ' line = codel.x_' +Queue ' If abbrev(line, "Q = ") then Do' +Queue ' line = translate(line, Q, "$")' +Queue ' End' +Queue ' If line = "&QQQ" then Do' +Queue ' Do y_ = 1 to codel.0' +Queue ' qline = codel.y_' +Queue ' Say "Queue" Q || qline || Q' +Queue ' End y_' +Queue ' End' +Queue ' else Do' +Queue ' Say line' +Queue ' End' +Queue ' End x_' +Queue '' + +X = 0 +Do while Queued() \= 0 + Parse pull code + X = X + 1; codel.0 = X; codel.X = code + End + +Do x_ = 1 for codel.0 + line = codel.x_ + If abbrev(line, "Q = ") then Do + line = translate(line, Q, "$") + End + If line = "&QQQ" then Do + Do y_ = 1 to codel.0 + qline = codel.y_ + Say "Queue" Q || qline || Q + End y_ + End + else Do + Say line + End + End x_ diff --git a/Task/Quine/REXX/quine.rexx b/Task/Quine/REXX/quine.rexx new file mode 100644 index 0000000000..05c9814cc6 --- /dev/null +++ b/Task/Quine/REXX/quine.rexx @@ -0,0 +1 @@ +/*REXX program outputs itself.*/ do j=1 for sourceline(); say sourceline(j); end diff --git a/Task/Quine/Ruby/quine-2.rb b/Task/Quine/Ruby/quine-2.rb new file mode 100644 index 0000000000..0e45038894 --- /dev/null +++ b/Task/Quine/Ruby/quine-2.rb @@ -0,0 +1,3 @@ +puts < something{something} diff --git a/Task/Quine/Tcl/quine-3.tcl b/Task/Quine/Tcl/quine-3.tcl new file mode 100644 index 0000000000..7d086bd1aa --- /dev/null +++ b/Task/Quine/Tcl/quine-3.tcl @@ -0,0 +1,2 @@ +join { {} \{ \} } { join { {} \{ \} } } +=> join { {} \{ \} } { join { {} \{ \} } } diff --git a/Task/Quine/Tcl/quine-4.tcl b/Task/Quine/Tcl/quine-4.tcl new file mode 100644 index 0000000000..922a17d5cf --- /dev/null +++ b/Task/Quine/Tcl/quine-4.tcl @@ -0,0 +1,34 @@ +program quine; + +const + apos: Char = Chr(39); + comma: Char = Chr(44); + lines: Array[1..17] of String[80] = ( +'program quine;', +'', +'const', +' apos: Char = Chr(39);', +' comma: Char = Chr(44);', +' lines: Array[1..17] of String[80] = (', +' );', +'', +'var', +' num: Integer;', +'', +'begin', +' for num := 1 to 6 do writeln(lines[num]);', +' for num := 1 to 16 do writeln(apos, lines[num], apos, comma);', +'% writeln(apos, lines[17], apos);', +' for num := 7 to 17 do writeln(lines[num]);', +'end.' + ); + +var + num: Integer; + +begin + for num := 1 to 6 do writeln(lines[num]); + for num := 1 to 16 do writeln(apos, lines[num], apos, comma); + writeln(apos, lines[17], apos); + for num := 7 to 17 do writeln(lines[num]); +end. diff --git a/Task/Quine/Tcl/quine.tcl b/Task/Quine/Tcl/quine.tcl new file mode 100644 index 0000000000..62191e47c8 --- /dev/null +++ b/Task/Quine/Tcl/quine.tcl @@ -0,0 +1,2 @@ +join { {} A B } any_string +=> any_stringAany_stringB diff --git a/Task/Search_a_list/0DESCRIPTION b/Task/Search_a_list/0DESCRIPTION new file mode 100644 index 0000000000..cdb83ba451 --- /dev/null +++ b/Task/Search_a_list/0DESCRIPTION @@ -0,0 +1,4 @@ +Find the index of a string (needle) in an indexable, ordered collection of strings (haystack). Raise an exception if the needle is missing. +If there is more than one occurrence then return the smallest index to the needle. + +As an extra task, return the largest index to a needle that has multiple occurrences in the haystack. diff --git a/Task/Search_a_list/1META.yaml b/Task/Search_a_list/1META.yaml new file mode 100644 index 0000000000..88eb5468ca --- /dev/null +++ b/Task/Search_a_list/1META.yaml @@ -0,0 +1,2 @@ +--- +note: Text processing diff --git a/Task/Search_a_list/AWK/search_a_list.awk b/Task/Search_a_list/AWK/search_a_list.awk new file mode 100644 index 0000000000..00f26b39cc --- /dev/null +++ b/Task/Search_a_list/AWK/search_a_list.awk @@ -0,0 +1,21 @@ +#! /usr/bin/awk -f +BEGIN { + # create the array, using the word as index... + words="Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo"; + split(words, haystack_byorder, " "); + j=0; + for(idx in haystack_byorder) { + haystack[haystack_byorder[idx]] = j; + j++; + } + # now check for needle (we know it is there, so no "else")... + if ( "Bush" in haystack ) { + print "Bush is at " haystack["Bush"]; + } + # check for unexisting needle + if ( "Washington" in haystack ) { + print "impossible"; + } else { + print "Washington is not here"; + } +} diff --git a/Task/Search_a_list/BASIC/search_a_list.bas b/Task/Search_a_list/BASIC/search_a_list.bas new file mode 100644 index 0000000000..b5035e9503 --- /dev/null +++ b/Task/Search_a_list/BASIC/search_a_list.bas @@ -0,0 +1,29 @@ +DATA foo, bar, baz, quux, quuux, quuuux, bazola, ztesch, foo, bar, thud, grunt +DATA foo, bar, bletch, foo, bar, fum, fred, jim, sheila, barney, flarp, zxc +DATA spqr, wombat, shme, foo, bar, baz, bongo, spam, eggs, snork, foo, bar +DATA zot, blarg, wibble, toto, titi, tata, tutu, pippo, pluto, paperino, aap +DATA noot, mies, oogle, foogle, boogle, zork, gork, bork + +DIM haystack(54) AS STRING +DIM needle AS STRING, found AS INTEGER, L0 AS INTEGER + +FOR L0 = 0 TO 54 + READ haystack(L0) +NEXT + +DO + INPUT "Word to search for? (Leave blank to exit) ", needle + IF needle <> "" THEN + FOR L0 = 0 TO UBOUND(haystack) + IF UCASE$(haystack(L0)) = UCASE$(needle) THEN + found = 1 + PRINT "Found "; CHR$(34); needle; CHR$(34); " at index "; LTRIM$(STR$(L0)) + END IF + NEXT + IF found < 1 THEN + PRINT CHR$(34); needle; CHR$(34); " not found" + END IF + ELSE + EXIT DO + END IF +LOOP diff --git a/Task/Search_a_list/C/search_a_list.c b/Task/Search_a_list/C/search_a_list.c new file mode 100644 index 0000000000..0bf75204f2 --- /dev/null +++ b/Task/Search_a_list/C/search_a_list.c @@ -0,0 +1,40 @@ +#include +#include + +const char *haystack[] = { + "Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty", "Charlie", + "Bush", "Boz", "Zag", NULL +}; + +int search_needle(const char *needle, const char **hs) +{ + int i = 0; + while( hs[i] != NULL ) { + if ( strcmp(hs[i], needle) == 0 ) return i; + i++; + } + return -1; +} + +int search_last_needle(const char *needle, const char **hs) +{ + int i, last=0; + i = last = search_needle(needle, hs); + if ( last < 0 ) return -1; + while( hs[++i] != NULL ) { + if ( strcmp(needle, hs[i]) == 0 ) { + last = i; + } + } + return last; +} + +int main() +{ + printf("Bush is at %d\n", search_needle("Bush", haystack)); + if ( search_needle("Washington", haystack) == -1 ) + printf("Washington is not in the haystack\n"); + printf("First index for Zag: %d\n", search_needle("Zag", haystack)); + printf("Last index for Zag: %d\n", search_last_needle("Zag", haystack)); + return 0; +} diff --git a/Task/Search_a_list/Clojure/search_a_list.clj b/Task/Search_a_list/Clojure/search_a_list.clj new file mode 100644 index 0000000000..4d23bffa5d --- /dev/null +++ b/Task/Search_a_list/Clojure/search_a_list.clj @@ -0,0 +1,5 @@ +(let [haystack ["Zig" "Zag" "Wally" "Ronald" "Bush" "Krusty" "Charlie" "Bush" "Bozo"]] + (let [idx (.indexOf haystack "Zig")] + (if (neg? idx) + (throw (Error. "item not found.")) + idx))) diff --git a/Task/Search_a_list/Erlang/search_a_list.erl b/Task/Search_a_list/Erlang/search_a_list.erl new file mode 100644 index 0000000000..07fbfb3417 --- /dev/null +++ b/Task/Search_a_list/Erlang/search_a_list.erl @@ -0,0 +1,15 @@ +-module(index). +-export([main/0]). + +main() -> + Haystack = ["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"], + Needles = ["Washington","Bush"], + lists:foreach(fun ?MODULE:print/1, [{N,pos(N, Haystack)} || N <- Needles]). + +pos(Needle, Haystack) -> pos(Needle, Haystack, 1). +pos(_, [], _) -> undefined; +pos(Needle, [Needle|_], Pos) -> Pos; +pos(Needle, [_|Haystack], Pos) -> pos(Needle, Haystack, Pos+1). + +print({Needle, undefined}) -> io:format("~s is not in haystack.~n",[Needle]); +print({Needle, Pos}) -> io:format("~s at position ~p.~n",[Needle,Pos]). diff --git a/Task/Search_a_list/Forth/search_a_list.fth b/Task/Search_a_list/Forth/search_a_list.fth new file mode 100644 index 0000000000..2d8b3c24d8 --- /dev/null +++ b/Task/Search_a_list/Forth/search_a_list.fth @@ -0,0 +1,11 @@ +include lib/row.4th + +create haystack + ," Zig" ," Zag" ," Wally" ," Ronald" ," Bush" ," Krusty" ," Charlie" + ," Bush" ," Boz" ," Zag" NULL , +does> + dup >r 1 string-key row 2>r type 2r> ." is " + if r> - ." at " . else r> drop drop ." not found" then cr +; + +s" Washington" haystack s" Bush" haystack diff --git a/Task/Search_a_list/Fortran/search_a_list.f b/Task/Search_a_list/Fortran/search_a_list.f new file mode 100644 index 0000000000..55e9d70e5d --- /dev/null +++ b/Task/Search_a_list/Fortran/search_a_list.f @@ -0,0 +1,35 @@ +program main + + implicit none + + character(len=7),dimension(10) :: haystack = [ & + 'Zig ',& + 'Zag ',& + 'Wally ',& + 'Ronald ',& + 'Bush ',& + 'Krusty ',& + 'Charlie',& + 'Bush ',& + 'Boz ',& + 'Zag '] + + call find_needle('Charlie') + call find_needle('Bush') + + contains + + subroutine find_needle(needle) + implicit none + character(len=*),intent(in) :: needle + integer :: i + do i=1,size(haystack) + if (needle==haystack(i)) then + write(*,'(A,I4)') trim(needle)//' found at index:',i + return + end if + end do + write(*,'(A)') 'Error: '//trim(needle)//' not found.' + end subroutine find_needle + + end program main diff --git a/Task/Search_a_list/Go/search_a_list.go b/Task/Search_a_list/Go/search_a_list.go new file mode 100644 index 0000000000..da03484dd3 --- /dev/null +++ b/Task/Search_a_list/Go/search_a_list.go @@ -0,0 +1,79 @@ +package main + +import "fmt" + +var haystack = []string{"Zig", "Zag", "Wally", "Ronald", "Bush", "Krusty", + "Charlie", "Bush", "Bozo", "Zag", "mouse", "hat", "cup", "deodorant", + "television", "soap", "methamphetamine", "severed cat heads", "foo", + "bar", "baz", "quux", "quuux", "quuuux", "bazola", "ztesch", "foo", + "bar", "thud", "grunt", "foo", "bar", "bletch", "foo", "bar", "fum", + "fred", "jim", "sheila", "barney", "flarp", "zxc", "spqr", ";wombat", + "shme", "foo", "bar", "baz", "bongo", "spam", "eggs", "snork", "foo", + "bar", "zot", "blarg", "wibble", "toto", "titi", "tata", "tutu", "pippo", + "pluto", "paperino", "aap", "noot", "mies", "oogle", "foogle", "boogle", + "zork", "gork", "bork", "sodium", "phosphorous", "californium", + "copernicium", "gold", "thallium", "carbon", "silver", "gold", "copper", + "helium", "sulfur"} + +func main() { + // first task + printSearchForward("soap") + printSearchForward("gold") + printSearchForward("fire") + // extra task + printSearchReverseMult("soap") + printSearchReverseMult("gold") + printSearchReverseMult("fire") +} + +// First task solution uses panic as an exception-like mechanism, as requested +// by the task. Note however, this is not idiomatic in Go and in fact +// is considered bad practice. +func printSearchForward(s string) { + fmt.Printf("Forward search: %s: ", s) + defer func() { + if x := recover(); x != nil { + if err, ok := x.(string); ok && err == "no match" { + fmt.Println(err) + return + } + panic(x) + } + }() + fmt.Println("smallest index =", searchForwardPanic(s)) +} + +func searchForwardPanic(s string) int { + for i, h := range haystack { + if h == s { + return i + } + } + panic("no match") + return -1 +} + +// Extra task, a quirky search for multiple occurrences. This is written +// without panic, and shows more acceptable Go programming practice. +func printSearchReverseMult(s string) { + fmt.Printf("Reverse search for multiples: %s: ", s) + if i := searchReverseMult(s); i > -1 { + fmt.Println("largest index =", i) + } else { + fmt.Println("no multiple occurrence") + } +} + +func searchReverseMult(s string) int { + largest := -1 + for i := len(haystack) - 1; i >= 0; i-- { + switch { + case haystack[i] != s: + case largest == -1: + largest = i + default: + return largest + } + } + return -1 +} diff --git a/Task/Search_a_list/Haskell/search_a_list-2.hs b/Task/Search_a_list/Haskell/search_a_list-2.hs new file mode 100644 index 0000000000..8dd1f2f7b0 --- /dev/null +++ b/Task/Search_a_list/Haskell/search_a_list-2.hs @@ -0,0 +1,2 @@ +*Main> map (\x -> (x,elemIndex x haystack)) needles +[("Washington",Nothing),("Bush",Just 4)] diff --git a/Task/Search_a_list/Haskell/search_a_list-3.hs b/Task/Search_a_list/Haskell/search_a_list-3.hs new file mode 100644 index 0000000000..dba8d8d848 --- /dev/null +++ b/Task/Search_a_list/Haskell/search_a_list-3.hs @@ -0,0 +1,2 @@ +*Main> map (\x -> (x,elemIndices x haystack)) needles +[("Washington",[]),("Bush",[4,7])] diff --git a/Task/Search_a_list/Haskell/search_a_list-4.hs b/Task/Search_a_list/Haskell/search_a_list-4.hs new file mode 100644 index 0000000000..5ff5965709 --- /dev/null +++ b/Task/Search_a_list/Haskell/search_a_list-4.hs @@ -0,0 +1,5 @@ +import Control.Monad +import Control.Arrow + +*Main> map (ap (,) (flip elemIndex haystack)) needles +[("Washington",Nothing),("Bush",Just 4)] diff --git a/Task/Search_a_list/Haskell/search_a_list.hs b/Task/Search_a_list/Haskell/search_a_list.hs new file mode 100644 index 0000000000..d61b7621af --- /dev/null +++ b/Task/Search_a_list/Haskell/search_a_list.hs @@ -0,0 +1,4 @@ +import Data.List + +haystack=["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"] +needles = ["Washington","Bush"] diff --git a/Task/Search_a_list/Java/search_a_list-2.java b/Task/Search_a_list/Java/search_a_list-2.java new file mode 100644 index 0000000000..1b4601f367 --- /dev/null +++ b/Task/Search_a_list/Java/search_a_list-2.java @@ -0,0 +1,11 @@ +String[] haystack = {"Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"}; + +OUTERLOOP: +for (String needle : new String[]{"Washington","Bush"}) { + for (int i = 0; i < haystack.length; i++) + if (needle.equals(haystack[i])) { + System.out.println(i + " " + needle); + continue OUTERLOOP; + } + System.out.println(needle + " is not in haystack"); +} diff --git a/Task/Search_a_list/Java/search_a_list.java b/Task/Search_a_list/Java/search_a_list.java new file mode 100644 index 0000000000..4e2ef52b3f --- /dev/null +++ b/Task/Search_a_list/Java/search_a_list.java @@ -0,0 +1,12 @@ +import java.util.List; +import java.util.Arrays; + +List haystack = Arrays.asList("Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"); + +for (String needle : new String[]{"Washington","Bush"}) { + int index = haystack.indexOf(needle); + if (index < 0) + System.out.println(needle + " is not in haystack"); + else + System.out.println(index + " " + needle); +} diff --git a/Task/Search_a_list/JavaScript/search_a_list-2.js b/Task/Search_a_list/JavaScript/search_a_list-2.js new file mode 100644 index 0000000000..6837e36dc7 --- /dev/null +++ b/Task/Search_a_list/JavaScript/search_a_list-2.js @@ -0,0 +1,18 @@ +for each (var needle in needles) { + var idx = haystack.indexOf(needle); + if (idx == -1) + throw needle + " does not appear in the haystack" + else + print(needle + " appears at index " + idx + " in the haystack"); +} + +// extra credit + +for each (var elem in haystack) { + var first_idx = haystack.indexOf(elem); + var last_idx = haystack.lastIndexOf(elem); + if (last_idx > first_idx) { + print(elem + " last appears at index " + last_idx + " in the haystack"); + break + } +} diff --git a/Task/Search_a_list/JavaScript/search_a_list.js b/Task/Search_a_list/JavaScript/search_a_list.js new file mode 100644 index 0000000000..f94a7b0447 --- /dev/null +++ b/Task/Search_a_list/JavaScript/search_a_list.js @@ -0,0 +1,16 @@ +var haystack = ['Zig', 'Zag', 'Wally', 'Ronald', 'Bush', 'Krusty', 'Charlie', 'Bush', 'Bozo'] +var needles = ['Bush', 'Washington'] + +for (var i in needles) { + var found = false; + for (var j in haystack) { + if (haystack[j] == needles[i]) { + found = true; + break; + } + } + if (found) + print(needles[i] + " appears at index " + j + " in the haystack"); + else + throw needles[i] + " does not appear in the haystack" +} diff --git a/Task/Search_a_list/Lua/search_a_list.lua b/Task/Search_a_list/Lua/search_a_list.lua new file mode 100644 index 0000000000..fe0144811e --- /dev/null +++ b/Task/Search_a_list/Lua/search_a_list.lua @@ -0,0 +1,7 @@ +list = {"mouse", "hat", "cup", "deodorant", "television", "soap", "methamphetamine", "severed cat heads"} --contents of my desk + +item = io.read() + +for i,v in ipairs(list) + if v == item then print(i) end +end diff --git a/Task/Search_a_list/PHP/search_a_list.php b/Task/Search_a_list/PHP/search_a_list.php new file mode 100644 index 0000000000..866a08d1bd --- /dev/null +++ b/Task/Search_a_list/PHP/search_a_list.php @@ -0,0 +1,9 @@ +$haystack = array("Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"); + +foreach (array("Washington","Bush") as $needle) { + $i = array_search($needle, $haystack); + if ($i === FALSE) // note: 0 is also considered false in PHP, so you need to specifically check for FALSE + echo "$needle is not in haystack\n"; + else + echo "$i $needle\n"; +} diff --git a/Task/Search_a_list/Perl/search_a_list-2.pl b/Task/Search_a_list/Perl/search_a_list-2.pl new file mode 100644 index 0000000000..9950308283 --- /dev/null +++ b/Task/Search_a_list/Perl/search_a_list-2.pl @@ -0,0 +1,13 @@ +use List::MoreUtils qw(first_index); + +my @haystack = qw(Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo); + +foreach my $needle (qw(Washington Bush)) { + my $index = first_index { $_ eq $needle } @haystack; # note that "eq" was used because we are comparing strings + # you would use "==" for numbers + if (defined $index) { + print "$index $needle\n"; + } else { + print "$needle is not in haystack\n"; + } +} diff --git a/Task/Search_a_list/Perl/search_a_list-3.pl b/Task/Search_a_list/Perl/search_a_list-3.pl new file mode 100644 index 0000000000..a7be3d255d --- /dev/null +++ b/Task/Search_a_list/Perl/search_a_list-3.pl @@ -0,0 +1,13 @@ +my @haystack = qw(Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo); + +my %haystack_indices; +@haystack_indices{ @haystack } = (0 .. $#haystack); # Caution: this finds the largest index, not the smallest + +foreach my $needle (qw(Washington Bush)) { + my $index = $haystack_indices{$needle}; + if (defined $index) { + print "$index $needle\n"; + } else { + print "$needle is not in haystack\n"; + } +} diff --git a/Task/Search_a_list/Perl/search_a_list.pl b/Task/Search_a_list/Perl/search_a_list.pl new file mode 100644 index 0000000000..3e890999b5 --- /dev/null +++ b/Task/Search_a_list/Perl/search_a_list.pl @@ -0,0 +1,13 @@ +use List::Util qw(first); + +my @haystack = qw(Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo); + +foreach my $needle (qw(Washington Bush)) { + my $index = first { $haystack[$_] eq $needle } (0 .. $#haystack); # note that "eq" was used because we are comparing strings + # you would use "==" for numbers + if (defined $index) { + print "$index $needle\n"; + } else { + print "$needle is not in haystack\n"; + } +} diff --git a/Task/Search_a_list/PicoLisp/search_a_list.l b/Task/Search_a_list/PicoLisp/search_a_list.l new file mode 100644 index 0000000000..3108496e63 --- /dev/null +++ b/Task/Search_a_list/PicoLisp/search_a_list.l @@ -0,0 +1,10 @@ +(de lastIndex (Item Lst) + (- (length Lst) (index Item (reverse Lst)) -1) ) + +(de findNeedle (Fun Sym Lst) + (prinl Sym " " (or (Fun Sym Lst) "not found")) ) + +(let Lst '(Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo) + (findNeedle index 'Washington Lst) + (findNeedle index 'Bush Lst) + (findNeedle lastIndex 'Bush Lst) ) diff --git a/Task/Search_a_list/Python/search_a_list-2.py b/Task/Search_a_list/Python/search_a_list-2.py new file mode 100644 index 0000000000..9f76c78f07 --- /dev/null +++ b/Task/Search_a_list/Python/search_a_list-2.py @@ -0,0 +1,9 @@ +>>> haystack=["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"] +>>> haystack.index('Bush') +4 +>>> haystack.index('Washington') +Traceback (most recent call last): + File "", line 1, in + haystack.index('Washington') +ValueError: list.index(x): x not in list +>>> diff --git a/Task/Search_a_list/Python/search_a_list-3.py b/Task/Search_a_list/Python/search_a_list-3.py new file mode 100644 index 0000000000..d6b8f52d37 --- /dev/null +++ b/Task/Search_a_list/Python/search_a_list-3.py @@ -0,0 +1,13 @@ +>>> def hi_index(needle, haystack): + return len(haystack)-1 - haystack[::-1].index(needle) + +>>> # Lets do some checks +>>> for n in haystack: + hi = hi_index(n, haystack) + assert haystack[hi] == n, "Hi index is of needle" + assert n not in haystack[hi+1:], "No higher index exists" + if haystack.count(n) == 1: + assert hi == haystack.index(n), "index == hi_index if needle occurs only once" + + +>>> diff --git a/Task/Search_a_list/Python/search_a_list.py b/Task/Search_a_list/Python/search_a_list.py new file mode 100644 index 0000000000..62fb0069b5 --- /dev/null +++ b/Task/Search_a_list/Python/search_a_list.py @@ -0,0 +1,7 @@ +haystack=["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"] + +for needle in ("Washington","Bush"): + try: + print haystack.index(needle), needle + except ValueError, value_error: + print needle,"is not in haystack" diff --git a/Task/Search_a_list/REXX/search_a_list-2.rexx b/Task/Search_a_list/REXX/search_a_list-2.rexx new file mode 100644 index 0000000000..bfb0ba2310 --- /dev/null +++ b/Task/Search_a_list/REXX/search_a_list-2.rexx @@ -0,0 +1,44 @@ +/*REXX program searches a collection of strings. */ +hay.0=1000 /*safely indicate highest item #.*/ +hay.200 = 'binilnilium' +hay.98 = 'californium' +hay.6 = 'carbon' +hay.112 = 'copernicium' +hay.29 = 'copper' +hay.114 = 'flerovium' +hay.79 = 'gold' +hay.2 = 'helium' +hay.1 = 'hydrogen' +hay.82 = 'lead' +hay.116 = 'livermorium' +hay.15 = 'phosphorous' +hay.47 = 'silver' +hay.11 = 'sodium' +hay.16 = 'sulfur' +hay.81 = 'thallium' +hay.92 = 'uranium' + +needle = 'gold' /*we'll be looking for the gold. */ +upper needle /*in case some people capitalize.*/ +found=0 /*assume needle isn't found, yet.*/ + + do j=1 for hay.0 /*start looking in haystack item1*/ + _=hay.j; upper _ /*make it uppercase to be safe. */ + if _=needle then do /*we've found needle in haystack.*/ + found=1 /*indicate that needle was found,*/ + leave /* and stop looking, of course. */ + end + end /*j*/ + +if found then return j /*return haystack index number. */ + else say needle "wasn't found in the haystack!" +return 0 /*indicates needle wasn't found. */ + +/*─────────────────────────────────────────────── incidentally, to find */ + /* the number of haystack items: */ +hayItems=0 + + do k=1 for hay.0 /*find item AFTER the last item.*/ + if hay.k\=='' then hayItems=hayItems+1 /*bump the item counter.*/ + end /*k*/ + /*stick a fork in it, we're done.*/ diff --git a/Task/Search_a_list/REXX/search_a_list-3.rexx b/Task/Search_a_list/REXX/search_a_list-3.rexx new file mode 100644 index 0000000000..6ac0973e04 --- /dev/null +++ b/Task/Search_a_list/REXX/search_a_list-3.rexx @@ -0,0 +1,29 @@ +/*REXX program searches a collection of strings. */ +hay.=0 /*initialize haystack collection.*/ +hay._sodium = 1 +hay._phosphorous = 1 +hay._califonium = 1 +hay._copernicium = 1 +hay._gold = 1 +hay._thallium = 1 +hay._carbon = 1 +hay._silver = 1 +hay._copper = 1 +hay._helium = 1 +hay._sulfur = 1 + /*underscores (_) are used to NOT*/ + /* conflict with variable names.*/ + +needle = 'gold' /*we'll be looking for the gold. */ + +Xneedle = '_'needle /*prefix an underscore (_) char. */ +upper Xneedle /*uppercase: how REXX stores 'em.*/ + + /*alternative version of above, */ + /* Xneedle=translate('_'needle)*/ + +found=hay.Xneedle /*this is it, it's found or not.*/ + +if found then return j /*return haystack index number. */ + else say needle "wasn't found in the haystack!" +return 0 /*indicates needle wasn't found. */ diff --git a/Task/Search_a_list/REXX/search_a_list-4.rexx b/Task/Search_a_list/REXX/search_a_list-4.rexx new file mode 100644 index 0000000000..b805f349e0 --- /dev/null +++ b/Task/Search_a_list/REXX/search_a_list-4.rexx @@ -0,0 +1,24 @@ +/*REXX program searches a collection of strings. */ + +haystack=, /*names of the first 200 elements of the periodic table*/ + 'hydrogen helium lithium berylliumbon nitrogen oxygen fluorine neon sodium magnesium aluminum silicon phosphorous sulfur chlorine argon potassium calcium scandium titanium', + 'vanadium chromium manganese iron kel copper zinc gallium germanium arsenic selenium bromine krypton rubidium strontium yttrium zirconium niobium molybdenum technetium ruthenium', + 'rhodium palladium silver cadmium antimony tellurium iodine xenon cesium barium lanthanum cerium praseodymium neodymium promethium samarium europium gadolinium terbium dysprosium', + 'holmium erbium thulium ytterbium afnium tantalum tungsten rhenium osmium irdium platinum gold mercury thallium lead bismuth polonium astatine radon francium radium actinium', + 'thorium protactinium uranium neptonium americium curium berkelium californium einsteinum fermium mendelevium nobelium lawrencium rutherfordium dubnium seaborgium bohrium hassium', + 'meitnerium darmstadtium roentgenicium ununtrium flerovium ununpentium livermorium ununseptium ununoctium ununennium unbinilium unbiunium unbibium unbitrium unbiquadium', + 'unbipentium unbihexium unbiseptiuum unbiennium untrinilium untriunium untribium untritrium untriquadium untripentium untrihexium untriseptium untrioctium untriennium unquadnilium', + 'unquadunium unquadbium unquadtriuadium unquadpentium unquadhexium unquadseptium unquadoctium unquadennium unpentnilium unpentunium unpentbium unpenttrium unpentquadium', + 'unpentpentium unpenthexium unpentpentoctium unpentennium unhexnilium unhexunium unhexbium unhextrium unhexquadium unhexpentium unhexhexium unhexseptium unhexoctium unhexennium', + 'unseptnilium unseptunium unseptbirium unseptquadium unseptpentium unsepthexium unseptseptium unseptoctium unseptennium unoctnilium unoctunium unoctbium unocttrium unoctquadium', + 'unoctpentium unocthexium unoctsepoctium unoctennium unennilium unennunium unennbium unenntrium unennquadium unennpentium unennhexium unennseptium unennoctium unennennium binilnilium' + +needle = 'gold' /*we'll be looking for the gold. */ + +upper needle haystack /*in case some people capitalize.*/ + +idx=wordpos(needle,haystack) /*use REXX's bif: WORDPOS */ + /* bif: built-in function.*/ +if idx\==0 then return idx /*return haystack index number. */ + else say needle "wasn't found in the haystack!" +return 0 /*indicates needle wasn't found. */ diff --git a/Task/Search_a_list/REXX/search_a_list.rexx b/Task/Search_a_list/REXX/search_a_list.rexx new file mode 100644 index 0000000000..56cb3c73d5 --- /dev/null +++ b/Task/Search_a_list/REXX/search_a_list.rexx @@ -0,0 +1,30 @@ +/*REXX program searches a collection of strings. */ +hay.= /*initialize haystack collection.*/ +hay.1 = 'sodium' +hay.2 = 'phosphorous' +hay.3 = 'californium' +hay.4 = 'copernicium' +hay.5 = 'gold' +hay.6 = 'thallium' +hay.7 = 'carbon' +hay.8 = 'silver' +hay.9 = 'curium' +hay.10 = 'copper' +hay.11 = 'helium' +hay.12 = 'sulfur' + +needle='gold' /*we'll be looking for the gold. */ +upper needle /*in case some people capitalize.*/ +found=0 /*assume needle isn't found yet. */ + + do j=1 while hay.j\=='' /*keep looking in haystack. */ + _=hay.j; upper _ /*make it uppercase to be safe. */ + if _=needle then do /*we've found needle in haystack.*/ + found=1 /*indicate that needle was found,*/ + leave /* and stop looking, of course. */ + end + end /*j*/ + +if found then return j /*return haystack index number. */ + else say needle "wasn't found in the haystack!" +return 0 /*indicates needle wasn't found. */ diff --git a/Task/Search_a_list/Ruby/search_a_list-2.rb b/Task/Search_a_list/Ruby/search_a_list-2.rb new file mode 100644 index 0000000000..99ecb018af --- /dev/null +++ b/Task/Search_a_list/Ruby/search_a_list-2.rb @@ -0,0 +1,7 @@ +haystack.each do |item| + last = haystack.rindex(item) + if last > haystack.index(item) + puts "#{item} last appears at index #{last}" + break + end +end diff --git a/Task/Search_a_list/Ruby/search_a_list-3.rb b/Task/Search_a_list/Ruby/search_a_list-3.rb new file mode 100644 index 0000000000..67ff7a12e0 --- /dev/null +++ b/Task/Search_a_list/Ruby/search_a_list-3.rb @@ -0,0 +1,3 @@ +multi_item = haystack .each_with_index .group_by {|elem, idx| elem} .find {|key, val| val.length > 1} +# multi_item is => ["Bush", [["Bush", 4], ["Bush", 7]]] +puts "#{multi_item[0]} last appears at index #{multi_item[1][-1][1]}" unless multi_item.nil? diff --git a/Task/Search_a_list/Ruby/search_a_list.rb b/Task/Search_a_list/Ruby/search_a_list.rb new file mode 100644 index 0000000000..24bfd0d5b7 --- /dev/null +++ b/Task/Search_a_list/Ruby/search_a_list.rb @@ -0,0 +1,9 @@ +haystack = %w(Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo) + +%w(Bush Washington).each do |needle| + if (i = haystack.index(needle)) + print i, " ", needle, "\n" + else + raise "#{needle} is not in haystack\n" + end +end diff --git a/Task/Search_a_list/Scala/search_a_list.scala b/Task/Search_a_list/Scala/search_a_list.scala new file mode 100644 index 0000000000..affd82fad5 --- /dev/null +++ b/Task/Search_a_list/Scala/search_a_list.scala @@ -0,0 +1,3 @@ +def findNeedles(needle: String, haystack: Seq[String]) = haystack.zipWithIndex.filter(_._1 == needle).map(_._2) +def firstNeedle(needle: String, haystack: Seq[String]) = findNeedles(needle, haystack).head +def lastNeedle(needle: String, haystack: Seq[String]) = findNeedles(needle, haystack).last diff --git a/Task/Search_a_list/Tcl/search_a_list-2.tcl b/Task/Search_a_list/Tcl/search_a_list-2.tcl new file mode 100644 index 0000000000..2fdafb3750 --- /dev/null +++ b/Task/Search_a_list/Tcl/search_a_list-2.tcl @@ -0,0 +1,9 @@ +set haystack {Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo} +foreach needle {Bush Washington} { + set indices [lsearch -all -exact $haystack $needle] + if {[llength $indices] == 0} { + error "$needle does not appear in the haystack" + } else { + puts "$needle appears first at index [lindex $indices 0] and last at [lindex $indices end]" + } +} diff --git a/Task/Search_a_list/Tcl/search_a_list.tcl b/Task/Search_a_list/Tcl/search_a_list.tcl new file mode 100644 index 0000000000..66b8f02d71 --- /dev/null +++ b/Task/Search_a_list/Tcl/search_a_list.tcl @@ -0,0 +1,8 @@ +set haystack {Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo} +foreach needle {Bush Washington} { + if {[set idx [lsearch -exact $haystack $needle]] == -1} { + error "$needle does not appear in the haystack" + } else { + puts "$needle appears at index $idx in the haystack" + } +}