OFFSET
1,2
COMMENTS
In "Bulgarian solitaire" a deck of cards or another finite set of objects is divided into one or more piles, and the "Bulgarian operation" is performed by taking one card from each pile, and making a new pile of them, which is added to the remaining set of piles. Essentially, this operation is a function whose domain and range are unordered integer partitions (cf. A000041) and which preserves the total size of a partition (the sum of its parts). This sequence is induced when the operation is implemented on the partitions as ordered by the list A241918.
REFERENCES
Martin Gardner, Colossal Book of Mathematics, Chapter 34, Bulgarian Solitaire and Other Seemingly Endless Tasks, pp. 455-467, W. W. Norton & Company, 2001.
LINKS
Antti Karttunen, Table of n, a(n) for n = 1..256
Ethan Akin and Morton Davis, "Bulgarian solitaire", American Mathematical Monthly 92 (4): 237-250. (1985).
Wikipedia, Bulgarian solitaire
FORMULA
EXAMPLE
For n = 10, we see that as 10 = 2*5 = p_1^1 * p_2^0 * p_3^1, it encodes a partition [2,2,2]. Applying one step of Bulgarian solitaire (subtract one from each part, and add a new part as large as there were parts in the old partition) to this partition results a new partition [1,1,1,3], which is encoded in the prime factorization of p_1^0 * p_2^0 * p_3^0 * p_4^3 = 7^3 = 343. Thus a(10) = 343.
For n = 46, we see that as 46 = 2*23 = p_1 * p_9 = p_1^1 * p_2^0 * p_3^0 * ... * p_9^1, it encodes a partition [2,2,2,2,2,2,2,2,2]. Applying one step of Bulgarian solitaire to this partition results a new partition [1,1,1,1,1,1,1,1,1,9], which is encoded in the prime factorization of p_1^0 * p_2^0 * ... * p_9^0 * p_10^9 = 29^9 = 14507145975869. Thus a(46) = 14507145975869.
For n = 1875, we see that as 1875 = p_1^0 * p_2^1 * p_3^4, it encodes a partition [1,2,5]. Applying Bulgarian Solitaire, we get a new partition [1,3,4]. This in turn is encoded by p_1^0 * p_2^2 * p_3^2 = 3^2 * 5^2 = 225. Thus a(1875)=225.
PROG
(Scheme, three different implementations)
;; The following requires Aubrey Jaffer's SLIB Scheme library:
(require 'factor)
(define (A243051 n) (explist->n (ascpart_to_prime-exps (bulgarian-operation (prime-exps_to_ascpart (primefacs->explist n))))))
(define (bulgarian-operation ascpart) (let loop ((newpartition (list (length ascpart))) (ascpart ascpart)) (cond ((null? ascpart) (sort newpartition <)) (else (loop (if (= 1 (car ascpart)) newpartition (cons (- (car ascpart) 1) newpartition)) (cdr ascpart))))))
(define (primefacs->explist n) (reverse! (primefactorization->explist n)))
(define (primefactorization->explist n) (if (= 1 n) (list) (let loop ((factors (sort (factor n) <)) (pf 1) (el (list))) (cond ((null? factors) el) ((= (car factors) pf) (set-car! el (1+ (car el))) (loop (cdr factors) (car factors) el)) (else (loop (cdr factors) (car factors) (cons 1 (cons-n-times (-1+ (- (A049084 (car factors)) (A049084 pf))) 0 el))))))))
(define (prime-exps_to_ascpart explist) (if (null? explist) explist (sub1from_the_last (partsums (cons (+ (car explist) 1) (cdr explist))))))
(define (partsums a) (cdr (reverse! (fold-left (lambda (psums n) (cons (+ n (car psums)) psums)) (list 0) a))))
(define (sub1from_the_last lista) (let ((rev (reverse lista))) (reverse! (cons (- (car rev) 1) (cdr rev)))))
(define (ascpart_to_prime-exps partlist) (if (null? partlist) partlist (add1to_the_last (cons (- (car partlist) 1) (diff partlist)))))
(define (add1to_the_last lista) (let ((rev (reverse lista))) (reverse! (cons (+ 1 (car rev)) (cdr rev)))))
(define (diff a) (map - (cdr a) (reverse! (cdr (reverse a)))))
(define (explist->n explist) (if (null? explist) 1 (mul (lambda (i) (expt (A000040 i) (list-ref explist (-1+ i)))) 1 (length explist))))
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, May 29 2014
STATUS
approved