2019年12月31日火曜日

開発環境

入門Goプログラミング (Nathan Youngman(著)、Roger Peppé(著)、吉川 邦夫(監修, 翻訳)、翔泳社)のUNIT 1(型)、LESSON 6(変数)の練習問題の解答を求めてみる。

コード

package main

import (
 "fmt"
 "math/rand"
 "time"
)

func main() {
 piggy := 0.0
 rand.Seed(time.Now().UnixNano())
 i := 0
 for piggy < 20.0 {
  switch rand.Intn(3) {
  case 0:
   piggy += 0.05
  case 1:
   piggy += 0.10
  case 2:
   piggy += 0.25
  }
  fmt.Printf("$%.2f\n", piggy)
  i++
 }
 fmt.Printf("%v日\n", i)
}

入出力結果(Zsh、PowerShell、Terminal)

% go run piggy.go
$0.10
$0.20
$0.25
$0.35
$0.45
$0.70
$0.80
$1.05
$1.15
$1.25
$1.50
$1.55
$1.80
$1.85
$1.90
$1.95
$2.05
$2.15
$2.25
$2.30
$2.40
$2.65
$2.70
$2.80
$2.90
$2.95
$3.00
$3.25
$3.30
$3.55
$3.80
$4.05
$4.30
$4.40
$4.65
$4.75
$5.00
$5.10
$5.20
$5.25
$5.50
$5.55
$5.60
$5.70
$5.75
$5.85
$5.95
$6.00
$6.25
$6.50
$6.55
$6.65
$6.70
$6.80
$6.90
$7.15
$7.25
$7.50
$7.55
$7.80
$8.05
$8.15
$8.20
$8.30
$8.40
$8.65
$8.70
$8.75
$8.80
$8.85
$8.95
$9.00
$9.05
$9.30
$9.35
$9.60
$9.85
$9.95
$10.05
$10.30
$10.35
$10.45
$10.50
$10.60
$10.85
$10.90
$11.15
$11.25
$11.30
$11.40
$11.50
$11.60
$11.70
$11.75
$11.80
$11.90
$12.00
$12.05
$12.10
$12.35
$12.60
$12.85
$12.90
$13.00
$13.10
$13.15
$13.40
$13.65
$13.90
$14.15
$14.20
$14.45
$14.70
$14.75
$15.00
$15.05
$15.30
$15.35
$15.60
$15.65
$15.70
$15.95
$16.00
$16.05
$16.15
$16.40
$16.45
$16.70
$16.95
$17.00
$17.10
$17.20
$17.30
$17.35
$17.45
$17.70
$17.75
$17.80
$17.90
$17.95
$18.20
$18.30
$18.55
$18.60
$18.70
$18.80
$18.85
$18.95
$19.00
$19.10
$19.20
$19.25
$19.35
$19.45
$19.70
$19.75
$20.00
157日
% go run piggy.go
$0.10
$0.35
$0.60
$0.85
$0.95
$1.20
$1.25
$1.50
$1.55
$1.60
$1.85
$1.90
$2.15
$2.40
$2.65
$2.75
$3.00
$3.05
$3.30
$3.35
$3.40
$3.50
$3.55
$3.65
$3.70
$3.95
$4.20
$4.30
$4.55
$4.80
$4.90
$4.95
$5.00
$5.10
$5.35
$5.60
$5.65
$5.90
$6.00
$6.10
$6.20
$6.25
$6.50
$6.60
$6.85
$7.10
$7.15
$7.40
$7.45
$7.55
$7.60
$7.70
$7.75
$8.00
$8.05
$8.10
$8.15
$8.40
$8.50
$8.60
$8.65
$8.90
$8.95
$9.20
$9.25
$9.50
$9.75
$9.80
$9.85
$10.10
$10.20
$10.45
$10.55
$10.60
$10.70
$10.80
$10.90
$10.95
$11.20
$11.30
$11.35
$11.40
$11.45
$11.70
$11.95
$12.00
$12.05
$12.30
$12.40
$12.65
$12.75
$13.00
$13.25
$13.35
$13.45
$13.70
$13.95
$14.05
$14.15
$14.25
$14.30
$14.55
$14.65
$14.75
$14.85
$14.90
$15.15
$15.40
$15.50
$15.55
$15.60
$15.65
$15.75
$16.00
$16.10
$16.15
$16.20
$16.45
$16.55
$16.65
$16.70
$16.95
$17.05
$17.15
$17.20
$17.30
$17.40
$17.50
$17.75
$17.80
$17.85
$18.10
$18.15
$18.40
$18.65
$18.90
$19.00
$19.25
$19.30
$19.55
$19.80
$19.90
$19.95
$20.00
144日
%

0 コメント:

コメントを投稿