Issues to manage a complex loop about Number Walls (Mathologer video) and tips for a faster coding

God evening, I’m new in Julia.
I’m trying to code an algorithm about the building of Number Walls (there’s a video of Mathologer talking about them).
I wrote a code but I don’t know how to make it work since:

  • the most of the time it doesn’t give me the right output
    -I did some changes in the past resulting in forever loops that’t can’t be stopped.

I program using VS Code, my Computer is a HP with Windows.
My Julia program is updated.

using Plotly, PlotlyJS
using Statistics, ProgressMeter
PlotlyJS.plotlyjs()  #gives me error
plotlyjs()  #gives me error too

width = 128
height = 128

data = zeros(Float32, width, height)

data[data .== 0] .=NaN

data[1,:] = zeros(Int, width)
data[2,:] = ones(Int, width)

seqq = [0, 1, 1, 0]
w = 0
while w <13
    seqq2 = .-1 .* seqq .+ 1
    seqq = vcat(seqq,seqq2)
    w += 1
end

data[3,:]= seqq[1:width]

riempi_matrice_2 = function()

    total_steps = (width - 3) * (width - 2)
    p = Progress(total_steps)

    for i in 3 : (width-1)
        for j in 2:(width-1)
            if !isnan(data[i, j-1]) 
                if data[i,j] != 0
                    if data[i-1, j] != 0 

                        data[i+1, j] = data[i, j]^2 - data[i, j-1] * data[i, j+1] / data[i-1, j]

                    elseif data[i-1,j] == 0 && data[i-2,j] != 0 #&& j-2>0 && j+2 <= 2000 

                        if j-2>0 && j+2 <= width
                            data[i+1, j] = (data[i-1,j-1]^2*data[i-1,j+2]+data[i-1,j+1]^2*data[i-1,j-2]-data[i-3,j]*data[i,j]^2)/data[i-2,j]^2
                        end

                    elseif data[i-1,j] == 0 && data[i-2,j] == 0 #j-2>0 && j+2 <= 2000 &&

                        l_lato_finestra = 0
                        posiz_sul_lato_dal_fondo = 1

                        for n in 1:(i-2)
                            if data[i-n,j] == 0
                                l_lato_finestra +=1
                                n += 1
                            else
                                break
                            end
                        end

                        for n in 1:(i-2)
                            if data[i-1,j+n] == 0
                                posiz_sul_lato_dal_fondo +=1
                                n += 1
                            else
                                break
                            end
                        end

                        lato_sinistro = j+posiz_sul_lato_dal_fondo-l_lato_finestra-1

                        rapp_geom_up = data[i-l_lato_finestra-1,j+1]/data[i-l_lato_finestra-1,j]
                        rapp_geom_left = data[i-1, lato_sinistro]/data[i-2,lato_sinistro]
                        rapp_geom_right = data[i-2, j + posiz_sul_lato_dal_fondo]/data[i-1, j + posiz_sul_lato_dal_fondo]

                        rapp_geom_down = (-1)^l_lato_finestra * rapp_geom_left * rapp_geom_right / rapp_geom_up

                        data[i+1,j]= (data[i-l_lato_finestra-2,j]/data[i-l_lato_finestra-1,j]*rapp_geom_left+
                        (-1)^posiz_sul_lato_dal_fondo*data[i-l_lato_finestra+posiz_sul_lato_dal_fondo,lato_sinistro-1]/data[i-l_lato_finestra+posiz_sul_lato_dal_fondo,lato_sinistro]*rapp_geom_up-
                        (-1)^posiz_sul_lato_dal_fondo*data[i-posiz_sul_lato_dal_fondo,j+posiz_sul_lato_dal_fondo]/data[i-posiz_sul_lato_dal_fondo,j+posiz_sul_lato_dal_fondo]*rapp_geom_down)*
                        data[i,j]/rapp_geom_right

                    end
                
                else # data[i,j] ==0
                    if  data[i-1,j] != 0 

                        data[i+1, j] = data[i, j]^2 - data[i, j-1] * data[i, j+1] / data[i-1, j]

                    else  #data[i-1,j] == 0

                        if data[i-2,j] != 0

                            if j-2>0 && j+2 <= width
                                data[i+1, j] = (data[i-1,j-1]^2*data[i-1,j+2]+data[i-1,j+1]^2*data[i-1,j-2]-data[i-3,j]*data[i,j]^2)/data[i-2,j]^2
                            end

                        else #data[i-2,j] == 0

                            if data[i+1,j-1] == 0

                                data[i+1,j] = 0

                            else #data[i+1,j-1] != 0

                                l_lato_finestra = 0
                                posiz_sul_lato_dal_fondo = 1

                                for n in 1:(i-2)
                                    if data[i-n,j] == 0
                                        l_lato_finestra += 1
                                        n += 1
                                    else
                                        break
                                    end
                                end

                                for n in 1:(i-2)
                                    if data[i-1,j+n] == 0
                                        posiz_sul_lato_dal_fondo += 1
                                        n += 1
                                    else
                                        break
                                    end
                                end

                                lato_sinistro = j+posiz_sul_lato_dal_fondo-l_lato_finestra-1

                                rapp_geom_up = data[i-l_lato_finestra,j+1]/data[i-l_lato_finestra,j]
                                rapp_geom_left = data[i-1, lato_sinistro]/data[i-2,lato_sinistro]
                                rapp_geom_right = data[i-2, j + posiz_sul_lato_dal_fondo]/data[i-1, j + posiz_sul_lato_dal_fondo]

                                rapp_geom_down = (-1)^l_lato_finestra * rapp_geom_left * rapp_geom_right / rapp_geom_up

                                data[i+1,j]=data[i+1,j-1]/rapp_geom_down
                            end
                        end                        
                    end
                end
            end
            next!(p)
        end
    end
end


riempi_matrice_2()



color_matrix = [isodd(abs(data[i,j])) ? "rgb(0, 0, 255)" : (iseven(abs(data[i,j])) ? "rgb(255, 0, 0)" : (isnan(data[i,j]) ? "rgb(0,0,0)" : "rgb(255,255,255)")) for i in 1:height, j in 1:width]


heatmap_plotly = PlotlyJS.plot(PlotlyJS.heatmap(
    z = data[1:30,1:60],
    color = color_matrix
))

here the code creates a NxN matrix of Nan. I fill the first 3 rows with desired numbers and then, thanks to the function ‘riempi_matrice_2()’ it should fill the remaining matrix. I should eventually obtain a matrix I can display with plotly…but until now it never happened properly.

Thank you in advance for your help and support.

New contributor

Maxim Tiburziano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật