Skip to content

Instantly share code, notes, and snippets.

@yuheiomori
Created August 19, 2014 08:30
Show Gist options
  • Save yuheiomori/6fedabe6009cf82d0a22 to your computer and use it in GitHub Desktop.
Save yuheiomori/6fedabe6009cf82d0a22 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
)
func AgeDistribution(age int) (distribution string) {
if age < 0 || age > 100 {
distribution = "This program is for humans"
} else if 0 <= age && age <= 2 {
distribution = "Still in Mama's arms"
} else if 3 <= age && age <= 4 {
distribution = "Preschool Maniac'"
} else if 5 <= age && age <= 11 {
distribution = "Elementary school"
} else if 12 <= age && age <= 14 {
distribution = "Middle school"
} else if 15 <= age && age <= 18 {
distribution = "High school"
} else if 19 <= age && age <= 22 {
distribution = "College"
} else if 23 <= age && age <= 65 {
distribution = "Working for the man"
} else if 66 <= age && age <= 100 {
distribution = "The Golden Years"
}
return distribution
}
func main() {
file, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
//'scanner.Text()' represents the test case, do something with it
var line string = scanner.Text()
age, err := strconv.Atoi(line)
if err != nil {
panic(err)
}
fmt.Println(AgeDistribution(age))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment