File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,23 @@ func inputEquation(order *int, args []int) string {
22
22
return buffer .String ()
23
23
}
24
24
25
+ func outputEquation (args []int ) string {
26
+ var buffer strings.Builder
27
+ var d int
28
+ order := len (args ) - 1
29
+ for i := order ; i > 0 ; i -- {
30
+ d = args [len (args )- 1 - i ] * i
31
+ if i > 2 {
32
+ buffer .WriteString (fmt .Sprintf ("%dx^%d + " , d , order - 1 ))
33
+ } else if i == 2 {
34
+ buffer .WriteString (fmt .Sprintf ("%dx + " , d ))
35
+ } else {
36
+ buffer .WriteString (fmt .Sprintf ("%d " , d ))
37
+ }
38
+ }
39
+ return buffer .String ()
40
+ }
41
+
25
42
func main () {
26
43
order := flag .Int ("order" , - 1 , "The order of the equation to be derived" )
27
44
flag .Parse ()
@@ -41,6 +58,8 @@ func main() {
41
58
}
42
59
}
43
60
44
- input := inputEquation (order , intArgs )
45
- fmt .Println (input )
61
+ fmt .Println (inputEquation (order , intArgs ))
62
+ fmt .Println ("Deriving..." )
63
+ fmt .Println (outputEquation (intArgs ))
64
+
46
65
}
You can’t perform that action at this time.
0 commit comments