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.

User: Nicholas Stefan Georgescu

Nicholas Stefan Georgescu's wiki page.

Nicholas Stefan Georgescu has authored 4 sequences.

A371949 Array read by antidiagonals: T(n,k) is the numerator of the probability of attacker victory in the game of Risk when n attacking armies face k defending armies in a territory.

Original entry on oeis.org

3240, 6415200, 45606240, 12702096000, 170514616320, 430865593920, 25150150080000, 753411576268800, 2398271752673280, 3552119332387200, 49797297158400000, 2595785508222566400, 13369373984761528320, 22330692411407861760, 28155000551019598080
Offset: 1

Author

Keywords

Comments

In the game of Risk, an attack occurs when a player moves some number of armies into a territory defended by the armies of another player, and the outcome of the attack is determined by repeatedly rolling 6-sided dice according to the number of attacking and defending armies present, up to a maximum of 3 and 2 dice for the attacker and defender, respectively. Some number of armies are eliminated corresponding to comparing highest versus highest roll (with the loser losing one army), and second-highest versus second-highest roll (with the loser again losing one army), with ties going to the defending side. This continues either until the aggressor decides to retreat before the next roll, or until one side has lost all of its armies in the territory (in which case the victor has possession of the territory with the remaining armies).
Example: 3 of Alice's armies invade a territory held by 3 of Bob's armies; Alice rolls a (1,2,5) and Bob rolls a (4,2). Alice's 5 beats Bob's 4, and Bob's 2 beats Alice's 2 (as Bob is defending). Each side therefore loses one army, with each side having 2 armies remaining. Note that in this example, if Alice continues the attack, she will now roll only 2 dice against Bob's 2, thereby reducing her odds of eliminating Bob's armies in that territory. It can be shown that, in an arbitrarily large set of rolls, the odds favor the attacker. When the attacking player rolls 3 dice and the defending player rolls 2, of the 6^5 = 7776 possible rolls (all equally likely to occur), there are
2890 that result in the loss of 2 armies by the defender,
2275 that result in the loss of 2 armies by the attacker, and
2611 that result in the loss of 1 army by each.
However, in a 1-vs.-1 scenario, the defense is favored 7/12 to 5/12 because defenders win ties. Thus the probabilities are not so trivial as to which matchups are favorable. This is further complicated by intermediate-size armies which require repeated rolling, such as the 3-vs.-3 example above, where there is a nearly 2/3 chance that the attacker will lose troops that land them below the three-army threshold, but a 1/3 chance that the defender will be down to 1 defender against 3 attackers, which heavily favors the attacker. This requires recursively calculating the probabilities for the further downstream outcomes.

Examples

			This sequence lists the numerators T(n,k) along antidiagonals of the probability of n attacking armies winning against k defending armies.  The denominator of each probability is 7776^(n+k-1).  The sequence starts with T(1,1) and moves to T(1,2), T(2,1); T(1,3), T(2,2), T(3,1); etc.  Hence the first value is 3240/7776 = 5/12.
A k-vs.-k attack by 4 or fewer armies, played until complete elimination, will favor the defender, but 5-vs.-5 or more will favor the attacker, with the probability of victory by the attacker steadily increasing with each additional die added to both sides.
		

Programs

  • Python
    from itertools import product
    from collections import Counter
    from functools import lru_cache
    from fractions import Fraction
    def get_elims(o,d): return tuple(-''.join(['od'[int(o>d)] for o,d in zip(*[sorted(i)[-2:][::-1] for i in [o,d]])]).count(j) for j in 'od')
    @lru_cache()
    def elim_p(o_n,d_n): return {j:Fraction(k,7776) for j,k in Counter([get_elims(i[:o_n],i[o_n:o_n+d_n]) for i in product(range(1,7),repeat=5)]).most_common()}
    @lru_cache()
    def res_p(o_n,d_n): return {(o_n+i[0],d_n+i[1]):j for i,j in elim_p(min(3,o_n), min(2,d_n)).items()}
    def get_final_result(o_n,d_n):
        d,g = {(o_n,d_n):1}, [(o_n,d_n)]
        while g:
            w,p = g[0], d.pop(g[0])
            for i,j in res_p(*w).items():
                d[i] = d.get(i,0)+j*p
            g = [i for i in d.keys() if min(i)>0]
        return d
    def get_win_count(o_n,d_n): return (sum(j for i,j in get_final_result(o_n,d_n).items() if i[0]>i[1])*(7776**(o_n+d_n-1))).numerator
    a = [get_win_count(o_n,t-o_n) for t in range(2,30) for o_n in range(1,t)]

