1. Is this a bug or expected behavior?

I decided to try doing the Advent of Code programming problems this year.

The first problem was pretty easy -- find 2 numbers from the list given that add up to 2020 and return the product of the 2 numbers. No problem. Then the second part of the first problem was find 3 numbers that add up to 2020 and give the product of those 3 numbers.

Due to a logic error in my program it just ended with no output. I put a

with trace 
trace(1) 

in to see if that would help me find my logic error.

eui advent0102.ex <input.txt  

the trace screen opened with the line after the trace highlighted.

None of the command keys seem to work

I hit CTRL c and got

Press Enter... 

Then I had to go to the Task Manager, select the Euphoria Interpreter (which was taking up about 60% of the processor) and do an End Task.

Then I got the lines below which showed that I hit the enter key, '1' key twice, enter 3 more times and then tried inputting numbers 123 and 456

C:\Users\Lonny\Programming\AdventofCode2020> 
C:\Users\Lonny\Programming\AdventofCode2020>11 
'11' is not recognized as an internal or external command, 
operable program or batch file. 
 
C:\Users\Lonny\Programming\AdventofCode2020> 
C:\Users\Lonny\Programming\AdventofCode2020> 
C:\Users\Lonny\Programming\AdventofCode2020> 
C:\Users\Lonny\Programming\AdventofCode2020>123 
'123' is not recognized as an internal or external command, 
operable program or batch file. 
 
C:\Users\Lonny\Programming\AdventofCode2020>456 
'456' is not recognized as an internal or external command, 
operable program or batch file. 

Here's some code that will show the bug:

file input.txt

12 
34 
56 
78 
90 
These are NOT the actual input I was using.

run the program with eui test.ex <input.txt

--test.ex 
include std/io.e 
include std/get.e 
 
sequence numbers = {} 
object line 
atom one_num 
with trace 
trace(1) 
while 1 do 
    line = get(STDIN) 
    if line[1] = GET_EOF then 
        exit 
    end if 
    one_num = line[2] 
    numbers &= one_num 
end while 

If I use the STDIN and type the numbers in on the main window of the trace it works correctly. So the question is "Is this a bug in the interpreter or the command shell?"

Lonny

new topic     » topic index » view message » categorize

2. Re: Is this a bug or expected behavior?

Hi Lonny, your program is fine, no output is the expected behaviour. STDIN is the console, and you are re-directing the input from the file instead of the console.

Add ?numbers after the end while to see that the sequence has indeed filled up with numbers. Turn off trace as well, just gets in the way here.

Cheers

Chris

new topic     » goto parent     » topic index » view message » categorize

3. Re: Is this a bug or expected behavior?

Hi Chris,

Did you actually try to run the program? It does not work (at least on my machine) with the trace line active and the input being redirected from a file. That made it hard to debug. I had to open the file and then read it. If I did my input from the console it worked correctly with no problems.

Lonny

PS: yes I forgot the ?numbers at the end but I was just looking to see the values in the trace window.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Is this a bug or expected behavior?

Hi Lonny

Sometimes it's a case of your program not meeting your expectations. I don't like trace, as generally it gets in the way.

Try this

--test.ex  
include std/io.e  
include std/get.e  
  
sequence numbers = {}  
object line  
atom one_num  
--with trace  
--trace(1)  
while 1 do  
    line = get(STDIN)  
    if line[1] = GET_EOF then  
        exit  
    end if  
 
    ?line   --shows each line as it comes in, whether from console or redirected STDIN 
 
    one_num = line[2]  
    numbers &= one_num  
end while 
?numbers 
 
--remember ctr-Z sends EOF from console 
 

What are you defined expectations of output here?

Cheers

Chris

new topic     » goto parent     » topic index » view message » categorize

5. Re: Is this a bug or expected behavior?

Actually, that kinda is what I would expect...

You are trying to redirect input AND debug using the console...

So, the application cannot read input.txt because the trace window is in the way.

And the trace window cannot get anything from the keyboard because it's been redirected.

I get the same behaviour on Phix. Afaict the 60% cpu is occuring somewhere deep inside windows itself, and the only way to fix that would probably be to install windows 98 or earlier...

As Chris just suggested, should you redirect input, you must also wave bye bye to the trace screen.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Is this a bug or expected behavior?

There is only one STDIN, which by default comes from the keyboard. You can redirect it to accept input from a file. Changing the I/O devices is done by the OS prior to running your program.

But trace() can't work without keyboard input, so it grabs STDIN back, and keeps it.

So it's not a program bug, or a Euphoria bug. It's what should be expected.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu