LoginSignup
3
3

More than 5 years have passed since last update.

ズンドコキヨシ with Tcl

Last updated at Posted at 2016-03-12

Tclの勉強

参考 http://pyomeha.blog42.fc2.com/blog-entry-6.html
参考 http://bitwalk.sitemix.jp/tcltk_intro_tcl_control.php
参考 http://wiki.tcl.tk/1549

実装内容

2進数で0b11110となった時にキヨシる。

文字
0 ドコ
1 ズン

ドコとズンを反対にしていると1つ目でキヨシる場合がある(0b00001)ので、こうした。

無限ループはideoneに迷惑なので上限100回とした。

chainという文字列変数はコードの残骸であるが、これはこれで後の参照時に有効かもしれないので残している。

code v0.1

proc random_get {} {
  return [expr int(rand()*2)]
}

proc is_zundoko { val } {
  set chk [expr ($val % 32)]
  if {$chk == 30} { # 0b11110 
    return 1
  } else {
    return 0
  }
}

set array(0) "ドコ"
set array(1) "ズン"

set idx 0

set chain ""
set val 0
while {$idx < 100} {
  set rnd [random_get]
  append chain $rnd
  set val [expr ($val*2)]
  if { $rnd == 0 } {
    puts $array(0)
    # no increment
  } else {
    puts $array(1)
    incr val 1
  }
  set judge [is_zundoko $val]
  if { $judge == 1 } {
    puts "キヨシ!"
    break;
  }
  incr idx 1
  set val [expr $val % 32]
}

#puts $val
#puts [expr $val % 32]
結果
Success time: 0 memory: 15768 signal:0
ドコ
ドコ
ドコ
ドコ
ドコ
ドコ
ドコ
ドコ
ズン
ドコ
ズン
ドコ
ドコ
ドコ
ドコ
ズン
ドコ
ドコ
ズン
ドコ
ドコ
ズン
ドコ
ズン
ドコ
ズン
ズン
ズン
ズン
ドコ
キヨシ!

今回の勉強が近いうちに Vivado で発揮されるはず。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3