Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BQN launch discards whitespace from input #27

Open
paul7 opened this issue Dec 6, 2022 · 3 comments
Open

BQN launch discards whitespace from input #27

paul7 opened this issue Dec 6, 2022 · 3 comments

Comments

@paul7
Copy link

paul7 commented Dec 6, 2022

Currently, BQN expects its input from command line arguments. However, using cat ... sends it through the shell's parser which tokenizes it using whitespace. Therefore all whitespace characters from input are lost.

https://github.com/aderepas/WeekGolf/blob/c95f32bb299d8d2d6b915ff2cecbefe9d1ca7fdc/docker/bqn/launch.sh#L9

@tkr-sh
Copy link
Owner

tkr-sh commented May 15, 2023

cat -v /mnt/in/input$testcount.txt

Should do it ?

@ovs-code
Copy link

Expanding on what I just said on Discord, I think there are two possible ways to fix this:

  1. Pass input via stdin:
./bin/bqn -f /mnt/in/prog.bqn         \
    < /mnt/in/input$testcount.txt     \
    > /mnt/out/out$testcount.txt      \
    2> /mnt/out/err$testcount.txt
  1. Pass input as a single command line argument. By my shell knowledge this should look something like this
./bin/bqn -f /mnt/in/prog.bqn         \
    "$(cat /mnt/in/input$testcount.txt)" \
    > /mnt/out/out$testcount.txt      \
    2> /mnt/out/err$testcount.txt

Either of those solution will break many of the existing solutions in BQN, but I think this is worth it to make sure future holes can be solved with BQN.

@ovs-code
Copy link

A third option, suggested by attinat: Pass each line of input as a separate command line argument, could be implemented as such:

cat /mnt/in/input$testcount.txt \
    | tr '\n' '\0' \
    | xargs -0 ./bin/bqn -f /mnt/in/prog.bqn \
    > /mnt/out/out$testcount.txt      \
    2> /mnt/out/err$testcount.txt

This has the advantage of keeping all existing solutions that dealt with one input per line working. Therefore my vote would be on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants