Compare commits
6 Commits
c41bd07c6c
...
8c06a5172e
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c06a5172e | |||
| 0961258fba | |||
| f020336ccb | |||
| 3cadabcf68 | |||
| 017ef8bac4 | |||
| 467ca0446a |
33
.lua-format
Normal file
33
.lua-format
Normal file
@@ -0,0 +1,33 @@
|
||||
column_limit: 80
|
||||
indent_width: 1
|
||||
use_tab: true
|
||||
tab_width: 4
|
||||
continuation_indent_width: 1
|
||||
spaces_before_call: 1
|
||||
keep_simple_control_block_one_line: true
|
||||
keep_simple_function_one_line: false
|
||||
align_args: true
|
||||
break_after_functioncall_lp: false
|
||||
break_before_functioncall_rp: false
|
||||
spaces_inside_functioncall_parens: false
|
||||
spaces_inside_functiondef_parens: false
|
||||
align_parameter: true
|
||||
chop_down_parameter: false
|
||||
break_after_functiondef_lp: false
|
||||
break_before_functiondef_rp: false
|
||||
align_table_field: true
|
||||
break_after_table_lb: true
|
||||
break_before_table_rb: true
|
||||
chop_down_table: false
|
||||
chop_down_kv_table: true
|
||||
table_sep: ","
|
||||
extra_sep_at_table_end: false
|
||||
column_table_limit: 0
|
||||
column_table_limit_kv: 0
|
||||
spaces_inside_table_braces: false
|
||||
break_after_operator: true
|
||||
double_quote_to_single_quote: false
|
||||
single_quote_to_double_quote: false
|
||||
spaces_around_equals_in_field: true
|
||||
line_breaks_after_function_body: 1
|
||||
line_separator: input
|
||||
@@ -1,7 +1,6 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function f()
|
||||
-- Your implementation here
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
17
anagrams.lua
17
anagrams.lua
@@ -1,7 +1,6 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function is_anagram(str1, str2)
|
||||
-- Your implementation here
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
@@ -9,31 +8,31 @@ end
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_listen_is_anagram_of_silent()
|
||||
luaunit.assertTrue(is_anagram("listen", "silent"))
|
||||
luaunit.assertTrue(is_anagram("listen", "silent"))
|
||||
end
|
||||
|
||||
function test_astronomers_is_anagram_of_moon_starers()
|
||||
luaunit.assertTrue(is_anagram("astronomers", "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"))
|
||||
luaunit.assertTrue(is_anagram("dormitory", "dirty room"))
|
||||
end
|
||||
|
||||
function test_foo_is_not_anagram_of_bar()
|
||||
luaunit.assertFalse(is_anagram("foo", "bar"))
|
||||
luaunit.assertFalse(is_anagram("foo", "bar"))
|
||||
end
|
||||
|
||||
function test_foo_is_not_anagram_of_of()
|
||||
luaunit.assertFalse(is_anagram("foo", "of"))
|
||||
luaunit.assertFalse(is_anagram("foo", "of"))
|
||||
end
|
||||
|
||||
function test_bar_is_not_anagram_of_barn()
|
||||
luaunit.assertFalse(is_anagram("bar", "barn"))
|
||||
luaunit.assertFalse(is_anagram("bar", "barn"))
|
||||
end
|
||||
|
||||
function test_barn_is_not_anagram_of_bar()
|
||||
luaunit.assertFalse(is_anagram("barn", "bar"))
|
||||
luaunit.assertFalse(is_anagram("barn", "bar"))
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
|
||||
54
balanced_brackets.lua
Normal file
54
balanced_brackets.lua
Normal file
@@ -0,0 +1,54 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
function is_balanced(input)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_single_paren_is_not_balanced()
|
||||
luaunit.assertFalse(is_balanced("("))
|
||||
end
|
||||
|
||||
function test_paren_pair_is_balanced()
|
||||
luaunit.assertTrue(is_balanced("()"))
|
||||
end
|
||||
|
||||
function test_inverted_paren_pair_is_not_balanced()
|
||||
luaunit.assertFalse(is_balanced(")("))
|
||||
end
|
||||
|
||||
function test_nested_parens_are_balanced()
|
||||
luaunit.assertTrue(is_balanced("(())"))
|
||||
end
|
||||
|
||||
function test_double_open_single_close_paren_is_not_balanced()
|
||||
luaunit.assertFalse(is_balanced("(()"))
|
||||
end
|
||||
|
||||
function test_single_open_double_close_brace_is_not_balanced()
|
||||
luaunit.assertFalse(is_balanced("{}}"))
|
||||
end
|
||||
|
||||
function test_nested_parens_and_brackets_are_balanced()
|
||||
luaunit.assertTrue(is_balanced("([])"))
|
||||
end
|
||||
|
||||
function test_nested_brackets_and_braces_are_balanced()
|
||||
luaunit.assertTrue(is_balanced("({})"))
|
||||
end
|
||||
|
||||
function test_sequence_of_paren_bracket_and_brace_pairs_are_balanced()
|
||||
luaunit.assertTrue(is_balanced("()[]{}"))
|
||||
end
|
||||
|
||||
function test_balanced_combination_of_nesting_and_sequencing()
|
||||
luaunit.assertTrue(is_balanced("(([]{}))[()[[]]]"))
|
||||
end
|
||||
|
||||
function test_interwoven_paren_and_bracket_pairs_are_not_balanced()
|
||||
luaunit.assertFalse(is_balanced("([)]"))
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
30
fibonacci_numbers.lua
Normal file
30
fibonacci_numbers.lua
Normal file
@@ -0,0 +1,30 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
function nth_fibonacci_number(n)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_3rd_fibonacci_number_is_2()
|
||||
luaunit.assertEquals(nth_fibonacci_number(3), 2)
|
||||
end
|
||||
|
||||
function test_5th_fibonacci_number_is_5()
|
||||
luaunit.assertEquals(nth_fibonacci_number(5), 5)
|
||||
end
|
||||
|
||||
function test_10th_fibonacci_number_is_55()
|
||||
luaunit.assertEquals(nth_fibonacci_number(10), 55)
|
||||
end
|
||||
|
||||
function test_20th_fibonacci_number_is_6765()
|
||||
luaunit.assertEquals(nth_fibonacci_number(20), 6765)
|
||||
end
|
||||
|
||||
function test_80th_fibonacci_number_is_23416728348467685()
|
||||
luaunit.assertEquals(nth_fibonacci_number(80), 23416728348467685)
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
@@ -1,7 +1,6 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function greatest_common_divisor(x, y)
|
||||
-- Your implementation here
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
@@ -9,15 +8,15 @@ end
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_greatest_common_divisor_of_1386_and_3213_is_63()
|
||||
luaunit.assertEquals(greatest_common_divisor(1386, 3213), 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)
|
||||
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)
|
||||
luaunit.assertEquals(greatest_common_divisor(931, 399), 133)
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function hamming_distance(str1, str2)
|
||||
-- Your implementation here
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
@@ -9,11 +8,11 @@ end
|
||||
local luaunit = require("luaunit.luauint")
|
||||
|
||||
function test_distance_between_foo_and_bar_is_3()
|
||||
luaunit.assertEquals(hamming_distance("foo", "bar"), 3)
|
||||
luaunit.assertEquals(hamming_distance("foo", "bar"), 3)
|
||||
end
|
||||
|
||||
function test_distance_between_bar_and_baz_is_1()
|
||||
luaunit.assertEquals(hamming_distance("bar", "baz"), 1)
|
||||
luaunit.assertEquals(hamming_distance("bar", "baz"), 1)
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
|
||||
34
hexadecimal.lua
Normal file
34
hexadecimal.lua
Normal file
@@ -0,0 +1,34 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
function hexadecimal(x)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_hexadecimal_of_8_is_8()
|
||||
luaunit.assertEquals(hexadecimal(8), "8")
|
||||
end
|
||||
|
||||
function test_hexadecimal_of_14_is_e()
|
||||
luaunit.assertEquals(hexadecimal(14), "e")
|
||||
end
|
||||
|
||||
function test_hexadecimal_of_42_is_2a()
|
||||
luaunit.assertEquals(hexadecimal(42), "2a")
|
||||
end
|
||||
|
||||
function test_hexadecimal_of_3735928559_is_deadbeef()
|
||||
luaunit.assertEquals(hexadecimal(3735928559), "deadbeef")
|
||||
end
|
||||
|
||||
function test_hexadecimal_of_12648430_is_c0ffee()
|
||||
luaunit.assertEquals(hexadecimal(12648430), "c0ffee")
|
||||
end
|
||||
|
||||
function test_hexadecimal_of_49374_is_c0de()
|
||||
luaunit.assertEquals(hexadecimal(49374), "c0de")
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
@@ -1,7 +1,6 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function is_leap_year(year)
|
||||
-- Your implementation here
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
@@ -9,19 +8,19 @@ end
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_2004_is_leap_year()
|
||||
luaunit.assertTrue(is_leap_year(2004))
|
||||
luaunit.assertTrue(is_leap_year(2004))
|
||||
end
|
||||
|
||||
function test_1993_is_not_leap_year()
|
||||
luaunit.assertFalse(is_leap_year(1993))
|
||||
luaunit.assertFalse(is_leap_year(1993))
|
||||
end
|
||||
|
||||
function test_1900_is_not_leap_year()
|
||||
luaunit.assertFalse(is_leap_year(1900))
|
||||
luaunit.assertFalse(is_leap_year(1900))
|
||||
end
|
||||
|
||||
function test_2000_is_leap_year()
|
||||
luaunit.assertTrue(is_leap_year(2000))
|
||||
luaunit.assertTrue(is_leap_year(2000))
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
|
||||
26
maximum.lua
Normal file
26
maximum.lua
Normal file
@@ -0,0 +1,26 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
function maximum(list)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_maximum_of_1_8_3_and_5_is_8()
|
||||
luaunit.assertEquals(maximum({1, 8, 3, 5}), 8)
|
||||
end
|
||||
|
||||
function test_maximum_of_123_321_231_and_213_is_321()
|
||||
luaunit.assertEquals(maximum({123, 321, 231, 213}), 321)
|
||||
end
|
||||
|
||||
function test_maximum_of_6_2_1_minus_5_and_minus_6_is_6()
|
||||
luaunit.assertEquals(maximum({6, 2, 1, -5, -6}), 6)
|
||||
end
|
||||
|
||||
function test_maximum_of_minus_4_minus_10_minus_8_and_minus_2_is_minus_2()
|
||||
luaunit.assertEquals(maximum({-4, -10, -8, -2}), -2)
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
34
palindromes.lua
Normal file
34
palindromes.lua
Normal file
@@ -0,0 +1,34 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
function is_palindrome(str)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_foo_is_not_palindrome()
|
||||
luaunit.assertFalse(is_palindrome("foo"))
|
||||
end
|
||||
|
||||
function test_wow_is_palindrome()
|
||||
luaunit.assertTrue(is_palindrome("wow"))
|
||||
end
|
||||
|
||||
function test_toast_is_not_palindrome()
|
||||
luaunit.assertFalse(is_palindrome("toast"))
|
||||
end
|
||||
|
||||
function test_Racecar_is_palindrome()
|
||||
luaunit.assertTrue(is_palindrome("Race car"))
|
||||
end
|
||||
|
||||
function test_Do_geese_see_God_is_palindrome()
|
||||
luaunit.assertTrue(is_palindrome("Do geese see God?"))
|
||||
end
|
||||
|
||||
function test_No_lemons_no_melon_is_palindrome()
|
||||
luaunit.assertTrue(is_palindrome("No lemons, no melon."))
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
@@ -1,7 +1,6 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function is_prime(x)
|
||||
-- Your implementation here
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
@@ -9,23 +8,23 @@ end
|
||||
local luaunit = require("luaunit.luauint")
|
||||
|
||||
function test_1_is_not_prime()
|
||||
luaunit.assertFalse(is_prime(1))
|
||||
luaunit.assertFalse(is_prime(1))
|
||||
end
|
||||
|
||||
function test_2_is_prime()
|
||||
luaunit.assertTrue(is_prime(2))
|
||||
luaunit.assertTrue(is_prime(2))
|
||||
end
|
||||
|
||||
function test_15_is_not_prime()
|
||||
luaunit.assertFalse(is_prime(15))
|
||||
luaunit.assertFalse(is_prime(15))
|
||||
end
|
||||
|
||||
function test_441_is_not_prime()
|
||||
luaunit.assertFalse(is_prime(441))
|
||||
luaunit.assertFalse(is_prime(441))
|
||||
end
|
||||
|
||||
function test_563_is_prime()
|
||||
luaunit.assertTrue(is_prime(563))
|
||||
luaunit.assertTrue(is_prime(563))
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function is_queen_threat(queen_position, pawn_position)
|
||||
-- Your implementation here
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
@@ -9,31 +8,31 @@ end
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_B4_theatens_G4()
|
||||
luaunit.assertTrue(is_queen_threat("B4", "G4"))
|
||||
luaunit.assertTrue(is_queen_threat("B4", "G4"))
|
||||
end
|
||||
|
||||
function test_D7_theatens_D1()
|
||||
luaunit.assertTrue(is_queen_threat("D7", "D1"))
|
||||
luaunit.assertTrue(is_queen_threat("D7", "D1"))
|
||||
end
|
||||
|
||||
function test_C5_theatens_F8()
|
||||
luaunit.assertTrue(is_queen_threat("C5", "F8"))
|
||||
luaunit.assertTrue(is_queen_threat("C5", "F8"))
|
||||
end
|
||||
|
||||
function test_B3_theatens_D1()
|
||||
luaunit.assertTrue(is_queen_threat("B3", "D1"))
|
||||
luaunit.assertTrue(is_queen_threat("B3", "D1"))
|
||||
end
|
||||
|
||||
function test_B4_does_not_threaten_F3()
|
||||
luaunit.assertFalse(is_queen_threat("B4", "F3"))
|
||||
luaunit.assertFalse(is_queen_threat("B4", "F3"))
|
||||
end
|
||||
|
||||
function test_E2_does_not_threaten_G1()
|
||||
luaunit.assertFalse(is_queen_threat("E2", "G1"))
|
||||
luaunit.assertFalse(is_queen_threat("E2", "G1"))
|
||||
end
|
||||
|
||||
function test_A8_does_not_threaten_G3()
|
||||
luaunit.assertFalse(is_queen_threat("A8", "G3"))
|
||||
luaunit.assertFalse(is_queen_threat("A8", "G3"))
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
-- Give the colours whatever values are convenient
|
||||
black = undefined
|
||||
brown = undefined
|
||||
@@ -15,7 +14,7 @@ gold = undefined
|
||||
silver = undefined
|
||||
|
||||
function decode_resistance(colours)
|
||||
-- Your implementation here
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
@@ -23,28 +22,28 @@ end
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_violet_orange_black_is_73_ohms()
|
||||
local resistance = decode_resistance({violet, orange, black})
|
||||
luaunit.assertEquals(resistance, 73)
|
||||
local resistance = decode_resistance({violet, orange, black})
|
||||
luaunit.assertEquals(resistance, 73)
|
||||
end
|
||||
|
||||
function test_brown_green_black_is_15_ohms()
|
||||
local resistance = decode_resistance({brown, green, black})
|
||||
luaunit.assertEquals(resistance, 15)
|
||||
local resistance = decode_resistance({brown, green, black})
|
||||
luaunit.assertEquals(resistance, 15)
|
||||
end
|
||||
|
||||
function test_green_blue_orange_is_56_kiloohms()
|
||||
local resistance = decode_resistance({green, blue, orange})
|
||||
luaunit.assertEquals(resistance, 56000)
|
||||
local resistance = decode_resistance({green, blue, orange})
|
||||
luaunit.assertEquals(resistance, 56000)
|
||||
end
|
||||
|
||||
function test_white_yellow_yellow_is_940_kiloohms()
|
||||
local resistance = decode_resistance({white, yellow, yellow})
|
||||
luaunit.assertEquals(resistance, 940000)
|
||||
local resistance = decode_resistance({white, yellow, yellow})
|
||||
luaunit.assertEquals(resistance, 940000)
|
||||
end
|
||||
|
||||
function test_orange_red_silver_is_320_milliohms()
|
||||
local resistance = decode_resistance({orange, red, silver})
|
||||
luaunit.assertEquals(resistance, 0.32)
|
||||
local resistance = decode_resistance({orange, red, silver})
|
||||
luaunit.assertEquals(resistance, 0.32)
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
|
||||
Reference in New Issue
Block a user