fork(2) download
  1. def distribute(h,b):
  2. if h < 1:
  3. return "B"*b
  4. if b < 1:
  5. return "H"*h
  6. ans=""
  7. if h > b:
  8. q = h//b
  9. r = h-q*b
  10. hperb = "H"*q
  11. for x in distribute(r, b):
  12. if x == "B":
  13. ans += hperb
  14. ans+=x
  15. else:
  16. q = b//h
  17. r = b-q*h
  18. bperh = "B"*q
  19. for x in distribute(h, r):
  20. if x == "H":
  21. ans += bperh
  22. ans+=x
  23. return ans
  24.  
  25. print (distribute(1,10))
  26. print (distribute(2,10))
  27. print (distribute(3,10))
  28. print (distribute(4,10))
  29. print (distribute(5,10))
  30. print (distribute(6,10))
  31. print (distribute(7,10))
  32. print (distribute(8,10))
  33. print (distribute(9,10))
  34. print (distribute(10,10))
  35.  
Success #stdin #stdout 0.02s 9172KB
stdin
Standard input is empty
stdout
BBBBBBBBBBH
BBBBBHBBBBBH
BBBHBBBHBBBHB
BBHBBHBBBHBBHB
BBHBBHBBHBBHBBH
BHBBHBBHBHBBHBBH
BHBHBBHBHBBHBHBBH
BHBHBHBHBBHBHBHBHB
BHBHBHBHBHBHBHBHBHB
BHBHBHBHBHBHBHBHBHBH