--- /dev/null
+# Rosetta Code
+
+This are Nit programs that solve some tasks from the [Rosetta Code] project.
+
+ [Rosetta Code]: http://rosettacode.org/
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: A+B
+# SEE: <http://rosettacode.org/wiki/A%2BB>
+#
+# Generic non-robust version.
+module ab
+
+var words = gets.split(" ")
+print words[0].to_i + words[1].to_i
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: abstract type
+# SEE: <http://rosettacode.org/wiki/Abstract_type>
+#
+# Methods withouts implementation are annotated `abstract`.
+#
+# Abstract classes and interfaces can contain abstract methods and concrete (i.e. non-abstract) methods.
+# Abstract classes can also have attributes.
+module abstract_type
+
+interface Inter
+ fun method1: Int is abstract
+ fun method2: Int do return 1
+end
+
+abstract class Abs
+ fun method1: Int is abstract
+ fun method2: Int do return 1
+ var attr: Int
+end
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# The `accumulator factory` task.
+# SEE: <http://rosettacode.org/wiki/Accumulator_factory>
+#
+# Nit has no first-class function.
+# A class is used to store the state.
+module accumulator_factory
+
+class Accumulator
+ # The accumulated sum
+ # Numeric is used, so Int and Float are accepted
+ private var sum: Numeric
+ fun call(n: Numeric): Numeric
+ do
+ # `add` is the safe `+` method on Numeric
+ sum = sum.add(n)
+ return sum
+ end
+end
+
+var x = new Accumulator(1)
+x.call(5)
+var y = new Accumulator(3)
+print x.call(2.3)
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Ackermann function
+# SEE: <http://rosettacode.org/wiki/Ackermann_function>
+#
+# A simple straightforward recursive implementation.
+module ackermann_function
+
+fun ack(m, n: Int): Int
+do
+ if m == 0 then return n + 1
+ if n == 0 then return ack(m-1,1)
+ return ack(m-1, ack(m, n-1))
+end
+
+for m in [0..3] do
+ for n in [0..6] do
+ print ack(m,n)
+ end
+ print ""
+end
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Align columns
+# SEE: <http://rosettacode.org/wiki/Align_columns>
+#
+# Use `Text::justify` for the standard library.
+module align_columns
+
+fun aligner(text: String, left: Float)
+do
+ # Each row is a sequence of fields
+ var rows = new Array[Array[String]]
+ var max = 0
+ for line in text.split('\n') do
+ rows.add line.split("$")
+ end
+
+ # Compute the final length of each column
+ var lengths = new Array[Int]
+ for fields in rows do
+ var i = 0
+ for field in fields do
+ var fl = field.length
+ if lengths.length <= i or fl > lengths[i] then
+ lengths[i] = fl
+ end
+ i += 1
+ end
+ end
+
+ # Process each line and align each field
+ for fields in rows do
+ var line = new Array[String]
+ var i = 0
+ for field in fields do
+ line.add field.justify(lengths[i], left)
+ i += 1
+ end
+ print line.join(" ")
+ end
+end
+
+var text = """
+Given$a$text$file$of$many$lines,$where$fields$within$a$line$
+are$delineated$by$a$single$'dollar'$character,$write$a$program
+that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$
+column$are$separated$by$at$least$one$space.
+Further,$allow$for$each$word$in$a$column$to$be$either$left$
+justified,$right$justified,$or$center$justified$within$its$column."""
+
+aligner(text, 0.0)
+aligner(text, 1.0)
+aligner(text, 0.5)
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Array concatenation
+# SEE: <http://rosettacode.org/wiki/Array_concatenation>
+module array_concatenation
+
+var arr1 = [1, 2, 3]
+var arr2 = [4, 5, 6]
+var arr3 = [7, 8, 9]
+var arr5 = [2, 1, 0]
+var arr4 = arr1 + arr2
+arr4.append arr3
+arr4.prepend arr5
+print arr4 # => 210123456789
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Arrays
+# SEE: <http://rosettacode.org/wiki/Arrays>
+module arrays
+
+# Creation of an array with a single element
+var a = [1]
+
+# Add objects
+a.add 2
+a.add_all([3, 4, 5])
+
+# Set values at a specific index
+a[0] = 100
+
+# Get a specific elements
+print a[0]
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Assertions
+# SEE: <http://rosettacode.org/wiki/Assertions>
+module assertions
+
+var n = 5
+assert n == 42
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: 100 doors
+# SEE: <http://rosettacode.org/wiki/100_doors>
+#
+# Generic unoptimized version.
+module doors
+
+var n = 100
+var doors = new Array[Bool].filled_with(false, n)
+for i in [0..n[ do
+ var j = i
+ while j < n do
+ doors[j] = not doors[j]
+ j += i+1
+ end
+end
+for i in [0..n[ do
+ var s
+ if doors[i] then s = "open" else s = "closed"
+ print "Door {i} is {s}."
+end
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Reverse a string
+# SEE: <http://rosettacode.org/wiki/Reverse_a_string>
+#
+# Unicode is not yet preserved :(
+print "asdf".reversed
+
+# does not work yet :(
+#print "as⃝df̅".reversed
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Reverse words in a string
+# SEE: <http://rosettacode.org/wiki/Reverse_words_in_a_string>
+module reverse_words
+var text = """
+---------- Ice and Fire ------------
+
+fire, in end will world the say Some
+ice. in say Some
+desire of tasted I've what From
+fire. favor who those with hold I
+
+... elided paragraph last ...
+
+Frost Robert -----------------------"""
+
+for l in text.split("\n") do print l.split(" ").reversed.join(" ")
--- /dev/null
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Unix/ls
+# SEE: <http://rosettacode.org/wiki/Unix/ls>
+for f in ".".files do print f
--- /dev/null
+Runtime error: Assert 'index' failed (../lib/standard/collection/array.nit:258)
--- /dev/null
+1
+2
+3
+4
+5
+6
+7
+
+2
+3
+4
+5
+6
+7
+8
+
+3
+5
+7
+9
+11
+13
+15
+
+5
+13
+29
+61
+125
+253
+509
+
--- /dev/null
+Given a text file of many lines, where fields within a line
+are delineated by a single 'dollar' character, write a program
+that aligns each column of fields by ensuring that words in each
+column are separated by at least one space.
+Further, allow for each word in a column to be either left
+justified, right justified, or center justified within its column.
+ Given a text file of many lines, where fields within a line
+ are delineated by a single 'dollar' character, write a program
+ that aligns each column of fields by ensuring that words in each
+ column are separated by at least one space.
+ Further, allow for each word in a column to be either left
+justified, right justified, or center justified within its column.
+ Given a text file of many lines, where fields within a line
+ are delineated by a single 'dollar' character, write a program
+ that aligns each column of fields by ensuring that words in each
+ column are separated by at least one space.
+ Further, allow for each word in a column to be either left
+justified, right justified, or center justified within its column.
--- /dev/null
+210123456789
--- /dev/null
+Runtime error: Assert failed (../examples/rosettacode/assertions.nit:11)
--- /dev/null
+Door 0 is open.
+Door 1 is closed.
+Door 2 is closed.
+Door 3 is open.
+Door 4 is closed.
+Door 5 is closed.
+Door 6 is closed.
+Door 7 is closed.
+Door 8 is open.
+Door 9 is closed.
+Door 10 is closed.
+Door 11 is closed.
+Door 12 is closed.
+Door 13 is closed.
+Door 14 is closed.
+Door 15 is open.
+Door 16 is closed.
+Door 17 is closed.
+Door 18 is closed.
+Door 19 is closed.
+Door 20 is closed.
+Door 21 is closed.
+Door 22 is closed.
+Door 23 is closed.
+Door 24 is open.
+Door 25 is closed.
+Door 26 is closed.
+Door 27 is closed.
+Door 28 is closed.
+Door 29 is closed.
+Door 30 is closed.
+Door 31 is closed.
+Door 32 is closed.
+Door 33 is closed.
+Door 34 is closed.
+Door 35 is open.
+Door 36 is closed.
+Door 37 is closed.
+Door 38 is closed.
+Door 39 is closed.
+Door 40 is closed.
+Door 41 is closed.
+Door 42 is closed.
+Door 43 is closed.
+Door 44 is closed.
+Door 45 is closed.
+Door 46 is closed.
+Door 47 is closed.
+Door 48 is open.
+Door 49 is closed.
+Door 50 is closed.
+Door 51 is closed.
+Door 52 is closed.
+Door 53 is closed.
+Door 54 is closed.
+Door 55 is closed.
+Door 56 is closed.
+Door 57 is closed.
+Door 58 is closed.
+Door 59 is closed.
+Door 60 is closed.
+Door 61 is closed.
+Door 62 is closed.
+Door 63 is open.
+Door 64 is closed.
+Door 65 is closed.
+Door 66 is closed.
+Door 67 is closed.
+Door 68 is closed.
+Door 69 is closed.
+Door 70 is closed.
+Door 71 is closed.
+Door 72 is closed.
+Door 73 is closed.
+Door 74 is closed.
+Door 75 is closed.
+Door 76 is closed.
+Door 77 is closed.
+Door 78 is closed.
+Door 79 is closed.
+Door 80 is open.
+Door 81 is closed.
+Door 82 is closed.
+Door 83 is closed.
+Door 84 is closed.
+Door 85 is closed.
+Door 86 is closed.
+Door 87 is closed.
+Door 88 is closed.
+Door 89 is closed.
+Door 90 is closed.
+Door 91 is closed.
+Door 92 is closed.
+Door 93 is closed.
+Door 94 is closed.
+Door 95 is closed.
+Door 96 is closed.
+Door 97 is closed.
+Door 98 is closed.
+Door 99 is open.
--- /dev/null
+------------ Fire and Ice ----------
+
+Some say the world will end in fire,
+Some say in ice.
+From what I've tasted of desire
+I hold with those who favor fire.
+
+... last paragraph elided ...
+
+----------------------- Robert Frost