blob: 01e14fdef8a1dc5f2a61ee26c5f429687d49dec8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package main
//
// See https://theweeklychallenge.org/blog/perl-weekly-challenge-123
//
//
// Run as: go run ch-1.go < input-file
//
import (
"fmt"
)
func main () {
var max int
for {
n, err := fmt . Scanf ("%d", &max)
if (n != 1 || err != nil) {
break
}
ugly := make ([] int, max)
ugly [0] = 1
count := 0
next_2 := 0
next_3 := 0
next_5 := 0
min := 0
for count < max - 1 {
count ++
c2 := 2 * ugly [next_2]
c3 := 3 * ugly [next_3]
c5 := 5 * ugly [next_5]
if c2 <= c3 && c2 <= c5 {min = c2}
if c3 <= c2 && c3 <= c5 {min = c3}
if c5 <= c2 && c5 <= c3 {min = c5}
ugly [count] = min
if (c2 <= ugly [count]) {next_2 ++}
if (c3 <= ugly [count]) {next_3 ++}
if (c5 <= ugly [count]) {next_5 ++}
}
fmt . Println (ugly [count])
}
}
|