Abstract & Overview
The Firefly Algorithm (FA) is a bio-inspired metaheuristic that performs robustly on multimodal optimization problems, but it is rarely encountered before graduate level because its Gaussian attraction formulation assumes fluency in calculus and probability that pre-university students do not yet have. This article presents a two-tier implementation of FA designed to make its core mechanism–attraction that decays with distance–directly manipulable across grade bands. A simplified single-attractor variant was implemented in MIT Scratch for elementary and secondary students, and a canonical pairwise variant was implemented in Python (NumPy) for upper-secondary, undergraduate and postgraduate study, complemented by an interactive Pygame visualization that lets students watch the algorithm converge in real time on an actual fitness landscape. Both implementations couple the light-absorption coefficient directly into the attraction strength following a Gaussian decay model and are aligned block-for-block so that students moving between environments can recognize each construct in its counterpart form; the accompanying lesson sequence is grounded in the 5E instructional model, Resnick’s Creative Learning Spiral, and Project- Based Learning. Convergence experiments on the Sphere, Rastrigin, and Ackley benchmark functions over 30 independent runs confirm that both implementations function correctly, with the canonical pairwise variant converging one to two orders of magnitude closer to the global optimum at the cost of Scratch-level manipulability. The two implementations, together with the interactive Pygame visualization, form a coherent, verified instructional pathway from block-based to textual programming for teaching bio-inspired Artificial Intelligence (AI) algorithms in K-12 and beyond.