martes, 23 de septiembre de 2014

Web scrapping with Haskell and PhatomJS

Some time ago I wrote a blog called Web scrapping with Julia and PhantomJS...today...I wanted to do the same but using Haskell instead...

The concept is the same...we create a PhantomJS script that will read a "user" Twitter page and get the hashtags of the first 5 pages...here's the PhantomJS script...

Hashtags.js
var system = require('system');

var webpage = require('webpage').create();
webpage.viewportSize = { width: 1280, height: 800 };
webpage.scrollPosition = { top: 0, left: 0 };

var userid = system.args[1];
var profileUrl = "http://www.twitter.com/" + userid;

webpage.open(profileUrl, function(status) {
 if (status === 'fail') {
  console.error('webpage did not open successfully');
  phantom.exit(1);
 }
 var i = 0,
 top,
 queryFn = function() {
  return document.body.scrollHeight;
 };
 setInterval(function() {
  top = webpage.evaluate(queryFn);
  i++;
   
  webpage.scrollPosition = { top: top + 1, left: 0 };

  if (i >= 5) {
   var twitter = webpage.evaluate(function () {
    var twitter = [];
    forEach = Array.prototype.forEach;
    var tweets = document.querySelectorAll('[data-query-source="hashtag_click"]');
    forEach.call(tweets, function(el) {
     twitter.push(el.innerText);
    });
    return twitter;
   });

   twitter.forEach(function(t) {
    console.log(t);
   });

   phantom.exit();
  }
}, 3000);
});

If we run the script we're going to see the following output...


Now...what I want to do with this information...is to send it to Haskell...and get the most used hashtags...so I will summarize them and then get rid of the ones that only appear less than 5 times...

Let's see the Haskell code...

hashtags.hs
import System.Process
import Data.List

hashTags :: String -> IO()
hashTags(user) = do
 let x = readProcess "phantomjs" ["Hashtags.js",user] []
 y <- x
 mapM_ print $ sortBy sortGT $ count y

count :: String -> [(String,Int)]
count xs = filter ((>=5).snd) $ 
     map(\ws -> (head ws, length ws)) $ 
           group $ sort $ words xs

sortGT :: (Ord a, Ord a1) => (a1, a) -> (a1, a) -> Ordering
sortGT (a1, b1) (a2, b2)
  | b1 < b2 = GT
  | b1 > b2 = LT
  | b1 == b2 = compare a1 a2

When we run this code...we're going to have this output...


The nice thing about this app is that we can pass any username as parameter and the result is going to nicely ordered and filtered...another reason to love Haskell -;)

Greetings,

Blag.
Development Culture.

miércoles, 17 de septiembre de 2014

Learn You a Haskell for Great Good! - Book review

Finally! I have finished reading Learn You a Haskell for Great Good! and here's my review -;)

After learning Erlang, I decided it was a good idea to get hardcore and learn an even more "Pure" functional programming language...Haskell was of course my best shot...

This book is just pretty awesome...it has 404 pages...so it's a big book...

The examples are really nice and easy to follow...of course...once you get your head around Haskell and it's weird way of doing things...after a few headaches and curses...you found yourself loving the language...

This book will teach you about recursion, pattern matching, guards, monoids, and a handful of things that you couldn't find on a imperative language...



If you want to learn Haskell...this book is definitely for you...written with lots of humor and great examples it makes learning Haskell a real joy...I would recommend it a 100%...

If you haven't ever try a functional language...I will recommend you to do so...you will not regret it...you will become smart and a better developer...sure...you will get frustrated a thousand of times...but there's a price to pay when it comes to becoming better at something...

Haskell will help you to become better and this book will guide you through the hard path...

Greetings,

Blag.
Development Culture.

martes, 2 de septiembre de 2014

Decimal to Romans - Haskell Style

As promised...here's my Haskell take on Decimal to Romans...I got say...it took me considerably less time to build it Haskell that it took me to build it Erlang...but for sure...I had already done it in Erlang...so I had some sort of advantage -;)

Anyway...this was so much fun to do...and couldn't be happier with the overall process...Haskell being so pure is really a joy to work with...

Too much talk...here's the source code...

Roman_Numerals.hs
showRomans :: Int -> IO()
showRomans(num) = do
 putStr $ concat $ get_roman num 0

