jueves, 1 de diciembre de 2016

LED is my new Hello World - Swift (for Linux) time

It took me some time to write this post...mainly because I'm now learning Rust and also because I just finished my latest demo...whose blog is coming later today -;)

This version of my LED Numbers app becomes the 25th language version...so...obviously...it's a pretty nice milestone for me -:D Who knows? Maybe I will do something nice if I can ever reach 50 languages -:D

Anyway...like I love to say..."Enough talk...show me the source code" -;)

LedNumbers.swift
let leds: [Character:String] = [
 "0" : " _  ,| | ,|_| ",
 "1" : "  ,| ,| ",
 "2" : " _  , _| ,|_  ",
 "3" : "_  ,_| ,_| ",
 "4" : "    ,|_| ,  | ",
 "5" : " _  ,|_  , _| ",
 "6" : " _  ,|_  ,|_| ",
 "7" : "_   , |  , |  ",
 "8" : " _  ,|_| ,|_| ",
 "9" : " _  ,|_| , _| "
];

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

var line = [String]();
var led = "";

for i in 0...2{
 for character in num!.characters{
  line = String(leds[character]!)!.
                       characters.split(separator: ",").map(String.init);
  print(line[i], terminator:"");
 }
 print("");
}

And here's the picture of it working its magic -:)


Greetings,

Blag.
Development Culture.

No hay comentarios: