مثلث Hosoya

سوال

سلام.لطفا برنامه پایتون برای مثلث هوسویا رو میخواستم که لیست زیر رو پرینت کنه. همینطور که میبینید از سطر سوم هر المنت در لیست برابر مجموع دو عدد بالای خودشه. ممنونم

 

۱

۱ ۱

۲ ۱ ۲

۳ ۲ ۲ ۳

۵ ۳ ۴ ۳ ۵

در حال بررسی 0
ehsan61 1 سال 2 پاسخ ها 145 دیده شده 1

پاسخ ها ( ۲ )

  1. :def hosoya(height, width)
        if (width == 0) and (height in (0,1))
            return 1

    :if (width == 1) and (height in (1,2))
            return 1
        :if height > width
            return hosoya(height – 1, width) + hosoya(height – 2, width)
        :if width == height
            return hosoya(height – 1, width – 1) + hosoya(height – 2, width – 2)
        return 0

    :def print_hosoya(height)
      :for i in range(height)
            :for j in range(i + 1)
                print(hosoya(i, j) , end = ” “)
            print (“n”, end = “”)

    print_hosoya(6)

  2.  

ارسال یک پاسخ