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,5 +1,4 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function f()
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function is_anagram(str1, str2)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
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,5 +1,4 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function greatest_common_divisor(x, y)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function hamming_distance(str1, str2)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
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,5 +1,4 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function is_leap_year(year)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
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,5 +1,4 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function is_prime(x)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
function is_queen_threat(queen_position, pawn_position)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
-- Solution --------------------------------------------------------------------
|
||||
|
||||
-- Give the colours whatever values are convenient
|
||||
black = undefined
|
||||
brown = undefined
|
||||
|
||||
Reference in New Issue
Block a user