|
./Ruby/Projects
|
Ruby
My new favorite programming language! It's a powerful high-level scripting language with the capability of a much lower-level programming language, like C++ or Java. «Read» the official scoop on Ruby.
|
Projects
Gaming Dice ···more info···
Spawned from a renewed interest in board games, I created a simple Dice object. The neat thing about it, is it extends the Fixnum base object to allow for a common gaming dice notation: 3d8 (3 8-sided dice). Using this library, you can create an array of random values with: 3.d(6) for example. I also added in a sum function and printing the dice out to ascii art (if they are 6 sided). You can also reset your dice object to any number of dice of any number of sides.
Logic Solver ···more info···
Whose Fish?
By Albert Einstein (maybe)
There are five houses in a row in different colors. In each house lives a person with a different
nationality. The five owners drink a different drink, smoke a different brand of cigar and keep
a different pet, one of which is a Walleye Pike.
The question is-- who owns the fish?
Hints:
1. The Brit lives in the red house.
2. The Swede keeps dogs as pets.
3. The Dane drinks tea.
4. The green house is on the left of the white house.
5. The green house owner drinks coffee.
6. The person who smokes Pall Malls keeps birds.
7. The owner of the yellow house smokes Dunhills.
8. The man living in the house right in the center drinks milk.
9. The man who smokes Blends lives next to the one who keeps cats.
10. The Norwegian lives in the first house.
11. The man who keeps horses lives next to the one who smokes Dunhills.
12. The owner who smokes Bluemasters drinks beer.
13. The German smokes Princes.
14. The Norwegian lives next to the blue house.
15. The man who smokes Blends has a neighbor who drinks water.
Brute force will give (5!)^5 combinations, each combination tested 15 times. If you're having a hard time calculating that in your head, that's 373,248,000,000 (373+ billion) tests to find the answer. Not fun... even for a computer.
Using Ruby, I created my own brute force method, however, I altered the order of the combination and test logic. I performed the calculations in layers, adding one layer of combinations and tests upon another. The result ended with a mere 50,000+ tests required taking only 0.25 secs!
Permutations and Combinations ···more info···
A class that contains member functions for the generation of mathematical permutations and combinations of user input sets. The functions to generate the results were created using recursion and allowed for a very small and elegant solution.
Internet Image Scraper ···more info···
Using Ruby's net/http library, a script was created that grabbed all the images from a web page, copied to a local folder, and generated an HTML summary showing the images that were grabbed. The user can specify a minimum file size (in kilobytes) to grab, and use a set of filters (regular expressions or explicitly stated strings) to prevent unwanted common images, such as banners or logos. A series of pages can also be specified to bulk download. A shorthand notation in the form of "test[0..10].html" systematically downloads images from sequentially numbered pages.
Casino Craps Simulator ···more info···
A simple Craps game engine was created to test out basic betting strategies across numerous runs (millions), logging important statistical data. (and yes, I did make money at the craps table...)
./Ruby/Work in Progress
I'm currently working on a generic game engine that will be scriptable to create custom board games. The idea is to create a set of APIs that allow an individual to define the graphic elements of the board by drawing shapes or laying out images, define the players' assets, and build the rules for the game. Ideally, I'd like to be able to output the board and pieces to a PDF as well as build an application to run the game on the computer. It would also be nice to have it build a simple TCP/IP server-client for multiplayer games to be played online.
We'll see where it goes...
Ruby is the interpreted scripting language for quick and easy
object-oriented programming. It has many features to process text files
and to do system management tasks (as in Perl). It is simple,
straight-forward, extensible, and portable.
Oh, I need to mention, it's totally free, which means not only free
of charge, but also freedom to use, copy, modify, and distribute it.
Features of Ruby
- Ruby has simple syntax, partially inspired by Eiffel and Ada.
- Ruby has exception handling features, like Java or Python, to make it easy to handle errors.
- Ruby's operators are syntax sugar for the methods. You can redefine them easily.
- Ruby
is a complete, full, pure object oriented language: OOL. This means all
data in Ruby is an object, in the sense of Smalltalk: no exceptions.
Example: In Ruby, the number 1 is an instance of class Fixnum.
- Ruby's
OO is carefully designed to be both complete and open for improvements.
Example: Ruby has the ability to add methods to a class, or even to an
instance during runtime. So, if needed, an instance of one class *can*
behave differently from other instances of the same class.
- Ruby
features single inheritance only, *on purpose*. But Ruby knows the
concept of modules (called Categories in Objective-C). Modules are
collections of methods. Every class can import a module and so gets all
its methods for free. Some of us think that this is a much clearer way
than multiple inheritance, which is complex, and not used very often
compared with single inheritance (don't count C++ here, as it has often
no other choice due to strong type checking!).
- Ruby features true closures. Not just unnamed function, but with present variable bindings.
- Ruby
features blocks in its syntax (code surrounded by '{' ... '}' or 'do'
... 'end'). These blocks can be passed to methods, or converted into
closures.
- Ruby features a true mark-and-sweep garbage
collector. It works with all Ruby objects. You don't have to care about
maintaining reference counts in extension libraries. This is better for
your health. ;-)
- Writing C extensions in Ruby is easier than in
Perl or Python, due partly to the garbage collector, and partly to the
fine extension API. SWIG interface is also available.
- Integers
in Ruby can (and should) be used without counting their internal
representation. There *are* small integers (instances of class Fixnum)
and large integers (Bignum), but you need not worry over which one is
used currently. If a value is small enough, an integer is a Fixnum,
otherwise it is a Bignum. Conversion occurs automatically.
- Ruby
needs no variable declarations. It uses simple naming conventions to
denote the scope of variables. Examples: simple 'var' = local variable,
'@var' = instance variable, '$var' = global variable. So it is also not
necessary to use a tiresome 'self.' prepended to every instance member.
- Ruby can load extension libraries dynamically if an OS allows.
- Ruby
features OS independent threading. Thus, for all platforms on which
Ruby runs, you also have multithreading, regardless of if the OS
supports it or not, even on MS-DOS! ;-)
- Ruby is highly
portable: it is developed mostly on Linux, but works on many types of
UNIX, DOS, Windows 95/98/Me/NT/2000/XP, MacOS, BeOS, OS/2, etc.
|