A365443 Triangle read by rows: T(n,s) is the numerator of the probability that the sum s occurs when repeated rolls of an n-sided die are summed for s = 0..2n.

Original entry on oeis.org

1, 1, 1, 1, 1, 1, 3, 5, 11, 1, 1, 4, 16, 37, 121, 376, 1, 1, 5, 25, 125, 369, 1589, 6665, 26925, 1, 1, 6, 36, 216, 1296, 4651, 24781, 129936, 667116, 3327696, 1, 1, 7, 49, 343, 2401, 16807, 70993, 450295, 2825473, 17492167, 106442161, 633074071, 1, 1, 8, 64
Offset: 0

Author

Keywords

Comments

The triangle is formed by considering the probability of occurrence of a zero-indexed sum, s, of repeated rolls of an n-sided die. The probability is obtained by considering that the sum s = 0 appears with probability 1, and then for every s > 0, the sum s has a probability of appearing that is 1/n times the sum of the probability of appearing of each of the previous n values of s. The denominator of this probability is n^s, and the numerator is given in the rows of the triangle below.
For example, consider repeated rolls of an n=4-sided die. Looking at the corresponding portion of the sequence (i.e., 1, 1, 3, 5, 11), the probability that s = 0 occurs is 1/1, the probability that s = 1 occurs is 1/(n^s) = 1/4, the probability that s = 2 occurs is 5/(n^s) = 5/16, as there is a 1/4 chance that it is rolled from the start plus the 1/16 chance that it occurs when two consecutive 1's are rolled, and so on. Hence the probability for all s <= n numbers that can be rolled is (n+1)^(s-1)/n^s, with a global maximum at s = n.
However, for s > n, where there is no longer the chance that the sum occurs in a single roll, the fraction drops precipitously. It then resumes rising until s = floor((n+1)^(n+1)/n^n - n) (see A366451) which is the s having the maximum probability for s > n. Therefore this maximum will always occur at s <= 2n for all nontrivial dice (i.e., dice with n > 1 sides). Hence the rows of this triangle have been terminated at 2n since that guarantees the maximum, but a row could in principle be extended in perpetuity, wherein the fraction would stabilize about the value 2/(n+1).

Examples

			Triangle begins:
  0  |  1
  1  |  1  1  1
  2  |  1  1  3   5   11
  3  |  1  1  4  16   37   121    376
  4  |  1  1  5  25  125   369   1589   6665   26925
  5  |  1  1  6  36  216  1296   4651  24781  129936   667116   3327696
		

Crossrefs

Main diagonal gives A000272(n+1).
Cf. A366451.

Programs

  • Maple
    b:= proc(n, s) option remember;
          `if`(s=0, 1, add(b(n, s-j)/n, j=1..min(s, n)))
        end:
    T:= (n, s)-> numer(b(n, s)):
    seq(seq(T(n,s), s=0..2*n), n=0..7);  # Alois P. Heinz, Apr 01 2025
  • Mathematica
    A365443[n_, s_] := If[s == 0, 1, (n+1)^(s-1) - If[s > n, (n+1)^(s-n-2)*s*n^n, 0]];
    Table[A365443[n, s], {n, 0, 6}, {s, 0, 2*n}] (* Paolo Xausa, Apr 02 2025 *)
  • Python
    def Pn(n,s): # probability numerator of rolling s with an n-sided die
        if s==0: return 1
        elif s>n: return int((n+1)**(s-n-2)*(n*(n+1)**n-n**n*s+(n+1)**n))
        else: return (n+1)**(s-1)
    [Pn(n,s) for n in range(10) for s in range(2*n+1)]

Formula

T(n,s) = 1 for s = 0,
(n+1)^(s-1) for 0 < s <= n,
(n+1)^(s-1) - (n+1)^(s-n-2)*s*n^n for n < s <= 2n.

A366451 The sum s > n which has the greatest probability of occurring when summing rolls of an n-sided die.

Original entry on oeis.org

4, 6, 8, 9, 11, 13, 15, 16, 18, 20, 21, 23, 25, 27, 28, 30, 32, 34, 35, 37, 39, 40, 42, 44, 46, 47, 49, 51, 52, 54, 56, 58, 59, 61, 63, 64, 66, 68, 70, 71, 73, 75, 76, 78, 80, 82, 83, 85, 87, 88, 90, 92, 94, 95, 97, 99, 101, 102, 104, 106, 107, 109, 111, 113
Offset: 2

Author

Keywords

Comments

