Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,18 @@
|
|||
(define (bump-value)
|
||||
(when (> value 1)
|
||||
(set! count (1+ count))
|
||||
(set! value (if (even? value) (/ value 2) (1+ (* 3 value))))))
|
||||
|
||||
(define (env-show name envs )
|
||||
(write name)
|
||||
(for ((env envs)) (write (format "%4a" (eval name env))))
|
||||
(writeln))
|
||||
|
||||
(define (task (envnum 12))
|
||||
(define envs (for/list ((i envnum)) (environment-new `((value ,(1+ i)) (count 0)))))
|
||||
(env-show 'value envs)
|
||||
(while
|
||||
(any (curry (lambda ( n env) (!= 1 (eval n env))) 'value) envs)
|
||||
(for/list ((env envs)) (eval '(bump-value) env))
|
||||
(env-show 'value envs))
|
||||
(env-show 'count envs))
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
func calculator({.is_one} ) { 1 }
|
||||
func calculator(n {.is_even}) { n / 2 }
|
||||
func calculator(n ) { 3*n + 1 }
|
||||
|
||||
func succ(this {_{:value}.is_one}, _) {
|
||||
return this
|
||||
}
|
||||
|
||||
func succ(this, get_next) {
|
||||
this{:value} = get_next(this{:value})
|
||||
this{:count}++
|
||||
return this
|
||||
}
|
||||
|
||||
var enviornments = (1..12 -> map {|i| Hash(value => i, count => 0) });
|
||||
|
||||
while (!enviornments.map{ _{:value} }.all { .is_one }) {
|
||||
say enviornments.map {|h| "%4s" % h{:value} }.join;
|
||||
enviornments.range.each { |i|
|
||||
enviornments[i] = succ(enviornments[i], calculator);
|
||||
}
|
||||
}
|
||||
|
||||
say 'Counts';
|
||||
say enviornments.map{ |h| "%4s" % h{:count} }.join;
|
||||
Loading…
Add table
Add a link
Reference in a new issue