News for hackers. Stuff that matters.
Re:Number systems of the world, sorted by complexity of coun... by tekkk on Thursday March 22, 2018 @11:22AM (#16649383)
Wow, Tongan number system is simply beautiful. Pure elegance that I'm sure could be defined mathematically very simply. I myself can only scribble a naive implementation for natural numbers in Javascript:

  const base = ["noa", "taha", "ua", "tolu", "fa", "nima", "ono", "fitu", "valu", "hiva"]
  const tongan = n => Array.from(n.toString()).map(Number).map(i => base[i]).join(" ")
Not as pretty as I thought. Probably would look better in functional language.
Re:Number systems of the world, sorted by complexity of coun... by kccqzy on Thursday March 22, 2018 @08:30PM (#16654034)
English numbers aren't much harder.

    englishNumbers n = ten9 !! (n - 1)
      where infixr 7 <<>>
            (<<>>) = liftA2 (<>)
            ten1 = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
            ten2 = ten1 <> ["ten", "eleven", "twelve"] <> (["thir", "four"] <> prefixes) <<>> ["teen"] <> (["twen", "thir", "for"] <> prefixes) <<>> ["ty"] <<>> ([[]] <> ten1)
              where prefixes = ["fif", "six", "seven", "eigh", "nine"]
            ten3 = ten2 <> ten1 <<>> ["hundred"] <<>> ([[]] <> ten2)
            ten6 = ten3 <> ten3 <<>> ["thousand"] <<>> ([[]] <> ten3)
            ten9 = ten6 <> ten3 <<>> ["million"] <<>> ([[]] <> ten6)
Re:Number systems of the world, sorted by complexity of coun... by FullyFunctional on Thursday March 22, 2018 @01:05PM (#16650519)
I theorize that humans do poorly with too much regularity and we actually benefit from irregularity, unlike computers.

In Haskell, first line would be the same without the const and the other could be

tongan = intercalate " ".reverse.map ((base !!).(`mod` 10)).takeWhile (> 0).iterate (`div` 10)

(ISTM that there must be a better alternative to takeWhile + iterate).

Re:Number systems of the world, sorted by complexity of coun... by kjaer on Thursday March 22, 2018 @06:49PM (#16653454)
I wrote it in Scala below; it's a bit shorter, and I really like the map(base). Getting the digits from a number turns out to be most of the work, and the int->string->int conversion also seems to be the best approach.

  val base = List("noa", "taha", "ua", "tolu", "fa", "nima", "ono", "fitu", "valu", "hiva")
  def tongan(n: Int) = n.toString.map(_.asDigit).map(base).mkString(" ")