Games, simulations, and randomized operations.
// games.ifa - Dice rolling and card shuffling
ise roll_dice(count, sides) {
ayanmo results = [];
ayanmo i = 0;
nigba (i < count) {
ayanmo roll = Owonrin.pese(1, sides);
ayanmo results = Ogunda.push(results, roll);
ayanmo i = i + 1;
}
padap? results;
}
ise create_deck() {
ayanmo suits = ["?", "?", "?", "?"];
ayanmo values = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
ayanmo deck = [];
fun suit ninu suits {
fun value ninu values {
ayanmo deck = Ogunda.push(deck, value + suit);
}
}
padap? deck;
}
ise shuffle_deck(deck) {
padap? Owonrin.ru(deck);
}
ise deal_cards(deck, count) {
ayanmo hand = Ogunda.slice(deck, 0, count);
ayanmo remaining = Ogunda.slice(deck, count, Ogunda.len(deck));
padap? {"hand": hand, "deck": remaining};
}
// Dice game
Irosu.fo("?? Rolling 3d6: ");
ayanmo rolls = roll_dice(3, 6);
Irosu.fo(rolls);
Irosu.fo("Total: " + Osa.sum(rolls));
// Card game
Irosu.fo("\n?? Dealing poker hands:");
ayanmo deck = shuffle_deck(create_deck());
ayanmo p1 = deal_cards(deck, 5);
ayanmo deck = p1["deck"];
Irosu.fo("Player 1: " + Ika.join(p1["hand"], " "));
ayanmo p2 = deal_cards(deck, 5);
Irosu.fo("Player 2: " + Ika.join(p2["hand"], " "));
// password_gen.ifa - Secure random passwords
ayanmo LOWERCASE = "abcdefghijklmnopqrstuvwxyz";
ayanmo UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ayanmo DIGITS = "0123456789";
ayanmo SYMBOLS = "!@#$%^&*()_+-=[]{}|;:,.<>?";
ise generate_password(length, options) {
ayanmo charset = "";
ti (options["lowercase"] != iro) {
ayanmo charset = charset + LOWERCASE;
}
ti (options["uppercase"] != iro) {
ayanmo charset = charset + UPPERCASE;
}
ti (options["digits"] != iro) {
ayanmo charset = charset + DIGITS;
}
ti (options["symbols"] == otito) {
ayanmo charset = charset + SYMBOLS;
}
ayanmo password = "";
ayanmo i = 0;
nigba (i < length) {
ayanmo idx = Owonrin.pese(0, Ika.len(charset) - 1);
ayanmo char = Ika.char_at(charset, idx);
ayanmo password = password + char;
ayanmo i = i + 1;
}
padap? password;
}
ise check_strength(password) {
ayanmo score = 0;
ti (Ika.len(password) >= 12) { ayanmo score = score + 2; }
bib?k? ti (Ika.len(password) >= 8) { ayanmo score = score + 1; }
ti (Ika.matches(password, "[a-z]")) { ayanmo score = score + 1; }
ti (Ika.matches(password, "[A-Z]")) { ayanmo score = score + 1; }
ti (Ika.matches(password, "[0-9]")) { ayanmo score = score + 1; }
ti (Ika.matches(password, "[!@#$%^&*]")) { ayanmo score = score + 2; }
ti (score >= 6) { padap? "Strong"; }
ti (score >= 4) { padap? "Medium"; }
padap? "Weak";
}
// Usage
Irosu.fo("?? Password Generator");
Irosu.fo("---------------------");
ayanmo options = {"lowercase": otito, "uppercase": otito, "digits": otito, "symbols": otito};
ayanmo i = 0;
nigba (i < 5) {
ayanmo pwd = generate_password(16, options);
ayanmo strength = check_strength(pwd);
Irosu.fo(pwd + " [" + strength + "]");
ayanmo i = i + 1;
}
// monte_carlo.ifa - Estimate Pi using random sampling
ise estimate_pi(samples) {
ayanmo inside = 0;
ayanmo i = 0;
nigba (i < samples) {
// Random point in unit square
ayanmo x = Owonrin.pese_float(0.0, 1.0);
ayanmo y = Owonrin.pese_float(0.0, 1.0);
// Check if inside unit circle
ti (x * x + y * y <= 1.0) {
ayanmo inside = inside + 1;
}
ayanmo i = i + 1;
}
// Pi ˜ 4 * (inside / total)
padap? 4.0 * inside / samples;
}
// Run simulation with increasing samples
ayanmo trials = [1000, 10000, 100000, 1000000];
Irosu.fo("?? Monte Carlo Pi Estimation");
Irosu.fo("---------------------------");
fun n ninu trials {
ayanmo start = Iwori.now_ms();
ayanmo pi = estimate_pi(n);
ayanmo elapsed = Iwori.now_ms() - start;
Irosu.fo(n + " samples: p ˜ " + pi + " (" + elapsed + "ms)");
}
Irosu.fo("\nActual p = 3.14159265...");
// test_data.ifa - Generate fake test data
ayanmo FIRST_NAMES = ["John", "Jane", "Bob", "Alice", "Charlie", "Diana", "Eve", "Frank"];
ayanmo LAST_NAMES = ["Smith", "Johnson", "Williams", "Brown", "Jones", "Davis", "Miller"];
ayanmo DOMAINS = ["gmail.com", "yahoo.com", "outlook.com", "example.com"];
ayanmo CITIES = ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Lagos", "London"];
ise random_name() {
ayanmo first = Owonrin.yan(FIRST_NAMES);
ayanmo last = Owonrin.yan(LAST_NAMES);
padap? first + " " + last;
}
ise random_email(name) {
ayanmo parts = Ika.split(Ika.lowercase(name), " ");
ayanmo domain = Owonrin.yan(DOMAINS);
padap? Ogunda.first(parts) + "." + Ogunda.last(parts) + "@" + domain;
}
ise random_user() {
ayanmo name = random_name();
padap? {
"id": Irete.uuid(),
"name": name,
"email": random_email(name),
"age": Owonrin.pese(18, 65),
"city": Owonrin.yan(CITIES),
"active": Owonrin.pese(0, 1) == 1
};
}
ise generate_users(count) {
ayanmo users = [];
ayanmo i = 0;
nigba (i < count) {
ayanmo users = Ogunda.push(users, random_user());
ayanmo i = i + 1;
}
padap? users;
}
// Usage
Irosu.fo("?? Generated Test Users");
Irosu.fo("-----------------------");
ayanmo users = generate_users(5);
fun user ninu users {
Irosu.fo(user["name"] + " (" + user["age"] + ")");
Irosu.fo(" ?? " + user["email"]);
Irosu.fo(" ?? " + user["city"]);
Irosu.fo("");
}