get_roman :: Int -> Int -> [[Char]]
get_roman num ctr
 | num >= roman = make_roman(roman) ++ get_roman(num - roman) ctr
 | num < roman && num > 0 = get_roman(num) (ctr+1)
 | num <= 0 = ["\n"]
 where roman = roman_keys [] !! ctr

make_roman :: Int -> [[Char]]
make_roman(1) = ["I"]; make_roman(4) = ["IV"]; make_roman(5) = ["V"];
make_roman(9) = ["IX"]; make_roman(10) = ["X"]; make_roman(40) = ["XL"];
make_roman(50) = ["L"]; make_roman(90) = ["XC"]; make_roman(100) = ["C"];
make_roman(400) = ["CD"]; make_roman(500) = ["D"]; make_roman(900) = ["CM"];
make_roman(1000) = ["M"]

roman_keys :: [Int] -> [Int]
roman_keys keys = [1000,900,500,400,100,90,50,40,10,9,5,4,1]

As usual...here's the screenshot...


After so many blogs in just a few days...I think I deserve a break, so I can keep reading the Haskell book...as I promised a review of it...

Greetings,

Blag.
Development Culture.

viernes, 29 de agosto de 2014

LED is my new Hello World - ABAP Time

It's been a long time since I did any ABAP development...so just for the good all times I decided to build the LED Number application on ABAP as well... -;)

I'm might be a little bit rusty...but I think I still remember most of the all tricks -:P

This goes out to all my ABAP friends...there are plenty -:)

ZLED
REPORT  zled.

TYPES: BEGIN OF ty_lines,
       line(1) TYPE c,
       index(1) TYPE c,
       map TYPE string,
       END OF ty_lines.

DATA: s_number TYPE string,
      counter TYPE i,
      num_counter TYPE i,
      line1 TYPE string,
      line2 TYPE string,
      line3 TYPE string.

DATA: t_lines TYPE STANDARD TABLE OF ty_lines.
FIELD-SYMBOLS: <fs_lines> LIKE LINE OF t_lines.

SELECTION-SCREEN BEGIN OF BLOCK params.
PARAMETERS: p_number TYPE i.
SELECTION-SCREEN END OF BLOCK params.

START-OF-SELECTION.
  PERFORM load_data.
  num_counter = 0.
  s_number = p_number.
  counter = strlen( s_number ) - 1.
  DO counter TIMES.
    READ TABLE t_lines ASSIGNING <fs_lines>
    WITH KEY line = 1
             index = s_number+num_counter(1).
    CONCATENATE line1 <fs_lines>-map INTO line1 SEPARATED BY space.
    READ TABLE t_lines ASSIGNING <fs_lines>
    WITH KEY line = 2
             index = s_number+num_counter(1).
    CONCATENATE line2 <fs_lines>-map INTO line2 SEPARATED BY space.
    READ TABLE t_lines ASSIGNING <fs_lines>
    WITH KEY line = 3
             index = s_number+num_counter(1).
    CONCATENATE line3 <fs_lines>-map INTO line3 SEPARATED BY space.
    num_counter = num_counter + 1.
  ENDDO.
  REPLACE ALL OCCURRENCES OF '%' IN line1 WITH ` ` IN CHARACTER MODE.
  REPLACE ALL OCCURRENCES OF '%' IN line2 WITH ` ` IN CHARACTER MODE.
  REPLACE ALL OCCURRENCES OF '%' IN line3 WITH ` ` IN CHARACTER MODE.
  WRITE:/ line1.
  WRITE:/ line2.
  WRITE:/ line3.

