Solution:
How to compile a TCL script into an EXE program
#Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: #1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... #By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. proc problem2 {} { set term 2 set term-1 1 set sum 0 while {$term <= 4000000} { if {($term % 2) == 0} { incr sum $term } set tmp ${term-1} set term-1 $term set term [expr $term + $tmp] } return $sum } # solution-2: 4613732
# If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. # Find the sum of all the multiples of 3 or 5 below 1000. proc Problem1 {} { set items {} for {set idx 3} {$idx<1000} {incr idx 3} { lappend items $idx } for {set idx 5} {$idx<1000} {incr idx 5} { if { [lsearch $items $idx] < 0 } { lappend items $idx } } set rval 0 foreach item $items { set rval [expr $rval + $item] }
return $rval } # solution: 233168
# Generated using http://pygments.org/
source unit-under-test.tcl ;# contains the definition of bits_serealize test base--always-ok {This is as simple as it gets.} -constraints { } -setup { } -body { return TRUE } -cleanup { } -result TRUE test bits_serealize--partial-quanta {description here...} -constraints { } -setup { } -body { return [bits_serealize 32 " 0x01 16 "] } -cleanup { } -result [list 1] test bits_serealize--full-quanta {description here...} -constraints { } -setup { } -body { return [bits_serealize 32 " 0xFFFFFFFF 32 "] } -cleanup { } -result [list [ format "%u" 0xFFFFFFFF ]] test bits_serealize--over-quanta {description here...} -constraints { } -setup { } -body { return [bits_serealize 32 " 0x060504030201 64 "] } -cleanup { } -result [list [ format "%u" 0x04030201 ] [ format "%u" 0x0605 ]] test bits_serealize--way-over-quanta {description here...} -constraints { } -setup { } -body { return [bits_serealize 32 " 0x060504030201 320 "] } -cleanup { } -result [list [ format "%u" 0x04030201 ] [ format "%u" 0x0605 ] 0 0 0 0 0 0 0 0] test bits_serealize--cross-quanta {description here...} -constraints { } -setup { } -body { return [bits_serealize 32 " 0xFF 1 0xFF 2 0xFF 3 0xFF 4 0xFF 6 0x04030201 32 "] } -cleanup { } -result [list [ format "%u" 0x201FFFF ] [ format "%u" 0x403 ]] test bits_serealize--quanta-and-half {description here...} -constraints { } -setup { } -body { return [bits_serealize 32 " 0xFFEEDDCCBBAA 48 "] } -cleanup { } -result [list [ format "%u" 0xDDCCBBAA ] [ format "%u" 0xFFEE ]]
![]() |
eclipse-unit-testing |