{"id":33706,"date":"2024-11-01T09:19:28","date_gmt":"2024-11-01T09:19:28","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33706"},"modified":"2024-11-01T11:47:02","modified_gmt":"2024-11-01T11:47:02","slug":"python-coding-test-course-planning-a-trip","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33706\/","title":{"rendered":"python coding test course, planning a trip"},"content":{"rendered":"<p><body><\/p>\n<p>\n    In modern society, travel provides people with various experiences and pleasures. However, planning a trip can be a challenging task. This is because several factors need to be considered, such as choosing a travel destination, coordinating dates, and managing budgets. In this course, we will address an algorithmic problem of planning a trip using Python.\n<\/p>\n<h2>Problem Definition<\/h2>\n<p>\n    Implement an algorithm that recommends an appropriate travel route based on given travel destinations and distance information between them. Each destination is prioritized based on its popularity and travel time. Destinations can be visited according to the recommended priority, aiming to visit all destinations with the least distance possible.\n<\/p>\n<h3>Problem Explanation<\/h3>\n<p>\n    &#8211; Input:\n<\/p>\n<ul>\n<li>List of destinations: Each destination is provided in the form of (name, popularity, location).<\/li>\n<li>Distance map: Data in the form of an adjacency matrix containing distance information between each destination.<\/li>\n<\/ul>\n<p>\n    &#8211; Output:\n<\/p>\n<ul>\n<li>List of destinations to be visited and the optimal travel route.<\/li>\n<li>Total distance required for the trip.<\/li>\n<\/ul>\n<h2>Problem Example<\/h2>\n<pre>\nInput:\ndestinations = [(\"Seoul\", 8, (37.5665, 126.978)), (\"Busan\", 7, (35.1796, 129.0756)), (\"Jeju\", 9, (33.4996, 126.5312))]\ndistance_map = [\n    [0, 325, 450],\n    [325, 0, 600],\n    [450, 600, 0]\n]\n\nOutput:\nTravel route: [\"Seoul\", \"Jeju\", \"Busan\"]\nTotal distance: 925\n<\/pre>\n<h2>Algorithm Design<\/h2>\n<p>\n    To solve the problem, we will use the following approach.\n<\/p>\n<ul>\n<li><strong>Priority Sorting:<\/strong> Sort the list of destinations in descending order based on popularity.<\/li>\n<li><strong>Optimal Route Exploration:<\/strong> Explore all possible routes based on the sorted list.<\/li>\n<li><strong>Distance Calculation:<\/strong> Calculate the total distance for each route and select the route with the least distance.<\/li>\n<\/ul>\n<h2>Implementation<\/h2>\n<p>Now, let&#8217;s implement the Python code based on the design above.<\/p>\n<pre><code>\nfrom itertools import permutations\n\ndef calculate_distance(route, distance_map):\n    total_distance = 0\n    for i in range(len(route) - 1):\n        from_city = route[i]\n        to_city = route[i + 1]\n        total_distance += distance_map[from_city][to_city]\n    return total_distance\n\ndef plan_trip(locations, distance_map):\n    locations.sort(key=lambda x: x[1], reverse=True)  # Sort by popularity\n    location_indices = {location[0]: index for index, location in enumerate(locations)}\n\n    best_route = []\n    min_distance = float('inf')\n\n    # Explore all possible travel routes\n    for perm in permutations(locations):\n        route = [location[0] for location in perm]\n        distance = calculate_distance(route, location_indices)\n        \n        if distance < min_distance:\n            min_distance = distance\n            best_route = route\n\n    return best_route, min_distance\n\n# Example execution\nlocations = [(\"Seoul\", 8), (\"Busan\", 7), (\"Jeju\", 9)]\ndistance_map = {\n    0: {0: 0, 1: 325, 2: 450},\n    1: {0: 325, 1: 0, 2: 600},\n    2: {0: 450, 1: 600, 2: 0},\n}\n\nbest_route, total_distance = plan_trip(locations, distance_map)\n\nprint(\"Travel route:\", best_route)\nprint(\"Total distance:\", total_distance)\n<\/code><\/pre>\n<h2>Code Explanation<\/h2>\n<p>\n    The above code implements an algorithm to solve the travel planning problem. The <code>plan_trip<\/code> function sorts the destinations by popularity, then uses the <code>itertools.permutations<\/code> module to generate all possible combinations. The <code>calculate_distance<\/code> function calculates the total distance for each route, and the route with the shortest distance is selected.\n<\/p>\n<h2>Conclusion<\/h2>\n<p>\n    Planning a trip requires considering many factors, and leveraging algorithms can help create more efficient travel plans. In this course, we explored how to find the optimal travel route by selecting travel destinations and calculating distances using Python. Developing problem-solving skills through various algorithms will also aid in your coding test preparation.\n<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In modern society, travel provides people with various experiences and pleasures. However, planning a trip can be a challenging task. This is because several factors need to be considered, such as choosing a travel destination, coordinating dates, and managing budgets. In this course, we will address an algorithmic problem of planning a trip using Python. &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33706\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;python coding test course, planning a trip&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[145],"tags":[],"class_list":["post-33706","post","type-post","status-publish","format-standard","hentry","category-python-coding-test"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>python coding test course, planning a trip - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/33706\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"python coding test course, planning a trip - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In modern society, travel provides people with various experiences and pleasures. However, planning a trip can be a challenging task. This is because several factors need to be considered, such as choosing a travel destination, coordinating dates, and managing budgets. In this course, we will address an algorithmic problem of planning a trip using Python. &hellip; \ub354 \ubcf4\uae30 &quot;python coding test course, planning a trip&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33706\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:19:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:47:02+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"2\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/33706\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33706\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"python coding test course, planning a trip\",\"datePublished\":\"2024-11-01T09:19:28+00:00\",\"dateModified\":\"2024-11-01T11:47:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33706\/\"},\"wordCount\":336,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Python Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33706\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33706\/\",\"name\":\"python coding test course, planning a trip - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:19:28+00:00\",\"dateModified\":\"2024-11-01T11:47:02+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33706\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33706\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33706\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"python coding test course, planning a trip\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"python coding test course, planning a trip - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/33706\/","og_locale":"ko_KR","og_type":"article","og_title":"python coding test course, planning a trip - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In modern society, travel provides people with various experiences and pleasures. However, planning a trip can be a challenging task. This is because several factors need to be considered, such as choosing a travel destination, coordinating dates, and managing budgets. In this course, we will address an algorithmic problem of planning a trip using Python. &hellip; \ub354 \ubcf4\uae30 \"python coding test course, planning a trip\"","og_url":"https:\/\/atmokpo.com\/w\/33706\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:19:28+00:00","article_modified_time":"2024-11-01T11:47:02+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"2\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/33706\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33706\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"python coding test course, planning a trip","datePublished":"2024-11-01T09:19:28+00:00","dateModified":"2024-11-01T11:47:02+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33706\/"},"wordCount":336,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Python Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33706\/","url":"https:\/\/atmokpo.com\/w\/33706\/","name":"python coding test course, planning a trip - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:19:28+00:00","dateModified":"2024-11-01T11:47:02+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33706\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33706\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33706\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"python coding test course, planning a trip"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=33706"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33706\/revisions"}],"predecessor-version":[{"id":33707,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33706\/revisions\/33707"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}