A080342 Number of weighings required to identify a single bad coin out of n coins, using a two-pan balance.
0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
Offset: 1
Examples
a(1) = 0 since no weighings are needed - the coin is bad. a(2) = 1 since one weighing is needed.
References
- J. Mongan, N. Suojanen, and E. Giguère, Programming Interviews Exposed: Secrets to Landing Your Next Job, 2nd Edition, Wiley Publishing, Inc., 2007, pp. 169-172.
Links
- Rick L. Shepherd, Table of n, a(n) for n = 1..10000
- R. K. Guy, R. J. Nowakowski, Coin-weighing problems, Am. Math. Monthly 102 (2) (1995) 164-167.
- B. Manvel, Counterfeit coin problems, Math. Mag. 50 (2) (1977) 90-92, theorem 1.
Programs
-
Haskell
import Data.List (transpose) a080342 n = genericIndex a080342_list (n - 1) a080342_list = 0 : zs where zs = 1 : 1 : (map (+ 1) $ concat $ transpose [zs, zs, zs]) -- Reinhard Zumkeller, Sep 02 2015
-
Mathematica
f[n_] := Floor[ Log[3, n]] - Floor[2^-FractionalPart[ Log[3, n]]] + 1; Array[f, 105] (* Robert G. Wilson v, Aug 05 2012 *)
-
PARI
a(n) = ceil(log(n)/log(3)) \\ Rick L. Shepherd, Sep 05 2013
Formula
a(n) = floor(L) - floor(2^(-f(L))) + 1, where L = log_3(n) and f() = fractional part.
a(n) = ceiling(log_3(n)). - Rick L. Shepherd, Sep 05 2013
A064235(n) = 3 ^ a(n). - Reinhard Zumkeller, Sep 02 2015
Comments