tokens => words
This commit is contained in:
parent
073728e750
commit
b1a4f2bd3c
38
f.go
38
f.go
|
@ -44,14 +44,14 @@ func main() {
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
input, _ := reader.ReadString('\n')
|
input, _ := reader.ReadString('\n')
|
||||||
input = strings.TrimSpace(input)
|
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"
|
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)
|
fmt.Println(error_msg_start)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
old_low, err1 := strconv.ParseFloat(tokens[0], 64)
|
old_low, err1 := strconv.ParseFloat(words[0], 64)
|
||||||
old_high, err2 := strconv.ParseFloat(tokens[1], 64)
|
old_high, err2 := strconv.ParseFloat(words[1], 64)
|
||||||
if err1 != nil || err2 != nil {
|
if err1 != nil || err2 != nil {
|
||||||
fmt.Println(error_msg_start)
|
fmt.Println(error_msg_start)
|
||||||
return
|
return
|
||||||
|
@ -65,21 +65,21 @@ EventForLoop:
|
||||||
if strings.TrimSpace(input) == "" {
|
if strings.TrimSpace(input) == "" {
|
||||||
continue EventForLoop
|
continue EventForLoop
|
||||||
}
|
}
|
||||||
tokens := strings.Split(strings.TrimSpace(input), " ")
|
words := strings.Split(strings.TrimSpace(input), " ")
|
||||||
|
|
||||||
var new_low, new_high float64
|
var new_low, new_high float64
|
||||||
var err1, err2 error
|
var err1, err2 error
|
||||||
err1, err2 = nil, nil
|
err1, err2 = nil, nil
|
||||||
|
|
||||||
switch tokens[0] {
|
switch words[0] {
|
||||||
case "*":
|
case "*":
|
||||||
switch len(tokens) {
|
switch len(words) {
|
||||||
case 1:
|
case 1:
|
||||||
fmt.Println("Can't multiply by nothing")
|
fmt.Println("Can't multiply by nothing")
|
||||||
fmt.Println(error_msg_cont)
|
fmt.Println(error_msg_cont)
|
||||||
continue EventForLoop
|
continue EventForLoop
|
||||||
case 2:
|
case 2:
|
||||||
single_float, err1 := strconv.ParseFloat(tokens[1], 64)
|
single_float, err1 := strconv.ParseFloat(words[1], 64)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
fmt.Println("Trying to multiply by a scalar, but scalar is not a float")
|
fmt.Println("Trying to multiply by a scalar, but scalar is not a float")
|
||||||
fmt.Println(error_msg_cont)
|
fmt.Println(error_msg_cont)
|
||||||
|
@ -88,8 +88,8 @@ EventForLoop:
|
||||||
new_low = single_float
|
new_low = single_float
|
||||||
new_high = single_float
|
new_high = single_float
|
||||||
case 3:
|
case 3:
|
||||||
new_low, err1 = strconv.ParseFloat(tokens[1], 64)
|
new_low, err1 = strconv.ParseFloat(words[1], 64)
|
||||||
new_high, err2 = strconv.ParseFloat(tokens[2], 64)
|
new_high, err2 = strconv.ParseFloat(words[2], 64)
|
||||||
if err1 != nil || err2 != nil {
|
if err1 != nil || err2 != nil {
|
||||||
fmt.Println(error_msg_cont)
|
fmt.Println(error_msg_cont)
|
||||||
fmt.Println("Trying to multiply by a distribution, but distribution is not specified as two floats")
|
fmt.Println("Trying to multiply by a distribution, but distribution is not specified as two floats")
|
||||||
|
@ -101,13 +101,13 @@ EventForLoop:
|
||||||
continue EventForLoop
|
continue EventForLoop
|
||||||
}
|
}
|
||||||
case "/":
|
case "/":
|
||||||
switch len(tokens) {
|
switch len(words) {
|
||||||
case 1:
|
case 1:
|
||||||
fmt.Println("Can't divide by nothing")
|
fmt.Println("Can't divide by nothing")
|
||||||
fmt.Println(error_msg_cont)
|
fmt.Println(error_msg_cont)
|
||||||
continue EventForLoop
|
continue EventForLoop
|
||||||
case 2:
|
case 2:
|
||||||
single_float, err1 := strconv.ParseFloat(tokens[0], 64)
|
single_float, err1 := strconv.ParseFloat(words[0], 64)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
fmt.Println("Trying to divide by a scalar, but scalar is not a float")
|
fmt.Println("Trying to divide by a scalar, but scalar is not a float")
|
||||||
fmt.Println(error_msg_cont)
|
fmt.Println(error_msg_cont)
|
||||||
|
@ -116,8 +116,8 @@ EventForLoop:
|
||||||
new_low = 1.0 / single_float
|
new_low = 1.0 / single_float
|
||||||
new_high = 1.0 / single_float
|
new_high = 1.0 / single_float
|
||||||
case 3:
|
case 3:
|
||||||
new_low, err1 = strconv.ParseFloat(tokens[1], 64)
|
new_low, err1 = strconv.ParseFloat(words[1], 64)
|
||||||
new_high, err2 = strconv.ParseFloat(tokens[2], 64)
|
new_high, err2 = strconv.ParseFloat(words[2], 64)
|
||||||
if err1 != nil || err2 != nil {
|
if err1 != nil || err2 != nil {
|
||||||
fmt.Println("Trying to divide by a distribution, but distribution is not specified as two floats")
|
fmt.Println("Trying to divide by a distribution, but distribution is not specified as two floats")
|
||||||
fmt.Println(error_msg_cont)
|
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")
|
fmt.Println("Trying to divide by something, but this something is neither a scalar nor a distribution")
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
switch len(tokens) {
|
switch len(words) {
|
||||||
case 0:
|
case 0:
|
||||||
continue EventForLoop
|
continue EventForLoop
|
||||||
case 1:
|
case 1:
|
||||||
switch tokens[0] {
|
switch words[0] {
|
||||||
case "i":
|
case "i":
|
||||||
fmt.Printf("=> %.1f %.1f\n", old_low, old_high)
|
fmt.Printf("=> %.1f %.1f\n", old_low, old_high)
|
||||||
logmean_old, logstd_old := boundsToLogParams(old_low, old_high)
|
logmean_old, logstd_old := boundsToLogParams(old_low, old_high)
|
||||||
|
@ -140,7 +140,7 @@ EventForLoop:
|
||||||
case "e":
|
case "e":
|
||||||
break EventForLoop
|
break EventForLoop
|
||||||
default:
|
default:
|
||||||
single_float, err1 := strconv.ParseFloat(tokens[0], 64)
|
single_float, err1 := strconv.ParseFloat(words[0], 64)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
fmt.Println("Trying to multiply by a scalar, but scalar is not a float")
|
fmt.Println("Trying to multiply by a scalar, but scalar is not a float")
|
||||||
fmt.Println(error_msg_cont)
|
fmt.Println(error_msg_cont)
|
||||||
|
@ -150,8 +150,8 @@ EventForLoop:
|
||||||
new_high = single_float
|
new_high = single_float
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
new_low, err1 = strconv.ParseFloat(tokens[0], 64)
|
new_low, err1 = strconv.ParseFloat(words[0], 64)
|
||||||
new_high, err2 = strconv.ParseFloat(tokens[1], 64)
|
new_high, err2 = strconv.ParseFloat(words[1], 64)
|
||||||
if err1 != nil || err2 != nil {
|
if err1 != nil || err2 != nil {
|
||||||
fmt.Println("Trying to multiply by a distribution, but distribution is not specified as two floats")
|
fmt.Println("Trying to multiply by a distribution, but distribution is not specified as two floats")
|
||||||
fmt.Println(error_msg_cont)
|
fmt.Println(error_msg_cont)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user