loljs 1.1
Version of implementation loljs of programming language LOLCODEThe latest version of loljs interpreter.
Links:
Examples:
Hello, World! - LOLCODE (430):
HAI
CAN HAS STDIO?
VISIBLE "Hello, World!"
KTHXBYE
Factorial - LOLCODE (431):
This example uses iterative factorial definition.
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
Factorial - LOLCODE (432):
This example uses recursive factorial calculation.
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
Fibonacci numbers - LOLCODE (433):
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
Fibonacci numbers - LOLCODE (434):
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
Quadratic equation - LOLCODE (435):
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 (436):
Note that LOLCODE has no character processing functions, except for concatenation, so you can’t compare characters or get their ASCII-codes. This means that to figure out whether a character is a letter you need to create a “dictionary” of all letters and just look it up.
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
Comments
]]>blog comments powered by Disqus
]]>