*&---------------------------------------------------------------------*
*&      Form  LOAD_DATA
*&---------------------------------------------------------------------*
FORM load_data.

  PERFORM add_lines USING '1' '0' '%_%%'.
  PERFORM add_lines USING '2' '0' '| |%'.
  PERFORM add_lines USING '3' '0' '|_|%'.
  PERFORM add_lines USING '1' '1' '%%'.
  PERFORM add_lines USING '2' '1' '|%'.
  PERFORM add_lines USING '3' '1' '|%'.
  PERFORM add_lines USING '1' '2' '%_%%'.
  PERFORM add_lines USING '2' '2' ' _|%'.
  PERFORM add_lines USING '3' '2' '|_%%'.
  PERFORM add_lines USING '1' '3' '_%%'.
  PERFORM add_lines USING '2' '3' '_|%'.
  PERFORM add_lines USING '3' '3' '_|%'.
  PERFORM add_lines USING '1' '4' '%%%%'.
  PERFORM add_lines USING '2' '4' '|_|%'.
  PERFORM add_lines USING '3' '4' '  |%'.
  PERFORM add_lines USING '1' '5' '%_%%'.
  PERFORM add_lines USING '2' '5' '|_ %'.
  PERFORM add_lines USING '3' '5' ' _|%'.
  PERFORM add_lines USING '1' '6' '%_%%'.
  PERFORM add_lines USING '2' '6' '|_%%'.
  PERFORM add_lines USING '3' '6' '|_|%'.
  PERFORM add_lines USING '1' '7' '_%%'.
  PERFORM add_lines USING '2' '7' '%|%'.
  PERFORM add_lines USING '3' '7' '%|%'.
  PERFORM add_lines USING '1' '8' '%_%%'.
  PERFORM add_lines USING '2' '8' '|_|%'.
  PERFORM add_lines USING '3' '8' '|_|%'.
  PERFORM add_lines USING '1' '9' '%_%%'.
  PERFORM add_lines USING '2' '9' '|_|%'.
  PERFORM add_lines USING '3' '9' ' _|%'.

ENDFORM.                    " LOAD_DATA

*&---------------------------------------------------------------------*
*&      Form  add_lines
*&---------------------------------------------------------------------*
FORM add_lines USING p_line p_index p_map.
  APPEND INITIAL LINE TO t_lines ASSIGNING <fs_lines>.
  <fs_lines>-line = p_line.
  <fs_lines>-index = p_index.
  <fs_lines>-map = p_map.
ENDFORM.                    "add_lines

Pics or it didn't happen -:)





Greetings,

Blag.
Development Culture.



LED is my new Hello World - R Time

Yep...as I have said many times before, the LED Number application has become my new Hello World...whenever I learn a new programming language I try to build this, because it compromises several language constructs and makes you learn more by trying to figure out how to build it again...

Yesterday I blog about how to build it using Haskell...and...I'm still learning Haskell...so I thought..."It's cool that I'm using this for my new programming languages...but what about the old ones?"

I suddenly realized that I had never wrote this using R...and that's really sad...I love R -:)

Anyway...here it goes -;)

LED.R
line<-c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3)
index<-c(0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9)
map<-c("  _ ","| | ","|_| ","  ","| ","| ","  _ "," _| ","|_  ",
       " _","_| ","_| ","    ","|_| ","  | ","  _ ","|_  "," _| ",
       "  _ ","|_  ","|_| "," _  "," |  "," |  ","  _ ","|_| ","|_| ",
       "  _ ","|_| "," _| ")

Lines<-cbind(line,index,map)
DF_Lines<-data.frame(Lines,stringsAsFactors=F)

line1<-""
line2<-""
line3<-""

p_number<-readline("Enter a number?: ")
l_number<-strsplit(p_number,"")
for(i in 1:nchar(p_number)){
  num_map<-DF_Lines[DF_Lines$index == as.numeric(l_number[[1]][i]),]
  line1<-paste(line1,num_map$map[1])
  line2<-paste(line2,num_map$map[2])
  line3<-paste(line3,num_map$map[3])
}
lines = paste(line1,"\n",line2,"\n",line3,"\n")
cat(lines)

Check the picture -;)


Greetings,

Blag.
Development Culture.

jueves, 28 de agosto de 2014

My first post on Haskell

So...as I get into functional programming thanks to Erlang...I decided to deep dive into Haskell...a pure functional programming language...

Of course...I'm reading a book for this...so when I finished it...which will take some time as I'm planning to start reading from the very first page again...soon you will read my review on Learn You a Haskell for Great Good...

Now...Haskell is hard...the hardest programming language I have ever dared to learn...and here's a couple of reasons why...
  • Variables are immutable...once assigned they cannot be re-assigned.
  • Functions only accept one parameter and one parameter only.
  • Functions can only call one function at a time.
  • There are no loops.
  • No side effects...everything is pure...a function will always return the same output

There's a really nice picture from XKCD explaining Haskell...


Anyway...Haskell makes you really forget everything you ever learn and make you learn everything again...for a developer like me...that's pure happiness -:)

