├── .gitattributes ├── src ├── _8kyu │ ├── _8kyu_opposite_number │ │ ├── opposite_test.py │ │ ├── opposite.py │ │ └── README.md │ ├── _8kyu_multiply_two_numbers │ │ └── multiply.py │ ├── _8kyu_will_you_make_it │ │ ├── kata.rb │ │ ├── kata.jl │ │ ├── kata.py │ │ ├── kata_test.py │ │ ├── kata_test.rb │ │ ├── kata.js │ │ ├── kata.rs │ │ ├── Kata.ts │ │ ├── kata.cpp │ │ ├── kata.c │ │ ├── kata.cfm │ │ ├── kata_test.jl │ │ ├── Kata.cs │ │ ├── kata_test.cpp │ │ ├── kata_test.rs │ │ ├── Kata.java │ │ ├── kata_test.js │ │ ├── KataTest.cs │ │ ├── KataTest.java │ │ ├── kata_test.c │ │ ├── KataTest.ts │ │ ├── kata_test.cfm │ │ └── README.md │ ├── _8kyu_area_of_perimeter │ │ ├── area_of_perimeter.py │ │ ├── area_of_perimeter_test.py │ │ └── README.md │ ├── _8kyu_makeuppercase │ │ ├── README.md │ │ ├── MakeUpperCase.java │ │ └── MakeUpperCaseTest.java │ ├── _8kyu_beginner_series_cockroach │ │ ├── cockroach_test.py │ │ ├── cockroach.py │ │ └── README.md │ ├── _8kyu_is_the_date_today │ │ ├── IsTheDateToday.groovy │ │ ├── README.md │ │ └── IsTheDateTodayTest.groovy │ ├── _8kyu_incorrect_division_method │ │ ├── divide_numbers.rb │ │ ├── README.md │ │ └── divide_numbers_test.rb │ ├── _8kyu_reversed_strings │ │ ├── README.md │ │ ├── ReversedStringsTest.java │ │ └── ReversedStrings.java │ ├── _8kyu_even_or_odd │ │ ├── README.md │ │ ├── EvenOrOdd.java │ │ └── EvenOrOddTest.java │ ├── _8kyu_sum_mixed_array │ │ ├── README.md │ │ └── SumMixedArray.java │ ├── _8kyu_square_n_sum │ │ ├── README.md │ │ ├── SquareNSumTest.java │ │ └── SquareNSum.java │ ├── _8kyu_third_angle_of_a_triangle │ │ ├── README.md │ │ ├── ThirdAngle.java │ │ └── ThirdAngleTest.java │ ├── _8kyu_enumerable_magic_number_25_take_the_first_n_elements │ │ ├── README.md │ │ └── take.js │ ├── _8kyu_array_plus_array │ │ ├── README.md │ │ ├── ArrayPlusArray.java │ │ └── ArrayPlusArrayTest.java │ ├── _8kyu_get_nth_even_number │ │ ├── README.md │ │ ├── Num.java │ │ └── NumTest.java │ ├── _8kyu_no-loops-2-you-only-need-one │ │ ├── no_loops_2_test.py │ │ ├── no_loops_2.py │ │ └── README.md │ ├── _8kyu_convert_a_number_to_a_string │ │ ├── README.md │ │ ├── ConvertNumberToString.java │ │ └── ConvertNumberToStringTest.java │ ├── _8kyu_remove_first_and_last_character │ │ ├── README.md │ │ ├── RemoveChars.java │ │ └── RemoveCharsTest.java │ ├── _8kyu_convert_number_to_reversed_array_of_digits │ │ ├── README.md │ │ └── DigitizeTest.java │ ├── _8kyu_grasshopper_summation │ │ ├── README.md │ │ ├── SummationTest.java │ │ └── Summation.java │ ├── _8kyu_easy_sql_ordering │ │ ├── easy_sql_ordering.sql │ │ ├── README.md │ │ └── easy_sql_ordering_test.rb │ ├── _8kyu_rearrange_integer_into_largest_possible │ │ ├── README.md │ │ ├── RearrangeIntegerIntoLargestPossible.js │ │ └── RearrangeIntegerIntoLargestPossibleTest.js │ ├── _8kyu_keep_hydrated │ │ ├── KeepHydrated.js │ │ ├── README.md │ │ └── KeepHydratedTest.js │ ├── _8kyu_grasshopper_terminal_game_move_function │ │ ├── README.md │ │ └── teminal_game_move.py │ ├── _8kyu_find_the_first_non_consecutive_number │ │ ├── find_the_first_non_consecutive_number_test.py │ │ ├── README.md │ │ └── find_the_first_non_consecutive_number.py │ ├── _8kyu_grasshopper_messi_goals_function │ │ ├── README.md │ │ └── messiGoals.js │ ├── _8kyu_l1_set_alarm │ │ ├── SetAlarmTest.java │ │ ├── README.md │ │ └── SetAlarm.java │ ├── _8kyu_101_dalmatians_squash_the_bugs_not_the_dogs │ │ ├── README.md │ │ └── HowManyDalmatians.js │ ├── _8kyu_odder_than_the_rest │ │ ├── README.md │ │ └── OdderThanTheRest.js │ ├── _8kyu_century_from_year │ │ ├── CenturyFromYearTest.java │ │ ├── README.md │ │ └── CenturyFromYear.java │ ├── _8kyu_is_n_divisible_by_x_and_y │ │ ├── README.md │ │ ├── IsNDivisible.kt │ │ └── IsNDivisibleTest.kt │ ├── _8kyu_counting_sheep_dot_dot_dot │ │ ├── CounterTest.java │ │ ├── README.md │ │ └── Counter.java │ ├── _8kyu_a_needle_in_the_haystack │ │ ├── README.md │ │ ├── NeedleExampleTests.java │ │ └── NeedleInTheHaystack.java │ ├── _8kyu_simple_fun_number_1_seats_in_theater │ │ └── NumberTest.java │ ├── _8kyu_count_the_monkeys │ │ ├── README.md │ │ ├── MonkeyCounterTest.java │ │ └── MonkeyCounter.java │ ├── _8kyu_convert_a_string_to_a_number │ │ ├── README.md │ │ ├── ConvertStringToNumber.java │ │ └── ConvertStringToNumberTest.java │ ├── _8kyu_check_for_factor │ │ ├── CheckForFactorTest.kt │ │ ├── README.md │ │ └── CheckForFactor.kt │ ├── _8kyu_correct_the_mistakes_of_the_character_recognition_software │ │ ├── README.md │ │ └── CorrectMistakes.java │ ├── _8kyu_difference_of_volumes_of_cuboids │ │ └── README.md │ ├── _8kyu_how_many_lightsabers_do_you_own │ │ ├── README.md │ │ └── HowManyLightSabersDoYouOwn.js │ └── _8kyu_classic_hello_world │ │ ├── README.md │ │ └── HelloWorld.java ├── _6kyu │ ├── _6kyu_backspaces_in_string │ │ ├── BackspacesInStringTest.js │ │ ├── README.md │ │ └── BackspacesInString.js │ ├── _6kyu_sql_basics_simple_in │ │ ├── simple_in.sql │ │ ├── README.md │ │ └── simple_in_test.rb │ ├── _6kyu_break_camel_case │ │ ├── break_camel_case_test.py │ │ ├── README.md │ │ └── break_camel_case.py │ ├── _6kyu_sql_bug_fixing_totaling │ │ ├── totaling_test.rb │ │ ├── totaling.sql │ │ └── README.md │ ├── _6kyu_find_the_odd_int │ │ ├── README.md │ │ ├── FindTheOddIntTest.java │ │ └── FindTheOddInt.java │ ├── _6kyu_split_strings │ │ ├── split_strings_test.py │ │ ├── README.md │ │ └── split_strings.py │ ├── _6kyu_sql_basics_simple_table_totaling │ │ ├── simple_table_totaling.sql │ │ ├── simple_table_totaling_test.rb │ │ └── README.md │ ├── _6kyu_multiples_of_3_or_5 │ │ ├── MultiplesTest.java │ │ ├── README.md │ │ └── Multiples.java │ ├── _6kyu_bit_counting │ │ ├── README.md │ │ ├── BitCountingTest.java │ │ └── BitCounting.java │ ├── _6kyu_sql_basics_simple_having │ │ ├── simple_having_test.rb │ │ ├── simple_having.sql │ │ └── README.md │ ├── _6kyu_are_they_the_same │ │ └── AreTheyTheSameTest.java │ ├── _6kyu_calculate_number_of_inversions_in_array │ │ ├── CalculateTest.cs │ │ ├── README.md │ │ └── Calculate.cs │ ├── _6kyu_find_the_missing_letter │ │ ├── FindMissingLetterTest.java │ │ ├── README.md │ │ └── FindMissingLetter.java │ ├── _6kyu_camelcase_method │ │ ├── README.md │ │ ├── CamelCaseMethod.java │ │ └── CamelCaseMethodTest.java │ ├── _6kyu_detect_pangram │ │ ├── README.md │ │ ├── PangramCheckerTest.java │ │ └── PangramChecker.java │ ├── _6kyu_highest_scoring_word │ │ ├── README.md │ │ ├── HighestScoringWordTest.java │ │ ├── HighestScoringWordTest.cs │ │ ├── HighestScoringWord.cs │ │ └── HighestScoringWord.java │ ├── _6kyu_new_cashier_does_not_know_about_space_or_shift │ │ ├── NewCashierTest.cs │ │ └── README.md │ ├── _6kyu_row_of_the_odd_triangle │ │ ├── odd_row.py │ │ ├── README.md │ │ └── odd_row_test.py │ ├── _6kyu_find_the_parity_outlier │ │ ├── FindTheParityOutlierTest.kt │ │ └── README.md │ ├── _6kyu_primorial_of_a_number │ │ └── PrimorialOfNumberTest.java │ ├── _6kyu_circularly_sorted_array │ │ ├── CircularlySortedArrayTest.java │ │ └── README.md │ ├── _6kyu_sql_basics_simple_exists │ │ ├── README.md │ │ ├── simple_exists.sql │ │ └── simple_exists_test.rb │ ├── _6kyu_counting_duplicates │ │ └── README.md │ ├── _6kyu_meeting │ │ └── README.md │ └── _6kyu_linked_lists_length_and_count │ │ └── length_and_count_test.py ├── _7kyu │ ├── _7kyu_sum_of_angles │ │ ├── README.md │ │ ├── AngleSum.java │ │ └── AngleSumTest.java │ ├── _7kyu_sql_with_lotr_elven_wildcards │ │ ├── sql_with_lotr_elven_wildcards.sql │ │ ├── test.rb │ │ └── README.md │ ├── _7kyu_help_bob_count_letters_and_digits │ │ ├── BobTest.cs │ │ ├── README.md │ │ └── Bob.cs │ ├── _7kyu_by_3_or_not_by_3_that_is_the_question │ │ ├── By3OrNotBy3.cs │ │ ├── By3OrNotBy3Test.cs │ │ └── README.md │ ├── _7kyu_spacify │ │ ├── README.md │ │ ├── Spacify.java │ │ └── SpacifyTest.java │ ├── _7kyu_odd_or_even │ │ ├── OddOrEvenTest.java │ │ ├── README.md │ │ └── OddOrEven.java │ ├── _7kyu_vowel_count │ │ ├── README.md │ │ ├── VowelCountTest.kt │ │ └── VowelCount.kt │ ├── _7kyu_no_oddities_here │ │ ├── NoOdditiesTest.cs │ │ ├── README.md │ │ └── NoOddities.cs │ ├── _7kyu_square_every_digit │ │ ├── README.md │ │ ├── SquareDigitTest.java │ │ └── SquareDigit.java │ ├── _7kyu_unlucky_days │ │ ├── UnluckyDaysTest.java │ │ ├── README.md │ │ └── UnluckyDays.java │ ├── _7kyu_string_ends_with │ │ ├── README.md │ │ ├── StringEndsWithTest.java │ │ └── StringEndsWith.java │ ├── _7kyu_recursion_number_1_factorial │ │ ├── FactorialTest.cs │ │ ├── FactorialTest.js │ │ ├── Factorial.js │ │ ├── README.md │ │ └── Factorial.cs │ ├── _7kyu_remove_duplicate_words │ │ ├── README.md │ │ ├── RemoveDuplicateWordsTest.java │ │ └── RemoveDuplicateWords.java │ ├── _7kyu_sum_of_minimums │ │ ├── SumOfMinimumsTest.js │ │ ├── README.md │ │ └── SumOfMinimums.js │ ├── _7kyu_sum_of_odd_numbers │ │ ├── SumOfOddNumbersTest.java │ │ ├── README.md │ │ └── SumOfOddNumbers.java │ ├── _7kyu_recursion_number_2_fibonacci │ │ ├── FibonacciTest.js │ │ ├── README.md │ │ └── Fibonacci.js │ ├── _7kyu_sum_even_numbers │ │ ├── README.md │ │ └── SumEvenNumbers.js │ ├── _7kyu_calculate_two_peoples_individual_ages │ │ ├── README.md │ │ └── CalculateTwoPeoplesIndividualAges.js │ ├── _7kyu_number_of_occurrences │ │ ├── README.md │ │ ├── OccurrencesKata.cs │ │ └── OccurrencesKataTests.cs │ ├── _7kyu_no-loops-1-small-enough │ │ ├── no_loops_1_test.py │ │ ├── no_loops_1.py │ │ └── README.md │ ├── _7kyu_java_functional_programming_closured_for_business │ │ └── AdderFactoryTest.java │ ├── _7kyu_drying_potatoes │ │ ├── PotatoesTest.java │ │ └── README.md │ ├── _7kyu_exes_and_ohs │ │ ├── README.md │ │ ├── ExesAndOhs.java │ │ └── ExesAndOhsTest.java │ ├── _7kyu_growth_of_a_population │ │ └── ArgeTest.java │ ├── _7kyu_java_functional_programming_the_beginning │ │ ├── FunctionalProgrammingTest.java │ │ └── Student.java │ ├── _7kyu_java_functional_programming_multiline_functions │ │ ├── Triangle.java │ │ └── FunctionalProgrammingTest.java │ ├── _7kyu_longest_vowel_chain │ │ ├── README.md │ │ └── longestVowelChain.js │ ├── _7kyu_leap_years │ │ ├── README.md │ │ └── LeapYears.js │ ├── _7kyu_1st_day_of_month_that_are_sunday_in_a_year_range │ │ └── README.md │ ├── _7kyu_sql_basics_simple_join_with_count │ │ ├── simple_join_with_count_test.rb │ │ ├── README.md │ │ └── simple_join_with_count.sql │ ├── _7kyu_form_the_minimum │ │ ├── FormTheMinimumTest.java │ │ ├── README.md │ │ └── FormTheMinimum.java │ ├── _7kyu_flatten_and_sort_an_array │ │ ├── README.md │ │ ├── FlattenAndSort.java │ │ └── FlattenAndSortTest.java │ ├── _7kyu_maximum_multiple │ │ ├── MaxMultipleTest.java │ │ └── README.md │ └── _7kyu_strong_number │ │ └── StrongNumberTest.java ├── _4kyu │ ├── _4kyu_sum_strings_as_numbers │ │ ├── SumStringsAsNumbersTest.cs │ │ ├── README.md │ │ └── SumStringsAsNumbers.cs │ ├── _4kyu_adding_big_numbers │ │ ├── BigNumbersAdderTest.cs │ │ ├── README.md │ │ └── BigNumbersAdder.cs │ ├── _4kyu_range_extraction │ │ ├── RangeExtractionTest.java │ │ └── README.md │ ├── _4kyu_strip_comments │ │ ├── StripCommentsTest.java │ │ └── README.md │ ├── _4kyu_human_readable_duration_format │ │ └── TimeFormatterTest.java │ └── _4kyu_pyramind_slide_down │ │ └── longest_slide_down_test.py └── _5kyu │ ├── _5kyu_moving_zeros_to_the_end │ ├── MovingZerosToTheEndTest.cs │ ├── README.md │ └── MovingZerosToTheEnd.cs │ ├── _5kyu_sql_basics_group_by_day │ ├── group_by_day_test.rb │ ├── README.md │ └── group_by_day.sql │ ├── _5kyu_human_readable_time │ ├── README.md │ ├── HumanReadableTime.java │ └── HumanReadableTimeTest.java │ ├── _5kyu_mean_square_error │ ├── MeanSquareTest.cs │ ├── README.md │ └── MeanSquare.cs │ └── _5kyu_is_my_friend_cheating │ └── IsMyFriendCheatingTest.java └── create_dir.py /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sql linguist-detectable=true -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_opposite_number/opposite_test.py: -------------------------------------------------------------------------------- 1 | test.assert_equals(opposite(1),-1) -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_multiply_two_numbers/multiply.py: -------------------------------------------------------------------------------- 1 | def multiply(x, y): 2 | return x * y 3 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata.rb: -------------------------------------------------------------------------------- 1 | def zero_fuel(distance, mpg, fuel_left) 2 | return mpg * fuel_left >= distance; 3 | end -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata.jl: -------------------------------------------------------------------------------- 1 | function zerofuel(distancetopump, mpg, fuelleft) 2 | return mpg * fuelleft >= distancetopump; 3 | end -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata.py: -------------------------------------------------------------------------------- 1 | def zero_fuel(distance_to_pump, mpg, fuel_left): 2 | return mpg * fuel_left >= distance_to_pump -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_area_of_perimeter/area_of_perimeter.py: -------------------------------------------------------------------------------- 1 | def area_or_perimeter(l, w): 2 | if l == w: return l * w 3 | return 2 * l + 2 * w 4 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata_test.py: -------------------------------------------------------------------------------- 1 | test.assert_equals(zero_fuel(50, 25, 2), True) 2 | test.assert_equals(zero_fuel(100, 50, 1), False) -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata_test.rb: -------------------------------------------------------------------------------- 1 | Test.assert_equals(zero_fuel(50, 25, 2), true) 2 | Test.assert_equals(zero_fuel(100, 50, 1), false) -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata.js: -------------------------------------------------------------------------------- 1 | const zeroFuel = (distanceToPump, mpg, fuelLeft) => { 2 | return mpg * fuelLeft >= distanceToPump; 3 | }; -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_area_of_perimeter/area_of_perimeter_test.py: -------------------------------------------------------------------------------- 1 | Test.assert_equals(area_or_perimeter(4, 4), 16) 2 | Test.assert_equals(area_or_perimeter(6, 10), 32) -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata.rs: -------------------------------------------------------------------------------- 1 | fn zero_fuel(distance_to_pump: u32, mpg: u32, gallons: u32) -> bool { 2 | return mpg * gallons >= distance_to_pump; 3 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_backspaces_in_string/BackspacesInStringTest.js: -------------------------------------------------------------------------------- 1 | Test.assertEquals(cleanString('abc#d##c'), "ac"); 2 | Test.assertEquals(cleanString('abc####d##c#'), "" ); -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/Kata.ts: -------------------------------------------------------------------------------- 1 | export const zeroFuel = (distance: number, mpg: number, fuelLeft: number): boolean => { 2 | return mpg * fuelLeft >= distance; 3 | }; -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata.cpp: -------------------------------------------------------------------------------- 1 | bool zero_fuel(uint32_t distance_to_pump, uint32_t mpg, uint32_t fuel_left) 2 | { 3 | return mpg * fuel_left >= distance_to_pump; 4 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_makeuppercase/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/makeuppercase/ 4 | 5 | ## Instructions 6 | 7 | Write function makeUpperCase. -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_basics_simple_in/simple_in.sql: -------------------------------------------------------------------------------- 1 | SELECT id, name 2 | FROM departments d 3 | WHERE id IN (SELECT department_id 4 | FROM sales 5 | WHERE price >= 98.00); -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool zero_fuel(double distance_to_pump, double mpg, double fuel_left) 4 | { 5 | return mpg * fuel_left >= distance_to_pump; 6 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata.cfm: -------------------------------------------------------------------------------- 1 | component { 2 | 3 | function zeroFuel( numeric distanceToPump, numeric mpg, numeric fuelLeft ){ 4 | return mpg * fuelLeft >= distanceToPump; 5 | } 6 | 7 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_beginner_series_cockroach/cockroach_test.py: -------------------------------------------------------------------------------- 1 | test.describe("Basic Tests") 2 | test.assert_equals(cockroach_speed(1.08),30) 3 | test.assert_equals(cockroach_speed(1.09),30) 4 | test.assert_equals(cockroach_speed(0),0) -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_opposite_number/opposite.py: -------------------------------------------------------------------------------- 1 | """ 2 | Very simple, given a number, find its opposite. 3 | 4 | Examples: 5 | 6 | 1: -1 7 | 14: -14 8 | -34: 34 9 | """ 10 | 11 | def opposite(number): 12 | return -number -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata_test.jl: -------------------------------------------------------------------------------- 1 | using FactCheck 2 | 3 | facts("zerofuel") do 4 | context("Sample Tests") do 5 | @fact zerofuel(50, 25, 2) --> true 6 | @fact zerofuel(100, 50, 1) --> false 7 | end 8 | end -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sum_of_angles/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5a03b3f6a1c9040084001765/ 4 | 5 | ## Instructions 6 | 7 | Find the total sum of angles in an n sided shape. N will be greater than 2. 8 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/Kata.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class Kata 4 | { 5 | public static bool ZeroFuel(uint distanceToPump, uint mpg, uint fuelLeft) 6 | { 7 | return mpg * fuelLeft >= distanceToPump; 8 | } 9 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_break_camel_case/break_camel_case_test.py: -------------------------------------------------------------------------------- 1 | Test.assert_equals(solution("helloWorld"), "hello World") 2 | Test.assert_equals(solution("camelCase"), "camel Case") 3 | Test.assert_equals(solution("breakCamelCase"), "break Camel Case") 4 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sql_with_lotr_elven_wildcards/sql_with_lotr_elven_wildcards.sql: -------------------------------------------------------------------------------- 1 | --but on the land of Lórien no shadow lay-- 2 | SELECT INITCAP(CONCAT(firstname, ' ', lastname)) AS shortlist 3 | FROM elves 4 | WHERE firstname LIKE '%tegil%' OR lastname LIKE '%astar%'; -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_is_the_date_today/IsTheDateToday.groovy: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_is_the_date_today 2 | 3 | class IsTheDateToday { 4 | 5 | static Boolean isToday(date) { 6 | return new Date().format('yyyyMMdd').equals(date.format('yyyyMMdd')) 7 | } 8 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata_test.cpp: -------------------------------------------------------------------------------- 1 | Describe(zero_fuel_function) 2 | { 3 | It(should_pass_sample_tests) 4 | { 5 | Assert::That(zero_fuel(50, 25, 2), Equals(true)); 6 | Assert::That(zero_fuel(100, 50, 1), Equals(false)); 7 | } 8 | }; -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_incorrect_division_method/divide_numbers.rb: -------------------------------------------------------------------------------- 1 | # This method, which is supposed to return the result 2 | # of dividing its first argument by its second, 3 | # isn't always returning correct values. Fix it. 4 | 5 | def divide_numbers x, y 6 | x.fdiv(y) 7 | end -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_opposite_number/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/56dec885c54a926dcd001095/ 4 | 5 | ## Instructions 6 | 7 | Very simple, given a number, find its opposite. 8 | 9 | Examples: 10 | 11 | 1: -1 12 | 14: -14 13 | -34: 34 -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata_test.rs: -------------------------------------------------------------------------------- 1 | #[cfg(test)] 2 | mod tests { 3 | use super::zero_fuel; 4 | 5 | #[test] 6 | fn sample_tests() { 7 | assert_eq!(zero_fuel(50, 25, 2), true); 8 | assert_eq!(zero_fuel(100, 50, 1), false); 9 | } 10 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_reversed_strings/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5168bb5dfe9a00b126000018/ 4 | 5 | ## Instructions 6 | 7 | Complete the solution so that it reverses the string value passed into it. 8 | 9 | Kata.solution("world") //returns "dlrow" -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_help_bob_count_letters_and_digits/BobTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class BobTest 6 | { 7 | [Test] 8 | public void Test1() 9 | { 10 | Assert.AreEqual(7,Kata.CountLettersAndDigits("n!!ice!!123")); 11 | } 12 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_makeuppercase/MakeUpperCase.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_makeuppercase; 2 | 3 | /* 4 | Write function makeUpperCase. 5 | */ 6 | 7 | class MakeUpperCase { 8 | 9 | static String makeUpperCase(String str) { 10 | return str.toUpperCase(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/Kata.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_will_you_make_it; 2 | 3 | public class Kata { 4 | 5 | public static boolean zeroFuel(double distanceToPump, double mpg, double fuelLeft) { 6 | return mpg * fuelLeft >= distanceToPump; 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata_test.js: -------------------------------------------------------------------------------- 1 | const assert = require("chai").assert; 2 | 3 | describe("zeroFill", function() { 4 | it("Sample Tests", function() { 5 | assert.equal(zeroFuel(50, 25, 2), true); 6 | assert.equal(zeroFuel(100, 50, 1), false); 7 | }); 8 | }); -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_even_or_odd/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/even-or-odd/train/java/ 4 | 5 | ## Instructions 6 | 7 | Create a function (or write a script in Shell) that takes an integer as an argument and returns "Even" for even numbers or "Odd" for odd numbers. -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_bug_fixing_totaling/totaling_test.rb: -------------------------------------------------------------------------------- 1 | # DATA FOR TESTS IS AVAILABLE ONLY ON WEBSITE 2 | 3 | compare_with expected do 4 | draw_chart( 5 | type: :timeseries, 6 | group_by: :department, 7 | x: :day, 8 | y: :sale_count, 9 | sort: false 10 | ) 11 | end -------------------------------------------------------------------------------- /src/_4kyu/_4kyu_sum_strings_as_numbers/SumStringsAsNumbersTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | [TestFixture] 5 | public class SumStringsAsNumbersTest 6 | { 7 | [Test] 8 | public void Given123And456Returns579() 9 | { 10 | Assert.AreEqual("579",Kata.sumStrings("123","456")); 11 | } 12 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_sum_mixed_array/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/sum-mixed-array/ 4 | 5 | ## Instructions 6 | 7 | Given an array of integers as strings and numbers, return the sum of the array values as if all were numbers. 8 | 9 | Return your answer as a number. 10 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_find_the_odd_int/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/find-the-odd-int/ 4 | 5 | ## Instructions 6 | 7 | Given an array, find the int that appears an odd number of times. 8 | 9 | There will always be only one integer that appears an odd number of times. 10 | 11 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sum_of_angles/AngleSum.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_sum_of_angles; 2 | 3 | /* 4 | Find the total sum of angles in an n sided shape. N will be greater than 2. 5 | */ 6 | 7 | public class AngleSum { 8 | public static int sumOfAngles(int n) { 9 | return (n - 2) * 180; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_incorrect_division_method/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/incorrect-division-method/ 4 | 5 | ## Instructions 6 | 7 | This method, which is supposed to return the result of dividing its first argument by its second, isn't always returning correct values. Fix it. 8 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_split_strings/split_strings_test.py: -------------------------------------------------------------------------------- 1 | test.describe("Example Tests") 2 | 3 | tests = ( 4 | ("asdfadsf", ['as', 'df', 'ad', 'sf']), 5 | ("asdfads", ['as', 'df', 'ad', 's_']), 6 | ("", []), 7 | ("x", ["x_"]), 8 | ) 9 | 10 | for inp, exp in tests: 11 | test.assert_equals(split_strings(inp), exp) -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_basics_simple_table_totaling/simple_table_totaling.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | RANK() OVER (ORDER BY SUM(points) DESC) AS rank, 3 | COALESCE(NULLIF(clan, ''), '[no clan specified]') AS clan, 4 | SUM(points) as total_points, 5 | COUNT(name) as total_people 6 | FROM people 7 | GROUP BY clan; -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_square_n_sum/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/square-n-sum/ 4 | 5 | ## Instructions 6 | 7 | Complete the square sum function so that it squares each number passed into it and then sums the results together. 8 | 9 | For example, for [1, 2, 2] it should return 9 because 1^2 + 2^2 + 2^2 = 9. -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_third_angle_of_a_triangle/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/third-angle-of-a-triangle/ 4 | 5 | ## Instructions 6 | 7 | You are given two angles (in degrees) of a triangle. 8 | 9 | Write a function to return the 3rd. 10 | 11 | Note: only positive integers will be tested. 12 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_break_camel_case/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/break-camelcase/ 4 | 5 | ## Instructions 6 | 7 | Complete the solution so that the function will 8 | break up camel casing, using a space between words. 9 | 10 | Example 11 | ``` 12 | solution("camelCasing") == "camel Casing" 13 | ``` -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_break_camel_case/break_camel_case.py: -------------------------------------------------------------------------------- 1 | """ 2 | Complete the solution so that the function will 3 | break up camel casing, using a space between words. 4 | 5 | Example 6 | 7 | solution("camelCasing") == "camel Casing" 8 | 9 | """ 10 | 11 | def break_camel_case(s): 12 | return ''.join(' ' + c if c.isupper() else c for c in s) -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_by_3_or_not_by_3_that_is_the_question/By3OrNotBy3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class By3OrNotBy3 4 | { 5 | public static bool DivisibleByThree(string n) 6 | { 7 | int sum = 0; 8 | for (int i = 0; i < n.Length; ++i) { 9 | sum += n[i] - '0'; 10 | } 11 | 12 | return sum % 3 == 0; 13 | } 14 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_spacify/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/spacify/train/java/ 4 | 5 | ## Instructions 6 | 7 | Modify the spacify function so that it returns the given string with spaces insertedbetween each character. 8 | 9 | ```java 10 | spacify("hello world") // returns "h e l l o w o r l d" 11 | ``` -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_odd_or_even/OddOrEvenTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_odd_or_even; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | public class OddOrEvenTest { 8 | 9 | @Test 10 | public void exampleTest() { 11 | assertEquals("odd", OddOrEven.oddOrEven(new int[]{2, 5, 34, 6})); 12 | } 13 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_vowel_count/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/54ff3102c1bad923760001f3/ 4 | 5 | ## Instructions 6 | 7 | Return the number (count) of vowels in the given string. 8 | 9 | We will consider a, e, i, o, and u as vowels for this Kata. 10 | 11 | The input string will only consist of lower case letters and/or spaces.a -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_multiples_of_3_or_5/MultiplesTest.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_multiples_of_3_or_5; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | public class MultiplesTest { 8 | 9 | @Test 10 | public void test() { 11 | assertEquals(23, new Multiples().solution(10)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_no_oddities_here/NoOdditiesTest.cs: -------------------------------------------------------------------------------- 1 | namespace Solution 2 | { 3 | using NUnit.Framework; 4 | using System.Linq; 5 | 6 | [TestFixture] 7 | public class NoOdditiesTest 8 | { 9 | [Test] 10 | public void OneThroughFive() 11 | { 12 | Assert.AreEqual(new int[]{2,4}, NoOddities.NoOdds(new int[]{1,2,3,4,5})); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_enumerable_magic_number_25_take_the_first_n_elements/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/enumerable-magic-number-25-take-the-first-n-elements/train/javascript 4 | 5 | ## Instructions 6 | 7 | Create a method take that accepts a list/array and a number n, and returns a list/array array of the first n elements from the list/array. 8 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_makeuppercase/MakeUpperCaseTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_makeuppercase; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class MakeUpperCaseTest { 8 | 9 | @Test 10 | void testSomething() { 11 | assertEquals("HELLO", MakeUpperCase.makeUpperCase("hello")); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_array_plus_array/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5a2be17aee1aaefe2a000151 4 | 5 | ## Instructions 6 | 7 | I'm new to coding and now I want to get the sum of two arrays...actually the sum of all their elements. I'll appreciate for your help. 8 | 9 | P.S. Each array includes only integer numbers. Output is a number too. 10 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sum_of_angles/AngleSumTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_sum_of_angles; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class AngleSumTest { 8 | 9 | @Test 10 | public void sampleTests() { 11 | assertEquals(AngleSum.sumOfAngles(3), 180); 12 | assertEquals(AngleSum.sumOfAngles(4), 360); 13 | } 14 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_vowel_count/VowelCountTest.kt: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_vowel_count 2 | 3 | import org.junit.Test 4 | import org.junit.Assert.assertEquals 5 | 6 | class TestExample { 7 | 8 | @Test 9 | fun testFixed() { 10 | assertEquals(5, getCount("abracadabra")) 11 | assertEquals(1, getCount("test")) 12 | assertEquals(3, getCount("example")) 13 | } 14 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_get_nth_even_number/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/get-nth-even-number/ 4 | 5 | ## Instructions 6 | 7 | Return the Nth Even Number 8 | 9 | ```java 10 | nthEven(1) //=> 0, the first even number is 0 11 | nthEven(3) //=> 4, the 3rd even number is 4 (0, 2, 4) 12 | 13 | nthEven(100) //=> 198 14 | nthEven(1298734) //=> 2597466 15 | ``` -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_is_the_date_today/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/is-the-date-today/ 4 | 5 | ## Instructions 6 | 7 | Write a simple function that takes as a parameter a date object and returns a boolean value representing whether the date is today or not. 8 | 9 | Make sure that your function does not return a false positive by just checking just the day. -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/KataTest.cs: -------------------------------------------------------------------------------- 1 | namespace Solution 2 | { 3 | using NUnit.Framework; 4 | using System; 5 | 6 | [TestFixture] 7 | public class SolutionTest 8 | { 9 | [Test] 10 | public void SampleTest() 11 | { 12 | Assert.AreEqual(true, Kata.ZeroFuel(50, 25, 2)); 13 | Assert.AreEqual(false, Kata.ZeroFuel(100, 50, 1)); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_no_oddities_here/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/51fd6bc82bc150b28e0000ce/ 4 | 5 | ## Instructions 6 | 7 | Write a small function that returns the values of an array that are not odd. 8 | 9 | All values in the array will be integers. Return the good values in the order they are given. 10 | 11 | ``` 12 | NoOdds(int[] values) 13 | ``` -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_no-loops-2-you-only-need-one/no_loops_2_test.py: -------------------------------------------------------------------------------- 1 | @Test.describe("Sample Test Cases") 2 | def example_tests(): 3 | test.assert_equals(check([66, 101], 66), True) 4 | test.assert_equals(check([80, 117, 115, 104, 45, 85, 112, 115], 45), True) 5 | test.assert_equals(check(['t', 'e', 's', 't'], 'e'), True) 6 | test.assert_equals(check(['what', 'a', 'great', 'kata'], 'kat'), False) -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_vowel_count/VowelCount.kt: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_vowel_count 2 | 3 | /* 4 | Return the number (count) of vowels in the given string. 5 | 6 | We will consider a, e, i, o, and u as vowels for this Kata. 7 | 8 | The input string will only consist of lower case letters and/or spaces. 9 | */ 10 | 11 | fun getCount(str : String) : Int { 12 | return str.count{it in "aeiou"} 13 | } 14 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_even_or_odd/EvenOrOdd.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_even_or_odd; 2 | 3 | /* 4 | Create a function (or write a script in Shell) 5 | that takes an integer as an argument and returns 6 | "Even" for even numbers or "Odd" for odd numbers. 7 | */ 8 | 9 | class EvenOrOdd { 10 | static String evenOrOdd(int number) { 11 | return (number & 1) == 0 ? "Even" : "Odd"; 12 | } 13 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_reversed_strings/ReversedStringsTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_reversed_strings; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | public class ReversedStringsTest { 8 | 9 | @Test 10 | public void sampleTests() { 11 | assertEquals("dlrow", ReversedStrings.solution("world")); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/_5kyu/_5kyu_moving_zeros_to_the_end/MovingZerosToTheEndTest.cs: -------------------------------------------------------------------------------- 1 | namespace Solution 2 | { 3 | using NUnit.Framework; 4 | using System; 5 | 6 | [TestFixture] 7 | public class Sample_Test 8 | { 9 | [Test] 10 | public void Test() 11 | { 12 | Assert.AreEqual(new int[] {1, 2, 1, 1, 3, 1, 0, 0, 0, 0}, Kata.MoveZeroes(new int[] {1, 2, 0, 1, 0, 1, 0, 3, 0, 1})); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_help_bob_count_letters_and_digits/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5738f5ea9545204cec000155/ 4 | 5 | ## Instructions 6 | 7 | Bob is a lazy man. 8 | 9 | He needs you to create a method that can determine how many letters and digits are in a given string. 10 | 11 | Example: 12 | 13 | "hel2!lo" --> 6 14 | 15 | "wicked .. !" --> 6 16 | 17 | "!?..A" --> 1 -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_spacify/Spacify.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_spacify; 2 | 3 | /* 4 | Modify the spacify function so that it returns the given string with spaces insertedbetween each character. 5 | 6 | spacify("hello world") // returns "h e l l o w o r l d" 7 | */ 8 | 9 | class Spacify { 10 | 11 | static String spacify(String str) { 12 | return str.replace("", " ").trim(); 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_square_every_digit/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/square-every-digit/ 4 | 5 | ## Instructions 6 | 7 | Welcome. In this kata, you are asked to square every digit of a number. 8 | 9 | For example, if we run 9119 through the function, 811181 will come out, because 92 is 81 and 12 is 1. 10 | 11 | Note: The function accepts an integer and returns an integer -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_even_or_odd/EvenOrOddTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_even_or_odd; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class EvenOrOddTest { 8 | 9 | @Test 10 | void testEvenOrOdd() { 11 | assertEquals(EvenOrOdd.evenOrOdd(6), "Even"); 12 | assertEquals(EvenOrOdd.evenOrOdd(7), "Odd"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_reversed_strings/ReversedStrings.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_reversed_strings; 2 | 3 | /* 4 | Complete the solution so that it reverses the string value passed into it. 5 | 6 | Kata.solution("world") //returns "dlrow" 7 | */ 8 | public class ReversedStrings { 9 | 10 | public static String solution(String str) { 11 | return new StringBuilder(str).reverse().toString(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_unlucky_days/UnluckyDaysTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_unlucky_days; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class UnluckyDaysTest { 8 | 9 | @Test 10 | void testSomething() { 11 | assertEquals(3, UnluckyDays.unluckyDays(2015)); 12 | assertEquals(1, UnluckyDays.unluckyDays(1986)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_convert_a_number_to_a_string/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/convert-a-number-to-a-string/ 4 | 5 | ## Instructions 6 | 7 | We need a function that can transform a number into a string. 8 | 9 | What ways of achieving this do you know? 10 | ``` 11 | Examples: 12 | Kata.numberToString(123); // returns "123"; 13 | Kata.numberToString(999); // returns "999"; 14 | ``` -------------------------------------------------------------------------------- /src/_5kyu/_5kyu_moving_zeros_to_the_end/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/moving-zeros-to-the-end/ 4 | 5 | ## Instructions 6 | 7 | Write an algorithm that takes an array 8 | and moves all of the zeros to the end, 9 | preserving the order of the other elements. 10 | 11 | ``` 12 | Kata.MoveZeroes(new int[] {1, 2, 0, 1, 0, 1, 0, 3, 0, 1}) => new int[] {1, 2, 1, 1, 3, 1, 0, 0, 0, 0} 13 | ``` -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_string_ends_with/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/string-ends-with/train/java/ 4 | 5 | ## Instructions 6 | 7 | Complete the solution so that it returns true if the first argument(string) passed in ends with the 2nd argument (also a string). 8 | 9 | Examples: 10 | 11 | ```java 12 | solution('abc', 'bc') // returns true 13 | solution('abc', 'd') // returns false 14 | ``` -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_get_nth_even_number/Num.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_get_nth_even_number; 2 | 3 | /* 4 | Return the Nth Even Number 5 | 6 | nthEven(1) //=> 0, the first even number is 0 7 | nthEven(3) //=> 4, the 3rd even number is 4 (0, 2, 4) 8 | 9 | nthEven(100) //=> 198 10 | nthEven(1298734) //=> 2597466 11 | */ 12 | 13 | class Num { 14 | static int nthEven(int n) { 15 | return 2 * n - 2; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_remove_first_and_last_character/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/56bc28ad5bdaeb48760009b0 4 | 5 | ## Instructions 6 | 7 | It's pretty straightforward. 8 | Your goal is to create a function that removes the first and last characters of a string. 9 | You're given one parameter, the original string. 10 | You don't have to worry with strings with less than two characters. -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_third_angle_of_a_triangle/ThirdAngle.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_third_angle_of_a_triangle; 2 | 3 | /* 4 | You are given two angles (in degrees) of a triangle. 5 | 6 | Write a function to return the 3rd. 7 | 8 | Note: only positive integers will be tested. 9 | */ 10 | 11 | class ThirdAngle { 12 | 13 | static int otherAngle(int angle1, int angle2) { 14 | return 180 - angle1 - angle2; 15 | } 16 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_spacify/SpacifyTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_spacify; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class SpacifyTest { 8 | 9 | @Test 10 | void basicTest() { 11 | assertEquals("h e l l o w o r l d", Spacify.spacify("hello world")); 12 | assertEquals("1 2 3 4 5", Spacify.spacify("12345")); 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/KataTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_will_you_make_it; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertFalse; 6 | import static org.junit.Assert.assertTrue; 7 | 8 | public class KataTest { 9 | 10 | @Test 11 | public void testSomething() { 12 | assertTrue(Kata.zeroFuel(50, 25, 2)); 13 | assertFalse(Kata.zeroFuel(100, 50, 1)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void test_zero_fuel(double distance_to_pump, double mpg, double fuel_left, bool expected); 5 | 6 | Test(zero_fuel, should_pass_example_tests) 7 | { 8 | test_zero_fuel(50, 25, 2, true); 9 | test_zero_fuel(60, 30, 3, true); 10 | test_zero_fuel(70, 25, 1, false); 11 | test_zero_fuel(100, 25, 3, false); 12 | } 13 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_bit_counting/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/bit-counting/ 4 | 5 | ## Instructions 6 | 7 | Write a function that takes an integer as input, and returns the number of bits that are equal to one in the binary representation of that number. You can guarantee that input is non-negative. 8 | 9 | Example: The binary representation of 1234 is 10011010010, so the function should return 5 in this case -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_third_angle_of_a_triangle/ThirdAngleTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_third_angle_of_a_triangle; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class ThirdAngleTest { 8 | 9 | @Test 10 | void testOtherAngle() { 11 | assertEquals(123, ThirdAngle.otherAngle(45,12)); 12 | assertEquals(70, ThirdAngle.otherAngle(50,60)); 13 | } 14 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/KataTest.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import {zeroFuel} from "./solution"; 4 | import {assert} from "chai"; 5 | 6 | describe("zeroFill", function() { 7 | it("Sample Tests", function() { 8 | assert.equal(zeroFuel(50, 25, 2), true); 9 | assert.equal(zeroFuel(100, 50, 1), false); 10 | }); 11 | }); -------------------------------------------------------------------------------- /src/_4kyu/_4kyu_adding_big_numbers/BigNumbersAdderTest.cs: -------------------------------------------------------------------------------- 1 | namespace Solution { 2 | using NUnit.Framework; 3 | using System; 4 | 5 | [TestFixture] 6 | public class BigNumbersAdderTest 7 | { 8 | [Test] 9 | public void MyTest() 10 | { 11 | Assert.AreEqual("99999", Kata.Add("99998", "1")); 12 | Assert.AreEqual("999999999999999999999999999999", Kata.Add("999999999999999999999999999998", "1")); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_no_oddities_here/NoOddities.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | /* 4 | Write a small function that returns the values of an array that are not odd. 5 | 6 | All values in the array will be integers. Return the good values in the order they are given. 7 | 8 | NoOdds(int[] values) 9 | */ 10 | 11 | public class NoOddities 12 | { 13 | public static int[] NoOdds(int[] values) => 14 | values.Where(e => e % 2 == 0).ToArray(); 15 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_recursion_number_1_factorial/FactorialTest.cs: -------------------------------------------------------------------------------- 1 | namespace Solution { 2 | using NUnit.Framework; 3 | using System; 4 | 5 | [TestFixture] 6 | public class RecursionTests { [Test] 7 | public void BasicTests() { 8 | Assert.AreEqual(1, Recursion.Factorial(0)); 9 | Assert.AreEqual(1, Recursion.Factorial(1)); 10 | Assert.AreEqual(2, Recursion.Factorial(2)); 11 | Assert.AreEqual(6, Recursion.Factorial(3)); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_square_every_digit/SquareDigitTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_square_every_digit; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class SquareDigitTest { 8 | 9 | @Test 10 | void test() { 11 | assertEquals(811181, new SquareDigit().squareDigits(9119)); 12 | assertEquals(1444, new SquareDigit().squareDigits(1222)); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_remove_duplicate_words/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/remove-duplicate-words/ 4 | 5 | ## Instructions 6 | 7 | Your task is to remove all duplicate words from a string, leaving only single (first) words entries. 8 | 9 | Example: 10 | 11 | Input: 12 | 13 | 'alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta' 14 | 15 | Output: 16 | 17 | 'alpha beta gamma delta' 18 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_convert_number_to_reversed_array_of_digits/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5583090cbe83f4fd8c000051/ 4 | 5 | ## Instructions 6 | 7 | Convert number to reversed array of digits 8 | 9 | Given a random number: 10 | C#: long; 11 | C++: unsigned long; 12 | 13 | You have to return the digits of this number within an array in reverse order. 14 | 15 | Example: 16 | ``` 17 | 348597 => [7,9,5,8,4,3] 18 | ``` -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_grasshopper_summation/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/grasshopper-summation/ 4 | 5 | ## Instructions 6 | 7 | Summation 8 | 9 | Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0. 10 | 11 | For example: 12 | ``` 13 | summation(2) -> 3 14 | 1 + 2 15 | 16 | summation(8) -> 36 17 | 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 18 | ``` -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sum_of_minimums/SumOfMinimumsTest.js: -------------------------------------------------------------------------------- 1 | describe("Basic tests", () => { 2 | it("Testing for [[7, 9, 8, 6, 2], [6, 3, 5, 4, 3], [5, 8, 7, 4, 5]]", () => assert.strictEqual(sumOfMinimums([[7, 9, 8, 6, 2], [6, 3, 5, 4, 3], [5, 8, 7, 4, 5]]), 9)); 3 | it("Testing for [[11, 12, 14, 54], [67, 89, 90, 56], [7, 9, 4, 3], [9, 8, 6, 7]]", () => assert.strictEqual(sumOfMinimums([[11, 12, 14, 54], [67, 89, 90, 56], [7, 9, 4, 3], [9, 8, 6, 7]]), 76)); 4 | }); 5 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sum_of_odd_numbers/SumOfOddNumbersTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_sum_of_odd_numbers; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | 8 | class SumOfOddNumbersTest { 9 | 10 | @Test 11 | void test1() { 12 | assertEquals(1, SumOfOddNumbers.rowSumOddNumbers(1)); 13 | assertEquals(74088, SumOfOddNumbers.rowSumOddNumbers(42)); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_easy_sql_ordering/easy_sql_ordering.sql: -------------------------------------------------------------------------------- 1 | /* SQL */ 2 | /* 3 | Your task is to sort the information in the provided table 'companies' by number of employees (high to low). Returned table should be in the same format as provided: 4 | 5 | companies table schema 6 | 7 | id 8 | ceo 9 | motto 10 | employees 11 | 12 | Solution should use pure SQL. Ruby is only used in test cases. 13 | */ 14 | SELECT * FROM companies 15 | ORDER BY employees DESC 16 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_backspaces_in_string/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/backspaces-in-string/ 4 | 5 | ## Instructions 6 | 7 | Assume "#" is like a backspace in string. This means that string "a#bc#d" actually is "bd" 8 | 9 | Your task is to process a string with "#" symbols. 10 | 11 | Examples 12 | ``` 13 | "abc#d##c" ==> "ac" 14 | "abc##d######" ==> "" 15 | "#######" ==> "" 16 | "" ==> "" 17 | ``` -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_grasshopper_summation/SummationTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_grasshopper_summation; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class SummationTest { 8 | 9 | @Test 10 | void test1() { 11 | assertEquals(1, Summation.summation(1)); 12 | } 13 | 14 | @Test 15 | void test2() { 16 | assertEquals(36, Summation.summation(8)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/_4kyu/_4kyu_sum_strings_as_numbers/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5324945e2ece5e1f32000370/ 4 | 5 | ## Instructions 6 | 7 | Given the string representations of two integers, 8 | return the string representation of the sum of those integers. 9 | 10 | For example: 11 | 12 | ``` 13 | sumStrings('1','2') // => '3' 14 | ``` 15 | A string representation of an integer will contain 16 | no characters besides the ten numerals "0" to "9". -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_recursion_number_1_factorial/FactorialTest.js: -------------------------------------------------------------------------------- 1 | describe(`Basic tests`, _ => { 2 | it(`factorial(0)`, _ => { 3 | Test.assertEquals(factorial(0), 1); 4 | }); 5 | it(`factorial(1)`, _ => { 6 | Test.assertEquals(factorial(1), 1); 7 | }); 8 | it(`factorial(2)`, _ => { 9 | Test.assertEquals(factorial(2), 2); 10 | }); 11 | it(`factorial(3)`, _ => { 12 | Test.assertEquals(factorial(3), 6); 13 | }); 14 | }); -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_recursion_number_2_fibonacci/FibonacciTest.js: -------------------------------------------------------------------------------- 1 | describe(`Basic tests`, _ => { 2 | it(`fibonacci(1)`, _ => { 3 | Test.assertEquals(fibonacci(1), 1); 4 | }); 5 | it(`fibonacci(2)`, _ => { 6 | Test.assertEquals(fibonacci(2), 1); 7 | }); 8 | it(`fibonacci(3)`, _ => { 9 | Test.assertEquals(fibonacci(3), 2); 10 | }); 11 | it(`fibonacci(4)`, _ => { 12 | Test.assertEquals(fibonacci(4), 3); 13 | }); 14 | }); -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sum_even_numbers/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/sum-even-numbers/ 4 | 5 | ## Instructions 6 | 7 | Write a function named sumEvenNumbers, 8 | taking an array of integers as single parameter. Your function must return the sum of the even values of this array. 9 | 10 | For example, 11 | considering this input value: 12 | [4,3,1,2,5,10,6,7,9,8], 13 | then your function should return 30 (because 4 + 2 + 10 + 6 + 8 = 30). -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_easy_sql_ordering/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/593ed37c93350098d600001d/ 4 | 5 | ## Instructions 6 | 7 | Your task is to sort the information in the provided table 'companies' by number of employees (high to low). Returned table should be in the same format as provided: 8 | 9 | companies table schema 10 | 11 | id 12 | ceo 13 | motto 14 | employees 15 | Solution should use pure SQL. Ruby is only used in test cases. -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sql_with_lotr_elven_wildcards/test.rb: -------------------------------------------------------------------------------- 1 | results = run_sql 2 | 3 | describe :query do 4 | 5 | it "should contain SELECT" do 6 | expect($sql.upcase).to include("SELECT") 7 | end 8 | end 9 | 10 | describe :columns do 11 | it "should return 1 column" do 12 | expect(results.first.keys.count).to eq 1 13 | end 14 | it "should contain a shortlist column" do 15 | expect(results.first.keys).to include(:shortlist) 16 | end 17 | end -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_is_the_date_today/IsTheDateTodayTest.groovy: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_is_the_date_today 2 | 3 | import org.junit.jupiter.api.Test 4 | 5 | class IsTheDateTodayTest { 6 | 7 | @Test 8 | void "Fixed Tests" () { 9 | Date yesterday = new Date() - 1 10 | Date tomorrow = new Date() + 1 11 | assert IsTheDateToday.isToday(new Date()) 12 | assert !IsTheDateToday.isToday(tomorrow) 13 | assert !IsTheDateToday.isToday(yesterday) 14 | } 15 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_multiples_of_3_or_5/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/514b92a657cdc65150000006/ 4 | 5 | ## Instructions 6 | 7 | If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. 8 | 9 | Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in. 10 | 11 | Note: If the number is a multiple of both 3 and 5, only count it once. 12 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_basics_simple_having/simple_having_test.rb: -------------------------------------------------------------------------------- 1 | # DATA FOR TESTS IS AVAILABLE ONLY ON WEBSITE 2 | 3 | compare_with expected do 4 | spec do 5 | it "should contain HAVING" do 6 | expect($sql.upcase).to include("HAVING") 7 | end 8 | 9 | it "should contain GROUP BY" do 10 | expect($sql.upcase).to include("GROUP BY") 11 | end 12 | 13 | it "should contain not WHERE" do 14 | expect($sql.upcase).not_to include("WHERE") 15 | end 16 | end 17 | end -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_calculate_two_peoples_individual_ages/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/calculate-two-peoples-individual-ages/train/javascript/ 4 | 5 | ## Instructions 6 | 7 | Create a function that takes in the sum and age difference of two people, calculates their individual ages, and returns a pair of values if those exist or an empty values if: 8 | 9 | ```js 10 | sum < 0 11 | difference < 0 12 | Either of the calculated ages come out to be negative 13 | ``` -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_number_of_occurrences/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/52829c5fe08baf7edc00122b/ 4 | 5 | ## Instructions 6 | 7 | Write a function that returns the number of occurrences of an element in an array. 8 | 9 | Examples 10 | ```javascript 1.8 11 | var sample = { 1, 0, 2, 2, 3 }; 12 | NumberOfOccurrences(0, sample) == 1; 13 | NumberOfOccurrences(4, sample) == 0; 14 | NumberOfOccurrences(2, sample) == 2; 15 | NumberOfOccurrences(3, sample) == 1; 16 | ``` -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_rearrange_integer_into_largest_possible/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5709bdd2f088096786000008/ 4 | 5 | ## Instructions 6 | 7 | Write a function that rearranges an integer into its largest possible value. 8 | ``` 9 | superSize(123456) //654321 10 | superSize(105) // 510 11 | superSize(12) // 21 12 | ``` 13 | If the argument passed through is single digit or is already the maximum possible integer, 14 | your function should simply return it. -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_no-loops-1-small-enough/no_loops_1_test.py: -------------------------------------------------------------------------------- 1 | @test.describe('Fixed Tests') 2 | def fixed_tests(): 3 | 4 | @test.it('Example tests') 5 | def basic_tests(): 6 | test.assert_equals(small_enough([66, 101], 200), True) 7 | test.assert_equals(small_enough([78, 117, 110, 99, 104, 117, 107, 115], 100), False) 8 | test.assert_equals(small_enough([101, 45, 75, 105, 99, 107], 107), True) 9 | test.assert_equals(small_enough([80, 117, 115, 104, 45, 85, 112, 115], 120), True) -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_string_ends_with/StringEndsWithTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_string_ends_with; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertFalse; 6 | import static org.junit.jupiter.api.Assertions.assertTrue; 7 | 8 | class StringEndsWithTest { 9 | 10 | @Test 11 | void testSomething() { 12 | assertTrue(StringEndsWith.solution("abc", "bc")); 13 | assertFalse(StringEndsWith.solution("abc", "d")); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_convert_number_to_reversed_array_of_digits/DigitizeTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_convert_number_to_reversed_array_of_digits; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertArrayEquals; 6 | 7 | public class DigitizeTest { 8 | 9 | @Test 10 | public void tests() { 11 | assertArrayEquals(new int[]{1, 3, 2, 5, 3}, Digitize.digitize(35231)); 12 | assertArrayEquals(new int[]{1, 3, 2, 5, 3}, Digitize.digitize2(35231)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_square_n_sum/SquareNSumTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_square_n_sum; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class SquareNSumTest { 8 | 9 | @Test 10 | void testBasic() { 11 | assertEquals(9, SquareNSum.squareSum(new int[]{1, 2, 2})); 12 | assertEquals(5, SquareNSum.squareSum(new int[]{1, 2})); 13 | assertEquals(50, SquareNSum.squareSum(new int[]{5, -3, 4})); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/_5kyu/_5kyu_sql_basics_group_by_day/group_by_day_test.rb: -------------------------------------------------------------------------------- 1 | # DATA FOR TESTS IS AVAILABLE ONLY ON WEBSITE 2 | 3 | compare_with expected, show_daff_table: true do 4 | column(:day) do 5 | it "should start at the begining of the day" do 6 | expect(actual.first[:day]).to eq expected.first[:day].beginning_of_day 7 | end 8 | end 9 | 10 | rows do 11 | it "should be sorted from earliest to latest" do 12 | expect(actual.first[:day]).to be < actual.last[:day] 13 | end 14 | end 15 | end -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_by_3_or_not_by_3_that_is_the_question/By3OrNotBy3Test.cs: -------------------------------------------------------------------------------- 1 | namespace Solution 2 | { 3 | using NUnit.Framework; 4 | using System; 5 | 6 | [TestFixture] 7 | public class SolutionTest 8 | { 9 | [Test] 10 | public void SampleTest() 11 | { 12 | Assert.That(Kata.DivisibleByThree("1891009"), Is.EqualTo(false)); 13 | Assert.That(Kata.DivisibleByThree("00009"), Is.EqualTo(true)); 14 | Assert.That(Kata.DivisibleByThree("57"), Is.EqualTo(true)); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_are_they_the_same/AreTheyTheSameTest.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_are_they_the_same; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertTrue; 6 | 7 | public class AreTheyTheSameTest { 8 | 9 | @Test 10 | public void test1() { 11 | int[] a = new int[]{121, 144, 19, 161, 19, 144, 19, 11}; 12 | int[] b = new int[]{121, 14641, 20736, 361, 25921, 361, 20736, 361}; 13 | assertTrue(AreTheyTheSame.comp(a, b)); 14 | } 15 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_calculate_number_of_inversions_in_array/CalculateTest.cs: -------------------------------------------------------------------------------- 1 | namespace Solution 2 | { 3 | using NUnit.Framework; 4 | using System; 5 | 6 | [TestFixture] 7 | public class CalculateTest 8 | { 9 | [Test] 10 | public void BasicTests() 11 | { 12 | Assert.AreEqual(0, Kata.CountInversions(new int[] { 1, 2, 3 }), "Sorted array has 0 inversions"); 13 | Assert.AreEqual(1, Kata.CountInversions(new int[] { 2, 1, 3 }), "Array [2,1,3] only has one inversion"); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_beginner_series_cockroach/cockroach.py: -------------------------------------------------------------------------------- 1 | """ 2 | The cockroach is one of the fastest insects. 3 | 4 | Write a function which takes its speed in km per 5 | hour and returns it in cm per second, 6 | rounded down to the integer (= floored). 7 | 8 | For example: 9 | 10 | cockroach_speed(1.08) == 30 11 | 12 | Note! The input is a Real number 13 | (actual type is language dependent) and is >= 0. 14 | The result should be an Integer. 15 | """ 16 | 17 | def cockroach_speed(s): 18 | return s * 250 // 9 -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_java_functional_programming_closured_for_business/AdderFactoryTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_java_functional_programming_closured_for_business; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class AdderFactoryTest { 8 | 9 | @Test 10 | public void testMakeFunction() throws Exception { 11 | assertEquals("Created add 1 function; gave it 4; did not get 5 back", 12 | 5, AdderFactory.create(1).applyAsInt(4)); 13 | } 14 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_drying_potatoes/PotatoesTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_drying_potatoes; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class PotatoesTest { 8 | 9 | private static void doTest(int p0, int w0, int p1, int expected) { 10 | assertEquals(expected, Potatoes.potatoes(p0, w0, p1)); 11 | } 12 | 13 | @Test 14 | void test() { 15 | doTest(82, 127, 80, 114); 16 | doTest(93, 129, 91, 100); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_number_of_occurrences/OccurrencesKata.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | public class OccurrencesKata 5 | { 6 | public static int NumberOfOccurrences(int x, int[] xs) 7 | { 8 | return xs.Count(el => el == x); 9 | } 10 | 11 | public static int NumberOfOccurrences2(int x, int[] xs) 12 | { 13 | int counter = 0; 14 | for (int i = 0; i < xs.Length; ++i) { 15 | if (xs[i] == x) ++counter; 16 | } 17 | 18 | return counter; 19 | } 20 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_convert_a_number_to_a_string/ConvertNumberToString.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_convert_a_number_to_a_string; 2 | 3 | /* 4 | We need a function that can transform a number into a string. 5 | 6 | What ways of achieving this do you know? 7 | 8 | Examples: 9 | Kata.numberToString(123); // returns "123"; 10 | Kata.numberToString(999); // returns "999"; 11 | */ 12 | 13 | class ConvertNumberToString { 14 | 15 | static String numberToString(int num) { 16 | return String.valueOf(num); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_grasshopper_summation/Summation.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_grasshopper_summation; 2 | 3 | /* 4 | Summation 5 | Write a program that finds the summation of every number from 1 to num. 6 | The number will always be a positive integer greater than 0. 7 | 8 | For example: 9 | 10 | summation(2) -> 3 11 | 1 + 2 12 | 13 | summation(8) -> 36 14 | 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 15 | */ 16 | 17 | class Summation { 18 | 19 | static int summation(int n) { 20 | return (1 + n) * n / 2; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_incorrect_division_method/divide_numbers_test.rb: -------------------------------------------------------------------------------- 1 | describe 'Dividing numbers:' do 2 | Test.expect defined?(divide_numbers), 'divide_numbers is not defined' 3 | Test.assert_equals divide_numbers(4, 2), 2, '4 / 2' 4 | Test.assert_equals divide_numbers(10, 2), 5, '10 / 2' 5 | Test.assert_equals divide_numbers(9, 4), 2.25, '9 / 4' 6 | Test.assert_equals divide_numbers(21, 5), 4.2, '21 / 5' 7 | Test.assert_equals divide_numbers(9, 3), 3, '9 / 3' 8 | Test.assert_equals divide_numbers(1, 100), 0.01, '1 / 100' 9 | end -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_rearrange_integer_into_largest_possible/RearrangeIntegerIntoLargestPossible.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function that rearranges an integer into its largest possible value. 3 | 4 | superSize(123456) //654321 5 | superSize(105) // 510 6 | superSize(12) // 21 7 | 8 | If the argument passed through is single digit or is already the maximum possible integer, 9 | your function should simply return it. 10 | */ 11 | 12 | function superSize(num) { 13 | return parseInt(num.toString().split('').sort().reverse().join('')); 14 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_find_the_missing_letter/FindMissingLetterTest.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_find_the_missing_letter; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class FindMissingLetterTest { 8 | 9 | @Test 10 | void exampleTests() { 11 | assertEquals('e', FindMissingLetter.findMissingLetter(new char[]{'a', 'b', 'c', 'd', 'f'})); 12 | assertEquals('P', FindMissingLetter.findMissingLetter(new char[]{'O', 'Q', 'R', 'S'})); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_enumerable_magic_number_25_take_the_first_n_elements/take.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a method take that accepts a list/array and a number n, 3 | and returns a list/array array of the first n elements from the list/array. 4 | */ 5 | 6 | function take(arr, n) { 7 | return arr.slice(0, n); 8 | } 9 | 10 | describe("Sample Tests", function(){ 11 | it("should work for sample tests", function(){ 12 | Test.assertDeepEquals(take([0, 1, 2, 3, 5, 8, 13], 3), [0, 1, 2], "should return the first 3 items"); 13 | }); 14 | }); -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_get_nth_even_number/NumTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_get_nth_even_number; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class NumTest { 8 | 9 | @Test 10 | void exampleTests() { 11 | assertEquals(0, Num.nthEven(1)); 12 | assertEquals(2, Num.nthEven(2)); 13 | assertEquals(4, Num.nthEven(3)); 14 | assertEquals(198, Num.nthEven(100)); 15 | assertEquals(2597466, Num.nthEven(1298734)); 16 | } 17 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_keep_hydrated/KeepHydrated.js: -------------------------------------------------------------------------------- 1 | /* 2 | Nathan loves cycling. 3 | 4 | Because Nathan knows it is important to stay hydrated, he drinks 0.5 litres of water per hour of cycling. 5 | 6 | You get given the time in hours and you need to return the number of litres Nathan will drink, rounded to the smallest value. 7 | 8 | For example: 9 | 10 | time = 3 ----> litres = 1 11 | 12 | time = 6.7---> litres = 3 13 | 14 | time = 11.8--> litres = 5 15 | */ 16 | 17 | function litres(time) { 18 | return Math.floor(time / 2); 19 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_square_n_sum/SquareNSum.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_square_n_sum; 2 | 3 | import java.util.Arrays; 4 | 5 | /* 6 | Complete the square sum function so that it squares 7 | each number passed into it and then sums the results together. 8 | 9 | For example, for [1, 2, 2] it should return 9 because 1^2 + 2^2 + 2^2 = 9. 10 | */ 11 | 12 | class SquareNSum { 13 | 14 | static int squareSum(int[] n) { 15 | return Arrays.stream(n) 16 | .map(e -> e * e) 17 | .sum(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_camelcase_method/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/camelcase-method/ 4 | 5 | ## Instructions 6 | 7 | Write simple .camelCase method 8 | (camel_case function in PHP, 9 | CamelCase in C# 10 | or camelCase in Java) for strings. 11 | All words must have their first letter capitalized without spaces. 12 | 13 | For instance: 14 | ``` 15 | camelCase("hello case"); // => "HelloCase" 16 | camelCase("camel case word"); // => "CamelCaseWord" 17 | ``` 18 | Don't forget to rate this kata! Thanks :) -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_detect_pangram/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/detect-pangram 4 | 5 | ## Instructions 6 | 7 | A pangram is a sentence that contains every single letter of the alphabet at least once. 8 | For example, the sentence "The quick brown fox jumps over the lazy dog" is a pangram, 9 | because it uses the letters A-Z at least once (case is irrelevant). 10 | 11 | Given a string, detect whether or not it is a pangram. 12 | Return True if it is, False if not. Ignore numbers and punctuation. -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_exes_and_ohs/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/exes-and-ohs/train/java/ 4 | 5 | ## Instructions 6 | 7 | Check to see if a string has the same amount of 'x's and 'o's. The method must return a boolean and be case insensitive. The string can contain any char. 8 | 9 | Examples input/output: 10 | ```java 11 | XO("ooxx") => true 12 | XO("xooxx") => false 13 | XO("ooxXm") => true 14 | XO("zpzpzpp") => true // when no 'x' and 'o' is present should return true 15 | XO("zzoo") => false 16 | ``` -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_recursion_number_1_factorial/Factorial.js: -------------------------------------------------------------------------------- 1 | /* 2 | ##1 - Factorial 3 | 4 | In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 5 | 6 | 5! = 5 * 4 * 3 * 2 * 1 = 120. 7 | 8 | The value of 0! is 1. 9 | 10 | #Your task 11 | 12 | You have to create the function factorial that receives n and returns n!. You have to use recursion. 13 | */ 14 | 15 | const factorial = n => { 16 | return n === 0 ? 1 : n * factorial(n - 1); 17 | }; -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_recursion_number_2_fibonacci/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/recursion-number-2-fibonacci/ 4 | 5 | ## Instructions 6 | 7 | ##### 2 - Fibonacci number 8 | 9 | In mathematical terms, the sequence f(n) of fibonacci numbers is defined by the recurrence relation 10 | 11 | f(n) = f(n-1) + f(n-2) 12 | 13 | with seed values 14 | 15 | f(1) = 1 and f(2) = 1 16 | 17 | ##### Your task 18 | 19 | You have to create the function fibonacci that receives n and returns f(n). You have to use recursion. -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_string_ends_with/StringEndsWith.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_string_ends_with; 2 | 3 | /* 4 | Complete the solution so that it returns true if 5 | the first argument(string) passed in ends with the 2nd argument (also a string). 6 | 7 | Examples: 8 | 9 | solution('abc', 'bc') // returns true 10 | solution('abc', 'd') // returns false 11 | */ 12 | 13 | class StringEndsWith { 14 | 15 | public static boolean solution(String str, String ending) { 16 | return str != null && str.endsWith(ending); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_remove_first_and_last_character/RemoveChars.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_remove_first_and_last_character; 2 | 3 | /* 4 | It's pretty straightforward. 5 | Your goal is to create a function that removes the first and last characters of a string. 6 | You're given one parameter, the original string. 7 | You don't have to worry with strings with less than two characters. 8 | */ 9 | 10 | public class RemoveChars { 11 | public static String remove(String str) { 12 | return str.substring(1, str.length() - 1); 13 | } 14 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_bit_counting/BitCountingTest.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_bit_counting; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | class BitCountingTest { 8 | 9 | @Test 10 | public void testGame() { 11 | assertEquals(5, BitCounting.countBits(1234)); 12 | assertEquals(1, BitCounting.countBits(4)); 13 | assertEquals(3, BitCounting.countBits(7)); 14 | assertEquals(2, BitCounting.countBits(9)); 15 | assertEquals(2, BitCounting.countBits(10)); 16 | } 17 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_split_strings/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/split-strings/ 4 | 5 | ## Instructions 6 | 7 | Complete the solution so that it splits the string 8 | into pairs of two characters. 9 | If the string contains an odd number of 10 | characters then it should replace 11 | the missing second character of the final pair 12 | with an underscore ('_'). 13 | 14 | Examples: 15 | 16 | ``` 17 | solution('abc') # should return ['ab', 'c_'] 18 | solution('abcdef') # should return ['ab', 'cd', 'ef'] 19 | ``` -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_growth_of_a_population/ArgeTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_growth_of_a_population; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class ArgeTest { 8 | 9 | @Test 10 | void test() { 11 | System.out.println("Fixed Tests: nbYear"); 12 | assertEquals(Arge.nbYear(1500, 5, 100, 5000), 15); 13 | assertEquals(Arge.nbYear(1500000, 2.5, 10000, 2000000), 10); 14 | assertEquals(Arge.nbYear(1500000, 0.25, 1000, 2000000), 94); 15 | } 16 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_recursion_number_1_factorial/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/recursion-number-1-factorial/ 4 | 5 | ## Instructions 6 | 7 | 1 - Factorial 8 | 9 | In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 10 | 11 | 5! = 5 * 4 * 3 * 2 * 1 = 120. 12 | 13 | The value of 0! is 1. 14 | 15 | #Your task 16 | 17 | You have to create the function factorial that receives n and returns n!. You have to use recursion. -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sum_of_odd_numbers/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/sum-of-odd-numbers/java 4 | 5 | ## Instructions 6 | 7 | Given the triangle of consecutive odd numbers: 8 | ``` 9 | 1 10 | 3 5 11 | 7 9 11 12 | 13 15 17 19 13 | 21 23 25 27 29 14 | ... 15 | ``` 16 | 17 | Calculate the row sums of this triangle from the row index (starting at index 1) e.g.: 18 | 19 | ```java 20 | rowSumOddNumbers(1); // 1 21 | rowSumOddNumbers(2); // 3 + 5 = 8 22 | ``` -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_java_functional_programming_the_beginning/FunctionalProgrammingTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_java_functional_programming_the_beginning; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertTrue; 6 | 7 | public class FunctionalProgrammingTest { 8 | @Test 9 | public void testJohnSmith() throws Exception { 10 | Student jSmith = new Student("John", "Smith", "js123"); 11 | assertTrue("John Smith with student number js123 did not return true", FunctionalProgramming.f.apply(jSmith)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_unlucky_days/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/unlucky-days/ 4 | 5 | ## Instructions 6 | 7 | Friday 13th or Black Friday is considered as unlucky day. Calculate how many unlucky days are in the given year. 8 | 9 | Find the number of Friday 13th in the given year. 10 | 11 | Input: Year as an integer. 12 | 13 | Output: Number of Black Fridays in the year as an integer. 14 | 15 | Examples: 16 | ``` 17 | unluckyDays(2015) == 3 18 | unluckyDays(1986) == 1 19 | ``` 20 | Note: In Ruby years will start from 1593. -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_beginner_series_cockroach/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/55fab1ffda3e2e44f00000c6/ 4 | 5 | ## Instructions 6 | 7 | The cockroach is one of the fastest insects. 8 | 9 | Write a function which takes its speed in km per 10 | hour and returns it in cm per second, 11 | rounded down to the integer (= floored). 12 | 13 | For example: 14 | 15 | cockroach_speed(1.08) == 30 16 | 17 | Note! The input is a Real number 18 | (actual type is language dependent) and is >= 0. 19 | The result should be an Integer. -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_grasshopper_terminal_game_move_function/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/grasshopper-terminal-game-move-function/ 4 | 5 | ## Instructions 6 | 7 | Terminal game move function 8 | In this game, the hero moves from left to right. The player rolls the dice and moves the number of spaces indicated by the dice two times. 9 | 10 | Create a function for the terminal game that takes the current position of the hero and the roll (1-6) and return the new position. 11 | 12 | Example: 13 | move(3, 6) should equal 15 14 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_keep_hydrated/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/582cb0224e56e068d800003c/ 4 | 5 | ## Instructions 6 | 7 | Nathan loves cycling. 8 | 9 | Because Nathan knows it is important to stay hydrated, he drinks 0.5 litres of water per hour of cycling. 10 | 11 | You get given the time in hours and you need to return the number of litres Nathan will drink, rounded to the smallest value. 12 | 13 | For example: 14 | 15 | time = 3 ----> litres = 1 16 | 17 | time = 6.7---> litres = 3 18 | 19 | time = 11.8--> litres = 5 -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_array_plus_array/ArrayPlusArray.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_array_plus_array; 2 | 3 | import java.util.stream.IntStream; 4 | /* 5 | I'm new to coding and now I want to get the sum of two arrays...actually the sum of all their elements. 6 | I'll appreciate for your help. 7 | 8 | P.S. Each array includes only integer numbers. Output is a number too. 9 | */ 10 | public class ArrayPlusArray { 11 | 12 | public static int arrayPlusArray(int[] arr1, int[] arr2) { 13 | return IntStream.of(arr1).sum() + IntStream.of(arr2).sum(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_find_the_first_non_consecutive_number/find_the_first_non_consecutive_number_test.py: -------------------------------------------------------------------------------- 1 | Test.describe("Basic tests") 2 | Test.assert_equals(first_non_consecutive([1,2,3,4,6,7,8]), 6) 3 | Test.assert_equals(first_non_consecutive([1,2,3,4,5,6,7,8]), None) 4 | Test.assert_equals(first_non_consecutive([4,6,7,8,9,11]), 6) 5 | Test.assert_equals(first_non_consecutive([4,5,6,7,8,9,11]), 11) 6 | Test.assert_equals(first_non_consecutive([31,32]), None) 7 | Test.assert_equals(first_non_consecutive([-3,-2,0,1]), 0) 8 | Test.assert_equals(first_non_consecutive([-5,-4,-3,-1]), -1) -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_grasshopper_messi_goals_function/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/grasshopper-messi-goals-function/train/javascript/ 4 | 5 | ## Instructions 6 | 7 | Messi goals function 8 | Messi is a soccer player with goals in three leagues: 9 | 10 | LaLiga 11 | Copa del Rey 12 | Champions. 13 | Complete the goals function to return his total goals (the sum) for all three leagues. 14 | 15 | Note: the parameter for this function will always be a valid number. 16 | 17 | Ex : 18 | ```js 19 | goals(5,10,2) == 5+10+2 = 17 20 | ``` -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_java_functional_programming_multiline_functions/Triangle.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_java_functional_programming_multiline_functions; 2 | 3 | public class Triangle { 4 | 5 | public final int height; 6 | public final int base; 7 | private double area; 8 | 9 | public Triangle(int height, int base) { 10 | this.height = height; 11 | this.base = base; 12 | } 13 | 14 | public void setArea(double a) { 15 | area = a; 16 | } 17 | 18 | public double getArea() { 19 | return area; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_longest_vowel_chain/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/longest-vowel-chain/train/javascript 4 | 5 | ## Instructions 6 | 7 | The vowel substrings in the word codewarriors are o,e,a,io. The longest of these has a length of 2. Given a lowercase string that has alphabetic characters only and no spaces, return the length of the longest vowel substring. Vowels are any of aeiou. 8 | 9 | Good luck! 10 | 11 | If you like substring Katas, please try: 12 | 13 | Non-even substrings 14 | 15 | Vowel-consonant lexicon 16 | 17 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_recursion_number_2_fibonacci/Fibonacci.js: -------------------------------------------------------------------------------- 1 | /* 2 | ##2 - Fibonacci number 3 | 4 | In mathematical terms, the sequence f(n) of fibonacci numbers is defined by the recurrence relation 5 | 6 | f(n) = f(n-1) + f(n-2) 7 | 8 | with seed values 9 | 10 | f(1) = 1 and f(2) = 1 11 | 12 | #Your task 13 | 14 | You have to create the function fibonacci that receives n and returns f(n). You have to use recursion. 15 | 16 | */ 17 | 18 | const fibonacci = n => { 19 | if (n === 1 || n === 2) return 1; 20 | return fibonacci(n - 1) + fibonacci(n - 2); 21 | }; 22 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_area_of_perimeter/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5ab6538b379d20ad880000ab/ 4 | 5 | ## Instructions 6 | 7 | You are given the length and width of a 4-sided polygon. The polygon can either be a rectangle or a square. 8 | If it is a square, return its area. If it is a rectangle, return its perimeter. 9 | 10 | area_or_perimeter(6, 10) --> 32 11 | area_or_perimeter(4, 4) --> 16 12 | 13 | Note: for the purposes of this kata you will assume that it is a square if its length and width are equal, otherwise it is a rectangle. -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_convert_a_number_to_a_string/ConvertNumberToStringTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_convert_a_number_to_a_string; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class ConvertNumberToStringTest { 8 | 9 | @Test 10 | void tests() { 11 | assertEquals("67", ConvertNumberToString.numberToString(67)); 12 | assertEquals("123", ConvertNumberToString.numberToString(123)); 13 | assertEquals("999", ConvertNumberToString.numberToString(999)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_highest_scoring_word/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/highest-scoring-word/ 4 | 5 | ## Instructions 6 | 7 | Given a string of words, you need to find the highest scoring word. 8 | 9 | Each letter of a word scores points according to its position in the alphabet: a = 1, b = 2, c = 3 etc. 10 | 11 | You need to return the highest scoring word as a string. 12 | 13 | If two words score the same, return the word that appears earliest in the original string. 14 | 15 | All letters will be lowercase and all inputs will be valid. 16 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_l1_set_alarm/SetAlarmTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_l1_set_alarm; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertTrue; 6 | import static org.junit.jupiter.api.Assertions.assertFalse; 7 | 8 | class SetAlarmTest { 9 | 10 | @Test 11 | void setAlarmTest() { 12 | assertTrue(SetAlarm.setAlarm(true, false)); 13 | assertFalse(SetAlarm.setAlarm(true, true)); 14 | assertFalse(SetAlarm.setAlarm(false, false)); 15 | assertFalse(SetAlarm.setAlarm(false, true)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_basics_simple_having/simple_having.sql: -------------------------------------------------------------------------------- 1 | /* 2 | For this challenge you need to create a simple HAVING statement, 3 | you want to count how many people have the same age 4 | and return the groups with 10 or more people who have that age. 5 | 6 | people table schema 7 | id 8 | name 9 | age 10 | 11 | return table schema 12 | age 13 | total_people 14 | 15 | NOTE: Your solution should use pure SQL. 16 | Ruby is used within the test cases to do the actual testing. 17 | */ 18 | 19 | SELECT age, COUNT(*) as total_people FROM people 20 | GROUP BY age 21 | HAVING COUNT(*) >= 10 -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_leap_years/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/leap-years/ 4 | 5 | ## Instructions 6 | 7 | In this kata you should simply determine, whether a given year is a leap year or not. In case you don't know the rules, here they are: 8 | 9 | years divisible by 4 are leap years 10 | but years divisible by 100 are not leap years 11 | but years divisible by 400 are leap years 12 | Additional Notes: 13 | 14 | Only valid years (positive integers) will be tested, so you don't have to validate them 15 | Examples can be found in the test fixture. 16 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_odd_or_even/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5949481f86420f59480000e7/ 4 | 5 | ## Instructions 6 | 7 | #### Task: 8 | 9 | Given a vector of numbers, determine whether the sum of all of the numbers is odd or even. 10 | 11 | Give your answer as a String matching "odd" or "even". 12 | 13 | If the input array is empty consider it as: [0] (array with a zero). 14 | 15 | Example: 16 | ```java 17 | odd_or_even([0]) returns "even" 18 | odd_or_even([0, 1, 4]) returns "odd" 19 | odd_or_even([0, -1, -5]) returns "even" 20 | ``` 21 | Have fun! -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_101_dalmatians_squash_the_bugs_not_the_dogs/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/101-dalmatians-squash-the-bugs-not-the-dogs/ 4 | 5 | ## Instructions 6 | 7 | Your friend has been out shopping for puppies (what a time to be alive!)... He arrives back with multiple dogs, and you simply do not know how to respond! 8 | 9 | By repairing the function provided, you will find out exactly how you should respond, depending on the number of dogs he has. 10 | 11 | The number of dogs will always be a number and there will always be at least 1 dog. -------------------------------------------------------------------------------- /src/_4kyu/_4kyu_adding_big_numbers/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/525f4206b73515bffb000b21/ 4 | 5 | ## Instructions 6 | 7 | We need to sum big numbers and we require your help. 8 | 9 | Write a function that returns the sum of two numbers. 10 | 11 | The input numbers are strings and the function must return a string. 12 | 13 | Example 14 | ``` 15 | add("123", "321"); -> "444" 16 | add("11", "99"); -> "110" 17 | ``` 18 | Notes 19 | 20 | The input numbers are big. 21 | 22 | The input is a string of only digits 23 | 24 | The numbers are positives -------------------------------------------------------------------------------- /src/_5kyu/_5kyu_human_readable_time/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/52685f7382004e774f0001f7/ 4 | 5 | ## Instructions 6 | 7 | Write a function, which takes a non-negative integer (seconds) 8 | as input and returns the time in a human-readable format (HH:MM:SS) 9 | 10 | ``` 11 | HH = hours, padded to 2 digits, range: 00 - 99 12 | MM = minutes, padded to 2 digits, range: 00 - 59 13 | SS = seconds, padded to 2 digits, range: 00 - 59 14 | The maximum time never exceeds 359999 (99:59:59) 15 | ``` 16 | 17 | You can find some examples in the test fixtures. -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_new_cashier_does_not_know_about_space_or_shift/NewCashierTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System; 3 | [TestFixture] 4 | public class OrderTest { [Test] 5 | public void Test1() { 6 | Assert.AreEqual("Burger Fries Chicken Pizza Pizza Pizza Sandwich Milkshake Milkshake Coke", Kata.GetOrder("milkshakepizzachickenfriescokeburgerpizzasandwichmilkshakepizza")); 7 | } 8 | 9 | [Test] 10 | public void Test2() { 11 | Assert.AreEqual("Burger Fries Fries Chicken Pizza Sandwich Milkshake Coke", Kata.GetOrder("pizzachickenfriesburgercokemilkshakefriessandwich")); 12 | } 13 | } -------------------------------------------------------------------------------- /src/_5kyu/_5kyu_mean_square_error/MeanSquareTest.cs: -------------------------------------------------------------------------------- 1 | namespace Solution 2 | { 3 | using NUnit.Framework; 4 | using System; 5 | 6 | [TestFixture] 7 | public class MeanSquareTest 8 | { 9 | [Test, Description("Sample Tests")] 10 | public void SampleTest() 11 | { 12 | Assert.AreEqual(9, MeanSquare.Solution(new int[] {1, 2, 3}, new int[] {4, 5, 6})); 13 | Assert.AreEqual(16.5, MeanSquare.Solution(new int[] {10, 20, 10, 2}, new int[] {10, 25, 5, -2})); 14 | Assert.AreEqual(1, MeanSquare.Solution(new int[] {0, -1}, new int[] {-1, 0})); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_rearrange_integer_into_largest_possible/RearrangeIntegerIntoLargestPossibleTest.js: -------------------------------------------------------------------------------- 1 | Test.describe("Basic tests", _ => { 2 | Test.assertEquals(superSize(69), 96); 3 | Test.assertEquals(superSize(513), 531); 4 | Test.assertEquals(superSize(2017), 7210); 5 | Test.assertEquals(superSize(414), 441); 6 | Test.assertEquals(superSize(608719), 987610); 7 | Test.assertEquals(superSize(123456789), 987654321); 8 | Test.assertEquals(superSize(700000000001), 710000000000); 9 | Test.assertEquals(superSize(666666), 666666); 10 | Test.assertEquals(superSize(2), 2) 11 | }); -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_remove_first_and_last_character/RemoveCharsTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_remove_first_and_last_character; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | public class RemoveCharsTest { 8 | 9 | @Test 10 | public void testRemoval() { 11 | assertEquals("loquen", RemoveChars.remove("eloquent")); 12 | assertEquals("ountr", RemoveChars.remove("country")); 13 | assertEquals("erso", RemoveChars.remove("person")); 14 | assertEquals("lac", RemoveChars.remove("place")); 15 | } 16 | } -------------------------------------------------------------------------------- /src/_4kyu/_4kyu_range_extraction/RangeExtractionTest.java: -------------------------------------------------------------------------------- 1 | package _4kyu._4kyu_range_extraction; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class RangeExtractionTest { 8 | 9 | @Test 10 | public void test_BasicTests() { 11 | assertEquals("-6,-3-1,3-5,7-11,14,15,17-20", RangeExtraction.rangeExtraction(new int[]{-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20})); 12 | 13 | assertEquals("-3--1,2,10,15,16,18-20", RangeExtraction.rangeExtraction(new int[]{-3, -2, -1, 2, 10, 15, 16, 18, 19, 20})); 14 | } 15 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_sum_mixed_array/SumMixedArray.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_sum_mixed_array; 2 | 3 | import java.util.List; 4 | 5 | /* 6 | Given an array of integers as strings and numbers, 7 | return the sum of the array values as if all were numbers. 8 | 9 | Return your answer as a number. 10 | */ 11 | 12 | class SumMixedArray { 13 | 14 | /* 15 | * Assume input will be only of Integer o String type 16 | */ 17 | int sum(List mixed) { 18 | return mixed.stream() 19 | .mapToInt(e -> Integer.parseInt(e.toString())) 20 | .sum(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_java_functional_programming_multiline_functions/FunctionalProgrammingTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_java_functional_programming_multiline_functions; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class FunctionalProgrammingTest { 8 | @Test 9 | public void testArea() throws Exception { 10 | Triangle t = new Triangle(5, 10); 11 | assertEquals("Incorrect area returned", 25D, FunctionalProgramming.f.applyAsDouble(t), 0.001); 12 | assertEquals("Incorrect area in Triangle object", 25D, t.getArea(), 0.001); 13 | } 14 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_odder_than_the_rest/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/odder-than-the-rest/ 4 | 5 | ## Instructions 6 | 7 | Create a method that takes an array/list as an input, and outputs the index at which the sole odd number is located. 8 | 9 | This method should work with arrays with negative numbers. If there are no odd numbers in the array, then the method should output -1. 10 | 11 | Examples: 12 | ```js 13 | oddOne([2,4,6,7,10]) // => 3 14 | oddOne([2,16,98,10,13,78]) // => 4 15 | oddOne([4,-8,98,-12,-7,90,100]) // => 4 16 | oddOne([2,4,6,8]) // => -1 17 | ``` 18 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_highest_scoring_word/HighestScoringWordTest.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_highest_scoring_word; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class HighestScoringWordTest { 8 | 9 | @Test 10 | void sampleTests() { 11 | assertEquals("taxi", HighestScoringWord.high("man i need a taxi up to ubud")); 12 | assertEquals("volcano", HighestScoringWord.high("what time are we climbing up to the volcano")); 13 | assertEquals("semynak", HighestScoringWord.high("take me to semynak")); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_basics_simple_having/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/58164ddf890632ce00000220/ 4 | 5 | ## Instructions 6 | 7 | For this challenge you need to create a simple HAVING statement, 8 | you want to count how many people have the same age 9 | and return the groups with 10 or more people who have that age. 10 | 11 | ``` 12 | people table schema 13 | 14 | id 15 | name 16 | age 17 | 18 | return table schema 19 | 20 | age 21 | total_people 22 | ``` 23 | NOTE: Your solution should use pure SQL. 24 | 25 | Ruby is used within the test cases to do the actual testing. -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_remove_duplicate_words/RemoveDuplicateWordsTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_remove_duplicate_words; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class RemoveDuplicateWordsTest { 8 | 9 | @Test 10 | void basicTests() { 11 | assertEquals("alpha beta gamma delta", RemoveDuplicateWords.removeDuplicateWords("alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta")); 12 | assertEquals("my cat is fat", RemoveDuplicateWords.removeDuplicateWords("my cat is my cat fat")); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_century_from_year/CenturyFromYearTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_century_from_year; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class CenturyFromYearTest { 8 | 9 | @Test 10 | void FixedTests() { 11 | assertEquals(18, CenturyFromYear.century(1705)); 12 | assertEquals(19, CenturyFromYear.century(1900)); 13 | assertEquals(17, CenturyFromYear.century(1601)); 14 | assertEquals(20, CenturyFromYear.century(2000)); 15 | assertEquals(1, CenturyFromYear.century(89)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_is_n_divisible_by_x_and_y/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5545f109004975ea66000086/ 4 | 5 | ## Instructions 6 | 7 | Create a function that checks if a number n is divisible by two numbers x AND y. 8 | 9 | All inputs are positive, non-zero digits. 10 | 11 | ``` 12 | Examples: 13 | n = 3, x = 1, y = 3 => true because 3 is divisible by 1 and 3 14 | n = 12, x = 2, y = 6 => true because 12 is divisible by 2 and 6 15 | n = 100, x = 5, y = 3 => false because 100 is not divisible by 3 16 | n = 12, x = 7, y = 5 => false because 12 is neither divisible by 7 nor 5 17 | ``` -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/kata_test.cfm: -------------------------------------------------------------------------------- 1 | // https://testbox.ortusbooks.com/ 2 | component extends="CodewarsBaseSpec" { 3 | // Submitted solution is written to Solution.cfc 4 | function beforeAll(){ 5 | SUT = createObject( 'Solution' ); 6 | } 7 | 8 | function run(){ 9 | given( "Will you make it?", () => { 10 | when( "sample tests", () => { 11 | then( "Input of 50, 25, 2", () => expect( SUT.zeroFuel( 50, 25, 2 ) ).toBeTrue() ); 12 | then( "Input of 100, 50, 1", () => expect( SUT.zeroFuel( 100, 50, 1 ) ).toBeFalse() ); 13 | }); 14 | }); 15 | } 16 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sum_even_numbers/SumEvenNumbers.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function named sumEvenNumbers, 3 | taking an array of integers as single parameter. 4 | Your function must return the sum of the even values of this array. 5 | 6 | For example, considering this input value : [4,3,1,2,5,10,6,7,9,8], 7 | then your function should return 30 (because 4 + 2 + 10 + 6 + 8 = 30). 8 | */ 9 | 10 | function sumEvenNumbers(input) { 11 | return input.reduce((x, y) => x + (y % 2 === 0 ? y : 0), 0); 12 | } 13 | 14 | Test.assertEquals( 15 | sumEvenNumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 16 | 30, 17 | "Simple integers input." 18 | ); -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_row_of_the_odd_triangle/odd_row.py: -------------------------------------------------------------------------------- 1 | """ 2 | Given a triangle of consecutive odd numbers: 3 | 4 | 1 5 | 3 5 6 | 7 9 11 7 | 13 15 17 19 8 | 21 23 25 27 29 9 | ... 10 | find the triangle's row knowing its index (the rows are 1-indexed), e.g.: 11 | 12 | odd_row(1) == [1] 13 | odd_row(2) == [3, 5] 14 | odd_row(3) == [7, 9, 11] 15 | Note: your code should be optimized to handle big inputs. 16 | 17 | The idea for this kata was taken from this kata: Sum of odd numbers 18 | """ 19 | 20 | def odd_row(n): 21 | return [i for i in range(n * n - n + 1, n * n + n, 2)] -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_recursion_number_1_factorial/Factorial.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ##1 - Factorial 3 | 4 | In mathematics, the factorial of a non-negative integer n, denoted by n!, 5 | is the product of all positive integers less than or equal to n. For example, 6 | 7 | 5! = 5 * 4 * 3 * 2 * 1 = 120. 8 | 9 | The value of 0! is 1. 10 | 11 | #Your task 12 | 13 | You have to create the function factorial that receives n and returns n!. You have to use recursion. 14 | */ 15 | 16 | public class Recursion { 17 | 18 | public static ulong Factorial(ulong n) { 19 | checked { 20 | if (n == 0) return 1; 21 | return n * Factorial(n - 1); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_counting_sheep_dot_dot_dot/CounterTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_counting_sheep_dot_dot_dot; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | class CounterTest { 8 | private Boolean[] array1 = {true, true, true, false, 9 | true, true, true, true, 10 | true, false, true, false, 11 | true, false, false, true, 12 | true, true, true, true, 13 | false, false, true, true}; 14 | 15 | @Test 16 | void test() { 17 | assertEquals("There are 17 sheeps in total", 17, new Counter().countSheeps(array1)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_keep_hydrated/KeepHydratedTest.js: -------------------------------------------------------------------------------- 1 | Test.describe('Fixed tests', _ => { 2 | Test.it('Tests', _ => { 3 | Test.assertEquals(litres(2), 1, 'should return 1 litre'); 4 | Test.assertEquals(litres(1.4), 0, 'should return 0 litres'); 5 | Test.assertEquals(litres(12.3), 6, 'should return 6 litres'); 6 | Test.assertEquals(litres(0.82), 0, 'should return 0 litres'); 7 | Test.assertEquals(litres(11.8), 5, 'should return 5 litres'); 8 | Test.assertEquals(litres(1787), 893, 'should return 893 litres'); 9 | Test.assertEquals(litres(0), 0, 'should return 0 litres'); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_1st_day_of_month_that_are_sunday_in_a_year_range/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/1st-day-of-month-that-are-sunday-in-a-year-range/ 4 | 5 | ## Instructions 6 | 7 | You will write a function that receive 2 parameters, 2 different years, to indicate a range of time. 8 | 9 | The function will return the number of times a month between those years begin on Sunday, meaning the 1st day of the month is Sunday. 10 | 11 | If there is only one year provided, return the number of times a month begin on Sunday on that year. 12 | 13 | For instance: between 1901 and 2000, a month began on Sunday 171 times. -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sum_of_minimums/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5d5ee4c35162d9001af7d699/ 4 | 5 | ## Instructions 6 | 7 | Given an 2D array of size m * n. Your task is to find the sum of minimum value in each row. 8 | 9 | For Example: 10 | 11 | [ 12 | [1, 2, 3, 4, 5], // minimum value of row is 1 13 | [5, 6, 7, 8, 9], // minimum value of row is 5 14 | [20, 21, 34, 56, 100] // minimum value of row is 20 15 | ] 16 | So, the function should return 26 because sum of minimums is as 1 + 5 + 20 = 26 17 | 18 | Note: You will be always given non-empty array containing Positive values. 19 | 20 | ENJOY CODING :) -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_grasshopper_terminal_game_move_function/teminal_game_move.py: -------------------------------------------------------------------------------- 1 | """ 2 | Terminal game move function 3 | In this game, the hero moves from left to right. The player rolls the dice and moves the number of spaces indicated by the dice two times. 4 | 5 | Create a function for the terminal game that takes the current position of the hero and the roll (1-6) and return the new position. 6 | 7 | Example: 8 | move(3, 6) should equal 15 9 | """ 10 | 11 | 12 | def move(position, roll): 13 | return position + 2 * roll 14 | 15 | 16 | test.assert_equals(move(0, 4), 8) 17 | test.assert_equals(move(3, 6), 15) 18 | test.assert_equals(move(2, 5), 12) 19 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sql_basics_simple_join_with_count/simple_join_with_count_test.rb: -------------------------------------------------------------------------------- 1 | # DATA FOR TESTS IS AVAILABLE ONLY ON WEBSITE 2 | 3 | results = run_sql 4 | 5 | describe :items do 6 | it "should return 2 items" do 7 | expect(results.count).to eq 2 8 | end 9 | 10 | it "should return names" do 11 | results.each do |result| 12 | expect(result[:name]).to eq find_record(:people, result[:id]).name 13 | end 14 | end 15 | 16 | it "should return toy count" do 17 | results.each do |result| 18 | toys = find_records_by_people_id(:toys, result[:id]) 19 | expect(result[:toy_count]).to eq toys.count 20 | end 21 | end 22 | end -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_is_n_divisible_by_x_and_y/IsNDivisible.kt: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_is_n_divisible_by_x_and_y 2 | 3 | /* 4 | Create a function that checks if a number n is divisible by two numbers x AND y. 5 | 6 | All inputs are positive, non-zero digits. 7 | 8 | Examples: 9 | n = 3, x = 1, y = 3 => true because 3 is divisible by 1 and 3 10 | n = 12, x = 2, y = 6 => true because 12 is divisible by 2 and 6 11 | n = 100, x = 5, y = 3 => false because 100 is not divisible by 3 12 | n = 12, x = 7, y = 5 => false because 12 is neither divisible by 7 nor 5 13 | */ 14 | 15 | fun isDivisible(n: Int, x: Int, y: Int): Boolean { 16 | return n % x == 0 && n % y == 0; 17 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_a_needle_in_the_haystack/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/a-needle-in-the-haystack/java 4 | 5 | ## Instructions 6 | 7 | Can you find the needle in the haystack? 8 | 9 | Write a function findNeedle() that takes an array full of junk but containing one "needle" 10 | 11 | After your function finds the needle it should return a message (as a string) that says: 12 | 13 | "found the needle at position " plus the index it found the needle, so: 14 | 15 | ```java 16 | findNeedle(new Object[] {"hay", "junk", "hay", "hay", "moreJunk", "needle", "randomJunk"}) 17 | should return "found the needle at position 5" 18 | ``` -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_simple_fun_number_1_seats_in_theater/NumberTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_simple_fun_number_1_seats_in_theater; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class NumberTest { 8 | 9 | @Test 10 | void exampleTests() { 11 | assertEquals(96, Number.seatsInTheater(16, 11, 5, 3)); 12 | assertEquals(0, Number.seatsInTheater(1, 1, 1, 1)); 13 | assertEquals(18, Number.seatsInTheater(13, 6, 8, 3)); 14 | assertEquals(99, Number.seatsInTheater(60, 100, 60, 1)); 15 | assertEquals(0, Number.seatsInTheater(1000, 1000, 1000, 1000)); 16 | } 17 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_help_bob_count_letters_and_digits/Bob.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | /* 4 | Bob is a lazy man. 5 | 6 | He needs you to create a method that can determine how many letters and digits are in a given string. 7 | 8 | Example: 9 | 10 | "hel2!lo" --> 6 11 | 12 | "wicked .. !" --> 6 13 | 14 | "!?..A" --> 1 15 | */ 16 | 17 | public static class Bob 18 | { 19 | public static int CountLettersAndDigits(string input) 20 | { 21 | int counter = 0; 22 | for (int i = 0; i < input.Length; ++i) { 23 | if (Char.IsLetterOrDigit(input[i])) { 24 | ++counter; 25 | } 26 | } 27 | 28 | return counter; 29 | } 30 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_count_the_monkeys/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/count-the-monkeys/ 4 | 5 | ## Instructions 6 | 7 | You take your son to the forest to see the monkeys. You know that there are a certain number there (n), but your son is too young to just appreciate the full number, he has to start counting them from 1. 8 | 9 | As a good parent, you will sit and count with him. Given the number (n), populate an array with all numbers up to and including that number, but excluding zero. 10 | 11 | For example: 12 | ```java 13 | monkeyCount(10) // --> new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} 14 | monkeyCount(1) // --> new int[]{1} 15 | ``` -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_find_the_parity_outlier/FindTheParityOutlierTest.kt: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_find_the_parity_outlier 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.jupiter.api.Assertions.assertEquals 6 | 7 | 8 | class FindTheParityOutlierTest { 9 | 10 | @Test 11 | fun testExample() { 12 | val exampleTest1 = arrayOf(2, 6, 8, -10, 3) 13 | val exampleTest2 = arrayOf(206847684, 1056521, 7, 17, 1901, 21104421, 7, 1, 35521, 1, 7781) 14 | val exampleTest3 = arrayOf(Integer.MAX_VALUE, 0, 1) 15 | assertEquals(3, find(exampleTest1)) 16 | assertEquals(206847684, find(exampleTest2)) 17 | assertEquals(0, find(exampleTest3)) 18 | } 19 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_convert_a_string_to_a_number/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/convert-a-string-to-a-number/ 4 | 5 | ## Instructions 6 | 7 | Note: This kata is inspired by Convert a Number to a String!. Try that one too. 8 | 9 | Description 10 | We need a function that can transform a string into a number. What ways of achieving this do you know? 11 | 12 | Note: Don't worry, all inputs will be strings, and every string is a perfectly valid representation of an integral number. 13 | ``` 14 | Examples 15 | stringToNumber("1234") == 1234 16 | stringToNumber("605" ) == 605 17 | stringToNumber("1405") == 1405 18 | stringToNumber("-7" ) == -7 19 | ``` -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sql_basics_simple_join_with_count/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/580918e24a85b05ad000010c/ 4 | 5 | ## Instructions 6 | 7 | For this challenge you need to create 8 | a simple SELECT statement that will 9 | return all columns from the people table, 10 | and join to the toys table so that you 11 | can return the COUNT of the toys 12 | ``` 13 | people table schema 14 | id 15 | name 16 | toys table schema 17 | id 18 | name 19 | people_id 20 | ``` 21 | You should return all people fields as well as the toy count as "toy_count". 22 | 23 | NOTE: You're solution should use pure SQL. Ruby is used within the test cases to do the actual testing. -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_row_of_the_odd_triangle/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5d5a7525207a674b71aa25b5/ 4 | 5 | ## Instructions 6 | 7 | Given a triangle of consecutive odd numbers: 8 | ``` 9 | 1 10 | 3 5 11 | 7 9 11 12 | 13 15 17 19 13 | 21 23 25 27 29 14 | ``` 15 | ... 16 | find the triangle's row knowing its index (the rows are 1-indexed), e.g.: 17 | 18 | ``` 19 | odd_row(1) == [1] 20 | odd_row(2) == [3, 5] 21 | odd_row(3) == [7, 9, 11] 22 | ``` 23 | 24 | Note: your code should be optimized to handle big inputs. 25 | 26 | The idea for this kata was taken from this kata: Sum of odd numbers -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_counting_sheep_dot_dot_dot/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/counting-sheep-dot-dot-dot/ 4 | 5 | ## Instructions 6 | 7 | Consider an array of sheep where some sheep may be missing from their place. 8 | We need a function that counts the number of sheep present in the array (true means present). 9 | 10 | For example, 11 | 12 | [true, true, true, false, 13 | true, true, true, true , 14 | true, false, true, false, 15 | true, false, false, true , 16 | true, true, true, true , 17 | false, false, true, true] 18 | The correct answer would be 17. 19 | 20 | Hint: Don't forget to check for bad values like null/undefined 21 | -------------------------------------------------------------------------------- /src/_4kyu/_4kyu_strip_comments/StripCommentsTest.java: -------------------------------------------------------------------------------- 1 | package _4kyu._4kyu_strip_comments; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class StripCommentsTest { 8 | 9 | @Test 10 | public void stripComments() throws Exception { 11 | assertEquals( 12 | "apples, pears\ngrapes\nbananas", 13 | StripComments.stripComments("apples, pears # and bananas\ngrapes\nbananas !apples", new String[]{"#", "!"}) 14 | ); 15 | 16 | assertEquals( 17 | "a\nc\nd", 18 | StripComments.stripComments("a #b\nc\nd $e f g", new String[]{"#", "$"}) 19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_odd_or_even/OddOrEven.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_odd_or_even; 2 | 3 | import java.util.Arrays; 4 | 5 | /* 6 | Task: 7 | Given a vector of numbers, determine whether the sum of all of the numbers is odd or even. 8 | 9 | Give your answer as a String matching "odd" or "even". 10 | 11 | If the input array is empty consider it as: [0] (array with a zero). 12 | 13 | Example: 14 | odd_or_even([0]) returns "even" 15 | odd_or_even([0, 1, 4]) returns "odd" 16 | odd_or_even([0, -1, -5]) returns "even" 17 | Have fun! 18 | */ 19 | 20 | public class OddOrEven { 21 | public static String oddOrEven(int[] array) { 22 | return Arrays.stream(array).sum() % 2 == 0 ? "even" : "odd"; 23 | } 24 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_century_from_year/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/century-from-year/train/java/ 4 | 5 | ## Instructions 6 | 7 | Introduction 8 | The first century spans from the year 1 up to and including the year 100, The second - from the year 101 up to and including the year 200, etc. 9 | 10 | Task : 11 | Given a year, return the century it is in. 12 | 13 | Input , Output Examples :: 14 | 15 | ```java 16 | centuryFromYear(1705) returns (18) 17 | centuryFromYear(1900) returns (19) 18 | centuryFromYear(1601) returns (17) 19 | centuryFromYear(2000) returns (20) 20 | ``` 21 | 22 | Hope you enjoy it .. Awaiting for Best Practice Codes 23 | 24 | Enjoy Learning !!! -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_find_the_parity_outlier/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5526fc09a1bbd946250002dc/ 4 | 5 | ## Instructions 6 | 7 | You are given an array (which will have a length of at least 3, but could be very large) containing integers. 8 | 9 | The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. 10 | 11 | Write a method that takes the array as an argument and returns this "outlier" N. 12 | 13 | Examples 14 | 15 | ``` 16 | [2, 4, 0, 100, 4, 11, 2602, 36] 17 | Should return: 11 (the only odd number) 18 | 19 | [160, 3, 1719, 19, 11, 13, -21] 20 | Should return: 160 (the only even number) 21 | ``` -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_split_strings/split_strings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Complete the solution so that it splits the string 3 | into pairs of two characters. 4 | If the string contains an odd number of 5 | characters then it should replace 6 | the missing second character of the final pair 7 | with an underscore ('_'). 8 | 9 | Examples: 10 | 11 | solution('abc') # should return ['ab', 'c_'] 12 | solution('abcdef') # should return ['ab', 'cd', 'ef'] 13 | """ 14 | 15 | 16 | def split_strings(s): 17 | list = [s[i:i + 2] for i in range(0, len(s), 2)] 18 | res = [] 19 | for e in list: 20 | if len(e) == 2: 21 | res.append(e) 22 | else: 23 | res.append(e + '_') 24 | return res 25 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_form_the_minimum/FormTheMinimumTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_form_the_minimum; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | public class FormTheMinimumTest { 8 | 9 | @Test 10 | public void testSomething() { 11 | assertEquals(13, FormTheMinimum.minValue(new int[]{1, 3, 1})); 12 | assertEquals(457, FormTheMinimum.minValue(new int[]{4, 7, 5, 7})); 13 | assertEquals(148, FormTheMinimum.minValue(new int[]{4, 8, 1, 4})); 14 | assertEquals(579, FormTheMinimum.minValue(new int[]{5, 7, 9, 5, 7})); 15 | assertEquals(678, FormTheMinimum.minValue(new int[]{6, 7, 8, 7, 6, 6})); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_detect_pangram/PangramCheckerTest.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_detect_pangram; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertFalse; 6 | import static org.junit.Assert.assertTrue; 7 | 8 | public class PangramCheckerTest { 9 | 10 | @Test 11 | public void test1() { 12 | String pangram1 = "The quick brown fox jumps over the lazy dog."; 13 | PangramChecker pc = new PangramChecker(); 14 | assertTrue(pc.check(pangram1)); 15 | } 16 | 17 | @Test 18 | public void test2() { 19 | String pangram2 = "You shall not pass!"; 20 | PangramChecker pc = new PangramChecker(); 21 | assertFalse(pc.check(pangram2)); 22 | } 23 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_multiples_of_3_or_5/Multiples.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_multiples_of_3_or_5; 2 | 3 | import java.util.stream.IntStream; 4 | 5 | /* 6 | If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. 7 | 8 | Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in. 9 | 10 | Note: If the number is a multiple of both 3 and 5, only count it once. 11 | 12 | */ 13 | 14 | public class Multiples { 15 | 16 | public int solution(int number) { 17 | return IntStream.range(0, number) 18 | .filter(e -> (e % 3 == 0) || (e % 5 == 0)) 19 | .sum(); 20 | } 21 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_no-loops-1-small-enough/no_loops_1.py: -------------------------------------------------------------------------------- 1 | """ 2 | * No Loops Allowed * 3 | 4 | You will be given an array (a) and a limit value (limit). 5 | 6 | You must check that all values in the array are below or 7 | equal to the limit value. 8 | 9 | If they are, return true. Else, return false. 10 | 11 | You can assume all values in the array are numbers. 12 | 13 | Do not use loops. Do not modify input array. 14 | 15 | Looking for more, loop-restrained fun? 16 | 17 | Check out the other kata in the series: 18 | 19 | https://www.codewars.com/kata/no-loops-2-you-only-need-one 20 | 21 | https://www.codewars.com/kata/no-loops-3-copy-within 22 | """ 23 | 24 | def small_enough(a, limit): 25 | return max(a) <= limit -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_number_of_occurrences/OccurrencesKataTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | [TestFixture] 4 | public class OccurrencesKataTests 5 | { 6 | [Test] 7 | public void Should_Work_On_Empty_List() 8 | { 9 | Assert.AreEqual(0, 10 | OccurrencesKata.NumberOfOccurrences(2, new int[0])); 11 | } 12 | 13 | [Test] 14 | public void Should_Work_On_Examples() 15 | { 16 | var example = new int[] { 4, 0, 4 }; 17 | 18 | Assert.AreEqual(2, 19 | OccurrencesKata.NumberOfOccurrences(4, example)); 20 | 21 | Assert.AreEqual(0, 22 | OccurrencesKata.NumberOfOccurrences(1, example)); 23 | 24 | Assert.AreEqual(1, 25 | OccurrencesKata.NumberOfOccurrences(0, example)); 26 | } 27 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_check_for_factor/CheckForFactorTest.kt: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_check_for_factor 2 | 3 | import org.junit.Test 4 | import org.junit.jupiter.api.Assertions.assertEquals 5 | 6 | class CheckForFactorTest { 7 | 8 | @Test 9 | fun basicTests() { 10 | assertEquals(true, checkForFactor(10, 2)) 11 | assertEquals(true, checkForFactor(63, 7)) 12 | assertEquals(true, checkForFactor(2450, 5)) 13 | assertEquals(true, checkForFactor(24612, 3)) 14 | assertEquals(false, checkForFactor(9, 2)) 15 | assertEquals(false, checkForFactor(653, 7)) 16 | assertEquals(false, checkForFactor(2453, 5)) 17 | assertEquals(false, checkForFactor(24617, 3)) 18 | } 19 | } -------------------------------------------------------------------------------- /src/_4kyu/_4kyu_adding_big_numbers/BigNumbersAdder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Numerics; 3 | 4 | /* 5 | We need to sum big numbers and we require your help. 6 | 7 | Write a function that returns the sum of two numbers. 8 | 9 | The input numbers are strings and the function must return a string. 10 | 11 | Example 12 | 13 | add("123", "321"); -> "444" 14 | add("11", "99"); -> "110" 15 | 16 | Notes 17 | 18 | The input numbers are big. 19 | 20 | The input is a string of only digits 21 | 22 | The numbers are positives 23 | */ 24 | 25 | public class BigNumbersAdder 26 | { 27 | public static string Add(string a, string b) 28 | { 29 | return (BigInteger.Parse(a) + BigInteger.Parse(b)).ToString(); 30 | } 31 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_highest_scoring_word/HighestScoringWordTest.cs: -------------------------------------------------------------------------------- 1 | namespace Solution { 2 | using NUnit.Framework; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | [TestFixture] 7 | public class Sample_Tests { 8 | private static IEnumerable < TestCaseData > testCases { 9 | get { 10 | yield 11 | return new TestCaseData("man i need a taxi up to ubud").Returns("taxi"); 12 | yield 13 | return new TestCaseData("what time are we climbing up to the volcano").Returns("volcano"); 14 | yield 15 | return new TestCaseData("take me to semynak").Returns("semynak"); 16 | } 17 | } 18 | 19 | [Test, TestCaseSource("testCases")] 20 | public string Test(string s) = >Kata.High(s); 21 | } 22 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_java_functional_programming_the_beginning/Student.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_java_functional_programming_the_beginning; 2 | 3 | public class Student { 4 | 5 | private final String firstName; 6 | private final String lastName; 7 | public final String studentNumber; 8 | 9 | public Student(String firstName, String lastName, String studentNumber) { 10 | this.firstName = firstName; 11 | this.lastName = lastName; 12 | this.studentNumber = studentNumber; 13 | } 14 | 15 | public String getFullName() { 16 | return firstName + " " + lastName; 17 | } 18 | 19 | public String getCommaName() { 20 | return lastName + ", " + firstName; 21 | } 22 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_flatten_and_sort_an_array/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/flatten-and-sort-an-array/ 4 | 5 | ## Instructions 6 | 7 | Challenge: 8 | 9 | Given a two-dimensional array of integers, return the flattened version of the array with all the integers in the sorted (ascending) order. 10 | 11 | Example: 12 | 13 | Given [[3, 2, 1], [4, 6, 5], [], [9, 7, 8]], your function should return [1, 2, 3, 4, 5, 6, 7, 8, 9]. 14 | 15 | Addendum: 16 | 17 | Please, keep in mind, that JavaScript is by default sorting objects alphabetically. For more information, please consult: 18 | 19 | http://stackoverflow.com/questions/6093874/why-doesnt-the-sort-function-of-javascript-work-well 20 | 21 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_no-loops-2-you-only-need-one/no_loops_2.py: -------------------------------------------------------------------------------- 1 | """ 2 | * No Loops Allowed * 3 | 4 | You will be given an array (a) and a value (x). 5 | 6 | All you need to do is check whether the provided 7 | array contains the value, without using a loop. 8 | 9 | Array can contain numbers or strings. 10 | 11 | X can be either. 12 | 13 | Return true if the array contains the value, 14 | 15 | false if not. With strings you will need to account for case. 16 | 17 | Looking for more, loop-restrained fun? 18 | Check out the other kata in the series: 19 | 20 | https://www.codewars.com/kata/no-loops-1-small-enough 21 | 22 | https://www.codewars.com/kata/no-loops-3-copy-within 23 | """ 24 | 25 | def check(a, x): 26 | return x in a -------------------------------------------------------------------------------- /src/_4kyu/_4kyu_human_readable_duration_format/TimeFormatterTest.java: -------------------------------------------------------------------------------- 1 | package _4kyu._4kyu_human_readable_duration_format; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class TimeFormatterTest { 8 | 9 | @Test 10 | public void exampleTests() { 11 | assertEquals("1 second", TimeFormatter.formatDuration(1)); 12 | assertEquals("1 minute and 2 seconds", TimeFormatter.formatDuration(62)); 13 | assertEquals("2 minutes", TimeFormatter.formatDuration(120)); 14 | assertEquals("1 hour", TimeFormatter.formatDuration(3600)); 15 | assertEquals("1 hour, 1 minute and 2 seconds", TimeFormatter.formatDuration(3662)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_remove_duplicate_words/RemoveDuplicateWords.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_remove_duplicate_words; 2 | 3 | import java.util.Arrays; 4 | import java.util.stream.Collectors; 5 | 6 | /* 7 | Your task is to remove all duplicate words from a string, 8 | leaving only single (first) words entries. 9 | 10 | Example: 11 | 12 | Input: 13 | 14 | 'alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta' 15 | 16 | Output: 17 | 18 | 'alpha beta gamma delta' 19 | */ 20 | 21 | class RemoveDuplicateWords { 22 | 23 | static String removeDuplicateWords(String s) { 24 | return Arrays.stream(s.split(" ")) 25 | .distinct() 26 | .collect(Collectors.joining(" ")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sql_basics_simple_join_with_count/simple_join_with_count.sql: -------------------------------------------------------------------------------- 1 | /* 2 | For this challenge you need to create 3 | a simple SELECT statement that will 4 | return all columns from the people table, 5 | and join to the toys table so that you can return the COUNT of the toys 6 | 7 | people table schema 8 | id 9 | name 10 | toys table schema 11 | id 12 | name 13 | people_id 14 | 15 | You should return all people fields as well as the toy count as "toy_count". 16 | 17 | NOTE: You're solution should use pure SQL. 18 | 19 | Ruby is used within the test cases to do the actual testing. 20 | */ 21 | 22 | SELECT people.*, COUNT(toys.*) as toy_count FROM people 23 | JOIN toys ON people.id = toys.people_id 24 | GROUP BY people.id, people.name -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_grasshopper_messi_goals_function/messiGoals.js: -------------------------------------------------------------------------------- 1 | /* 2 | Messi goals function 3 | Messi is a soccer player with goals in three leagues: 4 | 5 | LaLiga 6 | Copa del Rey 7 | Champions. 8 | Complete the goals function to return his total goals (the sum) for all three leagues. 9 | 10 | Note: the parameter for this function will always be a valid number. 11 | 12 | Ex : 13 | goals(5,10,2) == 5+10+2 = 17 14 | 15 | */ 16 | 17 | function goals(laLigaGoals, copaDelReyGoals, championsLeagueGoals) { 18 | return laLigaGoals + copaDelReyGoals + championsLeagueGoals; 19 | } 20 | 21 | // exit code 0 -> test passed 22 | var assert = require('assert'); 23 | assert.strictEqual(goals(0, 0, 0), 0); 24 | assert.strictEqual(goals(43, 10, 5), 58); -------------------------------------------------------------------------------- /src/_5kyu/_5kyu_human_readable_time/HumanReadableTime.java: -------------------------------------------------------------------------------- 1 | package _5kyu._5kyu_human_readable_time; 2 | 3 | /* 4 | Write a function, which takes a non-negative integer (seconds) 5 | as input and returns the time in a human-readable format (HH:MM:SS) 6 | 7 | HH = hours, padded to 2 digits, range: 00 - 99 8 | MM = minutes, padded to 2 digits, range: 00 - 59 9 | SS = seconds, padded to 2 digits, range: 00 - 59 10 | The maximum time never exceeds 359999 (99:59:59) 11 | 12 | You can find some examples in the test fixtures. 13 | */ 14 | public class HumanReadableTime { 15 | 16 | public static String makeReadable(int seconds) { 17 | return String.format("%02d:%02d:%02d", seconds / 3600, (seconds / 60) % 60, seconds % 60); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_primorial_of_a_number/PrimorialOfNumberTest.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_primorial_of_a_number; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class PrimorialOfNumberTest { 8 | 9 | @Test 10 | void checkSmallValues() { 11 | assertEquals("30", PrimorialOfNumber.numPrimorial(3)); 12 | assertEquals("210", PrimorialOfNumber.numPrimorial(4)); 13 | assertEquals("2310", PrimorialOfNumber.numPrimorial(5)); 14 | } 15 | 16 | @Test 17 | void checkLargerValues() { 18 | assertEquals("9699690", PrimorialOfNumber.numPrimorial(8)); 19 | assertEquals("223092870", PrimorialOfNumber.numPrimorial(9)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_basics_simple_in/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/sql-basics-simple-in/ 4 | 5 | ## Instructions 6 | 7 | For this challenge you need to create a SELECT statement, 8 | this SELECT statement will use an IN 9 | to check whether a department has had a sale with a price over 98.00 dollars. 10 | 11 | ``` 12 | departments table schema 13 | id 14 | name 15 | ``` 16 | 17 | ``` 18 | sales table schema 19 | id 20 | department_id (department foreign key) 21 | name 22 | price 23 | card_name 24 | card_number 25 | transaction_date 26 | ``` 27 | 28 | ``` 29 | resultant table schema 30 | id 31 | name 32 | ``` 33 | 34 | NOTE: sometimes a department will not not contain a sale over $98 so just resubmit. -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_check_for_factor/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/55cbc3586671f6aa070000fb/ 4 | 5 | ## Instructions 6 | 7 | This function should test if the factor is a factor of base. 8 | 9 | Return true if it is a factor or false if it is not. 10 | 11 | About factors 12 | Factors are numbers you can multiply together to get another number. 13 | 14 | 2 and 3 are factors of 6 because: 2 * 3 = 6 15 | 16 | You can find a factor by dividing numbers. If the remainder is 0 then the number is a factor. 17 | You can use the mod operator (%) in most languages to check for a remainder 18 | For example 2 is not a factor of 7 because: 7 % 2 = 1 19 | 20 | Note: base is a non-negative number, factor is a positive number. -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_maximum_multiple/MaxMultipleTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_maximum_multiple; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class MaxMultipleTest { 8 | 9 | @Test 10 | void smallPositives() { 11 | assertEquals(6, MaxMultiple.maxMultiple(2, 7)); 12 | assertEquals(9, MaxMultiple.maxMultiple(3, 10)); 13 | assertEquals(14, MaxMultiple.maxMultiple(7, 17)); 14 | } 15 | 16 | @Test 17 | void largerPositives() { 18 | assertEquals(50, MaxMultiple.maxMultiple(10, 50)); 19 | assertEquals(185, MaxMultiple.maxMultiple(37, 200)); 20 | assertEquals(98, MaxMultiple.maxMultiple(7, 100)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_array_plus_array/ArrayPlusArrayTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_array_plus_array; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | 8 | public class ArrayPlusArrayTest { 9 | 10 | @Test 11 | public void sampleTests() { 12 | assertEquals(21, ArrayPlusArray.arrayPlusArray(new int[]{1, 2, 3}, new int[]{4, 5, 6})); 13 | assertEquals(-21, ArrayPlusArray.arrayPlusArray(new int[]{-1, -2, -3}, new int[]{-4, -5, -6})); 14 | assertEquals(15, ArrayPlusArray.arrayPlusArray(new int[]{0, 0, 0}, new int[]{4, 5, 6})); 15 | assertEquals(2100, ArrayPlusArray.arrayPlusArray(new int[]{100, 200, 300}, new int[]{400, 500, 600})); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_will_you_make_it/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/will-you-make-it/ 4 | 5 | ## Instructions 6 | 7 | Will you make it? 8 | You were camping with your friends far away from home, 9 | but when it's time to go back, 10 | you realize that you fuel is running out 11 | and the nearest pump is 50 miles away! 12 | 13 | You know that on average, your car runs 14 | on about 25 miles per gallon. 15 | 16 | There are 2 gallons left. 17 | 18 | Considering these factors, 19 | write a function that tells you if 20 | it is possible to get to the pump or not. 21 | 22 | Function should return true (1 in Prolog) 23 | if it is possible and false (0 in Prolog) 24 | if not. The input values are always positive. -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_no-loops-1-small-enough/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/no-loops-1-small-enough/ 4 | 5 | ## Instructions 6 | 7 | * No Loops Allowed * 8 | 9 | You will be given an array (a) and a limit value (limit). 10 | 11 | You must check that all values in the array are below or 12 | equal to the limit value. 13 | 14 | If they are, return true. Else, return false. 15 | 16 | You can assume all values in the array are numbers. 17 | 18 | Do not use loops. Do not modify input array. 19 | 20 | Looking for more, loop-restrained fun? 21 | 22 | Check out the other kata in the series: 23 | 24 | https://www.codewars.com/kata/no-loops-2-you-only-need-one 25 | 26 | https://www.codewars.com/kata/no-loops-3-copy-within -------------------------------------------------------------------------------- /src/_5kyu/_5kyu_mean_square_error/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/51edd51599a189fe7f000015/ 4 | 5 | ## Instructions 6 | 7 | Complete the function that 8 | 9 | accepts two integer arrays of equal length 10 | 11 | compares the value each member in one array to the corresponding member in the other 12 | 13 | squares the absolute value difference between those two values 14 | 15 | and returns the average of those squared absolute value difference between each member pair. 16 | 17 | Examples 18 | ``` 19 | [1, 2, 3], [4, 5, 6] --> 9 because (9 + 9 + 9) / 3 20 | [10, 20, 10, 2], [10, 25, 5, -2] --> 16.5 because (0 + 25 + 25 + 16) / 4 21 | [-1, 0], [0, -1] --> 1 because (1 + 1) / 2 22 | ``` -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_circularly_sorted_array/CircularlySortedArrayTest.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_circularly_sorted_array; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class CircularlySortedArrayTest { 8 | 9 | @Test 10 | void testTrue() { 11 | CircularlySortedArray circularlySortedArray = new CircularlySortedArray(); 12 | 13 | int[] A = {3, 0, 1, 2}; 14 | assertTrue(circularlySortedArray.isCircleSorted(A)); 15 | } 16 | 17 | @Test 18 | void testFalse() { 19 | CircularlySortedArray circularlySortedArray = new CircularlySortedArray(); 20 | 21 | int[] A = {9, 10, 14, 12}; 22 | assertFalse(circularlySortedArray.isCircleSorted(A)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/_4kyu/_4kyu_sum_strings_as_numbers/SumStringsAsNumbers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Numerics; 3 | 4 | /* 5 | Given the string representations of two integers, 6 | return the string representation of the sum of those integers. 7 | 8 | For example: 9 | 10 | sumStrings('1','2') // => '3' 11 | 12 | A string representation of an integer will contain 13 | no characters besides the ten numerals "0" to "9". 14 | */ 15 | 16 | public static class SumStringsAsNumbers 17 | { 18 | public static string sumStrings(string a, string b) 19 | { 20 | BigInteger numberA; 21 | BigInteger numberB; 22 | 23 | BigInteger.TryParse(a, out numberA); 24 | BigInteger.TryParse(b, out numberB); 25 | 26 | return (numberA + numberB).ToString(); 27 | } 28 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_correct_the_mistakes_of_the_character_recognition_software/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/correct-the-mistakes-of-the-character-recognition-software/ 4 | 5 | ## Instructions 6 | 7 | Character recognition software is widely used to digitise printed texts. Thus the texts can be edited, searched and stored on a computer. 8 | 9 | When documents (especially pretty old ones written with a typewriter), are digitised character recognition softwares often make mistakes. 10 | 11 | Your task is correct the errors in the digitised text. You only have to handle the following mistakes: 12 | 13 | S is misinterpreted as 5 14 | O is misinterpreted as 0 15 | I is misinterpreted as 1 16 | The test cases contain numbers only by mistake. 17 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_difference_of_volumes_of_cuboids/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/difference-of-volumes-of-cuboids/train/javascript/ 4 | 5 | ## Instructions 6 | 7 | In this simple exercise, you will create a program that will take two lists of integers, a and b. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids a and b. You must find the difference of the cuboids' volumes regardless of which is bigger. 8 | 9 | For example, if the parameters passed are ([2, 2, 3], [5, 4, 1]), the volume of a is 12 and the volume of b is 20. Therefore, the function should return 8. 10 | 11 | Your function will be tested with pre-made examples as well as random ones. 12 | 13 | If you can, try writing it in one line of code. -------------------------------------------------------------------------------- /src/_4kyu/_4kyu_strip_comments/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/strip-comments/ 4 | 5 | ## Instructions 6 | 7 | Complete the solution so that it strips all 8 | text that follows any of a set of comment markers passed in. 9 | Any whitespace at the end of the 10 | line should also be stripped out. 11 | 12 | Example: 13 | 14 | Given an input string of: 15 | 16 | ``` 17 | apples, pears # and bananas 18 | grapes 19 | bananas !apples 20 | ``` 21 | The output expected would be: 22 | ``` 23 | apples, pears 24 | grapes 25 | bananas 26 | ``` 27 | 28 | The code would be called like so: 29 | 30 | ``` 31 | var result = solution("apples, pears # and bananas\ngrapes\nbananas !apples", ["#", "!"]) 32 | // result should == "apples, pears\ngrapes\nbananas" 33 | ``` -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_convert_a_string_to_a_number/ConvertStringToNumber.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_convert_a_string_to_a_number; 2 | 3 | /* 4 | Note: This kata is inspired by Convert a Number to a String!. Try that one too. 5 | 6 | Description 7 | We need a function that can transform a string into a number. What ways of achieving this do you know? 8 | 9 | Note: Don't worry, all inputs will be strings, and every string is a perfectly valid representation of an integral number. 10 | 11 | Examples 12 | stringToNumber("1234") == 1234 13 | stringToNumber("605" ) == 605 14 | stringToNumber("1405") == 1405 15 | stringToNumber("-7" ) == -7 16 | */ 17 | 18 | class ConvertStringToNumber { 19 | 20 | static int stringToNumber(String str) { 21 | return Integer.parseInt(str); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_no-loops-2-you-only-need-one/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/no-loops-2-you-only-need-one/ 4 | 5 | ## Instructions 6 | 7 | * No Loops Allowed * 8 | 9 | You will be given an array (a) and a value (x). 10 | 11 | All you need to do is check whether the provided 12 | array contains the value, without using a loop. 13 | 14 | Array can contain numbers or strings. 15 | 16 | X can be either. 17 | 18 | Return true if the array contains the value, 19 | 20 | false if not. With strings you will need to account for case. 21 | 22 | Looking for more, loop-restrained fun? 23 | Check out the other kata in the series: 24 | 25 | https://www.codewars.com/kata/no-loops-1-small-enough 26 | 27 | https://www.codewars.com/kata/no-loops-3-copy-within -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_check_for_factor/CheckForFactor.kt: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_check_for_factor 2 | 3 | /* 4 | This function should test if the factor is a factor of base. 5 | 6 | Return true if it is a factor or false if it is not. 7 | 8 | About factors 9 | Factors are numbers you can multiply together to get another number. 10 | 11 | 2 and 3 are factors of 6 because: 2 * 3 = 6 12 | 13 | You can find a factor by dividing numbers. If the remainder is 0 then the number is a factor. 14 | You can use the mod operator (%) in most languages to check for a remainder 15 | For example 2 is not a factor of 7 because: 7 % 2 = 1 16 | 17 | Note: base is a non-negative number, factor is a positive number. 18 | */ 19 | 20 | fun checkForFactor(base: Int, factor: Int): Boolean { 21 | return base % factor == 0; 22 | } -------------------------------------------------------------------------------- /src/_5kyu/_5kyu_human_readable_time/HumanReadableTimeTest.java: -------------------------------------------------------------------------------- 1 | package _5kyu._5kyu_human_readable_time; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | public class HumanReadableTimeTest { 8 | 9 | @Test 10 | public void Tests() { 11 | assertEquals("makeReadable(0)", "00:00:00", HumanReadableTime.makeReadable(0)); 12 | assertEquals("makeReadable(5)", "00:00:05", HumanReadableTime.makeReadable(5)); 13 | assertEquals("makeReadable(60)", "00:01:00", HumanReadableTime.makeReadable(60)); 14 | assertEquals("makeReadable(86399)", "23:59:59", HumanReadableTime.makeReadable(86399)); 15 | assertEquals("makeReadable(359999)", "99:59:59", HumanReadableTime.makeReadable(359999)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_backspaces_in_string/BackspacesInString.js: -------------------------------------------------------------------------------- 1 | /* 2 | Assume "#" is like a backspace in string. This means that string "a#bc#d" actually is "bd" 3 | 4 | Your task is to process a string with "#" symbols. 5 | 6 | Examples 7 | "abc#d##c" ==> "ac" 8 | "abc##d######" ==> "" 9 | "#######" ==> "" 10 | "" ==> "" 11 | */ 12 | 13 | function cleanString(s) { 14 | const result = []; 15 | 16 | for (const c of s) { 17 | if (c === "#") { 18 | result.pop() 19 | } else { 20 | result.push(c) 21 | } 22 | } 23 | 24 | return result.join("") 25 | } 26 | 27 | function cleanString2(s) { 28 | return s.split('') 29 | .reduce((r, e) => e === '#' 30 | ? r.slice(0, -1) 31 | : r + e, ''); 32 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_basics_simple_exists/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/58113a64e10b53ec36000293/ 4 | 5 | ## Instructions 6 | 7 | For this challenge you need to create a SELECT statement, 8 | this SELECT statement will use an EXISTS 9 | to check whether a department has had a sale with a price over 98.00 dollars. 10 | 11 | ``` 12 | departments table schema 13 | id 14 | name 15 | 16 | sales table schema 17 | id 18 | department_id (department foreign key) 19 | name 20 | price 21 | card_name 22 | card_number 23 | transaction_date 24 | 25 | resultant table schema 26 | id 27 | name 28 | ``` 29 | NOTE: Your solution should use pure SQL. 30 | 31 | Ruby is used within the test cases to do the actual testing. 32 | 33 | Do not: alias tables as this can cause a failure. -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_century_from_year/CenturyFromYear.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_century_from_year; 2 | 3 | /* 4 | Introduction 5 | The first century spans from the year 1 up to and including the year 100, 6 | The second - from the year 101 up to and including the year 200, etc. 7 | 8 | Task : 9 | Given a year, return the century it is in. 10 | 11 | Input , Output Examples :: 12 | 13 | centuryFromYear(1705) returns (18) 14 | centuryFromYear(1900) returns (19) 15 | centuryFromYear(1601) returns (17) 16 | centuryFromYear(2000) returns (20) 17 | 18 | Hope you enjoy it .. Awaiting for Best Practice Codes 19 | 20 | Enjoy Learning !!! 21 | */ 22 | 23 | class CenturyFromYear { 24 | static int century(int number) { 25 | return (number % 100 == 0) ? (number / 100) : (number / 100 + 1); 26 | } 27 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_basics_simple_exists/simple_exists.sql: -------------------------------------------------------------------------------- 1 | /* 2 | For this challenge you need to create a SELECT statement, 3 | this SELECT statement will use an EXISTS to check whether 4 | a department has had a sale with a price over 98.00 dollars. 5 | 6 | departments table schema 7 | id 8 | name 9 | 10 | sales table schema 11 | id 12 | department_id (department foreign key) 13 | name 14 | price 15 | card_name 16 | card_number 17 | transaction_date 18 | 19 | resultant table schema 20 | id 21 | name 22 | 23 | NOTE: Your solution should use pure SQL. Ruby is used within the test cases to do the actual testing. 24 | 25 | Do not: alias tables as this can cause a failure. 26 | */ 27 | 28 | SELECT d.* 29 | FROM departments d 30 | WHERE EXISTS (SELECT s.* FROM sales s WHERE s.department_id = d.id AND s.price > 98.00) -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_strong_number/StrongNumberTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_strong_number; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class StrongNumberTest { 8 | 9 | private static String STRONG = "STRONG!!!!"; 10 | private static String NOT_STRONG = "Not Strong !!"; 11 | 12 | @Test 13 | public void testSomething() { 14 | assertEquals(STRONG, StrongNumber.isStrongNumber(1)); 15 | assertEquals(STRONG, StrongNumber.isStrongNumber(2)); 16 | assertEquals(STRONG, StrongNumber.isStrongNumber(145)); 17 | assertEquals(NOT_STRONG, StrongNumber.isStrongNumber(7)); 18 | assertEquals(NOT_STRONG, StrongNumber.isStrongNumber(93)); 19 | assertEquals(NOT_STRONG, StrongNumber.isStrongNumber(185)); 20 | } 21 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_convert_a_string_to_a_number/ConvertStringToNumberTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_convert_a_string_to_a_number; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class ConvertStringToNumberTest { 8 | 9 | @Test 10 | void test1() { 11 | assertEquals(1234, ConvertStringToNumber.stringToNumber("1234")); 12 | } 13 | 14 | @Test 15 | void test2() { 16 | assertEquals(605, ConvertStringToNumber.stringToNumber("605")); 17 | } 18 | 19 | @Test 20 | void test3() { 21 | assertEquals(1405, ConvertStringToNumber.stringToNumber("1405")); 22 | } 23 | 24 | @Test 25 | void test4() { 26 | assertEquals(-7, ConvertStringToNumber.stringToNumber("-7")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /create_dir.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | 5 | def run(): 6 | number_of_directory_to_go = sys.argv[1] 7 | directory_name = sys.argv[2] 8 | link = sys.argv[3] 9 | prefix = "_" + number_of_directory_to_go + "kyu" 10 | create_directory_with_readme_file(prefix, directory_name, link) 11 | 12 | 13 | def create_directory_with_readme_file(prefix, directory_name, link): 14 | os.chdir("src") 15 | os.chdir(prefix) 16 | new_directory_name = prefix + "_" + directory_name 17 | os.mkdir(new_directory_name) 18 | os.chdir(new_directory_name) 19 | readme_file = open("README.md", "w+") 20 | readme_file.write("## Solution for problem:\r\n") 21 | readme_file.write(link) 22 | readme_file.write("\n\n## Instructions") 23 | 24 | 25 | if __name__ == "__main__": 26 | run() 27 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_l1_set_alarm/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/l1-set-alarm/ 4 | 5 | ## Instructions 6 | 7 | Write a function named setAlarm which receives two parameters. The first parameter, employed, is true whenever you are employed and the second parameter, vacation is true whenever you are on vacation. 8 | 9 | The function should return true if you are employed and not on vacation (because these are the circumstances under which you need to set an alarm). It should return false otherwise. Examples: 10 | 11 | setAlarm(true, true) -> false setAlarm(false, true) -> false setAlarm(false, false) -> false setAlarm(true, false) -> true 12 | 13 | setalarm(true, true) -> false 14 | setalarm(false, true) -> false 15 | setalarm(false, false) -> false 16 | setalarm(true, false) -> true -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_bit_counting/BitCounting.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_bit_counting; 2 | 3 | /* 4 | Write a function that takes an integer as input, 5 | and returns the number of bits that are equal 6 | to one in the binary representation of that number. 7 | You can guarantee that input is non-negative. 8 | 9 | Example: The binary representation of 1234 is 10011010010, 10 | so the function should return 5 in this case 11 | */ 12 | 13 | class BitCounting { 14 | 15 | static int countBits(int n) { 16 | int counter = 0; 17 | 18 | while (n != 0) { 19 | if (n % 2 == 1) ++counter; 20 | n /= 2; 21 | } 22 | 23 | return counter; 24 | } 25 | 26 | // better one 27 | 28 | static int countBits2(int n) { 29 | return Integer.bitCount(n); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_count_the_monkeys/MonkeyCounterTest.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_count_the_monkeys; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; 6 | 7 | class MonkeyCounterTest { 8 | 9 | @Test 10 | void basicTests() { 11 | assertArrayEquals(new int[]{1, 2, 3, 4, 5}, MonkeyCounter.monkeyCount(5)); 12 | assertArrayEquals(new int[]{1, 2, 3}, MonkeyCounter.monkeyCount(3)); 13 | assertArrayEquals(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, MonkeyCounter.monkeyCount(9)); 14 | assertArrayEquals(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, MonkeyCounter.monkeyCount(10)); 15 | assertArrayEquals(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, MonkeyCounter.monkeyCount(20)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_calculate_number_of_inversions_in_array/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/537529f42993de0e0b00181f/ 4 | 5 | ## Instructions 6 | 7 | Array inversion indicates how far the array is from being sorted. 8 | 9 | Inversions are pairs of elements in array, that are out of order. 10 | 11 | Examples 12 | ``` 13 | Kata.CountInversions(new int[] { 1,2,3,4 }); // 0 inversions 14 | 15 | Kata.CountInversions(new int[] { 1,3,2,4 }); // 1 inversion: 2 and 3 16 | 17 | Kata.CountInversions(new int[] { 4,1,2,3 }); // 3 inversions: 4 and 1, 4 and 2, 4 and 3 18 | 19 | Kata.CountInversions(new int[] { 4,3,2,1 }); // 6 inversions: 4 and 3, 4 and 2, 4 and 1, 3 and 2, 3 and 1, 2 and 1 20 | ``` 21 | Goal 22 | The goal is to come up with a function that can calculate inversions for any arbitrary array -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_is_n_divisible_by_x_and_y/IsNDivisibleTest.kt: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_is_n_divisible_by_x_and_y 2 | 3 | import org.junit.Test 4 | import org.junit.jupiter.api.Assertions.assertEquals 5 | 6 | class IsNDivisibleTest { 7 | 8 | @Test 9 | fun basicTests() { 10 | assertEquals(false, isDivisible(3, 3, 4)) 11 | assertEquals(true, isDivisible(12, 3, 4)) 12 | assertEquals(false, isDivisible(8, 3, 4)) 13 | assertEquals(true, isDivisible(48, 3, 4)) 14 | assertEquals(true, isDivisible(100, 5, 10)) 15 | assertEquals(false, isDivisible(100, 5, 3)) 16 | assertEquals(true, isDivisible(4, 4, 2)) 17 | assertEquals(false, isDivisible(5, 2, 3)) 18 | assertEquals(true, isDivisible(17, 17, 17)) 19 | assertEquals(true, isDivisible(17, 1, 17)) 20 | } 21 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_find_the_missing_letter/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/find-the-missing-letter/ 4 | 5 | ## Instructions 6 | 7 | Find the missing letter 8 | 9 | Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array. 10 | 11 | You will always get an valid array. And it will be always exactly one letter be missing. The length of the array will always be at least 2. 12 | The array will always contain letters in only one case. 13 | 14 | Example: 15 | 16 | ['a','b','c','d','f'] -> 'e' 17 | ['O','Q','R','S'] -> 'P' 18 | (Use the English alphabet with 26 letters!) 19 | 20 | Have fun coding it and please don't forget to vote and rank this kata! :-) 21 | 22 | I have also created other katas. Take a look if you enjoyed this kata! -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_how_many_lightsabers_do_you_own/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/how-many-lightsabers-do-you-own/train/javascript/5d8091d5caab81000ee390e5 4 | 5 | ## Instructions 6 | 7 | Inspired by the development team at Vooza, write the function 8 | ```js 9 | howManyLightsabersDoYouOwn/how_many_light_sabers_do_you_own 10 | ``` 11 | that accepts the name of a programmer, and 12 | returns the number of lightsabers owned by that person. 13 | The only person who owns lightsabers is Zach, by the way. He owns 18, which is an awesome number of lightsabers. Anyone else owns 0. 14 | 15 | Note: your function should have a default parameter. 16 | 17 | ```js 18 | howManyLightsabersDoYouOwn("anyone else") === 0 19 | howManyLightsabersDoYouOwn("Zach") === 18 20 | howManyLightsabersDoYouOwn() === 0 21 | ``` -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_row_of_the_odd_triangle/odd_row_test.py: -------------------------------------------------------------------------------- 1 | Test.assert_equals(odd_row(1), [1]) 2 | Test.assert_equals(odd_row(2), [3, 5]) 3 | 4 | Test.assert_equals(odd_row(13), [157, 159, 161, 163, 165, 167, 169, 171, 5 | 173, 175, 177, 179, 181]) 6 | 7 | Test.assert_equals(odd_row(19), [343, 345, 347, 349, 351, 353, 355, 357, 8 | 359, 361, 363, 365, 367, 369, 371, 373, 375, 377, 379]) 9 | 10 | Test.assert_equals(odd_row(41), [1641, 1643, 1645, 1647, 1649, 1651, 1653, 11 | 1655, 1657, 1659, 1661, 1663, 1665, 1667, 1669, 1671, 1673, 1675, 1677, 12 | 1679, 1681, 1683, 1685, 1687, 1689, 1691, 1693, 1695, 1697, 1699, 1701, 13 | 1703, 1705, 1707, 1709, 1711, 1713, 1715, 1717, 1719, 1721]) -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_exes_and_ohs/ExesAndOhs.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_exes_and_ohs; 2 | 3 | /* 4 | Check to see if a string has the same amount of 'x's and 'o's. The method must return a boolean and be case insensitive. The string can contain any char. 5 | 6 | Examples input/output: 7 | 8 | XO("ooxx") => true 9 | XO("xooxx") => false 10 | XO("ooxXm") => true 11 | XO("zpzpzpp") => true // when no 'x' and 'o' is present should return true 12 | XO("zzoo") => false 13 | 14 | */ 15 | 16 | class ExesAndOhs { 17 | 18 | static boolean getXO(String str) { 19 | int counter = 0; 20 | for (int i = 0; i < str.length(); ++i) { 21 | if (str.charAt(i) == 'X' || str.charAt(i) == 'x') ++counter; 22 | if (str.charAt(i) == 'O' || str.charAt(i) == 'o') --counter; 23 | } 24 | 25 | return counter == 0; 26 | } 27 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_classic_hello_world/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/57036f007fd72e3b77000023/ 4 | 5 | ## Instructions 6 | 7 | The main mode is having a method named main inside a class and should return nothing but should print a line to the standard output with the message Hello World! i.e. print the line Hello World! to the console. 8 | 9 | For Java the main method should receive String array as parameters that can be specified when running from console with the command. 10 | 11 | In many traditional programming languages can be only one main for a whole application since it denotes the application entry point. 12 | ``` 13 | java Solution.class parameter1 parameter2 14 | ``` 15 | Hints: 16 | 17 | Check your references 18 | Think about the scope of your method 19 | For prolog you can use write but there are better ways -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sum_of_minimums/SumOfMinimums.js: -------------------------------------------------------------------------------- 1 | /* 2 | Given an 2D array of size m * n. Your task is to find the sum of minimum value in each row. 3 | 4 | For Example: 5 | 6 | [ 7 | [1, 2, 3, 4, 5], // minimum value of row is 1 8 | [5, 6, 7, 8, 9], // minimum value of row is 5 9 | [20, 21, 34, 56, 100] // minimum value of row is 20 10 | ] 11 | So, the function should return 26 because sum of minimums is as 1 + 5 + 20 = 26 12 | 13 | */ 14 | 15 | function sumOfMinimums(arr) { 16 | let rowMin = Number.MAX_SAFE_INTEGER; 17 | let sumOfMaxValues = 0; 18 | for (let i = 0; i < arr.length; ++i) { 19 | rowMin = Number.MAX_SAFE_INTEGER; 20 | for (let j = 0; j < arr[i].length; ++j) { 21 | if (arr[i][j] < rowMin) rowMin = arr[i][j]; 22 | } 23 | sumOfMaxValues += rowMin; 24 | } 25 | 26 | return sumOfMaxValues; 27 | } -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_counting_duplicates/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/counting-duplicates/ 4 | 5 | ## Instructions 6 | 7 | Count the number of Duplicates 8 | Write a function that will return the count of 9 | distinct case-insensitive alphabetic characters 10 | and numeric digits that occur more than once in the input string. 11 | 12 | The input string can be assumed to contain only alphabets 13 | (both uppercase and lowercase) and numeric digits. 14 | 15 | Example 16 | ``` 17 | "abcde" -> 0 # no characters repeats more than once 18 | "aabbcde" -> 2 # 'a' and 'b' 19 | "aabBcde" -> 2 # 'a' occurs twice and 'b' twice (`b` and `B`) 20 | "indivisibility" -> 1 # 'i' occurs six times 21 | "Indivisibilities" -> 2 # 'i' occurs seven times and 's' occurs twice 22 | "aA11" -> 2 # 'a' and '1' 23 | "ABBA" -> 2 # 'A' and 'B' each occur twice 24 | ``` -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_find_the_odd_int/FindTheOddIntTest.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_find_the_odd_int; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class FindTheOddIntTest { 8 | 9 | @Test 10 | void findTest() { 11 | assertEquals(5, FindTheOddInt.findIt(new int[]{20, 1, -1, 2, -2, 3, 3, 5, 5, 1, 2, 4, 20, 4, -1, -2, 5})); 12 | assertEquals(-1, FindTheOddInt.findIt(new int[]{1, 1, 2, -2, 5, 2, 4, 4, -1, -2, 5})); 13 | assertEquals(5, FindTheOddInt.findIt(new int[]{20, 1, 1, 2, 2, 3, 3, 5, 5, 4, 20, 4, 5})); 14 | assertEquals(10, FindTheOddInt.findIt(new int[]{10})); 15 | assertEquals(10, FindTheOddInt.findIt(new int[]{1, 1, 1, 1, 1, 1, 10, 1, 1, 1, 1})); 16 | assertEquals(1, FindTheOddInt.findIt(new int[]{5, 4, 3, 2, 1, 5, 4, 3, 2, 10, 10})); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_bug_fixing_totaling/totaling.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Oh no! Timmys been moved into the database division of his software company but as we know Timmy loves making mistakes. 3 | 4 | Help Timmy keep his job by fixing his query... 5 | 6 | Timmy works for a statistical analysis company 7 | and has been given a task of totaling the number 8 | of sales on a given day grouped by each department name and then each day. 9 | 10 | Resultant table: 11 | day (type: date) {group by} [order by asc] 12 | department (type: text) {group by} [In a real world situation it is bad practice to name a column after a table] 13 | sale_count (type: int) 14 | */ 15 | 16 | SELECT 17 | DATE(s.transaction_date) AS day, 18 | d.name AS department, 19 | COUNT(s.id) AS sale_count 20 | FROM department d 21 | JOIN sale s ON d.id = s.department_id 22 | GROUP BY d.name, day 23 | ORDER BY DAY ASC -------------------------------------------------------------------------------- /src/_5kyu/_5kyu_moving_zeros_to_the_end/MovingZerosToTheEnd.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | /* 4 | Write an algorithm that takes an array 5 | and moves all of the zeros to the end, 6 | preserving the order of the other elements. 7 | 8 | Kata.MoveZeroes(new int[] {1, 2, 0, 1, 0, 1, 0, 3, 0, 1}) => new int[] {1, 2, 1, 1, 3, 1, 0, 0, 0, 0} 9 | */ 10 | 11 | public class Kata 12 | { 13 | public static int[] MoveZeroes(int[] arr) 14 | { 15 | return arr.OrderBy(x => x == 0).ToArray(); 16 | } 17 | 18 | public static int[] MoveZeroes2(int[] arr) 19 | { 20 | int nonZeroCounter = 0; 21 | 22 | for (int i = 0; i < arr.Length; ++i) { 23 | if (arr[i] != 0) { 24 | arr[nonZeroCounter++] = arr[i]; 25 | } 26 | } 27 | 28 | while (nonZeroCounter < arr.Length) 29 | arr[nonZeroCounter++] = 0; 30 | 31 | return arr; 32 | } 33 | } -------------------------------------------------------------------------------- /src/_5kyu/_5kyu_is_my_friend_cheating/IsMyFriendCheatingTest.java: -------------------------------------------------------------------------------- 1 | package _5kyu._5kyu_is_my_friend_cheating; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | class IsMyFriendCheatingTest { 11 | 12 | @Test 13 | void test12() { 14 | List res = new ArrayList<>(); 15 | res.add(new long[]{15, 21}); 16 | res.add(new long[]{21, 15}); 17 | 18 | List a = IsMyFriendCheating.removNb(26); 19 | assertArrayEquals(res.get(0), a.get(0)); 20 | assertArrayEquals(res.get(1), a.get(1)); 21 | } 22 | 23 | @Test 24 | void test14() { 25 | List res = new ArrayList<>(); 26 | List a = IsMyFriendCheating.removNb(100); 27 | assertEquals(res.size(), a.size()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_by_3_or_not_by_3_that_is_the_question/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/by-3-or-not-by-3-that-is-the-question/ 4 | 5 | ## Instructions 6 | 7 | A trick I learned in elementary school to determine whether or not 8 | a number was divisible by three is to add all of the integers 9 | in the number together and to divide the resulting sum by three. 10 | 11 | If there is no remainder from dividing the sum by three, 12 | then the original number is divisible by three as well. 13 | 14 | Given a series of numbers as a string, determine 15 | if the number represented by the string is divisible by three. 16 | 17 | You can expect all test case arguments to be strings representing values greater than 0. 18 | 19 | Example: 20 | 21 | ``` 22 | "123" -> true 23 | "8409" -> true 24 | "100853" -> false 25 | "33333333" -> true 26 | "7" -> false 27 | ``` -------------------------------------------------------------------------------- /src/_5kyu/_5kyu_sql_basics_group_by_day/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/5811597e9d278beb04000038/ 4 | 5 | ## Instructions 6 | 7 | There is an events table used to track different key activities taken on a website. 8 | 9 | For this task you need to filter the name field to only show "trained" events. 10 | 11 | Events should be grouped by the day they happened and counted. 12 | 13 | The description field is used to distinguish which items the events happened on. 14 | 15 | ```sql 16 | "events" Table Schema 17 | id 18 | name (String) 19 | created_at (DateTime) 20 | description (String) 21 | ``` 22 | The expected results is provided so that you can see what the expected output is supposed to look like. 23 | 24 | Your "actual" output needs to match the expected output. 25 | 26 | NOTE: Data is regenerated on each run, so don't expect to get the same data back twice. 27 | 28 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_basics_simple_exists/simple_exists_test.rb: -------------------------------------------------------------------------------- 1 | # DATA FOR TESTS IS AVAILABLE ONLY ON WEBSITE 2 | 3 | results = run_sql 4 | 5 | describe :query do 6 | describe "should contain keywords" do 7 | it "should contain EXISTS" do 8 | expect($sql.upcase).to include("EXISTS") 9 | end 10 | 11 | it "should contain WHERE" do 12 | expect($sql.upcase).to include("WHERE") 13 | end 14 | 15 | it "should not contain IN" do 16 | expect($sql.upcase).not_to include(" IN ") 17 | end 18 | end 19 | 20 | describe :columns do 21 | it "should return 2 columns" do 22 | expect(results.first.keys.count).to eq 2 23 | end 24 | 25 | it "should return an id column" do 26 | expect(results.first.keys).to include(:id) 27 | end 28 | 29 | it "should return a name column" do 30 | expect(results.first.keys).to include(:name) 31 | end 32 | end 33 | end -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_bug_fixing_totaling/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/582cba7d3be8ce3a8300007c/ 4 | 5 | ## Instructions 6 | 7 | Oh no! Timmys been moved into the database division of his software company but as we know Timmy loves making mistakes. 8 | 9 | Help Timmy keep his job by fixing his query... 10 | 11 | Timmy works for a statistical analysis company and has been given a task of totaling the number of sales on a given day grouped by each department name and then each day. 12 | 13 | ```sql 14 | Resultant table: 15 | 16 | day (type: date) {group by} [order by asc] 17 | department (type: text) {group by} [In a real world situation it is bad practice to name a column after a table] 18 | sale_count (type: int) 19 | Tables and relationship below: 20 | ``` 21 |

22 | DiaBeFriend 23 |

24 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sum_of_odd_numbers/SumOfOddNumbers.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_sum_of_odd_numbers; 2 | 3 | /* 4 | Given the triangle of consecutive odd numbers: 5 | ``` 6 | 1 7 | 3 5 8 | 7 9 11 9 | 13 15 17 19 10 | 21 23 25 27 29 11 | ... 12 | ``` 13 | 14 | Calculate the row sums of this triangle from the row index (starting at index 1) e.g.: 15 | 16 | rowSumOddNumbers(1); // 1 17 | rowSumOddNumbers(2); // 3 + 5 = 8 18 | */ 19 | 20 | class SumOfOddNumbers { 21 | 22 | static int rowSumOddNumbers(int n) { 23 | int firstInNthRow = n * n - (n - 1); 24 | int lastInNthRow = firstInNthRow + (n - 1) * 2; 25 | return (firstInNthRow + lastInNthRow) * n / 2; 26 | } 27 | 28 | // after simplification I noticed that it's same as 29 | 30 | static int rowSumOddNumbers2(int n) { 31 | return n * n * n; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/_4kyu/_4kyu_range_extraction/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/51ba717bb08c1cd60f00002f/ 4 | 5 | ## Instructions 6 | 7 | A format for expressing an ordered list of integers is to use a comma separated list of either individual integers 8 | or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. 9 | 10 | The range includes all integers in the interval including both endpoints. 11 | 12 | It is not considered a range unless it spans at least 3 numbers. For example ("12, 13, 15-17") 13 | 14 | Complete the solution so that it takes a list of integers in increasing order and returns a correctly formatted string in the range format. 15 | 16 | Example: 17 | ``` 18 | Solution.rangeExtraction(new int[] {-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20}) 19 | # returns "-6,-3-1,3-5,7-11,14,15,17-20" 20 | ``` -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_highest_scoring_word/HighestScoringWord.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Given a string of words, you need to find the highest scoring word. 3 | 4 | Each letter of a word scores points according to its position in the alphabet: a = 1, b = 2, c = 3 etc. 5 | 6 | You need to return the highest scoring word as a string. 7 | 8 | If two words score the same, return the word that appears earliest in the original string. 9 | 10 | All letters will be lowercase and all inputs will be valid. 11 | */ 12 | 13 | public class Kata { 14 | public static string High(string s) { 15 | int highestScore = 0; 16 | string highestScoredWord = ""; 17 | 18 | foreach(string word in s.Split(" ")) { 19 | int score = 0; 20 | foreach(char c in word) { 21 | score += c - 'a' + 1; 22 | } 23 | 24 | if (score > highestScore) { 25 | highestScore = score; 26 | highestScoredWord = word; 27 | } 28 | } 29 | 30 | return highestScoredWord; 31 | } 32 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_form_the_minimum/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/form-the-minimum/ 4 | 5 | ## Instructions 6 | 7 | Task 8 | Given a list of digits, 9 | return the smallest number that could be formed from these digits, 10 | using the digits only once (ignore duplicates). 11 | 12 | Notes: 13 | Only positive integers will be passed to the function (> 0 ), no negatives or zeros. 14 | Input >> Output Examples 15 | minValue ({1, 3, 1}) ==> return (13) 16 | Explanation: 17 | (13) is the minimum number could be formed from {1, 3, 1} , Without duplications 18 | 19 | minValue({5, 7, 5, 9, 7}) ==> return (579) 20 | Explanation: 21 | (579) is the minimum number could be formed from {5, 7, 5, 9, 7} , Without duplications 22 | 23 | minValue({1, 9, 3, 1, 7, 4, 6, 6, 7}) return ==> (134679) 24 | Explanation: 25 | (134679) is the minimum number could be formed from {1, 9, 3, 1, 7, 4, 6, 6, 7} , Without duplications -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_odder_than_the_rest/OdderThanTheRest.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a method that takes an array/list as an input, and outputs the index at which the sole odd number is located. 3 | 4 | This method should work with arrays with negative numbers. If there are no odd numbers in the array, then the method should output -1. 5 | 6 | Examples: 7 | 8 | oddOne([2,4,6,7,10]) // => 3 9 | oddOne([2,16,98,10,13,78]) // => 4 10 | oddOne([4,-8,98,-12,-7,90,100]) // => 4 11 | oddOne([2,4,6,8]) // => -1 12 | */ 13 | 14 | function oddOne(arr) { 15 | return arr.findIndex(i => i % 2 !== 0); 16 | } 17 | 18 | describe("Basic Tests", function(){ 19 | it("should pass basic tests", function(){ 20 | Test.assertEquals(oddOne([2,4,6,7,10]), 3); 21 | Test.assertEquals(oddOne([2,16,98,10,13,78]), 4); 22 | Test.assertEquals(oddOne([4,-8,98,-12,-7,90,100]), 4); 23 | Test.assertEquals(oddOne([2,4,6,8]), -1); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/_5kyu/_5kyu_sql_basics_group_by_day/group_by_day.sql: -------------------------------------------------------------------------------- 1 | /* 2 | There is an events table used to track different key activities taken on a website. 3 | 4 | For this task you need to filter the name field to only show "trained" events. 5 | 6 | Events should be grouped by the day they happened and counted. 7 | 8 | The description field is used to distinguish which items the events happened on. 9 | 10 | "events" Table Schema 11 | id 12 | name (String) 13 | created_at (DateTime) 14 | description (String) 15 | 16 | The expected results is provided so that you can see what the expected output is supposed to look like. 17 | 18 | Your "actual" output needs to match the expected output. 19 | 20 | NOTE: Data is regenerated on each run, so don't expect to get the same data back twice. 21 | 22 | 23 | */ 24 | 25 | SELECT DATE(created_at) as day, description, COUNT(*) as count 26 | FROM events 27 | GROUP BY name, day, description 28 | HAVING name = 'trained' -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_camelcase_method/CamelCaseMethod.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_camelcase_method; 2 | 3 | import java.util.Arrays; 4 | import java.util.stream.Collectors; 5 | 6 | /* 7 | Write simple .camelCase method 8 | (camel_case function in PHP, 9 | CamelCase in C# 10 | or camelCase in Java) for strings. 11 | All words must have their first letter capitalized without spaces. 12 | 13 | For instance: 14 | 15 | camelCase("hello case"); // => "HelloCase" 16 | camelCase("camel case word"); // => "CamelCaseWord" 17 | Don't forget to rate this kata! Thanks :) 18 | */ 19 | 20 | class CamelCaseMethod { 21 | 22 | static String camelCase(String str) { 23 | return Arrays.stream(str.split("\\s")) 24 | .filter(e -> !e.isEmpty()) 25 | .map(e -> e.substring(0, 1).toUpperCase() + e.substring(1).toLowerCase()) 26 | .collect(Collectors.joining()) 27 | .replaceAll("\\s", ""); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_circularly_sorted_array/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/circularly-sorted-array/ 4 | 5 | ## Instructions 6 | 7 | An array is circularly sorted if the elements are sorted in ascending order, but displaced, or rotated, by any number of steps. 8 | 9 | Complete the function/method that determines if the given array of integers is circularly sorted. 10 | 11 | Examples 12 | These arrays are circularly sorted (true): 13 | ``` 14 | [2, 3, 4, 5, 0, 1] --> [0, 1] + [2, 3, 4, 5] 15 | [4, 5, 6, 9, 1] --> [1] + [4, 5, 6, 9] 16 | [10, 11, 6, 7, 9] --> [6, 7, 9] + [10, 11] 17 | [1, 2, 3, 4, 5] --> [1, 2, 3, 4, 5] 18 | [5, 7, 43, 987, -9, 0] --> [-9, 0] + [5, 7, 43, 987] 19 | [1, 2, 3, 4, 1] --> [1] + [1, 2, 3, 4] 20 | ``` 21 | 22 | While these are not (false): 23 | ``` 24 | [4, 1, 2, 5] 25 | [8, 7, 6, 5, 4, 3] 26 | [6, 7, 4, 8] 27 | [7, 6, 5, 4, 3, 2, 1] 28 | ``` -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_meeting/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/meeting/ 4 | 5 | ## Instructions 6 | 7 | John has invited some friends. His list is: 8 | 9 | s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"; 10 | Could you make a program that 11 | 12 | makes this string uppercase 13 | gives it sorted in alphabetical order by last name. 14 | When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma. 15 | 16 | So the result of function meeting(s) will be: 17 | 18 | "(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)" 19 | It can happen that in two distinct families with the same family name two people have the same first name too. 20 | 21 | Notes 22 | You can see another examples in the "Sample tests". 23 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_linked_lists_length_and_count/length_and_count_test.py: -------------------------------------------------------------------------------- 1 | test.describe("tests for counting the length of a linked list.") 2 | list = build_one_two_three() 3 | test.assert_equals(length(None), 0, "Length of null list should be zero.") 4 | test.assert_equals(length(Node(99)), 1, "Length of single node list should be one.") 5 | test.assert_equals(length(list), 3, "Length of the three node list should be three.") 6 | 7 | test.describe("tests for counting occurrences of a particular integer in a linked list.") 8 | list = build_one_two_three(); 9 | test.assert_equals(count(list, 1), 1, "list should only contain one 1.") 10 | test.assert_equals(count(list, 2), 1, "list should only contain one 2.") 11 | test.assert_equals(count(list, 3), 1, "list should only contain one 3.") 12 | test.assert_equals(count(list, 99), 0, "list should return zero for integer not found in list.") 13 | test.assert_equals(count(None, 1), 0, "null list should always return count of zero.") -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_counting_sheep_dot_dot_dot/Counter.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_counting_sheep_dot_dot_dot; 2 | 3 | /* 4 | Consider an array of sheep where some sheep may be missing from their place. 5 | We need a function that counts the number of sheep present in the array (true means present). 6 | 7 | For example, 8 | 9 | [true, true, true, false, 10 | true, true, true, true , 11 | true, false, true, false, 12 | true, false, false, true , 13 | true, true, true, true , 14 | false, false, true, true] 15 | The correct answer would be 17. 16 | 17 | Hint: Don't forget to check for bad values like null/undefined 18 | */ 19 | 20 | import java.util.Arrays; 21 | import java.util.Objects; 22 | 23 | class Counter { 24 | int countSheeps(Boolean[] arrayOfSheeps) { 25 | return (int) Arrays.stream(arrayOfSheeps) 26 | .filter(Objects::nonNull) 27 | .filter(e -> e) 28 | .count(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_how_many_lightsabers_do_you_own/HowManyLightSabersDoYouOwn.js: -------------------------------------------------------------------------------- 1 | /* 2 | Inspired by the development team at Vooza, write the function 3 | 4 | howManyLightsabersDoYouOwn/how_many_light_sabers_do_you_own 5 | 6 | that accepts the name of a programmer, and 7 | returns the number of lightsabers owned by that person. 8 | The only person who owns lightsabers is Zach, by the way. He owns 18, which is an awesome number of lightsabers. Anyone else owns 0. 9 | 10 | Note: your function should have a default parameter.\ 11 | 12 | howManyLightsabersDoYouOwn("anyone else") === 0 13 | howManyLightsabersDoYouOwn("Zach") === 18 14 | howManyLightsabersDoYouOwn() === 0 15 | 16 | */ 17 | 18 | function howManyLightsabersDoYouOwn(name) { 19 | return name === "Zach" ? 18 : 0; 20 | } 21 | 22 | Test.assertEquals( howManyLightsabersDoYouOwn(), 0 ) 23 | Test.assertEquals( howManyLightsabersDoYouOwn("Adam"), 0 ) 24 | Test.assertEquals( howManyLightsabersDoYouOwn("Zach"), 18 ) -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_l1_set_alarm/SetAlarm.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_l1_set_alarm; 2 | 3 | /* 4 | Write a function named setAlarm which receives two parameters. 5 | The first parameter, employed, is true whenever 6 | you are employed and the second parameter, vacation is true whenever you are on vacation. 7 | 8 | The function should return true 9 | if you are employed and not on vacation 10 | (because these are the circumstances under which you need to set an alarm). 11 | It should return false otherwise. Examples: 12 | 13 | setAlarm(true, true) -> false 14 | setAlarm(false, true) -> false 15 | setAlarm(false, false) -> false 16 | setAlarm(true, false) -> true 17 | 18 | setalarm(true, true) -> false 19 | setalarm(false, true) -> false 20 | setalarm(false, false) -> false 21 | setalarm(true, false) -> true 22 | */ 23 | 24 | class SetAlarm { 25 | 26 | static boolean setAlarm(boolean employed, boolean vacation) { 27 | return employed && !vacation; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_flatten_and_sort_an_array/FlattenAndSort.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_flatten_and_sort_an_array; 2 | 3 | import java.util.Arrays; 4 | 5 | /* 6 | Challenge: 7 | 8 | Given a two-dimensional array of integers, return the flattened version of the array with all the integers in the sorted (ascending) order. 9 | 10 | Example: 11 | 12 | Given [[3, 2, 1], [4, 6, 5], [], [9, 7, 8]], your function should return [1, 2, 3, 4, 5, 6, 7, 8, 9]. 13 | 14 | Addendum: 15 | 16 | Please, keep in mind, that JavaScript is by default sorting objects alphabetically. For more information, please consult: 17 | 18 | http://stackoverflow.com/questions/6093874/why-doesnt-the-sort-function-of-javascript-work-well 19 | 20 | */ 21 | 22 | class FlattenAndSort { 23 | 24 | static int[] flattenAndSort(int[][] array) { 25 | return Arrays.stream(array) 26 | .flatMapToInt(Arrays::stream) 27 | .sorted() 28 | .toArray(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_classic_hello_world/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_classic_hello_world; 2 | 3 | /* 4 | The main mode is having a method named main inside a class 5 | and should return nothing but should print a line to the standard output 6 | with the message Hello World! i.e. print the line Hello World! to the console. 7 | 8 | For Java the main method should receive String array as parameters 9 | that can be specified when running from console with the command. 10 | 11 | In many traditional programming languages can be only one main 12 | for a whole application since it denotes the application entry point. 13 | 14 | java Solution.class parameter1 parameter2 15 | Hints: 16 | 17 | Check your references 18 | Think about the scope of your method 19 | For prolog you can use write but there are better ways 20 | */ 21 | 22 | public class HelloWorld { 23 | 24 | public static void main(String[] args) { 25 | System.out.println("Hello World!"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/_5kyu/_5kyu_mean_square_error/MeanSquare.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | /* 4 | Complete the function that 5 | 6 | accepts two integer arrays of equal length 7 | compares the value each member in one array to the corresponding member in the other 8 | squares the absolute value difference between those two values 9 | and returns the average of those squared absolute value difference between each member pair. 10 | Examples 11 | [1, 2, 3], [4, 5, 6] --> 9 because (9 + 9 + 9) / 3 12 | [10, 20, 10, 2], [10, 25, 5, -2] --> 16.5 because (0 + 25 + 25 + 16) / 4 13 | [-1, 0], [0, -1] --> 1 because (1 + 1) / 2 14 | */ 15 | 16 | public class MeanSquare 17 | { 18 | public static double Solution(int[] firstArray, int[] secondArray) 19 | { 20 | double sum = 0; 21 | for(int i = 0; i < firstArray.Length; ++i) { 22 | sum += Math.Pow(Math.Abs(firstArray[i] - secondArray[i]), 2); 23 | } 24 | 25 | return sum / firstArray.Length; 26 | } 27 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_flatten_and_sort_an_array/FlattenAndSortTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_flatten_and_sort_an_array; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; 6 | 7 | class FlattenAndSortTest { 8 | 9 | @Test 10 | void exampleTest() { 11 | assertArrayEquals(new int[]{}, FlattenAndSort.flattenAndSort(new int[][]{})); 12 | assertArrayEquals(new int[]{1}, FlattenAndSort.flattenAndSort(new int[][]{{}, {1}})); 13 | assertArrayEquals(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, FlattenAndSort.flattenAndSort(new int[][]{{3, 2, 1}, {7, 9, 8}, {6, 4, 5}})); 14 | assertArrayEquals(new int[]{1, 2, 3, 4, 5, 6, 100}, FlattenAndSort.flattenAndSort(new int[][]{{1, 3, 5}, {100}, {2, 4, 6}})); 15 | assertArrayEquals(new int[]{111, 222, 333, 444, 555, 666, 777, 888, 999}, FlattenAndSort.flattenAndSort(new int[][]{{111, 999}, {222}, {333}, {444}, {888}, {777}, {666}, {555}})); 16 | } 17 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_calculate_two_peoples_individual_ages/CalculateTwoPeoplesIndividualAges.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a function that takes in the sum and age difference of two people, 3 | calculates their individual ages, 4 | and returns a pair of values if those exist or an empty values if: 5 | 6 | sum < 0 7 | difference < 0 8 | Either of the calculated ages come out to be negative 9 | */ 10 | 11 | function getAges(sum, difference) { 12 | if (sum < 0 || difference < 0) return null; 13 | var first = (sum + difference) / 2; 14 | var second = (sum - difference) / 2; 15 | if (first < 0 || second < 0) return null; 16 | return [first, second]; 17 | } 18 | 19 | Test.describe('Calculating Individual Ages ', function () { 20 | it("it returns 14,10 when passed 24,4", function () { 21 | Test.assertSimilar(getAges(24, 4), [14, 10]); 22 | }); 23 | it("it returns null when passed 63,-14", function () { 24 | Test.assertSimilar(getAges(63, -14), null); 25 | }); 26 | }); -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_correct_the_mistakes_of_the_character_recognition_software/CorrectMistakes.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_correct_the_mistakes_of_the_character_recognition_software; 2 | 3 | /* 4 | Character recognition software is widely used to digitise printed texts. 5 | Thus the texts can be edited, searched and stored on a computer. 6 | 7 | When documents (especially pretty old ones written with a typewriter), 8 | are digitised character recognition softwares often make mistakes. 9 | 10 | Your task is correct the errors in the digitised text. 11 | You only have to handle the following mistakes: 12 | 13 | S is misinterpreted as 5 14 | O is misinterpreted as 0 15 | I is misinterpreted as 1 16 | The test cases contain numbers only by mistake. 17 | */ 18 | 19 | class CorrectMistakes { 20 | 21 | static String correct(String string) { 22 | return string 23 | .replaceAll("5", "S") 24 | .replaceAll("0", "O") 25 | .replaceAll("1", "I"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_calculate_number_of_inversions_in_array/Calculate.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Array inversion indicates how far the array is from being sorted. 3 | 4 | Inversions are pairs of elements in array, that are out of order. 5 | 6 | Examples 7 | Kata.CountInversions(new int[] { 1,2,3,4 }); // 0 inversions 8 | 9 | Kata.CountInversions(new int[] { 1,3,2,4 }); // 1 inversion: 2 and 3 10 | 11 | Kata.CountInversions(new int[] { 4,1,2,3 }); // 3 inversions: 4 and 1, 4 and 2, 4 and 3 12 | 13 | Kata.CountInversions(new int[] { 4,3,2,1 }); // 6 inversions: 4 and 3, 4 and 2, 4 and 1, 3 and 2, 3 and 1, 2 and 1 14 | Goal 15 | The goal is to come up with a function that can calculate inversions for any arbitrary array 16 | */ 17 | 18 | public class Calculate 19 | { 20 | public static int CountInversions(int[] array) 21 | { 22 | int counter = 0; 23 | for (int i = 0; i < array.Length - 1; ++i) { 24 | for (int j = i + 1; j < array.Length; ++j) { 25 | if (array[i] > array[j]) ++counter; 26 | } 27 | } 28 | 29 | return counter; 30 | } 31 | } -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_count_the_monkeys/MonkeyCounter.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_count_the_monkeys; 2 | 3 | import java.util.stream.*; 4 | /* 5 | You take your son to the forest to see the monkeys. 6 | You know that there are a certain number there (n), 7 | but your son is too young to just appreciate the full number, 8 | he has to start counting them from 1. 9 | 10 | As a good parent, you will sit and count with him. 11 | Given the number (n), populate an array with all numbers up to and including that number, but excluding zero. 12 | 13 | For example: 14 | 15 | monkeyCount(10) // --> new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} 16 | monkeyCount(1) // --> new int[]{1} 17 | */ 18 | 19 | class MonkeyCounter { 20 | 21 | static int[] monkeyCount(final int n) { 22 | return IntStream.rangeClosed(1, n).toArray(); 23 | } 24 | 25 | static int[] monkeyCount2(final int n) { 26 | int[] result = new int[n]; 27 | for (int i = 0; i < n; ++i) { 28 | result[i] = i + 1; 29 | } 30 | 31 | return result; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_exes_and_ohs/ExesAndOhsTest.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_exes_and_ohs; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class ExesAndOhsTest { 8 | 9 | @Test 10 | void testSomething1() { 11 | assertTrue(ExesAndOhs.getXO("xxxooo")); 12 | } 13 | 14 | @Test 15 | void testSomething2() { 16 | assertTrue(ExesAndOhs.getXO("xxxXooOo")); 17 | } 18 | 19 | @Test 20 | void testSomething3() { 21 | assertFalse(ExesAndOhs.getXO("xxx23424esdsfvxXXOOooo")); 22 | } 23 | 24 | @Test 25 | void testSomething4() { 26 | assertFalse(ExesAndOhs.getXO("xXxxoewrcoOoo")); 27 | } 28 | 29 | @Test 30 | void testSomething5() { 31 | assertFalse(ExesAndOhs.getXO("XxxxooO")); 32 | } 33 | 34 | @Test 35 | void testSomething6() { 36 | assertTrue(ExesAndOhs.getXO("zssddd")); 37 | } 38 | 39 | @Test 40 | void testSomething7() { 41 | assertFalse(ExesAndOhs.getXO("Xxxxertr34")); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_leap_years/LeapYears.js: -------------------------------------------------------------------------------- 1 | /* 2 | In this kata you should simply determine, whether a given year is a leap year or not. In case you don't know the rules, here they are: 3 | 4 | years divisible by 4 are leap years 5 | but years divisible by 100 are not leap years 6 | but years divisible by 400 are leap years 7 | Additional Notes: 8 | 9 | Only valid years (positive integers) will be tested, so you don't have to validate them 10 | Examples can be found in the test fixture. 11 | */ 12 | 13 | function isLeapYear(year) { 14 | return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; 15 | } 16 | 17 | describe('leap year', function() { 18 | it('should detect leap years', function() { 19 | Test.assertEquals(isLeapYear(1234), false, 'Year 1234'); 20 | Test.assertEquals(isLeapYear(1984), true, 'Year 1984'); 21 | Test.assertEquals(isLeapYear(2000), true, 'Year 2000'); 22 | Test.assertEquals(isLeapYear(2010), false, 'Year 2010'); 23 | Test.assertEquals(isLeapYear(2013), false, 'Year 2013'); 24 | }); 25 | }); -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_sql_with_lotr_elven_wildcards/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/sql-with-lotr-elven-wildcards/solutions/sql 4 | 5 | ## Instructions 6 | 7 | Deep within the fair realm of Lothlórien, 8 | you have been asked to create a shortlist of candidates 9 | for a recently vacated position on the council. 10 | 11 | Of so many worthy elves, who to choose for such a lofty position? 12 | 13 | After much thought you decide to select candidates by name, 14 | which are often closely aligned to an elf's skill and temperament. 15 | 16 | Choose those with tegil appearing anywhere in their first name, 17 | as they are likely to be good calligraphers, 18 | OR those with astar anywhere in their last name, 19 | who will be faithful to the role. 20 | 21 | Elves table: 22 | 23 | firstname 24 | lastname 25 | 26 | all names are in lowercase 27 | 28 | To aid the scribes, return the firstname 29 | and lastname column concatenated, 30 | separated by a space, into a single shortlist column, 31 | and capitalise the first letter of each name. -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_a_needle_in_the_haystack/NeedleExampleTests.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_a_needle_in_the_haystack; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class NeedleExampleTests { 8 | 9 | @Test 10 | void tests() { 11 | Object[] haystack1 = {"3", "123124234", null, "needle", "world", "hay", 2, "3", true, false}; 12 | Object[] haystack2 = {"283497238987234", "a dog", "a cat", "some random junk", "a piece of hay", "needle", "something somebody lost a while ago"}; 13 | Object[] haystack3 = {1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 5, 4, 3, 4, 5, 6, 67, 5, 5, 3, 3, 4, 2, 34, 234, 23, 4, 234, 324, 324, "needle", 1, 2, 3, 4, 5, 5, 6, 5, 4, 32, 3, 45, 54}; 14 | assertEquals("found the needle at position 3", NeedleInTheHaystack.findNeedle(haystack1)); 15 | assertEquals("found the needle at position 5", NeedleInTheHaystack.findNeedle(haystack2)); 16 | assertEquals("found the needle at position 30", NeedleInTheHaystack.findNeedle(haystack3)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_new_cashier_does_not_know_about_space_or_shift/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/new-cashier-does-not-know-about-space-or-shift/ 4 | 5 | ## Instructions 6 | 7 | Some new cashiers started to work at your restaurant. 8 | 9 | They are good at taking orders, but they don't know how to capitalize words, or use a space bar! 10 | 11 | All the orders they create look something like this: 12 | 13 | "milkshakepizzachickenfriescokeburgerpizzasandwichmilkshakepizza" 14 | 15 | The kitchen staff are threatening to quit, because of how difficult it is to read the orders. 16 | 17 | Their preference is to get the orders as a nice clean string with spaces and capitals like so: 18 | 19 | "Burger Fries Chicken Pizza Pizza Pizza Sandwich Milkshake Milkshake Coke" 20 | 21 | The kitchen staff expect the items to be in the same order as they appear in the menu. 22 | 23 | The menu items are fairly simple, there is no overlap in the names of the items: 24 | 25 | 1. Burger 26 | 2. Fries 27 | 3. Chicken 28 | 4. Pizza 29 | 5. Sandwich 30 | 6. Onionrings 31 | 7. Milkshake 32 | 8. Coke 33 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_basics_simple_table_totaling/simple_table_totaling_test.rb: -------------------------------------------------------------------------------- 1 | results = run_sql 2 | 3 | describe :items do 4 | it "should return all unique clan names" do 5 | clan_names = [] 6 | results.each do |result| 7 | expect(clan_names).to satisfy { |value| value != result[:clan] } 8 | clan_names.push(result[:clan]) 9 | end 10 | end 11 | 12 | 13 | it "should order by total_points descending" do 14 | last_highest = Float::INFINITY 15 | results.each do |result| 16 | expect(result[:total_points]).to be <= last_highest 17 | last_highest = result[:total_points] 18 | end 19 | end 20 | 21 | it "ranking should be in ascending order" do 22 | last_highest = 0 23 | results.each do |result| 24 | expect(result[:rank]).to be >= last_highest 25 | last_highest = result[:rank] 26 | end 27 | end 28 | 29 | it "sum of total people should equal 100" do 30 | sum_of_total_people = 0 31 | results.each do |result| 32 | sum_of_total_people += result[:total_people] 33 | end 34 | expect(sum_of_total_people).to eq 100 35 | end 36 | end -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_maximum_multiple/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/maximum-multiple/solutions 4 | 5 | ## Instructions 6 | 7 | Task 8 | 9 | Given a Divisor and a Bound , Find the largest integer N , Such That , 10 | 11 | Conditions : 12 | ``` 13 | N is divisible by divisor 14 | 15 | N is less than or equal to bound 16 | 17 | N is greater than 0. 18 | ``` 19 | Notes 20 | The parameters (divisor, bound) passed to the function are only positve values . 21 | It's guaranteed that a divisor is Found . 22 | Input >> Output Examples 23 | 24 | ```java 25 | maxMultiple (2,7) ==> return (6) 26 | ``` 27 | 28 | Explanation: 29 | (6) is divisible by (2) , (6) is less than or equal to bound (7) , and (6) is > 0 . 30 | 31 | ```java 32 | maxMultiple (10,50) ==> return (50) 33 | ``` 34 | 35 | Explanation: 36 | (50) is divisible by (10) , (50) is less than or equal to bound (50) , and (50) is > 0 .* 37 | 38 | ```java 39 | maxMultiple (37,200) ==> return (185) 40 | ``` 41 | 42 | Explanation: 43 | (185) is divisible by (37) , (185) is less than or equal to bound (200) , and (185) is > 0 . 44 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_square_every_digit/SquareDigit.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_square_every_digit; 2 | 3 | import java.util.stream.Collectors; 4 | 5 | /* 6 | Welcome. In this kata, you are asked to square every digit of a number. 7 | 8 | For example, if we run 9119 through the function, 811181 will come out, because 92 is 81 and 12 is 1. 9 | 10 | Note: The function accepts an integer and returns an integer 11 | */ 12 | 13 | class SquareDigit { 14 | 15 | int squareDigits(int n) { 16 | StringBuilder result = new StringBuilder(); 17 | 18 | while (n != 0) { 19 | int digit = n % 10; 20 | result.insert(0, digit * digit); 21 | n /= 10; 22 | } 23 | 24 | return Integer.parseInt(result.toString()); 25 | } 26 | 27 | int squareDigits2(int n) { 28 | return Integer.parseInt(String.valueOf(n) 29 | .chars() 30 | .map(c -> Integer.parseInt(String.valueOf((char) c))) 31 | .map(c -> c * c) 32 | .mapToObj(String::valueOf) 33 | .collect(Collectors.joining(""))); 34 | } 35 | } -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_drying_potatoes/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/drying-potatoes/java 4 | 5 | ## Instructions 6 | 7 | All we eat is water and dry matter. 8 | 9 | John bought potatoes: their weight is 100 kilograms. Potatoes contain water and dry matter. 10 | 11 | The water content is 99 percent of the total weight. He thinks they are too wet and puts them in an oven - at low temperature - for them to lose some water. 12 | 13 | At the output the water content is only 98%. 14 | 15 | What is the total weight in kilograms (water content plus dry matter) coming out of the oven? 16 | 17 | He finds 50 kilograms and he thinks he made a mistake: "So much weight lost for such a small change in water content!" 18 | 19 | Can you help him? 20 | 21 | Write function potatoes with 22 | ```java 23 | int parameter p0 - initial percent of water- 24 | int parameter w0 - initial weight - 25 | int parameter p1 - final percent of water - 26 | ``` 27 | potatoes should return the final weight coming out of the oven w1 truncated as an int. 28 | 29 | Example: 30 | ```java 31 | potatoes(99, 100, 98) --> 50 32 | ``` -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_highest_scoring_word/HighestScoringWord.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_highest_scoring_word; 2 | 3 | /* 4 | Given a string of words, you need to find the highest scoring word. 5 | 6 | Each letter of a word scores points according to its position in the alphabet: a = 1, b = 2, c = 3 etc. 7 | 8 | You need to return the highest scoring word as a string. 9 | 10 | If two words score the same, return the word that appears earliest in the original string. 11 | 12 | All letters will be lowercase and all inputs will be valid. 13 | */ 14 | 15 | class HighestScoringWord { 16 | 17 | static String high(String s) { 18 | 19 | int highestScore = 0; 20 | String highestScoredWord = ""; 21 | 22 | for (String word : s.split(" ")) { 23 | int score = 0; 24 | for (char c : word.toCharArray()) { 25 | score += c - 'a' + 1; 26 | } 27 | 28 | if (score > highestScore) { 29 | highestScore = score; 30 | highestScoredWord = word; 31 | } 32 | } 33 | 34 | return highestScoredWord; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_unlucky_days/UnluckyDays.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_unlucky_days; 2 | 3 | import java.time.DayOfWeek; 4 | import java.time.LocalDate; 5 | 6 | /* 7 | Friday 13th or Black Friday is considered as unlucky day. 8 | 9 | Calculate how many unlucky days are in the given year. 10 | 11 | Find the number of Friday 13th in the given year. 12 | 13 | Input: Year as an integer. 14 | 15 | Output: Number of Black Fridays in the year as an integer. 16 | 17 | Examples: 18 | 19 | unluckyDays(2015) == 3 20 | unluckyDays(1986) == 1 21 | Note: In Ruby years will start from 1593. 22 | */ 23 | 24 | class UnluckyDays { 25 | 26 | static int unluckyDays(int year) { 27 | LocalDate first = LocalDate.of(year, 1, 1); 28 | LocalDate last = LocalDate.of(year, 12, 31); 29 | 30 | int counter = 0; 31 | for (LocalDate date = first; date.isBefore(last); date = date.plusDays(1)) { 32 | if (DayOfWeek.FRIDAY.equals(date.getDayOfWeek()) 33 | && date.getDayOfMonth() == 13) { 34 | ++counter; 35 | } 36 | } 37 | 38 | return counter; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_find_the_first_non_consecutive_number/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/find-the-first-non-consecutive-number/ 4 | 5 | ## Instructions 6 | 7 | Your task is to find the first element of an array 8 | that is not consecutive. 9 | 10 | E.g. If we have an array [1,2,3,4,6,7,8] then 1 then 2 11 | then 3 then 4 are all consecutive but 6 is not, 12 | so that's the first non-consecutive number. 13 | 14 | If the whole array is consecutive then return null2. 15 | 16 | The array will always have at least 2 elements1 and 17 | all elements will be numbers. 18 | 19 | The numbers will also all be unique and in ascending order. 20 | 21 | The numbers could be positive or negative 22 | and the first non-consecutive could be either too! 23 | 24 | If you like this Kata, maybe try this one next: 25 | 26 | https://www.codewars.com/kata/represent-array-of-numbers-as-ranges 27 | 28 | 1 Can you write a solution that will return null2 for both [] and [ x ] though? ( This is not tested, but you can write your own example test. ) 29 | 30 | 2 31 | Swift, Ruby and Crystal: nil 32 | Haskell: Nothing 33 | Python: None -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_basics_simple_table_totaling/README.md: -------------------------------------------------------------------------------- 1 | ## Solution for problem: 2 | 3 | https://www.codewars.com/kata/sql-basics-simple-table-totaling/ 4 | 5 | ## Instructions 6 | 7 | For this challenge you need to create a simple query 8 | to display each unique clan with their total points 9 | and ranked by their total points. 10 | 11 | ``` 12 | people table schema 13 | 14 | name 15 | points 16 | clan 17 | ``` 18 | 19 | You should then return a table that resembles below 20 | 21 | select on 22 | 23 | ``` 24 | rank 25 | clan 26 | total_points 27 | total_people 28 | ``` 29 | 30 | The query must rank each clan by their total_points, 31 | you must return each unqiue clan and if there is no clan name 32 | (i.e. it's an empty string) you must replace it with [no clan specified], 33 | you must sum the total_points for each clan and the total_people within that clan. 34 | 35 | Note The data is loaded from the live leaderboard, 36 | this means values will change but also could cause 37 | the kata to time out retreiving the information. 38 | 39 | NOTE: You're solution should use pure SQL. 40 | Ruby is used within the test cases to do the actual testing. -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_find_the_odd_int/FindTheOddInt.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_find_the_odd_int; 2 | 3 | /* 4 | Given an array, find the int that appears an odd number of times. 5 | 6 | There will always be only one integer that appears an odd number of times. 7 | */ 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | class FindTheOddInt { 13 | 14 | // my first, naive solution: 15 | 16 | static int findIt(int[] a) { 17 | Map occurrences = new HashMap<>(); 18 | for (int value : a) { 19 | int counter = occurrences.getOrDefault(value, 0); 20 | occurrences.put(value, counter + 1); 21 | } 22 | 23 | for (Map.Entry entry : occurrences.entrySet()) { 24 | if (entry.getValue() % 2 == 1) return entry.getKey(); 25 | } 26 | 27 | throw new IllegalArgumentException("Incorrect array"); 28 | } 29 | 30 | // smart solution 31 | 32 | public static int findIt2(int[] a) { 33 | int xor = 0; 34 | 35 | for (int value : a) { 36 | xor ^= value; 37 | } 38 | 39 | return xor; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_detect_pangram/PangramChecker.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_detect_pangram; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | /* 8 | A pangram is a sentence that contains every single letter of the alphabet at least once. 9 | For example, the sentence "The quick brown fox jumps over the lazy dog" is a pangram, 10 | because it uses the letters A-Z at least once (case is irrelevant). 11 | 12 | Given a string, detect whether or not it is a pangram. 13 | Return True if it is, False if not. Ignore numbers and punctuation. 14 | */ 15 | 16 | public class PangramChecker { 17 | 18 | public boolean check(String sentence) { 19 | for (char c = 'a'; c <= 'z'; ++c) { 20 | if (!sentence.toLowerCase().contains("" + c)) 21 | return false; 22 | } 23 | 24 | return true; 25 | } 26 | 27 | public boolean check2(String sentence) { 28 | String replacedSentence = sentence.replaceAll("[^A-Za-z]", ""); 29 | Set lettersInSentence = new HashSet<>(Arrays.asList(replacedSentence.split(""))); 30 | return lettersInSentence.size() >= 26; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_sql_basics_simple_in/simple_in_test.rb: -------------------------------------------------------------------------------- 1 | results = run_sql 2 | 3 | describe :query do 4 | describe "should contain keywords" do 5 | it "should contain IN" do 6 | expect($sql.upcase).to include("IN") 7 | end 8 | 9 | it "should contain WHERE" do 10 | expect($sql.upcase).to include("WHERE") 11 | end 12 | 13 | it "should not contain EXISTS" do 14 | expect($sql.upcase).not_to include("EXISTS") 15 | end 16 | 17 | it "should not contain JOIN" do 18 | expect($sql.upcase).not_to include("JOIN") 19 | end 20 | 21 | it "should not contain DISTINCT" do 22 | expect($sql.upcase).not_to include("DISTINCT") 23 | end 24 | 25 | it "should not contain LIMIT" do 26 | expect($sql.upcase).not_to include("LIMIT") 27 | end 28 | end 29 | 30 | describe :columns do 31 | it "should return 2 columns" do 32 | expect(results.first.keys.count).to eq 2 33 | end 34 | 35 | it "should return an id column" do 36 | expect(results.first.keys).to include(:id) 37 | end 38 | 39 | it "should return a name column" do 40 | expect(results.first.keys).to include(:name) 41 | end 42 | end 43 | end -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_form_the_minimum/FormTheMinimum.java: -------------------------------------------------------------------------------- 1 | package _7kyu._7kyu_form_the_minimum; 2 | 3 | import java.util.Arrays; 4 | 5 | /* 6 | Task 7 | Given a list of digits, 8 | return the smallest number that could be formed from these digits, 9 | using the digits only once (ignore duplicates). 10 | 11 | Notes: 12 | Only positive integers will be passed to the function (> 0 ), no negatives or zeros. 13 | Input >> Output Examples 14 | minValue ({1, 3, 1}) ==> return (13) 15 | Explanation: 16 | (13) is the minimum number could be formed from {1, 3, 1} , Without duplications 17 | 18 | minValue({5, 7, 5, 9, 7}) ==> return (579) 19 | Explanation: 20 | (579) is the minimum number could be formed from {5, 7, 5, 9, 7} , Without duplications 21 | 22 | minValue({1, 9, 3, 1, 7, 4, 6, 6, 7}) return ==> (134679) 23 | Explanation: 24 | (134679) is the minimum number could be formed from {1, 9, 3, 1, 7, 4, 6, 6, 7} , Without duplications 25 | */ 26 | 27 | class FormTheMinimum { 28 | 29 | static int minValue(int[] values) { 30 | return Arrays.stream(values) 31 | .distinct() 32 | .sorted() 33 | .reduce(0, (a, b) -> a * 10 + b); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/_7kyu/_7kyu_longest_vowel_chain/longestVowelChain.js: -------------------------------------------------------------------------------- 1 | /* 2 | The vowel substrings in the word codewarriors are o,e,a,io. The longest of these has a length of 2. Given a lowercase string that has alphabetic characters only and no spaces, return the length of the longest vowel substring. Vowels are any of aeiou. 3 | 4 | Good luck! 5 | 6 | If you like substring Katas, please try: 7 | 8 | Non-even substrings 9 | 10 | Vowel-consonant lexicon 11 | */ 12 | 13 | function solve(s) { 14 | const splittedVowels = s.replace(/[^aeiou]/ig, " ").split(" "); 15 | 16 | var maxLength = 0; 17 | splittedVowels.forEach(function (elem) { 18 | maxLength = Math.max(elem.length, maxLength); 19 | }); 20 | 21 | return maxLength; 22 | } 23 | 24 | describe("Basic tests", function () { 25 | Test.assertEquals(solve("codewarriors"), 2); 26 | Test.assertEquals(solve("suoidea"), 3); 27 | Test.assertEquals(solve("ultrarevolutionariees"), 3); 28 | Test.assertEquals(solve("strengthlessnesses"), 1); 29 | Test.assertEquals(solve("cuboideonavicuare"), 2); 30 | Test.assertEquals(solve("chrononhotonthuooaos"), 5); 31 | Test.assertEquals(solve("iiihoovaeaaaoougjyaw"), 8); 32 | }); -------------------------------------------------------------------------------- /src/_4kyu/_4kyu_pyramind_slide_down/longest_slide_down_test.py: -------------------------------------------------------------------------------- 1 | @test.describe('longest_slide_down') 2 | def test_longest_slide_down(): 3 | @test.it('should work for small pyramids') 4 | def small_pyramids(): 5 | test.assert_equals(longest_slide_down([[3], [7, 4], [2, 4, 6], [8, 5, 9, 3]]), 23) 6 | 7 | @test.it('should work for medium pyramids') 8 | def medium_pyramids(): 9 | test.assert_equals(longest_slide_down([ 10 | [75], 11 | [95, 64], 12 | [17, 47, 82], 13 | [18, 35, 87, 10], 14 | [20, 4, 82, 47, 65], 15 | [19, 1, 23, 75, 3, 34], 16 | [88, 2, 77, 73, 7, 63, 67], 17 | [99, 65, 4, 28, 6, 16, 70, 92], 18 | [41, 41, 26, 56, 83, 40, 80, 70, 33], 19 | [41, 48, 72, 33, 47, 32, 37, 16, 94, 29], 20 | [53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14], 21 | [70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57], 22 | [91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48], 23 | [63, 66, 4, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31], 24 | [4, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 4, 23], 25 | ]), 1074) 26 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_easy_sql_ordering/easy_sql_ordering_test.rb: -------------------------------------------------------------------------------- 1 | # DATA FOR TESTS IS AVAILABLE ONLY ON WEBSITE 2 | 3 | results = run_sql 4 | 5 | describe :query do 6 | describe "should contain keywords" do 7 | it "should contain SELECT" do 8 | expect($sql.upcase).to include("SELECT") 9 | end 10 | 11 | it "should contain FROM" do 12 | expect($sql.upcase).to include("FROM") 13 | end 14 | 15 | it "should contain ORDER" do 16 | expect($sql.upcase).to include("ORDER") 17 | end 18 | end 19 | 20 | describe :columns do 21 | it "should return 4 columns" do 22 | expect(results.first.keys.count).to eq 4 23 | end 24 | 25 | it "should return an id column" do 26 | expect(results.first.keys).to include(:id) 27 | end 28 | 29 | it "should return a ceo column" do 30 | expect(results.first.keys).to include(:ceo) 31 | end 32 | 33 | it "should return a motto column" do 34 | expect(results.first.keys).to include(:motto) 35 | end 36 | 37 | it "should return an employees column" do 38 | expect(results.first.keys).to include(:employees) 39 | end 40 | end 41 | end 42 | 43 | compare_with expected do 44 | end -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_find_the_missing_letter/FindMissingLetter.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_find_the_missing_letter; 2 | 3 | /* 4 | #Find the missing letter 5 | 6 | Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array. 7 | 8 | You will always get an valid array. And it will be always exactly one letter be missing. The length of the array will always be at least 2. 9 | The array will always contain letters in only one case. 10 | 11 | Example: 12 | 13 | ['a','b','c','d','f'] -> 'e' 14 | ['O','Q','R','S'] -> 'P' 15 | (Use the English alphabet with 26 letters!) 16 | 17 | Have fun coding it and please don't forget to vote and rank this kata! :-) 18 | 19 | I have also created other katas. Take a look if you enjoyed this kata! 20 | */ 21 | 22 | class FindMissingLetter { 23 | 24 | static char findMissingLetter(char[] array) { 25 | for (int i = 1; i < array.length; ++i) { 26 | if (array[i - 1] + 1 != array[i]) { 27 | return (char) (array[i - 1] + 1); 28 | } 29 | } 30 | 31 | throw new IllegalArgumentException("Array should have missing letter, invalid argument!"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_101_dalmatians_squash_the_bugs_not_the_dogs/HowManyDalmatians.js: -------------------------------------------------------------------------------- 1 | /* 2 | Your friend has been out shopping for puppies (what a time to be alive!)... 3 | He arrives back with multiple dogs, and you simply do not know how to respond! 4 | 5 | By repairing the function provided, 6 | you will find out exactly how you should respond, depending on the number of dogs he has. 7 | 8 | The number of dogs will always be a number and there will always be at least 1 dog. 9 | */ 10 | 11 | function howManyDalmatians(number) { 12 | var dogs = ["Hardly any", "More than a handful!", "Woah that's a lot of dogs!", "101 DALMATIANS!!!"]; 13 | return number <= 10 ? dogs[0] : (number <= 50 ? dogs[1] : (number === 101 ? dogs[3] : dogs[2])); 14 | } 15 | 16 | Test.describe("Basic tests",_=> { 17 | Test.assertEquals(howManyDalmatians(26), "More than a handful!"); 18 | Test.assertEquals(howManyDalmatians(8), "Hardly any"); 19 | Test.assertEquals(howManyDalmatians(14), "More than a handful!"); 20 | Test.assertEquals(howManyDalmatians(80), "Woah that's a lot of dogs!"); 21 | Test.assertEquals(howManyDalmatians(100), "Woah that's a lot of dogs!"); 22 | Test.assertEquals(howManyDalmatians(101), "101 DALMATIANS!!!"); 23 | }) -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_find_the_first_non_consecutive_number/find_the_first_non_consecutive_number.py: -------------------------------------------------------------------------------- 1 | """ 2 | Your task is to find the first element of an array 3 | that is not consecutive. 4 | 5 | E.g. If we have an array [1,2,3,4,6,7,8] then 1 then 2 6 | then 3 then 4 are all consecutive but 6 is not, 7 | so that's the first non-consecutive number. 8 | 9 | If the whole array is consecutive then return null2. 10 | 11 | The array will always have at least 2 elements1 and 12 | all elements will be numbers. 13 | 14 | The numbers will also all be unique and in ascending order. 15 | 16 | The numbers could be positive or negative 17 | and the first non-consecutive could be either too! 18 | 19 | If you like this Kata, maybe try this one next: 20 | 21 | https://www.codewars.com/kata/represent-array-of-numbers-as-ranges 22 | 23 | 1 Can you write a solution that will return null2 for both [] and [ x ] though? ( This is not tested, but you can write your own example test. ) 24 | 25 | 2 26 | Swift, Ruby and Crystal: nil 27 | Haskell: Nothing 28 | Python: None 29 | """ 30 | 31 | 32 | def first_non_consecutive(arr): 33 | for x in range(1, len(arr)): 34 | if arr[x] - arr[x - 1] != 1: 35 | return arr[x] 36 | return None 37 | -------------------------------------------------------------------------------- /src/_6kyu/_6kyu_camelcase_method/CamelCaseMethodTest.java: -------------------------------------------------------------------------------- 1 | package _6kyu._6kyu_camelcase_method; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class CamelCaseMethodTest { 8 | 9 | @Test 10 | void testTwoWords() { 11 | assertEquals("TestCase", CamelCaseMethod.camelCase("test case")); 12 | } 13 | 14 | @Test 15 | void testThreeWords() { 16 | assertEquals("CamelCaseMethod", CamelCaseMethod.camelCase("camel case method")); 17 | } 18 | 19 | @Test 20 | void testLeadingSpace() { 21 | assertEquals("CamelCaseWord", CamelCaseMethod.camelCase(" camel case word")); 22 | } 23 | 24 | @Test 25 | void testTrailingSpace() { 26 | assertEquals("SayHello", CamelCaseMethod.camelCase("say hello ")); 27 | } 28 | 29 | @Test 30 | void testSingleLetter() { 31 | assertEquals("Z", CamelCaseMethod.camelCase("z")); 32 | } 33 | 34 | @Test 35 | void testTwoSpacesBetweenWords() { 36 | assertEquals("AbC", CamelCaseMethod.camelCase("ab c")); 37 | } 38 | 39 | @Test 40 | void testEmptyString() { 41 | assertEquals("", CamelCaseMethod.camelCase("")); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/_8kyu/_8kyu_a_needle_in_the_haystack/NeedleInTheHaystack.java: -------------------------------------------------------------------------------- 1 | package _8kyu._8kyu_a_needle_in_the_haystack; 2 | 3 | /* 4 | Can you find the needle in the haystack? 5 | 6 | Write a function findNeedle() that takes an array full of junk but containing one "needle" 7 | 8 | After your function finds the needle it should return a message (as a string) that says: 9 | 10 | "found the needle at position " plus the index it found the needle, so: 11 | 12 | findNeedle(new Object[] {"hay", "junk", "hay", "hay", "moreJunk", "needle", "randomJunk"}) 13 | should return "found the needle at position 5" 14 | */ 15 | 16 | class NeedleInTheHaystack { 17 | 18 | static String findNeedle(Object[] haystack) { 19 | if (haystack == null || haystack.length == 0) return null; 20 | 21 | for (int i = 0; i < haystack.length; ++i) { 22 | if ("needle".equals(haystack[i])) { 23 | return "found the needle at position " + i; 24 | } 25 | } 26 | 27 | return null; 28 | } 29 | 30 | // prettier solution 31 | 32 | static String findNeedle2(Object[] haystack) { 33 | return "found the needle at position " + java.util.Arrays.asList(haystack).indexOf("needle"); 34 | } 35 | } 36 | 37 | 38 | --------------------------------------------------------------------------------