Back to General discussions forum
Hi!
I would like to contribute to CodeAbbey with a basic problem idea.
I have an image, (width, height). I want to cut it in a specific aspect ratio (width, height). All integer numbers.
What is the biggest area that can be cut out?
Let's make it a little harder: I have a small display where I show the image. The display has a fixed width. The height is flexible. I resize the image to fit the width of the display and show the image.
Now, I draw a rectangle on the display. The rectangle has the same aspect ratio. (This is usually 16:9 for TV) The aspect ratio must be exact, otherwise TV rejects the uploaded image.
The height or the width of the rectangle is given. What is the area of the corresponding rectangle in the image?
Hi Özgür!
This sounds nice, moreover it is a problem very often haunting those of programmers who work with frontend/UI!
Would you like me to try go on with your idea and shape it out into some specific problem - or perhaps you may have fancy to try creating the problem yourself as a whole?
You'll need to provide two files - one with description (in markdown format, the same used here in forum) and the other with data generation / checking code (Python is supported as a language of choice for it).
Example of the task description in markdown (you can browse any task that way)
Instruction on creating code for task
Regretfully there is no automated way to setup the task itself, so you'll need to send the files by mail (just tell when ready - I'll provide the address and will watch my mailbox carefully).
Hi Rodion! the example link is not found for some reason. But it is ok because I know how task descriptions are in this website.
I looked at the instruction for creating the code. The checking code must produce at least two lines:
Should also the answers be generated by the checking code? I will write a first iteration for a basic version and you can comment if it fits your expectations.
Hi!
I am ready with the first iteration. I basically took the instructions and modified a little bit. If the first iteration is OK, I would like to go on with randomizing the aspect ratio and making it part of the input data.
Ah, sorry, I improperly shortened the link, please retry - should be better!
The checking code must produce at least two lines
rather like this:
it works simply like this - when page is loaded the whole your code is executed, the first part is shown as input, the answer is saved (in "session" variable) - when the user submits the answer, it is compared with the saved line.
if the problem requires some special logic to check the answer (e.g. when multiple answers are possible) - it is also achievable, but probably not needed for your case? feel free to tell - I'll explain better if necessary.
I would like to go on
yep, sure, I tried to set the message for you with my email - it should be shown in yellow below header (also we'll test this feature) - feel free to contact for any specific questions on code etc.
Hi Rodion, I know the problem is still in the test phase but right now the checker expects an unusual end
at the end of the output.
Dear Mathias :) yes, this suffix is just for testing, so that proper solution won't make task "solved" if sent inadvertently.
However, since you have already tried this, may we ask for your opinion - how exactly to deal with cutting out the rectangle
of requested ratio. There are two options (perhaps more?) - suppose we have 100x100
image and 16:9
ratio. Exact ratio
is achieved with rectangle 96x54
i.e. requires cutting both dimensions of image. Alternatively we may prefer to preserve
one dimension and cut the other, probably truncating down (100x56
). What do you think?
Hi, I am quite okay with the way it is implemented/asked right now where you have to achieve the exact target ratio, i.e. cutting in both dimensions might be necessary.
Ok, thanks! It's author's implementation also, so let it go live, moreover that some people already tried it :)
Hi, thank you for trying it.
The aspect ratio must be exact and side lenghts must be integer (no rounding, no half pixels). These are the requirements.
I am very happy about having contributed to the CodeAbbey with a task.
I am quite okay with the way it is implemented/asked right now where you have to achieve the exact target ratio, i.e. cutting in both dimensions might be necessary.
Perhaps this fact should be reflected/clearly stated in the problem description in order to avoid confusion. It shouldn't be needed to browse through the forum for a small though necessary detail.
Hi, Konstantine! glad to hear from you - and thanks for suggestion. I remember stumbling over this myself, so now added appropriate note at the bottom of problem statement.
This is great, as in the image/television sector the pixels have to be whole numbers, at least in the german public broadcasting.