Algorithm examples
Each example opens in the editor with one click: see the diagram, run it step by step and watch the variables change.
- Simple greetingThe simplest example possible: reads a name and greets it. Ideal starting point for anyone new to freeDFDWeb.
- Hello World!The classic first program — prints it in the Execution console and also says it out loud.
- Factorial of a numberComputes and prints the factorial of a number read from the keyboard.
- Is it a prime number?Determines whether a positive integer entered from the keyboard is prime.
- Greatest common divisor (Euclid)Calculates the greatest common divisor (GCD) of two numbers using Euclid's algorithm.
- Fibonacci sequenceGenerates and displays the first N terms of the Fibonacci sequence.
- Reverse the digits of a numberReverses the digits of a positive integer read from the keyboard.
- Grade average and pass/failCalculates the average of N entered grades and determines whether the student passes (average ≥ 3) or not.
- Multiplication table (nested loops)Multiplication table from 1 to 10 using two nested For loops — classic example of nested loops.
- Even/odd counterGoes through 1 to 20 and classifies each number as even or odd — combines a For loop with a Decision inside.
- Temperature converterConverts degrees Celsius to Fahrenheit or Kelvin, based on the option chosen from a menu.
- Quadratic equation (general formula)Solves a·x² + b·x + c = 0 with the quadratic formula: computes the discriminant and tells apart two roots, a double root or none real. Uses exponentiation, square root and unary minus.
- Decimal to binaryShows the conversion of a decimal number to binary.
- Guess the magic numberMagic number game: the program picks a secret number and the user tries to guess it, getting 'higher'/'lower' hints on each attempt until they get it right.
- Linear search in an arraySearches for an element X inside an array of N elements by going through it position by position (linear search).
- Sum of even numbers in an arrayGoes through an array and adds up only its even elements.
- Bubble sortSorts an array read from the keyboard.
- Search with early exitSearches for a number entered from the keyboard, attempt by attempt, and exits the loop as soon as it's found using Break loop — classic example of a search with early exit.
- Full program stopValidates the entered age; if it's invalid, stops the entire program execution using Exit program instead of continuing with incorrect data.
- Countdown (Sleep)Counts down from 5 to 1, pausing 1 second between each number using Sleep, to simulate a real wait time.
- Days of the week (Switch)Reads a day number (1-7) and uses Switch to print the matching day's name — demonstrates the Switch component with several cases + default.
- Simple IVR with voice menuSimple IVR: plays a menu by voice and branches based on the option chosen with Switch. The option is still entered from the keyboard (Read) — on purpose, so as not to force a choice between a spoken number or an option name.
- Voice greeting (Listen + Play)Combines the two voice plugin components: 'Listen (voice)' captures your name by speaking it (hold the microphone button and speak), 'Play voice' greets you back. Without a microphone or browser support, it falls back to keyboard entry — the program still runs the same.
- Array index error (demo)Demonstrates array index error handling: reading a position that was never assigned throws an explicit error instead of silent garbage like the original tool.
- Validate input (Repeat)The classic teaching case for Repeat (do-while): asks for a positive number until the entered value is valid. The body always runs at least once — unlike While, here the condition is only known after reading the value.
- Menu repeated until exit (Repeat + Switch)Simple calculator with a menu: Add, Subtract, or Exit. The menu repeats (Repeat + Switch, real nesting) until the user picks option 3 — a very common case in introductory courses.
- Most expensive product (parallel arrays)Loads N products into two parallel arrays (name and price, both indexed by the same position) and finds the most expensive one — a real and very common pattern (records "split" across several arrays related by index).
- Number to words (0-9999, Spanish)Converts an integer of up to 4 digits into its written form in Spanish words — e.g. 5432 -> "cinco mil cuatrocientos treinta y dos". Uses lookup tables (arrays) and subprograms to handle the language's real irregularities (11-15, 16-29 fused, "cien" vs "ciento").
- Number to Roman numerals (1-3999)Converts an integer into its Roman numeral representation — e.g. 1994 -> "MCMXCIV". Classic greedy algorithm with two parallel arrays (values and symbols, largest to smallest).
- Roman numerals to numberConverts Roman numeral text (I, V, X, L, C, D, M) into its integer value — e.g. "MCMXCIV" -> 1994. Walks the text adding each symbol's value, unless it's smaller than the next one (subtractive notation: "IV", "IX", "XL"...), in which case it subtracts. Uses a text-based Switch to translate each symbol.
- Parking lot (interactive component)Shows how a DFD can drive an external visual component with Llamada (Call): Activate("Estacionamiento") opens a floating window (draggable, resizable, doesn't block the rest of the app), CargarEscenario picks the world size, HayObstaculo asks a question and answers into the response_call variable, and MOVER moves the car — if it crashes, it throws a real runtime exception, same as any other language error.
- Maze (interactive component)Same mechanism as the parking lot example, applied to a maze (MOVER/HayObstaculo/CargarEscenario are verbs shared between both components): Activate("Laberinto") opens the floating window, CargarEscenario picks the maze size, HayObstaculo asks whether there's a wall and answers into response_call, and MOVER guides the explorer to the exit — hitting a wall throws a real runtime exception.
- Maze — exploring without knowing the map (level 3)The most advanced algorithm in the gallery: explores the maze WITHOUT knowing the map, with real DFS (two parallel vectors of visited positions plus a direction stack for backtracking out of dead ends). Combines vectors, loops, conditions, Switch and system calls all in one place. This example loads a maze WITH a solution — see also "impossible" for the other half of the exercise.
- Maze — detecting it's impossible (level 3)Same exhaustive-search algorithm as the other level-3 example, but loaded against a maze that's deliberately UNSOLVABLE (the exit is completely sealed off). The algorithm explores everything reachable and concludes "impossible" with CERTAINTY — not a heuristic giving up, a real exhaustive search proving there's no path.
- Towers of Hanoi (interactive component)Shows the Towers of Hanoi component with a PRELOADED move sequence (no recursive algorithm, manual solution) — same criterion as the parking lot/maze: teaches the MoverDisco/Discos/Termine syntax, doesn't solve the puzzle intelligently. Unlike the other components, Hanoi doesn't need to sense the world — an illegal move throws a real runtime exception from MoverDisco itself.
- Plot SEN(x) (interactive component)Plots the SEN(x) function point by point, with x stepping 0.2 at a time from 0 to 2*PI (one full sine wave) — uses the real PI constant and SEN builtin from the interpreter. Shows the Graficador component: each Llamada GraficarPunto(x, y) adds a point to the curve, and the plane rescales on its own as points grow.
- Plot COS(x) (interactive component)Plots the COS(x) function point by point, with x stepping 0.2 at a time from 0 to 2*PI (one full cosine wave) — same mechanism as the SEN(x) example, a good pair to compare the two curves.
- Koch snowflake (interactive component)Draws a full Koch snowflake with the Turtle component: 3 sides at level 3 (4^3=64 segments each, 192 total), each generated by the RECURSIVE Koch(longitud, nivel) subprogram. Shows how a short recursive algorithm (7 lines) produces a complex geometric figure — recursion made visually beautiful, unlike Hanoi where recursion solves a puzzle.
- Picas y Fijas — guess a number (interactive component)Unlike the other interactive components, Picas y Fijas has no logic of its own — the diagram itself compares the guess against a secret number (digit by digit, with SubCadena) and passes the already-computed result to PicasYFijas(numeroIntentado, cantidadFijas, cantidadPicas), which just paints it. Up to 3 attempts, cuts short as soon as it's guessed. Variable names meant to read like a sentence.
- Palabra Secreta — happy path (interactive component)A linear, burned-in flow (no Leer, no loops) meant to be stepped through in the debugger: tries the 4 letters of GATO in order, all correct, and ends in a win. Just like Picas y Fijas, PalabraSecreta has no logic of its own — the DFD builds the letrasIntentadas array by hand and the component only detects on its own when it won.
- Palabra Secreta — sad path (interactive component)A linear, burned-in flow (no Leer, no loops) meant to be stepped through in the debugger: tries 4 letters that aren't in SOL, one by one, and on the last call signals perdio=True. Shows the full catapult-firing-the-pie animation — the component never decides losing on its own, that count belongs to the DFD.
- Buscaminas — naive path (interactive component)A linear, burned-in flow (no Leer): sweeps the ENTIRE board revealing cell by cell, never looking at any number. Always ends in a real exception when it hits a mine — the board guarantees a safe move is always available, so losing here is evidence the algorithm never reasons, not bad luck. Buscaminas belongs to the SENSOR family (like Estacionamiento/Laberinto): the component generates and keeps the mines itself, the student never knows them in advance.
- Buscaminas — deduction path (interactive component)The same board, solved by pure logic: a fixed-point loop (nested Para + Consultar) applies the 2 deduction rules (if a number already has enough flagged neighbors, the rest are safe; if it needs as many mines as unknown neighbors remain, those are all mines) until the whole board is cleared, without guessing a single cell. Shows live why "code it right" isn't just a phrase here — it literally means "never lose".
- 8 Queens — happy path (interactive component)Places the 8 queens of the classic problem in a real solution, with all 8 positions already burned in — no algorithm computing them. The point is to show that winning clean IS possible: no queen attacks another (same row, column, or diagonal). 8 Queens belongs to the SENSOR family (like Buscaminas): it validates each placement on the spot, not at the end.
- 8 Queens — sad path (interactive component)A few correct queens, then one placed on purpose in the same column as another already there — ends in a real ColocarReina exception, to show the validation in action: two queens can never share a row, column, or diagonal.
- Knight's Tour — happy path (interactive component)Completes the classic knight's tour (visiting all 64 squares of an 8×8 board without repeating any) with a real solution, all 64 positions already burned in — no algorithm computing them. The point is to show that completing the tour IS possible, always moving in a real chess "L". Knight's Tour belongs to the SENSOR family (like 8 Queens): it validates each move on the spot, not at the end.
- Knight's Tour — sad path (interactive component)A few correct moves, then one that returns to an already-visited square (even though it's a valid "L") — ends in a real ColocarCaballo exception, to show the validation in action: the tour can never repeat a square.