Real-world data collection and manipulation.
// cart.ifa - E-commerce shopping cart
ayanmo cart = [];
ise add_item(product_id, name, price, quantity) {
// Check if item exists
ayanmo index = find_item_index(product_id);
ti (index >= 0) {
// Update quantity
ayanmo item = Ogunda.get(cart, index);
item["quantity"] = item["quantity"] + quantity;
} bib?k? {
// Add new item
ayanmo cart = Ogunda.push(cart, {
"id": product_id,
"name": name,
"price": price,
"quantity": quantity
});
}
}
ise find_item_index(product_id) {
ayanmo i = 0;
fun item ninu cart {
ti (item["id"] == product_id) {
padap? i;
}
ayanmo i = i + 1;
}
padap? -1;
}
ise remove_item(product_id) {
ayanmo new_cart = [];
fun item ninu cart {
ti (item["id"] != product_id) {
ayanmo new_cart = Ogunda.push(new_cart, item);
}
}
ayanmo cart = new_cart;
}
ise get_total() {
ayanmo total = 0;
fun item ninu cart {
ayanmo total = total + (item["price"] * item["quantity"]);
}
padap? total;
}
ise display_cart() {
Irosu.fo("\n?? Shopping Cart");
Irosu.fo("-----------------");
fun item ninu cart {
ayanmo subtotal = item["price"] * item["quantity"];
Irosu.fo(item["name"] + " x" + item["quantity"] + " = $" + subtotal);
}
Irosu.fo("-----------------");
Irosu.fo("Total: $" + get_total());
}
// Usage
add_item("SKU001", "Laptop", 999.99, 1);
add_item("SKU002", "Mouse", 29.99, 2);
add_item("SKU003", "Keyboard", 79.99, 1);
add_item("SKU002", "Mouse", 29.99, 1); // Add more mice
display_cart();
// queue.ifa - FIFO task queue implementation
ayanmo queue = [];
ise enqueue(task) {
ayanmo queue = Ogunda.push(queue, {
"id": Irete.uuid(),
"task": task,
"status": "pending",
"created": Iwori.now()
});
Irosu.fo("Enqueued: " + task["name"]);
}
ise dequeue() {
ti (Ogunda.len(queue) == 0) {
padap? nil;
}
ayanmo item = Ogunda.first(queue);
ayanmo queue = Ogunda.slice(queue, 1, Ogunda.len(queue));
padap? item;
}
ise peek() {
ti (Ogunda.len(queue) == 0) {
padap? nil;
}
padap? Ogunda.first(queue);
}
ise process_queue(handler) {
Irosu.fo("Processing " + Ogunda.len(queue) + " tasks...");
nigba (Ogunda.len(queue) > 0) {
ayanmo item = dequeue();
Irosu.fo("Processing: " + item["task"]["name"]);
handler(item["task"]);
Irosu.fo("? Completed");
}
Irosu.fo("Queue empty");
}
// Usage
enqueue({"name": "Send email", "to": "user@example.com"});
enqueue({"name": "Generate report", "type": "monthly"});
enqueue({"name": "Backup database", "target": "s3"});
process_queue(|task| {
Oyeku.sleep(500); // Simulate work
});
// leaderboard.ifa - Game score ranking system
ayanmo scores = [];
ise add_score(player, score) {
ayanmo scores = Ogunda.push(scores, {
"player": player,
"score": score,
"date": Iwori.now()
});
// Keep sorted by score (descending)
ayanmo scores = sort_scores();
}
ise sort_scores() {
// Bubble sort by score descending
ayanmo n = Ogunda.len(scores);
ayanmo i = 0;
nigba (i < n - 1) {
ayanmo j = 0;
nigba (j < n - i - 1) {
ayanmo a = Ogunda.get(scores, j);
ayanmo b = Ogunda.get(scores, j + 1);
ti (a["score"] < b["score"]) {
// Swap
ayanmo scores = Ogunda.set(scores, j, b);
ayanmo scores = Ogunda.set(scores, j + 1, a);
}
ayanmo j = j + 1;
}
ayanmo i = i + 1;
}
padap? scores;
}
ise get_top(n) {
ayanmo limit = Obara.min(n, Ogunda.len(scores));
padap? Ogunda.slice(scores, 0, limit);
}
ise display_leaderboard() {
Irosu.fo("\n?? LEADERBOARD");
Irosu.fo("------------------");
ayanmo top = get_top(10);
ayanmo rank = 1;
fun entry ninu top {
ayanmo medal = "";
ti (rank == 1) { ayanmo medal = "??"; }
bib?k? ti (rank == 2) { ayanmo medal = "??"; }
bib?k? ti (rank == 3) { ayanmo medal = "??"; }
bib?k? { ayanmo medal = rank + "."; }
Irosu.fo(medal + " " + entry["player"] + " - " + entry["score"]);
ayanmo rank = rank + 1;
}
}
// Usage
add_score("Alice", 15000);
add_score("Bob", 12500);
add_score("Carol", 18000);
add_score("Dave", 9500);
add_score("Eve", 21000);
display_leaderboard();
// inventory.ifa - Stock tracking system
ayanmo inventory = [];
ise add_product(sku, name, quantity, min_stock) {
ayanmo inventory = Ogunda.push(inventory, {
"sku": sku,
"name": name,
"quantity": quantity,
"min_stock": min_stock
});
}
ise update_stock(sku, delta) {
ayanmo i = 0;
fun item ninu inventory {
ti (item["sku"] == sku) {
item["quantity"] = item["quantity"] + delta;
ti (item["quantity"] < 0) {
item["quantity"] = 0;
}
padap? otito;
}
ayanmo i = i + 1;
}
padap? iro;
}
ise get_low_stock() {
ayanmo low = [];
fun item ninu inventory {
ti (item["quantity"] <= item["min_stock"]) {
ayanmo low = Ogunda.push(low, item);
}
}
padap? low;
}
ise generate_reorder_report() {
ayanmo low = get_low_stock();
ti (Ogunda.len(low) == 0) {
Irosu.fo("? All items adequately stocked");
padap?;
}
Irosu.fo("\n?? REORDER NEEDED");
Irosu.fo("---------------------");
fun item ninu low {
ayanmo needed = item["min_stock"] * 2 - item["quantity"];
Irosu.fo(item["sku"] + " | " + item["name"]);
Irosu.fo(" Current: " + item["quantity"] + " | Order: " + needed);
}
}
// Usage
add_product("WDG-001", "Widget A", 50, 20);
add_product("WDG-002", "Widget B", 15, 25);
add_product("GDG-001", "Gadget X", 100, 30);
add_product("GDG-002", "Gadget Y", 5, 10);
update_stock("WDG-001", -35); // Sell 35
update_stock("GDG-001", -80); // Sell 80
generate_reorder_report();