Add factorial and fibonacci examples

This commit is contained in:
2026-03-29 16:28:36 +03:00
parent 7254c1d1fd
commit a944cf3186
3 changed files with 71 additions and 2 deletions
+30
View File
@@ -0,0 +1,30 @@
# Kertoma — Factorial in Tampio
#
# Methods are defined as: "[param in genitive] [method name] on [expression]"
# The parameter "pieni luku" (small number) appears in genitive: "pienen luvun"
#
# "riippuen siitä, onko ... joko ... tai ..." = ternary expression
# "pienempi tai yhtä suuri kuin yksi" = "less than or equal to one"
# "kerrottuna ... kertomalla" = "multiplied by [factorial]"
# Multiplication uses adessive case: "kertomalla" = "by the factorial"
Pienen luvun kertoma on
riippuen siitä, onko se pienempi tai yhtä suuri kuin yksi,
joko yksi
tai pieni luku kerrottuna pienen luvun edeltäjän kertomalla.
# "edeltäjä" = "predecessor" — defines n-1 as a helper method
Luvun edeltäjä on se vähennettynä yhdellä.
# "Olkoon X uusi muuttuja, jonka arvo on Y" = declare variable X with value Y
Olkoon pieni muuttuja uusi muuttuja, jonka arvo on nolla.
# Page-load event: prompt for a number, display its factorial
# "luetaan luku" = "a number is read" (browser prompt)
# "näyttää ... kertoman" = "shows the factorial of..." (genitive: kertoman)
Kun nykyinen sivu avautuu,
pieneen muuttujaan luetaan luku
ja nykyinen sivu näyttää pienen muuttujan arvon kertoman.