Mostrando entradas con la etiqueta Kotlin. Mostrar todas las entradas
Mostrando entradas con la etiqueta Kotlin. Mostrar todas las entradas

martes, 10 de noviembre de 2015

LED is my new Hello World - Kotlin Time

Yep...I'm aware that there must be a lot of more efficient and short ways to do this...but then again...my purpose with this is to have the same base code for all the programming languages that I learn...

Usually I write this code after a couple of days of learning the language...so in no way I can be aware of all the crazy and optimized features...

This code is just for fun and for me...a really good way to introduce the syntax of a language in a very friendly way...

So...here's is Kotlin -:)

LEDNumbers.kt
package LEDNumbers

fun main(args: Array<String>) {
 if (args.size == 0) {
      println("Please provide a number...")
      return
    }
    val NumList:List<String> = args[0].split("")
 val Leds = mapOf("0" to listOf(" _  ", "| | ", "|_| "), 
                  "1" to listOf("  ", "| ", "| "),
                  "2" to listOf(" _  "," _| ","|_  "),
                  "3" to listOf("_  ","_| ","_| "),
                  "4" to listOf("    ","|_| ","  | "),
                  "5" to listOf(" _  ","|_  "," _| "),
                  "6" to listOf(" _  ","|_  ","|_| "),
                  "7" to listOf("_   "," |  "," |  "),
                  "8" to listOf(" _  ","|_| ","|_| "),
                  "9" to listOf(" _  ","|_| "," _| "))
 for(i in 0..2){
  for(j in 1..NumList.size - 2){
   print(Leds[NumList[j]]!![i])
  }
  print("\n")
 }                 
}

The result will like this -;)


Greetings,

Blag.
Development Culture.

My first post on Kotlin

As always...I was looking for another programming language to learn...I was thinking about Scala or Rust...but then I got this comment on Twitter -;)


So sure...why not Kotlin? -:)

So what's Kotlin all about? Well...Kotlin is a Statically typed programming language for the JVM, Android and the browser. It's also 100% interoperable with Java.

While this is not a mind bending language...meaning that you can get used to it pretty fast...it has some nice and cool feature that are worthy to explore...

As always...being this my first post...here's the Fibonacci list example...

fibonacci.kt
package Fibonacci

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

fun main(args: Array<String>) {
 if (args.size == 0) {
      println("Please provide a number...")
      return
    }
   val num: Int = args[0].toInt()
   println(fib(num,0,1))
}

And the screenshot for sure -:)


Will post the LED_Numbers app really soon...so stay tuned -;)

Greetings,

Blag.
Development Culture.