Example Programs

Complete, working Ifá-Lang programs

FizzBuzz

fizzbuzz.ifa
// Classic FizzBuzz problem
ayanmo i = 1;

nigba (i <= 20) {
    ti (i % 15 == 0) {
        Irosu.fo("FizzBuzz");
    } bib?k? ti (i % 3 == 0) {
        Irosu.fo("Fizz");
    } bib?k? ti (i % 5 == 0) {
        Irosu.fo("Buzz");
    } bib?k? {
        Irosu.fo(i);
    }
    ayanmo i = i + 1;
}
// Classic FizzBuzz problem
let i = 1;

while (i <= 20) {
    if (i % 15 == 0) {
        Irosu.println("FizzBuzz");
    } else if (i % 3 == 0) {
        Irosu.println("Fizz");
    } else if (i % 5 == 0) {
        Irosu.println("Buzz");
    } else {
        Irosu.println(i);
    }
    let i = i + 1;
}

Fibonacci Sequence

fibonacci.ifa
// Generate first 15 Fibonacci numbers
ayanmo a = 0;
ayanmo b = 1;
ayanmo n = 15;

Irosu.fo("Fibonacci:");
ayanmo i = 0;

nigba (i < n) {
    Irosu.fo(a);
    ayanmo temp = a + b;
    ayanmo a = b;
    ayanmo b = temp;
    ayanmo i = i + 1;
}
// Generate first 15 Fibonacci numbers
let a = 0;
let b = 1;
let n = 15;

Irosu.println("Fibonacci:");
let i = 0;

while (i < n) {
    Irosu.println(a);
    let temp = a + b;
    let a = b;
    let b = temp;
    let i = i + 1;
}
Output:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377

Password Generator

password.ifa
// Generate secure random password using Irete
ayanmo bytes = Irete.random_bytes(16);
ayanmo id = Irete.uuid();

Irosu.fo("=== Password Generator ===");
Irosu.fo("Random key: " + bytes);
Irosu.fo("Session ID: " + id);

// Hash a password
ayanmo password = "mySecretPassword123";
ayanmo hash = Irete.sha256(password);
Irosu.fo("Password hash: " + hash);
// Generate secure random password using Irete
let bytes = Irete.random_bytes(16);
let id = Irete.uuid();

Irosu.println("=== Password Generator ===");
Irosu.println("Random key: " + bytes);
Irosu.println("Session ID: " + id);

// Hash a password
let password = "mySecretPassword123";
let hash = Irete.sha256(password);
Irosu.println("Password hash: " + hash);

Data Analysis

analysis.ifa
// Parallel data analysis using Osa
ayanmo data = [23, 45, 12, 67, 89, 34, 56, 78, 90, 11];

Irosu.fo("=== Data Analysis ===");
Irosu.fo("Data: " + data);
Irosu.fo("");

// Parallel operations
ayanmo apap? = Osa.sum(data);
ayanmo kekere = Osa.min(data);
ayanmo tobi = Osa.max(data);
ayanmo tito = Osa.sort(data);

Irosu.fo("Sum: " + apap?);
Irosu.fo("Min: " + kekere);
Irosu.fo("Max: " + tobi);
Irosu.fo("Sorted: " + tito);

// Average calculation
ayanmo iye = 10;
ayanmo aropin = apap? / iye;
Irosu.fo("Average: " + aropin);
// Parallel data analysis using Osa
let data = [23, 45, 12, 67, 89, 34, 56, 78, 90, 11];

Irosu.println("=== Data Analysis ===");
Irosu.println("Data: " + data);
Irosu.println("");

// Parallel operations
let total = Osa.sum(data);
let minimum = Osa.min(data);
let maximum = Osa.max(data);
let sorted = Osa.sort(data);

Irosu.println("Sum: " + total);
Irosu.println("Min: " + minimum);
Irosu.println("Max: " + maximum);
Irosu.println("Sorted: " + sorted);

// Average calculation
let count = 10;
let average = total / count;
Irosu.println("Average: " + average);

Guessing Game

guess.ifa
// Number guessing game
Irosu.fo("=== Ere Aros? N?mba ===");
Irosu.fo("Mo ti yan n?mba kan laarin 1 ati 10.");

ayanmo answer = 7;  // In real game, use Owonrin.pese(1, 10)
ayanmo tries = 0;
ayanmo won = iro;

nigba (won == iro) {
    ayanmo guess = Irosu.ka("Gbiyanju: ");
    ayanmo tries = tries + 1;
    
    ti (guess == answer) {
        Irosu.fo("O ??gun! O gba ni igba " + tries);
        ayanmo won = otito;
    } bib?k? ti (guess < answer) {
        Irosu.fo("Kéré jù, gbiyanju síi.");
    } bib?k? {
        Irosu.fo("Tóbi jù, gbiyanju síi.");
    }
}
// Number guessing game
Irosu.println("=== Number Guessing Game ===");
Irosu.println("I picked a number between 1 and 10.");

let answer = 7;  // In real game, use Owonrin.pese(1, 10)
let tries = 0;
let won = false;

while (won == false) {
    let guess = Irosu.input("Guess: ");
    let tries = tries + 1;
    
    if (guess == answer) {
        Irosu.println("You won! It took " + tries + " tries.");
        let won = true;
    } else if (guess < answer) {
        Irosu.println("Too low, try again.");
    } else {
        Irosu.println("Too high, try again.");
    }
}