Commits

Laurens Rodriguez  committed 03cf827

Added 99bottless to test

  • Participants
  • Parent commits f628294
  • Branches default

Comments (0)

Files changed (1)

File bin/windows/test.kia

 
-
+//----------------------------------------------------------------------------------------
 var x, y = "private x", "private y"
 public var x = ["asdasdad"]
 global.x.gg = "gg"
 print(global.x.gg, global.y)
 print(x, y)
 
+//----------------------------------------------------------------------------------------
 var q = {}
 public var q = {}
 function q.f() {
 global.q.f()
 q.f()
 
+//----------------------------------------------------------------------------------------
 var t = [100,200,300]
 for each (var k = 0 to 2) {
     print(k ..") "..t[k])
     print(i .."] "..tostring(q[i]))
 }
 
+//----------------------------------------------------------------------------------------
 var A = {tt: {x: 20}}
 function A::ax(yy) {
     ////this.tt.x += yy
 A::ax(10)
 print(A.tt.x)
 
-
+//----------------------------------------------------------------------------------------
 function fibonacci(n) {
     if (n <= 1) {
         return 1
 }
 print(fibonacci(10))
 
+//----------------------------------------------------------------------------------------
 function fact(n, ans) {
     call:
     if (n == 0) {
 }
 print(fact(5, 1))
 
+//----------------------------------------------------------------------------------------
 for each (var z = 1 to 10) {
     for each (var y = 1 to 10) {
         for each (var x = 1 to 10) {
     zcontinue:
 }
 
+//----------------------------------------------------------------------------------------
 for each (var i = 2 to 9) {
     var s = i .. ") "
     for (var j,p = 1,1; p < 1_000_000; p *= i) {
     print(s)
 }
 
-//*
+//----------------------------------------------------------------------------------------
 function list_iterator(t) {
     var i = -1
     var n = $t
     print(element)
 }
 
+//----------------------------------------------------------------------------------------
 dofile('to_string.kia');
 dofile('decrypt.kia');
 
 }
 print(table.concat(primes(100),","))
 
+//----------------------------------------------------------------------------------------
 function printPowers(base, count) {
     for (var k = 0; k < count; k += 1) {
         print(base.."^"..k.." = "..(base ** k))
 }
 printPowers(2, 10)
 
+//----------------------------------------------------------------------------------------
 function fizzbuzz(min, max) {
     var i = min
     do {
 }
 fizzbuzz(5, 15)
 
+//----------------------------------------------------------------------------------------
 function fibonacci(n) {
     if (n < 3) {
         return n - 1
     n += 1
 } while (n <= 20)
 
-//print($"0123456789")
-//print(${1,2,3,4,5,6})
-//print(${key:1,2,3,4,5})
+//----------------------------------------------------------------------------------------
+assert($"0123456789" == 10)
+assert($[1,2,3,4,5,6] == 6)
+assert(${key:1} == 0)
 
+//----------------------------------------------------------------------------------------
 public var x = 10     // global variable
 {                     // new block
     var x = global.x  // new 'x', with value 10
 }
 print(global.x)       // 10  (the global one)
 
-
+//----------------------------------------------------------------------------------------
 var closures = []
 var cx = 20
 for (var i = 0; i < 10; i += 1) {
 print("closures[0](): "..closures[0]())
 print("closures[1](): "..closures[1]())
 
-
+//----------------------------------------------------------------------------------------
 function trueExpr() { 
     print("trueExpr")
     return 10
 var x = (y < 6)? "less than 6" : (y % 2 == 0)? "even" : "odd"
 print(x) // Output: even
 
-
+//----------------------------------------------------------------------------------------
 var s1 = 'testing '
 s1 ..= "concatenation"
 print(s1) // prints: "testing concatenation"
 
+////var mixed = {1, 3, name: "foo", ['new']: 234}  // mixed table constructor disallowed
 
-////var mixed = {1, 3, name: "foo", ['new']: 234}  // mixed table constructor disallowed
-////print(to_string(mixed))
-
-
+//----------------------------------------------------------------------------------------
 function getAverage(array) {
     var sum = 0
     var length = $array
 print(getAverage([10, 20, 40, 50])) 
 print(getAverage([]))
 
+//----------------------------------------------------------------------------------------
+// 99 Bottles of beer: http://99-bottles-of-beer.net/lyrics.html
+function songOfBeers(beers) {
+    
+    function bottlesOfBeer(i)    { return i .. ' bottles of beer' }
+    function bottlesOnTheWall(i) { return bottlesOfBeer(i) .. ' on the wall' }
+    function takeOneDown()       { return '\nTake one down and pass it around, ' }
 
-//*/
+    function createVerse(i) {
+        return function() {
+            return bottlesOnTheWall(i) .. ', ' .. bottlesOfBeer(i) .. '.'
+                   .. takeOneDown() .. bottlesOnTheWall(i - 1) .. '.\n'
+        }
+    }
+
+    // Create the closures that will sing the song.
+    var verses = []
+    for (var i = beers; i >= 0; i -= 1) {
+        if (i >= 2) {
+            table.insert(verses, createVerse(i));
+        }
+        else if (i == 1) {
+            table.insert(verses, function() {
+                return '1 bottle of beer on the wall, 1 bottle of beer.'
+                        .. takeOneDown() .. bottlesOnTheWall('no more') .. '.\n'
+            })
+        }
+        else {
+            table.insert(verses, function() {
+                return bottlesOnTheWall('No more') .. ', ' .. bottlesOfBeer('no more') 
+                       .. '.\nGo to the store and buy some more, ' 
+                       .. bottlesOnTheWall(99) .. '.\n'
+            })
+        }
+    }
+    return verses
+}
+
+for each (var k, verse in ipairs(songOfBeers(4))) { // must go with 99!
+    print(verse())
+}
+
+//*///------------------------------------------------------------------------------------