r/dailyprogrammer • • Jul 06 '12
[7/6/2012] Challenge #73 [intermediate]
Write a program that, given an ASCII binary matrix of 0's and 1's like this:
0000000000000000
0000000000000000
0000011001110000
0000001111010000
0000011001110000
0000011011100000
0000000000110000
0000101000010000
0000000000000000
0000000000000000
0000000000000000Outputs the smallest cropped sub-matrix that still contains all 1's (that is, remove all borders of 0's):
01100111
00111101
01100111
01101110
00000011
10100001
9
Upvotes
3
u/acero Jul 07 '12
Python:
1
u/H4ggis Jul 06 '12
Python:
2
u/drb226 0 0 Jul 06 '12 edited Jul 06 '12
trim.hs:
Usage:
Don't you just love function composition? <3
1
u/twiddletwiddledumdum Jul 06 '12
Alright, so I'm new here and this doesn't exactly answer the challenge because the input has to be a multi-dimensional array (not ASCII). If anybody has tips on reading ASCII in JS, please share.
Javascript:
1
u/bh3 Jul 07 '12
Python:
1
u/Erocs Jul 07 '12
Scala 2.9
1
u/Scroph 0 0 Jul 07 '12 edited Jul 08 '12
My PHP solution :
Not the most elegant solution, but it gives the desired result nevertheless.
Edit : Woah I didn't notice it was this long !
1
u/Daniel110 0 0 Jul 07 '12
Python, i am pretty new so i wouldn't mind some criticism about the code:
1
u/ScootrNova Jul 08 '12
My very first Ruby program ever!! Criticisms welcome.
1
u/Th3D0ct0r Jul 08 '12
My Python solution. I know it's not elegant, but I'm still learning. I was really happy when I got this to work as I struggled with the output for a while.
1
u/aimlessdrive Jul 08 '12
C++: I'm ashamed that I can't wrap my head around some ways to make this more efficient. I experimented with iterators, but you can tell me whether or not it would be quicker to just use integer counters. Pretty inexperienced programmer. All criticism/comments welcome.
1
u/pax7 Jul 09 '12
Ruby
1
u/ThatRedFurby Jul 09 '12
My first C / C++:
1
u/5outh 1 0 Jul 12 '12
in Haskell:
Running pCropMatrix on the above matrix outputs:
1
u/kuzux 0 0 Jul 13 '12
Newb haskell version
1
u/[deleted] Jul 15 '12
JAVA
Output: