├── .travis.yml ├── LICENCE ├── README.md ├── katas ├── __init__.py ├── beta │ ├── __init__.py │ ├── adding_fractions.py │ ├── addition_function_problem.py │ ├── algebraic_string.py │ ├── alien_beer_morse_code.py │ ├── anagram_or_not.py │ ├── another_one_down.py │ ├── another_one_down_survival_of_fittest.py │ ├── arithmetic_progression.py │ ├── array_2_binary.py │ ├── assignment_2.py │ ├── assignment_3.py │ ├── atm_money_counter.py │ ├── author_disambiguation_a_name_is_a_name.py │ ├── back_to_basics.py │ ├── basic_arabic_to_roman_numerals.py │ ├── beetlejuice_x3_bug_fix.py │ ├── beginner_series_2_clock.py │ ├── beginner_series_cockroach.py │ ├── beginner_series_paperwork.py │ ├── bin_to_decimal.py │ ├── bin_to_hex_and_back.py │ ├── binary_operations_1.py │ ├── binary_pyramid_101.py │ ├── bracket_buster.py │ ├── broken_sequence.py │ ├── bubble_sort.py │ ├── building_spheres.py │ ├── builtin_product_function.py │ ├── caesar_cipher.py │ ├── caesar_cipher_encryption_variation.py │ ├── calculator_with_brackets.py │ ├── capitals_first.py │ ├── cat_and_mouse_easy_version.py │ ├── cat_kata_part_1.py │ ├── chuck_norris_v_body_count.py │ ├── circular_primes.py │ ├── cis_122_simple_input.py │ ├── cis_122_simple_operations.py │ ├── cis_122_simple_printing.py │ ├── closest_neighbouring_points.py │ ├── closest_sum.py │ ├── colored_hexes.py │ ├── compare_section_numbers.py │ ├── compress_encode_a_msg_with_rle.py │ ├── correct_the_time_string.py │ ├── count_consecutive_characters.py │ ├── count_inversions.py │ ├── count_vowels_in_a_string.py │ ├── count_words.py │ ├── countdown_longest_word.py │ ├── counter_of_neighbor_ones.py │ ├── counting_array_elements.py │ ├── crazed_templating.py │ ├── create_a_house_cleaning_rota.py │ ├── credit_card_validifier.py │ ├── cycle_through_items.py │ ├── data_reverse.py │ ├── decipher_the_cipher.py │ ├── democracy_representation.py │ ├── denumerate_string.py │ ├── digit_sum.py │ ├── dinner_plans.py │ ├── divisible_by_four.py │ ├── doing_your_taxes.py │ ├── duck_shoot_easy_version.py │ ├── dumbphone_keypads.py │ ├── easiest_kata.py │ ├── easy_kata.py │ ├── email_validation.py │ ├── endless_string.py │ ├── esrever_esrever.py │ ├── evening_up_a_workload.py │ ├── exclusive_presentations.py │ ├── file_path_operations.py │ ├── find_all_the_unique_substrings.py │ ├── find_duplicate.py │ ├── find_gcf.py │ ├── find_jon_snow_parents.py │ ├── find_something_in_an_array.py │ ├── find_the_discounted_prices.py │ ├── find_the_gcf_of_two_numbers.py │ ├── find_the_middle_element.py │ ├── finding_averages.py │ ├── first_character_that_repeats.py │ ├── fix_the_base_conversion_function.py │ ├── fix_the_loop.py │ ├── flatten_me.py │ ├── food_combinations.py │ ├── for_loop.py │ ├── format_to_the_second.py │ ├── fractions_class.py │ ├── fractions_of_a_currencies_smallest_value.py │ ├── friend_or_foe.py │ ├── fuel_usage_reporting.py │ ├── fundamentals_return.py │ ├── geometric_progression.py │ ├── get_number_from_string.py │ ├── grasshopper_fantasy_points.py │ ├── greeting_my_friends.py │ ├── hail_caesar.py │ ├── heavy_metal_umlauts.py │ ├── help_suzuki_purchase_his_tofu.py │ ├── help_the_fruit_guy.py │ ├── herons_formula.py │ ├── hollow_triangle.py │ ├── how_many_minutes.py │ ├── how_many_numbers.py │ ├── how_many_stairs_will_suzuki_climb_in_20_years.py │ ├── how_many_times_does_it_contain.py │ ├── how_many_times_should_i_go.py │ ├── how_much_coffee_do_you_need.py │ ├── how_much_hex_is_the_fish.py │ ├── how_sexy_is_your_name.py │ ├── identify_case.py │ ├── identifying_top_users_and_their_corresponding_purchases.py │ ├── is_n_divisible_by_x_y.py │ ├── jacobs_weight_loss_program.py │ ├── keep_it_short_with_restrictions.py │ ├── keep_up_the_hoop.py │ ├── knight_or_knave.py │ ├── kontti_language.py │ ├── lets_flat_them_out.py │ ├── lightswitches.py │ ├── list_length_v1.py │ ├── list_length_v2.py │ ├── logical_and_nonnegative_matrix.py │ ├── logical_calculator.py │ ├── logistic_map.py │ ├── loose_change.py │ ├── loose_change_.py │ ├── lowest_product_of_4_consecutive_nums.py │ ├── make_acronym.py │ ├── master_of_files.py │ ├── merge_2048.py │ ├── modulus_11_check_digit.py │ ├── most_frequent_weekdays.py │ ├── mtv_cribs.py │ ├── multi_range_iterator.py │ ├── multiples.py │ ├── multiples_2.py │ ├── multiples_by_permutations_1.py │ ├── multiply_list_by_integer_with_restrictions.py │ ├── multiply_two_numbers_without_integers.py │ ├── multiply_without_asterisk.py │ ├── my_first_bug_fixing_kata.py │ ├── name_that_number.py │ ├── naming_files.py │ ├── ninety_degrees_rotation.py │ ├── no_duplicates_here.py │ ├── nothing_special.py │ ├── number_number_wait_letter.py │ ├── number_to_bytes.py │ ├── only_readable_once_list.py │ ├── oracle_coin_method.py │ ├── ordered_count_of_characters.py │ ├── pairing_brackets.py │ ├── palindrome_checker.py │ ├── parse_float.py │ ├── password_maker.py │ ├── phonewords.py │ ├── pirates_are_the_cannons_ready.py │ ├── plus_1_array.py │ ├── pop_shift.py │ ├── print_that_calendar.py │ ├── product_of_largest_pair.py │ ├── professor_oaks_trouble_new_pokedex_prototype.py │ ├── python_one_liner_1_introduction.py │ ├── quicksum.py │ ├── rammstein_needs_your_help.py │ ├── range_parser.py │ ├── re_ordering.py │ ├── remember.py │ ├── remove_duplicates_from_list.py │ ├── remove_first_and_last_character.py │ ├── remove_unnecessary_characters_from_items_in_list.py │ ├── reorganize_the_weapons.py │ ├── replace_multiples_with_string.py │ ├── required_data_1.py │ ├── required_data_2.py │ ├── resistor_color_codes.py │ ├── returning_strings.py │ ├── reverse_complement_dna.py │ ├── reverse_list.py │ ├── reverse_the_number.py │ ├── reversing_words_in_a_string.py │ ├── rigged_dice.py │ ├── rotate_a_square_matrix_in_place.py │ ├── rotated_string.py │ ├── round_to_next_5.py │ ├── sales_report.py │ ├── santas_missing_gift_list.py │ ├── sean_sean_sean.py │ ├── selecting_quotients_from_an_array.py │ ├── separate_filename_from_extension.py │ ├── seven_ate_9.py │ ├── shorten_ipv6_address.py │ ├── simple_barcode_scanner.py │ ├── simple_beads_count.py │ ├── simple_decrypt_algo.py │ ├── simple_decrypt_algo_2.py │ ├── simple_encryption_1_alternating_split.py │ ├── simple_encryption_2_index_difference.py │ ├── small_enough_beginner.py │ ├── sms_shortener.py │ ├── sort_a_massive_list_of_strings.py │ ├── sort_array_by_last_character.py │ ├── sort_deck_of_cards.py │ ├── sort_the_columns_of_a_csv_file.py │ ├── sort_the_odd.py │ ├── sortable_shapes.py │ ├── sorting_integers_into_a_nested_list.py │ ├── sorting_time.py │ ├── spanish_class_help.py │ ├── special_scores_for_words.py │ ├── split_string_by_multiple_delimiters.py │ ├── spy_games_rebuild_your_decoder.py │ ├── strange_strings_parser.py │ ├── string_cleaning.py │ ├── string_evaluation.py │ ├── string_incrementer.py │ ├── string_pyramid.py │ ├── string_repeat.py │ ├── string_repetition_without_function.py │ ├── string_to_list_of_integers.py │ ├── strip_my_comments.py │ ├── sum_of_all_arguments.py │ ├── sum_of_list_values.py │ ├── sum_of_numerous_arguments.py │ ├── sum_of_positive.py │ ├── sum_of_two_lowest_integers.py │ ├── sum_of_values_from_1_to_n_inclusive.py │ ├── sum_the_repeats.py │ ├── summations_1.py │ ├── super_duper_easy.py │ ├── swap_row_in_certain_columns_of_a_matrix.py │ ├── syntax_error_array_functions.py │ ├── tail_swap.py │ ├── testing_123.py │ ├── text_align_right.py │ ├── the_animals_went_in_two_by_two.py │ ├── the_office_4_find_a_meeting_room.py │ ├── the_skeptical_kid_generator.py │ ├── the_unknown_but_known_variables_addition.py │ ├── this_is_odd.py │ ├── time_for_validation.py │ ├── timer_decorator.py │ ├── to_buy_or_not_to_buy.py │ ├── transpose_of_a_matrix.py │ ├── trigrams.py │ ├── trumpness_detector.py │ ├── two_arrays_one_sort.py │ ├── two_fighters_one_winner.py │ ├── unique_sum.py │ ├── unscrambled_eggs.py │ ├── upper_body_strength.py │ ├── using_the_codewars_api_kata_rank.py │ ├── valid_hk_phone_number.py │ ├── vanity_plates.py │ ├── variance_in_array_of_words.py │ ├── vowel_shifting.py │ ├── well_efficiency_calculator.py │ ├── what_color_is_your_name.py │ ├── what_day_is_it.py │ ├── where_am_i.py │ ├── which_string_is_worth_more.py │ ├── who_ate_the_cookie.py │ ├── who_took_the_car_key.py │ ├── yes_no_yes_no.py │ └── your_basic_fizzbuzz_kata.py ├── incomplete │ ├── base64_numeric_translator.py │ ├── bouncing_balls.py │ ├── deja_vu_duplicates.py │ ├── fill_in_the_gaps_in_my_timesheet.py │ ├── my_kata.py │ ├── pagination_helper.py │ ├── password_validator.py │ ├── select_the_wanted_products.py │ ├── the_generals_orders.py │ ├── up_and_down.py │ ├── vigenere_cipher_helper.py │ ├── vowel_alternations.py │ ├── when_greatest_is_less_than_smallest.py │ └── word_wrap.py ├── kyu_3 │ ├── __init__.py │ ├── base64_encoding.py │ ├── calculator.py │ ├── did_you_mean.py │ └── finding_an_appointment.py ├── kyu_4 │ ├── __init__.py │ ├── breadcrumb_generator.py │ ├── coordinates_validator.py │ ├── human_readable_duration_format.py │ ├── ip_validation.py │ ├── nesting_structure_comparison.py │ ├── next_bigger_number_with_same_digits.py │ ├── permutations.py │ ├── pick_peaks.py │ ├── recover_a_secret_string_from_random_triplets.py │ ├── roman_numerals_decoder.py │ ├── roman_numerals_encoder.py │ ├── roman_numerals_helper.py │ ├── snail.py │ ├── strings_mix.py │ ├── strip_comments.py │ ├── strip_url_params.py │ ├── sudoku_solution_validator.py │ ├── the_observed_pin.py │ └── valid_braces.py ├── kyu_5 │ ├── __init__.py │ ├── airport_arrivals_departures_1.py │ ├── all_that_is_open_must_be_closed.py │ ├── ascii_hex_converter.py │ ├── best_travel.py │ ├── by_the_power_set_of_castle_grayskull.py │ ├── caesar_cipher_helper.py │ ├── convert_pascalcase_to_snake_case.py │ ├── convert_string_to_camelcase.py │ ├── delta_bits.py │ ├── did_i_finish_my_sudoku.py │ ├── directions_reduction.py │ ├── excels_countif_sumif_averageif_functions.py │ ├── extract_domain_name_from_url.py │ ├── find_the_missing_term_in_an_arithmetic_progression.py │ ├── first_non_repeating_letter.py │ ├── first_variation_on_caesar_cipher.py │ ├── human_readable_time.py │ ├── integer_to_english.py │ ├── josephus_permutation.py │ ├── largest_5_digit_number_in_a_series.py │ ├── least_common_multiple.py │ ├── luck_check.py │ ├── maximum_subarray_sum.py │ ├── metric_units_1.py │ ├── mod4_regex.py │ ├── mongodb_objectid.py │ ├── ninja_vs_samurai_attack_block.py │ ├── not_very_secure.py │ ├── ookkk_ok_o_ook_ok_ooo.py │ ├── palindrome_chain_length.py │ ├── pete_the_baker.py │ ├── phone_directory.py │ ├── prefill_an_array.py │ ├── readability_is_king.py │ ├── reversi_row_rudiments.py │ ├── rgb_to_hex_conversion.py │ ├── rot13.py │ ├── rot_13.py │ ├── scramblies.py │ ├── second_variation_on_caesar_cipher.py │ ├── secret_knock.py │ ├── simple_pig_latin.py │ ├── sum_of_pairs.py │ ├── tic_tac_toe_checker.py │ ├── two_joggers.py │ ├── valid_date_regex.py │ ├── valid_parenthesis.py │ ├── vector_class.py │ ├── weight_for_weight.py │ └── where_my_anagrams_at.py ├── kyu_6 │ ├── __init__.py │ ├── acronym_buster.py │ ├── adding_binary_numbers.py │ ├── almost_even.py │ ├── alternating_loops.py │ ├── arabian_string.py │ ├── are_they_the_same.py │ ├── array_diff.py │ ├── autocomplete_yay.py │ ├── balance_the_arrays.py │ ├── binary_to_text_conversion.py │ ├── binding_within_the_list_monad.py │ ├── bit_counting.py │ ├── build_tower.py │ ├── calculate_string_rotation.py │ ├── cambridge_word_scramble.py │ ├── cat_and_mouse_harder_version.py │ ├── character_frequency.py │ ├── checking_groups.py │ ├── classy_instance_1.py │ ├── collatz.py │ ├── compare_versions.py │ ├── consecutive_strings.py │ ├── counting_duplicates.py │ ├── cryptography_1_viva_cesare.py │ ├── custom_array_filters.py │ ├── dashatize_it.py │ ├── dbftbs_djqifs.py │ ├── decipher_this.py │ ├── decode_the_morse_code.py │ ├── delete_nth_occurrence.py │ ├── detect_pangram.py │ ├── digital_root.py │ ├── divisible_ints.py │ ├── dna_sequence_tester.py │ ├── does_my_number_look_big_in_this.py │ ├── dont_drink_the_water.py │ ├── dont_rely_on_luck.py │ ├── drunk_friend.py │ ├── dubstep.py │ ├── duplicate_encoder.py │ ├── ease_the_stockbroker.py │ ├── eighties_kids_4_legends_of_the_hidden_temple.py │ ├── eighties_kids_7_shes_a_small_wonder.py │ ├── english_to_enigeliisohe.py │ ├── equal_sides_of_an_array.py │ ├── evil_autocorrect_prank.py │ ├── exercise_in_summing.py │ ├── find_the_divisors.py │ ├── find_the_mine.py │ ├── find_the_missing_letter.py │ ├── find_the_odd_int.py │ ├── find_the_parity_outlier.py │ ├── fizz_buzz.py │ ├── float_or_integer_verifier.py │ ├── format_a_string_of_names.py │ ├── function_composition.py │ ├── function_iteration.py │ ├── get_all_possible_anagrams_from_a_hash.py │ ├── give_me_diamond.py │ ├── good_vs_evil.py │ ├── greatest_position_distance.py │ ├── group_in_10s.py │ ├── group_repeating_fractions.py │ ├── grouped_by_commas.py │ ├── guess_the_secret_integer.py │ ├── hamming_distance.py │ ├── help_the_bookseller.py │ ├── how_many_reindeers.py │ ├── html_complementary_color.py │ ├── interlace_an_arbitrary_number_of_strings.py │ ├── ipv4_to_int32.py │ ├── iq_test.py │ ├── irreducible_sum_of_rationals.py │ ├── is_prime.py │ ├── jojos_bizarre_kata.py │ ├── keyword_cipher_helper.py │ ├── l33t_greek_case.py │ ├── lambdas_as_mechanism_for_open_closed.py │ ├── leap_year_with_restrictions.py │ ├── length_of_missing_array.py │ ├── linked_lists_length_and_count.py │ ├── longest_2_character_substring.py │ ├── longest_palindrome.py │ ├── lotto_6_of_49.py │ ├── matrix_expanding.py │ ├── midpoint_sum.py │ ├── most_improved.py │ ├── multi_tap_keypad_text_entry.py │ ├── multiples_of_3_and_5.py │ ├── multiplication_tables.py │ ├── nested_list_depth.py │ ├── next_version.py │ ├── number_shortening_filter.py │ ├── objectify_all_the_strings.py │ ├── odd_even_num_of_divisors.py │ ├── parse_the_log.py │ ├── patterncraft_strategy.py │ ├── persistent_bugger.py │ ├── pingpong_service_problem.py │ ├── playing_with_digits.py │ ├── playing_with_passphrases.py │ ├── polybius_square_cipher_encode.py │ ├── pretty_date.py │ ├── prize_draw.py │ ├── rainfall.py │ ├── random_integers.py │ ├── rank_vector.py │ ├── regexp_basics_is_it_ipv4_address.py │ ├── regexp_basics_parsing_integers.py │ ├── regexp_basics_parsing_mana_cost.py │ ├── regexp_basics_parsing_time.py │ ├── remove_anchor_from_url.py │ ├── repeated_substring.py │ ├── replace_wth_alphabet_position.py │ ├── reverse_or_rotate.py │ ├── reverse_words.py │ ├── reversed_words.py │ ├── rna_to_protein.py │ ├── rotate_array.py │ ├── rotation_cipher_cracker.py │ ├── round_by_half_steps.py │ ├── run_length_encoding.py │ ├── salesmans_travel.py │ ├── same_array.py │ ├── scrabble_best_word.py │ ├── secret_message.py │ ├── sequences_and_series.py │ ├── simple_card_game.py │ ├── simple_sentences.py │ ├── simple_substitution_cipher_helper.py │ ├── single_word_pig_latin.py │ ├── split_strings.py │ ├── square_n_sum.py │ ├── statistics_for_an_athletic_association.py │ ├── stop_spinning_my_words.py │ ├── street_fighter_2_character_selection.py │ ├── string_searching_with_wildcard.py │ ├── string_shortener_shrink.py │ ├── string_suffixes.py │ ├── sum_consecutives.py │ ├── summarize_ranges.py │ ├── take_a_num_and_sum_digits_to_consecutive_powers.py │ ├── telephone_words.py │ ├── temperature_converter.py │ ├── the_book_of_mormon.py │ ├── the_shell_game.py │ ├── title_case.py │ ├── triple_trouble.py │ ├── ttt17_split_odd_and_even.py │ ├── turkish_national_identity_number.py │ ├── two_sum.py │ ├── unary_function_chainer.py │ ├── unique_in_order.py │ ├── unusual_sort.py │ ├── urban_dictionary.py │ ├── valid_phone_numbers.py │ ├── validate_credit_card_number.py │ ├── weird_string_case.py │ ├── what_adds_up.py │ ├── what_century_is_it.py │ ├── what_is_the_point.py │ ├── what_will_be_the_odd_one_out.py │ ├── wheel_of_fortune.py │ ├── which_are_in.py │ ├── who_likes_it.py │ ├── who_won_the_election.py │ ├── word_a10n.py │ ├── word_patterns.py │ ├── wordify.py │ ├── write_number_in_expanded_form.py │ ├── write_your_own_multiplication_function.py │ ├── your_order_please.py │ └── your_ride_is_here.py ├── kyu_7 │ ├── __init__.py │ ├── a_rule_of_divisibility_by_13.py │ ├── after_midnight.py │ ├── all_inclusive.py │ ├── all_unique.py │ ├── alphabetize_by_nth_char.py │ ├── alternate_square_sum.py │ ├── always_perfect.py │ ├── anagram_detection.py │ ├── anything.py │ ├── are_the_numbers_in_order.py │ ├── are_there_doubles.py │ ├── area_of_a_circle.py │ ├── array_comparator.py │ ├── array_info.py │ ├── author_disambiguation_to_the_point.py │ ├── average_scores.py │ ├── averages_of_numbers.py │ ├── batman_quotes.py │ ├── beginner_series_sum_of_numbers.py │ ├── binary_addition.py │ ├── binary_calculator.py │ ├── bobs_short_forms.py │ ├── boiled_eggs.py │ ├── bouncy_numbers.py │ ├── bug_fixing_algorithmic_predicament.py │ ├── bug_fixing_class_conundrum.py │ ├── bug_fixing_failed_filter.py │ ├── bug_fixing_failed_sort.py │ ├── bug_fixing_reducing_problems.py │ ├── bug_fixing_regex_failure.py │ ├── bug_fixing_unfinished_loop.py │ ├── building_blocks.py │ ├── c_wars.py │ ├── caeser_encryption.py │ ├── caffeine_script.py │ ├── calculate_meal_total.py │ ├── calculate_mean_and_concatenate_string.py │ ├── candy_problem.py │ ├── case_swapping.py │ ├── categorize_new_member.py │ ├── char_code_calculation.py │ ├── char_to_ascii.py │ ├── character_concatenation.py │ ├── character_counter.py │ ├── chessboard.py │ ├── coding_3_min_a_b_c.py │ ├── coding_3_min_to_lover_case.py │ ├── coding_3min_bug_in_apple.py │ ├── coding_3min_father_and_son.py │ ├── collatz_conjecture.py │ ├── colour_association.py │ ├── combine_objects.py │ ├── comfortable_words.py │ ├── common_substrings.py │ ├── compare_strings_by_sum_of_chars.py │ ├── competitive_eating_scoreboard.py │ ├── complementary_dna.py │ ├── composing_squared_strings.py │ ├── compound_array.py │ ├── conference_traveller.py │ ├── consecutive_numbers_needed.py │ ├── convert_improper_fraction_to_mixed_numeral.py │ ├── convert_integer_to_binary.py │ ├── count_consonants.py │ ├── count_the_digit.py │ ├── count_the_ones.py │ ├── countdown_to_christmas.py │ ├── counting_in_the_amazon.py │ ├── counting_occurrence_of_digits.py │ ├── credit_card_checker.py │ ├── credit_card_issuer_checking.py │ ├── credit_card_mask.py │ ├── cyclical_permutation.py │ ├── cyclops_number.py │ ├── dad_is_commatose.py │ ├── debug_basic_calculator.py │ ├── decreasing_inputs.py │ ├── deodorant_evaporator.py │ ├── descending_order.py │ ├── dict_from_two_lists.py │ ├── digitize.py │ ├── disagreeable_ascii.py │ ├── discover_the_original_price.py │ ├── disemvowel_trolls.py │ ├── distance_from_the_average.py │ ├── dna_gc_content.py │ ├── dont_give_me_five.py │ ├── double_char.py │ ├── down_arrow_with_numbers.py │ ├── dropcaps.py │ ├── ean_validation.py │ ├── easy_mathematical_callback.py │ ├── easy_wallpaper.py │ ├── eighties_kids_2_help_alf_find_his_spaceship.py │ ├── eighties_kids_3_punky_brewsters_socks.py │ ├── eighties_kids_5_you_cant_do_that_on_tv.py │ ├── email_address_obfuscator.py │ ├── even_ladder.py │ ├── every_archer_has_its_arrows.py │ ├── every_nth_array_element_basic.py │ ├── excel_sheet_column_numbers.py │ ├── exes_and_ohs.py │ ├── factorial.py │ ├── factorial_factory.py │ ├── filter_coffee.py │ ├── filter_list.py │ ├── filter_long_words.py │ ├── filter_the_number.py │ ├── filter_unused_digits.py │ ├── find_an_employees_role_in_the_company.py │ ├── find_count_of_most_frequent_item_in_array.py │ ├── find_divisors.py │ ├── find_duplicate.py │ ├── find_duplicates.py │ ├── find_factors_of_a_number.py │ ├── find_missing_numbers.py │ ├── find_smallest_int.py │ ├── find_the_capitals.py │ ├── find_the_longest_gap.py │ ├── find_the_motif_in_dna_sequence.py │ ├── find_the_stray_number.py │ ├── find_the_volume_of_a_cone.py │ ├── find_the_vowels.py │ ├── finding_remainder_without_using_modulo.py │ ├── first_class_function_factory.py │ ├── fizz_buzz.py │ ├── flatten.py │ ├── formatting_decimal_places_1.py │ ├── frequency_sequence.py │ ├── from_to_step_sequence_generator.py │ ├── fuel_economy_converter.py │ ├── functional_addition.py │ ├── gauss_needs_help.py │ ├── genetic_algorithm_series_1_generate.py │ ├── genetic_algorithm_series_2_mutation.py │ ├── genetic_algorithm_series_crossover.py │ ├── ghostbusters_whitespace_removal.py │ ├── gradually_adding_parameters.py │ ├── greatest_common_divisor.py │ ├── greatest_difference.py │ ├── green_glass_door.py │ ├── grid_blast.py │ ├── growth_of_a_population.py │ ├── guess_my_number.py │ ├── hamming_distance_binary_codes.py │ ├── head_tail_init_last.py │ ├── help_mr_e.py │ ├── help_suzuki_count_his_vegetables.py │ ├── help_suzuki_rake_his_garden.py │ ├── highest_and_lowest.py │ ├── highest_profit.py │ ├── hit_count.py │ ├── holiday_v_seasick_snorkelling.py │ ├── how_far_will_i_go.py │ ├── how_many_are_smaller_than_me.py │ ├── html_generator.py │ ├── identical_elements.py │ ├── insert_dashes.py │ ├── integer_difference.py │ ├── integer_to_currency_format.py │ ├── interactive_dictionary.py │ ├── invalid_input_error_handling_1.py │ ├── is_divisible.py │ ├── is_every_value_in_the_array_an_array.py │ ├── is_prime.py │ ├── is_this_a_triangle.py │ ├── is_valid_identifier.py │ ├── isograms.py │ ├── jaden_casing_strings.py │ ├── javascript_filter_1.py │ ├── katastrophe.py │ ├── keep_the_order.py │ ├── keypad_horror.py │ ├── largest_elements.py │ ├── last_man_standing.py │ ├── lazily_executing_a_function.py │ ├── leap_years.py │ ├── left_and_right.py │ ├── length_of_a_vector.py │ ├── length_of_line_segment.py │ ├── length_of_sequence.py │ ├── linked_lists_get_nth_node.py │ ├── linked_lists_push_and_build_123.py │ ├── looking_for_a_benefactor.py │ ├── lorraine_wants_to_win_tv_contest.py │ ├── make_a_function_that_does_arithmetic.py │ ├── make_acronym.py │ ├── make_backronym.py │ ├── make_them_bark.py │ ├── making_copies.py │ ├── maximum_length_difference.py │ ├── mobile_operator_detector.py │ ├── money_money_money.py │ ├── monotone_travel.py │ ├── more_than_zero.py │ ├── morse_code_encryption.py │ ├── most_frequent_elements.py │ ├── moves_in_squared_strings_one.py │ ├── multiply_characters.py │ ├── mumbling.py │ ├── narcissistic_numbers.py │ ├── nato_phonetic_alphabet.py │ ├── naughty_or_nice.py │ ├── new_5_pound_notes_collectors.py │ ├── ninja_vs_samurai_strike.py │ ├── noobcode_4_hot_singles.py │ ├── noonerize_me.py │ ├── not_all_but_sometimes_all.py │ ├── number_encrypting_cypher.py │ ├── number_of_occurrences.py │ ├── number_pairs.py │ ├── number_star_ladder.py │ ├── numbers_to_letters.py │ ├── numbers_with_this_digit_inside.py │ ├── nums_powers_of_digits_equal_num.py │ ├── odd_ladder.py │ ├── operations_with_sets.py │ ├── ordering_the_words.py │ ├── pair_zeros.py │ ├── paperboy.py │ ├── parallelogram.py │ ├── partial_word_searching.py │ ├── parts_of_a_list.py │ ├── pattern_1.py │ ├── pattern_2.py │ ├── pattern_3.py │ ├── pattern_4.py │ ├── patterncraft_visitor.py │ ├── pauls_misery.py │ ├── penultimate.py │ ├── perfect_number_verifier.py │ ├── perfect_squares_perfect_fun.py │ ├── permutation_average.py │ ├── pillow_on_the_fridge.py │ ├── please_help_bob.py │ ├── power_of_4.py │ ├── power_of_two.py │ ├── printer_errors.py │ ├── product_of_main_diagonal.py │ ├── pythons_dynamic_classes_1.py │ ├── radians_to_degrees.py │ ├── radio_dj_helper_function.py │ ├── random_case.py │ ├── recursive_reverse_string.py │ ├── reduce_my_fraction.py │ ├── regex_validate_pin_code.py │ ├── regexp_basics_is_eight_bit_number.py │ ├── regexp_basics_is_it_all_whitespace.py │ ├── regexp_basics_parsing_prices.py │ ├── regexp_fun_1_when_i_miss_few_days_of_gym.py │ ├── remove_all_marked_elements_of_list.py │ ├── remove_duplicates.py │ ├── remove_the_minimum.py │ ├── replace_all_items.py │ ├── return_a_sorted_list_of_objects.py │ ├── return_string_of_first_characters.py │ ├── return_the_closest_number_multiple_of_10.py │ ├── reverse_it.py │ ├── reversed_strings.py │ ├── reversing_fun.py │ ├── rotate_for_a_max.py │ ├── rule_of_divisibility_by_7.py │ ├── ruplesjs_3_string_eachchar.py │ ├── russian_postal_codes.py │ ├── satisfying_numbers.py │ ├── scaling_squared_strings.py │ ├── scoring_tests.py │ ├── selective_fear_of_numbers.py │ ├── self_descriptive_numbers.py │ ├── sentence_to_words.py │ ├── sequence_sum.py │ ├── sexy_primes.py │ ├── share_prices.py │ ├── shaving_the_beard.py │ ├── shorter_concat.py │ ├── shortest_word.py │ ├── show_multiples_of_two_numbers_within_a_range.py │ ├── silly_case.py │ ├── simple_elevator.py │ ├── simple_sequence_validator.py │ ├── simple_template.py │ ├── sir_show_me_your_id.py │ ├── slope_of_a_line.py │ ├── some_circles.py │ ├── sort_by_example.py │ ├── sort_numbers.py │ ├── sorted_union.py │ ├── sorted_yes_no_how.py │ ├── sorting_dictionaries.py │ ├── speed_control.py │ ├── split_the_bill.py │ ├── spoonerize_me.py │ ├── sports_league_table_help_local_team.py │ ├── square_digits.py │ ├── string_basics.py │ ├── string_chunks.py │ ├── string_ends_with.py │ ├── string_reversing_changing_case.py │ ├── string_to_integer_conversion.py │ ├── strive_matching_2.py │ ├── sum_factorial.py │ ├── sum_first_nth_term_of_series.py │ ├── sum_of_all_arguments.py │ ├── sum_of_numbers_from_zero_to_n.py │ ├── sum_squares_of_numbers_in_list_that_may_contain_more_lists.py │ ├── sum_up_the_random_string.py │ ├── summing_a_numbers_digits.py │ ├── supernatural.py │ ├── suzuki_needs_help_lining_up_his_students.py │ ├── switcheroo.py │ ├── tax_calculator.py │ ├── terminal_game_2.py │ ├── the_barksdale_code.py │ ├── the_coins_of_ter.py │ ├── the_ladies_of_eniac.py │ ├── the_mean_of_two_means.py │ ├── the_most_amicable_of_numbers.py │ ├── the_office_1_outed.py │ ├── the_office_3_broken_photocopier.py │ ├── the_old_switcheroo.py │ ├── the_old_switcheroo_2.py │ ├── the_owls_are_not_what_they_seem.py │ ├── thinkful_string_drills_poem_formatter.py │ ├── thinking_and_testing_a_and_b.py │ ├── thinking_and_testing_how_many_word.py │ ├── thinking_and_testing_something_capitalized.py │ ├── thinking_and_testing_sport_star.py │ ├── thinking_and_testing_true_or_false.py │ ├── time_converter_hh_mm_ss_ms.py │ ├── time_degrees.py │ ├── to_leet_speak.py │ ├── transpose_two_strings_in_an_array.py │ ├── triangular_range.py │ ├── triangular_treasure.py │ ├── truncate_a_string.py │ ├── tube_strike_options_calculator.py │ ├── two_to_one.py │ ├── unflatten_a_list.py │ ├── unique_pairs.py │ ├── unlimited_sum.py │ ├── unlucky_days.py │ ├── unpacking_arguments.py │ ├── uvb76_message_validator.py │ ├── vampire_numbers.py │ ├── volume_of_a_cup.py │ ├── vowel_count.py │ ├── what_dominates_your_array.py │ ├── what_is_my_name_score_1.py │ ├── where_is_vasya.py │ ├── where_is_wally.py │ ├── x_to_y_of_z.py │ ├── xmas_tree.py │ ├── you_are_a_square.py │ ├── zebulans_nightmare.py │ └── zip_it.py ├── kyu_8 │ ├── __init__.py │ ├── a_needle_in_the_haystack.py │ ├── adam_and_eve.py │ ├── add_length.py │ ├── add_more_item_to_list.py │ ├── addition.py │ ├── alternating_case.py │ ├── are_there_any_arrows_left.py │ ├── are_they_opposite.py │ ├── barking_mad.py │ ├── basic_mathematical_operations.py │ ├── beginner_lost_without_a_map.py │ ├── boolean_to_word.py │ ├── broken_greetings.py │ ├── bug_fixing_11.py │ ├── bug_fixing_6.py │ ├── bug_fixing_string_templates.py │ ├── character_frequency.py │ ├── classic_hello_world.py │ ├── classy_extensions.py │ ├── collatz_conjecture.py │ ├── color_ghost.py │ ├── convert_a_string_to_an_array.py │ ├── convert_boolean_to_a_string.py │ ├── convert_natural_num_to_binary.py │ ├── correct_the_mistakes_of_the_character_recognition_software.py │ ├── count_by_x.py │ ├── count_of_positives_sum_of_negatives.py │ ├── count_the_monkeys.py │ ├── counting_sheep.py │ ├── days_in_the_year.py │ ├── determine_offspring_sex_based_on_genes.py │ ├── did_she_say_hello.py │ ├── digitize.py │ ├── dna_to_rna.py │ ├── do_i_get_a_bonus.py │ ├── double_integer.py │ ├── drink_about.py │ ├── duck_duck_goose.py │ ├── even_or_odd.py │ ├── evil_or_odious.py │ ├── fake_binary.py │ ├── find_maximum_and_minimum_values_of_a_list.py │ ├── find_nth_digit_of_a_number.py │ ├── find_the_position.py │ ├── find_the_slope.py │ ├── finish_guess_the_number_game.py │ ├── fix_the_bugs_my_first_kata.py │ ├── fix_your_code_before_the_garden_dies.py │ ├── format_money.py │ ├── formatting_decimal_places_0.py │ ├── freudian_translator.py │ ├── function_within_function.py │ ├── generate_user_links.py │ ├── get_planet_name_by_id.py │ ├── get_the_mean_of_array.py │ ├── get_the_middle_character.py │ ├── grader.py │ ├── grasshopper_array_mean.py │ ├── grasshopper_bug_squashing.py │ ├── grasshopper_combine_strings.py │ ├── grasshopper_debug.py │ ├── grasshopper_grade_book.py │ ├── grasshopper_if_else_syntax_debug.py │ ├── grasshopper_make_change.py │ ├── grasshopper_messi_goals.py │ ├── grasshopper_shopping_list.py │ ├── grasshopper_summation.py │ ├── grasshopper_terminal_game_1.py │ ├── grasshopper_terminal_game_turn_function.py │ ├── grasshopper_variable_assignment_debug.py │ ├── greek_sort.py │ ├── hello_world.py │ ├── hex_to_decimal.py │ ├── how_do_i_compare_numbers.py │ ├── how_good_are_you_really.py │ ├── how_old_will_i_be_in_2099.py │ ├── i_love_you_a_little_a_lot_passionately_not_at_all.py │ ├── is_it_a_number.py │ ├── is_the_string_uppercase.py │ ├── is_there_a_vowel_in_there.py │ ├── is_this_my_tail.py │ ├── is_your_period_late.py │ ├── jennys_secret_msg.py │ ├── kata_example_twist.py │ ├── keep_hydrated.py │ ├── lario_and_muigi_pipe_problem.py │ ├── last.py │ ├── leonardo_dicaprio_and_oscars.py │ ├── lightsabers.py │ ├── localize_the_barycenter.py │ ├── mpg_to_kml.py │ ├── multiply.py │ ├── multiply_the_number.py │ ├── my_head_is_at_the_wrong_end.py │ ├── name_on_billboard.py │ ├── name_shuffler.py │ ├── name_your_python.py │ ├── no_zeros_for_heros.py │ ├── noob_code_1_supersize_me.py │ ├── number_of_people_in_the_bus.py │ ├── number_to_string.py │ ├── object_oriented_piracy.py │ ├── one_hundred_and_one_dalmatians.py │ ├── ones_and_zeros.py │ ├── opposite_number.py │ ├── opposites_attract.py │ ├── player_rank_up.py │ ├── playing_banjo.py │ ├── playing_with_cubes_2.py │ ├── plural.py │ ├── pole_vault_starting_marks.py │ ├── powers_of_2.py │ ├── price_of_mangoes.py │ ├── printing_array_elements_with_comma_delimiters.py │ ├── regex_count_lowercase_letters.py │ ├── regexp_basics_is_it_a_digit.py │ ├── regular_ball_super_ball.py │ ├── remove_exclamation_marks.py │ ├── remove_first_and_last_char_part_two.py │ ├── remove_the_time.py │ ├── removing_elements.py │ ├── repeat_it.py │ ├── return_negative.py │ ├── return_to_sanity.py │ ├── return_two_highest_values_in_list.py │ ├── reverse_list_order.py │ ├── rock_paper_scissors.py │ ├── sentence_smash.py │ ├── sleigh_authentication.py │ ├── smallest_unused_id.py │ ├── square.py │ ├── squash_the_bugs.py │ ├── string_to_number.py │ ├── stringy_strings.py │ ├── strive_matching_1.py │ ├── subtract_the_sum.py │ ├── sum_arrays.py │ ├── sum_mixed_array.py │ ├── sum_without_highest_and_lowest_number.py │ ├── surface_area_and_volume_of_a_box.py │ ├── switch_it_up.py │ ├── the_if_function.py │ ├── the_wide_mouthed_frog.py │ ├── training_js_7_if_else_ternary.py │ ├── transportation_on_vacation.py │ ├── triple_trouble.py │ ├── two_plus_two_times_two.py │ ├── unexpected_parsing.py │ ├── unicode_total.py │ ├── validate_code_with_simple_regex.py │ ├── volume_of_a_cuboid.py │ ├── vowel_remover.py │ ├── watermelon.py │ ├── welcome.py │ ├── welcome_to_the_city.py │ ├── well_of_ideas_easy_version.py │ ├── what_is_between.py │ ├── whats_the_real_floor.py │ ├── whats_wrong_with_these_identifiers.py │ ├── wilson_primes.py │ └── xor_logical_operator.py └── retired │ ├── __init__.py │ └── palindromes.py └── tests ├── __init__.py ├── beta_tests ├── __init__.py ├── test_adding_fractions.py ├── test_addition_function_problem.py ├── test_algebraic_string.py ├── test_alien_beer_morse_code.py ├── test_anagram_or_not.py ├── test_another_one_down.py ├── test_another_one_down_survival_of_fittest.py ├── test_arithmetic_progression.py ├── test_array_2_binary.py ├── test_assignment_2.py ├── test_assignment_3.py ├── test_atm_money_counter.py ├── test_author_disambiguation_a_name_is_a_name.py ├── test_back_to_basics.py ├── test_basic_arabic_to_roman_numerals.py ├── test_beetlejuice_x3_bug_fix.py ├── test_beginner_series_2_clock.py ├── test_beginner_series_cockroach.py ├── test_beginner_series_paperwork.py ├── test_bin_to_decimal.py ├── test_bin_to_hex_and_back.py ├── test_binary_operations_1.py ├── test_binary_pyramid_101.py ├── test_bracket_buster.py ├── test_broken_sequence.py ├── test_bubble_sort.py ├── test_building_spheres.py ├── test_builtin_product_function.py ├── test_caesar_cipher.py ├── test_caesar_cipher_encryption_variation.py ├── test_calculator_with_brackets.py ├── test_capitals_first.py ├── test_cat_and_mouse_easy_version.py ├── test_cat_kata_part_1.py ├── test_chuck_norris_v_body_count.py ├── test_circular_primes.py ├── test_closest_neighbouring_points.py ├── test_closest_sum.py ├── test_colored_hexes.py ├── test_compare_section_numbers.py ├── test_compress_encode_a_msg_with_rle.py ├── test_correct_the_time_string.py ├── test_count_consecutive_characters.py ├── test_count_inversions.py ├── test_count_vowels_in_a_string.py ├── test_count_words.py ├── test_countdown_longest_word.py ├── test_counter_of_neighbor_ones.py ├── test_counting_array_elements.py ├── test_crazed_templating.py ├── test_credit_card_validifier.py ├── test_cycle_through_items.py ├── test_data_reverse.py ├── test_decipher_the_cipher.py ├── test_democracy_representation.py ├── test_denumerate_string.py ├── test_digit_sum.py ├── test_dinner_plans.py ├── test_divisible_by_four.py ├── test_doing_your_taxes.py ├── test_duck_shoot_easy_version.py ├── test_dumbphone_keypads.py ├── test_easiest_kata.py ├── test_easy_kata.py ├── test_email_validation.py ├── test_endless_string.py ├── test_esrever_esrever.py ├── test_evening_up_a_workload.py ├── test_exclusive_presentations.py ├── test_file_path_operations.py ├── test_find_all_the_unique_substrings.py ├── test_find_duplicate.py ├── test_find_gcf.py ├── test_find_jon_snow_parents.py ├── test_find_something_in_an_array.py ├── test_find_the_discounted_prices.py ├── test_find_the_gcf_of_two_numbers.py ├── test_find_the_middle_element.py ├── test_finding_averages.py ├── test_first_character_that_repeats.py ├── test_fix_the_base_conversion_function.py ├── test_fix_the_loop.py ├── test_flatten_me.py ├── test_food_combinations.py ├── test_for_loop.py ├── test_format_to_the_second.py ├── test_fractions_class.py ├── test_fractions_of_a_currencies_smallest_value.py ├── test_friend_or_foe.py ├── test_fuel_usage_reporting.py ├── test_fundamentals_return.py ├── test_geometric_progression.py ├── test_get_number_from_string.py ├── test_grasshopper_fantasy_points.py ├── test_grasshopper_if_else_syntax_debug.py ├── test_greeting_my_friends.py ├── test_hail_caesar.py ├── test_heavy_metal_umlauts.py ├── test_help_suzuki_purchase_his_tofu.py ├── test_help_the_fruit_guy.py ├── test_herons_formula.py ├── test_hollow_triangle.py ├── test_how_many_minutes.py ├── test_how_many_numbers.py ├── test_how_many_stairs_will_suzuki_climb_in_20_years.py ├── test_how_many_times_does_it_contain.py ├── test_how_many_times_should_i_go.py ├── test_how_much_coffee_do_you_need.py ├── test_how_much_hex_is_the_fish.py ├── test_how_sexy_is_your_name.py ├── test_identify_case.py ├── test_identifying_top_users_and_their_corresponding_purchases.py ├── test_is_n_divisible_by_x_y.py ├── test_jacobs_weight_loss_program.py ├── test_keep_it_short_with_restrictions.py ├── test_keep_up_the_hoop.py ├── test_knight_or_knave.py ├── test_kontti_language.py ├── test_lets_flat_them_out.py ├── test_lightswitches.py ├── test_list_length_v1.py ├── test_list_length_v2.py ├── test_logical_and_nonnegative_matrix.py ├── test_logical_calculator.py ├── test_logistic_map.py ├── test_loose_change.py ├── test_loose_change_.py ├── test_lowest_product_of_4_consecutive_nums.py ├── test_make_acronym.py ├── test_master_of_files.py ├── test_merge_2048.py ├── test_modulus_11_check_digit.py ├── test_most_frequent_weekdays.py ├── test_mtv_cribs.py ├── test_multi_range_iterator.py ├── test_multiples.py ├── test_multiples_2.py ├── test_multiples_by_permutations_1.py ├── test_multiply_list_by_integer_with_restrictions.py ├── test_multiply_two_numbers_without_integers.py ├── test_multiply_without_asterisk.py ├── test_my_first_bug_fixing_kata.py ├── test_name_that_number.py ├── test_naming_files.py ├── test_ninety_degrees_rotation.py ├── test_no_duplicates_here.py ├── test_nothing_special.py ├── test_number_number_wait_letter.py ├── test_number_to_bytes.py ├── test_only_readable_once_list.py ├── test_oracle_coin_method.py ├── test_ordered_count_of_characters.py ├── test_pairing_brackets.py ├── test_palindrome_checker.py ├── test_parse_float.py ├── test_password_maker.py ├── test_phonewords.py ├── test_pirates_are_the_cannons_ready.py ├── test_plus_1_array.py ├── test_pop_shift.py ├── test_print_that_calendar.py ├── test_product_of_largest_pair.py ├── test_professor_oaks_trouble_new_pokedex_prototype.py ├── test_python_one_liner_1_introduction.py ├── test_quicksum.py ├── test_rammstein_needs_your_help.py ├── test_range_parser.py ├── test_re_ordering.py ├── test_remember.py ├── test_remove_duplicates_from_list.py ├── test_remove_first_and_last_character.py ├── test_remove_unnecessary_characters_from_items_in_list.py ├── test_reorganize_the_weapons.py ├── test_replace_multiples_with_string.py ├── test_required_data_1.py ├── test_required_data_2.py ├── test_resistor_color_codes.py ├── test_returning_strings.py ├── test_reverse_complement_dna.py ├── test_reverse_list.py ├── test_reverse_the_number.py ├── test_reversing_words_in_a_string.py ├── test_rigged_dice.py ├── test_rotate_a_square_matrix_in_place.py ├── test_rotated_string.py ├── test_round_to_next_5.py ├── test_sales_report.py ├── test_santas_missing_gift_list.py ├── test_sean_sean_sean.py ├── test_selecting_quotients_from_an_array.py ├── test_separate_filename_from_extension.py ├── test_seven_ate_9.py ├── test_shorted_ipv6_address.py ├── test_simple_barcode_scanner.py ├── test_simple_beads_count.py ├── test_simple_decrypt_algo.py ├── test_simple_decrypt_algo_2.py ├── test_simple_encryption_1_alternating_split.py ├── test_simple_encryption_2_index_difference.py ├── test_small_enough_beginner.py ├── test_sms_shortener.py ├── test_sort_a_massive_list_of_strings.py ├── test_sort_array_by_last_character.py ├── test_sort_deck_of_cards.py ├── test_sort_the_columns_of_a_csv_file.py ├── test_sort_the_odd.py ├── test_sortable_shapes.py ├── test_sorting_integers_into_a_nested_list.py ├── test_spanish_class_help.py ├── test_special_scores_for_words.py ├── test_split_string_by_delimiter.py ├── test_spy_games_rebuild_your_decoder.py ├── test_strange_strings_parser.py ├── test_string_cleaning.py ├── test_string_evaluation.py ├── test_string_incrementer.py ├── test_string_pyramid.py ├── test_string_repeat.py ├── test_string_repetition_without_function.py ├── test_string_to_list_of_integers.py ├── test_strip_my_comments.py ├── test_sum_of_all_arguments.py ├── test_sum_of_list_values.py ├── test_sum_of_numerous_arguments.py ├── test_sum_of_positive.py ├── test_sum_of_two_lowest_integers.py ├── test_sum_of_values_from_1_to_n_inclusive.py ├── test_sum_the_repeats.py ├── test_summations_1.py ├── test_super_duper_easy.py ├── test_swap_row_in_certain_columns_of_a_matrix.py ├── test_syntax_error_array_functions.py ├── test_tail_swap.py ├── test_testing_123.py ├── test_text_align_right.py ├── test_the_animals_went_in_two_by_two.py ├── test_the_office_4_find_a_meeting_room.py ├── test_the_skeptical_kid_generator.py ├── test_this_is_odd.py ├── test_time_for_validation.py ├── test_timer_decorator.py ├── test_to_buy_or_not_to_buy.py ├── test_transpose_of_a_matrix.py ├── test_trigrams.py ├── test_trumpness_detector.py ├── test_two_arrays_one_sort.py ├── test_two_fighters_one_winner.py ├── test_unique_sum.py ├── test_unknown_but_known_variables_addition.py ├── test_unscrambled_eggs.py ├── test_upper_body_strength.py ├── test_valid_hk_phone_number.py ├── test_vanity_plates.py ├── test_variance_in_array_of_words.py ├── test_vowel_shifting.py ├── test_well_efficiency_calculator.py ├── test_well_of_ideas_easy_version.py ├── test_what_color_is_your_name.py ├── test_what_day_is_it.py ├── test_where_am_i.py ├── test_which_string_is_worth_more.py ├── test_who_ate_the_cookie.py ├── test_who_took_the_car_key.py ├── test_yes_no_yes_no.py └── test_your_basic_fizzbuzz_kata.py ├── kyu_3_tests ├── __init__.py ├── test_base64_encoding.py ├── test_calculator.py ├── test_did_you_mean.py └── test_finding_an_appointment.py ├── kyu_4_tests ├── __init__.py ├── test_breadcrumb_generator.py ├── test_coordinates_validator.py ├── test_human_readable_duration_format.py ├── test_ip_validation.py ├── test_nesting_structure_comparison.py ├── test_next_bigger_number_with_same_digits.py ├── test_permutations.py ├── test_pick_peaks.py ├── test_recover_a_secret_string_from_random_triplets.py ├── test_roman_numerals_decoder.py ├── test_roman_numerals_encoder.py ├── test_roman_numerals_helper.py ├── test_snail.py ├── test_strings_mix.py ├── test_strip_comments.py ├── test_strip_url_params.py ├── test_sudoku_solution_validator.py ├── test_the_observed_pin.py └── test_valid_braces.py ├── kyu_5_tests ├── __init__.py ├── test_airport_arrivals_departures_1.py ├── test_all_that_is_open_must_be_closed.py ├── test_ascii_hex_converter.py ├── test_best_travel.py ├── test_by_the_power_set_of_castle_grayskull.py ├── test_caesar_cipher_helper.py ├── test_convert_pascalcase_to_snake_case.py ├── test_convert_string_to_camelcase.py ├── test_delta_bits.py ├── test_did_i_finish_my_sudoku.py ├── test_directions_reduction.py ├── test_excels_countif_sumif_averageif_functions.py ├── test_extract_domain_name_from_url.py ├── test_find_the_missing_term_in_an_arithmetic_progression.py ├── test_first_non_repeating_letter.py ├── test_first_variation_on_caesar_cipher.py ├── test_human_readable_time.py ├── test_integer_to_english.py ├── test_josephus_permutation.py ├── test_largest_5_digit_number_in_a_series.py ├── test_least_common_multiple.py ├── test_luck_check.py ├── test_maximum_subarray_sum.py ├── test_metric_units_1.py ├── test_mod4_regex.py ├── test_mongodb_objectid.py ├── test_ninja_vs_samurai_attack_block.py ├── test_not_very_secure.py ├── test_ookkk_ok_o_ook_ok_ooo.py ├── test_palindrome_chain_length.py ├── test_pete_the_baker.py ├── test_phone_directory.py ├── test_prefill_an_array.py ├── test_readability_is_king.py ├── test_reversi_row_rudiments.py ├── test_rgb_to_hex_conversion.py ├── test_rot13.py ├── test_rot_13.py ├── test_scramblies.py ├── test_second_variation_on_caesar_cipher.py ├── test_simple_pig_latin.py ├── test_sum_of_pairs.py ├── test_tic_tac_toe_checker.py ├── test_two_joggers.py ├── test_valid_date_regex.py ├── test_valid_parenthesis.py ├── test_vector_class.py ├── test_weight_for_weight.py └── test_where_my_anagrams_at.py ├── kyu_6_tests ├── __init__.py ├── test_acronym_buster.py ├── test_adding_binary_numbers.py ├── test_almost_even.py ├── test_alternating_loops.py ├── test_arabian_string.py ├── test_are_they_the_same.py ├── test_array_diff.py ├── test_autocomplete_yay.py ├── test_balance_the_arrays.py ├── test_binary_to_text_conversion.py ├── test_binding_within_the_list_monad.py ├── test_bit_counting.py ├── test_build_tower.py ├── test_calculation_string_rotation.py ├── test_cambridge_word_scramble.py ├── test_cat_and_mouse_harder_version.py ├── test_character_frequency.py ├── test_checking_groups.py ├── test_classy_instance_1.py ├── test_collatz.py ├── test_compare_versions.py ├── test_consecutive_strings.py ├── test_counting_duplicates.py ├── test_cryptography_1_viva_cesare.py ├── test_custom_array_filters.py ├── test_dashatize_it.py ├── test_dbftbs_djqifs.py ├── test_decipher_this.py ├── test_decode_the_morse_code.py ├── test_delete_nth_occurrence.py ├── test_detect_pangram.py ├── test_digital_root.py ├── test_divisible_ints.py ├── test_dna_sequence_tester.py ├── test_does_my_number_look_big_in_this.py ├── test_dont_drink_the_water.py ├── test_dont_rely_on_luck.py ├── test_drunk_friend.py ├── test_dubstep.py ├── test_duplicate_encoder.py ├── test_ease_the_stockbroker.py ├── test_eighties_kids_4_legends_of_the_hidden_temple.py ├── test_eighties_kids_7_shes_a_small_wonder.py ├── test_english_to_enigeliisohe.py ├── test_equal_sides_of_an_array.py ├── test_evil_autocorrect_prank.py ├── test_exercise_in_summing.py ├── test_find_the_divisors.py ├── test_find_the_mine.py ├── test_find_the_missing_letter.py ├── test_find_the_odd_int.py ├── test_find_the_parity_outlier.py ├── test_fizz_buzz.py ├── test_float_or_integer_verifier.py ├── test_format_a_string_of_names.py ├── test_function_composition.py ├── test_function_iteration.py ├── test_get_all_possible_anagrams_from_a_hash.py ├── test_give_me_diamond.py ├── test_good_vs_evil.py ├── test_greatest_position_distance.py ├── test_group_in_10s.py ├── test_group_repeating_fractions.py ├── test_grouped_by_commas.py ├── test_hamming_distance.py ├── test_help_the_bookseller.py ├── test_how_many_reindeers.py ├── test_html_complementary_color.py ├── test_interlace_an_arbitrary_number_of_strings.py ├── test_ipv4_to_int32.py ├── test_iq_test.py ├── test_irreducible_sum_of_rationals.py ├── test_is_prime.py ├── test_jojos_bizarre_kata.py ├── test_keyword_cipher_helper.py ├── test_l33t_greek_case.py ├── test_lambdas_as_mechanism_for_open_closed.py ├── test_leap_year_with_restrictions.py ├── test_length_of_missing_array.py ├── test_linked_lists_length_and_count.py ├── test_longest_2_character_substring.py ├── test_longest_palindrome.py ├── test_lotto_6_of_49.py ├── test_matrix_expanding.py ├── test_midpoint_sum.py ├── test_most_improved.py ├── test_multi_tap_keypad_text_entry.py ├── test_multiples_of_3_and_5.py ├── test_multiplication_table.py ├── test_nested_list_depth.py ├── test_next_version.py ├── test_number_shortening_filter.py ├── test_objectify_all_the_strings.py ├── test_odd_even_num_of_divisors.py ├── test_parse_the_log.py ├── test_patterncraft_strategy.py ├── test_persistent_bugger.py ├── test_pingpong_service_problem.py ├── test_playing_with_digits.py ├── test_playing_with_passphrases.py ├── test_polybius_square_cipher_encode.py ├── test_pretty_date.py ├── test_prize_draw.py ├── test_rainfall.py ├── test_random_integers.py ├── test_rank_vector.py ├── test_regexp_basics_is_it_ipv4_address.py ├── test_regexp_basics_parsing_integers.py ├── test_regexp_basics_parsing_mana_cost.py ├── test_regexp_basics_parsing_time.py ├── test_remove_anchor_from_url.py ├── test_repeated_substring.py ├── test_replace_with_alphabet_position.py ├── test_reverse_or_rotate.py ├── test_reverse_words.py ├── test_reversed_words.py ├── test_rna_to_protein.py ├── test_rotate_array.py ├── test_rotation_cipher_cracker.py ├── test_round_by_half_steps.py ├── test_run_length_encoding.py ├── test_salesmans_travel.py ├── test_same_array.py ├── test_scrabble_best_word.py ├── test_secret_message.py ├── test_sequences_and_series.py ├── test_simple_card_game.py ├── test_simple_sentences.py ├── test_simple_substitution_cipher_problem.py ├── test_single_word_pig_latin.py ├── test_split_strings.py ├── test_square_n_sum.py ├── test_statistics_for_an_athletic_association.py ├── test_stop_spinning_my_words.py ├── test_street_fighter_2_character_selection.py ├── test_string_searching_with_wildcard.py ├── test_string_shortener_shrink.py ├── test_string_suffixes.py ├── test_sum_consecutives.py ├── test_summarize_ranges.py ├── test_take_a_num_and_sum_digits_to_consecutive_powers.py ├── test_telephone_words.py ├── test_temperature_converter.py ├── test_the_book_of_mormon.py ├── test_the_shell_game.py ├── test_title_case.py ├── test_triple_trouble.py ├── test_ttt17_split_odd_and_even.py ├── test_turkish_national_identity_number.py ├── test_two_sum.py ├── test_unary_function_chainer.py ├── test_unique_in_order.py ├── test_unusual_sort.py ├── test_urban_dictionary.py ├── test_valid_phone_numbers.py ├── test_validate_credit_card_number.py ├── test_weird_string_case.py ├── test_what_adds_up.py ├── test_what_century_is_it.py ├── test_what_is_the_point.py ├── test_what_will_be_the_odd_one_out.py ├── test_wheel_of_fortune.py ├── test_which_are_in.py ├── test_who_likes_it.py ├── test_who_won_the_election.py ├── test_word_a10n.py ├── test_word_patterns.py ├── test_wordify.py ├── test_write_number_in_expanded_form.py ├── test_write_your_own_multiplication_function.py ├── test_your_order_please.py └── test_your_ride_is_here.py ├── kyu_7_tests ├── __init__.py ├── test_a_rule_of_divisibility_by_13.py ├── test_after_midnight.py ├── test_all_inclusive.py ├── test_all_unique.py ├── test_alphabetize_by_nth_char.py ├── test_alternate_square_sum.py ├── test_always_perfect.py ├── test_anagram_detection.py ├── test_anything.py ├── test_are_the_numbers_in_order.py ├── test_are_there_doubles.py ├── test_area_of_a_circle.py ├── test_array_comparator.py ├── test_array_info.py ├── test_author_disambiguation_to_the_point.py ├── test_average_scores.py ├── test_averages_of_numbers.py ├── test_batman_quotes.py ├── test_beginner_series_sum_of_numbers.py ├── test_binary_addition.py ├── test_binary_calculator.py ├── test_bobs_short_forms.py ├── test_boiled_eggs.py ├── test_bouncy_numbers.py ├── test_bug_fixing_algorithmic_predicament.py ├── test_bug_fixing_class_conundrum.py ├── test_bug_fixing_failed_filter.py ├── test_bug_fixing_failed_sort.py ├── test_bug_fixing_reducing_problems.py ├── test_bug_fixing_regex_failure.py ├── test_bug_fixing_unfinished_loop.py ├── test_building_blocks.py ├── test_c_wars.py ├── test_caeser_encryption.py ├── test_caffeine_script.py ├── test_calculate_meal_total.py ├── test_calculate_mean_and_concatenate_string.py ├── test_candy_problem.py ├── test_case_swapping.py ├── test_categorize_new_member.py ├── test_char_code_calculation.py ├── test_char_to_ascii.py ├── test_character_concatenation.py ├── test_character_counter.py ├── test_chessboard.py ├── test_coding_3_min_a_b_c.py ├── test_coding_3_min_to_lover_case.py ├── test_coding_3min_bug_in_apple.py ├── test_coding_3min_father_and_son.py ├── test_collatz_conjecture.py ├── test_colour_association.py ├── test_combine_objects.py ├── test_comfortable_words.py ├── test_common_substrings.py ├── test_compare_strings_by_sum_of_chars.py ├── test_competitive_eating_scoreboard.py ├── test_complementary_dna.py ├── test_composing_squared_strings.py ├── test_compound_array.py ├── test_conference_traveller.py ├── test_consecutive_numbers_needed.py ├── test_convert_improper_fraction_to_mixed_numeral.py ├── test_convert_integer_to_binary.py ├── test_count_consonants.py ├── test_count_the_digit.py ├── test_count_the_ones.py ├── test_countdown_to_christmas.py ├── test_counting_in_the_amazon.py ├── test_counting_occurrence_of_digits.py ├── test_credit_card_checker.py ├── test_credit_card_issuer_checking.py ├── test_credit_card_mask.py ├── test_cyclical_permutation.py ├── test_cyclops_number.py ├── test_dad_is_commatose.py ├── test_debug_basic_calculator.py ├── test_decreasing_inputs.py ├── test_deodorant_evaporator.py ├── test_descending_order.py ├── test_dict_from_two_lists.py ├── test_digitize.py ├── test_disagreeable_ascii.py ├── test_discover_the_original_price.py ├── test_disemvowel_trolls.py ├── test_distance_from_the_average.py ├── test_dna_gc_content.py ├── test_dont_give_me_five.py ├── test_double_char.py ├── test_down_arrow_with_numbers.py ├── test_dropcaps.py ├── test_ean_validation.py ├── test_easy_mathematical_callback.py ├── test_easy_wallpaper.py ├── test_eighties_kids_2_help_alf_find_his_spaceship.py ├── test_eighties_kids_3_punky_brewsters_socks.py ├── test_eighties_kids_5_you_cant_do_that_on_tv.py ├── test_email_address_obfuscator.py ├── test_even_ladder.py ├── test_every_archer_has_its_arrows.py ├── test_every_nth_array_element_basic.py ├── test_excel_sheet_column_numbers.py ├── test_exes_and_ohs.py ├── test_factorial.py ├── test_factorial_factory.py ├── test_filter_coffee.py ├── test_filter_list.py ├── test_filter_long_words.py ├── test_filter_the_number.py ├── test_filter_unused_digits.py ├── test_find_an_employees_role_in_the_company.py ├── test_find_count_of_most_frequent_item_in_array.py ├── test_find_divisors.py ├── test_find_duplicate.py ├── test_find_duplicates.py ├── test_find_factors_of_a_number.py ├── test_find_missing_numbers.py ├── test_find_smallest_int.py ├── test_find_the_capitals.py ├── test_find_the_longest_gap.py ├── test_find_the_motif_in_dna_sequence.py ├── test_find_the_stray_number.py ├── test_find_the_volume_of_a_cone.py ├── test_find_the_vowels.py ├── test_finding_remainder_without_using_modulo.py ├── test_first_class_function_factory.py ├── test_fizz_buzz.py ├── test_flatten.py ├── test_formatting_decimal_places_1.py ├── test_frequency_sequence.py ├── test_from_to_step_sequence_generator.py ├── test_fuel_economy_converter.py ├── test_functional_addition.py ├── test_gauss_needs_help.py ├── test_genetic_algorithm_series_1_generate.py ├── test_genetic_algorithm_series_2_mutation.py ├── test_genetic_algorithm_series_crossover.py ├── test_ghostbusters_whitespace_removal.py ├── test_gradually_adding_parameters.py ├── test_greatest_common_divisor.py ├── test_greatest_difference.py ├── test_green_glass_door.py ├── test_grid_blast.py ├── test_growth_of_a_population.py ├── test_guess_my_number.py ├── test_hamming_distance_binary_codes.py ├── test_head_tail_init_last.py ├── test_help_mr_e.py ├── test_help_suzuki_count_his_vegetables.py ├── test_help_suzuki_rake_his_garden.py ├── test_highest_and_lowest.py ├── test_highest_profit.py ├── test_hit_count.py ├── test_holiday_v_seasick_snorkelling.py ├── test_how_far_will_i_go.py ├── test_how_many_are_smaller_than_me.py ├── test_html_generator.py ├── test_identical_elements.py ├── test_insert_dashes.py ├── test_integer_difference.py ├── test_integer_to_currency_format.py ├── test_interactive_dictionary.py ├── test_invalid_input_error_handling_1.py ├── test_is_divisible.py ├── test_is_every_value_in_the_array_an_array.py ├── test_is_prime.py ├── test_is_this_a_triangle.py ├── test_is_valid_identifier.py ├── test_isograms.py ├── test_jaden_casing_strings.py ├── test_javascript_filter_1.py ├── test_katastrophe.py ├── test_keep_the_order.py ├── test_keypad_horror.py ├── test_largest_elements.py ├── test_last_man_standing.py ├── test_lazily_executing_a_function.py ├── test_leap_years.py ├── test_left_and_right.py ├── test_length_of_a_vector.py ├── test_length_of_line_segment.py ├── test_length_of_sequence.py ├── test_linked_lists_get_nth_node.py ├── test_linked_lists_push_and_build_123.py ├── test_looking_for_a_benefactor.py ├── test_lorraine_wants_to_win_tv_contest.py ├── test_make_a_function_that_does_arithmetic.py ├── test_make_acronym.py ├── test_make_backronym.py ├── test_make_them_bark.py ├── test_making_copies.py ├── test_maximum_length_difference.py ├── test_mobile_operator_detector.py ├── test_money_money_money.py ├── test_monotone_travel.py ├── test_more_than_zero.py ├── test_morse_code_encryption.py ├── test_most_frequent_elements.py ├── test_moves_in_squared_strings_one.py ├── test_multiply_characters.py ├── test_mumbling.py ├── test_narcissistic_numbers.py ├── test_nato_phonetic_alphabet.py ├── test_naughty_or_nice.py ├── test_new_5_pound_notes_collectors.py ├── test_ninja_vs_samurai_strike.py ├── test_noobcode_4_hot_singles.py ├── test_noonerize_me.py ├── test_not_all_but_sometimes_all.py ├── test_number_encrypting_cypher.py ├── test_number_of_occurrences.py ├── test_number_pairs.py ├── test_number_star_ladder.py ├── test_numbers_to_letters.py ├── test_numbers_with_this_digit_inside.py ├── test_nums_powers_of_digits_equal_num.py ├── test_odd_ladder.py ├── test_operations_with_sets.py ├── test_ordering_the_words.py ├── test_pair_zeros.py ├── test_paperboy.py ├── test_parallelogram.py ├── test_partial_word_searching.py ├── test_parts_of_a_list.py ├── test_pattern_1.py ├── test_pattern_2.py ├── test_pattern_3.py ├── test_pattern_4.py ├── test_patterncraft_visitor.py ├── test_pauls_misery.py ├── test_penultimate.py ├── test_perfect_number_verifier.py ├── test_perfect_squares_perfect_fun.py ├── test_permutation_average.py ├── test_pillow_on_the_fridge.py ├── test_please_help_bob.py ├── test_power_of_4.py ├── test_power_of_two.py ├── test_printer_errors.py ├── test_product_of_main_diagonal.py ├── test_pythons_dynamic_classes_1.py ├── test_radians_to_degrees.py ├── test_radio_dj_helper_function.py ├── test_recursive_reverse_string.py ├── test_reduce_my_fraction.py ├── test_regex_validate_pin_code.py ├── test_regexp_basics_is_eight_bit_number.py ├── test_regexp_basics_is_it_all_whitespace.py ├── test_regexp_basics_parsing_prices.py ├── test_regexp_fun_1_when_i_miss_few_days_of_gym.py ├── test_remove_all_marked_elements_of_list.py ├── test_remove_duplicates.py ├── test_remove_the_minimum.py ├── test_replace_all_items.py ├── test_return_a_sorted_list_of_objects.py ├── test_return_string_of_first_characters.py ├── test_return_the_closest_number_multiple_of_10.py ├── test_reverse_it.py ├── test_reversed_strings.py ├── test_reversing_fun.py ├── test_rotate_for_a_max.py ├── test_rule_of_divisibility_by_7.py ├── test_ruplesjs_3_string_eachchar.py ├── test_russian_postal_codes.py ├── test_satisfying_numbers.py ├── test_scaling_squared_strings.py ├── test_scoring_tests.py ├── test_selective_fear_of_numbers.py ├── test_self-descriptive_numbers.py ├── test_sentence_to_words.py ├── test_sequence_sum.py ├── test_sexy_primes.py ├── test_share_prices.py ├── test_shaving_the_beard.py ├── test_shorter_concat.py ├── test_shortest_word.py ├── test_show_multiples_of_two_numbers_within_a_range.py ├── test_silly_case.py ├── test_simple_elevator.py ├── test_simple_sequence_validator.py ├── test_simple_template.py ├── test_sir_show_me_your_id.py ├── test_slope_of_a_line.py ├── test_some_circles.py ├── test_sort_by_example.py ├── test_sort_numbers.py ├── test_sorted_union.py ├── test_sorted_yes_no_how.py ├── test_sorting_dictionaries.py ├── test_speed_control.py ├── test_split_the_bill.py ├── test_spoonerize_me.py ├── test_sports_league_table_help_local_team.py ├── test_square_digits.py ├── test_string_basics.py ├── test_string_chunks.py ├── test_string_ends_with.py ├── test_string_reversing_changing_case.py ├── test_string_to_integer_conversion.py ├── test_strive_matching_2.py ├── test_sum_factorial.py ├── test_sum_first_nth_term_of_series.py ├── test_sum_of_all_arguments.py ├── test_sum_of_numbers_from_zero_to_n.py ├── test_sum_squares_of_numbers_in_list_that_may_contain_more_lists.py ├── test_sum_up_the_random_string.py ├── test_summing_a_numbers_digits.py ├── test_supernatural.py ├── test_suzuki_needs_help_lining_up_his_students.py ├── test_switcheroo.py ├── test_tax_calculator.py ├── test_the_barksdale_code.py ├── test_the_coins_of_ter.py ├── test_the_ladies_of_eniac.py ├── test_the_mean_of_two_means.py ├── test_the_most_amicable_of_numbers.py ├── test_the_office_1_outed.py ├── test_the_office_3_broken_photocopier.py ├── test_the_old_switcheroo.py ├── test_the_old_switcheroo_2.py ├── test_the_owls_are_not_what_they_seem.py ├── test_thinkful_string_drills_poem_formatter.py ├── test_thinking_and_testing_a_and_b.py ├── test_thinking_and_testing_how_many_word.py ├── test_thinking_and_testing_something_capitalized.py ├── test_thinking_and_testing_sport_star.py ├── test_thinking_and_testing_true_or_false.py ├── test_time_converter_hh_mm_ss_ms.py ├── test_time_degrees.py ├── test_to_leet_speak.py ├── test_transpose_two_strings_in_an_array.py ├── test_triangular_range.py ├── test_triangular_treasure.py ├── test_truncate_a_string.py ├── test_tube_strike_options_calculator.py ├── test_two_to_one.py ├── test_unflatten_a_list.py ├── test_unique_pairs.py ├── test_unlimited_sum.py ├── test_unlucky_days.py ├── test_unpacking_arguments.py ├── test_uvb76_message_validator.py ├── test_vampire_numbers.py ├── test_volume_of_a_cup.py ├── test_vowel_count.py ├── test_what_dominates_your_array.py ├── test_what_is_my_name_score_1.py ├── test_where_is_vasya.py ├── test_where_is_wally.py ├── test_x_to_y_of_z.py ├── test_xmas_tree.py ├── test_you_are_a_square.py ├── test_zebulans_nightmare.py └── test_zip_it.py ├── kyu_8_tests ├── __init__.py ├── test_a_needle_in_the_haystack.py ├── test_adam_and_eve.py ├── test_add_length.py ├── test_add_more_item_to_list.py ├── test_addition.py ├── test_alternating_case.py ├── test_are_there_any_arrows_left.py ├── test_are_they_opposite.py ├── test_barking_mad.py ├── test_basic_mathematical_operations.py ├── test_beginner_lost_without_a_map.py ├── test_boolean_to_word.py ├── test_broken_greetings.py ├── test_bug_fixing_11.py ├── test_bug_fixing_6.py ├── test_bug_fixing_string_templates.py ├── test_character_frequency.py ├── test_classy_extensions.py ├── test_collatz_conjecture.py ├── test_color_ghost.py ├── test_convert_a_string_to_an_array.py ├── test_convert_boolean_to_a_string.py ├── test_convert_natural_num_to_binary.py ├── test_correct_the_mistakes_of_the_character_recognition_software.py ├── test_count_by_x.py ├── test_count_of_positives_sum_of_negatives.py ├── test_count_the_monkeys.py ├── test_counting_sheep.py ├── test_days_in_the_year.py ├── test_determine_offspring_sex_based_on_genes.py ├── test_did_she_say_hello.py ├── test_digitize.py ├── test_dna_to_rna.py ├── test_do_i_get_a_bonus.py ├── test_double_integer.py ├── test_drink_about.py ├── test_duck_duck_goose.py ├── test_even_or_odd.py ├── test_evil_or_odious.py ├── test_fake_binary.py ├── test_find_maximum_and_minimum_values_of_a_list.py ├── test_find_nth_digit_of_a_number.py ├── test_find_the_position.py ├── test_find_the_slope.py ├── test_finish_guess_the_number_game.py ├── test_fix_the_bugs_my_first_kata.py ├── test_fix_your_code_before_the_garden_dies.py ├── test_format_money.py ├── test_formatting_decimal_places_0.py ├── test_freudian_translator.py ├── test_function_within_function.py ├── test_generate_user_links.py ├── test_get_planet_name_by_id.py ├── test_get_the_mean_of_array.py ├── test_get_the_middle_character.py ├── test_grader.py ├── test_grasshopper_array_mean.py ├── test_grasshopper_bug_squashing.py ├── test_grasshopper_combine_strings.py ├── test_grasshopper_debug.py ├── test_grasshopper_grade_book.py ├── test_grasshopper_make_change.py ├── test_grasshopper_messi_goals.py ├── test_grasshopper_shopping_list.py ├── test_grasshopper_summation.py ├── test_grasshopper_terminal_game_1.py ├── test_grasshopper_variable_assignment_debug.py ├── test_greek_sort.py ├── test_hello_world.py ├── test_hex_to_decimal.py ├── test_how_do_i_compare_numbers.py ├── test_how_good_are_you_really.py ├── test_how_old_will_i_be_in_2099.py ├── test_i_love_you_a_little_a_lot_passionately_not_at_all.py ├── test_is_it_a_number.py ├── test_is_the_string_uppercase.py ├── test_is_there_a_vowel_in_there.py ├── test_is_this_my_tail.py ├── test_is_your_period_late.py ├── test_jennys_secret_msg.py ├── test_kata_example_twist.py ├── test_keep_hydrated.py ├── test_lario_and_muigi_pipe_problem.py ├── test_last.py ├── test_leonardo_dicaprio_and_oscars.py ├── test_lightsabers.py ├── test_localize_the_barycenter.py ├── test_mpg_to_kml.py ├── test_multiply.py ├── test_multiply_the_number.py ├── test_my_head_is_at_the_wrong_end.py ├── test_name_on_billboard.py ├── test_name_shuffler.py ├── test_name_your_python.py ├── test_no_zeros_for_heros.py ├── test_noob_code_1_supersize_me.py ├── test_number_of_people_in_the_bus.py ├── test_number_to_string.py ├── test_object_oriented_piracy.py ├── test_one_hundred_and_one_dalmatians.py ├── test_ones_and_zeros.py ├── test_opposite_number.py ├── test_opposites_attract.py ├── test_player_rank_up.py ├── test_playing_banjo.py ├── test_playing_with_cubes_2.py ├── test_plural.py ├── test_pole_vault_starting_marks.py ├── test_powers_of_2.py ├── test_price_of_mangoes.py ├── test_printing_array_elements_with_comma_delimiters.py ├── test_regex_count_lowercase_letters.py ├── test_regexp_basics_is_it_a_digit.py ├── test_regular_ball_super_ball.py ├── test_remove_exclamation_marks.py ├── test_remove_first_and_last_char_part_two.py ├── test_remove_the_time.py ├── test_removing_elements.py ├── test_repeat_it.py ├── test_return_negative.py ├── test_return_to_sanity.py ├── test_return_two_highest_values_in_list.py ├── test_reverse_list_order.py ├── test_rock_paper_scissors.py ├── test_sentence_smash.py ├── test_sleigh_authentication.py ├── test_smallest_unused_id.py ├── test_square.py ├── test_squash_the_bugs.py ├── test_string_to_number.py ├── test_stringy_strings.py ├── test_strive_matching_1.py ├── test_subtract_the_sum.py ├── test_sum_arrays.py ├── test_sum_mixed_array.py ├── test_sum_without_highest_and_lowest_number.py ├── test_surface_area_and_volume_of_a_box.py ├── test_switch_it_up.py ├── test_the_wide_mouthed_frog.py ├── test_training_js_7_if_else_ternary.py ├── test_transportation_on_vacation.py ├── test_triple_trouble.py ├── test_two_plus_two_times_two.py ├── test_unexpected_parsing.py ├── test_unicode_total.py ├── test_validate_code_with_simple_regex.py ├── test_volume_of_a_cuboid.py ├── test_vowel_remover.py ├── test_watermelon.py ├── test_welcome.py ├── test_welcome_to_the_city.py ├── test_what_is_between.py ├── test_whats_the_real_floor.py ├── test_wilson_primes.py └── test_xor_logical_operator.py └── retired_tests ├── __init__.py └── test_palindromes.py /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.7" 4 | before_install: 5 | - pip install pytest-cov 6 | - pip install coveralls 7 | script: 8 | - py.test tests/ --cov tests/ 9 | after_success: 10 | - coveralls 11 | -------------------------------------------------------------------------------- /katas/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/katas/__init__.py -------------------------------------------------------------------------------- /katas/beta/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/katas/beta/__init__.py -------------------------------------------------------------------------------- /katas/beta/adding_fractions.py: -------------------------------------------------------------------------------- 1 | from fractions import Fraction 2 | 3 | 4 | def add_fracs(*args): 5 | return str(sum(Fraction(a) for a in args)) if args else '' 6 | -------------------------------------------------------------------------------- /katas/beta/addition_function_problem.py: -------------------------------------------------------------------------------- 1 | from operator import add 2 | -------------------------------------------------------------------------------- /katas/beta/algebraic_string.py: -------------------------------------------------------------------------------- 1 | # import sys 2 | # 3 | # sys.setrecursionlimit(1700) # currently needed for Python 3 version 4 | 5 | 6 | def sum_prod(str_expression): 7 | return '{:.5e}'.format(eval(str_expression)) 8 | -------------------------------------------------------------------------------- /katas/beta/anagram_or_not.py: -------------------------------------------------------------------------------- 1 | def isAnagram(test, original): 2 | """ is_anagram == PEP8 (forced mixedCase by CodeWars) """ 3 | return sorted(a for a in test.lower() if a.isalnum()) \ 4 | == sorted(b for b in original.lower() if b.isalnum()) 5 | -------------------------------------------------------------------------------- /katas/beta/another_one_down.py: -------------------------------------------------------------------------------- 1 | def check(strng): 2 | if not isinstance(strng, str): 3 | return 'Input is not a string' 4 | -------------------------------------------------------------------------------- /katas/beta/arithmetic_progression.py: -------------------------------------------------------------------------------- 1 | def arithmetic_sequence_elements(a, r, n): 2 | return ', '.join(str(a + b * r) for b in xrange(n)) 3 | -------------------------------------------------------------------------------- /katas/beta/array_2_binary.py: -------------------------------------------------------------------------------- 1 | def arr2bin(arr): 2 | total = 0 3 | for a in arr: 4 | if not type(a) == int: 5 | return False 6 | total += a 7 | return '{:b}'.format(total) 8 | -------------------------------------------------------------------------------- /katas/beta/back_to_basics.py: -------------------------------------------------------------------------------- 1 | def types(x): 2 | return type(x).__name__ 3 | # result = str(type(x)) 4 | # return result[result.find('\'') + 1:-2] 5 | -------------------------------------------------------------------------------- /katas/beta/beetlejuice_x3_bug_fix.py: -------------------------------------------------------------------------------- 1 | def beetle_juice(name): 2 | return '{0} {0} {0}'.format(name) 3 | -------------------------------------------------------------------------------- /katas/beta/beginner_series_2_clock.py: -------------------------------------------------------------------------------- 1 | def past(h, m, s): 2 | return h * 3600000 + m * 60000 + s * 1000 3 | -------------------------------------------------------------------------------- /katas/beta/beginner_series_cockroach.py: -------------------------------------------------------------------------------- 1 | def cockroach_speed(km_h): 2 | return int(km_h / 0.036) # centimeters per second 3 | -------------------------------------------------------------------------------- /katas/beta/beginner_series_paperwork.py: -------------------------------------------------------------------------------- 1 | def paperwork(n, m): 2 | return 0 if n < 0 or m < 0 else n * m 3 | -------------------------------------------------------------------------------- /katas/beta/bin_to_decimal.py: -------------------------------------------------------------------------------- 1 | def bin_to_decimal(inp): 2 | return int(inp, 2) 3 | -------------------------------------------------------------------------------- /katas/beta/binary_operations_1.py: -------------------------------------------------------------------------------- 1 | def flip_bit(num, dex): 2 | return num ^ (1 << dex - 1) 3 | -------------------------------------------------------------------------------- /katas/beta/binary_pyramid_101.py: -------------------------------------------------------------------------------- 1 | BINARY = '{:b}'.format 2 | 3 | 4 | def binary_piramid(m, n): 5 | """ piramid != pyramid, typo is from CodeWars """ 6 | return BINARY(sum(int(BINARY(a)) for a in xrange(m, n + 1))) 7 | -------------------------------------------------------------------------------- /katas/beta/bracket_buster.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | REGEX = re.compile(r'\[(.*?)\]') 4 | 5 | 6 | def bracket_buster(strng): 7 | try: 8 | return REGEX.findall(strng) 9 | except TypeError: 10 | return 'Take a seat on the bench.' 11 | -------------------------------------------------------------------------------- /katas/beta/caesar_cipher_encryption_variation.py: -------------------------------------------------------------------------------- 1 | from string import ascii_lowercase as az 2 | 3 | 4 | def caesar_encode(phrase, shift): 5 | return ' '.join( 6 | ''.join(az[(az.index(a) + shift + i) % 26] for a in word) 7 | for i, word in enumerate(phrase.split()) 8 | ) 9 | -------------------------------------------------------------------------------- /katas/beta/calculator_with_brackets.py: -------------------------------------------------------------------------------- 1 | from __builtin__ import eval as evaluate 2 | -------------------------------------------------------------------------------- /katas/beta/capitals_first.py: -------------------------------------------------------------------------------- 1 | def capitals_first(string): 2 | return ' '.join(sorted((a for a in string.split() if a[0].isalpha()), 3 | key=str.islower)) 4 | -------------------------------------------------------------------------------- /katas/beta/cat_and_mouse_easy_version.py: -------------------------------------------------------------------------------- 1 | def cat_mouse(x): 2 | return 'Escaped!' if x.count('.') > 3 else 'Caught!' 3 | -------------------------------------------------------------------------------- /katas/beta/chuck_norris_v_body_count.py: -------------------------------------------------------------------------------- 1 | from re import search 2 | 3 | 4 | def body_count(code): 5 | return bool(search(r'(?:[A-Z]\d){5}\.-[A-Z]%\d\.\d{2}\.', code)) 6 | -------------------------------------------------------------------------------- /katas/beta/closest_sum.py: -------------------------------------------------------------------------------- 1 | from itertools import combinations 2 | 3 | 4 | def closest_sum(ints, num): 5 | return sum(min(combinations(ints, 3), key=lambda a: abs(num - sum(a)))) 6 | -------------------------------------------------------------------------------- /katas/beta/compress_encode_a_msg_with_rle.py: -------------------------------------------------------------------------------- 1 | from itertools import groupby 2 | 3 | 4 | def encode(s): 5 | return ''.join(k + str(sum(1 for _ in g)) for k, g in groupby(s)) 6 | -------------------------------------------------------------------------------- /katas/beta/count_vowels_in_a_string.py: -------------------------------------------------------------------------------- 1 | VOWELS = frozenset('aeiouAEIOU') 2 | 3 | 4 | def count_vowels(s=''): 5 | return sum(a in VOWELS for a in s) if isinstance(s, str) else None 6 | -------------------------------------------------------------------------------- /katas/beta/count_words.py: -------------------------------------------------------------------------------- 1 | from re import compile, finditer 2 | 3 | OMIT = {'a', 'the', 'on', 'at', 'of', 'upon', 'in', 'as'} 4 | REGEX = compile(r'[a-z]+') 5 | 6 | 7 | def word_count(s): 8 | return sum(a.group() not in OMIT for a in finditer(REGEX, s.lower())) 9 | -------------------------------------------------------------------------------- /katas/beta/counter_of_neighbor_ones.py: -------------------------------------------------------------------------------- 1 | from itertools import groupby 2 | 3 | 4 | def ones_counter(nums): 5 | return [sum(g) for k, g in groupby(nums) if k] 6 | -------------------------------------------------------------------------------- /katas/beta/counting_array_elements.py: -------------------------------------------------------------------------------- 1 | from collections import Counter as count 2 | -------------------------------------------------------------------------------- /katas/beta/crazed_templating.py: -------------------------------------------------------------------------------- 1 | def letter_pattern(words): 2 | return ''.join(a[0] if len(set(a)) == 1 else '*' for a in zip(*words)) 3 | -------------------------------------------------------------------------------- /katas/beta/create_a_house_cleaning_rota.py: -------------------------------------------------------------------------------- 1 | from random import shuffle 2 | 3 | 4 | def rota(rooms): 5 | result = [] 6 | for _ in xrange(0, 7, len(rooms)): 7 | shuffle(rooms) 8 | result.extend(rooms) 9 | return result[:7] 10 | -------------------------------------------------------------------------------- /katas/beta/data_reverse.py: -------------------------------------------------------------------------------- 1 | def data_reverse(data): 2 | return [b for a in xrange(len(data) - 8, -1, -8) for b in data[a:a + 8]] 3 | -------------------------------------------------------------------------------- /katas/beta/decipher_the_cipher.py: -------------------------------------------------------------------------------- 1 | from string import ascii_lowercase as az 2 | 3 | OPPOSITES = dict(zip(az, reversed(az))) 4 | 5 | 6 | def encrypter(strng): 7 | return ''.join(OPPOSITES.get(a, a) for a in strng.encode('rot13')) 8 | -------------------------------------------------------------------------------- /katas/beta/digit_sum.py: -------------------------------------------------------------------------------- 1 | def sum_digits(n): 2 | return 0 if not n else 1 + ((n - 1) % 9) 3 | # while n >= 10: 4 | # n = sum(int(a) for a in str(n)) 5 | # return n 6 | -------------------------------------------------------------------------------- /katas/beta/dinner_plans.py: -------------------------------------------------------------------------------- 1 | def common_ground(s1,s2): 2 | words = s2.split() 3 | return ' '.join(sorted((a for a in set(s1.split()) if a in words), 4 | key=lambda b: words.index(b))) or 'death' 5 | -------------------------------------------------------------------------------- /katas/beta/divisible_by_four.py: -------------------------------------------------------------------------------- 1 | def divisible_by_four(num): 2 | return not num % 4 3 | -------------------------------------------------------------------------------- /katas/beta/doing_your_taxes.py: -------------------------------------------------------------------------------- 1 | def tax(x): 2 | return x + x * 0.05 if not isinstance(x, str) else 'Error 404' 3 | -------------------------------------------------------------------------------- /katas/beta/duck_shoot_easy_version.py: -------------------------------------------------------------------------------- 1 | def duck_shoot(ammo, aim, ducks): 2 | return ducks.replace('2', 'X', int(ammo * aim)) 3 | -------------------------------------------------------------------------------- /katas/beta/easiest_kata.py: -------------------------------------------------------------------------------- 1 | from operator import add as addition_calc 2 | -------------------------------------------------------------------------------- /katas/beta/easy_kata.py: -------------------------------------------------------------------------------- 1 | def print_x(x): 2 | return x 3 | -------------------------------------------------------------------------------- /katas/beta/email_validation.py: -------------------------------------------------------------------------------- 1 | from re import compile, match 2 | 3 | REGEX = compile(r'[a-zA-Z]\w*@[\w-]+(\.\w+)+$') 4 | 5 | 6 | def validate(email): 7 | return bool(match(REGEX, email)) 8 | -------------------------------------------------------------------------------- /katas/beta/endless_string.py: -------------------------------------------------------------------------------- 1 | from itertools import cycle 2 | def endlessString(s, start, length): 3 | dex = (start if length >= 0 else start + length + 1) % len(s) 4 | endless = cycle(s[dex:] + s[:dex]) 5 | return ''.join(next(endless) for _ in xrange(abs(length))) 6 | -------------------------------------------------------------------------------- /katas/beta/esrever_esrever.py: -------------------------------------------------------------------------------- 1 | def esrever(s): 2 | return s[:-1][::-1] + s[-1] if s else '' 3 | -------------------------------------------------------------------------------- /katas/beta/find_duplicate.py: -------------------------------------------------------------------------------- 1 | def duplicate(arr): 2 | seen = set() 3 | for a in arr: 4 | if a in seen: 5 | return a 6 | seen.add(a) 7 | -------------------------------------------------------------------------------- /katas/beta/find_gcf.py: -------------------------------------------------------------------------------- 1 | from fractions import gcd as largestFactor # largest_factor == PEP8 2 | -------------------------------------------------------------------------------- /katas/beta/find_jon_snow_parents.py: -------------------------------------------------------------------------------- 1 | def jonSnowParents(dad, mom): 2 | if dad == 'Rhaegar Targaryen' and mom == 'Lyanna Stark': 3 | return 'Jon Snow you deserve the throne' 4 | return 'Jon Snow, you know nothing' 5 | -------------------------------------------------------------------------------- /katas/beta/find_something_in_an_array.py: -------------------------------------------------------------------------------- 1 | def find(item, items): 2 | return item in items 3 | -------------------------------------------------------------------------------- /katas/beta/find_the_gcf_of_two_numbers.py: -------------------------------------------------------------------------------- 1 | from fractions import gcd as find_GCF 2 | -------------------------------------------------------------------------------- /katas/beta/find_the_middle_element.py: -------------------------------------------------------------------------------- 1 | def gimme(triplet): 2 | return triplet.index(sorted(triplet)[1]) 3 | -------------------------------------------------------------------------------- /katas/beta/finding_averages.py: -------------------------------------------------------------------------------- 1 | def average(x): 2 | return sum(x) / len(x) if not isinstance(x, str) else 'Incorrect' 3 | -------------------------------------------------------------------------------- /katas/beta/first_character_that_repeats.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def first_dup(s): 5 | cnt = Counter(s) 6 | for a in s: 7 | if cnt[a] >= 2: 8 | return a 9 | -------------------------------------------------------------------------------- /katas/beta/fix_the_loop.py: -------------------------------------------------------------------------------- 1 | OUTPUT = '{}. {}\n'.format 2 | 3 | 4 | def list_animals(animals): 5 | return ''.join(OUTPUT(i, a) for i, a in enumerate(animals, start=1)) 6 | -------------------------------------------------------------------------------- /katas/beta/flatten_me.py: -------------------------------------------------------------------------------- 1 | def flatten_me(lst): 2 | result = [] 3 | for a in lst: 4 | try: 5 | result.extend(a) 6 | except TypeError: 7 | result.append(a) 8 | return result 9 | -------------------------------------------------------------------------------- /katas/beta/for_loop.py: -------------------------------------------------------------------------------- 1 | def problem(n): 2 | return range(1, n + 1) 3 | -------------------------------------------------------------------------------- /katas/beta/format_to_the_second.py: -------------------------------------------------------------------------------- 1 | def print_nums(*args): 2 | try: 3 | fmt = '{{:0>{}}}'.format(len(str(max(args)))).format 4 | except ValueError: 5 | return '' 6 | return '\n'.join(fmt(a) for a in args) 7 | -------------------------------------------------------------------------------- /katas/beta/fractions_class.py: -------------------------------------------------------------------------------- 1 | from fractions import Fraction 2 | -------------------------------------------------------------------------------- /katas/beta/friend_or_foe.py: -------------------------------------------------------------------------------- 1 | def friend(x): 2 | return [a for a in x if len(a) == 4] 3 | -------------------------------------------------------------------------------- /katas/beta/geometric_progression.py: -------------------------------------------------------------------------------- 1 | def geometric_sequence_elements(a, r, n): 2 | return ', '.join(str(a * r ** i) for i in xrange(n)) 3 | -------------------------------------------------------------------------------- /katas/beta/get_number_from_string.py: -------------------------------------------------------------------------------- 1 | def get_number_from_string(strng): 2 | return int(''.join(a for a in strng if a.isdigit())) 3 | -------------------------------------------------------------------------------- /katas/beta/grasshopper_fantasy_points.py: -------------------------------------------------------------------------------- 1 | assists = crosses = 3 2 | chancesCreated = goals = 4 3 | shotsOnTarget = 5 4 | successfulDribbles = 10 5 | points = 89 6 | # points = goals * 9 + assists * 6 + chancesCreated * 3 + \ 7 | # shotsOnTarget * 2 + crosses + successfulDribbles 8 | -------------------------------------------------------------------------------- /katas/beta/greeting_my_friends.py: -------------------------------------------------------------------------------- 1 | GREET = 'Hello, {}!'.format 2 | 3 | 4 | def greeting_for_all_friends(friends): 5 | return [GREET(a) for a in friends] if friends else None 6 | -------------------------------------------------------------------------------- /katas/beta/hail_caesar.py: -------------------------------------------------------------------------------- 1 | def hail_caesar(enc_str): 2 | return enc_str.decode('rot13') 3 | -------------------------------------------------------------------------------- /katas/beta/heavy_metal_umlauts.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | UMLAUTS = {'A': 'Ä', 'E': 'Ë', 'I': 'Ï', 'O': 'Ö', 'U': 'Ü', 'Y': 'Ÿ', 3 | 'a': 'ä', 'e': 'ë', 'i': 'ï', 'o': 'ö', 'u': 'ü', 'y': 'ÿ'} 4 | 5 | 6 | def heavy_metal_umlauts(s): 7 | return ''.join(UMLAUTS.get(a, a) for a in s) 8 | -------------------------------------------------------------------------------- /katas/beta/help_the_fruit_guy.py: -------------------------------------------------------------------------------- 1 | def remove_rotten(bag_of_fruits): 2 | return [] if not bag_of_fruits else \ 3 | [fruit.replace('rotten', '').lower() for fruit in bag_of_fruits] 4 | -------------------------------------------------------------------------------- /katas/beta/herons_formula.py: -------------------------------------------------------------------------------- 1 | def heron(a, b, c): 2 | """ https://en.wikipedia.org/wiki/Heron%27s_formula """ 3 | s = (a + b + c) / 2.0 4 | return (s * (s - a) * (s - b) * (s - c)) ** 0.5 5 | -------------------------------------------------------------------------------- /katas/beta/hollow_triangle.py: -------------------------------------------------------------------------------- 1 | def hollow_triangle(n): 2 | width = n * 2 - 1 3 | row = '{{:_^{}}}'.format(width).format 4 | return [row(mid(a)) for a in xrange(1, width, 2)] + [width * '#'] 5 | 6 | 7 | def mid(n): 8 | return '#' if n == 1 else '#{}#'.format('_' * (n - 2)) 9 | -------------------------------------------------------------------------------- /katas/beta/how_many_stairs_will_suzuki_climb_in_20_years.py: -------------------------------------------------------------------------------- 1 | def stairs_in_20(stairs): 2 | return sum(sum(a) for day in stairs for a in day) * 20 3 | -------------------------------------------------------------------------------- /katas/beta/how_many_times_does_it_contain.py: -------------------------------------------------------------------------------- 1 | string_counter = str.count 2 | -------------------------------------------------------------------------------- /katas/beta/how_many_times_should_i_go.py: -------------------------------------------------------------------------------- 1 | from math import ceil 2 | from operator import truediv 3 | 4 | 5 | def how_many_times(annual_price, individual_price): 6 | return int(ceil(truediv(annual_price, individual_price))) 7 | -------------------------------------------------------------------------------- /katas/beta/how_much_coffee_do_you_need.py: -------------------------------------------------------------------------------- 1 | def how_much_coffee(lst): 2 | result = sum(a.isalpha() if a.islower() else 2 * a.isalpha() for a in lst) 3 | return 'You need extra sleep' if result > 3 else result 4 | -------------------------------------------------------------------------------- /katas/beta/how_much_hex_is_the_fish.py: -------------------------------------------------------------------------------- 1 | VALID = frozenset('abcdefABCDEF') 2 | 3 | 4 | def fisHex(s): 5 | return reduce(lambda b, c: b ^ c, (int(a, 16) for a in s if a in VALID), 0) 6 | -------------------------------------------------------------------------------- /katas/beta/is_n_divisible_by_x_y.py: -------------------------------------------------------------------------------- 1 | def is_divisible(n, x, y): 2 | return not n % x and not n % y 3 | -------------------------------------------------------------------------------- /katas/beta/keep_it_short_with_restrictions.py: -------------------------------------------------------------------------------- 1 | short = lambda arr: __import__('collections').Counter(__import__('itertools').chain.from_iterable(arr)) 2 | -------------------------------------------------------------------------------- /katas/beta/keep_up_the_hoop.py: -------------------------------------------------------------------------------- 1 | def hoopCount(n): 2 | """ hoop_count == PEP8 (forced mixedCase by CodeWars) """ 3 | return 'Great, now move on to tricks' if n >= 10 else\ 4 | 'Keep at it until you get it' 5 | -------------------------------------------------------------------------------- /katas/beta/knight_or_knave.py: -------------------------------------------------------------------------------- 1 | def knight_or_knave(said): 2 | return 'Knight!' if eval(str(said)) else 'Knave! Do not trust.' 3 | -------------------------------------------------------------------------------- /katas/beta/lightswitches.py: -------------------------------------------------------------------------------- 1 | def lightswitch(n): 2 | # inspired by the solution from @mheavenor, no imports though 3 | return int(n ** 0.5) 4 | -------------------------------------------------------------------------------- /katas/beta/list_length_v1.py: -------------------------------------------------------------------------------- 1 | def count(lst): 2 | return sum(1 for _ in lst) 3 | -------------------------------------------------------------------------------- /katas/beta/list_length_v2.py: -------------------------------------------------------------------------------- 1 | def count(lst): 2 | return sum(1 for _ in lst) 3 | -------------------------------------------------------------------------------- /katas/beta/logical_calculator.py: -------------------------------------------------------------------------------- 1 | from operator import and_, or_, xor 2 | 3 | OPERATOR = {'AND': and_, 'OR': or_, 'XOR': xor} 4 | 5 | 6 | def logical_calc(array, op): 7 | return reduce(OPERATOR[op], array) 8 | -------------------------------------------------------------------------------- /katas/beta/loose_change_.py: -------------------------------------------------------------------------------- 1 | CHANGE = {'penny': 1, 'nickel': 5, 'dime': 10, 'quarter': 25, 'dollar': 100} 2 | 3 | 4 | def change_count(change): 5 | return '${}.{:0>2}'.format(*divmod( 6 | sum(CHANGE[a] for a in change.split()), 100 7 | )) 8 | -------------------------------------------------------------------------------- /katas/beta/make_acronym.py: -------------------------------------------------------------------------------- 1 | def to_acronym(input_str): 2 | return ''.join(a[0].upper() for a in input_str.split()) 3 | -------------------------------------------------------------------------------- /katas/beta/modulus_11_check_digit.py: -------------------------------------------------------------------------------- 1 | from itertools import cycle 2 | 3 | 4 | def add_check_digit(s): 5 | rem = 11 - sum(int(a) * b for a, b in zip( 6 | reversed(s), cycle(xrange(2, 8)))) % 11 7 | return '{}{}'.format(s, {10: 'X', 11: 0}.get(rem, rem)) 8 | -------------------------------------------------------------------------------- /katas/beta/multi_range_iterator.py: -------------------------------------------------------------------------------- 1 | from itertools import product 2 | 3 | 4 | def multiiter(*args): 5 | return product(*(xrange(b) for b in args)) 6 | -------------------------------------------------------------------------------- /katas/beta/multiples.py: -------------------------------------------------------------------------------- 1 | def multiple(x): 2 | if x % 15 == 0: 3 | return 'BangBoom' 4 | elif x % 3 == 0: 5 | return 'Bang' 6 | elif x % 5 == 0: 7 | return 'Boom' 8 | return 'Miss' 9 | -------------------------------------------------------------------------------- /katas/beta/multiples_2.py: -------------------------------------------------------------------------------- 1 | def multiples(x): 2 | if x % 147 == 0: 3 | return 'Fang' 4 | elif x % 7 == 0: 5 | return 'Fizz' 6 | elif x % 15 == 0: 7 | return 'Foo' 8 | return 'Far' 9 | -------------------------------------------------------------------------------- /katas/beta/multiples_by_permutations_1.py: -------------------------------------------------------------------------------- 1 | def search_permMult(n_max, k): 2 | """ search_perm_mult == PEP8 (forced mixedCase by Codewars) """ 3 | return sum(sorted(str(a)) == sorted(str(a * k)) 4 | for a in xrange(1, n_max / k)) 5 | -------------------------------------------------------------------------------- /katas/beta/multiply_list_by_integer_with_restrictions.py: -------------------------------------------------------------------------------- 1 | from operator import mul 2 | 3 | 4 | def multiply(n, l): 5 | return map(lambda a: mul(a, n), l) 6 | -------------------------------------------------------------------------------- /katas/beta/my_first_bug_fixing_kata.py: -------------------------------------------------------------------------------- 1 | def foo(): 2 | return 42 3 | -------------------------------------------------------------------------------- /katas/beta/naming_files.py: -------------------------------------------------------------------------------- 1 | def name_file(fmt, nbr, start): 2 | if not isinstance(nbr, int) or not isinstance(start, int) or nbr <= 0: 3 | return [] 4 | filename = fmt.replace('', '{0}').format 5 | return [filename(a) for a in xrange(start, start + nbr)] 6 | -------------------------------------------------------------------------------- /katas/beta/ninety_degrees_rotation.py: -------------------------------------------------------------------------------- 1 | def rotate(arr): 2 | return [list(a) for a in zip(*reversed(arr))] 3 | -------------------------------------------------------------------------------- /katas/beta/no_duplicates_here.py: -------------------------------------------------------------------------------- 1 | def list_de_dup(lst): 2 | return sorted(set(a for a in lst if a is not None)) \ 3 | if isinstance(lst, list) else 'Not an array' 4 | -------------------------------------------------------------------------------- /katas/beta/nothing_special.py: -------------------------------------------------------------------------------- 1 | from string import punctuation 2 | 3 | 4 | def nothing_special(s): 5 | try: 6 | return s.translate(None, punctuation) 7 | except AttributeError: 8 | return 'Not a string!' 9 | -------------------------------------------------------------------------------- /katas/beta/number_to_bytes.py: -------------------------------------------------------------------------------- 1 | from math import ceil 2 | 3 | 4 | def to_bytes(n): 5 | binary = '{:b}'.format(n) 6 | width = int(ceil(len(binary) / 8.0) * 8) 7 | padded = binary.zfill(width) 8 | return [padded[a:a + 8] for a in xrange(0, width, 8)] 9 | -------------------------------------------------------------------------------- /katas/beta/palindrome_checker.py: -------------------------------------------------------------------------------- 1 | def is_palindrome(string): 2 | try: 3 | string = ''.join(a for a in string.lower() if a.isalnum()) 4 | return string == string[::-1] 5 | except AttributeError: 6 | return False 7 | -------------------------------------------------------------------------------- /katas/beta/parse_float.py: -------------------------------------------------------------------------------- 1 | def parse_float(strng): 2 | try: 3 | return float(strng) 4 | except (TypeError, ValueError): 5 | return None 6 | -------------------------------------------------------------------------------- /katas/beta/password_maker.py: -------------------------------------------------------------------------------- 1 | SWAP = {'i': '1', 'I': '1', 'o': '0', 'O': '0', 's': '5', 'S': '5'} 2 | 3 | 4 | def make_password(password): 5 | return ''.join(SWAP.get(a[0], a[0]) for a in password.split()) 6 | -------------------------------------------------------------------------------- /katas/beta/pirates_are_the_cannons_ready.py: -------------------------------------------------------------------------------- 1 | def cannons_ready(gunners): 2 | return 'Shiver me timbers!' if 'nay' in gunners.itervalues() else 'Fire!' 3 | -------------------------------------------------------------------------------- /katas/beta/plus_1_array.py: -------------------------------------------------------------------------------- 1 | def up_array(arr): 2 | if arr and all(0 <= a < 10 and isinstance(a, int) for a in arr): 3 | return [int(c) for c in str(int(''.join(str(b) for b in arr)) + 1)] 4 | -------------------------------------------------------------------------------- /katas/beta/pop_shift.py: -------------------------------------------------------------------------------- 1 | def pop_shift(s): 2 | half, odd_len = divmod(len(s), 2) 3 | return [s[half + odd_len:][::-1], s[:half], s[half] if odd_len else ''] 4 | -------------------------------------------------------------------------------- /katas/beta/print_that_calendar.py: -------------------------------------------------------------------------------- 1 | from calendar import month as show_calendar 2 | 3 | 4 | # from calendar import TextCalendar 5 | # 6 | # 7 | # def show_calendar(yy, mm): 8 | # return TextCalendar().formatmonth(yy, mm) 9 | -------------------------------------------------------------------------------- /katas/beta/re_ordering.py: -------------------------------------------------------------------------------- 1 | def re_ordering(name): 2 | return ' '.join(sorted(name.split(), key=str.islower)) 3 | -------------------------------------------------------------------------------- /katas/beta/remember.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | 3 | 4 | def remember(string): 5 | d = defaultdict(int) 6 | result = [] 7 | for a in string: 8 | d[a] += 1 9 | if d[a] == 2: 10 | result.append(a) 11 | return result 12 | -------------------------------------------------------------------------------- /katas/beta/remove_duplicates_from_list.py: -------------------------------------------------------------------------------- 1 | def distinct(seq): 2 | result = [] 3 | seen = set() 4 | for a in seq: 5 | if a not in seen: 6 | result.append(a) 7 | seen.add(a) 8 | return result 9 | -------------------------------------------------------------------------------- /katas/beta/remove_first_and_last_character.py: -------------------------------------------------------------------------------- 1 | def remove_char(s): 2 | return s[1:-1] 3 | -------------------------------------------------------------------------------- /katas/beta/remove_unnecessary_characters_from_items_in_list.py: -------------------------------------------------------------------------------- 1 | from string import digits 2 | 3 | VALID_CHARS = '$.' + digits 4 | 5 | 6 | def remove_char(array): 7 | return [''.join(b for b in a if b in VALID_CHARS) for a in array] 8 | -------------------------------------------------------------------------------- /katas/beta/returning_strings.py: -------------------------------------------------------------------------------- 1 | def greet(name): 2 | return 'Hello, {} how are you doing today?'.format(name) 3 | -------------------------------------------------------------------------------- /katas/beta/reverse_complement_dna.py: -------------------------------------------------------------------------------- 1 | from string import maketrans 2 | 3 | 4 | def reverse_complement(dna): 5 | if not set('ACTG').issuperset(dna): 6 | return 'Invalid sequence' 7 | return dna[::-1].translate(maketrans('ACTG', 'TGAC')) 8 | -------------------------------------------------------------------------------- /katas/beta/reverse_list.py: -------------------------------------------------------------------------------- 1 | def reverse_list(lst): 2 | return lst[::-1] 3 | -------------------------------------------------------------------------------- /katas/beta/reverse_the_number.py: -------------------------------------------------------------------------------- 1 | def reverse(n): 2 | exp = 1 3 | while n / 10 ** exp: 4 | exp += 1 5 | 6 | return sum((n % 10 ** a / 10 ** (a - 1)) * (10 ** b) 7 | for a, b in zip(xrange(1, exp + 1), xrange(exp - 1, -1, -1))) 8 | -------------------------------------------------------------------------------- /katas/beta/reversing_words_in_a_string.py: -------------------------------------------------------------------------------- 1 | def reverse(st): 2 | return ' '.join(reversed(st.split(' '))) 3 | -------------------------------------------------------------------------------- /katas/beta/rigged_dice.py: -------------------------------------------------------------------------------- 1 | from random import randint, random 2 | 3 | 4 | def throw_rigged(): 5 | if random() < 0.22: 6 | return 6 7 | return randint(1, 5) 8 | -------------------------------------------------------------------------------- /katas/beta/rotate_a_square_matrix_in_place.py: -------------------------------------------------------------------------------- 1 | def rotate_in_place(matrix): 2 | for r, row in enumerate(zip(*matrix)): 3 | for c, col in enumerate(reversed(row)): 4 | matrix[r][c] = col 5 | return matrix 6 | -------------------------------------------------------------------------------- /katas/beta/rotated_string.py: -------------------------------------------------------------------------------- 1 | def is_rotation(s1, s2): 2 | return s1 in s2 + s2 and len(s1) == len(s2) 3 | -------------------------------------------------------------------------------- /katas/beta/round_to_next_5.py: -------------------------------------------------------------------------------- 1 | def round_to_next5(n): 2 | # return (n + 4) / 5 * 5 3 | q, r = divmod(n, 5) 4 | return n if not r else (q + 1) * 5 5 | -------------------------------------------------------------------------------- /katas/beta/sean_sean_sean.py: -------------------------------------------------------------------------------- 1 | def sean(s): 2 | if not isinstance(s, str): 3 | return 'Boo! Not a string, boo!' 4 | return "Ohhhhh it's {}".format(' '.join( 5 | 'Sean!' if a[0].islower() else 'SEAN!' for a in s.split()[2:] 6 | ) or 'Sean!') 7 | -------------------------------------------------------------------------------- /katas/beta/separate_filename_from_extension.py: -------------------------------------------------------------------------------- 1 | def separate_filename_from_extension(s): 2 | slash = s.rfind('/') + 1 3 | dex = slash + s[slash:].find('.', s[slash:].startswith('.')) 4 | return s[:dex], s[dex:] 5 | -------------------------------------------------------------------------------- /katas/beta/seven_ate_9.py: -------------------------------------------------------------------------------- 1 | from re import sub 2 | 3 | 4 | def seven_ate9(string): 5 | return sub('(?<=7)9+(?=7)', '', string) 6 | -------------------------------------------------------------------------------- /katas/beta/simple_beads_count.py: -------------------------------------------------------------------------------- 1 | def count_red_beads(n_blue): 2 | return (n_blue - 1) * 2 if n_blue >= 2 else 0 3 | -------------------------------------------------------------------------------- /katas/beta/simple_decrypt_algo.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | from string import ascii_lowercase 3 | 4 | 5 | def decrypt(test_key): 6 | cnt = Counter(test_key) 7 | return ''.join(str(cnt[a]) for a in ascii_lowercase) 8 | -------------------------------------------------------------------------------- /katas/beta/simple_decrypt_algo_2.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | from string import ascii_lowercase 3 | 4 | 5 | def decrypt(test_key): 6 | cnt = Counter(test_key.lower()) 7 | return ''.join(str(cnt[a]) for a in ascii_lowercase) 8 | -------------------------------------------------------------------------------- /katas/beta/small_enough_beginner.py: -------------------------------------------------------------------------------- 1 | def small_enough(array, limit): 2 | return all(a <= limit for a in array) 3 | -------------------------------------------------------------------------------- /katas/beta/sort_a_massive_list_of_strings.py: -------------------------------------------------------------------------------- 1 | from __builtin__ import sorted as s 2 | 3 | 4 | def sort(words): 5 | for a in s(words): 6 | yield a 7 | -------------------------------------------------------------------------------- /katas/beta/sort_array_by_last_character.py: -------------------------------------------------------------------------------- 1 | def sort_me(lst): 2 | lst.sort(key=lambda a: str(a)[-1]) 3 | return lst 4 | # return sorted(key=lambda a: str(a)[-1]) 5 | -------------------------------------------------------------------------------- /katas/beta/sort_deck_of_cards.py: -------------------------------------------------------------------------------- 1 | def sort_cards(cards): 2 | return sorted(cards, key='A23456789TJQK'.index) 3 | -------------------------------------------------------------------------------- /katas/beta/sort_the_columns_of_a_csv_file.py: -------------------------------------------------------------------------------- 1 | def sort_csv_columns(csv_file_content): 2 | return '\n'.join(';'.join(sorted_row) for sorted_row in zip(*sorted( 3 | (zip(*(row.split(';') for row in csv_file_content.split('\n')))), 4 | key=lambda col: col[0].lower() 5 | ))) 6 | -------------------------------------------------------------------------------- /katas/beta/sorting_integers_into_a_nested_list.py: -------------------------------------------------------------------------------- 1 | from itertools import groupby 2 | 3 | 4 | def group_ints(lst, key=0): 5 | return [list(g) for _, g in groupby(lst, lambda a: a < key)] 6 | 7 | 8 | # PEP8: katas function name should use snake_case 9 | groupInts = group_ints 10 | -------------------------------------------------------------------------------- /katas/beta/sorting_time.py: -------------------------------------------------------------------------------- 1 | def sort_time(times): 2 | pass 3 | 4 | 5 | print sort_time([['08:14', '11:34'], ['08:16', '08:18'], ['13:48', '01:14'], 6 | ['09:30', '10:32'], ['04:23', '05:11'], ['11:48', '13:48'], 7 | ['01:12', '01:14'], ['01:13', '08:15']]) 8 | -------------------------------------------------------------------------------- /katas/beta/spy_games_rebuild_your_decoder.py: -------------------------------------------------------------------------------- 1 | from string import ascii_lowercase 2 | 3 | AZ = ' ' + ascii_lowercase 4 | 5 | 6 | def decrypt(msg): 7 | return ''.join( 8 | AZ[sum(int(b) for b in a if b.isdigit()) % 27] for a in msg.split()) 9 | -------------------------------------------------------------------------------- /katas/beta/strange_strings_parser.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def parser(strng): 5 | return re.split(r'[!#%&*+:;=>?|]', strng) 6 | -------------------------------------------------------------------------------- /katas/beta/string_cleaning.py: -------------------------------------------------------------------------------- 1 | def string_clean(s): 2 | return ''.join(a for a in s if not a.isdigit()) 3 | -------------------------------------------------------------------------------- /katas/beta/string_repeat.py: -------------------------------------------------------------------------------- 1 | def repeat_str(repeat, strng): 2 | return strng * repeat 3 | -------------------------------------------------------------------------------- /katas/beta/string_to_list_of_integers.py: -------------------------------------------------------------------------------- 1 | def string_to_int_list(s): 2 | return [int(a) for a in s.split(',') if a] 3 | -------------------------------------------------------------------------------- /katas/beta/strip_my_comments.py: -------------------------------------------------------------------------------- 1 | from re import compile, sub, DOTALL 2 | 3 | REGEX = compile(r'/\*.*?\*/|//[^\n]+', DOTALL) 4 | 5 | 6 | def strip_it(code): 7 | return sub(REGEX, '', code) 8 | -------------------------------------------------------------------------------- /katas/beta/sum_of_all_arguments.py: -------------------------------------------------------------------------------- 1 | def sum_all(*args): 2 | try: 3 | return sum(args) 4 | except TypeError: 5 | return False 6 | -------------------------------------------------------------------------------- /katas/beta/sum_of_list_values.py: -------------------------------------------------------------------------------- 1 | try: 2 | from builtins import sum as sum_list # Python 3 3 | except ImportError: 4 | from __builtin__ import sum as sum_list # Python 2 5 | -------------------------------------------------------------------------------- /katas/beta/sum_of_numerous_arguments.py: -------------------------------------------------------------------------------- 1 | def find_sum(*args): 2 | total = 0 3 | for a in args: 4 | if a < 0: 5 | return -1 6 | total += a 7 | return total 8 | -------------------------------------------------------------------------------- /katas/beta/sum_of_positive.py: -------------------------------------------------------------------------------- 1 | def positive_sum(arr): 2 | return sum(a for a in arr if a > 0) 3 | -------------------------------------------------------------------------------- /katas/beta/sum_of_two_lowest_integers.py: -------------------------------------------------------------------------------- 1 | def sum_two_smallest_numbers(numbers): 2 | return sum(sorted(numbers)[:2]) 3 | -------------------------------------------------------------------------------- /katas/beta/sum_of_values_from_1_to_n_inclusive.py: -------------------------------------------------------------------------------- 1 | def total(n): 2 | return n * (n + 1) / 2 3 | -------------------------------------------------------------------------------- /katas/beta/sum_the_repeats.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | 3 | 4 | def repeat_sum(lst): 5 | count = defaultdict(int) 6 | for a in lst: 7 | for b in set(a): 8 | count[b] += 1 9 | return sum(k for k, v in count.iteritems() if v > 1) 10 | -------------------------------------------------------------------------------- /katas/beta/summations_1.py: -------------------------------------------------------------------------------- 1 | def summation(x): 2 | return sum(xrange(1, x + 1)) if isinstance(x, int) else 'Error 404' 3 | -------------------------------------------------------------------------------- /katas/beta/super_duper_easy.py: -------------------------------------------------------------------------------- 1 | def problem(a): 2 | return a * 50 + 6 if not isinstance(a, str) else 'Error' 3 | -------------------------------------------------------------------------------- /katas/beta/swap_row_in_certain_columns_of_a_matrix.py: -------------------------------------------------------------------------------- 1 | def swap(matrix, row1, row2, *columns): 2 | result = list(matrix) 3 | for a in columns: 4 | result[row1][a], result[row2][a] = result[row2][a], result[row1][a] 5 | return result 6 | -------------------------------------------------------------------------------- /katas/beta/tail_swap.py: -------------------------------------------------------------------------------- 1 | def tail_swap(arr): 2 | fmt = '{}:{}'.format 3 | (head, tail), (head_2, tail_2) = (a.split(':') for a in arr) 4 | return [fmt(head, tail_2), fmt(head_2, tail)] 5 | -------------------------------------------------------------------------------- /katas/beta/testing_123.py: -------------------------------------------------------------------------------- 1 | def number(lines): 2 | return ['{}: {}'.format(i, a) for i, a in enumerate(lines, 1)] 3 | -------------------------------------------------------------------------------- /katas/beta/text_align_right.py: -------------------------------------------------------------------------------- 1 | from textwrap import TextWrapper 2 | 3 | 4 | def align_right(text, width): 5 | tw = TextWrapper(width, break_on_hyphens=False) 6 | return '\n'.join(a.rjust(width) for a in tw.wrap(text)) 7 | -------------------------------------------------------------------------------- /katas/beta/the_animals_went_in_two_by_two.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def two_by_two(animals): 5 | if not animals: 6 | return False 7 | return {k: 2 for k, v in Counter(animals).items() if v >= 2} 8 | -------------------------------------------------------------------------------- /katas/beta/the_office_4_find_a_meeting_room.py: -------------------------------------------------------------------------------- 1 | def meeting(rooms): 2 | try: 3 | return rooms.index('O') 4 | except ValueError: 5 | return 'None available!' 6 | -------------------------------------------------------------------------------- /katas/beta/the_unknown_but_known_variables_addition.py: -------------------------------------------------------------------------------- 1 | from string import ascii_lowercase 2 | 3 | AZ = dict(zip(ascii_lowercase, xrange(1, 27))) 4 | 5 | 6 | def the_var(the_variables): 7 | return sum(AZ[a] for a in the_variables.split('+')) 8 | -------------------------------------------------------------------------------- /katas/beta/this_is_odd.py: -------------------------------------------------------------------------------- 1 | def is_odd(n): 2 | return n % 2 == 1 3 | -------------------------------------------------------------------------------- /katas/beta/to_buy_or_not_to_buy.py: -------------------------------------------------------------------------------- 1 | def buy_or_pass(stock_price, all_time_high): 2 | return 'Buy' if stock_price <= all_time_high * 0.8 else 'Pass' 3 | -------------------------------------------------------------------------------- /katas/beta/transpose_of_a_matrix.py: -------------------------------------------------------------------------------- 1 | def transpose(arr): 2 | return map(list, zip(*arr)) if all(arr) else [[]] 3 | -------------------------------------------------------------------------------- /katas/beta/trigrams.py: -------------------------------------------------------------------------------- 1 | def trigrams(phrase): 2 | phrase = phrase.replace(' ', '_') 3 | return ' '.join(phrase[a:a + 3] for a in xrange(len(phrase) - 2)) 4 | -------------------------------------------------------------------------------- /katas/beta/two_arrays_one_sort.py: -------------------------------------------------------------------------------- 1 | def linked_sort(a_to_sort, a_linked, key=None): 2 | d = dict(zip(a_linked, a_to_sort)) 3 | a_to_sort.sort(key=key or str) 4 | a_linked.sort(key=lambda a: a_to_sort.index(d[a])) 5 | return a_to_sort 6 | -------------------------------------------------------------------------------- /katas/beta/unique_sum.py: -------------------------------------------------------------------------------- 1 | def unique_sum(lst): 2 | return sum(set(lst)) 3 | -------------------------------------------------------------------------------- /katas/beta/unscrambled_eggs.py: -------------------------------------------------------------------------------- 1 | def unscramble_eggs(word): 2 | return word.replace('egg', '') 3 | -------------------------------------------------------------------------------- /katas/beta/variance_in_array_of_words.py: -------------------------------------------------------------------------------- 1 | def variance(array): 2 | nums = map(len, array) 3 | length = float(len(nums)) 4 | average = sum(nums) / length 5 | return round(sum((average - a) ** 2 for a in nums) / length, 4) 6 | -------------------------------------------------------------------------------- /katas/beta/what_day_is_it.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | WEEKDAYS = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 4 | 'Friday', 'Saturday', 'Sunday') 5 | 6 | 7 | def day(date): 8 | return WEEKDAYS[datetime.strptime(date, '%Y%m%d').weekday()] 9 | -------------------------------------------------------------------------------- /katas/beta/where_am_i.py: -------------------------------------------------------------------------------- 1 | from os import uname 2 | 3 | 4 | def get_pid(): 5 | return uname()[1] 6 | 7 | # Alternative: socket.gethostname() 8 | -------------------------------------------------------------------------------- /katas/beta/which_string_is_worth_more.py: -------------------------------------------------------------------------------- 1 | def highest_value(*args): 2 | return max(args, key=lambda a: sum(ord(b) for b in a)) 3 | -------------------------------------------------------------------------------- /katas/beta/who_ate_the_cookie.py: -------------------------------------------------------------------------------- 1 | def cookie(x): 2 | if isinstance(x, str): 3 | who = 'Zach' 4 | elif type(x) in (float, int): 5 | who = 'Monica' 6 | else: 7 | who = 'the dog' 8 | return 'Who ate the last cookie? It was {}!'.format(who) 9 | -------------------------------------------------------------------------------- /katas/beta/who_took_the_car_key.py: -------------------------------------------------------------------------------- 1 | def who_took_the_car_key(message): 2 | return ''.join(chr(int(a, 2)) for a in message) 3 | -------------------------------------------------------------------------------- /katas/beta/yes_no_yes_no.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | 4 | def yes_no(arr): 5 | d = deque(reversed(arr)) 6 | result = [] 7 | while d: 8 | result.append(d.pop()) 9 | d.rotate() 10 | return result 11 | -------------------------------------------------------------------------------- /katas/incomplete/bouncing_balls.py: -------------------------------------------------------------------------------- 1 | def bounce(height, window): 2 | pass 3 | 4 | 5 | print bounce(0.66, 1.5) # == 3 6 | print bounce(1, 1.5) # == -1 7 | -------------------------------------------------------------------------------- /katas/kyu_3/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/katas/kyu_3/__init__.py -------------------------------------------------------------------------------- /katas/kyu_3/calculator.py: -------------------------------------------------------------------------------- 1 | class Calculator(object): 2 | @staticmethod 3 | def evaluate(string): 4 | return round(eval(string), 3) 5 | -------------------------------------------------------------------------------- /katas/kyu_4/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/katas/kyu_4/__init__.py -------------------------------------------------------------------------------- /katas/kyu_4/nesting_structure_comparison.py: -------------------------------------------------------------------------------- 1 | def nones(itr): 2 | return [nones(a) if isinstance(a, (list, tuple)) else None for a in itr] 3 | 4 | 5 | def same_structure_as(a, b): 6 | return nones(a) == nones(b) if type(a) == type(b) else False 7 | -------------------------------------------------------------------------------- /katas/kyu_4/permutations.py: -------------------------------------------------------------------------------- 1 | from itertools import permutations as perm 2 | 3 | 4 | def permutations(strng): 5 | return set(''.join(a) for a in perm(strng)) 6 | -------------------------------------------------------------------------------- /katas/kyu_4/strip_comments.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from re import escape, sub 3 | 4 | 5 | def solution(s, markers): 6 | return s if not markers else \ 7 | sub(r'( *[{}].*)'.format(escape(''.join(markers))), '', s) 8 | -------------------------------------------------------------------------------- /katas/kyu_5/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/katas/kyu_5/__init__.py -------------------------------------------------------------------------------- /katas/kyu_5/by_the_power_set_of_castle_grayskull.py: -------------------------------------------------------------------------------- 1 | from itertools import combinations 2 | 3 | 4 | def power(lst): 5 | return [list(b) for a in xrange(len(lst) + 1) for b in combinations(lst, a)] 6 | -------------------------------------------------------------------------------- /katas/kyu_5/delta_bits.py: -------------------------------------------------------------------------------- 1 | from itertools import izip_longest 2 | 3 | 4 | def convert_bits(a, b): 5 | binary = '{:b}'.format 6 | return sum(c != d for c, d in izip_longest( 7 | reversed(binary(a)), reversed(binary(b)), fillvalue='0' 8 | )) 9 | -------------------------------------------------------------------------------- /katas/kyu_5/extract_domain_name_from_url.py: -------------------------------------------------------------------------------- 1 | from re import compile, match 2 | 3 | REGEX = compile(r'(http[s]*://)?(www.)?(?P[\w-]+)\.') 4 | 5 | 6 | def domain_name(url): 7 | return match(REGEX, url).group('domain') 8 | -------------------------------------------------------------------------------- /katas/kyu_5/find_the_missing_term_in_an_arithmetic_progression.py: -------------------------------------------------------------------------------- 1 | def find_missing(nums): 2 | a, b, c = nums[:3] 3 | diff = min(b - a, c - b, key=abs) 4 | for d in nums: 5 | if d != a: 6 | return a 7 | a += diff 8 | -------------------------------------------------------------------------------- /katas/kyu_5/human_readable_time.py: -------------------------------------------------------------------------------- 1 | def make_readable(seconds): 2 | hours, seconds = divmod(seconds, 3600) 3 | minutes, seconds = divmod(seconds, 60) 4 | return '{:02}:{:02}:{:02}'.format(hours, minutes, seconds) 5 | -------------------------------------------------------------------------------- /katas/kyu_5/josephus_permutation.py: -------------------------------------------------------------------------------- 1 | def josephus(items, k): 2 | dex = 0 3 | items_copy = list(items) 4 | result = [] 5 | while items_copy: 6 | dex = (dex + (k - 1)) % len(items_copy) 7 | result.append(items_copy.pop(dex)) 8 | return result 9 | -------------------------------------------------------------------------------- /katas/kyu_5/largest_5_digit_number_in_a_series.py: -------------------------------------------------------------------------------- 1 | def solution(digits): 2 | # return max(int(digits[a:a + 5]) for a in xrange(len(digits) - 4)) 3 | 4 | # code below only calls int once 5 | return int(max(digits[a:a + 5] for a in xrange(len(digits) - 4))) 6 | -------------------------------------------------------------------------------- /katas/kyu_5/luck_check.py: -------------------------------------------------------------------------------- 1 | def luck_check(s): 2 | q, r = divmod(len(s), 2) 3 | return sum(int(a) for a in s[:q]) == sum(int(b) for b in s[q + r:]) 4 | -------------------------------------------------------------------------------- /katas/kyu_5/mod4_regex.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | class Mod: 5 | mod4 = re.compile(r'.*\[[+-]?0*(\d*[13579][26]|(?:\d*[02468])?[048])\]') 6 | -------------------------------------------------------------------------------- /katas/kyu_5/not_very_secure.py: -------------------------------------------------------------------------------- 1 | alphanumeric = str.isalnum 2 | -------------------------------------------------------------------------------- /katas/kyu_5/ookkk_ok_o_ook_ok_ooo.py: -------------------------------------------------------------------------------- 1 | SCORE = {'O': '0', 'o': '0', 'k': '1'} 2 | 3 | 4 | def okkOokOo(s): 5 | """ okkookoo == PEP8, forced mixedCase by CodeWars """ 6 | return ''.join(chr(int(''.join(SCORE.get(a, '') for a in word), 2)) 7 | for word in s.split('?')) 8 | -------------------------------------------------------------------------------- /katas/kyu_5/palindrome_chain_length.py: -------------------------------------------------------------------------------- 1 | def palindrome_chain_length(num): 2 | steps = 0 3 | while True: 4 | tmp = str(num) 5 | rev = tmp[::-1] 6 | if tmp == rev: 7 | return steps 8 | num += int(rev) 9 | steps += 1 10 | -------------------------------------------------------------------------------- /katas/kyu_5/pete_the_baker.py: -------------------------------------------------------------------------------- 1 | def cakes(recipe, ingredients): 2 | return min(ingredients.get(k, 0) / v for k, v in recipe.iteritems()) 3 | -------------------------------------------------------------------------------- /katas/kyu_5/prefill_an_array.py: -------------------------------------------------------------------------------- 1 | def prefill(n, v=None): 2 | try: 3 | return [v] * int(n) 4 | except (TypeError, ValueError): 5 | raise TypeError('{} is invalid'.format(n)) 6 | -------------------------------------------------------------------------------- /katas/kyu_5/rgb_to_hex_conversion.py: -------------------------------------------------------------------------------- 1 | def rgb_range(n): 2 | return min(255, max(n, 0)) 3 | 4 | 5 | def rgb(r, g, b): 6 | return ('{:02X}' * 3).format(rgb_range(r), rgb_range(g), rgb_range(b)) 7 | -------------------------------------------------------------------------------- /katas/kyu_5/secret_knock.py: -------------------------------------------------------------------------------- 1 | knock(knock)()() 2 | -------------------------------------------------------------------------------- /katas/kyu_5/simple_pig_latin.py: -------------------------------------------------------------------------------- 1 | PIG = '{}{}ay'.format 2 | 3 | 4 | def pig_it(s): 5 | return ' '.join(PIG(a[1:], a[0]) if a.isalpha() else a for a in s.split()) 6 | -------------------------------------------------------------------------------- /katas/kyu_5/sum_of_pairs.py: -------------------------------------------------------------------------------- 1 | def sum_pairs(nums, sum_value): 2 | seen = set() 3 | for num in nums: 4 | diff = sum_value - num 5 | if diff in seen: 6 | return [diff, num] 7 | seen.add(num) 8 | -------------------------------------------------------------------------------- /katas/kyu_5/two_joggers.py: -------------------------------------------------------------------------------- 1 | from fractions import gcd 2 | 3 | 4 | def nbr_of_laps(x, y): 5 | lcm = (x * y) / gcd(x, y) 6 | return [lcm / x, lcm / y] 7 | -------------------------------------------------------------------------------- /katas/kyu_5/weight_for_weight.py: -------------------------------------------------------------------------------- 1 | def order_weight(string): 2 | return ' '.join(c[1] for c in sorted((sum(int(b) for b in a), a) 3 | for a in string.split())) 4 | -------------------------------------------------------------------------------- /katas/kyu_6/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/katas/kyu_6/__init__.py -------------------------------------------------------------------------------- /katas/kyu_6/almost_even.py: -------------------------------------------------------------------------------- 1 | def splitInteger(num, parts): 2 | """ split_integer == PEP8 (forced mixedCase by CodeWars) """ 3 | quo, rem = divmod(num, parts) 4 | if rem == 0: 5 | return [quo] * parts 6 | return [quo if a > rem else quo + 1 for a in xrange(parts, 0, -1)] 7 | -------------------------------------------------------------------------------- /katas/kyu_6/alternating_loops.py: -------------------------------------------------------------------------------- 1 | from itertools import izip_longest 2 | 3 | 4 | def combine(*args): 5 | return [b for a in izip_longest(*args) for b in a if b] 6 | -------------------------------------------------------------------------------- /katas/kyu_6/arabian_string.py: -------------------------------------------------------------------------------- 1 | from re import split 2 | 3 | 4 | def camelize(string): 5 | return ''.join(a.capitalize() for a in split('([^a-zA-Z0-9])', string) 6 | if a.isalnum()) 7 | -------------------------------------------------------------------------------- /katas/kyu_6/are_they_the_same.py: -------------------------------------------------------------------------------- 1 | def comp(array1, array2): 2 | if None in (array1, array2): 3 | return False 4 | return sorted(a ** 2 for a in array1) == sorted(array2) 5 | -------------------------------------------------------------------------------- /katas/kyu_6/array_diff.py: -------------------------------------------------------------------------------- 1 | def array_diff(a, b): 2 | b = set(b) 3 | return [c for c in a if c not in b] 4 | -------------------------------------------------------------------------------- /katas/kyu_6/autocomplete_yay.py: -------------------------------------------------------------------------------- 1 | def only_az(s): 2 | return ''.join(a for a in s if a.isalpha()) 3 | 4 | 5 | def autocomplete(s, lst): 6 | s = only_az(s) 7 | return [a for a in lst if only_az(a).lower().startswith(s)][:5] 8 | -------------------------------------------------------------------------------- /katas/kyu_6/balance_the_arrays.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def balance(arr1, arr2): 5 | return (sorted(Counter(arr1).itervalues()) == 6 | sorted(Counter(arr2).itervalues())) 7 | -------------------------------------------------------------------------------- /katas/kyu_6/binary_to_text_conversion.py: -------------------------------------------------------------------------------- 1 | def binary_to_string(binary): 2 | return ''.join(chr(int(binary[a:a + 8], 2)) 3 | for a in xrange(0, len(binary), 8)) 4 | -------------------------------------------------------------------------------- /katas/kyu_6/bit_counting.py: -------------------------------------------------------------------------------- 1 | def countBits(n): 2 | """ count_bits == PEP8 (forced mixedCase by CodeWars) """ 3 | return '{:b}'.format(n).count('1') 4 | -------------------------------------------------------------------------------- /katas/kyu_6/build_tower.py: -------------------------------------------------------------------------------- 1 | def tower_builder(n): 2 | length = n * 2 - 1 3 | return ['{:^{}}'.format('*' * a, length) for a in xrange(1, length + 1, 2)] 4 | -------------------------------------------------------------------------------- /katas/kyu_6/collatz.py: -------------------------------------------------------------------------------- 1 | def collatz(n): 2 | result = [str(n)] 3 | while n > 1: 4 | if n % 2 == 0: 5 | n /= 2 6 | else: 7 | n = (3 * n) + 1 8 | result.append(str(n)) 9 | return '->'.join(result) 10 | -------------------------------------------------------------------------------- /katas/kyu_6/counting_duplicates.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def duplicate_count(text): 5 | return sum(a >= 2 for a in Counter(text.lower()).values()) 6 | -------------------------------------------------------------------------------- /katas/kyu_6/cryptography_1_viva_cesare.py: -------------------------------------------------------------------------------- 1 | from string import ascii_letters as az, maketrans, translate 2 | 3 | 4 | def caesar_crypto_encode(text, shift): 5 | if not text: 6 | return '' 7 | sh = shift % 52 8 | return translate(text, maketrans(az, az[sh:] + az[:sh])).strip() 9 | -------------------------------------------------------------------------------- /katas/kyu_6/digital_root.py: -------------------------------------------------------------------------------- 1 | def digital_root(n): 2 | return n if n <= 10 else digital_root(sum(map(int, str(n)))) 3 | -------------------------------------------------------------------------------- /katas/kyu_6/dna_sequence_tester.py: -------------------------------------------------------------------------------- 1 | from string import maketrans 2 | 3 | TABLE = maketrans('ATGC', 'TACG') 4 | 5 | 6 | def check_DNA(seq1, seq2): 7 | one, two = sorted((seq1, seq2), key=len) 8 | return one.translate(TABLE) in two[::-1] 9 | -------------------------------------------------------------------------------- /katas/kyu_6/does_my_number_look_big_in_this.py: -------------------------------------------------------------------------------- 1 | def narcissistic(value): 2 | num_str = str(value) 3 | length = len(num_str) 4 | return sum(int(a) ** length for a in num_str) == value 5 | -------------------------------------------------------------------------------- /katas/kyu_6/dont_rely_on_luck.py: -------------------------------------------------------------------------------- 1 | from random import randint, seed 2 | 3 | seed(1) 4 | guess = randint(1, 100) 5 | seed(1) 6 | -------------------------------------------------------------------------------- /katas/kyu_6/dubstep.py: -------------------------------------------------------------------------------- 1 | def song_decoder(song): 2 | return ' '.join(a for a in song.split('WUB') if a) 3 | -------------------------------------------------------------------------------- /katas/kyu_6/duplicate_encoder.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def duplicate_encode(word): 5 | word = word.lower() 6 | cnt = Counter(word) 7 | return ''.join('(' if cnt[a] == 1 else ')' for a in word) 8 | -------------------------------------------------------------------------------- /katas/kyu_6/equal_sides_of_an_array.py: -------------------------------------------------------------------------------- 1 | def find_even_index(lst): 2 | left_sum = 0 3 | right_sum = sum(lst) 4 | for i, a in enumerate(lst): 5 | right_sum -= a 6 | if left_sum == right_sum: 7 | return i 8 | left_sum += a 9 | return -1 10 | -------------------------------------------------------------------------------- /katas/kyu_6/evil_autocorrect_prank.py: -------------------------------------------------------------------------------- 1 | from re import compile, sub 2 | 3 | REGEX = compile(r'\b[yY][oO][uU]+\b|\b[uU]\b') 4 | 5 | 6 | def autocorrect(string): 7 | return sub(REGEX, 'your sister', string) 8 | -------------------------------------------------------------------------------- /katas/kyu_6/exercise_in_summing.py: -------------------------------------------------------------------------------- 1 | def maximum_sum(values, n): 2 | values.sort() 3 | return sum(values[-n:]) 4 | 5 | 6 | def minimum_sum(values, n): 7 | values.sort() 8 | return sum(values[:n]) 9 | -------------------------------------------------------------------------------- /katas/kyu_6/find_the_divisors.py: -------------------------------------------------------------------------------- 1 | def divisors(num): 2 | return [a for a in xrange(2, num / 2 + 1) if num % a == 0] or \ 3 | '{} is prime'.format(num) 4 | -------------------------------------------------------------------------------- /katas/kyu_6/find_the_mine.py: -------------------------------------------------------------------------------- 1 | def mineLocation(field): 2 | """ mine_location == PEP8 (forced mixedCase by CodeWars) """ 3 | for row, a in enumerate(field): 4 | for column, b in enumerate(a): 5 | if b == 1: 6 | return [row, column] 7 | -------------------------------------------------------------------------------- /katas/kyu_6/find_the_missing_letter.py: -------------------------------------------------------------------------------- 1 | def find_missing_letter(arr): 2 | prev = None 3 | for a in arr: 4 | current = ord(a) 5 | if prev is None or current - 1 == prev: 6 | prev = current 7 | else: 8 | return chr(current - 1) 9 | -------------------------------------------------------------------------------- /katas/kyu_6/find_the_odd_int.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def find_it(seq): 5 | for k, v in Counter(seq).iteritems(): 6 | if v % 2: 7 | return k 8 | -------------------------------------------------------------------------------- /katas/kyu_6/float_or_integer_verifier.py: -------------------------------------------------------------------------------- 1 | from re import compile, match 2 | 3 | REGEX = compile(r'[+-]?(?:(?=\.?\d)\d*\.\d*|\d+)(?:[eE][+-]?\d+|\d+)?$') 4 | 5 | 6 | def i_or_f(s): 7 | return bool(match(REGEX, s)) 8 | -------------------------------------------------------------------------------- /katas/kyu_6/format_a_string_of_names.py: -------------------------------------------------------------------------------- 1 | def namelist(names): 2 | if not names: 3 | return '' 4 | names = [a['name'] for a in names] 5 | if len(names) > 1: 6 | return '{} & {}'.format(', '.join(names[:-1]), names[-1]) 7 | return names[0] 8 | -------------------------------------------------------------------------------- /katas/kyu_6/function_composition.py: -------------------------------------------------------------------------------- 1 | def compose(f, g): 2 | return lambda *args: f(g(*args)) 3 | -------------------------------------------------------------------------------- /katas/kyu_6/function_iteration.py: -------------------------------------------------------------------------------- 1 | def create_iterator(func, n): 2 | def loop_it(a): 3 | for _ in xrange(n): 4 | a = func(a) 5 | return a 6 | return loop_it 7 | -------------------------------------------------------------------------------- /katas/kyu_6/get_all_possible_anagrams_from_a_hash.py: -------------------------------------------------------------------------------- 1 | from itertools import permutations 2 | 3 | 4 | def get_words(hash_of_letters): 5 | return sorted(''.join(b) for b in set(permutations(''.join( 6 | k * a for k, v in hash_of_letters.iteritems() for a in v)))) 7 | -------------------------------------------------------------------------------- /katas/kyu_6/grouped_by_commas.py: -------------------------------------------------------------------------------- 1 | def group_by_commas(n): 2 | return '{:,}'.format(n) 3 | -------------------------------------------------------------------------------- /katas/kyu_6/hamming_distance.py: -------------------------------------------------------------------------------- 1 | def hamming(a, b): 2 | return sum(c != d for c, d in zip(a, b)) 3 | -------------------------------------------------------------------------------- /katas/kyu_6/how_many_reindeers.py: -------------------------------------------------------------------------------- 1 | from math import ceil 2 | 3 | 4 | def reindeer(presents): 5 | assert 0 <= presents <= 180 6 | return int(2 + (ceil(presents / 30.0))) 7 | -------------------------------------------------------------------------------- /katas/kyu_6/html_complementary_color.py: -------------------------------------------------------------------------------- 1 | def get_reversed_color(hex_color): 2 | if not isinstance(hex_color, str) or len(hex_color) >= 7: 3 | raise ValueError 4 | return '#{:06X}'.format(0xffffff - int(hex_color or '0', 16)) 5 | -------------------------------------------------------------------------------- /katas/kyu_6/interlace_an_arbitrary_number_of_strings.py: -------------------------------------------------------------------------------- 1 | from itertools import izip_longest 2 | 3 | 4 | def combine_strings(*args): 5 | return ''.join(''.join(a) for a in izip_longest(*args, fillvalue='')) 6 | -------------------------------------------------------------------------------- /katas/kyu_6/ipv4_to_int32.py: -------------------------------------------------------------------------------- 1 | BINARY = '{0:08b}'.format 2 | 3 | 4 | def ip_to_int32(ip): 5 | return int(''.join(BINARY(int(a)) for a in ip.split('.')), 2) 6 | -------------------------------------------------------------------------------- /katas/kyu_6/is_prime.py: -------------------------------------------------------------------------------- 1 | # def is_prime(n): 2 | # if n < 2 or any(n % i == 0 for i in xrange(2, int(n ** 0.5) + 1)): 3 | # return False 4 | # return True 5 | 6 | 7 | def is_prime(n): 8 | return n > 1 and not any(n % i == 0 for i in xrange(2, int(n ** 0.5) + 1)) 9 | -------------------------------------------------------------------------------- /katas/kyu_6/jojos_bizarre_kata.py: -------------------------------------------------------------------------------- 1 | from re import compile, match, I 2 | 3 | regex = compile(r'((Jo\w+).* (Jo\w+$|\w+Jo))|((Gio\w+).* (Gio\w+$|\w+Gio))', I) 4 | 5 | 6 | def is_jojo(name): 7 | return bool(match(regex, name)) 8 | -------------------------------------------------------------------------------- /katas/kyu_6/lambdas_as_mechanism_for_open_closed.py: -------------------------------------------------------------------------------- 1 | spoken = lambda greeting: '{}.'.format(greeting.capitalize()) 2 | shouted = lambda greeting: '{}!'.format(greeting.upper()) 3 | whispered = lambda greeting: '{}.'.format(greeting.lower()) 4 | 5 | greet = lambda style, msg: style(msg) 6 | -------------------------------------------------------------------------------- /katas/kyu_6/leap_year_with_restrictions.py: -------------------------------------------------------------------------------- 1 | # PEP8: do not assign a lambda expression, use a ~d e f~ 2 | is_leap = lambda year: year % 4 == 0 and not year % 100 == 0 or year % 400 == 0 3 | 4 | # is_leap = getattr(__builtins__, '__tropmi__'[::-1])('calendar').isleap 5 | -------------------------------------------------------------------------------- /katas/kyu_6/midpoint_sum.py: -------------------------------------------------------------------------------- 1 | def midpoint_sum(ints): 2 | for a in xrange(1, len(ints) - 1): 3 | if sum(ints[:a]) == sum(ints[a + 1:]): 4 | return a 5 | -------------------------------------------------------------------------------- /katas/kyu_6/multiples_of_3_and_5.py: -------------------------------------------------------------------------------- 1 | def solution(number): 2 | return sum(a for a in xrange(3, number) if not a % 3 or not a % 5) 3 | -------------------------------------------------------------------------------- /katas/kyu_6/multiplication_tables.py: -------------------------------------------------------------------------------- 1 | def multiplication_table(row, col): 2 | return [range(a, a * col + 1, a) for a in xrange(1, row + 1)] 3 | -------------------------------------------------------------------------------- /katas/kyu_6/nested_list_depth.py: -------------------------------------------------------------------------------- 1 | def list_depth(lst): 2 | result = [list_depth(a) for a in lst if isinstance(a, list)] 3 | return 1 + max(result) if result else 1 4 | -------------------------------------------------------------------------------- /katas/kyu_6/parse_the_log.py: -------------------------------------------------------------------------------- 1 | logparser = r'(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2},\d{3})\s+' \ 2 | r'(DEBUG|ERROR|INFO)\s+\[(\w+):(\w+):?(\w+)?\]\s+(.+)$' 3 | -------------------------------------------------------------------------------- /katas/kyu_6/persistent_bugger.py: -------------------------------------------------------------------------------- 1 | def persistence(n): 2 | cnt = 0 3 | n = str(n) 4 | while len(n) > 1: 5 | n = str(reduce(lambda a, b: a * b, (int(c) for c in n))) 6 | cnt += 1 7 | return cnt 8 | -------------------------------------------------------------------------------- /katas/kyu_6/pingpong_service_problem.py: -------------------------------------------------------------------------------- 1 | def service(score): 2 | total = sum(int(a) for a in score.split(':')) 3 | return ('first', 'second')[(total / (5 if total < 40 else 2)) % 2] 4 | -------------------------------------------------------------------------------- /katas/kyu_6/playing_with_digits.py: -------------------------------------------------------------------------------- 1 | def dig_pow(n, p): 2 | total = sum(int(a) ** i for i, a in enumerate(str(n), start=p)) 3 | quo, rem = divmod(total, n) 4 | return quo if rem == 0 else -1 5 | -------------------------------------------------------------------------------- /katas/kyu_6/rank_vector.py: -------------------------------------------------------------------------------- 1 | def ranks(array): 2 | ranking = {} 3 | for i, a in enumerate(sorted(array, reverse=True), start=1): 4 | if a not in ranking: 5 | ranking[a] = i 6 | return [ranking[b] for b in array] 7 | -------------------------------------------------------------------------------- /katas/kyu_6/regexp_basics_is_it_ipv4_address.py: -------------------------------------------------------------------------------- 1 | from re import compile, match 2 | 3 | REGEX = compile(r'((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){4}$') 4 | 5 | 6 | def ipv4_address(address): 7 | # refactored thanks to @leonoverweel on CodeWars 8 | return bool(match(REGEX, address + '.')) 9 | -------------------------------------------------------------------------------- /katas/kyu_6/remove_anchor_from_url.py: -------------------------------------------------------------------------------- 1 | from re import compile, match 2 | 3 | REGEX = compile('www\.\w+\.[^#]+') 4 | 5 | 6 | def remove_url_anchor(url): 7 | return match(REGEX, url).group(0) 8 | 9 | 10 | # def remove_url_anchor(url): 11 | # return url.split('#')[0] 12 | -------------------------------------------------------------------------------- /katas/kyu_6/repeated_substring.py: -------------------------------------------------------------------------------- 1 | def f(string): 2 | length = len(string) 3 | for a in xrange(1, length + 1): 4 | current = string[:a] 5 | number = length / a 6 | if current * number == string: 7 | return current, number 8 | -------------------------------------------------------------------------------- /katas/kyu_6/replace_wth_alphabet_position.py: -------------------------------------------------------------------------------- 1 | from string import ascii_uppercase 2 | 3 | AZ = dict(zip(ascii_uppercase, map(str, xrange(1, 27)))) 4 | 5 | 6 | def alphabet_position(text): 7 | return ' '.join(AZ[a] for a in text.upper() if a.isalpha()) 8 | -------------------------------------------------------------------------------- /katas/kyu_6/reverse_words.py: -------------------------------------------------------------------------------- 1 | def reverse_words(string): 2 | return ' '.join(a[::-1] for a in string.split(' ')) 3 | -------------------------------------------------------------------------------- /katas/kyu_6/reversed_words.py: -------------------------------------------------------------------------------- 1 | def reverseWords(string): 2 | """ reverse_words == PEP8 (forced mixedCase by CodeWars) """ 3 | return ' '.join(reversed(string.split())) 4 | -------------------------------------------------------------------------------- /katas/kyu_6/rotate_array.py: -------------------------------------------------------------------------------- 1 | def rotate(arr, n): 2 | dex = -(n % len(arr)) 3 | return arr[dex:] + arr[:dex] 4 | -------------------------------------------------------------------------------- /katas/kyu_6/round_by_half_steps.py: -------------------------------------------------------------------------------- 1 | def solution(n): 2 | return round(n * 2) / 2.0 3 | -------------------------------------------------------------------------------- /katas/kyu_6/run_length_encoding.py: -------------------------------------------------------------------------------- 1 | from itertools import groupby 2 | 3 | 4 | def run_length_encoding(string): 5 | return [[sum(1 for _ in g), k] for k, g in groupby(string)] 6 | -------------------------------------------------------------------------------- /katas/kyu_6/same_array.py: -------------------------------------------------------------------------------- 1 | def same(arr_a, arr_b): 2 | return sorted(sorted(a) for a in arr_a) == sorted(sorted(b) for b in arr_b) 3 | -------------------------------------------------------------------------------- /katas/kyu_6/sequences_and_series.py: -------------------------------------------------------------------------------- 1 | def get_score(n): 2 | return n * (n + 1) * 25 3 | -------------------------------------------------------------------------------- /katas/kyu_6/simple_sentences.py: -------------------------------------------------------------------------------- 1 | def make_sentences(parts): 2 | return '{}.'.format( 3 | ''.join(' ' + a if a.isalnum() else a for a in parts).strip(' .')) 4 | -------------------------------------------------------------------------------- /katas/kyu_6/split_strings.py: -------------------------------------------------------------------------------- 1 | from itertools import izip_longest 2 | 3 | 4 | def solution(s): 5 | return [''.join(a) for a in izip_longest(s[::2], s[1::2], fillvalue='_')] 6 | -------------------------------------------------------------------------------- /katas/kyu_6/square_n_sum.py: -------------------------------------------------------------------------------- 1 | def square_sum(numbers): 2 | return sum(a ** 2 for a in numbers) 3 | -------------------------------------------------------------------------------- /katas/kyu_6/stop_spinning_my_words.py: -------------------------------------------------------------------------------- 1 | def spin_words(sentence): 2 | return ' '.join(a if len(a) < 5 else a[::-1] for a in sentence.split()) 3 | -------------------------------------------------------------------------------- /katas/kyu_6/string_suffixes.py: -------------------------------------------------------------------------------- 1 | def string_suffix(string): 2 | total = 0 3 | for a in xrange(len(string)): 4 | for b, c in zip(string, string[a:]): 5 | if not b == c: 6 | break 7 | total += 1 8 | return total 9 | -------------------------------------------------------------------------------- /katas/kyu_6/sum_consecutives.py: -------------------------------------------------------------------------------- 1 | from itertools import groupby 2 | 3 | 4 | def sum_consecutives(nums): 5 | return [sum(g) for _, g in groupby(nums)] 6 | -------------------------------------------------------------------------------- /katas/kyu_6/take_a_num_and_sum_digits_to_consecutive_powers.py: -------------------------------------------------------------------------------- 1 | NUMS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 89, 135, 175, 518, 598, 2 | 1306, 1676, 2427, 2646798, 12157692622039623539] 3 | 4 | 5 | def sum_dig_pow(a, b): 6 | return filter(lambda c: a <= c <= b, NUMS) 7 | -------------------------------------------------------------------------------- /katas/kyu_6/the_shell_game.py: -------------------------------------------------------------------------------- 1 | def find_the_ball(start, swaps): 2 | for a, b in swaps: 3 | if a == start: 4 | start = b 5 | elif b == start: 6 | start = a 7 | return start 8 | -------------------------------------------------------------------------------- /katas/kyu_6/ttt17_split_odd_and_even.py: -------------------------------------------------------------------------------- 1 | from itertools import groupby 2 | 3 | 4 | def split_odd_and_even(n): 5 | return [int(''.join(str(b) for b in g)) for k, g in 6 | groupby((int(a) for a in str(n)), key=lambda b: b % 2)] 7 | -------------------------------------------------------------------------------- /katas/kyu_6/two_sum.py: -------------------------------------------------------------------------------- 1 | def two_sum(nums, target): 2 | d = {} 3 | for i, num in enumerate(nums): 4 | diff = target - num 5 | if diff in d: 6 | return [d[diff], i] 7 | d[num] = i 8 | -------------------------------------------------------------------------------- /katas/kyu_6/unique_in_order.py: -------------------------------------------------------------------------------- 1 | from itertools import groupby 2 | 3 | 4 | def unique_in_order(iterable): 5 | return [k for k, g in groupby(iterable)] 6 | -------------------------------------------------------------------------------- /katas/kyu_6/weird_string_case.py: -------------------------------------------------------------------------------- 1 | def to_weird_case(string): 2 | return ' '.join(''.join(a.upper() if i % 2 == 0 else a.lower() for i, a in 3 | enumerate(word)) for word in string.split()) 4 | -------------------------------------------------------------------------------- /katas/kyu_6/what_is_the_point.py: -------------------------------------------------------------------------------- 1 | def pointless(*args): 2 | return "Rick Astley" 3 | -------------------------------------------------------------------------------- /katas/kyu_6/write_your_own_multiplication_function.py: -------------------------------------------------------------------------------- 1 | from numpy import multiply # this works! 2 | 3 | # def multiply(n, f): # doesn't work (efficiently) for large numbers! 4 | # return sum(n for _ in xrange(f)) 5 | -------------------------------------------------------------------------------- /katas/kyu_6/your_order_please.py: -------------------------------------------------------------------------------- 1 | def order(sentence): 2 | return ' '.join(sorted(sentence.split(), 3 | key=lambda a: next(b for b in a if b.isdigit()))) 4 | 5 | # def order(sentence): 6 | # return ' '.join(sorted(sentence.split(), key=lambda a: sorted(a))) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/katas/kyu_7/__init__.py -------------------------------------------------------------------------------- /katas/kyu_7/all_unique.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def has_unique_chars(s): 5 | return Counter(s).most_common(1)[0][1] == 1 6 | 7 | 8 | # def has_unique_chars(s): 9 | # return len(s) == len(set(s)) 10 | -------------------------------------------------------------------------------- /katas/kyu_7/alphabetize_by_nth_char.py: -------------------------------------------------------------------------------- 1 | from operator import itemgetter 2 | 3 | 4 | def sort_it(lst, n): 5 | return ', '.join(sorted(lst.split(', '), key=itemgetter(n - 1))) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/alternate_square_sum.py: -------------------------------------------------------------------------------- 1 | def alternate_sq_sum(arr): 2 | return sum(a if i % 2 == 0 else a ** 2 for i, a in enumerate(arr)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/anagram_detection.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def is_anagram(test, original): 5 | return Counter(test.lower()) == Counter(original.lower()) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/anything.py: -------------------------------------------------------------------------------- 1 | class AlwaysTrue(object): 2 | __eq__ = __ne__ = __gt__ = __ge__ = __lt__ = __le__ = lambda _, __: True 3 | 4 | 5 | def anything(*_): 6 | return AlwaysTrue() 7 | -------------------------------------------------------------------------------- /katas/kyu_7/are_the_numbers_in_order.py: -------------------------------------------------------------------------------- 1 | def in_asc_order(arr): 2 | return arr == sorted(arr) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/area_of_a_circle.py: -------------------------------------------------------------------------------- 1 | from math import pi 2 | 3 | 4 | def circleArea(r): 5 | """ circle_area == PEP8 (forced camelCase by codewars) """ 6 | if r <= 0 or not isinstance(r, (int, float)): 7 | return False 8 | return round(pi * (r ** 2), 2) 9 | -------------------------------------------------------------------------------- /katas/kyu_7/array_comparator.py: -------------------------------------------------------------------------------- 1 | def hashable(v): 2 | return set(tuple(a) if isinstance(a, list) else a for a in v) 3 | 4 | 5 | def match_arrays(v, r): 6 | return len(hashable(v).intersection(hashable(r))) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/author_disambiguation_to_the_point.py: -------------------------------------------------------------------------------- 1 | def could_be(original, another): 2 | if not original.strip() or not another.strip(): 3 | return False 4 | return set(another.split()).issubset(original.split()) 5 | -------------------------------------------------------------------------------- /katas/kyu_7/averages_of_numbers.py: -------------------------------------------------------------------------------- 1 | from operator import truediv 2 | 3 | 4 | def averages(nums): 5 | return [truediv(a + b, 2) for a, b in zip(nums, nums[1:])] if nums else [] 6 | -------------------------------------------------------------------------------- /katas/kyu_7/beginner_series_sum_of_numbers.py: -------------------------------------------------------------------------------- 1 | def get_sum(a, b): 2 | if a > b: 3 | a, b = b, a 4 | return sum(xrange(a, b + 1)) 5 | -------------------------------------------------------------------------------- /katas/kyu_7/binary_addition.py: -------------------------------------------------------------------------------- 1 | def add_binary(a, b): 2 | return format(a + b, 'b') 3 | -------------------------------------------------------------------------------- /katas/kyu_7/bobs_short_forms.py: -------------------------------------------------------------------------------- 1 | def short_form(s): 2 | return '{}{}{}'.format(s[0], s[1:-1].translate(None, 'aeiouAEIOU'), s[-1]) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/boiled_eggs.py: -------------------------------------------------------------------------------- 1 | from math import ceil 2 | 3 | 4 | def cooking_time(eggs): 5 | return ceil(eggs / 8.0) * 5 6 | -------------------------------------------------------------------------------- /katas/kyu_7/bouncy_numbers.py: -------------------------------------------------------------------------------- 1 | def is_bouncy(n): 2 | s = str(n) 3 | decrease = increase = False 4 | for a, b in zip(s, s[1:]): 5 | if a < b: 6 | increase = True 7 | elif a > b: 8 | decrease = True 9 | return decrease and increase 10 | -------------------------------------------------------------------------------- /katas/kyu_7/bug_fixing_failed_filter.py: -------------------------------------------------------------------------------- 1 | def filter_numbers(string): 2 | return ''.join(a for a in string if not a.isdigit()) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/bug_fixing_failed_sort.py: -------------------------------------------------------------------------------- 1 | def sort_array(value): 2 | return ''.join(sorted(value, key=lambda a: int(a))) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/bug_fixing_reducing_problems.py: -------------------------------------------------------------------------------- 1 | def calculate_total(t1, t2): 2 | return sum(t1) > sum(t2) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/bug_fixing_regex_failure.py: -------------------------------------------------------------------------------- 1 | from re import compile, IGNORECASE, sub 2 | 3 | REGEX = compile('(bad|mean|ugly|horrible|hideous)', flags=IGNORECASE) 4 | 5 | 6 | def filter_words(phrase): 7 | return sub(REGEX, 'awesome', phrase) 8 | -------------------------------------------------------------------------------- /katas/kyu_7/bug_fixing_unfinished_loop.py: -------------------------------------------------------------------------------- 1 | def create_array(n): 2 | return range(1, n + 1) 3 | 4 | 5 | # def create_array(n): 6 | # res = [] 7 | # i = 1 8 | # while i <= n: 9 | # res+=[i] 10 | # i += 1 11 | # return res 12 | -------------------------------------------------------------------------------- /katas/kyu_7/c_wars.py: -------------------------------------------------------------------------------- 1 | def initials(name): 2 | names = name.title().split() 3 | length = len(names) - 1 4 | return '.'.join(a[0] if length != i else a for i, a in enumerate(names)) 5 | -------------------------------------------------------------------------------- /katas/kyu_7/caeser_encryption.py: -------------------------------------------------------------------------------- 1 | from string import ascii_uppercase as az, maketrans 2 | 3 | 4 | def caeser(message, key): 5 | return message.upper().translate(maketrans(az[-key:] + az[:-key], az)) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/caffeine_script.py: -------------------------------------------------------------------------------- 1 | def caffeineBuzz(n): 2 | if n % 12 == 0: 3 | return 'CoffeeScript' 4 | elif n % 6 == 0: 5 | return 'JavaScript' 6 | elif n % 3 == 0: 7 | return 'Java' 8 | return 'mocha_missing!' 9 | -------------------------------------------------------------------------------- /katas/kyu_7/calculate_meal_total.py: -------------------------------------------------------------------------------- 1 | def calculate_total(subtotal, tax, tip): 2 | return round(subtotal * (100 + tax + tip) / 100, 2) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/case_swapping.py: -------------------------------------------------------------------------------- 1 | def swap(string): 2 | return string.swapcase() 3 | -------------------------------------------------------------------------------- /katas/kyu_7/categorize_new_member.py: -------------------------------------------------------------------------------- 1 | def openOrSenior(data): 2 | """ open_or_senior == PEP8 (forced mixedCase by CodeWars) """ 3 | return ['Senior' if age >= 55 and h > 7 else 'Open' for age, h in data] 4 | -------------------------------------------------------------------------------- /katas/kyu_7/char_code_calculation.py: -------------------------------------------------------------------------------- 1 | def calc(s): 2 | num = ''.join(str(ord(a)) for a in s) 3 | num2 = num.replace('7', '1') 4 | return abs(sum(int(b) for b in num) - sum(int(c) for c in num2)) 5 | -------------------------------------------------------------------------------- /katas/kyu_7/char_to_ascii.py: -------------------------------------------------------------------------------- 1 | def char_to_ascii(string): 2 | return {a: ord(a) for a in set(string) if a.isalpha()} or None 3 | -------------------------------------------------------------------------------- /katas/kyu_7/character_concatenation.py: -------------------------------------------------------------------------------- 1 | def char_concat(word): 2 | mid = len(word) / 2 3 | return ''.join('{}{}'.format(''.join(pair), i) 4 | for i, pair in enumerate(zip(word[:mid], 5 | word[-mid:][::-1]), start=1)) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/character_counter.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def validate_word(word): 5 | return len(set(Counter(word.lower()).itervalues())) == 1 6 | -------------------------------------------------------------------------------- /katas/kyu_7/coding_3min_bug_in_apple.py: -------------------------------------------------------------------------------- 1 | def sc(apple): 2 | return next([row, col] for row, a in enumerate(apple) 3 | for col, b in enumerate(a) if b == 'B') 4 | -------------------------------------------------------------------------------- /katas/kyu_7/coding_3min_father_and_son.py: -------------------------------------------------------------------------------- 1 | def sc(strng): 2 | seen = set(strng) 3 | return ''.join(a for a in strng if a.swapcase() in seen) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/collatz_conjecture.py: -------------------------------------------------------------------------------- 1 | def collatz(n): 2 | result = 1 3 | while n != 1: 4 | if n % 2 == 0: 5 | n /= 2 6 | else: 7 | n = n * 3 + 1 8 | result += 1 9 | return result 10 | -------------------------------------------------------------------------------- /katas/kyu_7/colour_association.py: -------------------------------------------------------------------------------- 1 | def colour_association(arr): 2 | return [{k: v} for k, v in arr] 3 | -------------------------------------------------------------------------------- /katas/kyu_7/combine_objects.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def combine(*args): 5 | return sum((Counter(a) for a in args), Counter()) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/common_substrings.py: -------------------------------------------------------------------------------- 1 | def substring_test(*args): 2 | shorter, longer = sorted((a.lower() for a in args), key=len) 3 | for b in xrange(len(shorter) - 1): 4 | if longer.find(shorter[b:b + 2]) != -1: 5 | return True 6 | return False 7 | -------------------------------------------------------------------------------- /katas/kyu_7/compare_strings_by_sum_of_chars.py: -------------------------------------------------------------------------------- 1 | def string_cnt(s): 2 | try: 3 | return s.isalpha() and sum(ord(a) for a in s.upper()) 4 | except AttributeError: 5 | return 0 6 | 7 | 8 | def compare(s1, s2): 9 | return string_cnt(s1) == string_cnt(s2) 10 | -------------------------------------------------------------------------------- /katas/kyu_7/complementary_dna.py: -------------------------------------------------------------------------------- 1 | from string import maketrans 2 | 3 | DNA = maketrans('ACGT', 'TGCA') 4 | 5 | 6 | def DNA_strand(string): 7 | """ dna_strand == PEP8 (forced naming by CodeWars) """ 8 | return string.translate(DNA) 9 | -------------------------------------------------------------------------------- /katas/kyu_7/composing_squared_strings.py: -------------------------------------------------------------------------------- 1 | def compose(s1, s2): 2 | substrs = s1.split() 3 | n = len(substrs[0]) 4 | return '\n'.join('{}{}'.format(a[:i], b[:n - (i - 1)]) for i, (a, b) in 5 | enumerate(zip(substrs, reversed(s2.split())), 1)) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/conference_traveller.py: -------------------------------------------------------------------------------- 1 | def conference_picker(visited, offered): 2 | visited = set(visited) 3 | return next((city for city in offered if city not in visited), 4 | 'No worthwhile conferences this year!') 5 | -------------------------------------------------------------------------------- /katas/kyu_7/consecutive_numbers_needed.py: -------------------------------------------------------------------------------- 1 | def consecutive(arr): 2 | arr.sort() 3 | return len(set(xrange(arr[0], arr[-1] + 1)).difference(arr)) if arr else 0 4 | -------------------------------------------------------------------------------- /katas/kyu_7/convert_integer_to_binary.py: -------------------------------------------------------------------------------- 1 | def to_binary(n): 2 | return '{:b}'.format(n & 4294967295) 3 | # return '{:b}'.format(n & 0xffffffff) 4 | # return '{:b}'.format(n & 0b11111111111111111111111111111111) 5 | -------------------------------------------------------------------------------- /katas/kyu_7/count_consonants.py: -------------------------------------------------------------------------------- 1 | VOWELS = set('aeiouAEIOU') 2 | 3 | 4 | def consonant_count(s): 5 | return sum(1 for a in s if a.isalpha() and a not in VOWELS) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/count_the_digit.py: -------------------------------------------------------------------------------- 1 | def nb_dig(n, d): 2 | return ''.join(str(a ** 2) for a in xrange(n + 1)).count(str(d)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/count_the_ones.py: -------------------------------------------------------------------------------- 1 | def hamming_weight(x): 2 | return '{:b}'.format(x).count('1') 3 | -------------------------------------------------------------------------------- /katas/kyu_7/countdown_to_christmas.py: -------------------------------------------------------------------------------- 1 | from datetime import date 2 | 3 | 4 | def days_until_christmas(day): 5 | christmas = date(day.year, 12, 25) 6 | if day > christmas: 7 | christmas = date(day.year + 1, 12, 25) 8 | return (christmas - day).days 9 | -------------------------------------------------------------------------------- /katas/kyu_7/counting_in_the_amazon.py: -------------------------------------------------------------------------------- 1 | def count_arara(num): 2 | adak, anane = divmod(num, 2) 3 | return ' '.join(['adak'] * adak + ['anane'] * anane) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/credit_card_mask.py: -------------------------------------------------------------------------------- 1 | def maskify(cc): 2 | return '{:#>{}}'.format(cc[-4:], len(cc)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/cyclical_permutation.py: -------------------------------------------------------------------------------- 1 | def pattern(n): 2 | digits = map(str, xrange(1, n + 1)) 3 | return '\n'.join(''.join(digits[b % n] 4 | for b in xrange(a, a + n)) for a in xrange(n)) 5 | -------------------------------------------------------------------------------- /katas/kyu_7/cyclops_number.py: -------------------------------------------------------------------------------- 1 | def cyclops(n): 2 | binary = format(n, 'b') 3 | length = len(binary) 4 | if not length % 2: 5 | return False 6 | return binary[length / 2] == '0' and binary.count('0') == 1 7 | -------------------------------------------------------------------------------- /katas/kyu_7/dad_is_commatose.py: -------------------------------------------------------------------------------- 1 | from re import compile, sub 2 | 3 | REGEX = compile(r',+') 4 | 5 | 6 | def dad_filter(strng): 7 | return sub(REGEX, ',', strng).rstrip(' ,') 8 | -------------------------------------------------------------------------------- /katas/kyu_7/debug_basic_calculator.py: -------------------------------------------------------------------------------- 1 | def calculate(a, o, b): 2 | try: 3 | if o in '+-*/': 4 | return eval('{}{}{}'.format(a, o, b)) 5 | except (SyntaxError, ZeroDivisionError): 6 | return None 7 | -------------------------------------------------------------------------------- /katas/kyu_7/decreasing_inputs.py: -------------------------------------------------------------------------------- 1 | def add(*args): 2 | return round(sum(a / float(i) for i, a in enumerate(args, start=1))) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/descending_order.py: -------------------------------------------------------------------------------- 1 | def Descending_Order(num): 2 | """ descending_order == PEP8 """ 3 | return int(''.join(sorted(str(num), reverse=True))) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/digitize.py: -------------------------------------------------------------------------------- 1 | def digitize(n): 2 | return map(int, str(n)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/disagreeable_ascii.py: -------------------------------------------------------------------------------- 1 | def get_weight(name): 2 | return sum(ord(a) for a in name.swapcase() if a.isalpha()) 3 | 4 | 5 | # Kata function name should use snake_case not mixedCase 6 | getWeight = get_weight 7 | -------------------------------------------------------------------------------- /katas/kyu_7/discover_the_original_price.py: -------------------------------------------------------------------------------- 1 | def discover_original_price(discounted_price, sale_percentage): 2 | return round(discounted_price / ((100 - sale_percentage) * 0.01), 2) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/disemvowel_trolls.py: -------------------------------------------------------------------------------- 1 | # VOWELS = 'aeiou' 2 | # 3 | # 4 | # def disemvowel(string): 5 | # return ''.join(a for a in string if not a.lower() in VOWELS) 6 | 7 | 8 | def disemvowel(s): 9 | return s.translate(None, 'aeiouAEIOU') 10 | -------------------------------------------------------------------------------- /katas/kyu_7/dna_gc_content.py: -------------------------------------------------------------------------------- 1 | def gc_content(seq): 2 | if not seq: 3 | return 0 4 | gc_cnt = total_chars = 0 5 | for a in seq: 6 | if a in 'GC': 7 | gc_cnt += 1 8 | total_chars += 1 9 | return round(100.0 * gc_cnt / total_chars, 2) 10 | -------------------------------------------------------------------------------- /katas/kyu_7/dont_give_me_five.py: -------------------------------------------------------------------------------- 1 | def dont_give_me_five(start, stop): 2 | return sum('5' not in str(a) for a in xrange(start, stop + 1)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/double_char.py: -------------------------------------------------------------------------------- 1 | OUTPUT = '{0}{0}'.format 2 | 3 | 4 | def double_char(s): 5 | return ''.join(OUTPUT(a) for a in s) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/dropcaps.py: -------------------------------------------------------------------------------- 1 | from re import split 2 | 3 | 4 | def drop_cap(string): 5 | return ''.join(a.capitalize() if not a.isspace() and len(a) > 2 else a 6 | for a in split(r'(\s+)', string)) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/easy_mathematical_callback.py: -------------------------------------------------------------------------------- 1 | def process_array(arr, callback): 2 | return map(callback, arr) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/email_address_obfuscator.py: -------------------------------------------------------------------------------- 1 | REPLACEMENTS = ('.', ' [dot] '), ('@', ' [at] ') 2 | 3 | 4 | def obfuscate(email): 5 | return reduce(lambda a, kv: a.replace(*kv), REPLACEMENTS, email) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/even_ladder.py: -------------------------------------------------------------------------------- 1 | def pattern(string): 2 | return '\n'.join(str(a) * a for a in xrange(2, string + 1, 2)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/every_archer_has_its_arrows.py: -------------------------------------------------------------------------------- 1 | def archers_ready(archers): 2 | return all(a >= 5 for a in archers) if archers else False 3 | -------------------------------------------------------------------------------- /katas/kyu_7/every_nth_array_element_basic.py: -------------------------------------------------------------------------------- 1 | def every(lst, n=1, start=0): 2 | return lst[start::n] 3 | -------------------------------------------------------------------------------- /katas/kyu_7/excel_sheet_column_numbers.py: -------------------------------------------------------------------------------- 1 | def title_to_number(title): 2 | return sum((ord(a) - 64) * (26 ** i) for i, a in enumerate(title[::-1])) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/exes_and_ohs.py: -------------------------------------------------------------------------------- 1 | VALUES = {'x': 1, 'X': 1, 'o': -1, 'O': -1} 2 | 3 | 4 | def xo(s): 5 | return not sum(VALUES.get(a, 0) for a in s) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/factorial.py: -------------------------------------------------------------------------------- 1 | from math import factorial 2 | -------------------------------------------------------------------------------- /katas/kyu_7/factorial_factory.py: -------------------------------------------------------------------------------- 1 | def factorial(n): 2 | if n < 0: 3 | return None 4 | elif n == 0: 5 | return 1 6 | return reduce(lambda a, b: a * b, xrange(1, n + 1)) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/filter_coffee.py: -------------------------------------------------------------------------------- 1 | def search(budget, prices): 2 | return ','.join(str(a) for a in sorted(prices) if a <= budget) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/filter_list.py: -------------------------------------------------------------------------------- 1 | def filter_list(lst): 2 | return filter(lambda a: isinstance(a, int), lst) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/filter_long_words.py: -------------------------------------------------------------------------------- 1 | def filter_long_words(sentence, n): 2 | return filter(lambda a: len(a) > n, sentence.split()) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/filter_the_number.py: -------------------------------------------------------------------------------- 1 | def filter_string(string): 2 | return int(''.join(a for a in string if a.isdigit())) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/filter_unused_digits.py: -------------------------------------------------------------------------------- 1 | DIGITS = set('0123456789') 2 | 3 | 4 | def unused_digits(*args): 5 | return ''.join(sorted(DIGITS.difference(''.join(str(a) for a in args)))) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/find_count_of_most_frequent_item_in_array.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def most_frequent_item_count(collection): 5 | return Counter(collection).most_common(1)[0][1] if collection else 0 6 | -------------------------------------------------------------------------------- /katas/kyu_7/find_divisors.py: -------------------------------------------------------------------------------- 1 | def divisors(n): 2 | return sum(n % a == 0 for a in xrange(1, n + 1)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/find_duplicate.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def find_dup(arr): 5 | return Counter(arr).most_common(1)[0][0] 6 | -------------------------------------------------------------------------------- /katas/kyu_7/find_duplicates.py: -------------------------------------------------------------------------------- 1 | def duplicates(array): 2 | seen_before = set() 3 | result = [] 4 | for a in array: 5 | if a not in result and a in seen_before: 6 | result.append(a) 7 | seen_before.add(a) 8 | return result 9 | -------------------------------------------------------------------------------- /katas/kyu_7/find_missing_numbers.py: -------------------------------------------------------------------------------- 1 | def find_missing_numbers(arr): 2 | if not arr: 3 | return [] 4 | return sorted(set(xrange(arr[0] + 1, arr[-1])).difference(arr)) 5 | -------------------------------------------------------------------------------- /katas/kyu_7/find_smallest_int.py: -------------------------------------------------------------------------------- 1 | def findSmallestInt(arr): 2 | """ find_smallest_int == PEP8 (forced mixedCase by CodeWars) """ 3 | return min(arr) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/find_the_capitals.py: -------------------------------------------------------------------------------- 1 | def capitals(word): 2 | return [i for i, a in enumerate(word) if a.isupper()] 3 | -------------------------------------------------------------------------------- /katas/kyu_7/find_the_longest_gap.py: -------------------------------------------------------------------------------- 1 | from re import compile, findall 2 | 3 | REGEX = compile(r'(?=1(0+)1)') 4 | 5 | 6 | def gap(num): 7 | return max(len(a) for a in findall(REGEX, bin(num)) + ['']) 8 | -------------------------------------------------------------------------------- /katas/kyu_7/find_the_motif_in_dna_sequence.py: -------------------------------------------------------------------------------- 1 | def motif_locator(seq, motif): 2 | dex = 0 3 | result = [] 4 | while True: 5 | dex = seq.find(motif, dex) 6 | if dex == -1: 7 | return result 8 | dex += 1 9 | result.append(dex) 10 | -------------------------------------------------------------------------------- /katas/kyu_7/find_the_stray_number.py: -------------------------------------------------------------------------------- 1 | def stray(arr): 2 | return reduce(lambda prev, curr: prev ^ curr, arr) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/find_the_volume_of_a_cone.py: -------------------------------------------------------------------------------- 1 | from math import pi 2 | 3 | 4 | def volume(r, h): 5 | return int(pi * r ** 2 * h / 3) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/find_the_vowels.py: -------------------------------------------------------------------------------- 1 | VOWELS = set('aeiou') 2 | 3 | 4 | def vowel_indices(word): 5 | return [i for i, a in enumerate(word.lower(), 1) if a in VOWELS] 6 | -------------------------------------------------------------------------------- /katas/kyu_7/finding_remainder_without_using_modulo.py: -------------------------------------------------------------------------------- 1 | def remainder(dividend, divisor): 2 | return dividend - dividend / divisor * divisor 3 | -------------------------------------------------------------------------------- /katas/kyu_7/first_class_function_factory.py: -------------------------------------------------------------------------------- 1 | def factory(x): 2 | return lambda b: map(lambda a: a * x, b) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/flatten.py: -------------------------------------------------------------------------------- 1 | def flatten(lst): 2 | result = [] 3 | for a in lst: 4 | if isinstance(a, list): 5 | result.extend(a) 6 | else: 7 | result.append(a) 8 | return result 9 | -------------------------------------------------------------------------------- /katas/kyu_7/formatting_decimal_places_1.py: -------------------------------------------------------------------------------- 1 | from math import trunc 2 | 3 | 4 | def two_decimal_places(number): 5 | factor = float(10 ** 2) 6 | return trunc(number * factor) / factor 7 | -------------------------------------------------------------------------------- /katas/kyu_7/frequency_sequence.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def freq_seq(s, sep): 5 | cnt = Counter(s) 6 | return sep.join(str(cnt[a]) for a in s) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/from_to_step_sequence_generator.py: -------------------------------------------------------------------------------- 1 | def generator(start, stop, step): 2 | if step <= 0: 3 | return [] 4 | elif start > stop: 5 | step *= -1 6 | stop -= 2 7 | return range(start, stop + 1, step) 8 | -------------------------------------------------------------------------------- /katas/kyu_7/functional_addition.py: -------------------------------------------------------------------------------- 1 | def add(n): 2 | return lambda a: a + n 3 | -------------------------------------------------------------------------------- /katas/kyu_7/gauss_needs_help.py: -------------------------------------------------------------------------------- 1 | def f(n): 2 | if isinstance(n, int) and n >= 1: 3 | return n * (n + 1) / 2 4 | -------------------------------------------------------------------------------- /katas/kyu_7/genetic_algorithm_series_1_generate.py: -------------------------------------------------------------------------------- 1 | from random import choice 2 | 3 | ONEZERO = '10' 4 | 5 | 6 | def generate(length): 7 | return ''.join(choice(ONEZERO) for _ in xrange(length)) 8 | -------------------------------------------------------------------------------- /katas/kyu_7/genetic_algorithm_series_2_mutation.py: -------------------------------------------------------------------------------- 1 | from random import random 2 | 3 | 4 | def mutate(chromosome, p): 5 | return ''.join((a, '01'[a == '0'])[random() <= p] for a in chromosome) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/genetic_algorithm_series_crossover.py: -------------------------------------------------------------------------------- 1 | def crossover(chromosome1, chromosome2, index): 2 | return [chromosome1[:index] + chromosome2[index:], 3 | chromosome2[:index] + chromosome1[index:]] 4 | -------------------------------------------------------------------------------- /katas/kyu_7/ghostbusters_whitespace_removal.py: -------------------------------------------------------------------------------- 1 | def ghostbusters(building): 2 | return building.replace(' ', '') if building.find(' ') > -1 \ 3 | else 'You just wanted my autograph didn\'t you?' 4 | -------------------------------------------------------------------------------- /katas/kyu_7/gradually_adding_parameters.py: -------------------------------------------------------------------------------- 1 | def add(*args): 2 | return sum(i * a for i, a in enumerate(args, start=1)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/greatest_common_divisor.py: -------------------------------------------------------------------------------- 1 | def mygcd(a, b): 2 | while b: 3 | a, b = b, a % b 4 | return a 5 | -------------------------------------------------------------------------------- /katas/kyu_7/green_glass_door.py: -------------------------------------------------------------------------------- 1 | from itertools import izip 2 | 3 | 4 | def step_through_with(s): 5 | for a, b in izip(s, s[1:]): 6 | if a == b: 7 | return True 8 | return False 9 | -------------------------------------------------------------------------------- /katas/kyu_7/grid_blast.py: -------------------------------------------------------------------------------- 1 | grid = ['top left', 'top middle', 'top right', 2 | 'middle left', 'center', 'middle right', 3 | 'bottom left', 'bottom middle', 'bottom right'] 4 | 5 | 6 | def fire(x, y): 7 | return grid[x + y * 3] 8 | -------------------------------------------------------------------------------- /katas/kyu_7/growth_of_a_population.py: -------------------------------------------------------------------------------- 1 | def nb_year(p0, percent, aug, p): 2 | percent /= 100.0 3 | years = 0 4 | while p0 < p: 5 | p0 += p0 * percent + aug 6 | years += 1 7 | return years 8 | -------------------------------------------------------------------------------- /katas/kyu_7/guess_my_number.py: -------------------------------------------------------------------------------- 1 | def guess_my_number(guess, number='123-451-2345'): 2 | return ''.join(a if a in guess + '-' else '#' for a in number) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/hamming_distance_binary_codes.py: -------------------------------------------------------------------------------- 1 | def hamming_distance(a, b): 2 | return sum(c != d for c, d in zip(a, b)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/head_tail_init_last.py: -------------------------------------------------------------------------------- 1 | def head(lst): 2 | return lst[0] 3 | 4 | 5 | def tail(lst): 6 | return lst[1:] 7 | 8 | 9 | def init(lst): 10 | return lst[:-1] 11 | 12 | 13 | def last(lst): 14 | return lst[-1] 15 | -------------------------------------------------------------------------------- /katas/kyu_7/help_mr_e.py: -------------------------------------------------------------------------------- 1 | from re import compile, sub 2 | 3 | OUTPUT = '{}{}'.format 4 | REGEX = compile(r'[^a-zA-Z0-9 ]') 5 | 6 | 7 | def evenator(s): 8 | return ' '.join(OUTPUT(a, a[-1]) if len(a) % 2 else a 9 | for a in sub(REGEX, '', s).split()) 10 | -------------------------------------------------------------------------------- /katas/kyu_7/help_suzuki_rake_his_garden.py: -------------------------------------------------------------------------------- 1 | VALID = {'gravel', 'rock'} 2 | 3 | 4 | def rake_garden(garden): 5 | return ' '.join(a if a in VALID else 'gravel' for a in garden.split()) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/highest_and_lowest.py: -------------------------------------------------------------------------------- 1 | def high_and_low(numbers): 2 | nums = sorted(numbers.split(), key=int) 3 | return '{} {}'.format(nums[-1], nums[0]) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/highest_profit.py: -------------------------------------------------------------------------------- 1 | def min_max(lst): 2 | lst.sort() 3 | return [lst[0], lst[-1]] 4 | -------------------------------------------------------------------------------- /katas/kyu_7/hit_count.py: -------------------------------------------------------------------------------- 1 | def counter_effect(hit_count): 2 | return [list(xrange(int(a) + 1)) for a in hit_count] 3 | -------------------------------------------------------------------------------- /katas/kyu_7/holiday_v_seasick_snorkelling.py: -------------------------------------------------------------------------------- 1 | from operator import truediv 2 | 3 | 4 | def sea_sick(s): 5 | result = sum(s[a:a + 2] in '_~_' for a in xrange(len(s) - 1)) 6 | if truediv(result, len(s)) > 0.2: 7 | return 'Throw Up' 8 | return 'No Problem' 9 | -------------------------------------------------------------------------------- /katas/kyu_7/how_far_will_i_go.py: -------------------------------------------------------------------------------- 1 | def travel(total_time, run_time, rest_time, speed): 2 | q, r = divmod(total_time, run_time + rest_time) 3 | return (q * run_time + min(r, run_time)) * speed 4 | -------------------------------------------------------------------------------- /katas/kyu_7/how_many_are_smaller_than_me.py: -------------------------------------------------------------------------------- 1 | def smaller(arr): 2 | return [sum(b < a for b in arr[i + 1:]) for i, a in enumerate(arr)] 3 | -------------------------------------------------------------------------------- /katas/kyu_7/identical_elements.py: -------------------------------------------------------------------------------- 1 | def duplicate_elements(m, n): 2 | return bool(set(m).intersection(n)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/insert_dashes.py: -------------------------------------------------------------------------------- 1 | ODD = {1, 3, 5, 7, 9} 2 | 3 | 4 | def insert_dash(num): 5 | num = str(num) 6 | dex = {i for i, a in enumerate(num) if int(a) in ODD} 7 | return ''.join(b + '-' if {i, i + 1}.issubset(dex) else b 8 | for i, b in enumerate(num)) 9 | -------------------------------------------------------------------------------- /katas/kyu_7/integer_difference.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def int_diff(arr, n): 5 | cnts = Counter(arr) 6 | if n == 0: 7 | return sum(v * (v - 1) // 2 for v in cnts.values()) 8 | return sum(v * cnts[k + n] for k, v in cnts.items()) 9 | -------------------------------------------------------------------------------- /katas/kyu_7/integer_to_currency_format.py: -------------------------------------------------------------------------------- 1 | def to_currency(price): 2 | return '{:,}'.format(price) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/is_divisible.py: -------------------------------------------------------------------------------- 1 | def is_divisible(*args): 2 | n = args[0] 3 | return all(n % a == 0 for a in args[1:]) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/is_every_value_in_the_array_an_array.py: -------------------------------------------------------------------------------- 1 | def arr_check(arr): 2 | return all(isinstance(a, list) for a in arr) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/is_prime.py: -------------------------------------------------------------------------------- 1 | def is_prime(n): 2 | if n <= 1: 3 | return False 4 | for x in xrange(2, n): 5 | if n % x == 0: 6 | return False 7 | return True 8 | -------------------------------------------------------------------------------- /katas/kyu_7/is_this_a_triangle.py: -------------------------------------------------------------------------------- 1 | def is_triangle(*args): 2 | a, b, c = sorted(args) 3 | return a + b > c 4 | -------------------------------------------------------------------------------- /katas/kyu_7/is_valid_identifier.py: -------------------------------------------------------------------------------- 1 | from re import compile, match 2 | 3 | REGEX = compile(r'[a-zA-Z_$][\w$]*$') 4 | 5 | 6 | def is_valid(idn): 7 | return bool(match(REGEX, idn)) 8 | -------------------------------------------------------------------------------- /katas/kyu_7/isograms.py: -------------------------------------------------------------------------------- 1 | def is_isogram(string): 2 | return len(string) == len(set(string.lower())) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/jaden_casing_strings.py: -------------------------------------------------------------------------------- 1 | def toJadenCase(string): 2 | """ to_jaden_case == PEP8 (forced mixedCase by CodeWars) """ 3 | return ' '.join(a.capitalize() for a in string.split()) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/javascript_filter_1.py: -------------------------------------------------------------------------------- 1 | def search_names(logins): 2 | return filter(lambda (a, _): a.endswith('_'), logins) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/katastrophe.py: -------------------------------------------------------------------------------- 1 | def strong_enough(earthquake, age): 2 | magnitude = reduce(lambda a, b: a * b, (sum(c) for c in earthquake)) 3 | strength = 1000 * 0.99 ** age 4 | return 'Needs Reinforcement!' if magnitude > strength else 'Safe!' 5 | -------------------------------------------------------------------------------- /katas/kyu_7/keep_the_order.py: -------------------------------------------------------------------------------- 1 | from bisect import bisect_left as keep_order 2 | -------------------------------------------------------------------------------- /katas/kyu_7/keypad_horror.py: -------------------------------------------------------------------------------- 1 | from string import maketrans 2 | 3 | PHONE = maketrans('123789', '789123') 4 | 5 | 6 | def computer_to_phone(nums): 7 | return nums.translate(PHONE) 8 | -------------------------------------------------------------------------------- /katas/kyu_7/largest_elements.py: -------------------------------------------------------------------------------- 1 | def largest(n, xs): 2 | """Find the n highest elements in a list""" 3 | return sorted(xs)[-n:] 4 | -------------------------------------------------------------------------------- /katas/kyu_7/last_man_standing.py: -------------------------------------------------------------------------------- 1 | def last_man_standing(n): 2 | numbers = range(1, n + 1) 3 | go_right = True 4 | while len(numbers) > 1: 5 | numbers = numbers[1::2] if go_right else numbers[-2::-2][::-1] 6 | go_right = not go_right 7 | return numbers[0] 8 | -------------------------------------------------------------------------------- /katas/kyu_7/lazily_executing_a_function.py: -------------------------------------------------------------------------------- 1 | def make_lazy(func, *args, **kwargs): 2 | return lambda: func(*args, **kwargs) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/leap_years.py: -------------------------------------------------------------------------------- 1 | def isLeapYear(year): 2 | """ is_leap_year == PEP8, forced mixedCase by CodeWars """ 3 | return year % 4 == 0 and not year % 100 == 0 or year % 400 == 0 4 | -------------------------------------------------------------------------------- /katas/kyu_7/left_and_right.py: -------------------------------------------------------------------------------- 1 | def left(string, i=1): 2 | return string[:string.index(i) if isinstance(i, str) else i] 3 | 4 | 5 | def right(string, i=1): 6 | i = string[::-1].index(i[::-1]) if isinstance(i, str) else i 7 | return string[-i:] if not i == 0 else "" 8 | -------------------------------------------------------------------------------- /katas/kyu_7/length_of_a_vector.py: -------------------------------------------------------------------------------- 1 | def vector_length(vector): 2 | (x, y), (x2, y2) = vector 3 | return ((x2 - x) ** 2 + (y2 - y) ** 2) ** 0.5 4 | -------------------------------------------------------------------------------- /katas/kyu_7/length_of_line_segment.py: -------------------------------------------------------------------------------- 1 | def length_of_line(array): 2 | (x, y), (x2, y2) = array 3 | return '{:.2f}'.format(((x2 - x) ** 2 + (y2 - y) ** 2) ** 0.5) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/length_of_sequence.py: -------------------------------------------------------------------------------- 1 | def length_of_sequence(arr, n): 2 | total = [i for i, a in enumerate(arr) if a == n] 3 | return 0 if len(total) != 2 else total[1] - total[0] + 1 4 | -------------------------------------------------------------------------------- /katas/kyu_7/make_a_function_that_does_arithmetic.py: -------------------------------------------------------------------------------- 1 | from operator import add, mul, sub, truediv 2 | 3 | 4 | def arithmetic(a, b, operator): 5 | ops = {'add': add, 'subtract': sub, 'multiply': mul, 'divide': truediv} 6 | return ops[operator](a, b) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/make_them_bark.py: -------------------------------------------------------------------------------- 1 | class Dog(object): 2 | def __init__(self, name, breed, sex, age): 3 | self.age = age 4 | self.breed = breed 5 | self.name = name 6 | self.sex = sex 7 | 8 | setattr(Dog, 'bark', lambda a: 'Woof!') # class is pre-loaded in kata 9 | -------------------------------------------------------------------------------- /katas/kyu_7/making_copies.py: -------------------------------------------------------------------------------- 1 | def copy_list(l): 2 | return l[:] 3 | -------------------------------------------------------------------------------- /katas/kyu_7/monotone_travel.py: -------------------------------------------------------------------------------- 1 | def is_monotone(heights): 2 | return sorted(heights) == heights 3 | -------------------------------------------------------------------------------- /katas/kyu_7/more_than_zero.py: -------------------------------------------------------------------------------- 1 | def corrections(x): 2 | return '{} is {} than zero.'.format( 3 | x, 'more' if x > 0 else 'equal to or less') 4 | -------------------------------------------------------------------------------- /katas/kyu_7/moves_in_squared_strings_one.py: -------------------------------------------------------------------------------- 1 | def hor_mirror(s): 2 | return '\n'.join(reversed(s.split('\n'))) 3 | 4 | 5 | def vert_mirror(s): 6 | return '\n'.join(a[::-1] for a in s.split('\n')) 7 | 8 | 9 | def oper(fct, s): 10 | return fct(s) 11 | -------------------------------------------------------------------------------- /katas/kyu_7/multiply_characters.py: -------------------------------------------------------------------------------- 1 | def spam(number): 2 | return 'hue' * number 3 | -------------------------------------------------------------------------------- /katas/kyu_7/mumbling.py: -------------------------------------------------------------------------------- 1 | def accum(s): 2 | return '-'.join(str.title(a * i) for i, a in enumerate(s, 1)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/narcissistic_numbers.py: -------------------------------------------------------------------------------- 1 | def is_narcissistic(n): 2 | num = str(n) 3 | length = len(num) 4 | return sum(int(a) ** length for a in num) == n 5 | -------------------------------------------------------------------------------- /katas/kyu_7/new_5_pound_notes_collectors.py: -------------------------------------------------------------------------------- 1 | def get_new_notes(salary, bills): 2 | return max((salary - sum(bills)) // 5, 0) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/ninja_vs_samurai_strike.py: -------------------------------------------------------------------------------- 1 | class Warrior: 2 | def __init__(self, name): 3 | self.name = name 4 | self.health = 100 5 | 6 | @staticmethod 7 | def strike(enemy, swings): 8 | enemy.health = max((0, enemy.health - (swings * 10))) 9 | -------------------------------------------------------------------------------- /katas/kyu_7/noobcode_4_hot_singles.py: -------------------------------------------------------------------------------- 1 | from collections import OrderedDict 2 | from itertools import chain 3 | 4 | 5 | def hot_singles(arr1, arr2): 6 | diff = set(arr1).symmetric_difference(arr2) 7 | return [a for a in OrderedDict.fromkeys(chain(arr1, arr2)) if a in diff] 8 | -------------------------------------------------------------------------------- /katas/kyu_7/noonerize_me.py: -------------------------------------------------------------------------------- 1 | def noonerize(numbers): 2 | output = '{}{}'.format 3 | if any(not isinstance(a, int) for a in numbers): 4 | return 'invalid array' 5 | b, c = (str(d) for d in numbers) 6 | return abs(int(output(c[0], b[1:])) - int(output(b[0], c[1:]))) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/number_encrypting_cypher.py: -------------------------------------------------------------------------------- 1 | def cypher(text): 2 | d = dict(zip('IREASGTBOlzeasbtgo', '123456780123456790')) 3 | return ''.join(d.get(a, a) for a in text) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/number_of_occurrences.py: -------------------------------------------------------------------------------- 1 | def number_of_occurrences(item, lst): 2 | return lst.count(item) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/number_pairs.py: -------------------------------------------------------------------------------- 1 | def get_larger_numbers(a, b): 2 | return map(max, a, b) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/number_star_ladder.py: -------------------------------------------------------------------------------- 1 | OUTPUT = '1{}{}'.format 2 | 3 | 4 | def pattern(n): 5 | return '\n'.join(OUTPUT('*' * a, a + 1 if a else '') for a in xrange(n)) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/numbers_to_letters.py: -------------------------------------------------------------------------------- 1 | from string import ascii_lowercase as az 2 | 3 | 4 | def switcher(arr): 5 | letters = {i + 1: a for i, a in enumerate(reversed(' ?!' + az))} 6 | return ''.join(letters.get(int(b), '') for b in arr) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/numbers_with_this_digit_inside.py: -------------------------------------------------------------------------------- 1 | from operator import mul 2 | 3 | 4 | def numbers_with_digit_inside(x, d): 5 | num_str = str(d) 6 | nums = [a for a in xrange(1, x + 1) if num_str in str(a)] 7 | return [len(nums), sum(nums), reduce(mul, nums) if nums else 0] 8 | -------------------------------------------------------------------------------- /katas/kyu_7/nums_powers_of_digits_equal_num.py: -------------------------------------------------------------------------------- 1 | def eq_sum_powdig(hMax, exp): 2 | return [a for a in xrange(2, hMax + 1) 3 | if a == sum(int(b) ** exp for b in str(a))] 4 | -------------------------------------------------------------------------------- /katas/kyu_7/odd_ladder.py: -------------------------------------------------------------------------------- 1 | def pattern(n): 2 | return '\n'.join(str(a) * a for a in xrange(1, n + 1, 2)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/operations_with_sets.py: -------------------------------------------------------------------------------- 1 | def process_2arrays(arr1, arr2): 2 | arr1 = set(arr1) 3 | arr2 = set(arr2) 4 | diff = len(arr1 - arr2) 5 | diff2 = len(arr2 - arr1) 6 | return [len(arr1 & arr2), diff + diff2, diff, diff2] 7 | -------------------------------------------------------------------------------- /katas/kyu_7/ordering_the_words.py: -------------------------------------------------------------------------------- 1 | def order_word(s): 2 | return ''.join(sorted(s)) if s else 'Invalid String!' 3 | -------------------------------------------------------------------------------- /katas/kyu_7/partial_word_searching.py: -------------------------------------------------------------------------------- 1 | def word_search(query, seq): 2 | query = query.lower() 3 | return filter(lambda a: query in a.lower(), seq) or ['None'] 4 | -------------------------------------------------------------------------------- /katas/kyu_7/parts_of_a_list.py: -------------------------------------------------------------------------------- 1 | def partlist(arr): 2 | return [(' '.join(arr[:a]), ' '.join(arr[a:])) 3 | for a in xrange(1, len(arr))] 4 | -------------------------------------------------------------------------------- /katas/kyu_7/pattern_1.py: -------------------------------------------------------------------------------- 1 | def pattern(n): 2 | return '\n'.join(str(a) * a for a in xrange(1, n + 1)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/pattern_2.py: -------------------------------------------------------------------------------- 1 | def pattern(n): 2 | nums = map(str, xrange(n, 0, -1)) 3 | return '\n'.join(''.join(nums[:a]) for a in xrange(n, 0, -1)) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/pattern_3.py: -------------------------------------------------------------------------------- 1 | def pattern(n): 2 | nums = map(str, xrange(n, 0, -1)) 3 | return '\n'.join(''.join(nums[:a]) for a in xrange(1, n + 1)) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/pattern_4.py: -------------------------------------------------------------------------------- 1 | def pattern(n): 2 | nums = map(str, xrange(1, n + 1)) 3 | return '\n'.join(''.join(nums[-a:]) for a in xrange(n, 0, -1)) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/penultimate.py: -------------------------------------------------------------------------------- 1 | def penultimate(nums): 2 | return nums[-2] 3 | -------------------------------------------------------------------------------- /katas/kyu_7/perfect_number_verifier.py: -------------------------------------------------------------------------------- 1 | def isPerfect(n): 2 | nums = set() 3 | for a in xrange(1, int(n ** 0.5) + 1): 4 | q, r = divmod(n, a) 5 | if not r: 6 | nums.add(a) 7 | nums.add(q) 8 | return sum(nums) - n == n 9 | -------------------------------------------------------------------------------- /katas/kyu_7/pillow_on_the_fridge.py: -------------------------------------------------------------------------------- 1 | def pillow(arr): 2 | s1, s2 = arr 3 | return bool({i for i, a in enumerate(s1) if a == 'n'} & 4 | {i for i, b in enumerate(s2) if b == 'B'}) 5 | -------------------------------------------------------------------------------- /katas/kyu_7/power_of_two.py: -------------------------------------------------------------------------------- 1 | def power_of_two(num): 2 | return bin(num).count('1') == 1 3 | -------------------------------------------------------------------------------- /katas/kyu_7/printer_errors.py: -------------------------------------------------------------------------------- 1 | COLORS = set('abcdefghijklm') 2 | 3 | 4 | def printer_error(s): 5 | errors = 0 6 | for i, color in enumerate(s, 1): 7 | if color not in COLORS: 8 | errors += 1 9 | else: 10 | return '{}/{}'.format(errors, i) 11 | -------------------------------------------------------------------------------- /katas/kyu_7/product_of_main_diagonal.py: -------------------------------------------------------------------------------- 1 | from operator import mul 2 | 3 | 4 | def main_diagonal_product(matrix): 5 | return reduce(mul, (matrix[a][a] for a in xrange(len(matrix)))) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/pythons_dynamic_classes_1.py: -------------------------------------------------------------------------------- 1 | def class_name_changer(cls, new_name) : 2 | if not new_name[0].isupper() or not new_name.isalnum(): 3 | raise NameError('Invalid class name!') 4 | cls.__name__ = new_name 5 | -------------------------------------------------------------------------------- /katas/kyu_7/random_case.py: -------------------------------------------------------------------------------- 1 | from random import choice 2 | 3 | UP_LOW = (str.upper, str.lower) 4 | 5 | 6 | def random_case(strng): 7 | return ''.join(choice(UP_LOW)(a) for a in strng) 8 | -------------------------------------------------------------------------------- /katas/kyu_7/recursive_reverse_string.py: -------------------------------------------------------------------------------- 1 | def reverse(string): 2 | return string if len(string) == 1 else string[-1] + reverse(string[:-1]) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/reduce_my_fraction.py: -------------------------------------------------------------------------------- 1 | from fractions import Fraction 2 | 3 | 4 | def reduce(fraction): 5 | """ Shadows built-in name 'reduce' (forced by Codewars) """ 6 | f = Fraction(*fraction) 7 | return [f.numerator, f.denominator] 8 | -------------------------------------------------------------------------------- /katas/kyu_7/regex_validate_pin_code.py: -------------------------------------------------------------------------------- 1 | from re import match 2 | 3 | 4 | def validate_pin(pin): 5 | return bool(match(r'(\d{4}|\d{6})$', pin)) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/regexp_basics_is_eight_bit_number.py: -------------------------------------------------------------------------------- 1 | from re import compile, match 2 | 3 | REGEX = compile(r'(-[1-9]\d?|-1[0-1]\d|-12[0-8]|\d|[1-9]\d|1[0-1]\d|12[0-7])$') 4 | 5 | 6 | def signed_eight_bit_number(number): 7 | m = match(REGEX, number) 8 | return bool(m) and m.group(0) == number 9 | -------------------------------------------------------------------------------- /katas/kyu_7/regexp_basics_is_it_all_whitespace.py: -------------------------------------------------------------------------------- 1 | from re import compile, match 2 | 3 | REGEX = compile(r'\s*$') 4 | 5 | 6 | def whitespace(string): 7 | return bool(match(REGEX, string)) 8 | -------------------------------------------------------------------------------- /katas/kyu_7/remove_duplicates.py: -------------------------------------------------------------------------------- 1 | def unique(integers): 2 | uniq = set() 3 | result = [] 4 | for a in integers: 5 | if a not in uniq: 6 | result.append(a) 7 | uniq.add(a) 8 | return result 9 | -------------------------------------------------------------------------------- /katas/kyu_7/remove_the_minimum.py: -------------------------------------------------------------------------------- 1 | def remove_smallest(numbers): 2 | if not numbers: 3 | return [] 4 | numbers.remove(min(numbers)) 5 | return numbers 6 | -------------------------------------------------------------------------------- /katas/kyu_7/replace_all_items.py: -------------------------------------------------------------------------------- 1 | def replace_all(obj, old, new): 2 | if isinstance(obj, str): 3 | return obj.replace(old, new) 4 | return [new if a == old else a for a in obj] 5 | -------------------------------------------------------------------------------- /katas/kyu_7/return_a_sorted_list_of_objects.py: -------------------------------------------------------------------------------- 1 | def sort_list(sort_by, lst): 2 | return sorted(lst, key=lambda a: a[sort_by], reverse=True) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/return_string_of_first_characters.py: -------------------------------------------------------------------------------- 1 | def make_string(s): 2 | return ''.join(a[0] for a in s.split()) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/return_the_closest_number_multiple_of_10.py: -------------------------------------------------------------------------------- 1 | def closest_multiple_10(i): 2 | rem = i % 10 3 | return i - rem + (10 if rem >= 5 else 0) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/reverse_it.py: -------------------------------------------------------------------------------- 1 | def reverse_it(data): 2 | if isinstance(data, (int, float, str)): 3 | return type(data)(str(data)[::-1]) 4 | return data 5 | -------------------------------------------------------------------------------- /katas/kyu_7/reversed_strings.py: -------------------------------------------------------------------------------- 1 | def solution(string): 2 | return string[::-1] 3 | -------------------------------------------------------------------------------- /katas/kyu_7/rotate_for_a_max.py: -------------------------------------------------------------------------------- 1 | def max_rot(n): 2 | maximum = n 3 | s = list(str(n)) 4 | for i in xrange(len(s) - 1): 5 | s.append(s.pop(i)) 6 | current = int(''.join(s)) 7 | if current > maximum: 8 | maximum = current 9 | return maximum 10 | -------------------------------------------------------------------------------- /katas/kyu_7/rule_of_divisibility_by_7.py: -------------------------------------------------------------------------------- 1 | def seven(m): 2 | steps = 0 3 | while m > 99: 4 | q, r = divmod(m, 10) 5 | m = q - (2 * r) 6 | steps += 1 7 | return m, steps 8 | -------------------------------------------------------------------------------- /katas/kyu_7/ruplesjs_3_string_eachchar.py: -------------------------------------------------------------------------------- 1 | def each_char(s, arg): 2 | if isinstance(arg, str): 3 | return ''.join('{}{}'.format(a, arg) for a in s) 4 | return ''.join(arg(b) for b in s) 5 | -------------------------------------------------------------------------------- /katas/kyu_7/satisfying_numbers.py: -------------------------------------------------------------------------------- 1 | from fractions import gcd 2 | 3 | 4 | def smallest(n): 5 | return reduce(lambda a, b: (a * b) / gcd(a, b), xrange(1, n + 1), 1) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/scaling_squared_strings.py: -------------------------------------------------------------------------------- 1 | def scale(strng, k, n): 2 | return '\n'.join(''.join(b * k for b in a) for a in strng.split('\n') 3 | for _ in xrange(n)) if strng else '' 4 | -------------------------------------------------------------------------------- /katas/kyu_7/scoring_tests.py: -------------------------------------------------------------------------------- 1 | def score_test(tests, right, omit, wrong): 2 | points = (right, omit, -wrong) 3 | return sum(points[test] for test in tests) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/self_descriptive_numbers.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def self_descriptive(num): 5 | s = [int(a) for a in str(num)] 6 | cnt = Counter(s) 7 | return all(cnt[i] == b for i, b in enumerate(s)) 8 | -------------------------------------------------------------------------------- /katas/kyu_7/sentence_to_words.py: -------------------------------------------------------------------------------- 1 | def splitSentence(s): 2 | """ split_sentence == PEP8 (forced mixedCase by Codewars) """ 3 | return s.split() 4 | -------------------------------------------------------------------------------- /katas/kyu_7/sequence_sum.py: -------------------------------------------------------------------------------- 1 | def sum_of_n(n): 2 | last = 0 3 | is_positive = n > 0 4 | result = [0] 5 | for a in xrange(1, abs(n) + 1): 6 | last += a 7 | result.append(last if is_positive else last * -1) 8 | return result 9 | -------------------------------------------------------------------------------- /katas/kyu_7/sexy_primes.py: -------------------------------------------------------------------------------- 1 | def is_prime(n): 2 | return n > 1 and all(n % i for i in xrange(2, int(n ** 0.5) + 1)) 3 | 4 | 5 | def sexy_prime(x, y): 6 | return abs(x - y) == 6 and is_prime(x) and is_prime(y) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/share_prices.py: -------------------------------------------------------------------------------- 1 | def share_price(invested, changes): 2 | return '{:.2f}'.format( 3 | reduce(lambda a, b: a + (a * (b / 100.0)), changes, invested)) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/shorter_concat.py: -------------------------------------------------------------------------------- 1 | def shorter_reverse_longer(a, b): 2 | if len(a) >= len(b): 3 | b, a = a, b 4 | return '{0}{1}{0}'.format(a, b[::-1]) 5 | -------------------------------------------------------------------------------- /katas/kyu_7/shortest_word.py: -------------------------------------------------------------------------------- 1 | def find_short(s): 2 | return min(len(a) for a in s.split()) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/show_multiples_of_two_numbers_within_a_range.py: -------------------------------------------------------------------------------- 1 | def multiples(s1, s2, s3): 2 | return [a for a in xrange(1, s3) if not(a % s1 or a % s2)] 3 | -------------------------------------------------------------------------------- /katas/kyu_7/silly_case.py: -------------------------------------------------------------------------------- 1 | def sillycase(silly): 2 | mid = (len(silly) + 1) / 2 3 | return '{}{}'.format(silly[:mid].lower(), silly[mid:].upper()) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/simple_elevator.py: -------------------------------------------------------------------------------- 1 | def goto(level, button): 2 | if not isinstance(level, int) or not isinstance(button, str) \ 3 | or level not in xrange(4) or button not in map(str, xrange(4)): 4 | return 0 5 | return int(button) - level 6 | -------------------------------------------------------------------------------- /katas/kyu_7/simple_sequence_validator.py: -------------------------------------------------------------------------------- 1 | def validate_sequence(seq): 2 | return len({a - b for a, b in zip(seq, seq[1:])}) == 1 3 | -------------------------------------------------------------------------------- /katas/kyu_7/sir_show_me_your_id.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def show_me(name): 5 | return bool(re.match(r'(-[A-Z][a-z]+)+$', '-' + name)) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/slope_of_a_line.py: -------------------------------------------------------------------------------- 1 | def getSlope(p1, p2): 2 | """ get_slope == PEP8 (forced mixedCase by CodeWars) """ 3 | (x, y), (x2, y2) = p1, p2 4 | try: 5 | return (y - y2) / (x - x2) 6 | except ZeroDivisionError: 7 | pass 8 | -------------------------------------------------------------------------------- /katas/kyu_7/some_circles.py: -------------------------------------------------------------------------------- 1 | from math import pi 2 | 3 | OUTPUT = 'We have this much circle: {:.0f}'.format 4 | 5 | 6 | def sum_circles(*args): 7 | return OUTPUT(sum(pi * (diameter / 2.0) ** 2 for diameter in args)) 8 | -------------------------------------------------------------------------------- /katas/kyu_7/sort_by_example.py: -------------------------------------------------------------------------------- 1 | def example_sort(arr, example_arr): 2 | keys = {k: i for i, k in enumerate(example_arr)} 3 | return sorted(arr, key=lambda a: keys[a]) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/sort_numbers.py: -------------------------------------------------------------------------------- 1 | def solution(nums): 2 | return sorted(nums) if isinstance(nums, (list, tuple)) else [] 3 | -------------------------------------------------------------------------------- /katas/kyu_7/sorted_union.py: -------------------------------------------------------------------------------- 1 | def unite_unique(*args): 2 | result = [] 3 | for a in args: 4 | for b in a: 5 | if b not in result: 6 | result.append(b) 7 | return result 8 | -------------------------------------------------------------------------------- /katas/kyu_7/sorted_yes_no_how.py: -------------------------------------------------------------------------------- 1 | def is_sorted_and_how(nums): 2 | a_or_d = {'a': 'ascending', 'd': 'descending'} 3 | diffs = {'d' if b - a < 0 else 'a' for a, b in zip(nums, nums[1:])} 4 | return 'yes, {}'.format(a_or_d[diffs.pop()]) if len(diffs) == 1 else 'no' 5 | -------------------------------------------------------------------------------- /katas/kyu_7/sorting_dictionaries.py: -------------------------------------------------------------------------------- 1 | from operator import itemgetter 2 | 3 | 4 | def sort_dict(d): 5 | return sorted(d.items(), key=itemgetter(1), reverse=True) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/speed_control.py: -------------------------------------------------------------------------------- 1 | from itertools import izip 2 | 3 | 4 | def gps(s, x): 5 | return 0 if len(x) <= 1 else \ 6 | int(max(((b - a) / s) * 3600 for a, b in izip(x, x[1:]))) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/split_the_bill.py: -------------------------------------------------------------------------------- 1 | def split_the_bill(x): 2 | people = total = 0 3 | for k, v in x.iteritems(): 4 | people += 1 5 | total += v 6 | average = total / float(people) 7 | return {k: round(v - average, 2) for k, v in x.iteritems()} 8 | -------------------------------------------------------------------------------- /katas/kyu_7/spoonerize_me.py: -------------------------------------------------------------------------------- 1 | def spoonerize(words): 2 | a, b = words.split() 3 | return '{}{} {}{}'.format(b[0], a[1:], a[0], b[1:]) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/square_digits.py: -------------------------------------------------------------------------------- 1 | def square_digits(num): 2 | return int(''.join(str(int(a) ** 2) for a in str(num))) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/string_basics.py: -------------------------------------------------------------------------------- 1 | def get_users_ids(strng): 2 | return [a.replace('uid', '', 1).strip() 3 | for a in strng.lower().replace('#', '').split(',')] 4 | -------------------------------------------------------------------------------- /katas/kyu_7/string_chunks.py: -------------------------------------------------------------------------------- 1 | def string_chunk(strng, n=0): 2 | try: 3 | return [strng[a:a + n] for a in xrange(0, len(strng), n)] 4 | except (TypeError, ValueError): 5 | return [] 6 | -------------------------------------------------------------------------------- /katas/kyu_7/string_ends_with.py: -------------------------------------------------------------------------------- 1 | def solution(string, ending): 2 | return string.endswith(ending) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/string_reversing_changing_case.py: -------------------------------------------------------------------------------- 1 | def reverse_and_mirror(s1, s2): 2 | swap = s1.swapcase() 3 | return '{}@@@{}{}'.format(s2[::-1].swapcase(), swap[::-1], swap) 4 | 5 | 6 | # PEP8: function name should use snake_case 7 | reverseAndMirror = reverse_and_mirror 8 | -------------------------------------------------------------------------------- /katas/kyu_7/string_to_integer_conversion.py: -------------------------------------------------------------------------------- 1 | def my_parse_int(string): 2 | try: 3 | return int(string) 4 | except ValueError: 5 | return 'NaN' 6 | -------------------------------------------------------------------------------- /katas/kyu_7/sum_first_nth_term_of_series.py: -------------------------------------------------------------------------------- 1 | def series_sum(n): 2 | return '{:.2f}'.format(sum(1.0 / a for a in xrange(1, n * 3, 3))) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/sum_of_all_arguments.py: -------------------------------------------------------------------------------- 1 | def sum_args(*args): 2 | return sum(args) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/sum_of_numbers_from_zero_to_n.py: -------------------------------------------------------------------------------- 1 | def show_sequence(n): 2 | if n == 0: 3 | return '0=0' 4 | elif n < 0: 5 | return '{}<0'.format(n) 6 | return '{} = {}'.format( 7 | '+'.join(str(a) for a in xrange(n + 1)), n * (n + 1) // 2 8 | ) 9 | -------------------------------------------------------------------------------- /katas/kyu_7/sum_squares_of_numbers_in_list_that_may_contain_more_lists.py: -------------------------------------------------------------------------------- 1 | def SumSquares(lst): 2 | """ sum_squares == PEP8 (forced PascalCase by Codewars) """ 3 | try: 4 | return sum(SumSquares(a) for a in lst) 5 | except TypeError: 6 | return lst ** 2 7 | -------------------------------------------------------------------------------- /katas/kyu_7/sum_up_the_random_string.py: -------------------------------------------------------------------------------- 1 | from re import findall 2 | 3 | 4 | def sum_from_string(string): 5 | return sum(int(a) for a in findall(r'\d+', string)) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/summing_a_numbers_digits.py: -------------------------------------------------------------------------------- 1 | def sumDigits(number): 2 | """ sum_digits == PEP8 (camelCase forced by CodeWars) """ 3 | return sum(map(int, str(abs(number)))) 4 | -------------------------------------------------------------------------------- /katas/kyu_7/suzuki_needs_help_lining_up_his_students.py: -------------------------------------------------------------------------------- 1 | def lineup_students(names): 2 | return sorted(names.split(), key=lambda a: (len(a), a), reverse=True) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/switcheroo.py: -------------------------------------------------------------------------------- 1 | from string import maketrans, translate 2 | 3 | 4 | def switcheroo(strng): 5 | return translate(strng, maketrans('ab', 'ba')) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/the_coins_of_ter.py: -------------------------------------------------------------------------------- 1 | def adjust(coin, price): 2 | q, r = divmod(price, coin) 3 | return price if not r else (q + 1) * coin 4 | -------------------------------------------------------------------------------- /katas/kyu_7/the_ladies_of_eniac.py: -------------------------------------------------------------------------------- 1 | from string import ascii_uppercase 2 | 3 | VALID = set(ascii_uppercase + ' !') 4 | 5 | 6 | def rad_ladies(name): 7 | return ''.join(a for a in name.upper() if a in VALID) 8 | -------------------------------------------------------------------------------- /katas/kyu_7/the_office_1_outed.py: -------------------------------------------------------------------------------- 1 | def outed(meet, boss): 2 | result = (sum(meet.values()) + meet[boss]) / len(meet) 3 | return 'Nice Work Champ!' if result > 5 else 'Get Out Now!' 4 | -------------------------------------------------------------------------------- /katas/kyu_7/the_office_3_broken_photocopier.py: -------------------------------------------------------------------------------- 1 | from string import maketrans, translate 2 | 3 | 4 | def broken(inp): 5 | return translate(inp, maketrans('01', '10')) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/the_old_switcheroo.py: -------------------------------------------------------------------------------- 1 | VOWELS = {'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U'} 2 | 3 | 4 | def vowel_2_index(string): 5 | return ''.join(str(i) if a in VOWELS else a 6 | for i, a in enumerate(string, start=1)) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/the_owls_are_not_what_they_seem.py: -------------------------------------------------------------------------------- 1 | VALID = {'8', 'W', 'T', 'Y', 'U', 'I', 'O', 'A', 'H', 'X', 'V', 'M'} 2 | 3 | 4 | def owl_pic(text): 5 | string = ''.join(a for a in text.upper() if a in VALID) 6 | return '{}\'\'0v0\'\'{}'.format(string, string[::-1]) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/thinkful_string_drills_poem_formatter.py: -------------------------------------------------------------------------------- 1 | def format_poem(poem): 2 | return '.\n'.join(poem.split('. ')) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/thinking_and_testing_a_and_b.py: -------------------------------------------------------------------------------- 1 | def testit(a, b): 2 | return a | b 3 | -------------------------------------------------------------------------------- /katas/kyu_7/thinking_and_testing_something_capitalized.py: -------------------------------------------------------------------------------- 1 | def testit(s): 2 | return ' '.join(a.lower()[:-1] + a[-1].upper() for a in s.split()) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/thinking_and_testing_true_or_false.py: -------------------------------------------------------------------------------- 1 | def testit(n): 2 | return format(n, 'b').count('1') 3 | -------------------------------------------------------------------------------- /katas/kyu_7/time_converter_hh_mm_ss_ms.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | 4 | def convert(time): 5 | return '{:02}:{:02}:{:02},{:03}'.format( 6 | time.hour, time.minute, time.second, time.microsecond / 1000) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/time_degrees.py: -------------------------------------------------------------------------------- 1 | def clock_degree(clock_time): 2 | hour, minutes = (int(a) for a in clock_time.split(':')) 3 | if not (24 > hour >= 0 and 60 > minutes >= 0): 4 | return 'Check your time !' 5 | return '{}:{}'.format((hour % 12) * 30 or 360, minutes * 6 or 360) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/to_leet_speak.py: -------------------------------------------------------------------------------- 1 | LEET = {'A': '@', 'B': '8', 'C': '(', 'E': '3', 'G': '6', 'H': '#', 2 | 'I': '!', 'L': '1', 'O': '0', 'S': '$', 'T': '7', 'Z': '2'} 3 | 4 | 5 | def to_leet_speak(s): 6 | return ''.join(LEET.get(a, a) for a in s) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/transpose_two_strings_in_an_array.py: -------------------------------------------------------------------------------- 1 | from itertools import izip_longest 2 | 3 | 4 | def transpose_two_strings(arr): 5 | output = '{} {}'.format 6 | return '\n'.join(output(*a) for a in izip_longest(*arr, fillvalue=' ')) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/triangular_treasure.py: -------------------------------------------------------------------------------- 1 | def triangular(n): 2 | return n * (n + 1) / 2 if n >= 0 else 0 3 | -------------------------------------------------------------------------------- /katas/kyu_7/truncate_a_string.py: -------------------------------------------------------------------------------- 1 | def truncate_string(s, max_len): 2 | if len(s) <= max_len: 3 | return s 4 | return '{}...'.format(s[:max_len - (3 if max_len > 3 else 0)]) 5 | -------------------------------------------------------------------------------- /katas/kyu_7/two_to_one.py: -------------------------------------------------------------------------------- 1 | def longest(s1, s2): 2 | return ''.join(sorted(set(s1).union(s2))) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/unique_pairs.py: -------------------------------------------------------------------------------- 1 | def projectPartners(n): 2 | """ project_partners == PEP8 (forced mixedCase by CodeWars) """ 3 | return n * (n - 1) / 2 4 | -------------------------------------------------------------------------------- /katas/kyu_7/unlimited_sum.py: -------------------------------------------------------------------------------- 1 | def sum(*args): 2 | return reduce(lambda a, b: a + b, (c for c in args if isinstance(c, int))) 3 | 4 | 5 | # def sum(*args): 6 | # return __builtins__.sum(filter(lambda a: isinstance(a, int), args)) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/unlucky_days.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | 4 | def unlucky_days(year): 5 | return sum(datetime(year, a, 13).weekday() == 4 for a in xrange(1, 13)) 6 | -------------------------------------------------------------------------------- /katas/kyu_7/unpacking_arguments.py: -------------------------------------------------------------------------------- 1 | def spread(func, args): 2 | return func(*args) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/uvb76_message_validator.py: -------------------------------------------------------------------------------- 1 | from re import compile, match 2 | 3 | REGEX = compile(r'MDZHB \d{2} \d{3} [A-Z]+ \d{2} \d{2} \d{2} \d{2}$') 4 | 5 | 6 | def validate(message): 7 | return bool(match(REGEX, message)) 8 | -------------------------------------------------------------------------------- /katas/kyu_7/vampire_numbers.py: -------------------------------------------------------------------------------- 1 | def vampire_test(x, y): 2 | return sorted(str(x * y)) == sorted('{}{}'.format(x, y)) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/volume_of_a_cup.py: -------------------------------------------------------------------------------- 1 | from math import pi 2 | 3 | 4 | def cup_volume(top, bottom, height): 5 | r1 = top / 2.0 6 | r2 = bottom / 2.0 7 | return round((1 / 3.0 * pi) * (r1 ** 2 + r1 * r2 + r2 ** 2) * height, 2) 8 | -------------------------------------------------------------------------------- /katas/kyu_7/vowel_count.py: -------------------------------------------------------------------------------- 1 | VOWELS = 'aeiou' 2 | 3 | 4 | def getCount(string): 5 | """ get_count == PEP8 (forced mixedCase by CodeWars) """ 6 | return sum(a in VOWELS for a in string.lower()) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/what_dominates_your_array.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def dominator(arr): 5 | if not arr: 6 | return -1 7 | k, v = Counter(arr).most_common(1)[0] 8 | return k if v > len(arr) / 2 else -1 9 | -------------------------------------------------------------------------------- /katas/kyu_7/where_is_vasya.py: -------------------------------------------------------------------------------- 1 | def where_is_he(p, bef, aft): 2 | return min(p - bef, aft + 1) 3 | -------------------------------------------------------------------------------- /katas/kyu_7/x_to_y_of_z.py: -------------------------------------------------------------------------------- 1 | OUTPUT = 'Showing {} to {} of {} Products.'.format 2 | 3 | 4 | def pagination_text(page_num, page_size, total): 5 | to_y = page_num * page_size 6 | return OUTPUT(to_y - page_size + 1, to_y if to_y < total else total, total) 7 | -------------------------------------------------------------------------------- /katas/kyu_7/xmas_tree.py: -------------------------------------------------------------------------------- 1 | from itertools import chain 2 | 3 | 4 | def xMasTree(n): 5 | width = n * 2 - 1 6 | row = '{{:_^{}}}'.format(width).format 7 | return [row(a * '#') for a in chain(xrange(1, width + 1, 2), (1, 1))] 8 | -------------------------------------------------------------------------------- /katas/kyu_7/you_are_a_square.py: -------------------------------------------------------------------------------- 1 | # def is_square(n): 2 | # if n < 1: 3 | # return False 4 | # sqrt = n ** 0.5 5 | # return sqrt == int(sqrt) 6 | 7 | 8 | def is_square(n): 9 | return n > 0 and (n ** 0.5).is_integer() 10 | -------------------------------------------------------------------------------- /katas/kyu_7/zebulans_nightmare.py: -------------------------------------------------------------------------------- 1 | def zebulansNightmare(strng): 2 | """ zebulans_nightmare == PEP8 (forced mixedCase by CodeWars) """ 3 | words = strng.split('_') 4 | return '{}{}'.format(words[0], ''.join(a.capitalize() for a in words[1:])) 5 | -------------------------------------------------------------------------------- /katas/kyu_7/zip_it.py: -------------------------------------------------------------------------------- 1 | def lstzip(a, b, fn): 2 | return [fn(*c) for c in zip(a, b)] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/katas/kyu_8/__init__.py -------------------------------------------------------------------------------- /katas/kyu_8/a_needle_in_the_haystack.py: -------------------------------------------------------------------------------- 1 | def find_needle(haystack): 2 | return 'found the needle at position {}'.format(haystack.index('needle')) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/adam_and_eve.py: -------------------------------------------------------------------------------- 1 | class Human: 2 | pass 3 | 4 | 5 | class Man(Human): 6 | pass 7 | 8 | 9 | class Woman(Human): 10 | pass 11 | 12 | 13 | def God(): 14 | """ god == PEP8 (forced to capitalize by CodeWars) """ 15 | return [Man(), Woman()] 16 | -------------------------------------------------------------------------------- /katas/kyu_8/add_length.py: -------------------------------------------------------------------------------- 1 | def add_length(str_): 2 | return ['{} {}'.format(a, len(a)) for a in str_.split()] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/add_more_item_to_list.py: -------------------------------------------------------------------------------- 1 | class AddOne(object): 2 | def __init__(self, n): 3 | self.n = n 4 | 5 | def __len__(self): 6 | return self.n + 1 7 | 8 | 9 | def AddExtra(listOfNumbers): 10 | return AddOne(len(listOfNumbers)) 11 | -------------------------------------------------------------------------------- /katas/kyu_8/addition.py: -------------------------------------------------------------------------------- 1 | def on_square(square): 2 | return pow(2, square - 1) 3 | 4 | 5 | def total_after(square): 6 | return sum(pow(2, x) for x in xrange(square)) 7 | -------------------------------------------------------------------------------- /katas/kyu_8/alternating_case.py: -------------------------------------------------------------------------------- 1 | from string import swapcase as to_alternating_case 2 | -------------------------------------------------------------------------------- /katas/kyu_8/are_there_any_arrows_left.py: -------------------------------------------------------------------------------- 1 | def any_arrows(arrows): 2 | return any(not arrow.get('damaged', False) for arrow in arrows) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/are_they_opposite.py: -------------------------------------------------------------------------------- 1 | def is_opposite(s1, s2): 2 | return False if not(s1 or s2) else s1.swapcase() == s2 3 | -------------------------------------------------------------------------------- /katas/kyu_8/barking_mad.py: -------------------------------------------------------------------------------- 1 | class Dog: 2 | def __init__(self, breed): 3 | self.breed = breed 4 | 5 | @staticmethod 6 | def bark(): 7 | return 'Woof' 8 | -------------------------------------------------------------------------------- /katas/kyu_8/basic_mathematical_operations.py: -------------------------------------------------------------------------------- 1 | from operator import add, div, mul, sub 2 | 3 | 4 | def basic_op(op, a, b): 5 | return {'+': add, '/': div, '*': mul, '-': sub}[op](a, b) 6 | -------------------------------------------------------------------------------- /katas/kyu_8/beginner_lost_without_a_map.py: -------------------------------------------------------------------------------- 1 | def maps(arr): 2 | return [a * 2 for a in arr] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/boolean_to_word.py: -------------------------------------------------------------------------------- 1 | def bool_to_word(bool): 2 | return 'YES' if bool else 'NO' 3 | -------------------------------------------------------------------------------- /katas/kyu_8/broken_greetings.py: -------------------------------------------------------------------------------- 1 | class Person: 2 | def __init__(self, name): 3 | self.name = name 4 | 5 | def greet(self, other_name): 6 | return "Hi {}, my name is {}".format(other_name, self.name) 7 | -------------------------------------------------------------------------------- /katas/kyu_8/bug_fixing_6.py: -------------------------------------------------------------------------------- 1 | def eval_object(v): 2 | return {'+': v['a'] + v['b'], '-': v['a'] - v['b'], 3 | '/': v['a'] / v['b'], '*': v['a'] * v['b'], 4 | '%': v['a'] % v['b'], '**': v['a'] ** v['b']}.\ 5 | get(v['operation'], 1) 6 | -------------------------------------------------------------------------------- /katas/kyu_8/bug_fixing_string_templates.py: -------------------------------------------------------------------------------- 1 | def build_string(*args): 2 | return "I like {}!".format(", ".join(args)) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/character_frequency.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def char_freq(message): 5 | return Counter(message) 6 | -------------------------------------------------------------------------------- /katas/kyu_8/classic_hello_world.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | @staticmethod 3 | def main(*args): 4 | print 'Hello World!' 5 | -------------------------------------------------------------------------------- /katas/kyu_8/collatz_conjecture.py: -------------------------------------------------------------------------------- 1 | def hotpo(n): 2 | cnt = 0 3 | while n != 1: 4 | n = 3 * n + 1 if n % 2 else n / 2 5 | cnt += 1 6 | return cnt 7 | -------------------------------------------------------------------------------- /katas/kyu_8/color_ghost.py: -------------------------------------------------------------------------------- 1 | from random import choice 2 | 3 | COLORS = ('white', 'yellow', 'purple', 'red') 4 | 5 | 6 | class Ghost(object): 7 | def __init__(self): 8 | self.color = choice(COLORS) 9 | -------------------------------------------------------------------------------- /katas/kyu_8/convert_a_string_to_an_array.py: -------------------------------------------------------------------------------- 1 | def string_to_array(strng): 2 | return strng.split() or [''] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/convert_boolean_to_a_string.py: -------------------------------------------------------------------------------- 1 | def boolean_to_string(b): 2 | return ('False', 'True')[b] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/convert_natural_num_to_binary.py: -------------------------------------------------------------------------------- 1 | def int_to_bin(n): 2 | return format(n, 'b') 3 | -------------------------------------------------------------------------------- /katas/kyu_8/correct_the_mistakes_of_the_character_recognition_software.py: -------------------------------------------------------------------------------- 1 | from string import maketrans, translate 2 | 3 | 4 | def correct(s): 5 | return translate(s, maketrans('501', 'SOI')) 6 | -------------------------------------------------------------------------------- /katas/kyu_8/count_by_x.py: -------------------------------------------------------------------------------- 1 | def count_by(x, n): 2 | """ Return a sequence of numbers counting by `x` `n` times. """ 3 | return range(x, x * n + 1, x) 4 | -------------------------------------------------------------------------------- /katas/kyu_8/count_of_positives_sum_of_negatives.py: -------------------------------------------------------------------------------- 1 | def count_positives_sum_negatives(arr): 2 | neg = pos = 0 3 | for a in arr: 4 | if a > 0: 5 | pos += 1 6 | else: 7 | neg += a 8 | return [pos, neg] 9 | -------------------------------------------------------------------------------- /katas/kyu_8/count_the_monkeys.py: -------------------------------------------------------------------------------- 1 | def monkey_count(n): 2 | return range(1, n + 1) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/counting_sheep.py: -------------------------------------------------------------------------------- 1 | # def count_sheeps(sheeps): 2 | # return sum(sheep for sheep in sheeps if sheep is not None) 3 | 4 | 5 | def count_sheeps(sheeps): 6 | return sheeps.count(True) 7 | -------------------------------------------------------------------------------- /katas/kyu_8/did_she_say_hello.py: -------------------------------------------------------------------------------- 1 | from re import compile, search, I 2 | 3 | REGEX = compile(r'hello|ciao|salut|hallo|hola|ahoj|czesc', I) 4 | 5 | 6 | def validate_hello(greeting): 7 | return bool(search(REGEX, greeting)) 8 | -------------------------------------------------------------------------------- /katas/kyu_8/digitize.py: -------------------------------------------------------------------------------- 1 | def digitize(n): 2 | return map(int, str(n)[::-1]) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/dna_to_rna.py: -------------------------------------------------------------------------------- 1 | def DNAtoRNA(dna): 2 | """ dna_to_rna == PEP8 (forced camelCase by CodeWars) """ 3 | return dna.replace('T', 'U') 4 | -------------------------------------------------------------------------------- /katas/kyu_8/do_i_get_a_bonus.py: -------------------------------------------------------------------------------- 1 | def bonus_time(salary, bonus): 2 | return '${}'.format(salary * (10 if bonus else 1)) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/double_integer.py: -------------------------------------------------------------------------------- 1 | def doubleInteger(i): 2 | """ double_integer == PEP8 (forced mixedcase by CodeWars) """ 3 | return i * 2 4 | -------------------------------------------------------------------------------- /katas/kyu_8/drink_about.py: -------------------------------------------------------------------------------- 1 | def people_with_age_drink(age): 2 | if age < 14: 3 | return 'drink toddy' 4 | elif age < 18: 5 | return 'drink coke' 6 | elif age < 21: 7 | return 'drink beer' 8 | return 'drink whisky' 9 | -------------------------------------------------------------------------------- /katas/kyu_8/duck_duck_goose.py: -------------------------------------------------------------------------------- 1 | def duck_duck_goose(players, goose): 2 | return players[goose % len(players) - 1].name 3 | -------------------------------------------------------------------------------- /katas/kyu_8/even_or_odd.py: -------------------------------------------------------------------------------- 1 | def even_or_odd(number): 2 | return ('Even', 'Odd')[number % 2] 3 | # return 'Even' if number % 2 == 0 else 'Odd' 4 | -------------------------------------------------------------------------------- /katas/kyu_8/evil_or_odious.py: -------------------------------------------------------------------------------- 1 | def evil(n): 2 | return 'It\'s {}!'.format(('Evil', 'Odious')[bin(n).count('1') % 2]) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/fake_binary.py: -------------------------------------------------------------------------------- 1 | def fake_bin(x): 2 | return ''.join('0' if int(a) < 5 else '1' for a in x) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/find_nth_digit_of_a_number.py: -------------------------------------------------------------------------------- 1 | def find_digit(num, nth): 2 | if nth <= 0: 3 | return -1 4 | try: 5 | return int(str(num).lstrip('-')[-nth]) 6 | except IndexError: 7 | return 0 8 | -------------------------------------------------------------------------------- /katas/kyu_8/find_the_position.py: -------------------------------------------------------------------------------- 1 | from string import ascii_lowercase 2 | 3 | 4 | def position(char): 5 | return 'Position of alphabet: {}'.format(ascii_lowercase.index(char) + 1) 6 | -------------------------------------------------------------------------------- /katas/kyu_8/find_the_slope.py: -------------------------------------------------------------------------------- 1 | def find_slope(points): 2 | x, y, x2, y2 = points 3 | try: 4 | return str((y2 - y) / (x2 - x)) 5 | except ZeroDivisionError: 6 | return 'undefined' 7 | -------------------------------------------------------------------------------- /katas/kyu_8/fix_the_bugs_my_first_kata.py: -------------------------------------------------------------------------------- 1 | def my_first_kata(a, b): 2 | try: 3 | if not (isinstance(a, bool) or isinstance(b, bool)): 4 | return a % b + b % a 5 | except (TypeError, ZeroDivisionError): 6 | pass 7 | return False 8 | -------------------------------------------------------------------------------- /katas/kyu_8/fix_your_code_before_the_garden_dies.py: -------------------------------------------------------------------------------- 1 | def rain_amount(mm): 2 | if mm < 40: 3 | return 'You need to give your plant {}mm of water'.format(40 - mm) 4 | return 'Your plant has had more than enough water for today!' 5 | -------------------------------------------------------------------------------- /katas/kyu_8/format_money.py: -------------------------------------------------------------------------------- 1 | def format_money(amount): 2 | return '${:.2f}'.format(amount) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/formatting_decimal_places_0.py: -------------------------------------------------------------------------------- 1 | def two_decimal_places(n): 2 | return round(n, 2) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/freudian_translator.py: -------------------------------------------------------------------------------- 1 | def to_freud(sentence): 2 | return ' '.join('sex' for _ in sentence.split()) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/function_within_function.py: -------------------------------------------------------------------------------- 1 | # def always(n=0): 2 | # def closure(): 3 | # return n 4 | # return closure 5 | 6 | 7 | def always(n=0): 8 | return lambda: n 9 | -------------------------------------------------------------------------------- /katas/kyu_8/generate_user_links.py: -------------------------------------------------------------------------------- 1 | from urllib import quote 2 | 3 | CODEWARS = 'http://www.codewars.com/users/{}'.format 4 | 5 | 6 | def generate_link(user): 7 | return CODEWARS(quote(user)) 8 | -------------------------------------------------------------------------------- /katas/kyu_8/get_planet_name_by_id.py: -------------------------------------------------------------------------------- 1 | PLANETS = ('Mercury', 'Venus', 'Earth', 'Mars', 2 | 'Jupiter', 'Saturn', 'Uranus', 'Neptune') 3 | 4 | 5 | def get_planet_name(planet_id): 6 | return PLANETS[planet_id - 1] 7 | -------------------------------------------------------------------------------- /katas/kyu_8/get_the_mean_of_array.py: -------------------------------------------------------------------------------- 1 | def get_average(marks): 2 | num_marks = marks_sum = 0 3 | for mark in marks: 4 | num_marks += 1 5 | marks_sum += mark 6 | return marks_sum / num_marks 7 | -------------------------------------------------------------------------------- /katas/kyu_8/get_the_middle_character.py: -------------------------------------------------------------------------------- 1 | def get_middle(s): 2 | q, r = divmod(len(s), 2) 3 | return s[q - (1 if not r else 0):q + 1] 4 | -------------------------------------------------------------------------------- /katas/kyu_8/grader.py: -------------------------------------------------------------------------------- 1 | GRADE = ((0.9, 'A'), (0.8, 'B'), (0.7, 'C'), (0.6, 'D')) 2 | 3 | 4 | def grader(score): 5 | return next(v for k, v in GRADE if score >= k)\ 6 | if 1 >= score >= 0.6 else 'F' 7 | -------------------------------------------------------------------------------- /katas/kyu_8/grasshopper_bug_squashing.py: -------------------------------------------------------------------------------- 1 | def main(): pass 2 | health, position, coins = 100, 0, 0 3 | log = 'roll_dice move combat get_coins buy_health print_status'.split() 4 | -------------------------------------------------------------------------------- /katas/kyu_8/grasshopper_combine_strings.py: -------------------------------------------------------------------------------- 1 | def combine_names(*args): 2 | return ' '.join(args) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/grasshopper_debug.py: -------------------------------------------------------------------------------- 1 | def weather_info(temp): 2 | celsius = (temp - 32) * (5 / 9.0) 3 | if celsius > 0: 4 | return '{} is above freezing temperature'.format(celsius) 5 | return '{} is freezing temperature'.format(celsius) 6 | -------------------------------------------------------------------------------- /katas/kyu_8/grasshopper_if_else_syntax_debug.py: -------------------------------------------------------------------------------- 1 | def checkAlive(health): 2 | """ check_alive == PEP8 (forced by Codewars) """ 3 | return health > 0 4 | -------------------------------------------------------------------------------- /katas/kyu_8/grasshopper_make_change.py: -------------------------------------------------------------------------------- 1 | candy, change, chips, money, soda = 1.42, 5.18, 2.4, 10, 1 2 | -------------------------------------------------------------------------------- /katas/kyu_8/grasshopper_messi_goals.py: -------------------------------------------------------------------------------- 1 | la_liga_goals = 43 2 | champions_league_goals = 10 3 | copa_del_rey_goals = 5 4 | total_goals = la_liga_goals + champions_league_goals + copa_del_rey_goals 5 | -------------------------------------------------------------------------------- /katas/kyu_8/grasshopper_shopping_list.py: -------------------------------------------------------------------------------- 1 | frenchFries, salads, sandwiches, wraps, totalPrice = 10, 6, 4, 5, 118.5 2 | -------------------------------------------------------------------------------- /katas/kyu_8/grasshopper_summation.py: -------------------------------------------------------------------------------- 1 | def summation(num): 2 | return sum(xrange(1, num + 1)) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/grasshopper_terminal_game_1.py: -------------------------------------------------------------------------------- 1 | class Hero(object): 2 | def __init__(self, name='Hero'): 3 | self.damage = 5 4 | self.experience = 0 5 | self.health = 100 6 | self.name = name 7 | self.position = '00' 8 | -------------------------------------------------------------------------------- /katas/kyu_8/grasshopper_terminal_game_turn_function.py: -------------------------------------------------------------------------------- 1 | def do_turn(): 2 | [_() for _ in roll_dice, move, combat, get_coins, buy_health, print_status] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/grasshopper_variable_assignment_debug.py: -------------------------------------------------------------------------------- 1 | a = "dev" 2 | b = "Lab" 3 | name = a + b 4 | -------------------------------------------------------------------------------- /katas/kyu_8/hex_to_decimal.py: -------------------------------------------------------------------------------- 1 | def hex_to_dec(s): 2 | return int(s, 16) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/how_do_i_compare_numbers.py: -------------------------------------------------------------------------------- 1 | def what_is(x): 2 | if x == 42: 3 | return 'everything' 4 | elif x == 42 * 42: 5 | return 'everything squared' 6 | return 'nothing' 7 | -------------------------------------------------------------------------------- /katas/kyu_8/how_good_are_you_really.py: -------------------------------------------------------------------------------- 1 | def better_than_average(class_points, your_points): 2 | total_students = total_points = 0.0 3 | for a in class_points: 4 | total_points += a 5 | total_students += 1 6 | return your_points > total_points / total_students 7 | -------------------------------------------------------------------------------- /katas/kyu_8/is_it_a_number.py: -------------------------------------------------------------------------------- 1 | def isDigit(strng): 2 | """ is_digit == PEP8 (forced mixedCase by Codewars) """ 3 | try: 4 | float(strng) 5 | return True 6 | except ValueError: 7 | return False 8 | -------------------------------------------------------------------------------- /katas/kyu_8/is_the_string_uppercase.py: -------------------------------------------------------------------------------- 1 | is_uppercase = str.isupper 2 | -------------------------------------------------------------------------------- /katas/kyu_8/is_there_a_vowel_in_there.py: -------------------------------------------------------------------------------- 1 | def is_vow(s): 2 | vowels = {97: 'a', 111: 'o', 117: 'u', 101: 'e', 105: 'i'} 3 | return [vowels.get(a, a) for a in s] 4 | -------------------------------------------------------------------------------- /katas/kyu_8/is_this_my_tail.py: -------------------------------------------------------------------------------- 1 | def correct_tail(body, tail): 2 | return body.endswith(tail) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/is_your_period_late.py: -------------------------------------------------------------------------------- 1 | def period_is_late(last, today, cycle_length): 2 | return (today - last).days > cycle_length 3 | -------------------------------------------------------------------------------- /katas/kyu_8/jennys_secret_msg.py: -------------------------------------------------------------------------------- 1 | def greet(name): 2 | return "Hello, {}!".format('my love' if name == 'Johnny' else name) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/kata_example_twist.py: -------------------------------------------------------------------------------- 1 | websites = ['codewars'] * 1000 2 | -------------------------------------------------------------------------------- /katas/kyu_8/keep_hydrated.py: -------------------------------------------------------------------------------- 1 | def litres(total_time): 2 | return total_time // 2 3 | -------------------------------------------------------------------------------- /katas/kyu_8/lario_and_muigi_pipe_problem.py: -------------------------------------------------------------------------------- 1 | def pipe_fix(nums): 2 | return range(nums[0], nums[-1] + 1) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/last.py: -------------------------------------------------------------------------------- 1 | import __builtin__ 2 | 3 | 4 | def last(*args): 5 | end = args[-1] 6 | return end[-1] if isinstance(end, (__builtin__.str, list, tuple)) else end 7 | -------------------------------------------------------------------------------- /katas/kyu_8/lightsabers.py: -------------------------------------------------------------------------------- 1 | def howManyLightsabersDoYouOwn(name='Luke'): 2 | """ how_many_lightsabers_do_you_own == PEP8 3 | (forced mixedCase by CodeWars) """ 4 | return 18 if name == 'Zach' else 0 5 | -------------------------------------------------------------------------------- /katas/kyu_8/localize_the_barycenter.py: -------------------------------------------------------------------------------- 1 | def bar_triang(*args): 2 | return map(lambda a: round(sum(a) / 3.0, 4), zip(*args)) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/mpg_to_kml.py: -------------------------------------------------------------------------------- 1 | LITRES_PER_GALLON = 4.54609188 2 | KILOMETERS_PER_MILE = 1.609344 3 | 4 | 5 | def converter(mpg): 6 | return round(mpg * KILOMETERS_PER_MILE / LITRES_PER_GALLON, 2) 7 | -------------------------------------------------------------------------------- /katas/kyu_8/multiply.py: -------------------------------------------------------------------------------- 1 | def multiply(a, b): 2 | return a * b 3 | -------------------------------------------------------------------------------- /katas/kyu_8/multiply_the_number.py: -------------------------------------------------------------------------------- 1 | def multiply(n): 2 | return n * (5 ** len(str(abs(n)))) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/my_head_is_at_the_wrong_end.py: -------------------------------------------------------------------------------- 1 | def fix_the_meerkat(arr): 2 | return arr[::-1] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/name_on_billboard.py: -------------------------------------------------------------------------------- 1 | def billboard(name, price=30): 2 | return sum(price for _ in name) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/name_shuffler.py: -------------------------------------------------------------------------------- 1 | def name_shuffler(name): 2 | return '{1} {0}'.format(*name.split()) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/name_your_python.py: -------------------------------------------------------------------------------- 1 | class Python: 2 | def __init__(self, name): 3 | self.name = name 4 | -------------------------------------------------------------------------------- /katas/kyu_8/no_zeros_for_heros.py: -------------------------------------------------------------------------------- 1 | def no_boring_zeros(n): 2 | try: 3 | return int(str(n).rstrip('0')) 4 | except ValueError: 5 | return 0 6 | -------------------------------------------------------------------------------- /katas/kyu_8/noob_code_1_supersize_me.py: -------------------------------------------------------------------------------- 1 | def super_size(n): 2 | return int(''.join(sorted(str(n), reverse=True))) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/number_of_people_in_the_bus.py: -------------------------------------------------------------------------------- 1 | def number(bus_stops): 2 | return sum(on - off for on, off in bus_stops) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/number_to_string.py: -------------------------------------------------------------------------------- 1 | number_to_string = str 2 | -------------------------------------------------------------------------------- /katas/kyu_8/object_oriented_piracy.py: -------------------------------------------------------------------------------- 1 | class Ship: 2 | def __init__(self, draft, crew): 3 | self.draft = draft 4 | self.crew = crew 5 | 6 | def is_worth_it(self): 7 | return self.draft - self.crew * 1.5 > 20 8 | -------------------------------------------------------------------------------- /katas/kyu_8/one_hundred_and_one_dalmatians.py: -------------------------------------------------------------------------------- 1 | DOGS = ((100, '101 DALMATIONS!!!'), (50, 'Woah that\'s a lot of dogs!'), 2 | (10, 'More than a handful!')) 3 | 4 | 5 | def how_many_dalmatians(n): 6 | return next((msg for dogs, msg in DOGS if n > dogs), 'Hardly any') 7 | -------------------------------------------------------------------------------- /katas/kyu_8/ones_and_zeros.py: -------------------------------------------------------------------------------- 1 | def binary_array_to_number(arr): 2 | return int(''.join(str(a) for a in arr), 2) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/opposite_number.py: -------------------------------------------------------------------------------- 1 | def opposite(number): 2 | return -1 * number 3 | -------------------------------------------------------------------------------- /katas/kyu_8/opposites_attract.py: -------------------------------------------------------------------------------- 1 | def lovefunc(flower, flower2): 2 | return (flower + flower2) % 2 != 0 3 | -------------------------------------------------------------------------------- /katas/kyu_8/playing_banjo.py: -------------------------------------------------------------------------------- 1 | PLAY = 'plays' 2 | NOPE = 'does not play' 3 | 4 | 5 | def areYouPlayingBanjo(name): 6 | """ are_you_playing_banjo == PEP8 (forced mixedCase by CodeWars) """ 7 | return '{} {} banjo'.format(name, PLAY if name[0].lower() == 'r' else NOPE) 8 | -------------------------------------------------------------------------------- /katas/kyu_8/plural.py: -------------------------------------------------------------------------------- 1 | def plural(n): 2 | return n != 1 3 | -------------------------------------------------------------------------------- /katas/kyu_8/pole_vault_starting_marks.py: -------------------------------------------------------------------------------- 1 | def starting_mark(height): 2 | return round((height - 1.22) * 3.934 + 8.27, 2) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/powers_of_2.py: -------------------------------------------------------------------------------- 1 | def powers_of_two(n): 2 | return [2 ** a for a in xrange(n + 1)] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/price_of_mangoes.py: -------------------------------------------------------------------------------- 1 | def mango(quantity, price): 2 | return (quantity - quantity // 3) * price 3 | -------------------------------------------------------------------------------- /katas/kyu_8/printing_array_elements_with_comma_delimiters.py: -------------------------------------------------------------------------------- 1 | def print_array(arr): 2 | return ','.join(str(a) for a in arr) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/regex_count_lowercase_letters.py: -------------------------------------------------------------------------------- 1 | def lowercase_count(strng): 2 | return sum(a.islower() for a in strng) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/regexp_basics_is_it_a_digit.py: -------------------------------------------------------------------------------- 1 | from re import compile, match 2 | 3 | REGEX = compile(r'\d$') 4 | 5 | 6 | def is_digit(n): 7 | m = match(REGEX, n) 8 | return bool(m) and n[slice(*m.span())] == n 9 | -------------------------------------------------------------------------------- /katas/kyu_8/regular_ball_super_ball.py: -------------------------------------------------------------------------------- 1 | class Ball: 2 | def __init__(self, ball_type='regular'): 3 | self.ball_type = ball_type 4 | -------------------------------------------------------------------------------- /katas/kyu_8/remove_exclamation_marks.py: -------------------------------------------------------------------------------- 1 | def remove_exclamation_marks(s): 2 | return s.replace('!', '') 3 | -------------------------------------------------------------------------------- /katas/kyu_8/remove_first_and_last_char_part_two.py: -------------------------------------------------------------------------------- 1 | def array(strng): 2 | return ' '.join(strng.split(',')[1:-1]) or None 3 | -------------------------------------------------------------------------------- /katas/kyu_8/remove_the_time.py: -------------------------------------------------------------------------------- 1 | def shorten_to_date(long_date): 2 | return long_date.split(',')[0] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/removing_elements.py: -------------------------------------------------------------------------------- 1 | def remove_every_other(my_list): 2 | return my_list[::2] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/repeat_it.py: -------------------------------------------------------------------------------- 1 | def repeat_it(string, n): 2 | return string * n if isinstance(string, str) else 'Not a string' 3 | -------------------------------------------------------------------------------- /katas/kyu_8/return_negative.py: -------------------------------------------------------------------------------- 1 | # def make_negative(number): 2 | # return number if number <= 0 else number * -1 3 | 4 | 5 | def make_negative(number): 6 | return -abs(number) 7 | -------------------------------------------------------------------------------- /katas/kyu_8/return_to_sanity.py: -------------------------------------------------------------------------------- 1 | def mystery(): 2 | return {'sanity': 'Hello'} 3 | -------------------------------------------------------------------------------- /katas/kyu_8/return_two_highest_values_in_list.py: -------------------------------------------------------------------------------- 1 | def two_highest(nums): 2 | if not nums: 3 | return [] 4 | elif isinstance(nums, str): 5 | return False 6 | return sorted(set(nums), reverse=True)[:2] 7 | -------------------------------------------------------------------------------- /katas/kyu_8/reverse_list_order.py: -------------------------------------------------------------------------------- 1 | def reverse_list(lst): 2 | return lst[::-1] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/rock_paper_scissors.py: -------------------------------------------------------------------------------- 1 | P1_WINS = {'scissorspaper', 'paperrock', 'rockscissors'} 2 | 3 | 4 | def rps(p1, p2): 5 | if p1 == p2: 6 | return 'Draw!' 7 | return 'Player {} won!'.format(1 if p1 + p2 in P1_WINS else 2) 8 | -------------------------------------------------------------------------------- /katas/kyu_8/sentence_smash.py: -------------------------------------------------------------------------------- 1 | # def smash(words): 2 | # return ' '.join(words) 3 | 4 | # smash = lambda words: ' '.join(words) 5 | 6 | smash = ' '.join 7 | -------------------------------------------------------------------------------- /katas/kyu_8/sleigh_authentication.py: -------------------------------------------------------------------------------- 1 | class Sleigh: 2 | @staticmethod 3 | def authenticate(name, password): 4 | return name == 'Santa Claus' and password == 'Ho Ho Ho!' 5 | -------------------------------------------------------------------------------- /katas/kyu_8/smallest_unused_id.py: -------------------------------------------------------------------------------- 1 | def next_id(arr): 2 | return min(set(xrange(max(arr) + 2)).difference(arr)) if arr else 0 3 | -------------------------------------------------------------------------------- /katas/kyu_8/square.py: -------------------------------------------------------------------------------- 1 | def square(n): 2 | return n ** 2 3 | -------------------------------------------------------------------------------- /katas/kyu_8/squash_the_bugs.py: -------------------------------------------------------------------------------- 1 | def find_longest(strng): 2 | return max(len(a) for a in strng.split()) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/string_to_number.py: -------------------------------------------------------------------------------- 1 | def string_to_number(s): 2 | return int(s) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/stringy_strings.py: -------------------------------------------------------------------------------- 1 | ONE_ZERO = '10' 2 | 3 | 4 | def stringy(size): 5 | return ''.join(ONE_ZERO[a % 2] for a in xrange(size)) 6 | # return "10" * (size / 2) + "1" * (size % 2) 7 | -------------------------------------------------------------------------------- /katas/kyu_8/strive_matching_1.py: -------------------------------------------------------------------------------- 1 | def match(candidate, job): 2 | return candidate['min_salary'] * 0.9 <= job['max_salary'] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/sum_arrays.py: -------------------------------------------------------------------------------- 1 | sum_array = sum 2 | -------------------------------------------------------------------------------- /katas/kyu_8/sum_mixed_array.py: -------------------------------------------------------------------------------- 1 | def sum_mix(arr): 2 | result = 0 3 | for a in arr: 4 | try: 5 | result += a 6 | except TypeError: 7 | result += int(a) 8 | return result 9 | -------------------------------------------------------------------------------- /katas/kyu_8/sum_without_highest_and_lowest_number.py: -------------------------------------------------------------------------------- 1 | def sum_array(arr): 2 | return sum(sorted(arr)[1:-1]) if arr else 0 3 | -------------------------------------------------------------------------------- /katas/kyu_8/surface_area_and_volume_of_a_box.py: -------------------------------------------------------------------------------- 1 | def get_size(w, h, d): 2 | return [2 * (w * h) + 2 * (w * d) + 2 * (h * d), w * h * d] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/switch_it_up.py: -------------------------------------------------------------------------------- 1 | def switch_it_up(number): 2 | nums = {0: 'Zero', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 3 | 6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine'} 4 | return nums.get(number) 5 | -------------------------------------------------------------------------------- /katas/kyu_8/the_if_function.py: -------------------------------------------------------------------------------- 1 | def _if(bool, func, func2): 2 | func() if bool else func2() 3 | 4 | 5 | def truthy(): 6 | print('True') 7 | 8 | 9 | def falsey(): 10 | print('False') 11 | 12 | _if(True, truthy, falsey) # prints 'True' to the console 13 | -------------------------------------------------------------------------------- /katas/kyu_8/the_wide_mouthed_frog.py: -------------------------------------------------------------------------------- 1 | def mouth_size(animal): 2 | return 'small' if animal.lower() == 'alligator' else 'wide' 3 | -------------------------------------------------------------------------------- /katas/kyu_8/training_js_7_if_else_ternary.py: -------------------------------------------------------------------------------- 1 | def sale_hotdogs(n): 2 | return n * (100 if n < 5 else 95 if n < 10 else 90) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/transportation_on_vacation.py: -------------------------------------------------------------------------------- 1 | def rental_car_cost(d): 2 | return 40 * d - ((50, 20)[d < 7], 0)[d < 3] 3 | -------------------------------------------------------------------------------- /katas/kyu_8/triple_trouble.py: -------------------------------------------------------------------------------- 1 | def triple_trouble(one, two, three): 2 | return ''.join(''.join(a) for a in zip(one, two, three)) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/two_plus_two_times_two.py: -------------------------------------------------------------------------------- 1 | def calculate(): 2 | return (2 + 2) * 2 3 | -------------------------------------------------------------------------------- /katas/kyu_8/unexpected_parsing.py: -------------------------------------------------------------------------------- 1 | def get_status(is_busy): 2 | return {"status": ("available", "busy")[is_busy]} 3 | # return {"status": "busy" if is_busy else "available"} 4 | -------------------------------------------------------------------------------- /katas/kyu_8/unicode_total.py: -------------------------------------------------------------------------------- 1 | def uni_total(strng): 2 | return sum(ord(a) for a in strng) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/validate_code_with_simple_regex.py: -------------------------------------------------------------------------------- 1 | def validate_code(code): 2 | return str(code).startswith(('1', '2', '3')) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/volume_of_a_cuboid.py: -------------------------------------------------------------------------------- 1 | def get_volume_of_cuboid(length, width, height): 2 | return length * width * height 3 | 4 | 5 | # PEP8: kata function name should use snake_case not mixedCase 6 | getVolumeOfCubiod = get_volume_of_cuboid 7 | -------------------------------------------------------------------------------- /katas/kyu_8/vowel_remover.py: -------------------------------------------------------------------------------- 1 | LOWER_VOWELS = 'aeiou' 2 | 3 | 4 | # def shortcut(string): 5 | # return filter(lambda a: a not in LOWER_VOWELS, string) 6 | 7 | 8 | def shortcut(string): 9 | return string.translate(None, LOWER_VOWELS) 10 | -------------------------------------------------------------------------------- /katas/kyu_8/watermelon.py: -------------------------------------------------------------------------------- 1 | def divide(weight): 2 | return weight % 2 == 0 and weight > 2 3 | -------------------------------------------------------------------------------- /katas/kyu_8/welcome_to_the_city.py: -------------------------------------------------------------------------------- 1 | def say_hello(name, city, state): 2 | return 'Hello, {}! Welcome to {}, {}!'.format(' '.join(name), city, state) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/well_of_ideas_easy_version.py: -------------------------------------------------------------------------------- 1 | def well(ideas): 2 | good_ideas = ideas.count('good') 3 | if good_ideas == 0: 4 | return 'Fail!' 5 | elif good_ideas < 3: 6 | return 'Publish!' 7 | return 'I smell a series!' 8 | -------------------------------------------------------------------------------- /katas/kyu_8/what_is_between.py: -------------------------------------------------------------------------------- 1 | def between(a, b): 2 | return range(a, b + 1) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/whats_the_real_floor.py: -------------------------------------------------------------------------------- 1 | def get_real_floor(n): 2 | return n - (1 if n < 13 else 2) if n > 0 else n 3 | -------------------------------------------------------------------------------- /katas/kyu_8/whats_wrong_with_these_identifiers.py: -------------------------------------------------------------------------------- 1 | Person = { 2 | '1stname': "John", 3 | 'second-name': "Doe", 4 | 'email@ddress': "john.doe@email.com", 5 | 'male.female': "M" 6 | } 7 | -------------------------------------------------------------------------------- /katas/kyu_8/wilson_primes.py: -------------------------------------------------------------------------------- 1 | def am_i_wilson(n): 2 | return n in (5, 13, 563) 3 | -------------------------------------------------------------------------------- /katas/kyu_8/xor_logical_operator.py: -------------------------------------------------------------------------------- 1 | from operator import xor 2 | 3 | 4 | # def xor(a, b): # another version 5 | # return a ^ b 6 | -------------------------------------------------------------------------------- /katas/retired/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/katas/retired/__init__.py -------------------------------------------------------------------------------- /katas/retired/palindromes.py: -------------------------------------------------------------------------------- 1 | def is_palindrome(s): 2 | s = ''.join(a for a in s.lower() if a.isalpha()) 3 | return s == s[::-1] 4 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/tests/__init__.py -------------------------------------------------------------------------------- /tests/beta_tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/tests/beta_tests/__init__.py -------------------------------------------------------------------------------- /tests/beta_tests/test_counting_array_elements.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.beta.counting_array_elements import count 4 | 5 | 6 | class CountTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(count(['a', 'a', 'b', 'b', 'b']), {'a': 2, 'b': 3}) 9 | -------------------------------------------------------------------------------- /tests/beta_tests/test_for_loop.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.beta.for_loop import problem 4 | 5 | 6 | class ProblemTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(problem(5), [1, 2, 3, 4, 5]) 9 | -------------------------------------------------------------------------------- /tests/beta_tests/test_friend_or_foe.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.beta.friend_or_foe import friend 4 | 5 | 6 | class FriendTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(friend(['Ryan', 'Kieran', 'Mark']), ['Ryan', 'Mark']) 9 | -------------------------------------------------------------------------------- /tests/kyu_3_tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/tests/kyu_3_tests/__init__.py -------------------------------------------------------------------------------- /tests/kyu_4_tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/tests/kyu_4_tests/__init__.py -------------------------------------------------------------------------------- /tests/kyu_5_tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/tests/kyu_5_tests/__init__.py -------------------------------------------------------------------------------- /tests/kyu_6_tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/tests/kyu_6_tests/__init__.py -------------------------------------------------------------------------------- /tests/kyu_6_tests/test_your_order_please.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_6.your_order_please import order 4 | 5 | 6 | class OrderTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(order('is2 Thi1s T4est 3a'), 'Thi1s is2 3a T4est') 9 | -------------------------------------------------------------------------------- /tests/kyu_7_tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/tests/kyu_7_tests/__init__.py -------------------------------------------------------------------------------- /tests/kyu_7_tests/test_deodorant_evaporator.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_7.deodorant_evaporator import evaporator 4 | 5 | 6 | class EvaporatorTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(evaporator(10, 10, 10), 22) 9 | -------------------------------------------------------------------------------- /tests/kyu_7_tests/test_find_the_capitals.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_7.find_the_capitals import capitals 4 | 5 | 6 | class CapitalsTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(capitals('CoDeWaRs'), [0, 2, 4, 6]) 9 | -------------------------------------------------------------------------------- /tests/kyu_7_tests/test_largest_elements.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_7.largest_elements import largest 4 | 5 | 6 | class LargestTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(largest(2, [7, 6, 5, 4, 3, 2, 1]), [6, 7]) 9 | -------------------------------------------------------------------------------- /tests/kyu_7_tests/test_nato_phonetic_alphabet.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_7.nato_phonetic_alphabet import nato 4 | 5 | 6 | class NATOTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(nato('babble'), 'Bravo Alpha Bravo Bravo Lima Echo') 9 | -------------------------------------------------------------------------------- /tests/kyu_7_tests/test_vowel_count.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_7.vowel_count import getCount 4 | 5 | 6 | class GetCountTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(getCount('abracadabra'), 5) 9 | -------------------------------------------------------------------------------- /tests/kyu_8_tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/tests/kyu_8_tests/__init__.py -------------------------------------------------------------------------------- /tests/kyu_8_tests/test_adam_and_eve.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_8.adam_and_eve import God, Man 4 | 5 | 6 | class AdamAndEveTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertIsInstance(God()[0], Man) 9 | -------------------------------------------------------------------------------- /tests/kyu_8_tests/test_broken_greetings.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_8.broken_greetings import Person 4 | 5 | 6 | class PersonTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(Person('Z').greet('Jim'), 'Hi Jim, my name is Z') 9 | -------------------------------------------------------------------------------- /tests/kyu_8_tests/test_color_ghost.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_8.color_ghost import COLORS, Ghost 4 | 5 | 6 | class GhostTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertIn(Ghost().color, COLORS) 9 | -------------------------------------------------------------------------------- /tests/kyu_8_tests/test_format_money.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_8.format_money import format_money 4 | 5 | 6 | class FormatMoneyTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(format_money(39.99), '$39.99') 9 | -------------------------------------------------------------------------------- /tests/kyu_8_tests/test_hello_world.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_8.hello_world import greet 4 | 5 | 6 | class HelloWorldTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(greet(), 'hello world') 9 | -------------------------------------------------------------------------------- /tests/kyu_8_tests/test_name_your_python.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_8.name_your_python import Python 4 | 5 | 6 | class NameYourPythonTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(Python('Guido').name, 'Guido') 9 | -------------------------------------------------------------------------------- /tests/kyu_8_tests/test_number_to_string.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_8.number_to_string import number_to_string 4 | 5 | 6 | class NumberToStringTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(number_to_string(67), '67') 9 | -------------------------------------------------------------------------------- /tests/kyu_8_tests/test_return_to_sanity.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_8.return_to_sanity import mystery 4 | 5 | 6 | class MysteryTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(mystery(), {'sanity': 'Hello'}) 9 | -------------------------------------------------------------------------------- /tests/kyu_8_tests/test_reverse_list_order.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_8.reverse_list_order import reverse_list 4 | 5 | 6 | class ReverseListTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(reverse_list([1, 2, 3]), [3, 2, 1]) 9 | -------------------------------------------------------------------------------- /tests/kyu_8_tests/test_two_plus_two_times_two.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_8.two_plus_two_times_two import calculate 4 | 5 | 6 | class CalculateTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(calculate(), 8) 9 | -------------------------------------------------------------------------------- /tests/kyu_8_tests/test_vowel_remover.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from katas.kyu_8.vowel_remover import shortcut 4 | 5 | 6 | class ShortcutTestCase(unittest.TestCase): 7 | def test_equals(self): 8 | self.assertEqual(shortcut('hello'), 'hll') 9 | -------------------------------------------------------------------------------- /tests/retired_tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/the-zebulan/CodeWars/1eafd1247d60955a5dfb63e4882e8ce86019f43a/tests/retired_tests/__init__.py --------------------------------------------------------------------------------