All puzzles › AI Search and Planning

AI Search and Planning Practice Problems

25 puzzles (4 easy, 12 medium, 9 hard), 6 free, in Python, JavaScript and C++.

Search, planning, reasoning and the classic algorithms of intelligent agents.

The puzzles, easiest first

  1. Nudge the Estimate (Easy, free): Q-learning keeps a number for each action: how good it expects that action to be.
  2. Greedy Action (Easy): Given a list of action values, return the index of the best one.
  3. Manhattan Heuristic (Easy): Given two grid cells as [row, col], return the Manhattan distance between them: the row difference plus the column difference, both as absolute values.
  4. Tokenize Text (Easy): Given a sentence, return its words in lowercase.
  5. Cross Off What Cannot Work (Medium, free): Before a solver guesses, it removes values that could never be part of an answer.
  6. Let the Reward Spread (Medium, free): An agent walks a row of cells, and each cell pays a reward that is never negative.
  7. Bag-of-Words Cosine (Medium): Given two lists of words, return their bag-of-words cosine similarity, rounded to 3 decimals.
  8. BFS Distances (Medium): Given a graph as an adjacency list and a start node, return how many hops each node is from the start, or -1 if you can't reach it.
  9. Bigram Counts (Medium): Given a list of words, return a map from each pair of neighboring words to how many times that pair appears.
  10. Detect Dependency Cycle (Medium): Given a directed graph as an adjacency list, return true if it has a cycle.
  11. Flood Fill (Medium): Given a grid, a starting cell, and a new color, recolor the starting cell and every same-colored cell connected to it, up, down, left, or right.
  12. Intersection over Union (Medium): Given two boxes as [x1, y1, x2, y2], return their intersection over union, rounded to 3 decimals.
  13. Is Target Reachable? (Medium): Given a directed graph as an adjacency list, a start, and a target, return true if there's any path from start to target.
  14. Jaccard Similarity (Medium): Given two lists, return their Jaccard similarity, rounded to 3 decimals: how many values they share, divided by how many different values there are in total.
  15. Markov Next State (Medium): Given a grid of transition counts and the current state, return the most likely next state.
  16. Minimax Game Value (Medium): Given the scores at the bottom of a game tree and whether the first player is maximizing, return the game's value.
  17. Only One Choice Left (Hard, free): A formula is a list of clauses, and each clause is a list of literals: 3 means variable 3 is true, -3 means it is false.
  18. Stop Looking When It Cannot Matter (Hard, free): Minimax looks at every position in a game tree.
  19. Uncross the Route (Hard, free): The best tour through a set of cities is too hard to find exactly, so solvers improve a tour they already have.
  20. 0/1 Knapsack (Hard): Given item weights, item values, and a weight limit, return the most value you can carry.
  21. Coin Change (Fewest) (Hard): Given coin values and an amount, return the fewest coins that add up to it exactly, or -1 if you can't.
  22. Dijkstra Shortest Path (Hard): Given a weighted graph, where each node lists [neighbor, cost] pairs, return the cheapest total cost from src to target, or -1 if you can't get there.
  23. Edit Distance (Hard): Given two words, return the fewest single-letter inserts, deletes, or swaps that turn one into the other.
  24. Shortest Path (BFS) (Hard): Given a grid where 0 is open and 1 is a wall, a start, and an end, return the fewest steps from start to end, moving up, down, left, or right.
  25. Topological Order (Hard): Given a directed graph as an adjacency list, return an order where every node comes before the nodes it points to.

Practice another pattern

Or browse by subject

Browse all 676 puzzles