diff --git a/README.md b/README.md index 8783a7a..25879b5 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ $ go run f.go => 2573.1 33632.0 / 6 8 => 368.4 4893.5 -/ 60 60 +/ 60 => 6.1 81.6 ``` @@ -44,7 +44,7 @@ $ sed -u "s|#.*||" | sed -u 's|M|000000|g' | go run f.go => 2573.1 33632.0 / 6 8 # hours a day in which piano tuners work => 368.4 4893.5 -/ 60 60 # minutes to an hour +/ 60 # minutes to an hour => 6.1 81.6 # ^ piano tuners in Chicago ``` diff --git a/f.go b/f.go index d0f81db..6408252 100644 --- a/f.go +++ b/f.go @@ -42,19 +42,26 @@ func combineBounds(old_low, old_high, new_low, new_high float64) (float64, float func main() { reader := bufio.NewReader(os.Stdin) - input, _ := reader.ReadString('\n') - input = strings.TrimSpace(input) - words := strings.Split(input, " ") - error_msg_start := "Please enter two floats separated by a space, like: 1 10" - if len(words) != 2 { - fmt.Println(error_msg_start) - return - } - old_low, err1 := strconv.ParseFloat(words[0], 64) - old_high, err2 := strconv.ParseFloat(words[1], 64) - if err1 != nil || err2 != nil { - fmt.Println(error_msg_start) - return + + var old_low, old_high float64 + var input string + var err1, err2 error + for { + input, _ = reader.ReadString('\n') + input = strings.TrimSpace(input) + words := strings.Split(input, " ") + if len(words) != 2 { + fmt.Println("Please enter two floats separated by a space, like: 1 10") + continue + } + old_low, err1 = strconv.ParseFloat(words[0], 64) + old_high, err2 = strconv.ParseFloat(words[1], 64) + if err1 != nil || err2 != nil { + fmt.Println("Please enter two floats separated by a space, like: 1 10") + continue + } + break + } fmt.Printf("=> %.1f %.1f\n", old_low, old_high) @@ -68,8 +75,6 @@ EventForLoop: words := strings.Split(strings.TrimSpace(input), " ") var new_low, new_high float64 - var err1, err2 error - err1, err2 = nil, nil switch words[0] { case "*": @@ -107,7 +112,7 @@ EventForLoop: fmt.Println(error_msg_cont) continue EventForLoop case 2: - single_float, err1 := strconv.ParseFloat(words[0], 64) + single_float, err1 := strconv.ParseFloat(words[1], 64) if err1 != nil { fmt.Println("Trying to divide by a scalar, but scalar is not a float") fmt.Println(error_msg_cont) diff --git a/more/f.sh b/more/f.sh index f581adb..ddd5ccb 100755 --- a/more/f.sh +++ b/more/f.sh @@ -1,9 +1,12 @@ #!/bin/bash -#while IFS= read -r line; do echo "$line" | sed 's| //.*||' | go run main.go -# while IFS= read -r line; do echo "$line" | sed 's|//.*||'; done | go run main.go +function f(){ + sed -u "s|#.*||" | + sed -u "s|//.*||" | + sed -u 's|K|000|g' | + sed -u 's|M|000000|g' | + sed -u 's|B|000000000|g' | + /usr/bin/f +} - -sed -u 's|//.*||' | go run main.go -# ^ sed unbuffered. -# cat | tee -a log.f | sed -u 's|//.*||' | go run main.go | tee -a log.f +# f diff --git a/more/model.f b/more/model.f deleted file mode 100644 index cdc8a99..0000000 --- a/more/model.f +++ /dev/null @@ -1,2 +0,0 @@ -1 10 -2 20 diff --git a/more/piano-tuners-commented.f b/more/piano-tuners-commented.f index 9648998..9590255 100644 --- a/more/piano-tuners-commented.f +++ b/more/piano-tuners-commented.f @@ -4,6 +4,6 @@ / 48 52 # weeks a year that piano tuners work for / 5 6 # days a week in which piano tuners work / 6 8 # hours a day in which piano tuners work -/ 60 60 # minutes to an hour +/ 60 # minutes to an hour # ^ piano tuners in Chicago diff --git a/more/piano-tuners.f b/more/piano-tuners.f index e407de2..6897ede 100644 --- a/more/piano-tuners.f +++ b/more/piano-tuners.f @@ -4,4 +4,4 @@ / 48 52 / 5 6 / 6 8 -/ 60 60 +/ 60