Lua typing test
Lua is small and simple, and popular for scripting games and editors such as Neovim. Typing it is more about keywords than symbols: local, function, then, do and end, with elseif as one word. Tables are written with braces, and # gives a table's length.
What you'll type in Lua
localbefore variables and functions.then,doandendaround every block.elseifas a single word.{ }for tables, as in{ value = value }.#for length, as inout[#out + 1]...to join strings, and~=for not-equal.
Example: FizzBuzz in Lua
Lua's numeric for loop takes a start and an end, separated by a comma: for i = 1, 15 do.
for i = 1, 15 do
if i % 15 == 0 then
print("FizzBuzz")
elseif i % 3 == 0 then
print("Fizz")
elseif i % 5 == 0 then
print("Buzz")
else
print(i)
end
end
Tips for typing Lua faster
- Lua is mostly lowercase words, which makes it a good place to build raw speed before tackling symbol-heavy languages like Rust or C++.
out[#out + 1] = node.valueis the classic Lua way to add to the end of a list. Practise the[#combination.- Every
if,forandfunctionneeds a matchingend.
All 20 Lua programs
Every program is real, working Lua. Choose one to start typing it straight away.
Beginner
- Hello, World!Print a greeting.
- Count to fivePrint the numbers 1 to 5.
- Celsius to FahrenheitConvert 100 °C to Fahrenheit.
- Sum a listAdd up 3, 1, 4, 1, 5.
- Find the largestFind the biggest number in a list.
- Count vowelsCount the vowels in "keyboard".
Intermediate
- Reverse a stringTurn "hello" into "olleh".
- FizzBuzzFizz for 3s, Buzz for 5s, 1 to 15.
- FactorialA recursive function, called with 5.
- FibonacciPrint the first ten Fibonacci numbers.
- Greatest common divisorEuclid's algorithm for 48 and 18.
Advanced
- Primes to 20Print every prime up to 20.
- PalindromeCheck whether "racecar" reads the same backwards.
- Word countCount the words in a sentence.
- Bubble sortSort 5, 2, 9, 1, 7 by swapping neighbours.
- Binary searchFind 7 in a sorted list by halving.
Expert
- QuicksortSort a list by partitioning around a pivot.
- Binary search treeBuild a tree, then read the values back in order.
- Shortest path (BFS)Breadth-first search through a small graph.
- N-QueensCount the ways to place 6 queens so none attack.
How the test works
The timer starts on your first key and stops once every character is right. Press Enter for a new line and the indentation is filled in for you. A wrong key shows in red and counts as a mistake; press Backspace to go back and fix it. Your best time for each program is saved in your browser. Read more about how speed and accuracy are calculated, or get tips for typing code faster.