This code is supposed to create a list filled with random numbers (except for 0), and instead of repeating numbers, insert "". But the value of $ k == $ valume is always False ... How to make it so that the repetition would be True.
.................................................. .................................................. .................................................. ....
Yes, thanks, but the fact is that if the value of the set order {"VALUE"} is an infinite loop, and when the set order {} -> "order = 'empty'" ............. .................................................. .................................................. ......................................... The ldelete command in the body of foreach seems to be " eliminate "all". " Why this does not happen (only one is removed ""), and how to fix it. .................................................. .................................................. .................................................. ........ This is clear to me, but ldelete works in a loop, so why doesn’t it delete everything ""! .................................................. .................................................. .................................................. ........ Thank you very much for the set order [ldelete $ order ""] (the ldelete command was taken from the book by Brent Welch, 4th ed.), As well as for the rest of the help - now the code works correctly! But do not relax, the final number of numbers <A - I feel, recursion will be needed !! .................................................. .................................................. .................................................. .... The command! Spisok is executed 2 times - i.e. there is no recursion! Why? And how to fix it (can the Tcl version number I use relate to this) Or is it better to use a cycle. (I want the number of numbers in the final list = a) ..................................... .................................................. .................................................. .................! Spisok $ t $ order - inattention in half with inexperience. It remains to do so in the resulting list there is no repetition! .................................................. .................................................. .................................................. ............. I myself answered the question that I asked in the text of the program, but I do not know how to fix this error, so I just need the code!
proc Vvod {a} { global t puts stdout { Vvedite a:} set a [gets stdin] set t [format "%d" $a] } proc Ldelete {list value} { set ix [lsearch -exact $list $value] if {$ix >= 0} { return [lreplace $list $ix $ix] } else { return $list } } proc Bez_X {order} { foreach valume $order { set m [lsearch -all $order $valume] set y [lrange $m 1 end] foreach val $y { lset order $val X } set order [Ldelete $order X] } return $order } proc Spisok {t} { for {set i 1} {$i <= $t } {incr i} { set j [expr {round(rand()*$t)}] if {$j == 0} { set k [expr {$j + 1}] } else { set k $j } lappend order $k } puts stdout "order = $order" set order [Bez_X $order] puts stdout "order1 = $order" return $order } proc !Spisok {order t} { set dlina [llength $order] if {$dlina < $t} { set order1 [Spisok [expr $t - $dlina]] set order [concat $order $order1] puts stdout "order2 = $order" # ---------------------------------------------------------------------- set order [Bez_X $order ] #Почему при присутствии этой команды Bez_X получается бесконечный цикл? # ---------------------------------------------------------------------- puts stdout "order3 = $order" !Spisok $order $t } else { return $order } } while 1 { Vvod a set order [Spisok $t] set x [!Spisok $order $t] puts stdout "x = $x" }