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.

A080342 Number of weighings required to identify a single bad coin out of n coins, using a two-pan balance.

Original entry on oeis.org

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

Views

Author

Artemario Tadeu Medeiros da Silva (artemario(AT)uol.com.br), Mar 19 2003

Keywords

Comments

It is known that there is exactly one bad coin, which is heavier than the others. No weights are used in the weighings.
0 appears once, 1 twice, 2 6 times, 3 18 times, 4 54 times, ... which is the same as the number of base-3 numbers of length n; see A007089. - Jonathan Vos Post, Apr 20 2011
Records appear at positions 3^n+1 (=A034472(n)). - Robert G. Wilson v, Aug 06 2012
The "Heavy Marble" section of "Brainteaser Problems" in the Mongan et al. reference describes the n = 8 case in detail and then derives the general formula given below. Of course this sequence applies also when the single, unlike object is lighter than all the others. If the unlike object is only known to have a different weight (that is, to be lighter than all the others or heavier than all the others), use A064099. - Rick L. Shepherd, Sep 05 2013
If it is unknown whether the bad coin is heavier or lighter, then the minimum number of weighings is A029837(n) and the number of coins that must be used in the first weighing is A004526(n), for n > 2. - Ivan N. Ianakiev, Apr 13 2017

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.

Crossrefs

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