Hello,
There seem to be some errors with the the code provided for the Stock Exchange Losses challenge. My understanding was that the structure given in the “blank” IDE should be able to parse the valid inputs for all test cases. However, the provided code of the challenge in F# looks like the following:
(* Auto-generated code below aims at helping you parse *)
(* the standard input according to the problem statement. *)
open System
let n = int(Console.In.ReadLine())
let words = (Console.In.ReadLine()).Split [|' '|]
for i in 0 .. n - 1 do
let v = int(words.[0])
()
(* Write an action using printfn *)
(* To debug: Console.Error.WriteLine("Debug message") *)
printfn "answer"
in the for loop, let v = int(words.[0]) will always return the first value. The correct implementation should be let v = int(words.[i])
The code provided in Go looks like the following
package main
import "fmt"
import "os"
import "bufio"
import "strings"
import "strconv"
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
func main() {
scanner := bufio.NewScanner(os.Stdin)
var n int
scanner.Scan()
fmt.Sscan(scanner.Text(),&n)
scanner.Scan()
inputs := strings.Split(scanner.Text()," ")
for i := 0; i < n; i++ {
v,_ := strconv.ParseInt(inputs[i],10,32)
_ = v
}
// fmt.Fprintln(os.Stderr, "Debug messages...")
fmt.Println("answer")// Write answer to stdout
}
The line causing problems is v,_ := strconv.ParseInt(inputs[i],10,32) . As it is, it works well for all tests but the 5th. The ammount of datas are too big and inputs[i] can not be parsed animore. The test 5, as provided, fails due to:
Errors
panic: runtime error: index out of range
at Answer.go. on line 28
This does not seem expected to me either.
EDIT: I also found an issue in Lua.
The code provided is the following:
n = tonumber(io.read())
next_token = string.gmatch(io.read(), "[^%s]+")
for i=0,n-1 do
v = int next_token()
end
-- Write an action using print()
-- To debug: io.stderr:write("Debug message\n")
print("answer")
v = int next_token() returns a nil. I suppose that an invalid value is not the expected input. I could solve the puzzle by changing it to v = tonumber(next_token())