r/dailyprogrammer • u/fvandepitte 0 0 • Oct 26 '17
[2017-10-26] Challenge #337 [Intermediate] Scrambled images
Description
For this challenge you will get a couple of images containing a secret word, you will have to unscramble the images to be able to read the words.
To unscramble the images you will have to line up all non-gray scale pixels on each "row" of the image.
Formal Inputs & Outputs
You get a scrambled image, which you will have to unscramble to get the original image.
Input description
Challenge 1: input
Challenge 2: input
Challenge 3: input
Output description
You should post the correct images or words.
Notes/Hints
The colored pixels are red (#FF0000, rgb(255, 0, 0))
Bonus
Bonus: input
This image is scrambled both horizontally and vertically.
The colored pixels are a gradient from green to red ((255, 0, _), (254, 1, _), ..., (1, 254, _), (0, 255, _)).
Finally
Have a good challenge idea?
Consider submitting it to /r/dailyprogrammer_ideas
7
u/leonardo_m Oct 26 '17 edited Oct 29 '17
In Nigtly Rust, with bonus, using the image crate:
The use of get_pixel/put_pixel is not efficient, but it runs in about 0.03-0.04 seconds on each image. The hidden words are APPLESAUCE, ZUCCHINI, DAILYPROGRAMMER and EGGPLANT.
Edit: added bonus, removed bug.
5
u/gandalfx Oct 26 '17 edited Oct 26 '17
Python 3 with bonus
Uses only Pillow (PIL) as a dependency to read/write image files. Bonus takes only one line.
bonus result
5
u/nvoker Oct 26 '17
J (http://jsoftware.com)
4
u/mn-haskell-guy 1 0 Oct 26 '17 edited Oct 26 '17
python + scipy/numpy solution... used a slightly different algorithm for the bonus image.
Update: Thanks for /u/leonardo_m for spotting edge case that should be accounted for (applied to the bonus image.)
4
u/skeeto -9 8 Oct 26 '17
C using Netpbm (PPM) as the input and output format.
Usage example:
Code:
4
u/[deleted] Oct 28 '17 edited Oct 31 '17
In F#, without bonus
Would have had this completed last night, but I completely misunderstood the nature of the scramble. I didn't realize it was each individual line, I thought they were spread across other lines. Thinking back on it, that was rather silly of me :)
EDIT: With bonus (and active pattern matching :D) module Challenge337
3
u/chunes 1 2 Oct 26 '17 edited Oct 26 '17
Cool challenge! Factor:
Output:
3
u/nikit9999 Oct 26 '17 edited Oct 26 '17
C# no bonus.
3
u/[deleted] Oct 27 '17
Ruby
Fun challenge! I learned how to use RMagick in order to solve it.
Output images
2
u/Scroph 0 0 Oct 26 '17
Java, no bonus. I'm a Java noob coming from C++/D, so criticism is welcome.
Output :
2
u/JakDrako Oct 26 '17
VB.Net in LinqPad, with bonus (auto detects if the image is scrambled both ways)
2
u/[deleted] Oct 26 '17
A beginners C# solution:
2
u/Working-M4n Oct 26 '17 edited Oct 27 '17
JavaScript
Live link on CodePen.
Nowhere near as crisp as I would like, but it is readable.Much clearer now. No bonus... yet. Feedback always welcome.2
u/Gprime5 Oct 27 '17 edited Oct 27 '17
Python 3.5 using PIL and bonus
Basically finds where the colored pixels are for each row, splits the row into a left and right side and swaps them around.
Output: "EXAMPLE", "APPLESAUCE", "ZUCCHINI", "DAILYPROGRAMMER", "EGGPLANT"
2
u/[deleted] Oct 27 '17
Python with pygame for visuals - please note that pygames performance is abysmal :( there is also an option to run it without rendering but you wont see the solution of course
2
u/yeah_i_got_skills Oct 28 '17 edited Oct 28 '17
C#
Comments welcome.
2
u/thestoicattack Oct 29 '17 edited Nov 01 '17
C++17. With bonus. The thing I don't like is that I abused the << and >> operators, which are supposed to be for formatted, not raw, input, just so I could use the ostream/istream iterator adapters. The actual unscrambling is easy thanks to the <algorithm> header.
2
u/cacilheiro Oct 31 '17 edited Oct 31 '17
As somone who just took up Rust, I'd love to have feedback from more experienced Rust developers.
Anyway, had lots of fun doing this challenge :)
Edit: Added bonus.
3
u/popillol Oct 26 '17 edited Oct 27 '17
Go / Golang Playground Link.
Absolutely no idea if this works, can't test it at work. I've never worked with the image package before so it's almost guaranteed to be broken somehow, but this is fun. Putting here so I can work on it later :)Edit: Can't get it to work. I updated the Playground link if anyone wants to take a look. It appears to be finding the red pixels just fine, but I must be misunderstandingdraw.Draw()because the new image isn't changing, it's just a blank image.Edit2: Got it working! Playground Link
1
u/StoleAGoodUsername Oct 30 '17
Vanilla Javascript, solution runs entirely in browser
JSFiddle
1
u/jeaton Nov 10 '17
Python3
1
u/NitroFingers Nov 10 '17
Python No Bonus
1
u/Digg-Sucks Dec 06 '17
1
u/mtharrison86 Dec 25 '17
Go
0
u/[deleted] Oct 26 '17
[deleted] — view deleted comment
0
u/[deleted] Oct 27 '17
[deleted] — view deleted comment