So...I have done with already Ruby, Python, Julia and Erlang...I wanted my first Haskell application to be a LED Numbers application...so here goes the code...hang to you seat and watch this...BTW...I'm sure the code can be optimized...but I'm just a newbie...and my application works...so who cares about it -;)


LED.hs
showLED :: Int -> IO()
showLED(num) = do
 putStr(concat(addN(get_led(digits num) 1 num) (length(show num)) (length(show num))))

get_led :: [Int] -> Int -> Int -> [[Char]]
get_led (x:xs) n num = make_led_digit(x,n) ++ get_led(xs) n num
get_led [] n num = get_led2(digits num) (n+1) num

get_led2 :: [Int] -> Int -> Int -> [[Char]]
get_led2 (x:xs) n num = make_led_digit(x,n) ++ get_led2(xs) n num 
get_led2 [] n num = get_led3(digits num) (n+1) num

get_led3 :: [Int] -> Int -> Int -> [[Char]]
get_led3 (x:xs) n num = make_led_digit(x,n) ++ get_led3(xs) n num
get_led3 [] n num = []

digits :: Int -> [Int]
digits = map (read . (:[])) . show

addN :: [String] -> Int -> Int -> [String]
addN (x:xs) n ni
 | n > 0 = [x] ++ addN xs (n-1) ni
 | n == 0 = ["\n"] ++ [x] ++ addN xs (ni-1) ni
addN [] _ _ = [] ++ ["\n"]

make_led_digit :: (Int, Int) -> [[Char]]
make_led_digit(0,1) = [" _  "]; make_led_digit(0,2) = ["| | "]; make_led_digit(0,3) = ["|_| "];
make_led_digit(1,1) = ["  "];   make_led_digit(1,2) = ["| "];   make_led_digit(1,3) = ["| "];
make_led_digit(2,1) = [" _  "]; make_led_digit(2,2) = [" _| "]; make_led_digit(2,3) = ["|_  "];
make_led_digit(3,1) = ["_  "];  make_led_digit(3,2) = ["_| "];  make_led_digit(3,3) = ["_| "];
make_led_digit(4,1) = ["    "]; make_led_digit(4,2) = ["|_| "]; make_led_digit(4,3) = ["  | "];
make_led_digit(5,1) = [" _  "]; make_led_digit(5,2) = ["|_  "]; make_led_digit(5,3) = [" _| "];
make_led_digit(6,1) = [" _  "]; make_led_digit(6,2) = ["|_  "]; make_led_digit(6,3) = ["|_| "];
make_led_digit(7,1) = ["_   "]; make_led_digit(7,2) = [" |  "]; make_led_digit(7,3) = [" |  "];
make_led_digit(8,1) = [" _  "]; make_led_digit(8,2) = ["|_| "]; make_led_digit(8,3) = ["|_| "];
make_led_digit(9,1) = [" _  "]; make_led_digit(9,2) = ["|_| "]; make_led_digit(9,3) = [" _| "]

Here's a picture that show how it works...


I will keep learning Haskell and write another blog called "Decimals to Roman - Haskell Style"...stay tuned -;)

UPDATE!

Ok...I must face it...I couldn't leave the application like that knowing that I could make better...here's the new updated version -;)

LED_Fixed.hs
showLED :: Int -> IO()
showLED(num) = do
 putStr(concat(addN(get_led(digits num) 1 num) (length(show num)) (length(show num))))

get_led :: [Int] -> Int -> Int -> [[Char]]
get_led (x:xs) n num = make_led_digit(x,n) ++ get_led(xs) n num
get_led [] n num
 | n < 3 = get_led(digits num) (n+1) num
 | n == 3 = []

digits :: Int -> [Int]
digits = map (read . (:[])) . show

addN :: [String] -> Int -> Int -> [String]
addN (x:xs) n ni
 | n > 0 = [x] ++ addN xs (n-1) ni
 | n == 0 = ["\n"] ++ [x] ++ addN xs (ni-1) ni
addN [] _ _ = [] ++ ["\n"]

