commit 4204db0c322c8855254bc494279421ac2d34ec96
parent b1a4f2bd3c20c69d5070f0b4fab53fed03d639a6
Author: NunoSempere <nuno.semperelh@protonmail.com>
Date: Sat, 11 May 2024 12:22:07 +0100
propagate scalar ops, tweaks
Diffstat:
6 files changed, 34 insertions(+), 28 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -1,2 +0,0 @@
-1 10
-2 20
diff --git 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
@@ -4,4 +4,4 @@
/ 48 52
/ 5 6
/ 6 8
-/ 60 60
+/ 60