Table of Contents

About

The API is compatible with the LOLCODE Specification 1.2. The functions have to be used between the opening and closing program blocks. For example:

HAI 1.2

[... insert function ...]

  I HAS A VAR ITZ 4
  VISIBLE SMOOSH "Factorial: " AN I IZ WAS_FAK YR VAR MKAY
  
KTHXBYE

will print out the factorial of 4 provided that the WAS_FAK function is inserted into the placeholder (this is because functions in LOLCODE cannot live outside of the HAI/KTHXBYE code-blocks.

Numerical Inequalities

A set of functions that perform various numerical inequalities following LaTeX syntax: LT ($<$), LE ($\le$), GT ($>$) and GE ($\ge$).

Less Than

OBTW  Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3  TLDR
HOW IZ I LT YR LEFT AN YR RIGHT
    FOUND YR DIFFRINT LEFT AN BIGGR OF LEFT AN RIGHT
IF U SAY SO

Greater Than

OBTW  Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3  TLDR
HOW IZ I GT YR LEFT AN YR RIGHT
    FOUND YR DIFFRINT LEFT AN SMALLR OF LEFT AN RIGHT
IF U SAY SO

Less or Equal Than

OBTW  Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3  TLDR
HOW IZ I LE YR LEFT AN YR RIGHT
    BOTH SAEM LEFT AN SMALLR OF LEFT AN RIGHT
IF U SAY SO

Greater or Equal Than

OBTW  Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3  TLDR
HOW IZ I GE YR LEFT AN YR RIGHT
    FOUND YR BOTH SAEM LEFT AN BIGGR OF LEFT AN RIGHT
IF U SAY SO

Raise Base to Exponent

OBTW  Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3  TLDR
HOW IZ I WAS_RAIZ YR FOOT AN YR PAW
  I HAS A BASE ITZ FOOT
  IM IN YR LOOP UPPIN YR STUFF WILE DIFFRINT STUFF AN PAW
    FOOT R PRODUKT OF FOOT AN BASE
  IM OUTTA YR LOOP
  FOUND YR QUOSHUNT OF FOOT AN BASE
IF U SAY SO

Factorial

OBTW  Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3  TLDR
HOW IZ I WAS_FAK YR TAIL
    TAIL, WTF?
        OMG 0
          FOUND YR 1
        OMG 1
          FOUND YR TAIL
    OIC
    FOUND YR PRODUKT OF TAIL AN I IZ WAS_FAK YR DIFF OF TAIL AN 1 MKAY 
IF U SAY SO

Random Number Generator

This is a Lehmer random number generator,

$$
X_{k+1} = g*X_{k} \mod{n}
$$

using the ZX Spectrum Fermat prime vectors where $g=75$ and $n=65537$.

OBTW  Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3  TLDR
I HAS A COUNTER ITZ 1
HOW IZ I WAS_MESS YR NUMBER
    I HAS A THING ITZ MAEK NUMBER A NUMBAR
    IM IN YR LOOP UPPIN YR ROUNDS WILE DIFFRINT ROUNDS AN NUMBER
        THING R MOD OF PRODUKT OF 75 AN SUM OF THING AN COUNTER AN 65537
        COUNTER R SUM OF COUNTER AN 1
    IM OUTTA YR LOOP
    FOUND YR MOD OF THING AN NUMBER
IF U SAY SO

The algorithm will generate numbers in the interval $[0,65537)$ (larger if a different Fermat prime is chosen for $g$). The function takes a parameter an upper bound NUMBER and can be called using:

VISIBLE I IZ WAS_MESS YR 100 MKAY

which will generate a random number in the interval $[0, 100)$.

The following plot:

is the result of by drawing $10^3$ numbers in the interval $[0, 100)$ using:

IM IN YR LOOP UPPIN YR DRAWS WILE DIFFRINT DRAWS AN 1000
    VISIBLE I IZ WAS_MESS YR 100 MKAY
IM OUTTA YR LOOP

Fibonacci Number Generator

The WAS_FIB function prints out the first ROUNDS number of Fibonacci numbers starting with the initialisation vectors (either 0 and 1 or 1 and 1) passed to the function as FIRST and SECOND.

OBTW  Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3  TLDR
HOW IZ I WAS_FIB YR ROUNDS AN YR FIRST AN YR SECOND
    DIFFRINT ROUNDS AN SMALLR OF ROUNDS AN 0, O RLY?
        YA RLY,
            VISIBLE FIRST
            FOUND YR I IZ WAS_FIB YR DIFF OF ROUNDS AN 1 AN YR SECOND AN YR SUM OF FIRST AN SECOND MKAY
        NO WAI,
            GTFO
    OIC
IF U SAY SO

An example call is:

I HAS A ROUNDS ITZ 10
I HAS A FIRST ITZ 0
I HAS A SECOND ITZ 1
I IZ WAS_FIB YR ROUNDS AN YR FIRST AN YR SECOND MKAY

which prints out:

0
1
1
2
3
5
8
13
21
34

Note that the edge-cases where the function is passed a ROUNDS number smaller than the initialisation vector are respected by WAS_FIB.