cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A334473 The n-cowboy shootout problem: a(3^k) = 3^k, a((3^k)+b) = b if (3^k)+b <= 2*3^k, otherwise a((3^k)+b) = 2*b-3^k, where b is a positive integer.

This page as a plain text file.
%I A334473 #29 Aug 22 2025 20:03:29
%S A334473 1,1,3,1,2,3,5,7,9,1,2,3,4,5,6,7,8,9,11,13,15,17,19,21,23,25,27,1,2,3,
%T A334473 4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,29,
%U A334473 31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69
%N A334473 The n-cowboy shootout problem: a(3^k) = 3^k, a((3^k)+b) = b if (3^k)+b <= 2*3^k, otherwise a((3^k)+b) = 2*b-3^k, where b is a positive integer.
%C A334473 Arrange n cowboys in a circle, each takes it in turn to shoot the cowboy directly opposite them, so there is only one cowboy shooting at a time. If there is a gap directly opposite them, because the number of remaining cowboys is odd, they shoot the cowboy on the left of the gap. Turns progress clockwise from the starting cowboy. Every time a cowboy is killed the circle is rearranged so every cowboy is evenly spaced.
%C A334473 a(n) is the starting position of the surviving cowboy.
%C A334473 A variant of the Josephus problem.
%H A334473 JWSon, <a href="https://www.reddit.com/r/mathriddles/comments/gct41o/turnbased_cowboy_standoff/">Turn-Based Cowboy Standoff</a>
%H A334473 Wikipedia <a href="https://en.wikipedia.org/wiki/Josephus_problem">Josephus problem</a>
%H A334473 <a href="/index/J#Josephus">Index entries for sequences related to the Josephus Problem</a>
%e A334473 a(4) = 1: The first cowboy shoots the 3rd cowboy opposite him. The 2nd cowboy would then be aiming in a gap between the 1st and the 4th cowboy so shoots the cowboy on the left of the gap (the 4th cowboy). We are now back with the 1st cowboy who shoots the only remaining cowboy (the 2nd) so wins.
%o A334473 (Python)
%o A334473 def highest_power_of_3(n):
%o A334473     option = 0
%o A334473     while 3**option <= n:
%o A334473         option +=1
%o A334473     return 3 ** (option -1)
%o A334473 def answer(n):
%o A334473     x = highest_power_of_3(n)
%o A334473     if x == n:
%o A334473         return x
%o A334473     else:
%o A334473         if n < 2 * x:
%o A334473             return n%x
%o A334473         else:
%o A334473             return x + 2 * (n%x)
%o A334473 number_of_terms = 100
%o A334473 answers = []
%o A334473 for i in range(1, number_of_terms + 1):
%o A334473     answers.append(answer(i))
%o A334473 print(answers)
%Y A334473 Cf. A006257, A336233.
%K A334473 nonn
%O A334473 1,3
%A A334473 _Neil Hacker_, May 05 2020