otobrglez / compression-puzzle

Attempts to crack the "compression puzzle".
15 stars 47 forks source link

Added Red solution #16

Closed rebolek closed 2 years ago

rebolek commented 2 years ago

This is a solution written in Red language. It’s a one-liner but split into commented multiple lines for easier understanding. As a bonus, I added decompression also.

otobrglez commented 2 years ago

Thank you @rebolek for your effort and submission!

Please give me some time to add red support to the "build system". I've found out that it's unsupported on my darwin arch.

Epic!

otobrglez commented 2 years ago

@rebolek How do I run this thing? :) Assuming that I have rebol/red installed?

otobrglez commented 2 years ago

I've experimented with this. Without luck. ;|

docker run -ti --rm -v $PWD:/tmp/app --entrypoint nix-shell nixos/nix -p red \
  --run "red -r /tmp/app/src/red/compress.red"
Screenshot 2022-02-01 at 16 53 00
rebolek commented 2 years ago

@otobrglez your command should be "red /tmp/app/src/red/compress.red" without -r. Anyway, if I try it, it still complains it can’t find the file. It has something to do with Docker path mapping. I’m not an expert on Docker but I try to find a solution and let you know.

otobrglez commented 2 years ago

@rebolek can you please explain this cryptic error message to me please?

$ docker run -ti -v $PWD:/app --entrypoint /bin/bash kskarthik/redlang:0.6.4 /app/src/red/run-red.sh
+ cd /app/src/red
+ red compress.red
Compiling compression library...
Compiling Red console...
*** Syntax Error: invalid value at "^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@"
*** Where: do
*** Stack: load

This is me trying to use kskarthik/redlang:0.6.4 docker image with Red with a bash script to overcome this issue.

The run-red.sh looks like this

#!/usr/bin/env bash
set -ex

cd /app/src/red && red compress.red

Thank you!

PR for work on adding support here.

loziniak commented 2 years ago

Perhaps you could find useful this repo as an example: https://github.com/exercism/red-test-runner/

rebolek commented 2 years ago

@otobrglez ^@ is zero, so it's somehow reading an empty file. @hiiamboris wrote: "This looks like a problem with 32-bit file system driver. I got smth like that on WSL2 when reading files from NTFS partitions."

rebolek commented 2 years ago

@otobrglez

Ok, I've got it, removing -t is enough, the script works then, here's the proper command (assuming you are in the repo's root):

docker run -ti --rm -v $PWD:/tmp/app --entrypoint nix-shell nixos/nix -p red \
  --run "red -r /tmp/app/src/red/compress.red"

However, there is no output from the script as it only throws an error if the assertion failed and outputs nothing if there's no error.

otobrglez commented 2 years ago

Closing in favour of this PR