loljs 1.1
Версия реализации loljs языка программирования LOLCODEПоследняя версия интерпретатора loljs.
Ссылки:
Примеры:
Hello, World! - LOLCODE (444):
HAI
CAN HAS STDIO?
VISIBLE "Hello, World!"
KTHXBYE
Факториал - LOLCODE (457):
Используется рекурсивное определение факториала.
HAI
HOW DUZ I FACTORIAL N
BOTH SAEM 0 AN N
O RLY?
YA RLY
FOUND YR 1
NO WAI
FOUND YR PRODUKT OF N AN FACTORIAL DIFF OF N AN 1
OIC
IF U SAY SO
I HAS A N ITZ 0
IM IN YR LOOP UPPIN YR N WILE N SMALLR THAN 17
VISIBLE SMOOSH N "! = " FACTORIAL N
IM OUTTA YR LOOP
KTHXBYE
Факториал - LOLCODE (458):
Используется итеративное определение факториала.
HAI
I HAS A N ITZ 0
I HAS A FACTORIAL ITZ 1
IM IN YR LOOP UPPIN YR N WILE N SMALLR THAN 17
VISIBLE SMOOSH N "! = " FACTORIAL
FACTORIAL R PRODUKT OF FACTORIAL AN SUM OF N AN 1
IM OUTTA YR LOOP
KTHXBYE
Числа Фибоначчи - LOLCODE (459):
Числа Фибоначчи вычисляются итеративно.
HAI
I HAS A I ITS 0
I HAS A FIB1 ITS 0
I HAS A FIB2 ITS 1
IM IN YR LOOP UPPIN YR I TIL BOTH SAEM I AN 16
VISIBLE SMOOSH FIB2 ", "!
I HAS A FIB3 ITS SUM OF FIB1 AN FIB2
FIB1 R FIB2
FIB2 R FIB3
IM OUTTA YR LOOP
VISIBLE "..."
KTHXBYE
Числа Фибоначчи - LOLCODE (460):
Числа Фибоначчи вычисляются рекурсивно.
HAI
HOW DUZ I FIBONACCI N
BOTH SAEM 1 AN BIGGR OF N AN 1, O RLY?
YA RLY
FOUND YR 1
NO WAI
FOUND YR SUM OF FIBONACCI DIFF OF N AN 1 AN FIBONACCI DIFF OF N AN 2
OIC
IF U SAY SO
I HAS A N ITZ 0
IM IN YR LOOP UPPIN YR N WILE N SMALLR THAN 16
VISIBLE SMOOSH FIBONACCI N ", "!
IM OUTTA YR LOOP
VISIBLE "..."
KTHXBYE
Квадратное уравнение - LOLCODE (461):
HAI
HOW DUZ I SQRT X
I HAS A X_N ITZ 10
I HAS A LIMIT ITZ 100
I HAS A COUNTER ITZ 0
IM IN YR LOOP UPPIN YR COUNTER WILE COUNTER SMALLR THAN LIMIT
I HAS A TERM ITZ QUOSHUNT OF X AN X_N
TERM R SUM OF X_N AN TERM
TERM R QUOSHUNT OF TERM AN 2
X_N R TERM
IM OUTTA YR LOOP
FOUND YR X_N
IF U SAY SO
I HAS A AC
GIMMEH AC
AC IS NOW A NUMBR
BOTH SAEM AC AN 0, O RLY?
YA RLY
VISIBLE "Not a quadratic equation."
NO WAI
I HAS A BC
GIMMEH BC
BC IS NOW A NUMBR
I HAS A CC
GIMMEH CC
CC IS NOW A NUMBR
I HAS A D ITZ DIFF OF PRODUKT OF BC AN BC AN PRODUKT OF 4 AN PRODUKT OF AC AN CC
BOTH SAEM D AN 0, O RLY?
YA RLY
VISIBLE SMOOSH "x = " QUOSHUNT OF BC AN PRODUKT OF -2 AN AC
NO WAI
BOTH SAEM 0 AN SMALLR OF 0 AN D, O RLY?
YA RLY
VISIBLE SMOOSH "x1 = " QUOSHUNT OF SUM OF BC AN SQRT D AN PRODUKT OF -2 AN AC
VISIBLE SMOOSH "x2 = " QUOSHUNT OF DIFF OF BC AN SQRT D AN PRODUKT OF -2 AN AC
NO WAI
D R PRODUKT OF D AN -1
VISIBLE SMOOSH "x1 = (" QUOSHUNT OF BC AN PRODUKT OF -2 AN AC ", " QUOSHUNT OF SQRT D AN PRODUKT OF -2 AN AC ")"
VISIBLE SMOOSH "x2 = (" QUOSHUNT OF BC AN PRODUKT OF -2 AN AC ", " QUOSHUNT OF SQRT D AN PRODUKT OF 2 AN AC ")"
OIC
OIC
OIC
KTHXBYE
CamelCase - LOLCODE (462):
Отметим, что в LOLCODE нет функций работы со строками и символами, кроме конкатенации — например, символы нельзя сравнивать BIGGR OF
или SMALLR OF
или получить их ASCII-коды. Поэтому для определения того, является ли символ буквой, и перевода его в другой регистр приходится создавать “словари” букв и искать в них нужную перебором.
HAI
I HAS A UPP ITZ "QWERTYUIOPASDFGHJKLZXCVBNM"
I HAS A LOW ITZ "qwertyuiopasdfghjklzxcvbnm"
HOW DUZ I LOWER CHAR
I HAS A I ITZ 0
IM IN YR LOOP UPPIN YR I TIL BOTH SAEM I AN LEN OF UPP
BOTH SAEM UPP!I AN CHAR, O RLY?
YA RLY
FOUND YR LOW!I
OIC
IM OUTTA YR LOOP
FOUND YR CHAR
IF U SAY SO
HOW DUZ I UPPER CHAR
I HAS A I ITZ 0
IM IN YR LOOP UPPIN YR I TIL BOTH SAEM I AN LEN OF UPP
BOTH SAEM LOW!I AN CHAR, O RLY?
YA RLY
FOUND YR UPP!I
OIC
IM OUTTA YR LOOP
FOUND YR CHAR
IF U SAY SO
HOW DUZ I ISLOWER CHAR
I HAS A I ITZ 0
IM IN YR LOOP UPPIN YR I TIL BOTH SAEM I AN LEN OF UPP
BOTH SAEM LOW!I AN CHAR, O RLY?
YA RLY
FOUND YR WIN
OIC
IM OUTTA YR LOOP
FOUND YR FAIL
IF U SAY SO
I HAS A TEXT
GIMMEH TEXT
I HAS A CAMELCASE ITZ ""
I HAS A I ITZ 0
I HAS A SPACE ITZ WIN
IM IN YR LOOP UPPIN YR I TIL BOTH SAEM I AN LEN OF TEXT
I HAS A CHAR ITZ LOWER TEXT!I
ISLOWER CHAR, O RLY?
YA RLY
BTW this is a letter (already lowercase), modify depending on SPACE
SPACE, O RLY?
YA RLY
CHAR R UPPER CHAR
OIC
CAMELCASE R SMOOSH CAMELCASE CHAR
SPACE R FAIL
NO WAI
BTW this is space - mark it
SPACE R WIN
OIC
IM OUTTA YR LOOP
VISIBLE CAMELCASE
KTHXBYE
Комментарии
]]>blog comments powered by Disqus
]]>