lunes, 28 de noviembre de 2016

My first post on Swift (for Linux)


As Apple kindly released Swift for Linux...I had to learn about it -:)

Of course...it's not fully implemented...so most of the things that makes Swift awesome on IOS are not here yet...but still...it's awesome! -:D

Swift is kind of functional...so you can see a lot from Haskell and Erlang...but it's also imperative and Object Oriented...so that makes it a really interesting language...

As usual...here's my Fibonacci numbers little app...

fibonacci.swift
func fib(num:Int,a:Int,b:Int) -> String{
 var result: String = "";
 if a > 0 && num > 1{
  result = result + String(a + b) + " " + 
           fib(num: (num - 1), a: (a + b), b: a);
 }else if a == 0{
  result = String(a) + " " + String(b) + " " + 
           String(a + b) + " " + 
           fib(num: (num - 1), a: (a + b), b: b);
 }
 return result;
}

print("Enter a number: ",terminator:"");
let number = Int(readLine(strippingNewline: true)!);

print(fib(num: number!, a: 0, b: 1));

And here's the result....


I already have the LED Numbers app ready...so just wait for it -;)

Greetings,

Blag.
Development Culture.

martes, 15 de noviembre de 2016

LED is my new Hello World - Perl Time

As promised...here's my LED Numbers a la Perl...and as always...please keep in mind that I'm Perl newbie...I know that there are more efficient, short and concise way of doing this app...but...how good is an introductory code that uses some obscure and arcane code? I don't want to scare people away from Perl...I want people to say "Hey...that doesn't look hard...I want to learn Perl"...

So...here it is...

LedNumbers.pl
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;

my %leds = (
 0 => ' _  ,| | ,|_| ',
 1 => '  ,| ,| ',
 2 => ' _  , _| ,|_  ',
 3 => '_  ,_| ,_| ',
 4 => '    ,|_| ,  | ',
 5 => ' _  ,|_  , _| ',
 6 => ' _  ,|_  ,|_| ',
 7 => '_   , |  , |  ',
 8 => ' _  ,|_| ,|_| ',
 9 => ' _  ,|_| , _| '
);

print "Enter a number: ";
my $num = <>;
my @numbers = ( $num =~ /\d/g );

for my $i (0 .. 2){
 for my $j (0 .. scalar(@numbers) - 1){
  my @line = split /\,/,$leds{$numbers[$j]};
  print $line[$i];
 }
 print "\n";
}

And here's the output...


And just so you know...this is my 24th version of this code...yep...I have written my LED Numbers app in 24 languages so far -;) What's going to be my end point? Who knows...programming is the limit -;)

Greetings,

Blag.
Development Culture.

My first post on Perl



So yes...I started to learn Perl...why? 3 simple reasons...


  1. I love programming.
  2. For me...Perl belongs to the whole trinity of Scripting Languages along with Ruby and Python (Sorry PHP...you don't make the cut)
  3. Because...it's Perl! Come on!

So...I have been reading Beginning Perl...an awesome book by the way...



If you're using any flavor of Linux or Mac...you should have Perl installed already...if you're using Windows...well...you can always download it and install it -:)

So far...I love Perl...it's pretty amazing...and now I can see why people say that both Python and Ruby heavily borrow stuff from Perl...and sure...PHP too...

I don't have of course much experience...but as always...I start doing a simple and small program to get me into the right track...so here's my Fibonacci numbers app...

fibonacci.pl
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;

sub fib {
 my ($num,$a,$b) = @_;
 my $result = '';
 if ($a>0 && $num>1){
  $result = $result . ($a+$b) . " " . fib($num-1,$a+$b,$a)
 }elsif($a == 0){
  $result = $a . " " . $b . " " . ($a+$b) . " " . fib($num-1,$a+$b,$b)
 }
 return $result
}

print "Enter a number: ";
my $num = <>;

print(fib($num,0,1));

And here's the nice output...


By now...I already have my classic "LED Numbers" app ready...but that goes into another post -;)

Greetings,

Blag.
Development Culture.