函数和分形 – recursion树 –Bash!逻辑问题

函数和分形 – recursion树 –Bash!逻辑问题,第1张

概述函数和分形 – recursion树 – Bash! 逻辑问题

我正在尝试构build一个基于需求的分形树来构build它。 有什么不对 请协助。 我正在尝试基于所请求的级别来构build分形树。 这里的水平正在跳过。 需要了解如何解决这个问题。

#!/bin/bash declare -A matrix for ((i=1;i<=63;i++)) do for ((j=1;j<=100;j++)) do matrix[$i,$j]='_' done done function update_matrix { p1=$1 p2=$(echo $2-1|bc) p1=$(echo $p1-1|bc) p3=$(echo 2^$p2|bc) p4=$(echo 2*$p3|bc) p5=$(echo $p3/2|bc) p6=$3 for ((q1=$p3;q1<$p4;q1++)) do if [ "$(echo $q1-$p3|bc)" -lt "$p5" ] then q2=$(echo $p6-$(echo $p5-$(echo $q1-$p3|bc)|bc)|bc) q3=$(echo $p6+$(echo $p5-$(echo $q1-$p3|bc)|bc)|bc) matrix[$q1,$q2]=1 matrix[$q1,$q3]=1 #printf '%s' "$q1 $q2 -- $q1 $q3" #echo "" else matrix[$q1,$p6]=1 #echo $q1 $p6 fi done if [ $p1 -ge 1 ] then update_matrix $p1 $p2 $(echo $p6+$p5|bc) update_matrix $p1 $p2 $(echo $p6-$p5|bc) else return fi } read iteration if [ $iteration -ge 1 ] then update_matrix $iteration 6 32 fi for ((i=1;i<=63;i++)) do for ((j=1;j<=100;j++)) do printf '%s' "${matrix[$i,$j]}" done echo "" done

输出是:

____________________________________________________________________________________________________ ________________________________________________1_1_________________________________________________ _________________________________________________1__________________________________________________ _________________________________________________1___1______________________________________________ __________________________________________________1_1_______________________________________________ ___________________________________________________1________________________________________________ ___________________________________________________1________________________________________________ ___________________________________________________1_______1________________________________________ ____________________________________________________1_____1_________________________________________ _____________________________________________________1___1__________________________________________ ______________________________________________________1_1___________________________________________ _______________________________________________________1____________________________________________ _______________________________________________________1____________________________________________ _______________________________________________________1____________________________________________ _______________________________________________________1____________________________________________ _______________________________________1_______________1____________________________________________ ________________________________________1_____________1_____________________________________________ _________________________________________1___________1______________________________________________ __________________________________________1_________1_______________________________________________ ___________________________________________1_______1________________________________________________ ____________________________________________1_____1_________________________________________________ _____________________________________________1___1__________________________________________________ ______________________________________________1_1___________________________________________________ _______________________________________________1____________________________________________________ _______________________________________________1____________________________________________________ _______________________________________________1____________________________________________________ _______________________________________________1____________________________________________________ _______________________________________________1____________________________________________________ _______________________________________________1____________________________________________________ _______________________________________________1____________________________________________________ _______________________________________________1____________________________________________________ _______________1_______________________________1____________________________________________________ ________________1_____________________________1_____________________________________________________ _________________1___________________________1______________________________________________________ __________________1_________________________1_______________________________________________________ ___________________1_______________________1________________________________________________________ ____________________1_____________________1_________________________________________________________ _____________________1___________________1__________________________________________________________ ______________________1_________________1___________________________________________________________ _______________________1_______________1____________________________________________________________ ________________________1_____________1_____________________________________________________________ _________________________1___________1______________________________________________________________ __________________________1_________1_______________________________________________________________ ___________________________1_______1________________________________________________________________ ____________________________1_____1_________________________________________________________________ _____________________________1___1__________________________________________________________________ ______________________________1_1___________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________ _______________________________1____________________________________________________________________

需要了解为什么左节点创build正确的一个没有创build。

.bmp文件格式的最大分辨率

感谢堆栈溢出。 这只是一个很好的伴侣。 真的帮助我更好地理解bash。 我所缺少的是将变量声明为本地。 由于哪些全局变量得到更新,因此我的程序工作不正常。 我解决了这个问题,并使用局部变量,它像一个魅力。

解决方案的代码是它的Hackerrank函数和分形 – 递归树 – Bash! 程序。 花了我3小时,以确定它。 真的提神,终于解决了。

#!/bin/bash declare -A matrix for ((i=1;i<=63;i++)) do for ((j=1;j<=100;j++)) do matrix[$i,$j]='_' done done i=0 declare -A arr function update_matrix { local p1 p2 p3 p4 p5 p6 q1 q2 q3 p11 p12 p13 p14 p15 p16 p1=$1 p2=$(echo $2-1|bc) p1=$(echo $p1-1|bc) p3=$(echo 2^$p2|bc) p4=$(echo 2*$p3|bc) p5=$(echo $p3/2|bc) p6=$3 for ((q1=$p3;q1<$p4;q1++)) do if [ "$(echo $q1-$p3|bc)" -lt "$p5" ] then q2=$(echo 18+$p6-$(echo $p5-$(echo $q1-$p3|bc)|bc)|bc) q3=$(echo 18+$p6+$(echo $p5-$(echo $q1-$p3|bc)|bc)|bc) matrix[$q1,$(echo 18+$p6|bc)]=1 #echo $q1 $p6 fi done if [ $p1 -ge 1 ] then p11=$p1 p12=$p2 p13=$(echo $p6-$p5|bc) p14=$(echo $p6+$p5|bc) p15=$p1 p16=$p2 #echo $p11 $p12 $p6 $p5 $p13 update_matrix $p11 $p12 $p13 #echo $p15 $p16 $p6 $p5 $p14 update_matrix $p15 $p16 $p14 t=4 else s=2 fi } read iteration if [ $iteration -ge 1 ] then #echo $iteration 6 32 update_matrix $iteration 6 32 fi for ((i=1;i<=63;i++)) do for ((j=1;j<=100;j++)) do printf '%s' "${matrix[$i,$j]}" done echo "" done

总结

以上是内存溢出为你收集整理的函数和分形 – recursion树 – Bash! 逻辑问题全部内容,希望文章能够帮你解决函数和分形 – recursion树 – Bash! 逻辑问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1273157.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存