--- id: 6a0dcd03ee4e68698080ef68 title: "Challenge 304: Itinerary Arrangements" challengeType: 29 dashedName: challenge-304 --- # --description-- Given an array of at least two optional stops for a day trip, return the number of valid itinerary arrangements. The itinerary always includes `"breakfast"`, `"lunch"`, and `"dinner"`, these will not be passed in as arguments. The optional stops can be placed anywhere in the itinerary, subject to the following rules: - `"breakfast"` is always first, with at least one stop before `"lunch"`. - `"lunch"` must appear before `"dinner"`, with at least one stop in between. - At most, one optional stop may appear after `"dinner"`. Return the number of valid arrangements. # --hints-- `get_itinerary_count(["library", "park"])` should return `2`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_itinerary_count(["library", "park"]), 2)`) }}) ``` `get_itinerary_count(["library", "park", "arcade"])` should return `18`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_itinerary_count(["library", "park", "arcade"]), 18)`) }}) ``` `get_itinerary_count(["library", "park", "arcade", "store"])` should return `120`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_itinerary_count(["library", "park", "arcade", "store"]), 120)`) }}) ``` `get_itinerary_count(["library", "park", "arcade", "store", "cafe"])` should return `840`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_itinerary_count(["library", "park", "arcade", "store", "cafe"]), 840)`) }}) ``` `get_itinerary_count(["library", "park", "arcade", "store", "cafe", "market", "museum"])` should return `55440`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_itinerary_count(["library", "park", "arcade", "store", "cafe", "market", "museum"]), 55440)`) }}) ``` # --seed-- ## --seed-contents-- ```py def get_itinerary_count(stops): return stops ``` # --solutions-- ```py from math import factorial def get_itinerary_count(stops): n = len(stops) return (2 * n - 3) * factorial(n) ```