A player chooses a target t > n and rolls a fair n-sided die repeatedly, keeping a running total of the numbers rolled. The player wins if t occurs in the sequence of running totals. a(n) is the choice of t that maximizes the probability of winning
A fair die with sides numbered 1 through n is assumed.
For given n, sum s occurs by adding one die role to a sum s-n .. s-1; so the probability p(s) of s occurring is p(s) = Sum_{i=1..n} p(s-i)*(1/n), i.e., the mean of the preceding n probabilities, and starting from p(0) = 1 for s=0 always occurring and p(s) = 0 for s < 0 never occurring.
It is immediately apparent upon plotting the probabilities from sum s = n+1 onwards that the highest probability is achieved at s = a(n).
It can be shown that, given the equation of n < s <= 2n, the maximum near a(n) is the only zero of the first derivative, and the second derivative is always negative, therefore any following probability must necessarily be less the maximum of the previous n probabilities, and therefore less than p(a(n)). Therefore any subsequent terms must then be less than p(a(n)). Because this is appending a rolling average of the previous n terms the probabilities dampen in their oscillations about a value of 2/(n+1).

Examples

			For n=20, the probability of occurrence p(s) of sum s > n begins at p(21) = 0.08266... and rises to p(35) = 0.09767... before decreasing to p(36) = 0.09760... and never reaches p(35) again, so a(20) = 35 is the sum s with greatest probability of occurrence.
           s     p(s)
          --  ----------
          21  0.08266...
          ...
          34  0.09751...
  a(20) = 35  0.09767... <--- maximum probability
          36  0.09760...
          ...
          42  0.09350...
		

Crossrefs

Programs

  • Mathematica
    A366451[n_] := Floor[(n+1)^(n+1)/n^n] - n; Array[A366451, 100, 2] (* Paolo Xausa, Oct 12 2024 *)
  • Python
    from fractions import Fraction
    a = lambda n: int(Fraction((n+1)*(n+1)**n-n**(n+1),n**n))

Formula

For n < s < 2n, the probability of sum s occurring is p(s) = ((n+1)^(s-1) - s*n^n*(n+1)^(s-n-2))/n^s, which means that, from the difference between s and s-1, the sequence value is given by:
a(n) = floor(((n+1)*(n+1)^n - n^(n+1))/n^n).
a(n) = A060644(n) - n.
An empirical observation is that a(n) is well approximated by (e-1)*(n+1/2).
From Javier Múgica, May 01 2025: (Start)
Taylor expansion of the maximum of p(s) gives a(n) ~ (e-1)*(n+1/2) - (e-2)/(24n).
The maximum for s > 2n is attained at s ~ (e-sqrt(-e^2+2e+2))*n, approx. 2.5*n. In general, the position of the maximum for s > kn is given by an algebraic equation in s and e of degree k in each of them. (End)

A357913 Inverse of 10 modulo prime(n).

Original entry on oeis.org

5, 10, 4, 12, 2, 7, 3, 28, 26, 37, 13, 33, 16, 6, 55, 47, 64, 22, 8, 25, 9, 68, 91, 31, 75, 11, 34, 89, 118, 96, 14, 15, 136, 110, 49, 117, 52, 18, 163, 172, 58, 138, 20, 190, 67, 159, 23, 70, 24, 217, 226, 180, 79, 27, 244, 194, 253, 85, 88, 215, 280, 94, 222, 298, 236, 243
Offset: 4

Author

Keywords

Comments

Original definition: "Another test for divisibility by the n-th prime (see Comments for precise definition)."
Given a number M, delete its last digit d, then add d*a(n). If the result is divisible by prime(n), then M is also divisible by prime(n). This process may be repeated.
a(n) can be quickly calculated by finding the smallest multiple of prime(n) ending in 9, adding one, and dividing that result by 10. E.g., 7 -> 49 -> 5, 11 -> 99 -> 10, 13 -> 39 -> 4, 17 -> 119 -> 12, 19 -> 19 -> 2.
Equivalent definition: a(n) = 10^(p - 2) mod p, where p = prime(n). - Mauro Fiorentini, Feb 06 2025

Crossrefs

Programs

  • Mathematica
    PowerMod[10, -1, Prime[Range[4, 100]]] (* Paolo Xausa, Feb 07 2025 *)
  • PARI
    apply( {A357913(n)=lift(1/Mod(10,prime(n)))}, [4..49]) \\ M. F. Hasler, Feb 03 2025
  • Python
    import sympy
    [pow(10, -1, p) for p in sympy.primerange(7,348)]
    

Formula

a(n) = prime(n) - A103876(n).
a(n) = (A114013(n) + 1)/10. - Hugo Pfoertner, Jan 28 2023

Extensions

Better definition from M. F. Hasler, Feb 03 2025