The Riddle-Count of the Ammareth Sphinx
Commission of the Dunewalkers' Lodge: Passage Past the Ammareth Sphinx
At the mouth of the Ammareth Dunes, a great stone Sphinx guards the only road to the buried city of Qesh. A traveller who wishes to pass carves a number into the Sphinx's paw. The Sphinx then lights a row of brazier-marks, one number per mark, and the traveller must name every mark before the first is lit. The Lodge pays well for anyone who can reckon the row in advance.
The first mark is the carved number itself. Each later mark comes from the one before it, x, by the first of these rules that applies:
1. If x is divisible by 3, the next mark is x divided by 3. 2. Otherwise, if x is even, the next mark is x divided by 2. 3. Otherwise, the next mark is x + 5.
The rules are checked in that order, so a number divisible by both 2 and 3 follows rule 1.
Write riddleCount(seed, count).
seedis a positive integer (at least 1): the carved number.countis a non-negative integer: how many marks the Sphinx lights.
Return a list of exactly count integers: the marks in order, beginning with seed itself. If count is 0, return an empty list.
examples
- case 1
seed of 7, count of 6[7, 12, 4, 2, 1, 6] (7 is odd and not divisible by 3, so it becomes 12; 12 is divisible by 3, so it becomes 4) - case 2
seed of 12, count of 4[12, 4, 2, 1] (12 is divisible by both 2 and 3; the rule for 3 comes first) - case 3
seed of 20, count of 5[20, 10, 5, 10, 5] - case 4
seed of 9, count of 0[]
- reward
- 220 XP
- signature
riddleCount
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- seven_six_marks
- divisible_by_both_prefers_three
- settles_into_ten_five_loop
- zero_count_is_empty
- single_mark_is_seed
- long_row_from_twenty_five
- even_multiple_of_three_chain
- odd_jump_then_halving
- powers_of_three_descend
- one_cycles