// runWithDefaultInteractor executes the problem solution with the default interactor.
runWithDefaultInteractor executes the problem solution with the default interactor.
// runWithDefaultInteractor executes the problem solution with the default interactor .
func (e *Executor) runWithDefaultInteractor(testCase *testCaseFiles) error {
	var err error
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	solution := e.SolutionProgramService.GetExecutionCommand(ctx, e.filePathSolutionSource, e.filePathSolutionBinary)
	solution, err = e.SolutionCage.Encage(solution)
	if err != nil {
		return fmt.Errorf("error encaging solution command: %w", err)
	}
	input, err := e.FileService.OpenFile(testCase.input)
	if err != nil {
		return fmt.Errorf("error opening input file for test case execution: %w", err)
	}
	defer input.Close()
	output, err := e.FileService.CreateFile(testCase.output)
	if err != nil {
		return fmt.Errorf("error creating output file for test case execution: %w", err)
	}
	defer output.Close()
	solutionInput, err := solution.StdinPipe()
	if err != nil {
		return fmt.Errorf("error creating pipe for solution input: %w", err)
	}
	defer solutionInput.Close()
	solutionOutput, err := solution.StdoutPipe()
	if err != nil {
		return fmt.Errorf("error creating pipe for solution output: %w", err)
	}
	defer solutionOutput.Close()
	if err := solution.Start(); err != nil {
		return fmt.Errorf("error starting problem solution process: %w", err)
	}
	defer func() { _ = solution.Wait() }()
	inputScanner := bufio.NewScanner(input)
	outputScanner := bufio.NewScanner(solutionOutput)
	for inputScanner.Scan() {
		var linesToFeed uint
		if _, err := fmt.Sscanf(inputScanner.Text(), "%d", &linesToFeed); err != nil {
			return fmt.Errorf("error scanning lines to feed for interactive input: %w", err)
		}
		for i := uint(0); i < linesToFeed; i++ {
			if !inputScanner.Scan() {
				return fmt.Errorf("error reading line from test case input: %w", err)
			}
			line := inputScanner.Text() + "\n"
			if _, err := solutionInput.Write([]byte(line)); err != nil {
				return fmt.Errorf("error writing line to solution process stdin: %w", err)
			}
		}
		var linesToCollect uint
		if !outputScanner.Scan() {
			return fmt.Errorf("problem solution stopped responding interactor: %w", err)
		}
		if _, err := fmt.Sscanf(outputScanner.Text(), "%d", &linesToCollect); err != nil {
			return fmt.Errorf("error scanning lines to collect for interactive output: %w", err)
		}
		for i := uint(0); i < linesToCollect; i++ {
			if !outputScanner.Scan() {
				return fmt.Errorf("problem solution stopped responding interactor: %w", err)
			}
			line := outputScanner.Text() + "\n"
			if _, err := output.Write([]byte(line)); err != nil {
				return fmt.Errorf("error writing problem solution output: %w", err)
			}
		}
	}
	solutionInput.Close() 
	return nil
}
func ( e * Executor ) runWithDefaultInteractor ( testCase * testCaseFiles ) error { var err error ctx , cancel := context . WithCancel ( context . Background ( ) ) defer cancel ( ) solution := e . SolutionProgramService . GetExecutionCommand ( ctx , e . filePathSolutionSource , e . filePathSolutionBinary ) solution , err = e . SolutionCage . Encage ( solution ) if err != nil { return fmt . Errorf ( " " , err ) } input , err := e . FileService . OpenFile ( testCase . input ) if err != nil { return fmt . Errorf ( " " , err ) } defer input . Close ( ) output , err := e . FileService . CreateFile ( testCase . output ) if err != nil { return fmt . Errorf ( " " , err ) } defer output . Close ( ) solutionInput , err := solution . StdinPipe ( ) if err != nil { return fmt . Errorf ( " " , err ) } defer solutionInput . Close ( ) solutionOutput , err := solution . StdoutPipe ( ) if err != nil { return fmt . Errorf ( " " , err ) } defer solutionOutput . Close ( ) if err := solution . Start ( ) ; err != nil { return fmt . Errorf ( " " , err ) } defer func ( ) { _ = solution . Wait ( ) } ( ) inputScanner := bufio . NewScanner ( input ) outputScanner := bufio . NewScanner ( solutionOutput ) for inputScanner . Scan ( ) { var linesToFeed uint if _ , err := fmt . Sscanf ( inputScanner . Text ( ) , " " , & linesToFeed ) ; err != nil { return fmt . Errorf ( " " , err ) } for i := uint ( 0 ) ; i < linesToFeed ; i ++ { if ! inputScanner . Scan ( ) { return fmt . Errorf ( " " , err ) } line := inputScanner . Text ( ) + " \n " if _ , err := solutionInput . Write ( [ ] byte ( line ) ) ; err != nil { return fmt . Errorf ( " " , err ) } } var linesToCollect uint if ! outputScanner . Scan ( ) { return fmt . Errorf ( " " , err ) } if _ , err := fmt . Sscanf ( outputScanner . Text ( ) , " " , & linesToCollect ) ; err != nil { return fmt . Errorf ( " " , err ) } for i := uint ( 0 ) ; i < linesToCollect ; i ++ { if ! outputScanner . Scan ( ) { return fmt . Errorf ( " " , err ) } line := outputScanner . Text ( ) + " \n " if _ , err := output . Write ( [ ] byte ( line ) ) ; err != nil { return fmt . Errorf ( " " , err ) } } } solutionInput . Close ( ) return nil }
runWithDefaultInteractor executes the problem solution with the default interactor.
runWithDefaultInteractor executes the problem solution with the default interactor .
// tells solution process to exit