make_led_digit :: (Int, Int) -> [[Char]]
make_led_digit(0,1) = [" _  "]; make_led_digit(0,2) = ["| | "]; make_led_digit(0,3) = ["|_| "];
make_led_digit(1,1) = ["  "];   make_led_digit(1,2) = ["| "];   make_led_digit(1,3) = ["| "];
make_led_digit(2,1) = [" _  "]; make_led_digit(2,2) = [" _| "]; make_led_digit(2,3) = ["|_  "];
make_led_digit(3,1) = ["_  "];  make_led_digit(3,2) = ["_| "];  make_led_digit(3,3) = ["_| "];
make_led_digit(4,1) = ["    "]; make_led_digit(4,2) = ["|_| "]; make_led_digit(4,3) = ["  | "];
make_led_digit(5,1) = [" _  "]; make_led_digit(5,2) = ["|_  "]; make_led_digit(5,3) = [" _| "];
make_led_digit(6,1) = [" _  "]; make_led_digit(6,2) = ["|_  "]; make_led_digit(6,3) = ["|_| "];
make_led_digit(7,1) = ["_   "]; make_led_digit(7,2) = [" |  "]; make_led_digit(7,3) = [" |  "];
make_led_digit(8,1) = [" _  "]; make_led_digit(8,2) = ["|_| "]; make_led_digit(8,3) = ["|_| "];
make_led_digit(9,1) = [" _  "]; make_led_digit(9,2) = ["|_| "]; make_led_digit(9,3) = [" _| "]

Greetings,

Blag.
Development Culture.

viernes, 22 de agosto de 2014

Programming Erlang Software for a Concurrent World - Book Review

I just finished reading Programming Erlang Software for a Concurrent World by Joe Armstrong...the creator of Erlang.

Nothing better that reading about a language, from the mouth of it's creator -:)


The book is huge with 519 pages...but every single page is worth reading...full of nice, funny and well explained examples, Mr. Armstrong makes you love Erlang -:)

Learn about Sequential Programming, Concurrent Programming, Distrubuted Programming, Sockets, DETS, OTP and Mnesia...among others...




This book is just great and I have learned so much...of course...while I'm still an Erlang newbie..I have enough knowledge to build small applications and have a lot of fun -;)

What I like about the book is that the approach is very light and casual...the example are not too easy or too hard, so using them to learn is just right...

Erlang is a language is that more than worth learning...and this book really does the job of hooking you up and getting ready for more...

Greetings,

Blag.
Development Culture.

viernes, 8 de agosto de 2014

Bioinformatics with R Cookbook - Book Review

I just finished reading Bioinformatics with R Cookbook...so here's my review -:)



I was excited to read this book, because it's been a while since I read any R book...but...I gotta admit...this is not my kind of book...as I discovered that obviously I had minus one experience in Bioinformatics...

The book is not short but not long either...340 pages...and it's full of recipes...

It starts with a basic introduction to R, which should be appreciated by newbies...but for more season developers that just can be skipped out...

The are chapters dedicated to Sequence Analysis, Protein Structure Analysis and even Machine Learning in Bioinformatics...

Of course there's a lot of new packages that are used for the recipes and well as many interesting graphics...




If you have some knowledge of Bioinformatics...then you should for sure get this book...if you're not...well...you can buy it anyway...even if you don't understand anything...it is still a book about R and it's full of interesting codes...so you might end learning a bunch of new things -;)

The recipes are well explained and the result is always shown...which is good so we can know exactly what to expect...

Greetings,

Blag.
Development Culture.



miércoles, 6 de agosto de 2014

Decimal to Romans - Erlang Style

As I keep going with my Erlang enlightenment...I decided to try to make a Decimal to Roman Numbers application...as I have done with other programming languages in the past...and it wasn't that easy -:)

First...there's no such thing as associative arrays in Erlang...also...you can only assign variables once...on top of that there's no loops...but...who cares...functional programming is cool -;)

Of course...my code might be have done better...but...I'm learning...and by coding I learn more...so that's fine with me...

Here's why I wrote -;)

roman_numerals.erl
-module(roman_numerals).
-export([showRomans/1]).
-define(DECIMALS,{1000,900,500,400,100,90,50,40,10,9,5,4,1}).

showRomans(Number) when is_integer(Number) ->
 showRomans(Number,1,"").

showRomans(0,_,Acc) ->
 io:format("~s~n",[Acc]);
showRomans(Number,Counter,Acc) ->
 case Number >= element(Counter,?DECIMALS) of 
  true -> showRomans(Number - element(Counter,?DECIMALS),
         Counter,Acc ++ make_roman(element(Counter,?DECIMALS)));
  false -> showRomans(Number,Counter + 1,Acc)
 end.
  
