From fc899b0b0281e24dedc19165f44e9b59571bd0a8 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Tue, 28 Dec 2021 16:12:22 +0100 Subject: [PATCH] chore: initial commit Signed-off-by: Matej Focko --- 3kyu/battleship_field_validator/solution.cs | 127 ++++++ 3kyu/binomial_expansion/solution.cs | 103 +++++ 3kyu/screen_locking_patterns/solution.cs | 88 ++++ 4kyu/4_by_4_skyscrapers/solution.cs | 181 +++++++++ 4kyu/4_by_4_skyscrapers/solution.java | 264 ++++++++++++ 4kyu/adding_big_numbers/solution.cs | 44 ++ 4kyu/breadcrumb_generator/solution.js | 61 +++ 4kyu/counting_change_combinations/solution.cs | 28 ++ 4kyu/es5_generators_i/solution.js | 115 ++++++ .../solution.cs | 39 ++ 4kyu/magnet_particules_in_boxes/solution.cs | 15 + 4kyu/matrix_determinant/solution.cpp | 44 ++ 4kyu/next_bigger_with_same_digits/solution.cs | 65 +++ 4kyu/permutations/solution.cpp | 47 +++ 4kyu/priori_incantatem/solution.js | 24 ++ 4kyu/pyramid_slide_down/solution.cs | 19 + 4kyu/remove_zeros/solution.js | 28 ++ 4kyu/route_calculator/solution.ts | 69 ++++ 4kyu/simplistic_tcp_fsm/solution.cs | 57 +++ 4kyu/snail/solution.cs | 46 +++ 4kyu/sudoku_solution_validator/solution.cs | 53 +++ 4kyu/sum_by_factors/solution.rs | 29 ++ 4kyu/sum_strings_as_numbers/solution.cs | 63 +++ 4kyu/the_observed_pin/solution.cs | 29 ++ 4kyu/twice_linear/solution.js | 31 ++ 5kyu/buddy_pairs/solution.kt | 15 + 5kyu/calculating_with_functions/solution.js | 15 + 5kyu/common_denominators/solution.cs | 32 ++ 5kyu/convert_a_hex_string_to_rgb/solution.c | 13 + 5kyu/count_ip_addresses/solution.rs | 10 + 5kyu/did_i_finish_my_sudokou/solution.js | 57 +++ 5kyu/directions_reduction/solution.hs | 20 + 5kyu/esolang_interpreters_ii/solution.swift | 61 +++ 5kyu/greed_is_good/solution.cpp | 48 +++ 5kyu/halloween_sweets/solution.js | 24 ++ 5kyu/human_readable_time/solution.cs | 14 + 5kyu/i32_to_ipv4/solution.c | 6 + 5kyu/is_my_friend_cheating/solution.cpp | 46 +++ 5kyu/maximum_subarray_sum/solution.kt | 4 + 5kyu/memoized_fibonacci/solution.py | 12 + 5kyu/moving_zeros_to_the_end/solution.cs | 13 + .../solution.rs | 86 ++++ .../solution.cs | 16 + .../solution.rs | 21 + 5kyu/rgb_to_hex_conversion/solution.cs | 16 + 5kyu/rot13/solution.js | 17 + 5kyu/scramblies/solution.cs | 19 + 5kyu/simple_assembler_interpreter/solution.kt | 38 ++ 5kyu/simple_pig_latin/solution.py | 9 + 5kyu/snakes_and_ladders/solution.cpp | 62 +++ 5kyu/sum_of_pairs/solution.py | 11 + 5kyu/the_clockwise_spiral/solution.cpp | 32 ++ 5kyu/the_hashtag_generator/solution.js | 7 + 5kyu/tic_tac_toe_checker/solution.js | 71 ++++ 5kyu/valid_parentheses/solution.py | 11 + 5kyu/vector_class/solution.js | 54 +++ 5kyu/weight_for_weight/solution.py | 22 + 5kyu/where_my_anagrams_at/solution.js | 15 + 5kyu/which_x_for_that_sum/solution.rs | 24 ++ 6kyu/are_they_the_same/solution.js | 16 + 6kyu/ball_upwards/solution.kt | 12 + 6kyu/bit_counting/solution.py | 7 + 6kyu/bouncing_balls/solution.py | 9 + 6kyu/build_tower/solution.js | 25 ++ 6kyu/build_tower_advanced/solution.js | 30 ++ 6kyu/camelcase_method/solution.rs | 19 + .../solution.c | 12 + 6kyu/consecutive_strings/solution.java | 42 ++ 6kyu/convert_string_to_camel_case/solution.js | 13 + 6kyu/count_the_smiley_faces/solution.cs | 17 + 6kyu/counting_duplicates/solution.rs | 24 ++ 6kyu/create_phone_number/solution.js | 12 + 6kyu/decode_the_morse_code/solution.rs | 18 + 6kyu/delete_occurrences_if_occurs/solution.js | 17 + 6kyu/design_a_simple_automaton/solution.cpp | 36 ++ .../solution.cs | 19 + 6kyu/duplicate_encoder/solution.java | 15 + 6kyu/equal_sides_of_an_array/solution.cs | 23 ++ 6kyu/esolang_interpreters_i/solution.swift | 17 + 6kyu/evil_autocorrect_prank/solution.js | 12 + 6kyu/fat_fingers/solution.py | 19 + 6kyu/find_the_missing_letter/solution.java | 12 + .../solution.py | 17 + 6kyu/find_the_odd_int/solution.cs | 28 ++ 6kyu/find_the_unique_number/solution.py | 16 + 6kyu/give_me_a_diamond/solution.swift | 23 ++ 6kyu/halloween_trick_or_treat/solution.js | 27 ++ 6kyu/help_the_bookseller/solution.rs | 35 ++ 6kyu/highest_scoring_word/solution.py | 13 + 6kyu/ip_validation/solution.c | 21 + 6kyu/irreducible_sum_of_rationals/solution.rs | 28 ++ 6kyu/is_a_number_prime/solution.py | 16 + 6kyu/length_of_missing_array/solution.cs | 21 + 6kyu/linked_lists_length_count/solution.cpp | 28 ++ 6kyu/lotto_6_aus_49/solution.cs | 55 +++ 6kyu/make_the_deadfish_swim/solution.hs | 10 + 6kyu/multiples_of_3_or_5/solution.hs | 7 + 6kyu/multiplication_table/solution.go | 16 + 6kyu/parabolic_arc_length/solution.rs | 20 + 6kyu/pascals_triangle/solution.hs | 7 + 6kyu/playing_with_digits/solution.kt | 16 + 6kyu/pyramid_array/solution.hs | 4 + 6kyu/rectangle_into_squares/solution.cs | 26 ++ 6kyu/roman_numerals_decoder/solution.cs | 35 ++ 6kyu/roman_numerals_encoder/solution.cs | 38 ++ 6kyu/rpn_calculator/solution.js | 32 ++ .../solution.rs | 39 ++ 6kyu/split_strings/solution.py | 16 + .../solution.cpp | 105 +++++ 6kyu/stop_gninnips_my_sdrow/solution.cs | 22 + 6kyu/sum_of_digits__digital_root/solution.hs | 5 + 6kyu/take_a_ten_minute_walk/solution.hs | 10 + 6kyu/the_supermarket_queue/solution.cs | 25 ++ 6kyu/two_sum/solution.java | 18 + 6kyu/valid_braces/solution.ts | 23 ++ 6kyu/who_likes_it/solution.cs | 29 ++ 6kyu/word_a10n/solution.cs | 32 ++ 6kyu/your_order_please/solution.py | 12 + 7kyu/anagram_detection/solution.py | 2 + 7kyu/are_the_numbers_in_order/solution.cpp | 7 + 7kyu/beginner_series_iii/solution.cs | 14 + 7kyu/binary_addition/solution.cs | 17 + 7kyu/bumps_in_the_road/solution.py | 8 + 7kyu/categorize_new_member/solution.js | 12 + 7kyu/complementary_dna/solution.kt | 11 + 7kyu/credit_card_mask/solution.cs | 12 + 7kyu/deodorant_evaporator/solution.cs | 11 + 7kyu/digital_cypher/solution.rs | 19 + 7kyu/digital_cypher_vol_2/solution.cs | 20 + 7kyu/distributing_candies_fairly/solution.js | 20 + 7kyu/dont_give_me_five/solution.py | 2 + 7kyu/exes_and_ohs/solution.hs | 13 + 7kyu/fibonacci/solution.hs | 4 + 7kyu/find_the_divisors/solution.js | 17 + 7kyu/find_the_next_perfect_square/solution.cs | 15 + 7kyu/fizz_buzz_cuckoo_clock/solution.swift | 27 ++ 7kyu/growth_of_a_population/solution.js | 11 + 7kyu/highest_and_lowest/solution.js | 11 + 7kyu/hit_count/solution.py | 5 + 7kyu/inspiring_strings/solution.py | 10 + 7kyu/is_this_a_triangle/solution.cpp | 17 + 7kyu/isograms/solution.js | 14 + 7kyu/jaden_casing_strings/solution.cs | 10 + 7kyu/list_filtering/solution.cs | 18 + 7kyu/looking_for_a_benefactor/solution.c | 14 + .../solution.hs | 10 + 7kyu/maximum_length_difference/solution.rs | 27 ++ 7kyu/most_digits/solution.c | 20 + 7kyu/mumbling/solution.cs | 19 + 7kyu/number_of_people_in_the_bus/solution.kt | 2 + 7kyu/odd_or_even/solution.py | 5 + 7kyu/ones_and_zeros/solution.py | 2 + 7kyu/palindrome_chain_length/solution.py | 10 + 7kyu/parts_of_a_list/solution.cs | 19 + 7kyu/pirate_code/solution.js | 12 + 7kyu/predict_your_age/solution.kt | 5 + 7kyu/printer_errors/solution.php | 9 + 7kyu/product_of_array_items/solution.hs | 5 + 7kyu/regex_validate_pin_code/solution.java | 16 + 7kyu/remove_the_minimum/solution.cs | 24 ++ 7kyu/resistor_color_codes/solution.swift | 59 +++ 7kyu/rotate_for_a_max/solution.kt | 26 ++ 7kyu/shortest_word/solution.cs | 13 + 7kyu/small_enough_beginner/solution.kt | 1 + 7kyu/sorted_yes_no_how/solution.py | 8 + 7kyu/speed_control/solution.c | 20 + 7kyu/sum_of_angles/solution.cpp | 3 + 7kyu/sum_of_odd_numbers/solution.kt | 12 + .../solution.cs | 26 ++ 7kyu/vowel_count/solution.cs | 18 + 8kyu/a_needle_in_the_haystack/solution.cs | 15 + 8kyu/alternating_case/solution.js | 14 + 8kyu/beginner_lost_without_a_map/solution.kt | 1 + 8kyu/beginner_series_ii/solution.kt | 1 + 8kyu/beginner_series_iv/solution.pas | 14 + 8kyu/calculate_average/solution.hs | 4 + 8kyu/century_from_year/solution.hs | 6 + .../solution.hs | 5 + .../solution.cs | 21 + .../solution.py | 2 + 8kyu/count_the_monkeys/solution.java | 8 + 8kyu/counting_sheep/solution.cpp | 9 + .../solution.rs | 3 + 8kyu/enumerable_magic_iii/solution.cs | 11 + 8kyu/even_or_odd/solution.hs | 4 + 8kyu/exclamation_marks/solution.cs | 7 + 8kyu/fake_binary/solution.c | 18 + .../solution.rs | 3 + 8kyu/five_without_numbers/solution.py | 2 + 8kyu/get_nth_even_number/solution.c | 3 + 8kyu/get_the_mean_of_an_array/solution.c | 10 + 8kyu/grasshopper_grade_book/solution.cs | 16 + .../solution.js | 6 + 8kyu/grasshopper_summation/solution.pas | 16 + 8kyu/how_many_lightsabers/solution.hs | 5 + 8kyu/is_it_a_palindrome/solution.cpp | 22 + 8kyu/is_the_string_uppercase/solution.c | 12 + 8kyu/jennys_secret_message/solution.java | 8 + 8kyu/keep_hydrated/solution.hs | 4 + 8kyu/make_upper_case/solution.py | 5 + 8kyu/multiply/solution.cpp | 4 + 8kyu/opposite_number/solution.hs | 4 + 8kyu/opposites_attract/solution.kt | 1 + 8kyu/parse_nice_int_from_char/solution.c | 5 + .../solution.php | 3 + 8kyu/return_negative/solution.hs | 4 + 8kyu/reversed_strings/solution.cpp | 9 + 8kyu/square_n_sum/solution.js | 9 + 8kyu/string_repeat/solution.c | 13 + 8kyu/students_final_grade/solution.js | 6 + 8kyu/sum_arrays/solution.py | 5 + 8kyu/sum_of_positive/solution.py | 2 + .../solution.cpp | 24 ++ 8kyu/to_square_or_not_to_square/solution.cs | 18 + 8kyu/will_you_make_it/solution.cpp | 4 + 8kyu/xor/solution.hs | 4 + README.md | 383 ++++++++++++++++++ 217 files changed, 5356 insertions(+) create mode 100644 3kyu/battleship_field_validator/solution.cs create mode 100644 3kyu/binomial_expansion/solution.cs create mode 100644 3kyu/screen_locking_patterns/solution.cs create mode 100644 4kyu/4_by_4_skyscrapers/solution.cs create mode 100644 4kyu/4_by_4_skyscrapers/solution.java create mode 100644 4kyu/adding_big_numbers/solution.cs create mode 100644 4kyu/breadcrumb_generator/solution.js create mode 100644 4kyu/counting_change_combinations/solution.cs create mode 100644 4kyu/es5_generators_i/solution.js create mode 100644 4kyu/human_readable_duration_format/solution.cs create mode 100644 4kyu/magnet_particules_in_boxes/solution.cs create mode 100644 4kyu/matrix_determinant/solution.cpp create mode 100644 4kyu/next_bigger_with_same_digits/solution.cs create mode 100644 4kyu/permutations/solution.cpp create mode 100644 4kyu/priori_incantatem/solution.js create mode 100644 4kyu/pyramid_slide_down/solution.cs create mode 100644 4kyu/remove_zeros/solution.js create mode 100644 4kyu/route_calculator/solution.ts create mode 100644 4kyu/simplistic_tcp_fsm/solution.cs create mode 100644 4kyu/snail/solution.cs create mode 100644 4kyu/sudoku_solution_validator/solution.cs create mode 100644 4kyu/sum_by_factors/solution.rs create mode 100644 4kyu/sum_strings_as_numbers/solution.cs create mode 100644 4kyu/the_observed_pin/solution.cs create mode 100644 4kyu/twice_linear/solution.js create mode 100644 5kyu/buddy_pairs/solution.kt create mode 100644 5kyu/calculating_with_functions/solution.js create mode 100644 5kyu/common_denominators/solution.cs create mode 100644 5kyu/convert_a_hex_string_to_rgb/solution.c create mode 100644 5kyu/count_ip_addresses/solution.rs create mode 100644 5kyu/did_i_finish_my_sudokou/solution.js create mode 100644 5kyu/directions_reduction/solution.hs create mode 100644 5kyu/esolang_interpreters_ii/solution.swift create mode 100644 5kyu/greed_is_good/solution.cpp create mode 100644 5kyu/halloween_sweets/solution.js create mode 100644 5kyu/human_readable_time/solution.cs create mode 100644 5kyu/i32_to_ipv4/solution.c create mode 100644 5kyu/is_my_friend_cheating/solution.cpp create mode 100644 5kyu/maximum_subarray_sum/solution.kt create mode 100644 5kyu/memoized_fibonacci/solution.py create mode 100644 5kyu/moving_zeros_to_the_end/solution.cs create mode 100644 5kyu/my_smallest_code_interpreter_bf/solution.rs create mode 100644 5kyu/number_of_trailing_zeros_of_nf/solution.cs create mode 100644 5kyu/perimeter_of_squares_in_a_rectangle/solution.rs create mode 100644 5kyu/rgb_to_hex_conversion/solution.cs create mode 100644 5kyu/rot13/solution.js create mode 100644 5kyu/scramblies/solution.cs create mode 100644 5kyu/simple_assembler_interpreter/solution.kt create mode 100644 5kyu/simple_pig_latin/solution.py create mode 100644 5kyu/snakes_and_ladders/solution.cpp create mode 100644 5kyu/sum_of_pairs/solution.py create mode 100644 5kyu/the_clockwise_spiral/solution.cpp create mode 100644 5kyu/the_hashtag_generator/solution.js create mode 100644 5kyu/tic_tac_toe_checker/solution.js create mode 100644 5kyu/valid_parentheses/solution.py create mode 100644 5kyu/vector_class/solution.js create mode 100644 5kyu/weight_for_weight/solution.py create mode 100644 5kyu/where_my_anagrams_at/solution.js create mode 100644 5kyu/which_x_for_that_sum/solution.rs create mode 100644 6kyu/are_they_the_same/solution.js create mode 100644 6kyu/ball_upwards/solution.kt create mode 100644 6kyu/bit_counting/solution.py create mode 100644 6kyu/bouncing_balls/solution.py create mode 100644 6kyu/build_tower/solution.js create mode 100644 6kyu/build_tower_advanced/solution.js create mode 100644 6kyu/camelcase_method/solution.rs create mode 100644 6kyu/cheat_or_you_shall_not_pass_easy/solution.c create mode 100644 6kyu/consecutive_strings/solution.java create mode 100644 6kyu/convert_string_to_camel_case/solution.js create mode 100644 6kyu/count_the_smiley_faces/solution.cs create mode 100644 6kyu/counting_duplicates/solution.rs create mode 100644 6kyu/create_phone_number/solution.js create mode 100644 6kyu/decode_the_morse_code/solution.rs create mode 100644 6kyu/delete_occurrences_if_occurs/solution.js create mode 100644 6kyu/design_a_simple_automaton/solution.cpp create mode 100644 6kyu/does_my_number_look_big_in_this/solution.cs create mode 100644 6kyu/duplicate_encoder/solution.java create mode 100644 6kyu/equal_sides_of_an_array/solution.cs create mode 100644 6kyu/esolang_interpreters_i/solution.swift create mode 100644 6kyu/evil_autocorrect_prank/solution.js create mode 100644 6kyu/fat_fingers/solution.py create mode 100644 6kyu/find_the_missing_letter/solution.java create mode 100644 6kyu/find_the_missing_term_in_arith_prog/solution.py create mode 100644 6kyu/find_the_odd_int/solution.cs create mode 100644 6kyu/find_the_unique_number/solution.py create mode 100644 6kyu/give_me_a_diamond/solution.swift create mode 100644 6kyu/halloween_trick_or_treat/solution.js create mode 100644 6kyu/help_the_bookseller/solution.rs create mode 100644 6kyu/highest_scoring_word/solution.py create mode 100644 6kyu/ip_validation/solution.c create mode 100644 6kyu/irreducible_sum_of_rationals/solution.rs create mode 100644 6kyu/is_a_number_prime/solution.py create mode 100644 6kyu/length_of_missing_array/solution.cs create mode 100644 6kyu/linked_lists_length_count/solution.cpp create mode 100644 6kyu/lotto_6_aus_49/solution.cs create mode 100644 6kyu/make_the_deadfish_swim/solution.hs create mode 100644 6kyu/multiples_of_3_or_5/solution.hs create mode 100644 6kyu/multiplication_table/solution.go create mode 100644 6kyu/parabolic_arc_length/solution.rs create mode 100644 6kyu/pascals_triangle/solution.hs create mode 100644 6kyu/playing_with_digits/solution.kt create mode 100644 6kyu/pyramid_array/solution.hs create mode 100644 6kyu/rectangle_into_squares/solution.cs create mode 100644 6kyu/roman_numerals_decoder/solution.cs create mode 100644 6kyu/roman_numerals_encoder/solution.cs create mode 100644 6kyu/rpn_calculator/solution.js create mode 100644 6kyu/simple_substitution_cipher_helper/solution.rs create mode 100644 6kyu/split_strings/solution.py create mode 100644 6kyu/statistics_for_an_athletic_association/solution.cpp create mode 100644 6kyu/stop_gninnips_my_sdrow/solution.cs create mode 100644 6kyu/sum_of_digits__digital_root/solution.hs create mode 100644 6kyu/take_a_ten_minute_walk/solution.hs create mode 100644 6kyu/the_supermarket_queue/solution.cs create mode 100644 6kyu/two_sum/solution.java create mode 100644 6kyu/valid_braces/solution.ts create mode 100644 6kyu/who_likes_it/solution.cs create mode 100644 6kyu/word_a10n/solution.cs create mode 100644 6kyu/your_order_please/solution.py create mode 100644 7kyu/anagram_detection/solution.py create mode 100644 7kyu/are_the_numbers_in_order/solution.cpp create mode 100644 7kyu/beginner_series_iii/solution.cs create mode 100644 7kyu/binary_addition/solution.cs create mode 100644 7kyu/bumps_in_the_road/solution.py create mode 100644 7kyu/categorize_new_member/solution.js create mode 100644 7kyu/complementary_dna/solution.kt create mode 100644 7kyu/credit_card_mask/solution.cs create mode 100644 7kyu/deodorant_evaporator/solution.cs create mode 100644 7kyu/digital_cypher/solution.rs create mode 100644 7kyu/digital_cypher_vol_2/solution.cs create mode 100644 7kyu/distributing_candies_fairly/solution.js create mode 100644 7kyu/dont_give_me_five/solution.py create mode 100644 7kyu/exes_and_ohs/solution.hs create mode 100644 7kyu/fibonacci/solution.hs create mode 100644 7kyu/find_the_divisors/solution.js create mode 100644 7kyu/find_the_next_perfect_square/solution.cs create mode 100644 7kyu/fizz_buzz_cuckoo_clock/solution.swift create mode 100644 7kyu/growth_of_a_population/solution.js create mode 100644 7kyu/highest_and_lowest/solution.js create mode 100644 7kyu/hit_count/solution.py create mode 100644 7kyu/inspiring_strings/solution.py create mode 100644 7kyu/is_this_a_triangle/solution.cpp create mode 100644 7kyu/isograms/solution.js create mode 100644 7kyu/jaden_casing_strings/solution.cs create mode 100644 7kyu/list_filtering/solution.cs create mode 100644 7kyu/looking_for_a_benefactor/solution.c create mode 100644 7kyu/make_a_function_that_does_arithmetic/solution.hs create mode 100644 7kyu/maximum_length_difference/solution.rs create mode 100644 7kyu/most_digits/solution.c create mode 100644 7kyu/mumbling/solution.cs create mode 100644 7kyu/number_of_people_in_the_bus/solution.kt create mode 100644 7kyu/odd_or_even/solution.py create mode 100644 7kyu/ones_and_zeros/solution.py create mode 100644 7kyu/palindrome_chain_length/solution.py create mode 100644 7kyu/parts_of_a_list/solution.cs create mode 100644 7kyu/pirate_code/solution.js create mode 100644 7kyu/predict_your_age/solution.kt create mode 100644 7kyu/printer_errors/solution.php create mode 100644 7kyu/product_of_array_items/solution.hs create mode 100644 7kyu/regex_validate_pin_code/solution.java create mode 100644 7kyu/remove_the_minimum/solution.cs create mode 100644 7kyu/resistor_color_codes/solution.swift create mode 100644 7kyu/rotate_for_a_max/solution.kt create mode 100644 7kyu/shortest_word/solution.cs create mode 100644 7kyu/small_enough_beginner/solution.kt create mode 100644 7kyu/sorted_yes_no_how/solution.py create mode 100644 7kyu/speed_control/solution.c create mode 100644 7kyu/sum_of_angles/solution.cpp create mode 100644 7kyu/sum_of_odd_numbers/solution.kt create mode 100644 7kyu/sum_of_two_lowest_positive_integers/solution.cs create mode 100644 7kyu/vowel_count/solution.cs create mode 100644 8kyu/a_needle_in_the_haystack/solution.cs create mode 100644 8kyu/alternating_case/solution.js create mode 100644 8kyu/beginner_lost_without_a_map/solution.kt create mode 100644 8kyu/beginner_series_ii/solution.kt create mode 100644 8kyu/beginner_series_iv/solution.pas create mode 100644 8kyu/calculate_average/solution.hs create mode 100644 8kyu/century_from_year/solution.hs create mode 100644 8kyu/convert_boolean_values_to_strings/solution.hs create mode 100644 8kyu/convert_number_to_reversed_digits/solution.cs create mode 100644 8kyu/correct_mistakes_of_character_recognition/solution.py create mode 100644 8kyu/count_the_monkeys/solution.java create mode 100644 8kyu/counting_sheep/solution.cpp create mode 100644 8kyu/difference_of_volumes_of_cuboids/solution.rs create mode 100644 8kyu/enumerable_magic_iii/solution.cs create mode 100644 8kyu/even_or_odd/solution.hs create mode 100644 8kyu/exclamation_marks/solution.cs create mode 100644 8kyu/fake_binary/solution.c create mode 100644 8kyu/find_the_smallest_integer_in_the_array/solution.rs create mode 100644 8kyu/five_without_numbers/solution.py create mode 100644 8kyu/get_nth_even_number/solution.c create mode 100644 8kyu/get_the_mean_of_an_array/solution.c create mode 100644 8kyu/grasshopper_grade_book/solution.cs create mode 100644 8kyu/grasshopper_personalized_message/solution.js create mode 100644 8kyu/grasshopper_summation/solution.pas create mode 100644 8kyu/how_many_lightsabers/solution.hs create mode 100644 8kyu/is_it_a_palindrome/solution.cpp create mode 100644 8kyu/is_the_string_uppercase/solution.c create mode 100644 8kyu/jennys_secret_message/solution.java create mode 100644 8kyu/keep_hydrated/solution.hs create mode 100644 8kyu/make_upper_case/solution.py create mode 100644 8kyu/multiply/solution.cpp create mode 100644 8kyu/opposite_number/solution.hs create mode 100644 8kyu/opposites_attract/solution.kt create mode 100644 8kyu/parse_nice_int_from_char/solution.c create mode 100644 8kyu/remove_first_and_last_character/solution.php create mode 100644 8kyu/return_negative/solution.hs create mode 100644 8kyu/reversed_strings/solution.cpp create mode 100644 8kyu/square_n_sum/solution.js create mode 100644 8kyu/string_repeat/solution.c create mode 100644 8kyu/students_final_grade/solution.js create mode 100644 8kyu/sum_arrays/solution.py create mode 100644 8kyu/sum_of_positive/solution.py create mode 100644 8kyu/sum_without_highest_and_lowest/solution.cpp create mode 100644 8kyu/to_square_or_not_to_square/solution.cs create mode 100644 8kyu/will_you_make_it/solution.cpp create mode 100644 8kyu/xor/solution.hs create mode 100644 README.md diff --git a/3kyu/battleship_field_validator/solution.cs b/3kyu/battleship_field_validator/solution.cs new file mode 100644 index 0000000..0c2d7f7 --- /dev/null +++ b/3kyu/battleship_field_validator/solution.cs @@ -0,0 +1,127 @@ +namespace Solution { + using System; + using System.Collections.Generic; + + public class BattleshipField { + private enum Direction { + HORIZONTAL, + VERTICAL + } + + private class Ship { + private int y, x; + private Direction d; + private int size; + + public int Size {get => size;} + + public Ship(int y, int x, Direction d, int size) { + this.y = y; + this.x = x; + this.d = d; + this.size = size; + } + public bool IsTouching(Ship b) { + if (d == Direction.HORIZONTAL) { + if ((b.y >= this.y - 1 && b.y <= this.y + 1) && + (b.x >= this.x - 1 && b.x <= this.x + this.size)) + return true; + else return false; + } + + if (d == Direction.VERTICAL) { + if ((b.x >= this.x - 1 && b.x <= this.x + 1) && + (b.y >= this.y - 1 && b.y <= this.y + this.size)) + return true; + else return false; + } + + return false; + } + public override string ToString() { + string direction = this.d == Direction.HORIZONTAL ? "horizontal" : "vertical"; + return $"x: {this.x}\ty: {this.y}\tdir: {direction}\tsize: {this.size}"; + } + } + + private List ships; + private int battleships = 1, + cruisers = 2, + destroyers = 3, + submarines = 4; + + public BattleshipField() { + this.ships = new List(); + } + + private void registerShip(int y, int x, Direction d, int count) { + this.ships.Add(new Ship(y, x, d, count)); + switch (count) { + case 1: + this.submarines--; + break; + case 2: + this.destroyers--; + break; + case 3: + this.cruisers--; + break; + case 4: + this.battleships--; + break; + } + } + + private bool areTouching() { + for (var i = 0; i < this.ships.Count - 1; i++) + for (var j = i + 1; j < this.ships.Count; j++) + if (this.ships[i].IsTouching(this.ships[j])) return true; + return false; + } + + public bool IsValidField() { + if (this.submarines != 0 || this.destroyers != 0 || + this.cruisers != 0 || this.battleships != 0) + return false; + else if (this.areTouching()) + return false; + return true; + } + + public static bool ValidateBattlefield(int[,] field) { + // Write your magic here + var validator = new BattleshipField(); + int count = 0; + + for (int y = 0, rows = field.GetLength(0); y < rows; y++) { + for (int x = 0, cols = field.GetLength(0); x < cols; x++) { + if (field[y, x] == 1) { + // check for vertical ship + if (count == 0) { + if (y < rows - 1 && field[y + 1, x] == 1) { + for (int dy = 0; y + dy < rows; dy++) { + if (field[y + dy, x] == 1) { + field[y + dy, x] = 0; + count++; + } else break; + } + + if (count > 1) { + validator.registerShip(y, x, Direction.VERTICAL, count); + count = 0; + continue; + } + } + } + field[y, x] = 0; + count++; + } else if (field[y, x] == 0 && count > 0) { + validator.registerShip(y, x - count, Direction.HORIZONTAL, count); + count = 0; + } + } + } + return validator.IsValidField(); + } + } +} diff --git a/3kyu/binomial_expansion/solution.cs b/3kyu/binomial_expansion/solution.cs new file mode 100644 index 0000000..7bd6089 --- /dev/null +++ b/3kyu/binomial_expansion/solution.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +public class KataSolution { + public static IEnumerable Combinations(long n) { + if (n < 0) { + Console.WriteLine("Error happened"); + throw new ArgumentException("n cannot be negative"); + } + + for ( + long k = 0, nCk = 1; + k <= n; + nCk = nCk * (n - k) / (k + 1), k++ + ) { + yield return nCk; + } + } + + public static IEnumerable Range(long count) { + for (var i = 0; i < count; i++) { + yield return i; + } + } + + public static IEnumerable Expand(int a, int b, int n) { + long aExpd = (long) Math.Pow(a, n); + long bExpd = 1; + foreach (var nCk in Combinations(n)) { + yield return nCk * aExpd * bExpd; + + aExpd /= a; + bExpd *= b; + } + } + + public static (int, int, string) ParseInner(string expr) { + var innerPart = expr.Split('^')[0]; + innerPart = innerPart.Substring(1, innerPart.Length - 2); + + var coeffA = new String( + innerPart.TakeWhile(c => !char.IsLetter(c)).ToArray() + ); + var variable = new String( + innerPart.SkipWhile(c => !char.IsLetter(c)).TakeWhile(char.IsLetter).ToArray() + ); + var coeffB = new String( + innerPart.SkipWhile(c => !char.IsLetter(c)).SkipWhile(char.IsLetter).ToArray() + ); + + var parsedCoeffA = coeffA switch { + "" => 1, + "-" => -1, + _ => int.Parse(coeffA) + }; + + return (parsedCoeffA, int.Parse(coeffB), variable); + } + + public static int ParseExponent(string expr) { + var splitExpr = expr.Split('^'); + return int.Parse(splitExpr[1]); + } + + public static string FormatTerm(long coefficient, string variable, long exponent) { + var prefix = (coefficient > 0) ? "+" : ""; + + if (coefficient == 0) { + return ""; + } + + if ((coefficient == 1 || coefficient == -1) && exponent == 0) { + return $"{prefix}{coefficient}"; + } + + var coeff = coefficient switch { + 0 => "", + 1 => prefix, + -1 => "-", + _ => $"{prefix}{coefficient}" + }; + var varExp = exponent switch { + 0 => "", + 1 => variable, + _ => $"{variable}^{exponent}" + }; + return $"{coeff}{varExp}"; + } + + public static string Expand(string expr) { + var n = ParseExponent(expr); + var (a, b, variable) = ParseInner(expr); + + var result = ""; + + foreach (var (exponent, coefficient) in Range(n + 1).Reverse().Zip(Expand(a, b, n))) { + result += FormatTerm(coefficient, variable, exponent); + } + + return result.TrimStart(new char[] {'+'}); + } +} diff --git a/3kyu/screen_locking_patterns/solution.cs b/3kyu/screen_locking_patterns/solution.cs new file mode 100644 index 0000000..d6f0ae0 --- /dev/null +++ b/3kyu/screen_locking_patterns/solution.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +public static class Kata { + private class Graph { + private struct Edge { + public char Through { get; set; } + public char To { get; set; } + }; + + public static readonly char NO_CONDITION = '\0'; + + private Dictionary> edges = new Dictionary>(); + private HashSet visited = new HashSet(); + + private Graph addEdge(char src, char through, char dst) { + var newEdge = new Edge { + Through = through, + To = dst + }; + + if (edges.TryGetValue(src, out var lst)) { + lst.Add(newEdge); + } else { + edges.Add(src, new List() { newEdge }); + } + + return this; + } + + public Graph AddDirectEdge(char src, char dst) + => addEdge(src, NO_CONDITION, dst); + public Graph AddIndirectEdge(char src, char through, char dst) + => addEdge(src, through, dst); + public Graph AddBiDirectEdge(char src, char dst) + => AddBiIndirectEdge(src, NO_CONDITION, dst); + public Graph AddBiIndirectEdge(char src, char through, char dst) => + addEdge(src, through, dst) + .addEdge(dst, through, src); + + public void ResetVisited() => visited.Clear(); + public bool BeenVisited(char vertex) => visited.Contains(vertex); + public void Mark(char vertex) => visited.Add(vertex); + public void Unmark(char vertex) => visited.Remove(vertex); + + public bool HasEdge(char fromVertex, char toVertex) + => edges[fromVertex].Any(e => e.To == toVertex && (e.Through == NO_CONDITION || BeenVisited(e.Through))); + + public Graph AddMultipleBiDirectEdges(char fromVertex, string toVertices) { + foreach (var toVertex in toVertices) { + AddBiDirectEdge(fromVertex, toVertex); + } + return this; + } + } + + private static Graph g = new Graph() + .AddMultipleBiDirectEdges('A', "BDEFH").AddMultipleBiDirectEdges('B', "CDEFGI") + .AddMultipleBiDirectEdges('C', "DEFH").AddMultipleBiDirectEdges('D', "EGHI") + .AddMultipleBiDirectEdges('E', "FGHI").AddMultipleBiDirectEdges('F', "GHI") + .AddMultipleBiDirectEdges('G', "H").AddMultipleBiDirectEdges('H', "I") + .AddBiIndirectEdge('A', 'B', 'C').AddBiIndirectEdge('A', 'D', 'G').AddBiIndirectEdge('A', 'E', 'I') + .AddBiIndirectEdge('B', 'E', 'H').AddBiIndirectEdge('C', 'E', 'G').AddBiIndirectEdge('C', 'F', 'I') + .AddBiIndirectEdge('D', 'E', 'F').AddBiIndirectEdge('G', 'H', 'I'); + + public static int CountPatternsFrom(char firstDot, int length) { + if (length <= 0 || length >= 10) { + return 0; + } + + if (length == 1) { + return 1; + } + + int total = 0; + + g.Mark(firstDot); + foreach (var vertex in "ABCDEFGHI") { + if (!g.BeenVisited(vertex) && g.HasEdge(firstDot, vertex)) { + total += CountPatternsFrom(vertex, length - 1); + } + } + g.Unmark(firstDot); + + return total; + } +} diff --git a/4kyu/4_by_4_skyscrapers/solution.cs b/4kyu/4_by_4_skyscrapers/solution.cs new file mode 100644 index 0000000..d71afe9 --- /dev/null +++ b/4kyu/4_by_4_skyscrapers/solution.cs @@ -0,0 +1,181 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +public class Skyscrapers { + private static IEnumerable> Permutations(List initial) + where T: IComparable { + yield return initial; + + var hasNext = initial.Count > 1; + while (hasNext) { + var k = 0; + var l = 0; + hasNext = false; + + for (var i = initial.Count - 1; i > 0; i--) { + if (initial[i].CompareTo(initial[i - 1]) > 0) { + k = i - 1; + hasNext = true; + break; + } + } + + for (var i = initial.Count - 1; i > k; i--) { + if (initial[i].CompareTo(initial[k]) > 0) { + l = i; + break; + } + } + + (initial[k], initial[l]) = (initial[l], initial[k]); + initial.Reverse(k + 1, initial.Count - k - 1); + + if (hasNext) { + yield return initial; + } + } + } + + private static bool IsValid(List heights, int clue) { + var canSee = 1; + var lastHeight = heights[0]; + + for (var i = 1; i < heights.Count; i++) { + var currentHeight = heights[i]; + if (currentHeight > lastHeight) { + lastHeight = currentHeight; + canSee++; + } + } + + return canSee == clue; + } + + private static IEnumerable> PossibleHeights(int size, int clue) { + var initial = new List(); + for (var i = 0; i < size; i++) { + initial.Add(i + 1); + } + + if (clue == 0) { + return Permutations(initial); + } + + return Permutations(initial).Where(heights => IsValid(heights, clue)); + } + + private static int Size { + get => 4; + } + + private static (int, int) GetDiffs(int clueIndex) { + if (clueIndex < Size) { + return (0, 1); + } else if (clueIndex < 2 * Size) { + return (-1, 0); + } else if (clueIndex < 3 * Size) { + return (0, -1); + } + return (1, 0); + } + + private static (int, int) GetStarts(int clueIndex) { + if (clueIndex < Size) { + return (clueIndex, 0); + } else if (clueIndex < 2 * Size) { + return (Size - 1, clueIndex % Size); + } else if (clueIndex < 3 * Size) { + return (Size - 1 - clueIndex % Size, Size - 1); + } + return (0, Size - 1 - clueIndex % Size); + } + + private static List BackupHeights(int[][] heights, int clueIndex) { + var backup = new List(); + + var (dx, dy) = GetDiffs(clueIndex); + for ( + var (x, y) = GetStarts(clueIndex); + x >= 0 && x < Size && y >= 0 && y < Size; + x += dx, y += dy + ) { + backup.Add(heights[y][x]); + } + + return backup; + } + + private static bool EmplaceHeights( + int[][] heights, int clueIndex, List newHeights, bool force + ) { + int i = 0; + + var (dx, dy) = GetDiffs(clueIndex); + for ( + var (x, y) = GetStarts(clueIndex); + x >= 0 && x < Size && y >= 0 && y < Size; + x += dx, y += dy + ) { + if ( + !force && heights[y][x] != 0 && heights[y][x] != newHeights[i] + ) { + return false; + } + + heights[y][x] = newHeights[i++]; + } + + return true; + } + + private static bool SolvePuzzle( + int[][] heights, int[] clues, int clueIndex, bool ignoreZeroes + ) { + while (clueIndex < 4 * Size && ( + (ignoreZeroes && clues[clueIndex] == 0) || (!ignoreZeroes && clues[clueIndex] != 0) + )) { + clueIndex++; + } + + if (clueIndex >= 4 * Size) { + return true; + } + + // create copy of heights to ensure correct resetting + var currentHeights = BackupHeights(heights, clueIndex); + + // iterate through the options + foreach (var possibleHeights in PossibleHeights(Size, clues[clueIndex])) { + // emplace heights and if conflict occurs, reset and try next one + if (!EmplaceHeights(heights, clueIndex, possibleHeights, false)) { + EmplaceHeights(heights, clueIndex, currentHeights, true); + continue; + } + + // if no conflict present, try filling out other clues + if (SolvePuzzle(heights, clues, clueIndex + 1, ignoreZeroes)) { + return true; + } + + // otherwise reset heights and try again + EmplaceHeights(heights, clueIndex, currentHeights, true); + } + + // if we got here, there is no feasible configuration of buildings + return false; + } + + public static int[][] SolvePuzzle(int[] clues) { + var result = new int[Size][]; + for (var i = 0; i < Size; i++) { + result[i] = new int[Size]; + } + SolvePuzzle(result, clues, 0, true); + + // in case there are left zeroes + SolvePuzzle(result, clues, 0, false); + + return result; + } +} diff --git a/4kyu/4_by_4_skyscrapers/solution.java b/4kyu/4_by_4_skyscrapers/solution.java new file mode 100644 index 0000000..2a00c76 --- /dev/null +++ b/4kyu/4_by_4_skyscrapers/solution.java @@ -0,0 +1,264 @@ +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +public class SkyScrapers { + private static class Permutations> implements Iterable> { + public class PermutationsIterator implements Iterator> { + private List elements; + private boolean _hasNext; + private boolean firstIteration = true; + + public PermutationsIterator(List elements) { + this.elements = elements; + _hasNext = elements.size() > 0; + } + + private void swap(int k, int l) { + T tmp = elements.get(k); + elements.set(k, elements.get(l)); + elements.set(l, tmp); + } + + public boolean hasNext() { + return _hasNext; + } + + public List next() { + if (!_hasNext) { + throw new NoSuchElementException("No more permutations are left"); + } + + var lastIteration = new ArrayList(elements); + + int k = 0, l = 0; + _hasNext = false; + for (int i = elements.size() - 1; i > 0; i--) { + if (elements.get(i).compareTo(elements.get(i - 1)) > 0) { + k = i - 1; + _hasNext = true; + break; + } + } + + for (int i = elements.size() - 1; i > k; i--) { + if (elements.get(i).compareTo(elements.get(k)) > 0) { + l = i; + break; + } + } + + swap(k, l); + Collections.reverse(elements.subList(k + 1, elements.size())); + + return lastIteration; + } + } + + private List elements; + + public Permutations(List elements) { + this.elements = elements; + Collections.sort(this.elements); + } + + public Iterator> iterator() { + return new PermutationsIterator(elements); + } + + public Stream> stream() { + return StreamSupport.stream(this.spliterator(), false); + } + } + + private static class PossibleConfigurations implements Iterable> { + private List initial; + private int clue; + + private void generateInitial(int size) { + initial = new ArrayList(); + + for (int i = 0; i < size; i++) { + initial.add(i + 1); + } + } + + public PossibleConfigurations(int size, int clue) { + generateInitial(size); + this.clue = clue; + } + + public Iterator> iterator() { + if (clue == 0) { + return (new Permutations(initial)).iterator(); + } + + return (new Permutations(initial)) + .stream() + .filter(heights -> isValid((List) heights, clue)) + .iterator(); + } + } + + private static boolean isValid(List heights, int clue) { + int canSee = 1; + int lastHeight = heights.get(0); + + for (int i = 1; i < heights.size(); i++) { + int currentHeight = heights.get(i); + if (currentHeight > lastHeight) { + lastHeight = currentHeight; + canSee++; + } + } + + return canSee == clue; + } + + private static int getDx(int clueIndex) { + if (clueIndex >= 4 && clueIndex <= 7) { + return -1; + } + + if (clueIndex >= 12) { + return 1; + } + + return 0; + } + + private static int getDy(int clueIndex) { + if (clueIndex <= 3) { + return 1; + } + + if (clueIndex >= 8 && clueIndex <= 11) { + return -1; + } + + return 0; + } + + private static int getStartX(int clueIndex) { + if (clueIndex < 4) { + return clueIndex; + } + + if (clueIndex <= 7) { + return 3; + } + + if (clueIndex <= 11) { + return 3 - clueIndex % 4; + } + + return 0; + } + + private static int getStartY(int clueIndex) { + if (clueIndex < 4) { + return 0; + } + + if (clueIndex <= 7) { + return clueIndex % 4; + } + + if (clueIndex <= 11) { + return 3; + } + + return 3 - clueIndex % 4; + } + + private static List backupHeights(int[][] heights, int clueIndex) { + List backup = new ArrayList(); + + int dx = getDx(clueIndex); + int dy = getDy(clueIndex); + + for ( + int x = getStartX(clueIndex), y = getStartY(clueIndex); + x >= 0 && x < 4 && y >= 0 && y < 4; + x += dx, y += dy + ) { + backup.add(heights[y][x]); + } + + return backup; + } + + private static boolean emplaceHeights( + int[][] heights, int clueIndex, List newHeights, boolean force + ) { + int i = 0; + int dx = getDx(clueIndex); + int dy = getDy(clueIndex); + + for ( + int x = getStartX(clueIndex), y = getStartY(clueIndex); + x >= 0 && x < 4 && y >= 0 && y < 4; + x += dx, y += dy + ) { + if ( + !force && heights[y][x] != 0 && heights[y][x] != newHeights.get(i) + ) { + return false; + } + + heights[y][x] = newHeights.get(i++); + } + + return true; + } + + private static boolean solvePuzzle( + int[][] heights, int[] clues, int clueIndex, boolean ignoreZeroes + ) { + while (clueIndex < 16 && ((ignoreZeroes && clues[clueIndex] == 0) || (!ignoreZeroes && clues[clueIndex] != 0))) { + clueIndex++; + } + + if (clueIndex >= 16) { + return true; + } + + // create copy of heights to ensure correct resetting + List currentHeights = backupHeights(heights, clueIndex); + + // iterate through the options + for (List possibleHeights : new PossibleConfigurations(4, clues[clueIndex])) { + + // emplace heights and if conflict occurs, reset and try next one + if (!emplaceHeights(heights, clueIndex, possibleHeights, false)) { + emplaceHeights(heights, clueIndex, currentHeights, true); + continue; + } + + // if no conflict present, try filling out other clues + if (solvePuzzle(heights, clues, clueIndex + 1, ignoreZeroes)) { + return true; + } + + // otherwise reset heights and try again + emplaceHeights(heights, clueIndex, currentHeights, true); + } + + // if we got here, there is no feasible configuration of buildings + return false; + } + + static int[][] solvePuzzle(int[] clues) { + var result = new int[4][4]; + solvePuzzle(result, clues, 0, true); + + // in case there are left zeroes + solvePuzzle(result, clues, 0, false); + + return result; + } +} diff --git a/4kyu/adding_big_numbers/solution.cs b/4kyu/adding_big_numbers/solution.cs new file mode 100644 index 0000000..f265de0 --- /dev/null +++ b/4kyu/adding_big_numbers/solution.cs @@ -0,0 +1,44 @@ +using System; + +public class Kata { + public static (uint remainder, uint digit) SumTwo(char a, char b, uint c = 0) { + uint val_a = (uint) a - 48; + uint val_b = (uint) b - 48; + + var sum = val_a + val_b + c; + return (sum / 10, sum % 10); + } + public static string Add(string a, string b) { + var result = ""; + + if (a.Length > b.Length) { + var temp = a; + a = b; + b = temp; + } + + int idx_a = a.Length - 1; + int idx_b = b.Length - 1; + uint remainder = 0; + uint last_digit = 0; + + while (idx_a >= 0) { + (remainder, last_digit) = SumTwo(a[idx_a], b[idx_b], remainder); + result = last_digit.ToString() + result; + idx_a--; + idx_b--; + } + + while (idx_b >= 0) { + (remainder, last_digit) = SumTwo('0', b[idx_b], remainder); + result = last_digit.ToString() + result; + idx_b--; + } + + if (remainder > 0) { + result = remainder.ToString() + result; + } + + return result; + } +} diff --git a/4kyu/breadcrumb_generator/solution.js b/4kyu/breadcrumb_generator/solution.js new file mode 100644 index 0000000..42a5b10 --- /dev/null +++ b/4kyu/breadcrumb_generator/solution.js @@ -0,0 +1,61 @@ +function checkExtension(name) { + const extensions = ['.html', '.htm', '.php', '.asp']; + return name.replace(/\.html/g, '').replace(/\.htm/g, '').replace(/\.php/g, '').replace(/\.asp/g, ''); +} + +function shorten(name) { + if (name.length <= 30) { + name = name.replace(/-/g, ' '); + } else { + const ignore = ["the","of","in","from","by","with","and", "or", "for", "to", "at", "a"]; + + name = name.split('-').filter(e => !ignore.includes(e)).map(e => e[0]); + name = name.join(''); + } + + return name.toUpperCase(); +} + +function buildSegment(url, name, last=false) { + if (last) { + return `${shorten(checkExtension(name))}`; + } else { + return `${shorten(checkExtension(name))}`; + } +} + +function generateBC(url, separator) { + console.log(url); + if (url.includes('//')) { + url = url.split('//')[1]; + } + + url = url.split("/").filter(e => { + return !e.startsWith('index'); + }).map(e => { + if (e.includes("#")) + return e.substring(0, e.indexOf("#")); + else if (e.includes("?")) + return e.substring(0, e.indexOf("?")); + else + return e; + }); + + let result = []; + let path = '/'; + if ((url.length == 2 && url[1] == '') || url.length == 1) { + result.push(buildSegment('/', 'home', true)); + return result.join(''); + } else + result.push(buildSegment('/', 'home')); + + + for (let i = 1; i < url.length - 1; i++) { + path += `${url[i]}/`; + result.push(buildSegment(path, url[i])); + } + path += `/${url[url.length - 1]}` + result.push(buildSegment(path, url[url.length - 1], true)); + + return result.join(separator); +} diff --git a/4kyu/counting_change_combinations/solution.cs b/4kyu/counting_change_combinations/solution.cs new file mode 100644 index 0000000..ea8dd06 --- /dev/null +++ b/4kyu/counting_change_combinations/solution.cs @@ -0,0 +1,28 @@ +using System; + +public static class Kata { + public static int CountCombinations(int money, int[] coins, bool recursivelyCalled = false) { + if (money == 0 && recursivelyCalled) return 1; + else if (coins.GetLength(0) == 1) { + if (money % coins[0] == 0) return 1; + else return 0; + } else if (!recursivelyCalled) { + Array.Sort(coins); + Array.Reverse(coins); + } + + var result = 0; + + var times = money / coins[0]; + var newCoins = new int[coins.GetLength(0) - 1]; + + for (var i = 0; i < coins.GetLength(0) - 1; i++) + newCoins[i] = coins[i + 1]; + + for (var i = 0; i <= times; i++) { + result += CountCombinations(money - i * coins[0], newCoins, true); + } + + return result; + } +} diff --git a/4kyu/es5_generators_i/solution.js b/4kyu/es5_generators_i/solution.js new file mode 100644 index 0000000..e360387 --- /dev/null +++ b/4kyu/es5_generators_i/solution.js @@ -0,0 +1,115 @@ +function generator(sequencer) { + return sequencer.apply( + null, + [] + .slice + .call(arguments) + .slice(1) + ); +} + +function dummySeq() { + this.next = function() { + return "dummy"; + }; + + return this; +} + +function factorialSeq() { + this.n = 1; + this.i = 0; + + this.next = function() { + const value = this.n; + + this.i++; + this.n *= this.i; + + return value; + }; + + return this; +} + +function fibonacciSeq() { + this.prev = 0; + this.current = 1; + + this.next = function() { + const value = this.current; + + const newValue = this.prev + this.current; + this.prev = this.current; + this.current= newValue; + + return value; + }; + + return this; +} + +function rangeSeq(start, step) { + this.value = start; + this.step = step; + + this.next = function() { + const oldValue = this.value; + this.value += this.step; + + return oldValue; + }; + + return this; +} + +function primeSeq() { + const isPrime = function(n) { + const top = Math.floor(Math.sqrt(n)); + for (let i = 2; i <= top; i++) { + if (n % i == 0) { + return false; + } + } + + return true; + }; + + const nextPrime = function(n) { + n++; + while (!isPrime(n)) { + n++; + } + + return n; + }; + + this.p = 1; + + this.next = function() { + this.p = nextPrime(this.p); + + return this.p; + }; + + return this; +} + +function partialSumSeq() { + this.values = arguments; + this.length = arguments.length; + this.runningSum = 0; + this.i = 0; + + this.next = function() { + if (this.i >= this.length) { + throw new RangeError("All input was processed!"); + } + + this.runningSum += this.values[this.i++]; + + return this.runningSum; + }; + + return this; +} diff --git a/4kyu/human_readable_duration_format/solution.cs b/4kyu/human_readable_duration_format/solution.cs new file mode 100644 index 0000000..6d56443 --- /dev/null +++ b/4kyu/human_readable_duration_format/solution.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +public class HumanTimeFormat{ + private static Dictionary conversions = new Dictionary() { + {"year", 31536000}, + {"day", 86400}, + {"hour", 3600}, + {"minute", 60}, + {"second", 1} + }; + + public static string formatDuration(int seconds){ + if (seconds == 0) return "now"; + + var results = new List(); + foreach (var pair in conversions) { + var units = seconds / pair.Value; + seconds %= pair.Value; + if (units > 0) { + var part = $"{units} {pair.Key}"; + if (units > 1) { + part += "s"; + } + results.Add(part); + } + } + + if (results.Count == 1) return results[0]; + else { + var last = results.Last(); + results.Remove(last); + + var result = String.Join(", ", results); + return result + " and " + last; + } + } +} diff --git a/4kyu/magnet_particules_in_boxes/solution.cs b/4kyu/magnet_particules_in_boxes/solution.cs new file mode 100644 index 0000000..d4cf6a8 --- /dev/null +++ b/4kyu/magnet_particules_in_boxes/solution.cs @@ -0,0 +1,15 @@ +using System; + +public class Magnets +{ + public static double Doubles(int maxk, int maxn) + { + double val = 0; + + for (int k = 1; k <= maxk; k++) + for (int n = 1; n <= maxn; n++) + val += 1 / (k * Math.Pow(n + 1, 2 * k)); + + return val; + } +} diff --git a/4kyu/matrix_determinant/solution.cpp b/4kyu/matrix_determinant/solution.cpp new file mode 100644 index 0000000..3c57347 --- /dev/null +++ b/4kyu/matrix_determinant/solution.cpp @@ -0,0 +1,44 @@ +#include +#include +#include + +using namespace std; + +vector> transform(vector> m, int row, + int col) { + vector> result; + + for (int i = 0; i < m.size(); i++) { + if (i == row) + continue; + vector actual_row; + for (int j = 0; j < m[i].size(); j++) { + if (j == col) + continue; + actual_row.push_back(m[i][j]); + } + result.push_back(actual_row); + } + + return result; +} + +long long determinant(vector> m) { + switch (m.size()) { + case 1: + return m[0][0]; + break; + case 2: + return m[0][0] * m[1][1] - m[0][1] * m[1][0]; + break; + } + + long long result = 0; + + for (int i = 0; i < m.size(); i++) { + auto l_m = transform(m, i, 0); + result += pow(-1, i + 2) * m[i][0] * determinant(l_m); + } + + return result; +} diff --git a/4kyu/next_bigger_with_same_digits/solution.cs b/4kyu/next_bigger_with_same_digits/solution.cs new file mode 100644 index 0000000..45fa92b --- /dev/null +++ b/4kyu/next_bigger_with_same_digits/solution.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +public class Kata { + public static List ExtractDigits(long n) { + var result = new List(); + + while (n > 0) { + result.Add(n % 10); + n /= 10; + } + + result.Reverse(); + return result; + } + + public static bool NextPermutation(List digits) { +// foreach (var digit in digits) Console.Write($"{digit} "); +// Console.WriteLine(); + + var k = -1; + + for (var i = 0; i < digits.Count - 1; i++) { + if (digits[i] < digits[i + 1]) + k = i; + } + if (k == -1) return false; + + var l = k; + for (var i = 0; i < digits.Count; i++) + if (digits[k] < digits[i]) l = i; + if (l == k) return false; + + var tmp = digits[k]; + digits[k] = digits[l]; + digits[l] = tmp; + +// foreach (var digit in digits) Console.Write($"{digit} "); +// Console.WriteLine(); + + digits.Reverse(k + 1, digits.Count - k - 1); + +// foreach (var digit in digits) Console.Write($"{digit} "); +// Console.WriteLine(); + + return true; + } + + public static long NextBiggerNumber(long n) { + if (n < 10) return -1; + + var digits = ExtractDigits(n); + if (!NextPermutation(digits)) { + return -1; + } else { + var result = 0l; + foreach (var digit in digits) { + result *= 10; + result += digit; + } + return result; + } + } +} diff --git a/4kyu/permutations/solution.cpp b/4kyu/permutations/solution.cpp new file mode 100644 index 0000000..a0900cc --- /dev/null +++ b/4kyu/permutations/solution.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include + +template bool nextPermutation(std::vector &vec) { + // Find non-increasing suffix + if (vec.empty()) + return false; + typename std::vector::iterator i = vec.end() - 1; + while (i > vec.begin() && *(i - 1) >= *i) + --i; + if (i == vec.begin()) + return false; + + // Find successor to pivot + typename std::vector::iterator j = vec.end() - 1; + while (*j <= *(i - 1)) + --j; + std::iter_swap(i - 1, j); + + // Reverse suffix + std::reverse(i, vec.end()); + return true; +} + +std::vector permutations(std::string s) { + std::set strings; + std::vector result; + std::vector s_vec; + + // copy string into vector + + for (auto ch = s.begin(); ch != s.end(); ch++) { + s_vec.push_back(*ch); + } + + // do the magic + std::sort(s_vec.begin(), s_vec.end()); + do { + strings.insert(std::string(s_vec.begin(), s_vec.end())); + } while (nextPermutation(s_vec)); + + std::copy(strings.begin(), strings.end(), std::back_inserter(result)); + return result; +} diff --git a/4kyu/priori_incantatem/solution.js b/4kyu/priori_incantatem/solution.js new file mode 100644 index 0000000..f7593b2 --- /dev/null +++ b/4kyu/priori_incantatem/solution.js @@ -0,0 +1,24 @@ +class Wand { + constructor(spells) { + this.history = []; + Object.assign(this, spells); + + return new Proxy(this, { + get: (target, property) => { + const val = target[property]; + if (typeof val === 'function') { + target.history.unshift(property); + } + return val; + } + }); + } + + prioriIncantatem() { + return this.history.slice(1, MAX_PRIOR_SPELLS + 1); + } + + deletrius() { + this.history = ['deletrius']; + } +} diff --git a/4kyu/pyramid_slide_down/solution.cs b/4kyu/pyramid_slide_down/solution.cs new file mode 100644 index 0000000..d6e6019 --- /dev/null +++ b/4kyu/pyramid_slide_down/solution.cs @@ -0,0 +1,19 @@ +using System; + +public class PyramidSlideDown +{ + public static int LongestSlideDown(int[][] pyramid) + { + for (var i = pyramid.GetLength(0) - 2; i >= 0; i--) { + for (var j = 0; j <= i; j++) { + if (pyramid[i + 1][j] > pyramid[i + 1][j + 1]) { + pyramid[i][j] += pyramid[i + 1][j]; + } else { + pyramid[i][j] += pyramid[i + 1][j + 1]; + } + } + } + + return pyramid[0][0]; + } +} diff --git a/4kyu/remove_zeros/solution.js b/4kyu/remove_zeros/solution.js new file mode 100644 index 0000000..ab779bf --- /dev/null +++ b/4kyu/remove_zeros/solution.js @@ -0,0 +1,28 @@ +function swap(array, i, j) { + let temporary = array[i]; + array[i] = array[j]; + array[j] = temporary; +} + +function removeZeros(array) { + // Sort "array" so that all elements with the value of zero are moved to the + // end of the array, while the other elements maintain order. + // [0, 1, 2, 0, 3] --> [1, 2, 3, 0, 0] + // Zero elements also maintain order in which they occurred. + // [0, "0", 1, 2, 3] --> [1, 2, 3, 0, "0"] + + // Do not use any temporary arrays or objects. Additionally, you're not able + // to use any Array or Object prototype methods such as .shift(), .push(), etc + + // the correctly sorted array should be returned. + + for (let i = array.length - 2; i > -1; i--) { + if (array[i] === 0 || array[i] === '0') { + for (let j = i; j < array.length - 1 && array[j + 1] !== 0 && array[j + 1] !== '0'; j++) { + swap(array, j, j + 1); + } + } + } + + return array; +} diff --git a/4kyu/route_calculator/solution.ts b/4kyu/route_calculator/solution.ts new file mode 100644 index 0000000..9b9d186 --- /dev/null +++ b/4kyu/route_calculator/solution.ts @@ -0,0 +1,69 @@ +class Expression { + private static readonly INVALID_REQUEST: string = "400: Bad request"; + + value: string; + + l: Expression | null = null; + r: Expression | null = null; + + private splitBy(operation: string): boolean { + let splitOperands = this.value.split(operation); + if (splitOperands.length < 2) { + return false; + } + + this.value = operation; + this.r = new Expression(splitOperands.pop()); + this.l = new Expression(splitOperands.join(operation)); + return true; + } + + constructor(expr: string) { + this.value = expr; + + for (let operation of "+-*$") { + if (this.splitBy(operation)) { + return; + } + } + } + + public evaluate(): (number | string) { + if (this.l === null && this.r === null) { + // process constants + if (![...this.value].every(c => "0123456789.".includes(c))) { + return Expression.INVALID_REQUEST; + } + + const val = Number.parseFloat(this.value); + return val; + } + + if (this.l === null || this.r === null || !("+-$*".includes(this.value))) { + return Expression.INVALID_REQUEST; + } + + const left = this.l.evaluate(); + const right = this.r.evaluate(); + + if (typeof left !== "number" || typeof right !== "number") { + return Expression.INVALID_REQUEST; + } + + let operation = null; + switch (this.value) { + case "+": + return left + right; + case "-": + return left - right; + case "$": + return left / right; + case "*": + return left * right; + } + } +} + +export const calculate = (sum: string): (number | string) => { + return new Expression(sum).evaluate(); +} diff --git a/4kyu/simplistic_tcp_fsm/solution.cs b/4kyu/simplistic_tcp_fsm/solution.cs new file mode 100644 index 0000000..5b26e4c --- /dev/null +++ b/4kyu/simplistic_tcp_fsm/solution.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; + +public class TCP { + private static bool IsInitialized = false; + private static Dictionary> Transitions = new Dictionary>(); + + private static void InitializeIfNeeded() { + if (IsInitialized) { + return; + } + IsInitialized = true; + + var transitions = new List<(string, string, string)>() { + ("CLOSED", "APP_PASSIVE_OPEN" , "LISTEN"), + ("CLOSED", "APP_ACTIVE_OPEN" , "SYN_SENT"), + ("LISTEN", "RCV_SYN" , "SYN_RCVD"), + ("LISTEN", "APP_SEND" , "SYN_SENT"), + ("LISTEN", "APP_CLOSE" , "CLOSED"), + ("SYN_RCVD", "APP_CLOSE" , "FIN_WAIT_1"), + ("SYN_RCVD", "RCV_ACK" , "ESTABLISHED"), + ("SYN_SENT", "RCV_SYN" , "SYN_RCVD"), + ("SYN_SENT", "RCV_SYN_ACK" , "ESTABLISHED"), + ("SYN_SENT", "APP_CLOSE" , "CLOSED"), + ("ESTABLISHED", "APP_CLOSE" , "FIN_WAIT_1"), + ("ESTABLISHED", "RCV_FIN" , "CLOSE_WAIT"), + ("FIN_WAIT_1", "RCV_FIN" , "CLOSING"), + ("FIN_WAIT_1", "RCV_FIN_ACK" , "TIME_WAIT"), + ("FIN_WAIT_1", "RCV_ACK" , "FIN_WAIT_2"), + ("CLOSING", "RCV_ACK" , "TIME_WAIT"), + ("FIN_WAIT_2", "RCV_FIN" , "TIME_WAIT"), + ("TIME_WAIT", "APP_TIMEOUT" , "CLOSED"), + ("CLOSE_WAIT", "APP_CLOSE" , "LAST_ACK"), + ("LAST_ACK", "RCV_ACK" , "CLOSED"), + }; + + foreach (var (fromState, byEvent, toState) in transitions) { + var fromStateDictionary = Transitions.GetValueOrDefault(fromState, new Dictionary()); + fromStateDictionary.Add(byEvent, toState); + Transitions[fromState] = fromStateDictionary; + } + } + + public static string TraverseStates(string[] events) { + InitializeIfNeeded(); + + var state = "CLOSED"; // initial state, always + + foreach (var ev in events) { + state = Transitions + .GetValueOrDefault(state, new Dictionary()) + .GetValueOrDefault(ev, "ERROR"); + } + + return state; + } +} diff --git a/4kyu/snail/solution.cs b/4kyu/snail/solution.cs new file mode 100644 index 0000000..f0b1c91 --- /dev/null +++ b/4kyu/snail/solution.cs @@ -0,0 +1,46 @@ +using System; + +public class SnailSolution { + private static void Update(ref int dx, ref int dy) { + int newDx = -dy, newDy = dx; + dy = newDy; + dx = newDx; + } + + public static int[] Snail(int[][] array) { + if (array.Length == 1 && array[0].Length == 0) { + return new int[] {}; + } + + int[] result = new int[array.Length * array.Length]; + + int y = 0, x = 0; + int dy = 0, dx = 1; + + int left = -1, right = array.Length; + int top = 0, bottom = array.Length; + + for (var i = 0; i < result.Length; i++) { + result[i] = array[y][x]; + + if (dx != 0 && x + dx <= left) { + left++; + Update(ref dx, ref dy); + } else if (dx != 0 && x + dx >= right) { + right--; + Update(ref dx, ref dy); + } else if (dy != 0 && y + dy <= top) { + top++; + Update(ref dx, ref dy); + } else if (dy != 0 && y + dy >= bottom) { + bottom--; + Update(ref dx, ref dy); + } + + x += dx; + y += dy; + } + + return result; + } +} diff --git a/4kyu/sudoku_solution_validator/solution.cs b/4kyu/sudoku_solution_validator/solution.cs new file mode 100644 index 0000000..a014272 --- /dev/null +++ b/4kyu/sudoku_solution_validator/solution.cs @@ -0,0 +1,53 @@ +using System.Collections.Generic; + +public class Sudoku { + private static readonly int FULL = (~(((~0) >> 9) << 9)) << 1; + + private static IEnumerable<(int, int)> Row(int row) { + for (var col = 0; col < 9; col++) { + yield return (row, col); + } + } + + private static IEnumerable<(int, int)> Column(int column) { + for (var row = 0; row < 9; row++) { + yield return (row, column); + } + } + + private static IEnumerable<(int, int)> Box(int k) { + var row = 3 * (k / 3); + var col = 3 * (k % 3); + + for (var i = 0; i < 3; i++) { + for (var j = 0; j < 3; j++) { + yield return (row + i, col + j); + } + } + } + + private static bool Valid(int[][] board, IEnumerable<(int, int)> coordinates) { + var encountered = 0; + foreach (var (row, col) in coordinates) { + if (board[row][col] == 0) { + return false; + } else if ((encountered & (1 << board[row][col])) != 0) { + return false; + } + + encountered |= 1 << board[row][col]; + } + + return encountered == FULL; + } + + public static bool ValidateSolution(int[][] board) { + for (var i = 0; i < 9; i++) { + if (!Valid(board, Row(i)) || !Valid(board, Column(i)) || !Valid(board, Box(i))) { + return false; + } + } + + return true; + } +} diff --git a/4kyu/sum_by_factors/solution.rs b/4kyu/sum_by_factors/solution.rs new file mode 100644 index 0000000..ce8eb14 --- /dev/null +++ b/4kyu/sum_by_factors/solution.rs @@ -0,0 +1,29 @@ +use std::vec::Vec; + +fn is_prime(n: i64) -> bool { + match n { + x if x % 2 == 0 => x == 2, + _ => { + let max_value = (n as f64).sqrt().ceil() as i64; + (3..max_value + 1).step_by(2).all(|i| n % i != 0) + } + } +} + +pub fn sum_of_divided(l: Vec) -> Vec<(i64, i64)> { + let max_value = l.iter().max_by_key(|x| x.abs()); + + match max_value { + Some(max_val) => (2..max_val.abs() + 1) + .filter(|&i| is_prime(i) && l.iter().any(|x| x % i == 0)) + .map(|i| { + ( + i, + l.iter() + .fold(0, |acc, &x| acc + if x % i == 0 { x } else { 0 }), + ) + }) + .collect(), + None => vec![], + } +} diff --git a/4kyu/sum_strings_as_numbers/solution.cs b/4kyu/sum_strings_as_numbers/solution.cs new file mode 100644 index 0000000..2f82c0c --- /dev/null +++ b/4kyu/sum_strings_as_numbers/solution.cs @@ -0,0 +1,63 @@ +using System; + +public static class Kata { + public static string sumStrings(string a, string b) { + var result = ""; + var i = a.Length - 1; + var j = b.Length - 1; + var remainder = 0; + + while (i >= 0 && j >= 0) { + var a_digit = a[i] - '0'; + var b_digit = b[j] - '0'; + var sum = a_digit + b_digit + remainder; + + result = (sum % 10) + result; + + if (sum >= 10) { + remainder = sum / 10; + } else { + remainder = 0; + } + + i--; + j--; + } + + while (i >= 0) { + var a_digit = a[i] - '0'; + var sum = a_digit + remainder; + + result = (sum % 10) + result; + + if (sum >= 10) { + remainder = sum / 10; + } else { + remainder = 0; + } + + i--; + } + + while (j >= 0) { + var b_digit = b[j] - '0'; + var sum = b_digit + remainder; + + result = (sum % 10) + result; + + if (sum >= 10) { + remainder = sum / 10; + } else { + remainder = 0; + } + + j--; + } + + if (remainder > 0) { + result = remainder + result; + } + + return result.TrimStart('0'); + } +} diff --git a/4kyu/the_observed_pin/solution.cs b/4kyu/the_observed_pin/solution.cs new file mode 100644 index 0000000..873fe85 --- /dev/null +++ b/4kyu/the_observed_pin/solution.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.Linq; + +public class Kata { + private static Dictionary Possible = new Dictionary() { + { '1', "124"}, { '2', "1235" }, { '3', "236" }, + { '4', "1457"}, { '5', "24568" }, { '6', "3569" }, + { '7', "478"}, { '8', "57890" }, { '9', "689" }, + { '0', "80" } + }; + + public static List GetPINs(string observed) { + var result = new HashSet() { + "" + }; + + foreach (char observedDigit in observed) { + var possibleDigits = Possible[observedDigit]; + + result = new HashSet( + result + .Select(pin => possibleDigits.Select(d => pin + d)) + .Aggregate((acc, e) => acc.Union(e)) + ); + } + + return result.ToList(); + } +} diff --git a/4kyu/twice_linear/solution.js b/4kyu/twice_linear/solution.js new file mode 100644 index 0000000..e85cae6 --- /dev/null +++ b/4kyu/twice_linear/solution.js @@ -0,0 +1,31 @@ +function dblLinear(n) { + let values = [1]; + let seen = new Set(values); + let index = 0; + let length = 0; + + while (length < n) { + const x = values.shift(); + seen.delete(x); + + const a = 2 * x + 1; + const b = 3 * x + 1; + + if (!seen.has(a)) { + let i = index; + + for (;i < values.length; i++) + if (values[i] > a) + break; + values.splice(i, 0, a); + seen.add(a); + index = i; + } + + seen.add(b); + values.push(b); + length++; + } + console.log(values); + return values[0]; +} diff --git a/5kyu/buddy_pairs/solution.kt b/5kyu/buddy_pairs/solution.kt new file mode 100644 index 0000000..c674151 --- /dev/null +++ b/5kyu/buddy_pairs/solution.kt @@ -0,0 +1,15 @@ +fun getSumOfDivisors(n: Long): Long = + (1 until Math.sqrt(n.toDouble()).toLong() + 1).reduce { + acc, e -> acc + if (n.rem(e) == 0.toLong()) e + n.div(e) else 0.toLong() + } + +fun buddy(start: Long, limit: Long): String { + for (n in start..limit) { + val m = getSumOfDivisors(n) - 1 + if (m > n && getSumOfDivisors(m) - 1 == n) { + return "($n $m)" + } + } + + return "Nothing" +} diff --git a/5kyu/calculating_with_functions/solution.js b/5kyu/calculating_with_functions/solution.js new file mode 100644 index 0000000..2e1ee45 --- /dev/null +++ b/5kyu/calculating_with_functions/solution.js @@ -0,0 +1,15 @@ +function zero(operand=null) { return (operand) ? operand(0) : 0; } +function one(operand=null) { return (operand) ? operand(1) : 1; } +function two(operand=null) { return (operand) ? operand(2) : 2; } +function three(operand=null) { return (operand) ? operand(3) : 3; } +function four(operand=null) { return (operand) ? operand(4) : 4; } +function five(operand=null) { return (operand) ? operand(5) : 5; } +function six(operand=null) { return (operand) ? operand(6) : 6; } +function seven(operand=null) { return (operand) ? operand(7) : 7; } +function eight(operand=null) { return (operand) ? operand(8) : 8; } +function nine(operand=null) { return (operand) ? operand(9) : 9; } + +function plus(right) { return (x) => x + right; } +function minus(right) { return (x) => x - right; } +function times(right) { return (x) => x * right; } +function dividedBy(right) { return (x) => Math.floor(x / right); } diff --git a/5kyu/common_denominators/solution.cs b/5kyu/common_denominators/solution.cs new file mode 100644 index 0000000..889b5c7 --- /dev/null +++ b/5kyu/common_denominators/solution.cs @@ -0,0 +1,32 @@ +using System; + +public class Fracts { + public static string convertFrac(long[,] lst) + { + if (lst.GetLength(0) < 1) return ""; + long denominator = lst[0, 1]; + + string result = ""; + + for (int i = 0; i < lst.GetLength(0); i++) denominator = LeastCommonMultiple(denominator, lst[i, 1]); + + for (int i = 0; i < lst.GetLength(0); i++) + { + long factor = denominator / lst[i, 1]; + result += String.Format("({0},{1})", lst[i, 0] * factor, lst[i, 1] * factor); + } + + return result; + } + + public static long GreatestCommonDivisor(long a, long b) + { + if (b == 0) return a; + else return GreatestCommonDivisor(b, a % b); + } + + public static long LeastCommonMultiple(long a, long b) + { + return a * b / GreatestCommonDivisor(a, b); + } +} diff --git a/5kyu/convert_a_hex_string_to_rgb/solution.c b/5kyu/convert_a_hex_string_to_rgb/solution.c new file mode 100644 index 0000000..6d279c5 --- /dev/null +++ b/5kyu/convert_a_hex_string_to_rgb/solution.c @@ -0,0 +1,13 @@ +#include + +typedef struct { + int r, g, b; +} rgb; + +rgb hex_str_to_rgb(const char *hex_str) { + rgb result; + + sscanf(hex_str, "#%2x%2x%2x", &result.r, &result.g, &result.b); + + return result; +} diff --git a/5kyu/count_ip_addresses/solution.rs b/5kyu/count_ip_addresses/solution.rs new file mode 100644 index 0000000..89fac9b --- /dev/null +++ b/5kyu/count_ip_addresses/solution.rs @@ -0,0 +1,10 @@ +fn parse_ip(ip_str: &str) -> u32 { + ip_str + .split(".") + .map(|octet| octet.parse::().unwrap()) + .fold(0, |ip, octet| (ip << 8) | octet) +} + +pub fn ips_between(start: &str, end: &str) -> u32 { + parse_ip(end) - parse_ip(start) +} diff --git a/5kyu/did_i_finish_my_sudokou/solution.js b/5kyu/did_i_finish_my_sudokou/solution.js new file mode 100644 index 0000000..241f5de --- /dev/null +++ b/5kyu/did_i_finish_my_sudokou/solution.js @@ -0,0 +1,57 @@ +function checkSet(set) { + if (set.size != 9) { + return false; + } else { + for (let num = 1; num <= 9; num++) { + if (!set.has(num)) { + return false; + } + } + } + + return true; +} + +function doneOrNot(board) { + const positive = "Finished!"; + const negative = "Try again!"; + + // Check rows + for (let row of board) { + row = new Set(row); + if (!checkSet(row)) { + return negative; + } + } + + // Check columns + for (let col = 0; col < 9; col++) { + // Construct set for a column + let column = new Set(); + for (let i = 0; i < 9; i++) { + column.add(board[i][col]); + } + + if (!checkSet(column)) { + return negative; + } + } + + // Check boxes + for (let i = 0; i < 9; i += 3) { + for (let j = 0; j < 9; j += 3) { + // Construct set of a box + let box = new Set(); + for (let k = 0; k < 3; k++) { + box.add(board[i + k][j]).add(board[i][j + k]).add(board[i + k][j + k]); + } + box.add(board[i + 2][j + 1]).add(board[i + 1][j + 2]); + + if (!checkSet(box)) { + return negative; + } + } + } + + return positive; +} diff --git a/5kyu/directions_reduction/solution.hs b/5kyu/directions_reduction/solution.hs new file mode 100644 index 0000000..3f5db31 --- /dev/null +++ b/5kyu/directions_reduction/solution.hs @@ -0,0 +1,20 @@ +module Codewars.Kata.Reduction where +import Codewars.Kata.Reduction.Direction + +-- data Direction = North | East | West | South deriving (Eq) + +areOpposite :: Direction -> Direction -> Bool +areOpposite North South = True +areOpposite South North = True +areOpposite East West = True +areOpposite West East = True +areOpposite _ _ = False + +folding :: Direction -> [Direction] -> [Direction] +folding x [] = [x] +folding x (y:rest) | areOpposite x y = rest + | otherwise = x:y:rest + +dirReduce :: [Direction] -> [Direction] +dirReduce [] = [] +dirReduce directions = foldr folding [] directions diff --git a/5kyu/esolang_interpreters_ii/solution.swift b/5kyu/esolang_interpreters_ii/solution.swift new file mode 100644 index 0000000..5115886 --- /dev/null +++ b/5kyu/esolang_interpreters_ii/solution.swift @@ -0,0 +1,61 @@ +func interpreter(_ code: String, _ tape: String) -> String { + func fromTape(stringTape: String) -> [Int] { + return stringTape.map({ c in (c == "0") ? 0 : 1 }) + } + + func toTape(intTape: [Int]) -> String { + return intTape.reduce("", { x, b in x + (b == 0 ? "0" : "1") }) + } + + func findComplement(direction: Int, startIndex: Int, l: Character, r: Character) -> Int { + var depth = 0 + var i = startIndex + + repeat { + let c = code[code.index(code.startIndex, offsetBy: i)] + + if c == l { + depth += 1 + } else if c == r { + depth -= 1 + } + + i += direction + } while depth != 0 + + return i + } + + var bits = fromTape(stringTape: tape) + var i = 0 + + var codeIndex = 0 + while codeIndex >= 0 && codeIndex < code.count { + switch code[code.index(code.startIndex, offsetBy: codeIndex)] { + case ">": + i += 1 + case "<": + i -= 1 + case "*": + bits[i] = (bits[i] + 1) % 2 + case "[": + if bits[i] == 0 { + codeIndex = findComplement(direction: 1, startIndex: codeIndex, l: "[", r: "]") - 1 + } + case "]": + if bits[i] != 0 { + codeIndex = findComplement(direction: -1, startIndex: codeIndex, l: "]", r: "[") + } + default: + break + } + + codeIndex += 1 + + if i < 0 || i >= bits.count { + break + } + } + + return toTape(intTape: bits) +} diff --git a/5kyu/greed_is_good/solution.cpp b/5kyu/greed_is_good/solution.cpp new file mode 100644 index 0000000..131af9c --- /dev/null +++ b/5kyu/greed_is_good/solution.cpp @@ -0,0 +1,48 @@ +#include +#include +#include + +std::map process_dice(const std::vector& dice) { + std::map freqs; + + for (auto val : dice) { + freqs[val]++; + } + + return freqs; +} + +int score(const std::vector& dice) { + const std::map, int> options{ + {{3, 1}, 1000}, + {{3, 6}, 600}, + {{3, 5}, 500}, + {{3, 4}, 400}, + {{3, 3}, 300}, + {{3, 2}, 200} + }; + + auto counts = process_dice(dice); + auto total = 0; + + for (auto has_changed = true; has_changed;) { + has_changed = false; + + for (const auto& [option, points] : options) { + const auto& [count, die] = option; + + if (counts[die] >= count) { + counts[die] -= count; + total += points; + + has_changed = true; + break; + } + } + } + + total += counts[1] * 100; + total += counts[5] * 50; + + return total; +} diff --git a/5kyu/halloween_sweets/solution.js b/5kyu/halloween_sweets/solution.js new file mode 100644 index 0000000..b9a153c --- /dev/null +++ b/5kyu/halloween_sweets/solution.js @@ -0,0 +1,24 @@ +function pick(bags, scale) { + if (bags.length == 1) { + return bags[0]; + } + + let sets = []; + let sizeOfSet = bags.length / 3; + + for (let i = 0; i < bags.length; i += sizeOfSet) { + sets.push(bags.slice(i, i + sizeOfSet)); + } + + switch (scale.weigh(sets[0], sets[1])) { + case -1: + return pick(sets[0], scale); + break; + case 0: + return pick(sets[2], scale); + break; + case 1: + return pick(sets[1], scale); + break; + } +} diff --git a/5kyu/human_readable_time/solution.cs b/5kyu/human_readable_time/solution.cs new file mode 100644 index 0000000..c1407a5 --- /dev/null +++ b/5kyu/human_readable_time/solution.cs @@ -0,0 +1,14 @@ +using System; + +public static class TimeFormat +{ + public static string GetReadableTime(int seconds) + { + var hours = seconds / 3600; + seconds %= 3600; + var minutes = seconds / 60; + seconds %= 60; + + return String.Format("{0:00}:{1:00}:{2:00}", hours, minutes, seconds); + } +} diff --git a/5kyu/i32_to_ipv4/solution.c b/5kyu/i32_to_ipv4/solution.c new file mode 100644 index 0000000..15343a2 --- /dev/null +++ b/5kyu/i32_to_ipv4/solution.c @@ -0,0 +1,6 @@ +#include +#include + +void uint32_to_ip(uint32_t ip, char *output) { + sprintf(output, "%d.%d.%d.%d", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF); +} diff --git a/5kyu/is_my_friend_cheating/solution.cpp b/5kyu/is_my_friend_cheating/solution.cpp new file mode 100644 index 0000000..f6355cf --- /dev/null +++ b/5kyu/is_my_friend_cheating/solution.cpp @@ -0,0 +1,46 @@ +#include +#include + +class RemovedNumbers +{ + static long long get_lower_bound(long long n); + static long long get_complement(long long ax, long long n); + + public: + static std::vector> removNb(long long n); +}; + +long long RemovedNumbers::get_lower_bound(long long n) +{ + return (long long)ceil((2 * n - n * n - n) / (-2 * n - 2.0)); +} + +long long RemovedNumbers::get_complement(long long ax, long long n) +{ + auto result = (0.5 * (n * n + n) - ax) / (ax + 1); + + if (floor(result) == result) + { + return (long long)result; + } + else + { + return 0; + } +} + +std::vector> RemovedNumbers::removNb(long long n) +{ + std::vector> result; + + for (long long ax = get_lower_bound(n); ax <= n; ax++) + { + auto complement = get_complement(ax, n); + if (complement != 0) + { + result.push_back({ax, complement}); + } + } + + return result; +} diff --git a/5kyu/maximum_subarray_sum/solution.kt b/5kyu/maximum_subarray_sum/solution.kt new file mode 100644 index 0000000..b24544d --- /dev/null +++ b/5kyu/maximum_subarray_sum/solution.kt @@ -0,0 +1,4 @@ +fun maxSequence(arr: List): Int = + arr.scan(0) { k, it -> + maxOf(k, 0) + it + }.maxOrNull() ?: 0 diff --git a/5kyu/memoized_fibonacci/solution.py b/5kyu/memoized_fibonacci/solution.py new file mode 100644 index 0000000..dc2b0b8 --- /dev/null +++ b/5kyu/memoized_fibonacci/solution.py @@ -0,0 +1,12 @@ +fibonacci_memory = {} + +def fibonacci(n): + if n in [0, 1]: + return n + + if n not in fibonacci_memory: + value = fibonacci(n - 1) + fibonacci(n - 2) + fibonacci_memory[n] = value + return value + else: + return fibonacci_memory[n] diff --git a/5kyu/moving_zeros_to_the_end/solution.cs b/5kyu/moving_zeros_to_the_end/solution.cs new file mode 100644 index 0000000..7c0e597 --- /dev/null +++ b/5kyu/moving_zeros_to_the_end/solution.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Linq; + +public class Kata { + public static int[] MoveZeroes(int[] arr) { + var length = arr.GetLength(0); + + var new_arr = arr.Where(x => x != 0).ToList(); + for (var i = length - new_arr.Count(); i > 0; i--) new_arr.Add(0); + + return new_arr.ToArray(); + } +} diff --git a/5kyu/my_smallest_code_interpreter_bf/solution.rs b/5kyu/my_smallest_code_interpreter_bf/solution.rs new file mode 100644 index 0000000..b5bc74b --- /dev/null +++ b/5kyu/my_smallest_code_interpreter_bf/solution.rs @@ -0,0 +1,86 @@ +use std::collections::HashMap; + +fn find_left(instructions: &[u8], index: usize) -> usize { + let mut result = index - 1; + let mut count = 1; + + while count != 0 { + if instructions[result] == ']' as u8 { + count += 1; + } else if instructions[result] == '[' as u8 { + count -= 1; + } + + result -= 1; + } + + result + 1 +} + +fn find_right(instructions: &[u8], index: usize) -> usize { + let mut result = index + 1; + let mut count = 1; + + while count != 0 { + if instructions[result] == '[' as u8 { + count += 1; + } else if instructions[result] == ']' as u8 { + count -= 1; + } + + result += 1; + } + + result - 1 +} + +fn brain_luck(code: &str, input: Vec) -> Vec { + let instructions = code.as_bytes(); + + let mut result = Vec::::new(); + let mut tape = HashMap::::new(); + let mut i = 0; + let mut tape_i = 0; + let mut input_i = 0; + + while i < instructions.len() { + match instructions[i] as char { + '>' => tape_i += 1, + '<' => tape_i -= 1, + '+' => { + tape.insert(tape_i, (tape.get(&tape_i).unwrap_or(&0) + 1) % 256); + () + } + '-' => { + let new_value = tape.get(&tape_i).unwrap_or(&0) - 1; + tape.insert(tape_i, if new_value < 0 { 255 } else { new_value }); + () + } + '.' => { + result.push(*tape.get(&tape_i).unwrap_or(&0) as u8); + () + } + ',' => { + tape.insert(tape_i, input[input_i] as i16); + input_i += 1; + () + } + '[' => { + if *tape.get(&tape_i).unwrap_or(&0) == 0 { + i = find_right(instructions, i); + } + () + } + ']' => { + if *tape.get(&tape_i).unwrap_or(&0) != 0 { + i = find_left(instructions, i); + } + () + } + _ => {} + } + + i += 1; + } + result +} diff --git a/5kyu/number_of_trailing_zeros_of_nf/solution.cs b/5kyu/number_of_trailing_zeros_of_nf/solution.cs new file mode 100644 index 0000000..7da8ed9 --- /dev/null +++ b/5kyu/number_of_trailing_zeros_of_nf/solution.cs @@ -0,0 +1,16 @@ +using System; + +public static class Kata +{ + public static int TrailingZeros(int n) + { + var sum = 0.0; + var max = Math.Floor(Math.Log(n)/Math.Log(5)); + + for (var i = 1; i <= max; i++) { + sum += Math.Floor(n / Math.Pow(5, i)); + } + + return (int) sum; + } +} diff --git a/5kyu/perimeter_of_squares_in_a_rectangle/solution.rs b/5kyu/perimeter_of_squares_in_a_rectangle/solution.rs new file mode 100644 index 0000000..e58629a --- /dev/null +++ b/5kyu/perimeter_of_squares_in_a_rectangle/solution.rs @@ -0,0 +1,21 @@ +use std::vec::Vec; + +fn fibonacci(n: u64) -> Vec { + match n { + 0 => vec![1], + 1 => vec![1, 1], + _ => { + let mut result = vec![1, 1]; + + for i in 2..(n as usize + 1) { + result.push(result[i - 1] + result[i - 2]); + } + + result + } + } +} + +pub fn perimeter(n: u64) -> u64 { + fibonacci(n).iter().fold(0, |acc, x| acc + 4 * x) +} diff --git a/5kyu/rgb_to_hex_conversion/solution.cs b/5kyu/rgb_to_hex_conversion/solution.cs new file mode 100644 index 0000000..24ed7c7 --- /dev/null +++ b/5kyu/rgb_to_hex_conversion/solution.cs @@ -0,0 +1,16 @@ +public class Kata +{ + public static int Constrain(int val, int min, int max) { + if (val < min) return min; + else if (val > max) return max; + else return val; + } + + public static string Rgb(int r, int g, int b) + { + r = Constrain(r, 0, 255); + g = Constrain(g, 0, 255); + b = Constrain(b, 0, 255); + return $"{r,2:X2}{g,2:X2}{b,2:X2}"; + } +} diff --git a/5kyu/rot13/solution.js b/5kyu/rot13/solution.js new file mode 100644 index 0000000..6b8854d --- /dev/null +++ b/5kyu/rot13/solution.js @@ -0,0 +1,17 @@ +function rot13(message) { + let result = ""; + + for (let character of message) { + let val = character.charCodeAt(); + + if (val >= 97 && val <= 122) { + result += String.fromCharCode(97 + (val - 97 + 13) % 26); + } else if (val >= 65 && val <= 90) { + result += String.fromCharCode(65 + (val - 65 + 13) % 26); + } else { + result += character; + } + } + + return result; +} diff --git a/5kyu/scramblies/solution.cs b/5kyu/scramblies/solution.cs new file mode 100644 index 0000000..b1c86f9 --- /dev/null +++ b/5kyu/scramblies/solution.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +public class Scramblies { + public static bool Scramble(string str1, string str2) { + var list = new List(str1.ToCharArray()); + list.Sort(); + + foreach (char letter in str2) { + if (list.Contains(letter)) { + list.Remove(letter); + } else { + return false; + } + } + + return true; + } +} diff --git a/5kyu/simple_assembler_interpreter/solution.kt b/5kyu/simple_assembler_interpreter/solution.kt new file mode 100644 index 0000000..aa269c8 --- /dev/null +++ b/5kyu/simple_assembler_interpreter/solution.kt @@ -0,0 +1,38 @@ +private fun constantOrRegister(token: String, regs: Map): Int = + token.toIntOrNull() ?: regs.getOrDefault(token, 0) + +fun interpret(program: Array): Map { + var result = mutableMapOf() + var instruction = 0 + + while (instruction in program.indices) { + val ops = program.elementAt(instruction).split(' ') + + when (ops[0]) { + "mov" -> { + val value = constantOrRegister(ops[2], result) + result.put(ops[1], value) + } + "inc" -> { + val value = result.getOrDefault(ops[1], 0) + result.put(ops[1], value + 1) + } + "dec" -> { + val value = result.getOrDefault(ops[1], 0) + result.put(ops[1], value - 1) + } + "jnz" -> { + val diff = constantOrRegister(ops[2], result) + val cond = constantOrRegister(ops[1], result) + + if (cond != 0) { + instruction = instruction + diff - 1 + } + } + else -> error("invalid instruction") + } + instruction++ + } + + return result +} diff --git a/5kyu/simple_pig_latin/solution.py b/5kyu/simple_pig_latin/solution.py new file mode 100644 index 0000000..6350cff --- /dev/null +++ b/5kyu/simple_pig_latin/solution.py @@ -0,0 +1,9 @@ +def pig_it(text): + result = '' + + for word in text.split(): + if word in '.?!\',': + result += word + ' ' + else: + result += word[1:] + word[0] + 'ay ' + return result.strip() diff --git a/5kyu/snakes_and_ladders/solution.cpp b/5kyu/snakes_and_ladders/solution.cpp new file mode 100644 index 0000000..8b2e70f --- /dev/null +++ b/5kyu/snakes_and_ladders/solution.cpp @@ -0,0 +1,62 @@ +#include + +class SnakesLadders +{ + private: + static std::map sls; + int positions[2]; + int player = 0; + public: + SnakesLadders(){ + positions[0] = positions[1] = 0; + }; + std::string play(int die1, int die2) + { + if (positions[0] == 100 || positions[1] == 100) { + return "Game over!"; + } else { + positions[player] += die1 + die2; + + if (positions[player] > 100) { + positions[player] = 100 - positions[player] % 100; + } else if (positions[player] == 100) { + return "Player " + std::to_string(player + 1) + " Wins!"; + } + + if (sls.find(positions[player]) != sls.end()) { + positions[player] = sls[positions[player]]; + } + + int p = player + 1; + if (die1 != die2) { + player = (player + 1) % 2; + } + + return "Player " + std::to_string(p) + " is on square " + std::to_string(positions[p - 1]); + } + }; +}; + +std::map SnakesLadders::sls = { + { 2, 38}, + { 7, 14}, + { 8, 31}, + {15, 26}, + {16, 6}, + {21, 42}, + {28, 84}, + {36, 44}, + {46, 25}, + {49, 11}, + {51, 67}, + {62, 19}, + {64, 60}, + {71, 91}, + {74, 53}, + {78, 98}, + {87, 94}, + {89, 68}, + {92, 88}, + {95, 75}, + {99, 80}, +}; diff --git a/5kyu/sum_of_pairs/solution.py b/5kyu/sum_of_pairs/solution.py new file mode 100644 index 0000000..0e31890 --- /dev/null +++ b/5kyu/sum_of_pairs/solution.py @@ -0,0 +1,11 @@ +def sum_pairs(ints, s): + passed = {} + + for num in ints: + other = s - num + if other in passed: + return [other, num] + else: + passed[num] = True + + return None diff --git a/5kyu/the_clockwise_spiral/solution.cpp b/5kyu/the_clockwise_spiral/solution.cpp new file mode 100644 index 0000000..09f1e6d --- /dev/null +++ b/5kyu/the_clockwise_spiral/solution.cpp @@ -0,0 +1,32 @@ +#include + +static void next_diff(int &dy, int &dx) { + int new_dx = -dy, new_dy = dx; + dy = new_dy; + dx = new_dx; +} + +std::vector> create_spiral(int n) { + if (n < 1) { + return {}; + } + + auto result = std::vector>( + static_cast(n), std::vector( static_cast(n), 0 ) + ); + + int y = 0, x = 0; + int dy = 0, dx = 1; + for (int i = 1, max = n * n; i <= max; i++) { + result[y][x] = i; + + if (y + dy == n || y + dy < 0 || x + dx == n || x + dx < 0 || result[y + dy][x + dx] != 0) { + next_diff(dy, dx); + } + + y += dy; + x += dx; + } + + return result; +} diff --git a/5kyu/the_hashtag_generator/solution.js b/5kyu/the_hashtag_generator/solution.js new file mode 100644 index 0000000..d01e932 --- /dev/null +++ b/5kyu/the_hashtag_generator/solution.js @@ -0,0 +1,7 @@ +function generateHashtag (str) { + const result = str.split(/\s+/igm).reduce((accum, word) => + accum + word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase() + , "#"); + + return (result.length > 140 || result == "#") ? false : result; +} diff --git a/5kyu/tic_tac_toe_checker/solution.js b/5kyu/tic_tac_toe_checker/solution.js new file mode 100644 index 0000000..f688359 --- /dev/null +++ b/5kyu/tic_tac_toe_checker/solution.js @@ -0,0 +1,71 @@ +function checkEmpty(board) { + for (let i = 0; i < 3; i++) { + for (let j = 0; j < 3; j++) { + if (board[i][j] === 0) { + return true; + } + } + } +} + +function checkColumn(board, column) { + for (let i = 1; i < 3; i++) { + if (board[i - 1][column] !== board[i][column]) { + return 0; + } + } + return board[0][column]; +} + +function checkRow(board, row) { + for (let i = 1; i < 3; i++) { + if (board[row][i - 1] !== board[row][i]) { + return 0; + } + } + return board[row][0]; +} + +function checkDiagonal(board) { + let leftToRight = true; + let rightToLeft = true; + for (let i = 1; i < 3; i++) { + if (board[i - 1][i - 1] !== board[i][i]) { + leftToRight = false; + } + if (board[i - 1][3 - i] !== board[i][2 - i]) { + rightToLeft = false; + } + } + + if (leftToRight) { + return board[0][0]; + } else if (rightToLeft) { + return board[0][2]; + } else { + return 0; + } +} + +function isSolved(board) { + for (let i = 0; i < 3; i++) { + const col = checkColumn(board, i); + const row = checkRow(board, i); + if (col != 0) { + return col; + } else if (row != 0) { + return row; + } + } + + const diagonal = checkDiagonal(board); + if (diagonal != 0) { + return diagonal; + } + + if (checkEmpty(board)) { + return -1; + } + + return 0; +} diff --git a/5kyu/valid_parentheses/solution.py b/5kyu/valid_parentheses/solution.py new file mode 100644 index 0000000..57581e6 --- /dev/null +++ b/5kyu/valid_parentheses/solution.py @@ -0,0 +1,11 @@ +def valid_parentheses(string): + opened = 0 + + for letter in string: + if letter == '(': + opened += 1 + elif letter == ')': + opened -= 1 + if opened < 0: + return False + return opened == 0 diff --git a/5kyu/vector_class/solution.js b/5kyu/vector_class/solution.js new file mode 100644 index 0000000..d7a3ab0 --- /dev/null +++ b/5kyu/vector_class/solution.js @@ -0,0 +1,54 @@ +class Vector { + constructor(array) { + this.values = array.slice(0); + } + + mathOperation(vector, f) { + if (!vector || !(vector instanceof Vector) || this.values.length !== vector.values.length) { + throw "invalid operation"; + } + + let result = []; + for (let i = 0; i < this.values.length; i++) { + result.push(f(this.values[i], vector.values[i])); + } + + return new Vector(result); + } + + add(vector) { + return this.mathOperation(vector, (t, o) => t + o); + } + + subtract(vector) { + return this.mathOperation(vector, (t, o) => t - o); + } + + dot(vector) { + return this.mathOperation(vector, (t, o) => t * o) + .values.reduce((t, e) => t + e, 0); + } + + norm() { + return Math.sqrt(this.dot(this)); + } + + toString() { + return `(${this.values.join(',')})`; + } + + equals(other) { + if (!other || !(other instanceof Vector) || this.values.length !== other.values.length) { + return false; + } else if (other === this) { + return true; + } else { + for (let i = 0; i < this.values.length; i++) { + if (this.values[i] !== other.values[i]) { + return false; + } + } + return true; + } + } +} diff --git a/5kyu/weight_for_weight/solution.py b/5kyu/weight_for_weight/solution.py new file mode 100644 index 0000000..c8ae7bf --- /dev/null +++ b/5kyu/weight_for_weight/solution.py @@ -0,0 +1,22 @@ +def digit_sum(n): + total = 0 + while n > 0: + total += n % 10 + n //= 10 + return total + +class Weight: + def __init__(self, weight): + self.weight = weight + self.digit_sum = digit_sum(weight) + + def __lt__(self, other): + if self.digit_sum == other.digit_sum: + return str(self.weight) < str(other.weight) + return self.digit_sum < other.digit_sum + + def __str__(self): + return str(self.weight) + +def order_weight(strng): + return ' '.join(map(lambda e: str(e), sorted(map(lambda e: Weight(int(e)), strng.split())))) diff --git a/5kyu/where_my_anagrams_at/solution.js b/5kyu/where_my_anagrams_at/solution.js new file mode 100644 index 0000000..6d16c0c --- /dev/null +++ b/5kyu/where_my_anagrams_at/solution.js @@ -0,0 +1,15 @@ +function anagrams(word, words) { + word = word.split(''); + word.sort(); + word = word.join(''); + + let result = []; + for (let testedWord of words) { + twSorted = testedWord.split(''); + twSorted.sort(); + if (word == twSorted.join('')) + result.push(testedWord); + } + + return result; +} diff --git a/5kyu/which_x_for_that_sum/solution.rs b/5kyu/which_x_for_that_sum/solution.rs new file mode 100644 index 0000000..108a16c --- /dev/null +++ b/5kyu/which_x_for_that_sum/solution.rs @@ -0,0 +1,24 @@ +fn solve_quadratic(a: f64, b: f64, c: f64) -> Option<(f64, f64)> { + let d = b * b - 4.0 * a * c; + + if d < 0.0 { + None + } else { + Some(((-b + d.sqrt()) / (2.0 * a), (-b - d.sqrt()) / (2.0 * a))) + } +} + +pub fn solve(m: f64) -> f64 { + match solve_quadratic(m, -2.0 * m - 1.0, m) { + Some((left, right)) => { + if left > 0.0 && left < 1.0 { + left + } else if right > 0.0 && right < 1.0 { + right + } else { + 0.0 + } + } + None => 0.0, + } +} diff --git a/6kyu/are_they_the_same/solution.js b/6kyu/are_they_the_same/solution.js new file mode 100644 index 0000000..bc3b8c0 --- /dev/null +++ b/6kyu/are_they_the_same/solution.js @@ -0,0 +1,16 @@ +function comp(array1, array2){ + let squares = []; + for (let num of array1) { + squares.push(num * num); + } + + if (!array2) + return false; + + for (let square of array2) { + let index = squares.indexOf(square); + if (index != -1) squares.splice(index, 1); + } + if (squares.length > 0) return false; + else return true; +} diff --git a/6kyu/ball_upwards/solution.kt b/6kyu/ball_upwards/solution.kt new file mode 100644 index 0000000..1308d79 --- /dev/null +++ b/6kyu/ball_upwards/solution.kt @@ -0,0 +1,12 @@ +package ball + +val G = 9.81 + +fun maxBall(v0: Int): Int { + val v = v0 * 5 / 18.0 + val maxT = v * 10 / G + + return (0..maxT.toInt() + 1).maxBy { + v * it / 10.0 - 0.5 * G * it * it / 100.0 + } ?: 0 +} diff --git a/6kyu/bit_counting/solution.py b/6kyu/bit_counting/solution.py new file mode 100644 index 0000000..eba8280 --- /dev/null +++ b/6kyu/bit_counting/solution.py @@ -0,0 +1,7 @@ +def countBits(n): + count = 0 + while n > 0: + if n % 2 == 1: + count += 1 + n //= 2 + return count diff --git a/6kyu/bouncing_balls/solution.py b/6kyu/bouncing_balls/solution.py new file mode 100644 index 0000000..7a77b3d --- /dev/null +++ b/6kyu/bouncing_balls/solution.py @@ -0,0 +1,9 @@ +def bouncingBall(h, bounce, window): + if h <= 0 or (bounce <= 0 or bounce >= 1) or window >= h: + return -1 + + result = -1 + while h > window: + h *= bounce + result += 2 + return result diff --git a/6kyu/build_tower/solution.js b/6kyu/build_tower/solution.js new file mode 100644 index 0000000..e292f84 --- /dev/null +++ b/6kyu/build_tower/solution.js @@ -0,0 +1,25 @@ +String.prototype.centerJustify = function(length, char) { + let i = 0; + let str = this; + let toggle = true; + while (i + this.length < length) { + i++; + if (toggle) + str = str + char; + else + str = char + str; + toggle = !toggle; + } + return str; +} + +function towerBuilder(nFloors) { + let floor = '*'; + const width = nFloors * 2 - 1; + let result = []; + for (let i = 0, count = 1; i < nFloors; i++, count += 2) { + result.push(floor.centerJustify(width, ' ')); + floor += '**'; + } + return result; +} diff --git a/6kyu/build_tower_advanced/solution.js b/6kyu/build_tower_advanced/solution.js new file mode 100644 index 0000000..05a9e09 --- /dev/null +++ b/6kyu/build_tower_advanced/solution.js @@ -0,0 +1,30 @@ +String.prototype.centerJustify = function(length, char) { + let i = 0; + let str = this; + let toggle = true; + while (i + this.length < length) { + i++; + if (toggle) + str = str + char; + else + str = char + str; + toggle = !toggle; + } + return str; +} + +function towerBuilder(nFloors, nBlockSz) { + let floor = ''; + for (let i = 0; i < nBlockSz[0]; i++) + floor += '*'; + const width = nFloors * 2 * nBlockSz[0] - nBlockSz[0]; + let result = []; + for (let i = 0, count = 1; i < nFloors; i++, count += 2) { + for (let j = 0; j < nBlockSz[1]; j++) { + result.push(floor.centerJustify(width, ' ')); + } + for (let j = 0; j < nBlockSz[0]; j++) + floor += '**'; + } + return result; +} diff --git a/6kyu/camelcase_method/solution.rs b/6kyu/camelcase_method/solution.rs new file mode 100644 index 0000000..3553156 --- /dev/null +++ b/6kyu/camelcase_method/solution.rs @@ -0,0 +1,19 @@ +fn camel_case(str: &str) -> String { + let mut result = String::from(""); + + let mut was_space: bool = true; + for character in str.chars() { + if character.is_whitespace() { + was_space = true; + } else if character.is_alphabetic() { + if was_space { + result += &character.to_uppercase().to_string(); + was_space = false; + } else { + result += &character.to_lowercase().to_string(); + } + } + } + + result.to_string() +} diff --git a/6kyu/cheat_or_you_shall_not_pass_easy/solution.c b/6kyu/cheat_or_you_shall_not_pass_easy/solution.c new file mode 100644 index 0000000..5df19ac --- /dev/null +++ b/6kyu/cheat_or_you_shall_not_pass_easy/solution.c @@ -0,0 +1,12 @@ +#include + +int solution() +{ + // return the right answer here + srand(0); + int a = 0; + int b = 1000; + int result = rand() % (b - a) + a; + srand(0); + return result; +} diff --git a/6kyu/consecutive_strings/solution.java b/6kyu/consecutive_strings/solution.java new file mode 100644 index 0000000..0c9e90a --- /dev/null +++ b/6kyu/consecutive_strings/solution.java @@ -0,0 +1,42 @@ +class LongestConsec { + public static String longestConsec(String[] strarr, int k) { + int n = strarr.length; + + // handle limits + if (n == 0 || k <= 0 || k > n) { + return ""; + } + + // determine lengths + int[] lengths = new int[n]; + for (int i = 0; i < n; i++) { + lengths[i] = strarr[i].length(); + } + + // calculate first index + int maxIndex = 0, maxLength = 0; + for (int i = 0; i < k; i++) { + maxLength += lengths[i]; + } + + // Check rest of the array + int tmpLength = maxLength; + for (int i = 1; i < n - k + 1; i++) { + tmpLength += lengths[i + k - 1]; + tmpLength -= lengths[i - 1]; + + if (tmpLength > maxLength) { + maxIndex = i; + maxLength = tmpLength; + } + } + + // Join the strings + String result = ""; + for (int i = maxIndex; i < maxIndex + k; i++) { + result += strarr[i]; + } + + return result; + } +} diff --git a/6kyu/convert_string_to_camel_case/solution.js b/6kyu/convert_string_to_camel_case/solution.js new file mode 100644 index 0000000..5e77860 --- /dev/null +++ b/6kyu/convert_string_to_camel_case/solution.js @@ -0,0 +1,13 @@ +function toCamelCase(str){ + if (str.indexOf('-') != -1) { + str = str.split('-'); + } else { + str = str.split('_'); + } + + for (let i = 1; i < str.length; i++) { + str[i] = str[i].charAt(0).toUpperCase() + str[i].substring(1); + } + + return str.join(''); +} diff --git a/6kyu/count_the_smiley_faces/solution.cs b/6kyu/count_the_smiley_faces/solution.cs new file mode 100644 index 0000000..c26c15c --- /dev/null +++ b/6kyu/count_the_smiley_faces/solution.cs @@ -0,0 +1,17 @@ +using System.Text.RegularExpressions; + +public static class Kata +{ + public static int CountSmileys(string[] smileys) + { + var count = 0; + + var regex = new Regex(@"[:;][-~]?[D\)]"); + + foreach (string smiley in smileys) { + if (regex.Match(smiley).Success) count++; + } + + return count; + } +} diff --git a/6kyu/counting_duplicates/solution.rs b/6kyu/counting_duplicates/solution.rs new file mode 100644 index 0000000..8d94aef --- /dev/null +++ b/6kyu/counting_duplicates/solution.rs @@ -0,0 +1,24 @@ +use std::collections::HashMap; + +fn count_duplicates(text: &str) -> u32 { + let mut counts: HashMap = HashMap::new(); + + for character in text.to_lowercase().chars() { + match counts.get_mut(&character) { + None => { + counts.insert(character, 1); + {} + }, + Some(x) => *x += 1 + } + } + + counts + .iter() + .fold(0, |total, (_, &count)| + match count > 1 { + true => total + 1, + _ => total + } + ) +} diff --git a/6kyu/create_phone_number/solution.js b/6kyu/create_phone_number/solution.js new file mode 100644 index 0000000..2e397bd --- /dev/null +++ b/6kyu/create_phone_number/solution.js @@ -0,0 +1,12 @@ +function createPhoneNumber(numbers) { + let result = '('; + for (let i = 0; i < 10; i++) { + result += numbers[i]; + if (i == 2) { + result += ') '; + } else if (i == 5) { + result += '-'; + } + } + return result; +} diff --git a/6kyu/decode_the_morse_code/solution.rs b/6kyu/decode_the_morse_code/solution.rs new file mode 100644 index 0000000..7390d51 --- /dev/null +++ b/6kyu/decode_the_morse_code/solution.rs @@ -0,0 +1,18 @@ +mod preloaded; +use preloaded::MORSE_CODE; +// MORSE_CODE is `HashMap`. e.g. ".-" -> "A". + +fn decode_morse(encoded: &str) -> String { + let mut result = String::new(); + + encoded.split(" ").map(|x| x.trim()).for_each(|x| { + x.split_whitespace().for_each(|c| { + result += MORSE_CODE.get(c).unwrap(); + }); + + result += " "; + }); + + + String::from(result.trim()) +} diff --git a/6kyu/delete_occurrences_if_occurs/solution.js b/6kyu/delete_occurrences_if_occurs/solution.js new file mode 100644 index 0000000..73084b4 --- /dev/null +++ b/6kyu/delete_occurrences_if_occurs/solution.js @@ -0,0 +1,17 @@ +function deleteNth(arr, n) { + const freqs = {}; + const result = []; + + for (const element of arr) { + if (!freqs[element]) { + freqs[element] = 1; + } else if (freqs[element] < n) { + freqs[element]++; + } else { + continue; + } + result.push(element); + } + + return result; +} diff --git a/6kyu/design_a_simple_automaton/solution.cpp b/6kyu/design_a_simple_automaton/solution.cpp new file mode 100644 index 0000000..9079d4a --- /dev/null +++ b/6kyu/design_a_simple_automaton/solution.cpp @@ -0,0 +1,36 @@ +#include +#include + +class Automaton +{ + std::set F{2}; + const int initial_state = 1; + + std::map> transitions{ + {1, std::map{ + {'0', 1}, {'1', 2} + } + }, + {2, std::map{ + {'0', 3}, {'1', 2} + } + }, + {3, std::map{ + {'0', 2}, {'1', 2} + } + } + }; + +public: + Automaton() {} + + bool read_commands(const std::vector& commands) { + int state = initial_state; + + for (const char c : commands) { + state = transitions[state][c]; + } + + return F.find(state) != F.end(); + } +}; diff --git a/6kyu/does_my_number_look_big_in_this/solution.cs b/6kyu/does_my_number_look_big_in_this/solution.cs new file mode 100644 index 0000000..a981b30 --- /dev/null +++ b/6kyu/does_my_number_look_big_in_this/solution.cs @@ -0,0 +1,19 @@ +using System; + +public class Kata { + public static bool Narcissistic(int value) { + var narcissistic = 0; + var length = (int) Math.Log10(value + 0.5) + 1; + var copyOfValue = value; + + while (copyOfValue > 0) { + narcissistic += (int) Math.Pow(copyOfValue % 10, length); + copyOfValue /= 10; + if (narcissistic > value) { + return false; + } + } + + return narcissistic == value; + } +} diff --git a/6kyu/duplicate_encoder/solution.java b/6kyu/duplicate_encoder/solution.java new file mode 100644 index 0000000..1b0b352 --- /dev/null +++ b/6kyu/duplicate_encoder/solution.java @@ -0,0 +1,15 @@ +public class DuplicateEncoder { + static String encode(String word) { + word = word.toLowerCase(); + String result = ""; + for (int i = 0; i < word.length(); i++) { + char character = word.charAt(i); + if (word.indexOf(character) != word.lastIndexOf(character)) { + result += ")"; + } else { + result += "("; + } + } + return result; + } +} diff --git a/6kyu/equal_sides_of_an_array/solution.cs b/6kyu/equal_sides_of_an_array/solution.cs new file mode 100644 index 0000000..64a1eff --- /dev/null +++ b/6kyu/equal_sides_of_an_array/solution.cs @@ -0,0 +1,23 @@ +public class Kata +{ + public static int SumOfTheArray(int[] arr) + { + int sum = 0; + for (int i = 0, max = arr.Length; i < max; sum += arr[i++]); + return sum; + } + public static int FindEvenIndex(int[] arr) + { + int left, right; + left = 0; + right = SumOfTheArray(arr) - arr[0]; + for (int i = 1, max = arr.Length; i < max; i++) + { + left += arr[i - 1]; + right -= arr[i]; + if (left == right) return i; + } + + return -1; + } +} diff --git a/6kyu/esolang_interpreters_i/solution.swift b/6kyu/esolang_interpreters_i/solution.swift new file mode 100644 index 0000000..0bfc623 --- /dev/null +++ b/6kyu/esolang_interpreters_i/solution.swift @@ -0,0 +1,17 @@ +func interpreter(_ prog: String) -> String { + var cell = 0 + var result = "" + + for i in prog { + switch i { + case "+": + cell = (cell + 1) % 256 + case ".": + result += String(Character(Unicode.Scalar(cell)!)) + default: + break + } + } + + return result +} diff --git a/6kyu/evil_autocorrect_prank/solution.js b/6kyu/evil_autocorrect_prank/solution.js new file mode 100644 index 0000000..afc4081 --- /dev/null +++ b/6kyu/evil_autocorrect_prank/solution.js @@ -0,0 +1,12 @@ +const REGEX = new RegExp("(^|[^a-z]+)(u|you+)($|[^a-z]+)", "gi") + +function autocorrect(input){ + var result = input; + + do { + input = result; + result = result.replace(REGEX, "$1your sister$3"); + } while (result != input); + + return result; +} diff --git a/6kyu/fat_fingers/solution.py b/6kyu/fat_fingers/solution.py new file mode 100644 index 0000000..54bb94b --- /dev/null +++ b/6kyu/fat_fingers/solution.py @@ -0,0 +1,19 @@ +def fat_fingers(string): + if string == "": + return "" + + result = "" + caps = False + + for letter in string[0:]: + if letter == 'A' or letter == 'a': + caps = not caps + elif caps: + if letter.isupper(): + result += letter.lower() + else: + result += letter.upper() + else: + result += letter + + return result diff --git a/6kyu/find_the_missing_letter/solution.java b/6kyu/find_the_missing_letter/solution.java new file mode 100644 index 0000000..c617515 --- /dev/null +++ b/6kyu/find_the_missing_letter/solution.java @@ -0,0 +1,12 @@ +public class Kata { + public static char findMissingLetter(char[] array) { + int last = (int)array[0]; + for (int i = 1; i < array.length; i++) + if ((int)array[i] != last + 1) { + return (char) (last + 1); + } else { + last++; + } + return (char) -1; + } +} diff --git a/6kyu/find_the_missing_term_in_arith_prog/solution.py b/6kyu/find_the_missing_term_in_arith_prog/solution.py new file mode 100644 index 0000000..b47933f --- /dev/null +++ b/6kyu/find_the_missing_term_in_arith_prog/solution.py @@ -0,0 +1,17 @@ +def find_missing(sequence): + # Relation => a_n - a_(n-1) = d + + diffs = [] + + for i in range(len(sequence) - 1): + diffs.append(sequence[i + 1] - sequence[i]) + + max_diff = diffs[0] + + for index, diff in enumerate(diffs[1:], 1): + if abs(diff) > abs(max_diff): + return sequence[index] + max_diff + elif abs(max_diff) > abs(diff): + return sequence[0] + diff + + raise ValueError() diff --git a/6kyu/find_the_odd_int/solution.cs b/6kyu/find_the_odd_int/solution.cs new file mode 100644 index 0000000..b5860df --- /dev/null +++ b/6kyu/find_the_odd_int/solution.cs @@ -0,0 +1,28 @@ +using System; + +namespace Solution +{ + class Kata + { + public static int find_it(int[] seq) + { + Array.Sort(seq); + + int count = 1; + + for (int i = 1; i < seq.Length; i++) + { + if (seq[i] == seq[i - 1]) count++; + else + { + if (count % 2 == 1) return seq[i - 1]; + else count = 1; + } + } + + if (count % 2 == 1) return seq[seq.Length - 1]; + + return -1; + } + } +} diff --git a/6kyu/find_the_unique_number/solution.py b/6kyu/find_the_unique_number/solution.py new file mode 100644 index 0000000..44e5135 --- /dev/null +++ b/6kyu/find_the_unique_number/solution.py @@ -0,0 +1,16 @@ +def find_uniq(arr): + a = arr[0] + count_a = 1 + b = None + count_b = 0 + + for e in arr[1:]: + if e != a: + count_b += 1 + b = e + else: + count_a += 1 + if count_a < count_b: + return a + else: + return b diff --git a/6kyu/give_me_a_diamond/solution.swift b/6kyu/give_me_a_diamond/solution.swift new file mode 100644 index 0000000..59b0a3f --- /dev/null +++ b/6kyu/give_me_a_diamond/solution.swift @@ -0,0 +1,23 @@ +func diamond(_ size: Int) -> String? { + if size < 0 || size % 2 == 0 { + return nil + } + + var result = "" + var (count, diff) = (1, 2) + + while count > 0 { + print(count, diff) + result += String(repeating: " ", count: (size - count) / 2) + result += String(repeating: "*", count: count) + result += "\n" + + if count == size { + diff = -2 + } + + count += diff + } + + return result +} diff --git a/6kyu/halloween_trick_or_treat/solution.js b/6kyu/halloween_trick_or_treat/solution.js new file mode 100644 index 0000000..6b221aa --- /dev/null +++ b/6kyu/halloween_trick_or_treat/solution.js @@ -0,0 +1,27 @@ +function trickOrTreat(children,candies){ + if (candies.length != children) { + return "Trick or treat!"; + } + + let lastCount = -1; + for (let packet of candies) { + let count = 0; + for (let e of packet) { + if (e == "bomb") { + return "Trick or treat!"; + } else if (e == "candy") { + count++; + } + } + + if (lastCount == -1) { + lastCount = count; + } + + if (count < 2 || lastCount != count) { + return "Trick or treat!"; + } + } + + return "Thank you, strange uncle!"; +} diff --git a/6kyu/help_the_bookseller/solution.rs b/6kyu/help_the_bookseller/solution.rs new file mode 100644 index 0000000..f6137cc --- /dev/null +++ b/6kyu/help_the_bookseller/solution.rs @@ -0,0 +1,35 @@ +use std::collections::HashMap; + +fn stock_list(list_art: Vec<&str>, list_cat: Vec<&str>) -> String { + if list_art.is_empty() || list_cat.is_empty() { + return "".to_string(); + } + + let mut map: HashMap<&str, i32> = HashMap::new(); + + // Initialize with zero values + for cat in &list_cat { + map.insert(cat, 0); + } + + // Iterate through art + for art in &list_art { + for cat in &list_cat { + if art.starts_with(cat) { + let v: Vec<&str> = art.split_terminator(' ').collect(); + let count: i32 = v[1].parse().unwrap(); + map.insert(cat, map[cat] + count); + } + } + } + + // Get result string + list_cat + .iter() + .map( + |category| format!("({} : {})", category, map[category]) + ) + .collect::>() + .as_slice() + .join(" - ") +} diff --git a/6kyu/highest_scoring_word/solution.py b/6kyu/highest_scoring_word/solution.py new file mode 100644 index 0000000..85726fc --- /dev/null +++ b/6kyu/highest_scoring_word/solution.py @@ -0,0 +1,13 @@ +from functools import reduce + +def high(x): + x = x.split() + h = reduce(lambda total, char: total + ord(char) - 96, x[0], 0) + hw = x[0] + + for word in x[1:]: + total = reduce(lambda total, char: total + ord(char) - 96, word, 0) + if total > h: + h = total + hw = word + return hw diff --git a/6kyu/ip_validation/solution.c b/6kyu/ip_validation/solution.c new file mode 100644 index 0000000..3fdd1db --- /dev/null +++ b/6kyu/ip_validation/solution.c @@ -0,0 +1,21 @@ +#include + +int is_valid_ip(const char * addr) { + int seg[4]; + + if (sscanf(addr, "%d.%d.%d.%d", &seg[0], &seg[1], &seg[2], &seg[3]) != 4) return 0; + + for (size_t i = 0; i < 4; i++) if (seg[i] <= 0 || seg[i] > 255) return 0; + + int count = 0; + + for (size_t i = 0; addr[i] != '\0'; i++) + { + if (addr[i] == '.') count++; + if ((addr[i] == '.' && addr[i + 1] == '0') || addr[i] == ' ') return 0; + } + + if (count != 3) return 0; + + return 1; +} diff --git a/6kyu/irreducible_sum_of_rationals/solution.rs b/6kyu/irreducible_sum_of_rationals/solution.rs new file mode 100644 index 0000000..26a2cb0 --- /dev/null +++ b/6kyu/irreducible_sum_of_rationals/solution.rs @@ -0,0 +1,28 @@ +fn gcd(mut a: i64, mut b: i64) -> i64 { + while b != 0 { + let t = b; + b = a % b; + a = t; + } + + a +} + +fn lcm(a: i64, b: i64) -> i64 { + (a*b).abs() / gcd(a, b) +} + +fn sum_fracts(l: Vec<(i64, i64)>) -> Option<(i64, i64)> { + if l.is_empty() { + return None; + } + + let denom = l.iter().fold(1, |a, b| lcm(a, b.1)); + + let (num, den) = l.iter().fold((0, denom), |runner, frac| + (runner.0 + (frac.0 * denom / frac.1), denom) + ); + + let divisor = gcd(num, den); + Some((num / divisor, den / divisor)) +} diff --git a/6kyu/is_a_number_prime/solution.py b/6kyu/is_a_number_prime/solution.py new file mode 100644 index 0000000..1f21b68 --- /dev/null +++ b/6kyu/is_a_number_prime/solution.py @@ -0,0 +1,16 @@ +import math + +def is_prime(num): + if num <= 1: + return False + elif num == 2: + return True + elif num % 2 == 0: + return False + + bound = int(math.ceil(math.sqrt(num))) + + for div in range(3, bound + 1, 2): + if num % div == 0: + return False + return True diff --git a/6kyu/length_of_missing_array/solution.cs b/6kyu/length_of_missing_array/solution.cs new file mode 100644 index 0000000..256560b --- /dev/null +++ b/6kyu/length_of_missing_array/solution.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Linq; + +public class Kata { + public static int GetLengthOfMissingArray(object[][] arrayOfArrays) { + if (arrayOfArrays == null || arrayOfArrays.GetLength(0) < 2) return 0; + var lengths = new HashSet(); + + foreach (var array in arrayOfArrays) { + if (array == null) return 0; + var size = array.GetLength(0); + if (size == 0) return 0; + else lengths.Add(size); + } + + var max = lengths.Max(); + var min = lengths.Min(); + + return (int) (0.5 * (arrayOfArrays.GetLength(0) + 1) * (max + min) - lengths.Sum()); + } +} diff --git a/6kyu/linked_lists_length_count/solution.cpp b/6kyu/linked_lists_length_count/solution.cpp new file mode 100644 index 0000000..52495e8 --- /dev/null +++ b/6kyu/linked_lists_length_count/solution.cpp @@ -0,0 +1,28 @@ +/* Node Definition +struct Node { + Node * next; + int data; +} +*/ + +int Length(Node *head) +{ + int count = 0; + while (head != NULL) { + count++; + head = head->next; + } + return count; +} + +int Count(Node *head, int data) +{ + int count = 0; + + while (head != NULL) { + if (head->data == data) count++; + head = head->next; + } + + return count; +} diff --git a/6kyu/lotto_6_aus_49/solution.cs b/6kyu/lotto_6_aus_49/solution.cs new file mode 100644 index 0000000..33faf94 --- /dev/null +++ b/6kyu/lotto_6_aus_49/solution.cs @@ -0,0 +1,55 @@ +using System; +using System.Linq; + +public class LOTTO { + private static Random r = new Random(); + + public static int[] NumberGenerator() { + var result = new int[7]; + result[6] = 50; + + for (var i = 0; i < 6; i++) { + var number = 0; + do { + number = r.Next(1, 50); + } while (result.Contains(number)); + result[i] = number; + } + Array.Sort(result); + result[6] = r.Next(0, 10); + + return result; + } + + public static int CheckForWinningCategory(int[] checkCombination, int[] winningCombination) { + var count = 0; + var superzahl = checkCombination.Last() == winningCombination.Last(); + + for (var i = 0; i < 6; i++) { + var index = Array.IndexOf(checkCombination, winningCombination[i]); + if (index != -1 && index != 6) count++; + } + + var result = -1; + + switch (count) { + case 6: + result = 2; + break; + case 5: + result = 4; + break; + case 4: + result = 6; + break; + case 3: + result = 8; + break; + } + + if (count == 2 && superzahl) result = 9; + else if (superzahl && result != -1) result--; + + return result; + } +} diff --git a/6kyu/make_the_deadfish_swim/solution.hs b/6kyu/make_the_deadfish_swim/solution.hs new file mode 100644 index 0000000..2756b9b --- /dev/null +++ b/6kyu/make_the_deadfish_swim/solution.hs @@ -0,0 +1,10 @@ +module Kata.Deadfish (parse) where + +parse :: String -> [Int] +parse = snd . foldl exec (0, []) + where exec (value, output) cmd = case cmd of + 'i' -> (value + 1, output) + 'd' -> (value - 1, output) + 's' -> (value * value, output) + 'o' -> (value, output ++ [value]) + _ -> (value, output) diff --git a/6kyu/multiples_of_3_or_5/solution.hs b/6kyu/multiples_of_3_or_5/solution.hs new file mode 100644 index 0000000..24e6813 --- /dev/null +++ b/6kyu/multiples_of_3_or_5/solution.hs @@ -0,0 +1,7 @@ +module MultiplesOf3And5 where + +sumOfMultiples :: Integer -> Integer -> Integer +sumOfMultiples n upTo = div ((div (upTo - 1) n) * (n + (upTo - 1 - mod (upTo - 1) n))) 2 + +solution :: Integer -> Integer +solution number = sumOfMultiples 3 number + sumOfMultiples 5 number - sumOfMultiples 15 number diff --git a/6kyu/multiplication_table/solution.go b/6kyu/multiplication_table/solution.go new file mode 100644 index 0000000..29ba966 --- /dev/null +++ b/6kyu/multiplication_table/solution.go @@ -0,0 +1,16 @@ +package multiplicationtable + +func MultiplicationTable(size int) [][]int { + result := make([][]int, size); + for i := 0; i < size; i++ { + result[i] = make([]int, size); + } + + for i := 0; i < size; i++ { + for j := 0; j < size; j++ { + result[i][j] = (i + 1) * (j + 1); + } + } + + return result; +} diff --git a/6kyu/parabolic_arc_length/solution.rs b/6kyu/parabolic_arc_length/solution.rs new file mode 100644 index 0000000..25d0b3e --- /dev/null +++ b/6kyu/parabolic_arc_length/solution.rs @@ -0,0 +1,20 @@ +fn len_curve_of(f: F, from: f64, to: f64, n: i32) -> f64 +where + F: Fn(f64) -> f64, +{ + let dx = (to - from) / n as f64; + let dx2 = dx * dx; + + (0..n) + .map(|i| { + let left = f(from + i as f64 * dx); + let right = f(from + (i + 1) as f64 * dx); + + (dx2 + (left - right).abs().powf(2.0)).sqrt() + }) + .sum() +} + +pub fn len_curve(n: i32) -> f64 { + len_curve_of(|x| x * x, 0.0, 1.0, n) +} diff --git a/6kyu/pascals_triangle/solution.hs b/6kyu/pascals_triangle/solution.hs new file mode 100644 index 0000000..33d0bc9 --- /dev/null +++ b/6kyu/pascals_triangle/solution.hs @@ -0,0 +1,7 @@ +module Codewars.Kata.PascalsTriangle where + +pascalsRow :: Int -> [Int] +pascalsRow n = scanl (\nCk k -> (nCk * (n - k)) `div` (k + 1)) 1 [0..n - 1] + +pascalsTriangle :: Int -> [Int] +pascalsTriangle n = concatMap pascalsRow [0..n - 1] diff --git a/6kyu/playing_with_digits/solution.kt b/6kyu/playing_with_digits/solution.kt new file mode 100644 index 0000000..5f41bb7 --- /dev/null +++ b/6kyu/playing_with_digits/solution.kt @@ -0,0 +1,16 @@ +fun getSum(n: Int, p: Int, l: Int): Int { + var result = 0 + var runningN = n + + for (q in p + l - 1 downTo p) { + result += Math.pow(runningN.rem(10).toDouble(), q.toDouble()).toInt() + runningN /= 10 + } + + return result +} + +fun digPow(n: Int, p: Int): Int { + val sum = getSum(n, p, n.toString().length) + return if (sum.rem(n) == 0) sum.div(n) else -1 +} diff --git a/6kyu/pyramid_array/solution.hs b/6kyu/pyramid_array/solution.hs new file mode 100644 index 0000000..267c15d --- /dev/null +++ b/6kyu/pyramid_array/solution.hs @@ -0,0 +1,4 @@ +module Kata where + +pyramid :: Int -> [[Int]] +pyramid n = [[1 | _ <- [1..i]] | i <- [1..n]] diff --git a/6kyu/rectangle_into_squares/solution.cs b/6kyu/rectangle_into_squares/solution.cs new file mode 100644 index 0000000..9787cfe --- /dev/null +++ b/6kyu/rectangle_into_squares/solution.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; + +public class SqInRect { + public static List sqInRect(int lng, int wdth) { + if (lng == wdth) return null; + + List result = new List(); + + while (lng > 0 && wdth > 0) { + if (lng < wdth) { + int a = lng; + result.Add(a); + lng = wdth - a; + wdth = a; + } else { + int a = wdth; + result.Add(a); + wdth = lng - a; + lng = a; + } + } + + return result; + } +} diff --git a/6kyu/roman_numerals_decoder/solution.cs b/6kyu/roman_numerals_decoder/solution.cs new file mode 100644 index 0000000..5c43d4a --- /dev/null +++ b/6kyu/roman_numerals_decoder/solution.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; + +public class RomanDecode { + private static Dictionary values = new Dictionary() { + { 'I', 1 }, + { 'V', 5 }, + { 'X', 10 }, + { 'L', 50 }, + { 'C', 100 }, + { 'D', 500 }, + { 'M', 1000 } + }; + + public static int Solution(string roman) { + int result = 0; + var i = roman.Length - 1; + while (i > 0) { + var val1 = values[roman[i]]; + var val2 = values[roman[i - 1]]; + if (val1 > val2) { + result += val1 - val2; + i -= 2; + } else { + result += val1; + i--; + } + Console.WriteLine(result); + } + if (i > -1) { + result += values[roman[i]]; + } + return result; + } +} diff --git a/6kyu/roman_numerals_encoder/solution.cs b/6kyu/roman_numerals_encoder/solution.cs new file mode 100644 index 0000000..afc0d08 --- /dev/null +++ b/6kyu/roman_numerals_encoder/solution.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +public class RomanConvert +{ + private static Dictionary values = new Dictionary() { + { 1, "I" }, + { 4, "IV" }, + { 5, "V" }, + { 9, "IX" }, + { 10, "X" }, + { 40, "XL" }, + { 50, "L" }, + { 90, "XC" }, + { 100, "C" }, + { 400, "CD" }, + { 500, "D" }, + { 900, "CM" }, + { 1000, "M" } + }; + + public static string Solution(int n) + { + var result = ""; + + var keys = values.Keys.Reverse(); + + foreach (var key in keys) { + while (n / key > 0) { + result += values[key]; + n -= key; + } + } + + return result; + } +} diff --git a/6kyu/rpn_calculator/solution.js b/6kyu/rpn_calculator/solution.js new file mode 100644 index 0000000..ebd5686 --- /dev/null +++ b/6kyu/rpn_calculator/solution.js @@ -0,0 +1,32 @@ +function calc(expr) { + expr = expr.split(' '); + + let stack = []; + + for (let token of expr) { + if (token == '+' || token == '-' || token == '*' || token == '/') { + let op2 = stack.pop(); + let op1 = stack.pop(); + let result; + + switch (token) { + case '-': + op2 = -op2; + case '+': + result = op1 + op2; + break; + case '/': + op2 = 1 / op2; + case '*': + result = op1 * op2; + break; + } + stack.push(result); + + } else { + stack.push(Number(token)); + } + } + + return stack.pop(); +} diff --git a/6kyu/simple_substitution_cipher_helper/solution.rs b/6kyu/simple_substitution_cipher_helper/solution.rs new file mode 100644 index 0000000..3172457 --- /dev/null +++ b/6kyu/simple_substitution_cipher_helper/solution.rs @@ -0,0 +1,39 @@ +pub struct Cipher { + decoded: Vec, + encoded: Vec, +} + +impl Cipher { + pub fn new(map1: &str, map2: &str) -> Cipher { + Cipher { + decoded: map1.as_bytes().to_vec(), + encoded: map2.as_bytes().to_vec(), + } + } + + pub fn encode(&self, string: &str) -> String { + String::from_utf8( + string + .bytes() + .map(|c| match self.decoded.iter().position(|x| x == &c) { + Some(i) => self.encoded[i], + None => c, + }) + .collect::>(), + ) + .unwrap() + } + + pub fn decode(&self, string: &str) -> String { + String::from_utf8( + string + .bytes() + .map(|c| match self.encoded.iter().position(|x| x == &c) { + Some(i) => self.decoded[i], + None => c, + }) + .collect::>(), + ) + .unwrap() + } +} diff --git a/6kyu/split_strings/solution.py b/6kyu/split_strings/solution.py new file mode 100644 index 0000000..f1e04a1 --- /dev/null +++ b/6kyu/split_strings/solution.py @@ -0,0 +1,16 @@ +def solution(s): + if len(s) == 0: + return [] + elif len(s) % 2 == 1: + s += "_" + arr = [] + index = -1 + + for i, letter in enumerate(s): + if i % 2 == 0: + index += 1 + arr.append(letter) + else: + arr[index] += letter + + return arr diff --git a/6kyu/statistics_for_an_athletic_association/solution.cpp b/6kyu/statistics_for_an_athletic_association/solution.cpp new file mode 100644 index 0000000..f2219e4 --- /dev/null +++ b/6kyu/statistics_for_an_athletic_association/solution.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include +#include +#include + +class Stat +{ + unsigned int h; + unsigned int m; + unsigned int s; + + public: + static std::string stat(const std::string &strg); + + Stat(const std::string &strg); + Stat(unsigned int seconds); + unsigned int get_seconds() const; + friend std::ostream &operator<<(std::ostream &out, const Stat &s); + bool operator<(const Stat &s); +}; + +std::string Stat::stat(const std::string &strg) +{ + std::vector stats; + std::string buffer; + + for (const char &c : strg) + { + if (c == ' ') + continue; + else if (c == ',') + { + stats.push_back(Stat(buffer)); + buffer = ""; + } + else + buffer += c; + } + + stats.push_back(Stat(buffer)); + + std::sort(stats.begin(), stats.end(), [](Stat a, Stat b) { + return a.get_seconds() < b.get_seconds(); + }); + + unsigned int seconds; + + seconds = stats.back().get_seconds() - stats.front().get_seconds(); + Stat range(seconds); + + seconds = std::accumulate(stats.begin(), stats.end(), 0u, + [](unsigned int r, Stat s) { + return r + s.get_seconds(); + }); + + Stat average(seconds / stats.size()); + + if (stats.size() % 2 == 1) + { + seconds = stats[stats.size() / 2].get_seconds(); + } + else + { + size_t index = stats.size() / 2; + seconds = (stats[index].get_seconds() + stats[index - 1].get_seconds()) / 2; + } + Stat median(seconds); + + std::stringstream result; + + result << "Range: " << range << " Average: " << average << " Median: " << median; + + return result.str(); +} + +Stat::Stat(const std::string &strg) +{ + char delimiter; + std::stringstream ss(strg); + ss >> this->h >> delimiter >> this->m >> delimiter >> this->s; +} + +Stat::Stat(unsigned int seconds) +{ + this->h = seconds / 3600; + seconds %= 3600; + this->m = seconds / 60; + this->s = seconds % 60; +} + +unsigned int Stat::get_seconds() const +{ + return this->h * 3600 + this->m * 60 + this->s; +} + +std::ostream &operator<<(std::ostream &out, const Stat &s) +{ + out << std::setfill('0') << std::setw(2) << s.h << "|"; + out << std::setfill('0') << std::setw(2) << s.m << "|"; + out << std::setfill('0') << std::setw(2) << s.s; + return out; +} diff --git a/6kyu/stop_gninnips_my_sdrow/solution.cs b/6kyu/stop_gninnips_my_sdrow/solution.cs new file mode 100644 index 0000000..f9c9458 --- /dev/null +++ b/6kyu/stop_gninnips_my_sdrow/solution.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using System.Linq; +using System; + +public class Kata +{ + public static string SpinWords(string sentence) + { + string[] words = sentence.Split(' '); + string result = ""; + + foreach (string word in words) + { + if (word.Length >= 5) + { + result += new string(word.ToCharArray().Reverse().ToArray()) + " "; + } + else result += word + " "; + } + return result.Trim(); + } +} diff --git a/6kyu/sum_of_digits__digital_root/solution.hs b/6kyu/sum_of_digits__digital_root/solution.hs new file mode 100644 index 0000000..087c32c --- /dev/null +++ b/6kyu/sum_of_digits__digital_root/solution.hs @@ -0,0 +1,5 @@ +module DigitalRoot where + +digitalRoot :: Integral a => a -> a +digitalRoot 0 = 0 +digitalRoot n = if n `mod` 9 == 0 then 9 else n `mod` 9 diff --git a/6kyu/take_a_ten_minute_walk/solution.hs b/6kyu/take_a_ten_minute_walk/solution.hs new file mode 100644 index 0000000..64fdd1e --- /dev/null +++ b/6kyu/take_a_ten_minute_walk/solution.hs @@ -0,0 +1,10 @@ +module Codewars.Kata.TenMinuteWalk where + +isValidWalk :: [Char] -> Bool +isValidWalk walk = (length . take 11) walk == 10 && (0, 0) == foldl change (0, 0) walk + where change (x, y) d = case d of + 'n' -> (x, y + 1) + 's' -> (x, y - 1) + 'e' -> (x + 1, y) + 'w' -> (x - 1, y) + _ -> error "invalid move" diff --git a/6kyu/the_supermarket_queue/solution.cs b/6kyu/the_supermarket_queue/solution.cs new file mode 100644 index 0000000..f89ee48 --- /dev/null +++ b/6kyu/the_supermarket_queue/solution.cs @@ -0,0 +1,25 @@ +using System; + +public class Kata +{ + public static int[] FilterOutZeroes(int[] queue) => Array.FindAll(queue, e => e > 0); + + public static long QueueTime(int[] customers, int n) + { + var sum = 0l; + + while (customers.Length > 0) + { + var upTo = Math.Min(n, customers.Length); + var shortest = customers[0]; + for (var i = 1; i < upTo; i++) + if (customers[i] < shortest) shortest = customers[i]; + + sum += shortest; + for (var i = 0; i < upTo; i++) customers[i] -= shortest; + customers = FilterOutZeroes(customers); + } + + return sum; + } +} diff --git a/6kyu/two_sum/solution.java b/6kyu/two_sum/solution.java new file mode 100644 index 0000000..d53d7b7 --- /dev/null +++ b/6kyu/two_sum/solution.java @@ -0,0 +1,18 @@ +import java.util.Map; +import java.util.HashMap; + +public class Solution { + public static int[] twoSum(int[] numbers, int target) { + Map encountered = new HashMap<>(); + + for (int i = 0; i < numbers.length; i++) { + Integer other = encountered.get(target - numbers[i]); + if (other != null) { + return new int[] {other, i}; + } + encountered.put(numbers[i], i); + } + + return null; // Do your magic! + } +} diff --git a/6kyu/valid_braces/solution.ts b/6kyu/valid_braces/solution.ts new file mode 100644 index 0000000..65f4ade --- /dev/null +++ b/6kyu/valid_braces/solution.ts @@ -0,0 +1,23 @@ +export function validBraces(braces: string): boolean { + let stack: string[] = []; + + for (let b of braces) { + switch (b) { + case "(": + stack.push(")"); + break; + case "[": + stack.push("]"); + break; + case "{": + stack.push("}"); + break; + default: + if (stack.length == 0 || stack.pop() != b) { + return false; + } + } + } + + return stack.length == 0; +} diff --git a/6kyu/who_likes_it/solution.cs b/6kyu/who_likes_it/solution.cs new file mode 100644 index 0000000..f02e439 --- /dev/null +++ b/6kyu/who_likes_it/solution.cs @@ -0,0 +1,29 @@ +using System; + +public static class Kata +{ + public static string Likes(string[] name) + { + var prefix = ""; + switch (name.Length) { + case 0: + prefix = "no one"; + break; + case 1: + prefix = name[0]; + break; + case 2: + prefix = String.Join(" and ", name); + break; + case 3: + prefix = String.Join(", ", name, 0, 2) + " and " + name[2]; + break; + default: + prefix = String.Join(", ", name, 0, 2) + String.Format(" and {0} others", name.Length - 2); + break; + } + + if (name.Length <= 1) return prefix + " likes this"; + else return prefix + " like this"; + } +} diff --git a/6kyu/word_a10n/solution.cs b/6kyu/word_a10n/solution.cs new file mode 100644 index 0000000..cc1c813 --- /dev/null +++ b/6kyu/word_a10n/solution.cs @@ -0,0 +1,32 @@ +using System; + +public class Abbreviator +{ + public static string Abbreviate(string input) + { + string result = "", temp = ""; + + for (int i = 0; i < input.Length; i++) + { + if (Char.IsLetter(input[i])) + temp += input[i]; + else + { + if (temp.Length <= 3) result += temp + input[i]; + else + { + result += temp[0] + (temp.Length - 2).ToString() + temp[temp.Length - 1] + input[i]; + } + temp = ""; + } + } + + if (temp.Length <= 3) result += temp; + else + { + result += temp[0] + (temp.Length - 2).ToString() + temp[temp.Length - 1]; + } + + return result; + } +} diff --git a/6kyu/your_order_please/solution.py b/6kyu/your_order_please/solution.py new file mode 100644 index 0000000..1cbfb26 --- /dev/null +++ b/6kyu/your_order_please/solution.py @@ -0,0 +1,12 @@ +def order(sentence): + arr = sentence.split(' ') + result = '' + count = 1 + for i in range(len(arr)): + for j in range(len(arr)): + if str(count) in arr[j]: + result += arr[j] + ' ' + del arr[j] + count += 1 + break + return result.strip() diff --git a/7kyu/anagram_detection/solution.py b/7kyu/anagram_detection/solution.py new file mode 100644 index 0000000..dcca6a6 --- /dev/null +++ b/7kyu/anagram_detection/solution.py @@ -0,0 +1,2 @@ +def is_anagram(test, original): + return sorted(list(test.lower())) == sorted(list(original.lower())) diff --git a/7kyu/are_the_numbers_in_order/solution.cpp b/7kyu/are_the_numbers_in_order/solution.cpp new file mode 100644 index 0000000..47292ce --- /dev/null +++ b/7kyu/are_the_numbers_in_order/solution.cpp @@ -0,0 +1,7 @@ +bool isAscOrder(std::vector arr) +{ + for (int i = 0, length = arr.size() - 1; i < length; i++) + if (arr[i] > arr[i + 1]) + return false; + return true; +} diff --git a/7kyu/beginner_series_iii/solution.cs b/7kyu/beginner_series_iii/solution.cs new file mode 100644 index 0000000..00208a6 --- /dev/null +++ b/7kyu/beginner_series_iii/solution.cs @@ -0,0 +1,14 @@ +using System; +public class Sum +{ + public int GetSum(int a, int b) + { + if (a > b) { + var temp = a; + a = b; + b = temp; + } + + return (a + b) * (Math.Abs(b - a) + 1) / 2; + } +} diff --git a/7kyu/binary_addition/solution.cs b/7kyu/binary_addition/solution.cs new file mode 100644 index 0000000..17360d7 --- /dev/null +++ b/7kyu/binary_addition/solution.cs @@ -0,0 +1,17 @@ +using System; + +public static class Kata +{ + public static string AddBinary(int a, int b) + { + var sum = a + b; + var result = ""; + + while (sum > 0) { + result = $"{sum % 2}" + result; + sum /= 2; + } + + return result; + } +} diff --git a/7kyu/bumps_in_the_road/solution.py b/7kyu/bumps_in_the_road/solution.py new file mode 100644 index 0000000..b58dee9 --- /dev/null +++ b/7kyu/bumps_in_the_road/solution.py @@ -0,0 +1,8 @@ +def bumps(road): + count = 0 + for part in road: + if part == "n": + count += 1 + if count > 15: + return "Car Dead" + return "Woohoo!" diff --git a/7kyu/categorize_new_member/solution.js b/7kyu/categorize_new_member/solution.js new file mode 100644 index 0000000..20376ef --- /dev/null +++ b/7kyu/categorize_new_member/solution.js @@ -0,0 +1,12 @@ +function openOrSenior(data){ + let result = []; + + for (let pair of data) { + if (pair[0] >= 55 && pair[1] > 7) + result.push("Senior"); + else + result.push("Open"); + } + + return result; +} diff --git a/7kyu/complementary_dna/solution.kt b/7kyu/complementary_dna/solution.kt new file mode 100644 index 0000000..2ab65af --- /dev/null +++ b/7kyu/complementary_dna/solution.kt @@ -0,0 +1,11 @@ +package dna + +fun makeComplement(dna : String) : String = dna.map { it -> + when (it) { + 'A' -> 'T' + 'T' -> 'A' + 'C' -> 'G' + 'G' -> 'C' + else -> it + } +}.joinToString("") diff --git a/7kyu/credit_card_mask/solution.cs b/7kyu/credit_card_mask/solution.cs new file mode 100644 index 0000000..3ad2751 --- /dev/null +++ b/7kyu/credit_card_mask/solution.cs @@ -0,0 +1,12 @@ +public static class Kata +{ + // return masked string + public static string Maskify(string cc) + { + if (cc.Length <= 4) { + return cc; + } else { + return cc.Substring(cc.Length - 4, 4).PadLeft(cc.Length, '#'); + } + } +} diff --git a/7kyu/deodorant_evaporator/solution.cs b/7kyu/deodorant_evaporator/solution.cs new file mode 100644 index 0000000..b8e92ee --- /dev/null +++ b/7kyu/deodorant_evaporator/solution.cs @@ -0,0 +1,11 @@ +public class Evaporator { + public static int evaporator(double content, double evap_per_day, double threshold) { + double c = 1, t = threshold / 100, e = 1 - evap_per_day / 100; + int i = 0; + while (c >= t) { + c *= e; + i++; + } + return i; + } +} diff --git a/7kyu/digital_cypher/solution.rs b/7kyu/digital_cypher/solution.rs new file mode 100644 index 0000000..f67637d --- /dev/null +++ b/7kyu/digital_cypher/solution.rs @@ -0,0 +1,19 @@ +fn get_ciphers(mut n: i32) -> Vec { + let mut result = Vec::new(); + + while n > 0 { + result.insert(0, n % 10); + n = n / 10; + } + + return result; +} + +fn encode(msg: String, n: i32) -> Vec { + let ciphers = get_ciphers(n); + let length = ciphers.len(); + + msg.as_bytes().iter().enumerate().map(|(i, x)| { + *x as i32 + ciphers[i % length] - 'a' as i32 + 1 + }).collect() +} diff --git a/7kyu/digital_cypher_vol_2/solution.cs b/7kyu/digital_cypher_vol_2/solution.cs new file mode 100644 index 0000000..4f3a02d --- /dev/null +++ b/7kyu/digital_cypher_vol_2/solution.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using System.Linq; + +public class Kata { + public static IEnumerable KeyToCiphers(int key) => + key.ToString().Select( + c => c - '0' + ); + + public static string Decode(int[] code, int key) { + var ciphers = KeyToCiphers(key); + var result = ""; + + for (var i = 0; i < code.Length; i++) { + result += (char) ('a' - 1 + code[i] - ciphers.ElementAt(i % ciphers.Count())); + } + + return result; + } +} diff --git a/7kyu/distributing_candies_fairly/solution.js b/7kyu/distributing_candies_fairly/solution.js new file mode 100644 index 0000000..5816a0a --- /dev/null +++ b/7kyu/distributing_candies_fairly/solution.js @@ -0,0 +1,20 @@ +function distribute(m, n) { + if (n <= 0) { + return []; + } + + let result = Array(n); + if (m <= 0) { + result.fill(0); + } else { + + result.fill(Math.floor(m / n)); + m %= n; + + for (let i = 0; i < m; i++) { + result[i]++; + } + } + + return result; +} diff --git a/7kyu/dont_give_me_five/solution.py b/7kyu/dont_give_me_five/solution.py new file mode 100644 index 0000000..2856de2 --- /dev/null +++ b/7kyu/dont_give_me_five/solution.py @@ -0,0 +1,2 @@ +def dont_give_me_five(start,end): + return len(list(filter(lambda s: not '5' in s, map(str, range(start, end + 1))))) diff --git a/7kyu/exes_and_ohs/solution.hs b/7kyu/exes_and_ohs/solution.hs new file mode 100644 index 0000000..29998a5 --- /dev/null +++ b/7kyu/exes_and_ohs/solution.hs @@ -0,0 +1,13 @@ +module Codewars.Kata.XO where + +import Data.Char + +-- | Returns true if the number of +-- Xs is equal to the number of Os +-- (case-insensitive) +xo :: String -> Bool +xo str = xs == os + where counter (x, o) 'x' = (x + 1, o) + counter (x, o) 'o' = (x, o + 1) + counter counts _ = counts + (xs, os) = foldl counter (0, 0) $ map toLower str diff --git a/7kyu/fibonacci/solution.hs b/7kyu/fibonacci/solution.hs new file mode 100644 index 0000000..0afd60c --- /dev/null +++ b/7kyu/fibonacci/solution.hs @@ -0,0 +1,4 @@ +module Fibonacci where + +fib :: Int -> Int +fib n = snd $ foldl (\(prev, curr) _ -> (curr, prev + curr)) (1, 1) [3..n] diff --git a/7kyu/find_the_divisors/solution.js b/7kyu/find_the_divisors/solution.js new file mode 100644 index 0000000..0e8ab45 --- /dev/null +++ b/7kyu/find_the_divisors/solution.js @@ -0,0 +1,17 @@ +function divisors(integer) { + let sqrt = Math.floor(Math.sqrt(integer)); + let left = [], right = []; + for (let i = 2; i <= sqrt; i++) { + if (integer % i == 0) { + left.push(i); + if (i !== integer / i) { + right.splice(0, 0, integer / i); + } + } + } + if (left.length != 0) { + return left.concat(right); + } else { + return `${integer} is prime`; + } +} diff --git a/7kyu/find_the_next_perfect_square/solution.cs b/7kyu/find_the_next_perfect_square/solution.cs new file mode 100644 index 0000000..9320fd4 --- /dev/null +++ b/7kyu/find_the_next_perfect_square/solution.cs @@ -0,0 +1,15 @@ +using System; + +public class Kata +{ + public static long FindNextSquare(long num) + { + double root = Math.Sqrt(num); + if (root - (int) root > double.Epsilon) + { + return -1; + } + + return (long) Math.Pow(Math.Round(root) + 1, 2); + } +} diff --git a/7kyu/fizz_buzz_cuckoo_clock/solution.swift b/7kyu/fizz_buzz_cuckoo_clock/solution.swift new file mode 100644 index 0000000..0874793 --- /dev/null +++ b/7kyu/fizz_buzz_cuckoo_clock/solution.swift @@ -0,0 +1,27 @@ +func parseTime(time: String) -> (Int, Int) { + let parts = time.split(separator: ":") + return (Int(parts[0])!, Int(parts[1])!) +} + +func fizzBuzzCuckooClock(_ time: String) -> String { + let (hour, minute) = parseTime(time: time) + + if minute % 15 == 0 { + if minute == 0 { + let count = hour % 12 + var result = String(repeating: "Cuckoo ", count: (count != 0) ? count : 12) + result.removeLast(1) + return result + } else if minute == 30 { + return "Cuckoo" + } + + return "Fizz Buzz" + } else if minute % 5 == 0 { + return "Buzz" + } else if minute % 3 == 0 { + return "Fizz" + } + + return "tick" +} diff --git a/7kyu/growth_of_a_population/solution.js b/7kyu/growth_of_a_population/solution.js new file mode 100644 index 0000000..4198be1 --- /dev/null +++ b/7kyu/growth_of_a_population/solution.js @@ -0,0 +1,11 @@ +function nbYear(p0, percent, aug, p) { + percent = percent / 100; + + let count = 0; + while (p0 < p) { + p0 *= 1 + percent; + p0 += aug; + count++; + } + return count; +} diff --git a/7kyu/highest_and_lowest/solution.js b/7kyu/highest_and_lowest/solution.js new file mode 100644 index 0000000..f3dabfa --- /dev/null +++ b/7kyu/highest_and_lowest/solution.js @@ -0,0 +1,11 @@ +function highAndLow(numbers){ + numbers = numbers.split(' '); + let min = parseInt(numbers[0]), + max = parseInt(numbers[0]); + for (let i = 1; i < numbers.length; i++) { + let n = parseInt(numbers[i]); + if (n < min) min = n; + else if (n > max) max = n; + } + return `${max} ${min}`; +} diff --git a/7kyu/hit_count/solution.py b/7kyu/hit_count/solution.py new file mode 100644 index 0000000..999e4ea --- /dev/null +++ b/7kyu/hit_count/solution.py @@ -0,0 +1,5 @@ +def counter_effect(hit_count): + result = [] + for num in map(int, hit_count): + result.append(list(range(num + 1))) + return result diff --git a/7kyu/inspiring_strings/solution.py b/7kyu/inspiring_strings/solution.py new file mode 100644 index 0000000..3ad889a --- /dev/null +++ b/7kyu/inspiring_strings/solution.py @@ -0,0 +1,10 @@ +def longest_word(string_of_words): + words = string_of_words.split(' ') + + result = (words[0], len(words[0])) + + for word in words: + if len(word) >= result[1]: + result = (word, len(word)) + + return result[0] diff --git a/7kyu/is_this_a_triangle/solution.cpp b/7kyu/is_this_a_triangle/solution.cpp new file mode 100644 index 0000000..91b155a --- /dev/null +++ b/7kyu/is_this_a_triangle/solution.cpp @@ -0,0 +1,17 @@ +namespace Triangle +{ + bool isTriangle(int ia, int ib, int ic) + { + long long a = ia; + long long b = ib; + long long c = ic; + + if (a == 0 || b == 0 || c == 0) return false; + else if (a == b && b == c) return true; + else if (a + b <= c) return false; + else if (a + c <= b) return false; + else if (b + c <= a) return false; + + return true; + } +} diff --git a/7kyu/isograms/solution.js b/7kyu/isograms/solution.js new file mode 100644 index 0000000..a694da2 --- /dev/null +++ b/7kyu/isograms/solution.js @@ -0,0 +1,14 @@ +function isIsogram(str){ + str = str.toLowerCase(); + let encountered = new Set(); + + for (let character of str.split('')) { + if (!encountered.has(character)) { + encountered.add(character); + } else { + return false; + } + } + + return true; +} diff --git a/7kyu/jaden_casing_strings/solution.cs b/7kyu/jaden_casing_strings/solution.cs new file mode 100644 index 0000000..6ad7e1c --- /dev/null +++ b/7kyu/jaden_casing_strings/solution.cs @@ -0,0 +1,10 @@ +using System; +using System.Linq; + +public static class JadenCase +{ + public static string ToJadenCase(this string phrase) + { + return String.Join(" ", phrase.Split(' ').Select(word => word.First().ToString().ToUpper() + word.Substring(1))); + } +} diff --git a/7kyu/list_filtering/solution.cs b/7kyu/list_filtering/solution.cs new file mode 100644 index 0000000..d018527 --- /dev/null +++ b/7kyu/list_filtering/solution.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; + +public class ListFilterer +{ + public static IEnumerable GetIntegersFromList(List listOfItems) + { + var result = new List(); + + foreach (var o in listOfItems) { + if (o is int) { + result.Add((int) o); + } + } + + return result; + } +} diff --git a/7kyu/looking_for_a_benefactor/solution.c b/7kyu/looking_for_a_benefactor/solution.c new file mode 100644 index 0000000..98724b5 --- /dev/null +++ b/7kyu/looking_for_a_benefactor/solution.c @@ -0,0 +1,14 @@ +#include +#include + +long long newAvg(double *arr, size_t szArray, double navg) +{ + double sum = 0.0; + + for (size_t i = 0; i < szArray; sum += arr[i++]); + + long long result = (long long) ceil(navg * (szArray + 1) - sum); + + if (result <= 0) return -1; + else return result; +} diff --git a/7kyu/make_a_function_that_does_arithmetic/solution.hs b/7kyu/make_a_function_that_does_arithmetic/solution.hs new file mode 100644 index 0000000..001fdf2 --- /dev/null +++ b/7kyu/make_a_function_that_does_arithmetic/solution.hs @@ -0,0 +1,10 @@ +module Kata where + +data Operation = Add | Divide | Multiply | Subtract deriving (Eq, Show, Enum, Bounded) + +arithmetic :: Fractional a => a -> a -> Operation -> a +arithmetic a b operator = case operator of + Add -> (a + b) + Divide -> (a / b) + Multiply -> (a * b) + Subtract -> (a - b) diff --git a/7kyu/maximum_length_difference/solution.rs b/7kyu/maximum_length_difference/solution.rs new file mode 100644 index 0000000..1fd5e9d --- /dev/null +++ b/7kyu/maximum_length_difference/solution.rs @@ -0,0 +1,27 @@ +use std::cmp; + +struct Extremes { + min: i128, + max: i128 +} + +fn mx_dif_lg(a1: Vec<&str>, a2: Vec<&str>) -> i32 { + if a1.len() == 0 || a2.len() == 0 { + return -1 + } + + fn mx(strings: &Vec<&str>) -> Extremes { + Extremes { + min: strings.iter().map(|&x| x.len()).min().unwrap() as i128, + max: strings.iter().map(|&x| x.len()).max().unwrap() as i128, + } + } + + let a1_extremes = mx(&a1); + let a2_extremes = mx(&a2); + + cmp::max( + (a1_extremes.min - a2_extremes.max).abs() as i32, + (a1_extremes.max - a2_extremes.min).abs() as i32 + ) +} diff --git a/7kyu/most_digits/solution.c b/7kyu/most_digits/solution.c new file mode 100644 index 0000000..e5d03fb --- /dev/null +++ b/7kyu/most_digits/solution.c @@ -0,0 +1,20 @@ +#include +#include + +int find_longest(int *numbers, size_t numbers_size) +{ + double digits = floor(log10(fabs(numbers[0]))); + int number = numbers[0]; + + for (size_t i = 1; i < numbers_size; i++) + { + double digits_now = floor(log10(fabs(numbers[i]))); + if (digits_now > digits) + { + digits = digits_now; + number = numbers[i]; + } + } + + return number; +} diff --git a/7kyu/mumbling/solution.cs b/7kyu/mumbling/solution.cs new file mode 100644 index 0000000..dd4c4cc --- /dev/null +++ b/7kyu/mumbling/solution.cs @@ -0,0 +1,19 @@ +using System; + +public class Accumul +{ + public static String Accum(string s) + { + var result = ""; + var count = 1; + + foreach (var c in s) + { + result += Char.ToUpper(c); + for (var i = 1; i < count; i++) result += Char.ToLower(c); + result += "-"; + count++; + } + return result.Trim('-'); + } +} diff --git a/7kyu/number_of_people_in_the_bus/solution.kt b/7kyu/number_of_people_in_the_bus/solution.kt new file mode 100644 index 0000000..1bcc470 --- /dev/null +++ b/7kyu/number_of_people_in_the_bus/solution.kt @@ -0,0 +1,2 @@ +fun people(busStops: Array>) : Int = + busStops.fold(0) { inBus, (gotOn, gotOff) -> inBus + gotOn - gotOff } diff --git a/7kyu/odd_or_even/solution.py b/7kyu/odd_or_even/solution.py new file mode 100644 index 0000000..3fc9ffe --- /dev/null +++ b/7kyu/odd_or_even/solution.py @@ -0,0 +1,5 @@ +def oddOrEven(arr): + if sum(arr) % 2 == 0: + return 'even' + else: + return 'odd' diff --git a/7kyu/ones_and_zeros/solution.py b/7kyu/ones_and_zeros/solution.py new file mode 100644 index 0000000..fb9cabd --- /dev/null +++ b/7kyu/ones_and_zeros/solution.py @@ -0,0 +1,2 @@ +def binary_array_to_number(arr): + return int(''.join(map(str, arr)), 2) diff --git a/7kyu/palindrome_chain_length/solution.py b/7kyu/palindrome_chain_length/solution.py new file mode 100644 index 0000000..e9b2bef --- /dev/null +++ b/7kyu/palindrome_chain_length/solution.py @@ -0,0 +1,10 @@ +def palindrome_chain_length(n): + c = 0 + r = int(str(n)[::-1]) + + while n != r: + n += r + r = int(str(n)[::-1]) + c += 1 + + return c diff --git a/7kyu/parts_of_a_list/solution.cs b/7kyu/parts_of_a_list/solution.cs new file mode 100644 index 0000000..1f57cc7 --- /dev/null +++ b/7kyu/parts_of_a_list/solution.cs @@ -0,0 +1,19 @@ +public class PartList +{ + public static string[][] Partlist(string[] arr) + { + string[][] result = new string[arr.Length - 1][]; + + for (int i = 0, upTo = arr.Length - 1; i < upTo; i++) + { + result[i] = new string[2]; + result[i][0] = ""; + for (int j = 0; j <= i; j++) result[i][0] += arr[j] + " "; + result[i][0] = result[i][0].Trim(); + result[i][1] = ""; + for (int j = i + 1; j < arr.Length; j++) result[i][1] += arr[j] + " "; + result[i][1] = result[i][1].Trim(); + } + return result; + } +} diff --git a/7kyu/pirate_code/solution.js b/7kyu/pirate_code/solution.js new file mode 100644 index 0000000..47e3b78 --- /dev/null +++ b/7kyu/pirate_code/solution.js @@ -0,0 +1,12 @@ +function amaroPlan(pirateNum){ + let total = 20 * pirateNum; + + let result = []; + result.push(total - Math.floor((pirateNum - 1) / 2)); + + for (let i = 1; i < pirateNum; i++) { + result.push((i + 1) % 2); + } + + return result; +} diff --git a/7kyu/predict_your_age/solution.kt b/7kyu/predict_your_age/solution.kt new file mode 100644 index 0000000..b022b32 --- /dev/null +++ b/7kyu/predict_your_age/solution.kt @@ -0,0 +1,5 @@ +fun predictAge(vararg ages: Int): Int = Math.floor( + Math.sqrt( + ages.sumOf { it * it }.toDouble() + ).div(2) +).toInt() diff --git a/7kyu/printer_errors/solution.php b/7kyu/printer_errors/solution.php new file mode 100644 index 0000000..dbe2f88 --- /dev/null +++ b/7kyu/printer_errors/solution.php @@ -0,0 +1,9 @@ +function printerError($s) { + $length = strlen($s); + $errors = 0; + + for ($i = 0; $i < $length; $i++) { + if ($s[$i] > 'm') $errors++; + } + return "$errors/$length"; +} diff --git a/7kyu/product_of_array_items/solution.hs b/7kyu/product_of_array_items/solution.hs new file mode 100644 index 0000000..7386bf3 --- /dev/null +++ b/7kyu/product_of_array_items/solution.hs @@ -0,0 +1,5 @@ +module Product where + +product' :: [Integer] -> Maybe Integer +product' [] = Nothing +product' xs = Just $ foldl1 (*) xs diff --git a/7kyu/regex_validate_pin_code/solution.java b/7kyu/regex_validate_pin_code/solution.java new file mode 100644 index 0000000..4214975 --- /dev/null +++ b/7kyu/regex_validate_pin_code/solution.java @@ -0,0 +1,16 @@ +public class Solution { + public static boolean validatePin(String pin) { + int length = pin.length(); + + if (length != 4 && length != 6) { + return false; + } else { + for (int i = 0; i < length; i++) { + if (!Character.isDigit(pin.charAt(i))) { + return false; + } + } + } + return true; + } +} diff --git a/7kyu/remove_the_minimum/solution.cs b/7kyu/remove_the_minimum/solution.cs new file mode 100644 index 0000000..c3305c8 --- /dev/null +++ b/7kyu/remove_the_minimum/solution.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +public class Remover +{ + public static List RemoveSmallest(List numbers) + { + if (numbers.Count == 0) return numbers; + + List new_numbers = new List(numbers); + + int lowest = new_numbers[0]; + + foreach (int e in numbers) + { + if (e < lowest) lowest = e; + } + + new_numbers.Remove(lowest); + + return new_numbers; + } +} diff --git a/7kyu/resistor_color_codes/solution.swift b/7kyu/resistor_color_codes/solution.swift new file mode 100644 index 0000000..6e3765e --- /dev/null +++ b/7kyu/resistor_color_codes/solution.swift @@ -0,0 +1,59 @@ +let COLOR_MAPPING: [String: Int] = [ + "black": 0, + "brown": 1, + "red": 2, + "orange": 3, + "yellow": 4, + "green": 5, + "blue": 6, + "violet": 7, + "gray": 8, + "white": 9 +] + +func formatOhms(_ ohms: Int) -> String { + func formatBig(n: Int, base: Int, suffix: String) -> String { + var short: String + if (n % base == 0) { + short = String(n / base) + } else { + short = String(Double(ohms) / Double(base)) + } + + return "\(short)\(suffix)" + } + + if ohms < 1000 { + return String(ohms) + } else if ohms < 1000000 { + return formatBig(n: ohms, base: 1000, suffix: "k") + } + return formatBig(n: ohms, base: 1000000, suffix: "M") +} + +func decodeResistorColors(_ bands: String) -> String { + var (ohms, tolerance) = (0, 20) + let splitBands = bands.split(separator: " ") + + for i in 0..<2 { + ohms *= 10 + ohms += COLOR_MAPPING[String(splitBands[i])]! + } + + for _ in 0.. 3 { + switch String(splitBands[3]) { + case "gold": + tolerance = 5 + case "silver": + tolerance = 10 + default: + tolerance = 20 + } + } + + return "\(formatOhms(ohms)) ohms, \(tolerance)%" +} diff --git a/7kyu/rotate_for_a_max/solution.kt b/7kyu/rotate_for_a_max/solution.kt new file mode 100644 index 0000000..9c6dba1 --- /dev/null +++ b/7kyu/rotate_for_a_max/solution.kt @@ -0,0 +1,26 @@ +package maxrot + +fun maxRot(n: Long): Long { + // keep length of n + val length = n.toString().length + var firstDigit = Math.pow(10.toDouble(), (length - 1).toDouble()).toLong() + + var number = n // keep modified n + var maxN = n // keep maximum + + // rotate left for the length of n + for (x in 0 until length) { + val highest = number.div(firstDigit).rem(10) + val remainder = number.div(firstDigit).div(10).times(firstDigit).times(10) + + number = remainder.plus(number.rem(firstDigit).times(10).plus(highest)) + firstDigit = firstDigit.div(10) + + if (number > maxN) { + maxN = number + } + } + + // return maximum + return maxN +} diff --git a/7kyu/shortest_word/solution.cs b/7kyu/shortest_word/solution.cs new file mode 100644 index 0000000..f0831b9 --- /dev/null +++ b/7kyu/shortest_word/solution.cs @@ -0,0 +1,13 @@ +public class Kata +{ + public static int FindShort(string s) + { + int shortest = s.Length; + + string[] words = s.Split(' '); + foreach (string word in words) + if (word.Length < shortest) shortest = word.Length; + + return shortest; + } +} diff --git a/7kyu/small_enough_beginner/solution.kt b/7kyu/small_enough_beginner/solution.kt new file mode 100644 index 0000000..ef28243 --- /dev/null +++ b/7kyu/small_enough_beginner/solution.kt @@ -0,0 +1 @@ +fun smallEnough(a : IntArray, limit : Int) : Boolean = a.all { it <= limit } diff --git a/7kyu/sorted_yes_no_how/solution.py b/7kyu/sorted_yes_no_how/solution.py new file mode 100644 index 0000000..d7845cf --- /dev/null +++ b/7kyu/sorted_yes_no_how/solution.py @@ -0,0 +1,8 @@ +def is_sorted_and_how(arr): + last = "ascending" if arr[0] <= arr[1] else "descending" + for i in range(1, len(arr) - 1): + if arr[i] <= arr[i + 1] and last != "ascending": + return "no" + elif arr[i] >= arr[i + 1] and last != "descending": + return "no" + return "yes, " + last diff --git a/7kyu/speed_control/solution.c b/7kyu/speed_control/solution.c new file mode 100644 index 0000000..9854e5f --- /dev/null +++ b/7kyu/speed_control/solution.c @@ -0,0 +1,20 @@ +#include + +int gps(int s, double* x, int sz) { + if (sz < 2) { + return 0; + } + + double maxDiff = x[1] - x[0]; + int maxIndex = 0; + + for (int i = 0; i < sz - 1; i++) { + double diff = x[i + 1] - x[i]; + if (diff > maxDiff) { + maxDiff = diff; + maxIndex = i; + } + } + + return floor((3600 * maxDiff) / s); +} diff --git a/7kyu/sum_of_angles/solution.cpp b/7kyu/sum_of_angles/solution.cpp new file mode 100644 index 0000000..946bea8 --- /dev/null +++ b/7kyu/sum_of_angles/solution.cpp @@ -0,0 +1,3 @@ +int angle(int n) { + return 180 * (n - 2); +} diff --git a/7kyu/sum_of_odd_numbers/solution.kt b/7kyu/sum_of_odd_numbers/solution.kt new file mode 100644 index 0000000..8117af2 --- /dev/null +++ b/7kyu/sum_of_odd_numbers/solution.kt @@ -0,0 +1,12 @@ +// How to get k-th odd number: p = 2k + 1 (zero indexed) +// Decomposition: +// 1. Find out how many odd numbers we have in front +// 2. Figure out next index +// 3. Sum those numbers + +private fun kthOdd(k: Int): Int = 2*k + 1 +private fun oddNumbersBefore(n: Int) = n.times(n + 1).div(2) + +fun rowSumOddNumbers(n: Int): Int = + (oddNumbersBefore(n - 1)..oddNumbersBefore(n) - 1) + .sumOf { kthOdd(it) } diff --git a/7kyu/sum_of_two_lowest_positive_integers/solution.cs b/7kyu/sum_of_two_lowest_positive_integers/solution.cs new file mode 100644 index 0000000..7b21669 --- /dev/null +++ b/7kyu/sum_of_two_lowest_positive_integers/solution.cs @@ -0,0 +1,26 @@ +public static class Kata +{ + public static int sumTwoSmallestNumbers(int[] numbers) + { + var smallest = new int[] {numbers[0], numbers[1]}; + + if (smallest[0] > smallest[1]) { + var temp = smallest[0]; + smallest[0] = smallest[1]; + smallest[1] = temp; + } + + for (var i = 2; i < numbers.GetLength(0); i++) { + var number = numbers[i]; + if (number < 0) continue; + else if (number < smallest[0]) { + smallest[1] = smallest[0]; + smallest[0] = number; + } else if (number < smallest[1]) { + smallest[1] = number; + } + } + + return smallest[0] + smallest[1]; + } +} diff --git a/7kyu/vowel_count/solution.cs b/7kyu/vowel_count/solution.cs new file mode 100644 index 0000000..5168e2d --- /dev/null +++ b/7kyu/vowel_count/solution.cs @@ -0,0 +1,18 @@ +using System; +using System.Linq; + +public static class Kata +{ + public static int GetVowelCount(string str) + { + int vowelCount = 0; + const string vowels = "aeiou"; + + foreach (char x in str) + { + if (vowels.Contains(x)) vowelCount++; + } + + return vowelCount; + } +} diff --git a/8kyu/a_needle_in_the_haystack/solution.cs b/8kyu/a_needle_in_the_haystack/solution.cs new file mode 100644 index 0000000..0f23170 --- /dev/null +++ b/8kyu/a_needle_in_the_haystack/solution.cs @@ -0,0 +1,15 @@ +using System; +public class Kata { + public static string FindNeedle(object[] haystack) { + var index = 0; + + foreach (var o in haystack) { + //if (o is string s && s == "needle") break; + if (o == null); + else if (o.ToString() == "needle") break; + index++; + } + + return $"found the needle at position {index}"; + } +} diff --git a/8kyu/alternating_case/solution.js b/8kyu/alternating_case/solution.js new file mode 100644 index 0000000..d3aeeb4 --- /dev/null +++ b/8kyu/alternating_case/solution.js @@ -0,0 +1,14 @@ +String.prototype.toAlternatingCase = function () { + // Define your method here :) + let result = ""; + + for (let i = 0; i < this.length; i++) { + if (this[i].toLowerCase() === this[i]) { + result += this[i].toUpperCase(); + } else { + result += this[i].toLowerCase(); + } + } + + return result; +} diff --git a/8kyu/beginner_lost_without_a_map/solution.kt b/8kyu/beginner_lost_without_a_map/solution.kt new file mode 100644 index 0000000..54fbdb2 --- /dev/null +++ b/8kyu/beginner_lost_without_a_map/solution.kt @@ -0,0 +1 @@ +fun maps(x: IntArray): IntArray = x.map { 2 * it }.toIntArray() diff --git a/8kyu/beginner_series_ii/solution.kt b/8kyu/beginner_series_ii/solution.kt new file mode 100644 index 0000000..51704b0 --- /dev/null +++ b/8kyu/beginner_series_ii/solution.kt @@ -0,0 +1 @@ +fun past(h: Int, m: Int, s: Int): Int = h.times(60).plus(m).times(60).plus(s).times(1000) diff --git a/8kyu/beginner_series_iv/solution.pas b/8kyu/beginner_series_iv/solution.pas new file mode 100644 index 0000000..74f4ef2 --- /dev/null +++ b/8kyu/beginner_series_iv/solution.pas @@ -0,0 +1,14 @@ +unit Kata; + +interface + +function CockroachSpeed(s: Real): Integer; + +implementation + +function CockroachSpeed(s: Real): Integer; +begin + Result := Trunc(250 * s / 9); +end; + +end. diff --git a/8kyu/calculate_average/solution.hs b/8kyu/calculate_average/solution.hs new file mode 100644 index 0000000..5298ff1 --- /dev/null +++ b/8kyu/calculate_average/solution.hs @@ -0,0 +1,4 @@ +module Average where + +avg :: [Float] -> Float +avg l = (sum l) / (fromIntegral $ length l) diff --git a/8kyu/century_from_year/solution.hs b/8kyu/century_from_year/solution.hs new file mode 100644 index 0000000..8099850 --- /dev/null +++ b/8kyu/century_from_year/solution.hs @@ -0,0 +1,6 @@ +module Century where + +century :: Int -> Int +century year = case year `mod` 100 of + 0 -> year `div` 100 + _ -> 1 + year `div` 100 diff --git a/8kyu/convert_boolean_values_to_strings/solution.hs b/8kyu/convert_boolean_values_to_strings/solution.hs new file mode 100644 index 0000000..a1ec95d --- /dev/null +++ b/8kyu/convert_boolean_values_to_strings/solution.hs @@ -0,0 +1,5 @@ +module YesNo where + +boolToWord :: Bool -> String +boolToWord True = "Yes" +boolToWord False = "No" diff --git a/8kyu/convert_number_to_reversed_digits/solution.cs b/8kyu/convert_number_to_reversed_digits/solution.cs new file mode 100644 index 0000000..b4ede7a --- /dev/null +++ b/8kyu/convert_number_to_reversed_digits/solution.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace Solution +{ + class Digitizer + { + public static long[] Digitize(long n) + { + long[] arr = new long[(int) Math.Log10(n + 0.5) + 1]; + + long n_tmp = n; + for (int i = 0, i_max = arr.Length; i < i_max; i++) + { + arr[i] = n_tmp % 10; + n_tmp /= 10; + } + return arr; + } + } +} diff --git a/8kyu/correct_mistakes_of_character_recognition/solution.py b/8kyu/correct_mistakes_of_character_recognition/solution.py new file mode 100644 index 0000000..472d79b --- /dev/null +++ b/8kyu/correct_mistakes_of_character_recognition/solution.py @@ -0,0 +1,2 @@ +def correct(string): + return string.replace('5', 'S').replace('0', 'O').replace('1', 'I') diff --git a/8kyu/count_the_monkeys/solution.java b/8kyu/count_the_monkeys/solution.java new file mode 100644 index 0000000..6d73a12 --- /dev/null +++ b/8kyu/count_the_monkeys/solution.java @@ -0,0 +1,8 @@ +public class MonkeyCounter { + public static int[] monkeyCount(final int n) { + int[] result = new int[n]; + for (int i = 0; i < n; i++) + result[i] = i+1; + return result; + } +} diff --git a/8kyu/counting_sheep/solution.cpp b/8kyu/counting_sheep/solution.cpp new file mode 100644 index 0000000..d8ed790 --- /dev/null +++ b/8kyu/counting_sheep/solution.cpp @@ -0,0 +1,9 @@ +sing namespace std; + +int count_sheep(vector arr) +{ + int count = 0; + for (const bool e : arr) + if (e) count++; + return count; +} diff --git a/8kyu/difference_of_volumes_of_cuboids/solution.rs b/8kyu/difference_of_volumes_of_cuboids/solution.rs new file mode 100644 index 0000000..c9784cf --- /dev/null +++ b/8kyu/difference_of_volumes_of_cuboids/solution.rs @@ -0,0 +1,3 @@ +fn find_difference(a: &[i32; 3], b: &[i32; 3]) -> i32 { + (a.iter().product::() - b.iter().product::()).abs() +} diff --git a/8kyu/enumerable_magic_iii/solution.cs b/8kyu/enumerable_magic_iii/solution.cs new file mode 100644 index 0000000..ee29708 --- /dev/null +++ b/8kyu/enumerable_magic_iii/solution.cs @@ -0,0 +1,11 @@ +public class Kata +{ + public static bool Include(int[] arr, int item) + { + foreach (var e in arr) { + if (e == item) return true; + } + + return false; + } +} diff --git a/8kyu/even_or_odd/solution.hs b/8kyu/even_or_odd/solution.hs new file mode 100644 index 0000000..4de4058 --- /dev/null +++ b/8kyu/even_or_odd/solution.hs @@ -0,0 +1,4 @@ +module EvenOrOdd where + +evenOrOdd :: Integral a => a -> [Char] +evenOrOdd n = if (mod n 2) == 0 then "Even" else "Odd" diff --git a/8kyu/exclamation_marks/solution.cs b/8kyu/exclamation_marks/solution.cs new file mode 100644 index 0000000..ef155b7 --- /dev/null +++ b/8kyu/exclamation_marks/solution.cs @@ -0,0 +1,7 @@ +public class Kata +{ + public static string Remove(string s) + { + return s.Replace("!", "") + "!"; + } +} diff --git a/8kyu/fake_binary/solution.c b/8kyu/fake_binary/solution.c new file mode 100644 index 0000000..7c59853 --- /dev/null +++ b/8kyu/fake_binary/solution.c @@ -0,0 +1,18 @@ +void fakeBin(const char *digits, char *buffer) { + char * digit = digits; + char * new_digit = buffer; + + while (*digit != '\0') { + if (*digit >= '5') { + *new_digit = '1'; + } else { + *new_digit = '0'; + } + + digit++; + new_digit++; + } + *new_digit = '\0'; + printf("%s\n", digits); + printf("%s\n", buffer); +} diff --git a/8kyu/find_the_smallest_integer_in_the_array/solution.rs b/8kyu/find_the_smallest_integer_in_the_array/solution.rs new file mode 100644 index 0000000..aaf08e2 --- /dev/null +++ b/8kyu/find_the_smallest_integer_in_the_array/solution.rs @@ -0,0 +1,3 @@ +fn find_smallest_int(arr: &[i32]) -> i32 { + *arr.iter().min().unwrap() +} diff --git a/8kyu/five_without_numbers/solution.py b/8kyu/five_without_numbers/solution.py new file mode 100644 index 0000000..521a4f0 --- /dev/null +++ b/8kyu/five_without_numbers/solution.py @@ -0,0 +1,2 @@ +def unusual_five(): + return ord('') diff --git a/8kyu/get_nth_even_number/solution.c b/8kyu/get_nth_even_number/solution.c new file mode 100644 index 0000000..a13cff0 --- /dev/null +++ b/8kyu/get_nth_even_number/solution.c @@ -0,0 +1,3 @@ +int nth_even(int n){ + return 2 * (n - 1); +} diff --git a/8kyu/get_the_mean_of_an_array/solution.c b/8kyu/get_the_mean_of_an_array/solution.c new file mode 100644 index 0000000..28d9c3f --- /dev/null +++ b/8kyu/get_the_mean_of_an_array/solution.c @@ -0,0 +1,10 @@ +#include + +int get_average(const int *marks, size_t count) +{ + int sum = 0; + + for (int i = 0; i < count; sum += marks[i++]); + + return sum / count; +} diff --git a/8kyu/grasshopper_grade_book/solution.cs b/8kyu/grasshopper_grade_book/solution.cs new file mode 100644 index 0000000..dcbf36d --- /dev/null +++ b/8kyu/grasshopper_grade_book/solution.cs @@ -0,0 +1,16 @@ +using System; + +public class Kata +{ + public static char GetGrade(int s1, int s2, int s3) + { + int sum = s1 + s2 + s3; + int avg = (int) (sum / 3.0); + + if (avg >= 90) return 'A'; + else if (avg >= 80) return 'B'; + else if (avg >= 70) return 'C'; + else if (avg >= 60) return 'D'; + else return 'F'; + } +} diff --git a/8kyu/grasshopper_personalized_message/solution.js b/8kyu/grasshopper_personalized_message/solution.js new file mode 100644 index 0000000..65d4dc1 --- /dev/null +++ b/8kyu/grasshopper_personalized_message/solution.js @@ -0,0 +1,6 @@ +function greet (name, owner) { + if (name == owner) + return "Hello boss"; + else + return "Hello guest"; +} diff --git a/8kyu/grasshopper_summation/solution.pas b/8kyu/grasshopper_summation/solution.pas new file mode 100644 index 0000000..9ca9b50 --- /dev/null +++ b/8kyu/grasshopper_summation/solution.pas @@ -0,0 +1,16 @@ +unit GrashopperSummation; + +{$mode objfpc}{$H+} + +interface + +function Summation(const N: Integer): Integer; + +implementation + +function Summation(const N: Integer): Integer; +begin + Result := N*(N + 1) div 2; +end; + +end. diff --git a/8kyu/how_many_lightsabers/solution.hs b/8kyu/how_many_lightsabers/solution.hs new file mode 100644 index 0000000..3d0b050 --- /dev/null +++ b/8kyu/how_many_lightsabers/solution.hs @@ -0,0 +1,5 @@ +module Lightsabers where + +howManyLightsabersDoYouOwn :: Num a => [Char] -> a +howManyLightsabersDoYouOwn "Zach" = 18 +howManyLightsabersDoYouOwn _ = 0 diff --git a/8kyu/is_it_a_palindrome/solution.cpp b/8kyu/is_it_a_palindrome/solution.cpp new file mode 100644 index 0000000..d4226d4 --- /dev/null +++ b/8kyu/is_it_a_palindrome/solution.cpp @@ -0,0 +1,22 @@ +#include +#include + +bool isPalindrom (const std::string& str) +{ + if (str.size() == 0) return true; + + auto i = 0; + auto j = str.size() - 1; + + std::cout << str << std::endl; + + while (i < j) + { + if (std::tolower(str[i++]) != std::tolower(str[j--])) + { + return false; + } + } + + return true; +} diff --git a/8kyu/is_the_string_uppercase/solution.c b/8kyu/is_the_string_uppercase/solution.c new file mode 100644 index 0000000..6f23980 --- /dev/null +++ b/8kyu/is_the_string_uppercase/solution.c @@ -0,0 +1,12 @@ +#include + +bool is_uppercase(const char *source) +{ + for (int i = 0; source[i] != '\0'; i++) + { + if (source[i] >= 'a' && source[i] <= 'z') + return false; + } + + return true; +} diff --git a/8kyu/jennys_secret_message/solution.java b/8kyu/jennys_secret_message/solution.java new file mode 100644 index 0000000..c67259d --- /dev/null +++ b/8kyu/jennys_secret_message/solution.java @@ -0,0 +1,8 @@ +public class Greeter { + public static String greet(String name) { + if (name.equals("Johnny")) { + return "Hello, my love!"; + } + return String.format("Hello, %s!", name); + } +} diff --git a/8kyu/keep_hydrated/solution.hs b/8kyu/keep_hydrated/solution.hs new file mode 100644 index 0000000..b7c737b --- /dev/null +++ b/8kyu/keep_hydrated/solution.hs @@ -0,0 +1,4 @@ +module Litres where + +litres :: Double -> Integer +litres d = floor (d * 0.5) diff --git a/8kyu/make_upper_case/solution.py b/8kyu/make_upper_case/solution.py new file mode 100644 index 0000000..29ef94e --- /dev/null +++ b/8kyu/make_upper_case/solution.py @@ -0,0 +1,5 @@ +def make_upper_case(s): + result = "" + for char in s: + result += char.upper() + return result diff --git a/8kyu/multiply/solution.cpp b/8kyu/multiply/solution.cpp new file mode 100644 index 0000000..d2cf8d7 --- /dev/null +++ b/8kyu/multiply/solution.cpp @@ -0,0 +1,4 @@ +int multiply(int a, int b) +{ + return a * b; +} diff --git a/8kyu/opposite_number/solution.hs b/8kyu/opposite_number/solution.hs new file mode 100644 index 0000000..5e0e5c4 --- /dev/null +++ b/8kyu/opposite_number/solution.hs @@ -0,0 +1,4 @@ +module Codewars.Kata.Opposite where + +opposite :: Num a => a -> a +opposite num = - num diff --git a/8kyu/opposites_attract/solution.kt b/8kyu/opposites_attract/solution.kt new file mode 100644 index 0000000..f21c88d --- /dev/null +++ b/8kyu/opposites_attract/solution.kt @@ -0,0 +1 @@ +fun loveFun(flowerA: Int, flowerB: Int): Boolean = flowerA.xor(flowerB).and(1) != 0 diff --git a/8kyu/parse_nice_int_from_char/solution.c b/8kyu/parse_nice_int_from_char/solution.c new file mode 100644 index 0000000..9c198ab --- /dev/null +++ b/8kyu/parse_nice_int_from_char/solution.c @@ -0,0 +1,5 @@ +int getAge(const char *inputString) +{ + // return correct age (int). Happy coding :) + return (int) inputString[0] - 48; +} diff --git a/8kyu/remove_first_and_last_character/solution.php b/8kyu/remove_first_and_last_character/solution.php new file mode 100644 index 0000000..b8bcd86 --- /dev/null +++ b/8kyu/remove_first_and_last_character/solution.php @@ -0,0 +1,3 @@ +function remove_char(string $s): string { + return substr($s, 1, strlen($s) - 2); +} diff --git a/8kyu/return_negative/solution.hs b/8kyu/return_negative/solution.hs new file mode 100644 index 0000000..4792fd7 --- /dev/null +++ b/8kyu/return_negative/solution.hs @@ -0,0 +1,4 @@ +module Codewars.Kata.Negative where + +makeNegative :: (Num a, Ord a) => a -> a +makeNegative n = - abs n diff --git a/8kyu/reversed_strings/solution.cpp b/8kyu/reversed_strings/solution.cpp new file mode 100644 index 0000000..fcd5438 --- /dev/null +++ b/8kyu/reversed_strings/solution.cpp @@ -0,0 +1,9 @@ +#include +using namespace std; + +string reverseString (string str) +{ + string res = ""; + for (int i = str.size() - 1; i >= 0; i--) res += str[i]; + return res; +} diff --git a/8kyu/square_n_sum/solution.js b/8kyu/square_n_sum/solution.js new file mode 100644 index 0000000..05370fd --- /dev/null +++ b/8kyu/square_n_sum/solution.js @@ -0,0 +1,9 @@ +function squareSum(numbers) { + let result = 0; + + for (let x of numbers) { + result += x * x; + } + + return result; +} diff --git a/8kyu/string_repeat/solution.c b/8kyu/string_repeat/solution.c new file mode 100644 index 0000000..ba206ec --- /dev/null +++ b/8kyu/string_repeat/solution.c @@ -0,0 +1,13 @@ +#include + +char *repeat_str(size_t count, const char *src) { + char* result = (char *) malloc(strlen(src) * count); + + size_t upper = count * strlen(src); + size_t len = strlen(src); + + for (size_t i = 0; i < upper; i += len) + strcpy(&result[i], src); + + return result; +} diff --git a/8kyu/students_final_grade/solution.js b/8kyu/students_final_grade/solution.js new file mode 100644 index 0000000..cb84c9c --- /dev/null +++ b/8kyu/students_final_grade/solution.js @@ -0,0 +1,6 @@ +function finalGrade (exam, projects) { + if (exam > 90 || projects > 10) return 100; + else if (exam > 75 && projects >= 5) return 90; + else if (exam > 50 && projects >= 2) return 75; + else return 0; +} diff --git a/8kyu/sum_arrays/solution.py b/8kyu/sum_arrays/solution.py new file mode 100644 index 0000000..a3df57d --- /dev/null +++ b/8kyu/sum_arrays/solution.py @@ -0,0 +1,5 @@ +def sum_array(a): + sum = 0 + for e in a: + sum += e + return sum diff --git a/8kyu/sum_of_positive/solution.py b/8kyu/sum_of_positive/solution.py new file mode 100644 index 0000000..27e9035 --- /dev/null +++ b/8kyu/sum_of_positive/solution.py @@ -0,0 +1,2 @@ +def positive_sum(arr): + return sum(filter(lambda e: e > 0, arr)) diff --git a/8kyu/sum_without_highest_and_lowest/solution.cpp b/8kyu/sum_without_highest_and_lowest/solution.cpp new file mode 100644 index 0000000..b7cd07f --- /dev/null +++ b/8kyu/sum_without_highest_and_lowest/solution.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +int sum(vector numbers) +{ + if (numbers.size() < 3) return 0; + + int min = numbers[0]; + int max = numbers[0]; + + int result = 0; + + for (const int num : numbers) + { + if (num < min) + min = num; + else if (num > max) + max = num; + + result += num; + } + + return result - (min + max); +} diff --git a/8kyu/to_square_or_not_to_square/solution.cs b/8kyu/to_square_or_not_to_square/solution.cs new file mode 100644 index 0000000..c5a1711 --- /dev/null +++ b/8kyu/to_square_or_not_to_square/solution.cs @@ -0,0 +1,18 @@ +using System; + +public class Kata +{ + public static int[] SquareOrSquareRoot(int[] array) + { + int[] new_array = new int[array.Length]; + + for (int i = 0, max = array.Length; i < max; i++) + { + double root = Math.Sqrt(array[i]); + if (root - (int) root <= double.Epsilon) new_array[i] = (int) root; + else new_array[i] = array[i] * array[i]; + } + + return new_array; + } +} diff --git a/8kyu/will_you_make_it/solution.cpp b/8kyu/will_you_make_it/solution.cpp new file mode 100644 index 0000000..d33d801 --- /dev/null +++ b/8kyu/will_you_make_it/solution.cpp @@ -0,0 +1,4 @@ +bool zero_fuel(uint32_t distance_to_pump, uint32_t mpg, uint32_t fuel_left) +{ + return (distance_to_pump / (float) mpg) <= fuel_left; +} diff --git a/8kyu/xor/solution.hs b/8kyu/xor/solution.hs new file mode 100644 index 0000000..11504ac --- /dev/null +++ b/8kyu/xor/solution.hs @@ -0,0 +1,4 @@ +module Codewars.Kata.Xor where + +xor :: Bool -> Bool -> Bool +xor = (!=) diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c2b017 --- /dev/null +++ b/README.md @@ -0,0 +1,383 @@ +# CodeWars + +## 1 kyu + +## 2 kyu + +## 3 kyu + +### C# + +- [Screen Locking Patterns](https://www.codewars.com/kata/585894545a8a07255e0002f1) - [solution](3kyu/screen_locking_patterns) +- [Binomial Expansion](https://www.codewars.com/kata/540d0fdd3b6532e5c3000b5b) - [solution](3kyu/binomial_expansion) +- [Battleship field validator](https://www.codewars.com/kata/52bb6539a4cf1b12d90005b7) - [solution](3kyu/battleship_field_validator) + +## 4 kyu + +### Rust + +- [Sum by Factors](https://www.codewars.com/kata/54d496788776e49e6b00052f) - [solution](4kyu/sum_by_factors) + +### C# + +- [Magnet particules in boxes](https://www.codewars.com/kata/56c04261c3fcf33f2d000534) - [solution](4kyu/magnet_particules_in_boxes) +- [The observed PIN](https://www.codewars.com/kata/5263c6999e0f40dee200059d) - [solution](4kyu/the_observed_pin) +- [Next bigger number with the same digits](https://www.codewars.com/kata/55983863da40caa2c900004e) - [solution](4kyu/next_bigger_with_same_digits) +- [Snail](https://www.codewars.com/kata/521c2db8ddc89b9b7a0000c1) - [solution](4kyu/snail) +- [Pyramid Slide Down](https://www.codewars.com/kata/551f23362ff852e2ab000037) - [solution](4kyu/pyramid_slide_down) +- [Human readable duration format](https://www.codewars.com/kata/52742f58faf5485cae000b9a) - [solution](4kyu/human_readable_duration_format) +- [4 By 4 Skyscrapers](https://www.codewars.com/kata/5671d975d81d6c1c87000022) - [solution (also Java)](4kyu/4_by_4_skyscrapers) +- [A Simplistic TCP Finite State Machine (FSM)](https://www.codewars.com/kata/54acc128329e634e9a000362) - [solution](4kyu/simplistic_tcp_fsm) +- [Counting Change Combinations](https://www.codewars.com/kata/541af676b589989aed0009e7) - [solution](4kyu/counting_change_combinations) +- [Sudoku Solution Validator](https://www.codewars.com/kata/529bf0e9bdf7657179000008) - [solution](4kyu/sudoku_solution_validator) +- [Sum Strings as Numbers](https://www.codewars.com/kata/5324945e2ece5e1f32000370) - [solution](4kyu/sum_strings_as_numbers) +- [Adding Big Numbers](https://www.codewars.com/kata/525f4206b73515bffb000b21) - [solution](4kyu/adding_big_numbers) + +### C++ + +- [Permutations](https://www.codewars.com/kata/5254ca2719453dcc0b00027d) - [solution](4kyu/permutations) +- [Matrix Determinant](https://www.codewars.com/kata/52a382ee44408cea2500074c) - [solution](4kyu/matrix_determinant) + +### JS + +- [Twice linear](https://www.codewars.com/kata/5672682212c8ecf83e000050) - [solution](4kyu/twice_linear) +- [Breadcrumb Generator](https://www.codewars.com/kata/563fbac924106b8bf7000046) - [solution](4kyu/breadcrumb_generator) +- [Priori Incantatem](https://www.codewars.com/kata/574d0b01b4b769b207000ca3) - [solution](4kyu/priori_incantatem) +- [ES5 Generators(i)](https://www.codewars.com/kata/53c29a6abb5187180d000b65) - [solution](4kyu/es5_generators_i) +- [Remove Zeros](https://www.codewars.com/kata/52aae14aa7fd03d57400058f) - [solution](4kyu/remove_zeros) + +### TS + +- [Route Calculator](https://www.codewars.com/kata/581bc0629ad9ff9873000316) - [solution](4kyu/route_calculator) + +## 5 kyu + +### Kotlin + +- [Buddy Pairs](https://www.codewars.com/kata/59ccf051dcc4050f7800008f) - [solution](5kyu/buddy_pairs) +- [Simple assembler interpreter](https://www.codewars.com/kata/58e24788e24ddee28e000053) - [solution](5kyu/simple_assembler_interpreter) +- [Maximum subarray sum](https://www.codewars.com/kata/54521e9ec8e60bc4de000d6c) - [solution](5kyu/maximum_subarray_sum) + +### C# + +- [Moving Zeros To The End](https://www.codewars.com/kata/52597aa56021e91c93000cb0) - [solution](5kyu/moving_zeros_to_the_end) +- [Common Denominators](https://www.codewars.com/kata/54d7660d2daf68c619000d95) - [solution](5kyu/common_denominators) +- [Number of trailing zeros of N!](https://www.codewars.com/kata/52f787eb172a8b4ae1000a34) - [solution](5kyu/number_of_trailing_zeros_of_nf) +- [Human Readable Time](https://www.codewars.com/kata/52685f7382004e774f0001f7) - [solution](5kyu/human_readable_time) +- [RGB To Hex Conversion](https://www.codewars.com/kata/513e08acc600c94f01000001) - [solution](5kyu/rgb_to_hex_conversion) +- [Scramblies](https://www.codewars.com/kata/55c04b4cc56a697bb0000048) - [solution](5kyu/scramblies) + +### Rust + +- [Which x for that sum?](https://www.codewars.com/kata/5b1cd19fcd206af728000056) - [solution](5kyu/which_x_for_that_sum) +- [Perimeter of squares in a rectangle](https://www.codewars.com/kata/559a28007caad2ac4e000083) - [solution](5kyu/perimeter_of_squares_in_a_rectangle) +- [My smallest code interpreter (aka Brainf**k)](https://www.codewars.com/kata/526156943dfe7ce06200063e) - [solution](5kyu/my_smallest_code_interpreter_bf) +- [Count IP Addresses](https://www.codewars.com/kata/526989a41034285187000de4) - [solution](5kyu/count_ip_addresses) + +### C + +- [int32 to IPv4](https://www.codewars.com/kata/52e88b39ffb6ac53a400022e) - [solution](5kyu/i32_to_ipv4) +- [Convert A Hex String To RGB](https://www.codewars.com/kata/5282b48bb70058e4c4000fa7) - [solution](5kyu/convert_a_hex_string_to_rgb) + +### C++ + +- [Is my friend cheating?](https://www.codewars.com/kata/5547cc7dcad755e480000004) - [solution](5kyu/is_my_friend_cheating) +- [Greed is Good](https://www.codewars.com/kata/5270d0d18625160ada0000e4) - [solution](5kyu/greed_is_good) +- [Snakes and Ladders](https://www.codewars.com/kata/587136ba2eefcb92a9000027) - [solution](5kyu/snakes_and_ladders) +- [The Clockwise Spiral](https://www.codewars.com/kata/536a155256eb459b8700077e) - [solution](5kyu/the_clockwise_spiral) + +### Python + +- [Weight for weight](https://www.codewars.com/kata/55c6126177c9441a570000cc) - [solution](5kyu/weight_for_weight) +- [Valid Parentheses](https://www.codewars.com/kata/52774a314c2333f0a7000688) - [solution](5kyu/valid_parentheses) +- [Simple Pig Latin](https://www.codewars.com/kata/520b9d2ad5c005041100000f) - [solution](5kyu/simple_pig_latin) +- [Sum of pairs](https://www.codewars.com/kata/54d81488b981293527000c8f) - [solution](5kyu/sum_of_pairs) +- [Memoized Fibonacci](https://www.codewars.com/kata/529adbf7533b761c560004e5) - [solution](5kyu/memoized_fibonacci) + +### Haskell + +- [Directions Reduction](https://www.codewars.com/kata/550f22f4d758534c1100025a) - [solution](5kyu/directions_reduction) + +### JS + +- [Where my anagrams at?](https://www.codewars.com/kata/523a86aa4230ebb5420001e1) - [solution](5kyu/where_my_anagrams_at) +- [Rot13](https://www.codewars.com/kata/530e15517bc88ac656000716) - [solution](5kyu/rot13) +- [The Hashtag Generator](https://www.codewars.com/kata/52449b062fb80683ec000024) - [solution](5kyu/the_hashtag_generator) +- [Tic-Tac-Toe Checker](https://www.codewars.com/kata/525caa5c1bf619d28c000335) - [solution](5kyu/tic_tac_toe_checker) +- [Did I Finish my Sudoku?](https://www.codewars.com/kata/53db96041f1a7d32dc0004d2) - [solution](5kyu/did_i_finish_my_sudokou) +- [Calculating with Functions](https://www.codewars.com/kata/525f3eda17c7cd9f9e000b39) - [solution](5kyu/calculating_with_functions) +- [Vector class](https://www.codewars.com/kata/526dad7f8c0eb5c4640000a4) - [solution](5kyu/vector_class) +- [Halloween Sweets](https://www.codewars.com/kata/526bd612696e23c43a00032e) - [solution](5kyu/halloween_sweets) + +### Swift + +- [Esolang Interpreters #2 - Custom Smallfuck Interpreter](https://www.codewars.com/kata/58678d29dbca9a68d80000d7) - [solution](5kyu/esolang_interpreters_ii) + +## 6 kyu + +### Rust + +- [Irreducible Sum of Rationals](https://www.codewars.com/kata/5517fcb0236c8826940003c9) - [solution](6kyu/irreducible_sum_of_rationals) +- [Help the bookseller !](https://www.codewars.com/kata/54dc6f5a224c26032800005c) - [solution](6kyu/help_the_bookseller) +- [Counting Duplicates](https://www.codewars.com/kata/54bf1c2cd5b56cc47f0007a1) - [solution](6kyu/counting_duplicates) +- [Decode the Morse code](https://www.codewars.com/kata/54b724efac3d5402db00065e) - [solution](6kyu/decode_the_morse_code) +- [Parabolic Arc Length](https://www.codewars.com/kata/562e274ceca15ca6e70000d3) - [solution](6kyu/parabolic_arc_length) +- [CamelCase Method](https://www.codewars.com/kata/587731fda577b3d1b0001196) - [solution](6kyu/camelcase_method) +- [Simple Substitution Cipher Helper](https://www.codewars.com/kata/52eb114b2d55f0e69800078d) - [solution](6kyu/simple_substitution_cipher_helper) + +### C# + +- [Find the odd int](https://www.codewars.com/kata/54da5a58ea159efa38000836) - [solution](6kyu/find_the_odd_int) +- [Rectangle into Squares](https://www.codewars.com/kata/55466989aeecab5aac00003e) - [solution](6kyu/rectangle_into_squares) +- [Does my number look big in this?](https://www.codewars.com/kata/5287e858c6b5a9678200083c) - [solution](6kyu/does_my_number_look_big_in_this) +- [Stop gninnipS My sdroW!](https://www.codewars.com/kata/5264d2b162488dc400000001) - [solution](6kyu/stop_gninnips_my_sdrow) +- [Count the smiley faces!](https://www.codewars.com/kata/583203e6eb35d7980400002a) - [solution](6kyu/count_the_smiley_faces) +- [Who likes it?](https://www.codewars.com/kata/5266876b8f4bf2da9b000362) - [solution](6kyu/who_likes_it) +- [Roman Numerals Encoder](https://www.codewars.com/kata/51b62bf6a9c58071c600001b) - [solution](6kyu/roman_numerals_encoder) +- [Roman Numerals Decoder](https://www.codewars.com/kata/51b6249c4612257ac0000005) - [solution](6kyu/roman_numerals_dekcoder) +- [Equal Sides Of An Array](https://www.codewars.com/kata/5679aa472b8f57fb8c000047) - [solution](6kyu/equal_sides_of_an_array) +- [The Supermarket Queue](https://www.codewars.com/kata/57b06f90e298a7b53d000a86) - [solution](6kyu/the_supermarket_queue) +- [LOTTO 6 aus 49 - 6 of 49](https://www.codewars.com/kata/57a98e8172292d977b000079) - [solution](6kyu/lotto_6_aus_49) +- [Length of missing array](https://www.codewars.com/kata/57b6f5aadb5b3d0ae3000611) - [solution](6kyu/length_of_missing_array) +- [Word a10n (abbreviation)](https://www.codewars.com/kata/5375f921003bf62192000746) - [solution](6kyu/word_a10n) + +### Haskell + +- [Take a Ten Minute Walk](https://www.codewars.com/kata/54da539698b8a2ad76000228) - [solution](6kyu/take_a_ten_minute_walk) +- [Multiples of 3 or 5](https://www.codewars.com/kata/514b92a657cdc65150000006) - [solution](6kyu/multiples_of_3_or_5) +- [Sum of Digits / Digital Root](https://www.codewars.com/kata/541c8630095125aba6000c00) - [solution](6kyu/sum_of_digits__digital_root) +- [Pyramid Array](https://www.codewars.com/kata/515f51d438015969f7000013) - [solution](6kyu/pyramid_array) +- [Make the Deadfish swim](https://www.codewars.com/kata/51e0007c1f9378fa810002a9) - [solution](6kyu/make_the_deadfish_swim) +- [Pascal's Triangle](https://www.codewars.com/kata/5226eb40316b56c8d500030f) - [solution](6kyu/pascals_triangle) + +### Python + +- [Bit Counting](https://www.codewars.com/kata/526571aae218b8ee490006f4) - [solution](6kyu/bit_counting) +- [Is a number prime?](https://www.codewars.com/kata/5262119038c0985a5b00029f) - [solution](6kyu/is_a_number_prime) +- [Bouncing Balls](https://www.codewars.com/kata/5544c7a5cb454edb3c000047) - [solution](6kyu/bouncing_balls) +- [Highest Scoring Word](https://www.codewars.com/kata/57eb8fcdf670e99d9b000272) - [solution](6kyu/highest_scoring_word) +- [Your order, please](https://www.codewars.com/kata/55c45be3b2079eccff00010f) - [solution](6kyu/your_order_please) +- [Find the unique number](https://www.codewars.com/kata/585d7d5adb20cf33cb000235) - [solution](6kyu/find_the_unique_number) +- [Split Strings](https://www.codewars.com/kata/515de9ae9dcfc28eb6000001) - [solution](6kyu/split_strings) +- [Find the missing term in an Arithmetic Progression](https://www.codewars.com/kata/52de553ebb55d1fca3000371) - [solution](6kyu/find_the_missing_term_in_arith_prog) +- [Fat Fingers](https://www.codewars.com/kata/5aa99584fd5777ee9a0001f1) - [solution](6kyu/fat_fingers) + +### Kotlin + +- [Playing with digits](https://www.codewars.com/kata/5552101f47fc5178b1000050) - [solution](6kyu/playing_with_digits) +- [Ball Upwards](https://www.codewars.com/kata/566be96bb3174e155300001b) - [solution](6kyu/ball_upwards) + +### C++ + +- [Statistics for an Athletic Association](https://www.codewars.com/kata/55b3425df71c1201a800009c) - [solution](6kyu/statistics_for_an_athletic_association) +- [Linked Lists - Length & Count](https://www.codewars.com/kata/55beec7dd347078289000021) - [solution](6kyu/linked_lists_length_count) +- [Design a Simple Automaton (Finite State Machine)](https://www.codewars.com/kata/5268acac0d3f019add000203) - [solution](6kyu/design_a_simple_automaton) + +### JS + +- [Are they the "same"?](https://www.codewars.com/kata/550498447451fbbd7600041c/) - [solution](6kyu/are_they_the_same) +- [Create Phone Number](https://www.codewars.com/kata/525f50e3b73515a6db000b83) - [solution](6kyu/create_phone_number) +- [Build Tower](https://www.codewars.com/kata/576757b1df89ecf5bd00073b) - [solution](6kyu/build_tower) +- [Convert string to camel case](https://www.codewars.com/kata/517abf86da9663f1d2000003) - [solution](6kyu/convert_string_to_camel_case) +- [Delete occurrences of an element if it occurs more than n times](https://www.codewars.com/kata/554ca54ffa7d91b236000023) - [solution](6kyu/delete_occurrences_if_occurs) +- [Reverse polish notation calculator](https://www.codewars.com/kata/52f78966747862fc9a0009ae) - [solution](6kyu/rpn_calculator) +- [Halloween: trick or treat!](https://www.codewars.com/kata/581302bbbee85709d00002ae) - [solution](6kyu/halloween_trick_or_treat) +- [Build Tower Advanced](https://www.codewars.com/kata/57675f3dedc6f728ee000256) - [solution](6kyu/build_tower_advanced) +- [Evil Autocorrect Prank](https://www.codewars.com/kata/538ae2eb7a4ba8c99b000439) - [solution](6kyu/evil_autocorrect_prank) + +### Java + +- [Consecutive strings](https://www.codewars.com/kata/56a5d994ac971f1ac500003e) - [solution](6kyu/consecutive_strings) +- [Duplicate Encoder](https://www.codewars.com/kata/54b42f9314d9229fd6000d9c) - [solution](6kyu/duplicate_encoder) +- [Find the missing letter](https://www.codewars.com/kata/5839edaa6754d6fec10000a2) - [solution](6kyu/find_the_missing_letter) +- [Two Sum](https://www.codewars.com/kata/52c31f8e6605bcc646000082) - [solution](6kyu/two_sum) + +### C + +- [IP Validation](https://www.codewars.com/kata/515decfd9dcfc23bb6000006) - [solution](6kyu/ip_validation) +- [Cheat or you shall not pass: easy](https://www.codewars.com/kata/58f5ae82164573de7c00038c) - [solution](6kyu/cheat_or_you_shall_not_pass_easy) + +### Go + +- [Multiplication table](https://www.codewars.com/kata/534d2f5b5371ecf8d2000a08) - [solution](6kyu/multiplication_table) + +### Swift + +- [Give me a Diamond](https://www.codewars.com/kata/5503013e34137eeeaa001648) - [solution](6kyu/give_me_a_diamond) +- [Esolang Interpreters #1 - Introduction to Esolangs and My First Interpreter (MiniStringFuck)](https://www.codewars.com/kata/586dd26a69b6fd46dd0000c0) - [solution](6kyu/esolang_interpreters_i) + +### TS + +- [Valid Braces](https://www.codewars.com/kata/5277c8a221e209d3f6000b56) - [solution](6kyu/valid_braces) + +## 7 kyu + +### JS + +- [Isograms](https://www.codewars.com/kata/54ba84be607a92aa900000f1) - [solution](7kyu/isograms) +- [Highest and Lowest](https://www.codewars.com/kata/554b4ac871d6813a03000035) - [solution](7kyu/highest_and_lowest) +- [Growth of a Population](https://www.codewars.com/kata/563b662a59afc2b5120000c6) - [solution](7kyu/growth_of_a_population) +- [Pirate Code](https://www.codewars.com/kata/59e77930233243a7b7000026) - [solution](7kyu/pirate_code) +- [Find the divisors!](https://www.codewars.com/kata/544aed4c4a30184e960010f4) - [solution](7kyu/find_the_divisors) +- [Categorize New Member](https://www.codewars.com/kata/5502c9e7b3216ec63c0001aa) - [solution](7kyu/categorize_new_member) +- [Distributing Candies Fairly](https://www.codewars.com/kata/59901cd68fc658ab6c000025) - [solution](7kyu/distributing_candies_fairly) + +### C++ + +- [Is this a triangle?](https://www.codewars.com/kata/56606694ec01347ce800001b) - [solution](7kyu/is_this_a_triangle) +- [Sum of angles](https://www.codewars.com/kata/5a03b3f6a1c9040084001765) - [solution](7kyu/sum_of_angles) +- [Are the numbers in order?](https://www.codewars.com/kata/56b7f2f3f18876033f000307) - [solution](7kyu/are_the_numbers_in_order) + +### PHP + +- [Printer Errors](https://www.codewars.com/kata/56541980fa08ab47a0000040) - [solution](7kyu/printer_errors) + +### Python + +- [Bumps in the Road](https://www.codewars.com/kata/57ed30dde7728215300005fa) - [solution](7kyu/bumps_in_the_road) +- [Ones and Zeros](https://www.codewars.com/kata/578553c3a1b8d5c40300037c) - [solution](7kyu/ones_and_zeros) +- [Odd or Even?](https://www.codewars.com/kata/5949481f86420f59480000e7) - [solution](7kyu/odd_or_even) +- [Palindrome chain length](https://www.codewars.com/kata/525f039017c7cd0e1a000a26) - [solution](7kyu/palindrome_chain_length) +- [Inspiring Strings](https://www.codewars.com/kata/5939ab6eed348a945f0007b2) - [solution](7kyu/inspiring_strings) +- [Anagram Detection](https://www.codewars.com/kata/529eef7a9194e0cbc1000255) - [solution](7kyu/anagram_detection) +- [Sorted? yes? no? how?](https://www.codewars.com/kata/580a4734d6df748060000045) - [solution](7kyu/sorted_yes_no_how) +- [Hit Count](https://www.codewars.com/kata/57b6f850a6fdc76523001162) - [solution](7kyu/hit_count) +- [Don't give me five!](https://www.codewars.com/kata/5813d19765d81c592200001a) - [solution](7kyu/dont_give_me_five) + +### C# + +- [Beginner Series #3 Sum of Numbers](https://www.codewars.com/kata/55f2b110f61eb01779000053) - [solution](7kyu/beginner_series_iii) +- [Find the next perfect square!](https://www.codewars.com/kata/56269eb78ad2e4ced1000013) - [solution](7kyu/find_the_next_perfect_square) +- [Vowel Count](https://www.codewars.com/kata/54ff3102c1bad923760001f3) - [solution](7kyu/vowel_count) +- [Credit Card Mask](https://www.codewars.com/kata/5412509bd436bd33920011bc) - [solution](7kyu/credit_card_mask) +- [Shortest Word](https://www.codewars.com/kata/57cebe1dc6fdc20c57000ac9) - [solution](7kyu/shortest_word) +- [Jaden Casing Strings](https://www.codewars.com/kata/5390bac347d09b7da40006f6) - [solution](7kyu/jaden_casing_strings) +- [Deodorant Evaporator](https://www.codewars.com/kata/5506b230a11c0aeab3000c1f) - [solution](7kyu/deodorant_evaporator) +- [Parts of a list](https://www.codewars.com/kata/56f3a1e899b386da78000732) - [solution](7kyu/parts_of_a_list) +- [Mumbling](https://www.codewars.com/kata/5667e8f4e3f572a8f2000039) - [solution](7kyu/mumbling) +- [Binary Addition](https://www.codewars.com/kata/551f37452ff852b7bd000139) - [solution](7kyu/binary_addition) +- [Sum of two lowest positive integers](https://www.codewars.com/kata/558fc85d8fd1938afb000014) - [solution](7kyu/sum_of_two_lowest_positive_integers) +- [Digital cypher vol 2](https://www.codewars.com/kata/592edfda5be407b9640000b2) - [solution](7kyu/digital_cypher_vol_2) +- [List Filtering](https://www.codewars.com/kata/53dbd5315a3c69eed20002dd) - [solution](7kyu/list_filtering) +- [Remove the minimum](https://www.codewars.com/kata/563cf89eb4747c5fb100001b) - [solution](7kyu/remove_the_minimum) + +### Haskell + +- [Fibonacci](https://www.codewars.com/kata/57a1d5ef7cb1f3db590002af) - [solution](7kyu/fibonacci) +- [Product of Array Items](https://www.codewars.com/kata/5901f361927288d961000013) - [solution](7kyu/product_of_array_items) +- [Make a function that does arithmetic!](https://www.codewars.com/kata/583f158ea20cfcbeb400000a) - [solution](7kyu/make_a_function_that_does_arithmetic) +- [Exes and Ohs](https://www.codewars.com/kata/55908aad6620c066bc00002a) - [solution](7kyu/exes_and_ohs) + +### Kotlin + +- [Sum of odd numbers](https://www.codewars.com/kata/55fd2d567d94ac3bc9000064) - [solution](7kyu/sum_of_odd_numbers) +- [Number of People in the Bus](https://www.codewars.com/kata/5648b12ce68d9daa6b000099) - [solution](7kyu/number_of_people_in_the_bus) +- [Complementary DNA](https://www.codewars.com/kata/554e4a2f232cdd87d9000038) - [solution](7kyu/complementary_dna) +- [Small enough? - Beginner](https://www.codewars.com/kata/57cc981a58da9e302a000214) - [solution](7kyu/small_enough_beginner) +- [Rotate for a Max](https://www.codewars.com/kata/56a4872cbb65f3a610000026) - [solution](7kyu/rotate_for_a_max) +- [Predict your age!](https://www.codewars.com/kata/5aff237c578a14752d0035ae) - [solution](7kyu/predict_your_age) + +### C + +- [Looking for a benefactor](https://www.codewars.com/kata/569b5cec755dd3534d00000f) - [solution](7kyu/looking_for_a_benefactor) +- [Speed Control](https://www.codewars.com/kata/56484848ba95170a8000004d) - [solution](7kyu/speed_control) +- [Most digits](https://www.codewars.com/kata/58daa7617332e59593000006) - [solution](7kyu/most_digits) + +### Rust + +- [Maximum Length Difference](https://www.codewars.com/kata/5663f5305102699bad000056) - [solution](7kyu/maximum_length_difference) +- [Digital cypher](https://www.codewars.com/kata/592e830e043b99888600002d) - [solution](7kyu/digital_cypher) + +### Java + +- [Regex validate PIN code](https://www.codewars.com/kata/55f8a9c06c018a0d6e000132) - [solution](7kyu/regex_validate_pin_code) + +### Swift + +- [Fizz Buzz Cuckoo Clock](https://www.codewars.com/kata/58485a43d750d23bad0000e6) - [solution](7kyu/fizz_buzz_cuckoo_clock) +- [Resistor Color Codes](https://www.codewars.com/kata/57cf3dad05c186ba22000348) - [solution](7kyu/resistor_color_codes) + +## 8 kyu + +### JS + +- [Square(n) Sum](https://www.codewars.com/kata/515e271a311df0350d00000f) - [solution](8kyu/square_n_sum) +- [Student's Final Grade](https://www.codewars.com/kata/5ad0d8356165e63c140014d4) - [solution](8kyu/students_final_grade) +- [Grasshopper - Personalized Message](https://www.codewars.com/kata/5772da22b89313a4d50012f7) - [solution](8kyu/grasshopper_personalized_message) +- [altERnaTIng cAsE <=> ALTerNAtiNG CaSe](https://www.codewars.com/kata/56efc695740d30f963000557) - [solution](8kyu/alternating_case) + +### C + +- [String repeat](https://www.codewars.com/kata/57a0e5c372292dd76d000d7e) - [solution](8kyu/string_repeat) +- [Parse nice int from char problem](https://www.codewars.com/kata/557cd6882bfa3c8a9f0000c1) - [solution](8kyu/parse_nice_int_from_char) +- [Get Nth Even Number](https://www.codewars.com/kata/5933a1f8552bc2750a0000ed) - [solution](8kyu/get_nth_even_number) +- [Get the mean of an array](https://www.codewars.com/kata/563e320cee5dddcf77000158) - [solution](8kyu/get_the_mean_of_an_array) +- [Fake Binary](https://www.codewars.com/kata/57eae65a4321032ce000002d) - [solution](8kyu/fake_binary) +- [Is the string uppercase?](https://www.codewars.com/kata/56cd44e1aa4ac7879200010b) - [solution](8kyu/is_the_string_uppercase) + +### C++ + +- [Counting sheep...](https://www.codewars.com/kata/54edbc7200b811e956000556) - [solution](8kyu/counting_sheep) +- [Reversed Strings](https://www.codewars.com/kata/5168bb5dfe9a00b126000018) - [solution](8kyu/reversed_strings) +- [Multiply](https://www.codewars.com/kata/50654ddff44f800200000004) - [solution](8kyu/multiply) +- [Will you make it?](https://www.codewars.com/kata/5861d28f124b35723e00005e) - [solution](8kyu/will_you_make_it) +- [Is it a palindrome?](https://www.codewars.com/kata/57a1fd2ce298a731b20006a4) - [solution](8kyu/is_it_a_palindrome) +- [Sum without highest and lowest number](https://www.codewars.com/kata/576b93db1129fcf2200001e6) - [solution](8kyu/sum_without_highest_and_lowest) + +### Haskell + +- [Even or Odd](https://www.codewars.com/kata/53da3dbb4a5168369a0000fe) - [solution](8kyu/even_or_odd) +- [Convert boolean values to strings 'Yes' or 'No'.](https://www.codewars.com/kata/53369039d7ab3ac506000467) - [solution](8kyu/convert_boolean_values_to_strings) +- [Century From Year](https://www.codewars.com/kata/5a3fe3dde1ce0e8ed6000097) - [solution](8kyu/century_from_year) +- [Return Negative](https://www.codewars.com/kata/55685cd7ad70877c23000102) - [solution](8kyu/return_negative) +- [Opposite number](https://www.codewars.com/kata/56dec885c54a926dcd001095) - [solution](8kyu/opposite_number) +- [Keep Hydrated!](https://www.codewars.com/kata/582cb0224e56e068d800003c) - [solution](8kyu/keep_hydrated) +- [Calculate average](https://www.codewars.com/kata/57a2013acf1fa5bfc4000921) - [solution](8kyu/calculate_average) +- [How many lightsabers do you own?](https://www.codewars.com/kata/51f9d93b4095e0a7200001b8) - [solution](8kyu/how_many_lightsabers) +- [Exclusive "or" (xor) Logical Operator](https://www.codewars.com/kata/56fa3c5ce4d45d2a52001b3c) - [solution](8kyu/xor) + +### Python + +- [Correct the mistakes of the character recognition software](https://www.codewars.com/kata/577bd026df78c19bca0002c0) - [solution](8kyu/correct_mistakes_of_character_recognition) +- [Sum of positive](https://www.codewars.com/kata/5715eaedb436cf5606000381) - [solution](8kyu/sum_of_positive) +- [MakeUpperCase](https://www.codewars.com/kata/57a0556c7cb1f31ab3000ad7) - [solution](8kyu/make_upper_case) +- [Sum Arrays](https://www.codewars.com/kata/53dc54212259ed3d4f00071c) - [solution](8kyu/sum_arrays) +- [5 without numbers !!](https://www.codewars.com/kata/59441520102eaa25260000bf) - [solution](8kyu/five_without_numbers) + +### Pascal + +- [Beginner Series #4 Cockroach](https://www.codewars.com/kata/55fab1ffda3e2e44f00000c6) - [solution](8kyu/beginner_series_iv) +- [Grasshopper - Summation](https://www.codewars.com/kata/55d24f55d7dd296eb9000030) - [solution](8kyu/grasshopper_summation) + +### Kotlin + +- [Beginner Series #2 Clock](https://www.codewars.com/kata/55f9bca8ecaa9eac7100004a) - [solution](8kyu/beginner_series_ii) +- [Opposites Attract](https://www.codewars.com/kata/555086d53eac039a2a000083) - [solution](8kyu/opposites_attract) +- [Beginner - Lost Without a Map](https://www.codewars.com/kata/57f781872e3d8ca2a000007e) - [solution](8kyu/beginner_lost_without_a_map) + +### Rust + +- [Difference of Volumes of Cuboids](https://www.codewars.com/kata/58cb43f4256836ed95000f97) - [solution](8kyu/difference_of_volumes_of_cuboids) +- [Find the smallest integer in the array](https://www.codewars.com/kata/55a2d7ebe362935a210000b2) - [solution](8kyu/find_the_smallest_integer_in_the_array) + +### PHP + +- [Remove First and Last Character](https://www.codewars.com/kata/56bc28ad5bdaeb48760009b0) - [solution](8kyu/remove_first_and_last_character) + +### C# + +- [Convert number to reversed array of digits](https://www.codewars.com/kata/5583090cbe83f4fd8c000051) - [solution](8kyu/convert_number_to_reversed_digits) +- [Grasshopper - Grade book](https://www.codewars.com/kata/55cbd4ba903825f7970000f5) - [solution](8kyu/grasshopper_grade_book) +- [A Needle in the Haystack](https://www.codewars.com/kata/56676e8fabd2d1ff3000000c) - [solution](8kyu/a_needle_in_the_haystack) +- [Enumerable Magic #3 - Does My List Include This?](https://www.codewars.com/kata/545991b4cbae2a5fda000158) - [solution](8kyu/enumerable_magic_iii) +- [Exclamation marks series #4: Remove all exclamation marks from sentence but ensure a exclamation mark at the end of string](https://www.codewars.com/kata/57faf12b21c84b5ba30001b0) - [solution](8kyu/exclamation_marks) +- [To square(root) or not to square(root)](https://www.codewars.com/kata/57f6ad55cca6e045d2000627) - [solution](8kyu/to_square_or_not_to_square) + +### Java + +- [Jenny's secret message](https://www.codewars.com/kata/55225023e1be1ec8bc000390) - [solution](8kyu/jennys_secret_message) +- [Count the Monkeys!](https://www.codewars.com/kata/56f69d9f9400f508fb000ba7) - [solution](8kyu/count_the_monkeys) + +--- + +- [](https://www.codewars.com/kata/) - [solution]()