commit b1a4f2bd3c20c69d5070f0b4fab53fed03d639a6
parent 073728e7500d235860b1b547b73b96493d51c49e
Author: NunoSempere <nuno.semperelh@protonmail.com>
Date: Sat, 11 May 2024 11:08:24 +0100
tokens => words
Diffstat:
| M | f.go | | | 38 | +++++++++++++++++++------------------- |
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/f.go b/f.go
@@ -44,14 +44,14 @@ func main() {
reader := bufio.NewReader(os.Stdin)
input, _ := reader.ReadString('\n')
input = strings.TrimSpace(input)
- tokens := strings.Split(input, " ")
+ words := strings.Split(input, " ")
error_msg_start := "Please enter two floats separated by a space, like: 1 10"
- if len(tokens) != 2 {
+ if len(words) != 2 {
fmt.Println(error_msg_start)
return
}
- old_low, err1 := strconv.ParseFloat(tokens[0], 64)
- old_high, err2 := strconv.ParseFloat(tokens[1], 64)
+ 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
@@ -65,21 +65,21 @@ EventForLoop:
if strings.TrimSpace(input) == "" {
continue EventForLoop
}
- tokens := strings.Split(strings.TrimSpace(input), " ")
+ words := strings.Split(strings.TrimSpace(input), " ")
var new_low, new_high float64
var err1, err2 error
err1, err2 = nil, nil
- switch tokens[0] {
+ switch words[0] {
case "*":
- switch len(tokens) {
+ switch len(words) {
case 1:
fmt.Println("Can't multiply by nothing")
fmt.Println(error_msg_cont)
continue EventForLoop
case 2:
- single_float, err1 := strconv.ParseFloat(tokens[1], 64)
+ single_float, err1 := strconv.ParseFloat(words[1], 64)
if err1 != nil {
fmt.Println("Trying to multiply by a scalar, but scalar is not a float")
fmt.Println(error_msg_cont)
@@ -88,8 +88,8 @@ EventForLoop:
new_low = single_float
new_high = single_float
case 3:
- new_low, err1 = strconv.ParseFloat(tokens[1], 64)
- new_high, err2 = strconv.ParseFloat(tokens[2], 64)
+ new_low, err1 = strconv.ParseFloat(words[1], 64)
+ new_high, err2 = strconv.ParseFloat(words[2], 64)
if err1 != nil || err2 != nil {
fmt.Println(error_msg_cont)
fmt.Println("Trying to multiply by a distribution, but distribution is not specified as two floats")
@@ -101,13 +101,13 @@ EventForLoop:
continue EventForLoop
}
case "/":
- switch len(tokens) {
+ switch len(words) {
case 1:
fmt.Println("Can't divide by nothing")
fmt.Println(error_msg_cont)
continue EventForLoop
case 2:
- single_float, err1 := strconv.ParseFloat(tokens[0], 64)
+ single_float, err1 := strconv.ParseFloat(words[0], 64)
if err1 != nil {
fmt.Println("Trying to divide by a scalar, but scalar is not a float")
fmt.Println(error_msg_cont)
@@ -116,8 +116,8 @@ EventForLoop:
new_low = 1.0 / single_float
new_high = 1.0 / single_float
case 3:
- new_low, err1 = strconv.ParseFloat(tokens[1], 64)
- new_high, err2 = strconv.ParseFloat(tokens[2], 64)
+ new_low, err1 = strconv.ParseFloat(words[1], 64)
+ new_high, err2 = strconv.ParseFloat(words[2], 64)
if err1 != nil || err2 != nil {
fmt.Println("Trying to divide by a distribution, but distribution is not specified as two floats")
fmt.Println(error_msg_cont)
@@ -127,11 +127,11 @@ EventForLoop:
fmt.Println("Trying to divide by something, but this something is neither a scalar nor a distribution")
}
default:
- switch len(tokens) {
+ switch len(words) {
case 0:
continue EventForLoop
case 1:
- switch tokens[0] {
+ switch words[0] {
case "i":
fmt.Printf("=> %.1f %.1f\n", old_low, old_high)
logmean_old, logstd_old := boundsToLogParams(old_low, old_high)
@@ -140,7 +140,7 @@ EventForLoop:
case "e":
break EventForLoop
default:
- single_float, err1 := strconv.ParseFloat(tokens[0], 64)
+ single_float, err1 := strconv.ParseFloat(words[0], 64)
if err1 != nil {
fmt.Println("Trying to multiply by a scalar, but scalar is not a float")
fmt.Println(error_msg_cont)
@@ -150,8 +150,8 @@ EventForLoop:
new_high = single_float
}
case 2:
- new_low, err1 = strconv.ParseFloat(tokens[0], 64)
- new_high, err2 = strconv.ParseFloat(tokens[1], 64)
+ new_low, err1 = strconv.ParseFloat(words[0], 64)
+ new_high, err2 = strconv.ParseFloat(words[1], 64)
if err1 != nil || err2 != nil {
fmt.Println("Trying to multiply by a distribution, but distribution is not specified as two floats")
fmt.Println(error_msg_cont)