make_roman(1) -> "I";make_roman(4) -> "IV";make_roman(5) -> "V";
make_roman(9) -> "IX";make_roman(10) -> "X";make_roman(40) -> "XL";
make_roman(50) -> "L";make_roman(90) -> "XC";make_roman(100) -> "C";
make_roman(400) -> "CD";make_roman(500) -> "D";make_roman(900) -> "CM";
make_roman(1000) -> "M".

When we execute it...we can see that it works nicely -;)


As you can see...Erlang is all about functions, recursion, accumulators and a new way of thinking -:)

Greetings,

Blag.
Development Culture.

lunes, 4 de agosto de 2014

A trip down memory lane - Basic for Macintosh Plus

Many years ago...in the good old days...my first computer was a Macintosh Plus...


Of course...back then I didn't have a clue about programming...but...thanks to the wonderful world of the Internet I was able to get my hands on a Macintosh Plus Emulator called Mini vMac.

I got it a couple of years ago but barely used it...so today...I wanted to get the feeling of old programming by using...


Yep...Microsoft Basic 2.0 for the Mac...

This is how the environment of the Mini vMac looks like...using MacOS 7.0.1


As I have been using the LED example for many programming languages...I thought it would be a good idea to use it here as well...


The output doesn't look to good...but who cares -;)



Here's the source code in case you're interested -:D

LED
Dim Five$(2)
Dim Six$(2)
Dim Seven$(2)
Dim Eight$(2)
Dim Nine$(2)
Zero$(0) = " _  "
Zero$(1) = "| | "
Zero$(2) = "|_| "
One$(0) = "  "
One$(1) = "| "
One$(2) = "| "
Two$(0) = " _  "
Two$(1) = " _| "
Two$(2) = "|_  "
Three$(0) = "_  "
Three$(1) = "_| "
Three$(2) = "_| "
Four$(0) = "    "
Four$(1) = "|_| "
Four$(2) = "  | "
Five$(0) = " _  "
Five$(1) = "|_  "
Five$(2) = " _| "
Six$(0) = " _  "
Six$(1) = "|_  "
Six$(2) = "|_| "
Seven$(0) = "_  "
Seven$(1) = "  |"
Seven$(2) = "  |"
Eight$(0) = " _  "
Eight$(1) = "|_| "
Eight$(2) = "|_| "
Nine$(0) = " _  "
Nine$(1) = "|_| "
Nine$(2) = " _| "
INPUT "Enter a Number: ", Number$
NumLen = LEN(Number$)
FOR i = 1 to NumLen
Digit$ = MID$(Number$,i,1)
IF Digit$ = "0" THEN line1$ = line1$ + Zero$(0):line2$ = line2$ + Zero$(1):line3$ = line3$+Zero$(2)
IF Digit$ = "1" THEN line1$ = line1$ + One$(0):line2$ = line2$ + One$(1):line3$ = line3$+One$(2)
IF Digit$ = "2" THEN line1$ = line1$ + Two$(0):line2$ = line2$ + Two$(1):line3$ = line3$+Two$(2)
IF Digit$ = "3" THEN line1$ = line1$ + Three$(0):line2$ = line2$ + Three$(1):line3$ = line3$+Three$(2)
IF Digit$ = "4" THEN line1$ = line1$ + Four$(0):line2$ = line2$ + Four$(1):line3$ = line3$+Four$(2)
IF Digit$ = "5" THEN line1$ = line1$ + Five$(0):line2$ = line2$ + Five$(1):line3$ = line3$+Five$(2)
IF Digit$ = "6" THEN line1$ = line1$ + Six$(0):line2$ = line2$ + Six$(1):line3$ = line3$+Six$(2)
IF Digit$ = "7" THEN line1$ = line1$ + Seven$(0):line2$ = line2$ + Seven$(1):line3$ = line3$+Seven$(2)
IF Digit$ = "8" THEN line1$ = line1$ + Eight$(0):line2$ = line2$ + Eight$(1):line3$ = line3$+Eight$(2)
IF Digit$ = "9" THEN line1$ = line1$ + Nine$(0):line2$ = line2$ + Nine$(1):line3$ = line3$+Nine$(2)
NEXT i
PRINT line1$
PRINT line2$
PRINT line3$

The code might not be the most optimal...but what can you expect? It's basic...old basic -:P

Greetings,

Blag.
Development Culture.