Compare commits
10 Commits
d3d6c9e650
...
c41bd07c6c
Author | SHA1 | Date | |
---|---|---|---|
c41bd07c6c | |||
01681dae61 | |||
e011e17e51 | |||
8eeaaac890 | |||
4879819ac0 | |||
fd63fae3ae | |||
7d28f9ff21 | |||
8b1e91f054 | |||
eecd8f6dc9 | |||
37c911fa60 |
11
.template.lua
Normal file
11
.template.lua
Normal file
@ -0,0 +1,11 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function f()
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
39
anagrams.lua
Normal file
39
anagrams.lua
Normal file
@ -0,0 +1,39 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function is_anagram(str1, str2)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_listen_is_anagram_of_silent()
|
||||
luaunit.assertTrue(is_anagram("listen", "silent"))
|
||||
end
|
||||
|
||||
function test_astronomers_is_anagram_of_moon_starers()
|
||||
luaunit.assertTrue(is_anagram("astronomers", "moon starers"))
|
||||
end
|
||||
|
||||
function test_dormitory_is_anagram_of_dirty_room()
|
||||
luaunit.assertTrue(is_anagram("dormitory", "dirty room"))
|
||||
end
|
||||
|
||||
function test_foo_is_not_anagram_of_bar()
|
||||
luaunit.assertFalse(is_anagram("foo", "bar"))
|
||||
end
|
||||
|
||||
function test_foo_is_not_anagram_of_of()
|
||||
luaunit.assertFalse(is_anagram("foo", "of"))
|
||||
end
|
||||
|
||||
function test_bar_is_not_anagram_of_barn()
|
||||
luaunit.assertFalse(is_anagram("bar", "barn"))
|
||||
end
|
||||
|
||||
function test_barn_is_not_anagram_of_bar()
|
||||
luaunit.assertFalse(is_anagram("barn", "bar"))
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
@ -1,26 +0,0 @@
|
||||
function leap_year(year)
|
||||
-- Your solution here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
package.path = package.path .. ";../luaunit/?.lua"
|
||||
local luaunit = require("luaunit")
|
||||
|
||||
function test_2004_is_leap_year()
|
||||
luaunit.assertTrue(leap_year(2004))
|
||||
end
|
||||
|
||||
function test_1993_is_not_leap_year()
|
||||
luaunit.assertFalse(leap_year(1993))
|
||||
end
|
||||
|
||||
function test_1900_is_not_leap_year()
|
||||
luaunit.assertFalse(leap_year(1900))
|
||||
end
|
||||
|
||||
function test_2000_is_leap_year()
|
||||
luaunit.assertTrue(leap_year(2000))
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
23
greatest_common_divisor.lua
Normal file
23
greatest_common_divisor.lua
Normal file
@ -0,0 +1,23 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function greatest_common_divisor(x, y)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_greatest_common_divisor_of_1386_and_3213_is_63()
|
||||
luaunit.assertEquals(greatest_common_divisor(1386, 3213), 63)
|
||||
end
|
||||
|
||||
function test_greatest_common_divisor_of_1470_and_3234_is_294()
|
||||
luaunit.assertEquals(greatest_common_divisor(1470, 3234), 294)
|
||||
end
|
||||
|
||||
function test_greatest_common_divisor_of_931_and_399_is_133()
|
||||
luaunit.assertEquals(greatest_common_divisor(931, 399), 133)
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
@ -1,11 +1,12 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function hamming_distance(str1, str2)
|
||||
-- Your solution here
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
package.path = package.path .. ";../luaunit/?.lua"
|
||||
local luaunit = require("luaunit")
|
||||
local luaunit = require("luaunit.luauint")
|
||||
|
||||
function test_distance_between_foo_and_bar_is_3()
|
||||
luaunit.assertEquals(hamming_distance("foo", "bar"), 3)
|
27
leap_years.lua
Normal file
27
leap_years.lua
Normal file
@ -0,0 +1,27 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function is_leap_year(year)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_2004_is_leap_year()
|
||||
luaunit.assertTrue(is_leap_year(2004))
|
||||
end
|
||||
|
||||
function test_1993_is_not_leap_year()
|
||||
luaunit.assertFalse(is_leap_year(1993))
|
||||
end
|
||||
|
||||
function test_1900_is_not_leap_year()
|
||||
luaunit.assertFalse(is_leap_year(1900))
|
||||
end
|
||||
|
||||
function test_2000_is_leap_year()
|
||||
luaunit.assertTrue(is_leap_year(2000))
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
31
prime_numbers.lua
Normal file
31
prime_numbers.lua
Normal file
@ -0,0 +1,31 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function is_prime(x)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
local luaunit = require("luaunit.luauint")
|
||||
|
||||
function test_1_is_not_prime()
|
||||
luaunit.assertFalse(is_prime(1))
|
||||
end
|
||||
|
||||
function test_2_is_prime()
|
||||
luaunit.assertTrue(is_prime(2))
|
||||
end
|
||||
|
||||
function test_15_is_not_prime()
|
||||
luaunit.assertFalse(is_prime(15))
|
||||
end
|
||||
|
||||
function test_441_is_not_prime()
|
||||
luaunit.assertFalse(is_prime(441))
|
||||
end
|
||||
|
||||
function test_563_is_prime()
|
||||
luaunit.assertTrue(is_prime(563))
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
39
queen_threats.lua
Normal file
39
queen_threats.lua
Normal file
@ -0,0 +1,39 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function is_queen_threat(queen_position, pawn_position)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_B4_theatens_G4()
|
||||
luaunit.assertTrue(is_queen_threat("B4", "G4"))
|
||||
end
|
||||
|
||||
function test_D7_theatens_D1()
|
||||
luaunit.assertTrue(is_queen_threat("D7", "D1"))
|
||||
end
|
||||
|
||||
function test_C5_theatens_F8()
|
||||
luaunit.assertTrue(is_queen_threat("C5", "F8"))
|
||||
end
|
||||
|
||||
function test_B3_theatens_D1()
|
||||
luaunit.assertTrue(is_queen_threat("B3", "D1"))
|
||||
end
|
||||
|
||||
function test_B4_does_not_threaten_F3()
|
||||
luaunit.assertFalse(is_queen_threat("B4", "F3"))
|
||||
end
|
||||
|
||||
function test_E2_does_not_threaten_G1()
|
||||
luaunit.assertFalse(is_queen_threat("E2", "G1"))
|
||||
end
|
||||
|
||||
function test_A8_does_not_threaten_G3()
|
||||
luaunit.assertFalse(is_queen_threat("A8", "G3"))
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
@ -1,3 +1,5 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
-- Give the colours whatever values are convenient
|
||||
black = undefined
|
||||
brown = undefined
|
||||
@ -13,13 +15,12 @@ gold = undefined
|
||||
silver = undefined
|
||||
|
||||
function decode_resistance(colours)
|
||||
-- Your solution here
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
package.path = package.path .. ";../luaunit/?.lua"
|
||||
local luaunit = require("luaunit")
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_violet_orange_black_is_73_ohms()
|
||||
local resistance = decode_resistance({violet, orange, black})
|
Loading…
x
Reference in New Issue
Block a user