Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,163,442 members, 7,853,926 topics. Date: Saturday, 08 June 2024 at 08:08 AM |
Nairaland Forum / Science/Technology / Programming / Weekend Challenge For Practice: RLE Encoding (3654 Views)
Recommend Site Where One Can Get Web Development Projects For Practice / Challenge For Javascript Beginners/intermidiate / Coding Challenge For Fun (2) (3) (4)
Weekend Challenge For Practice: RLE Encoding by Nobody: 4:38pm On Aug 05, 2017 |
Run Length Encoding Given an input string, write a function that returns the Run Length Encoded string for the input string. For example, if the input string is “wwwwaaadexxxxxx”, then the function should return “w4a3d1e1x6”. You can use this to compile your code https://ideone.com Usage of this Algorithm Compression of String if the need of character length is highly emphasized. |
Re: Weekend Challenge For Practice: RLE Encoding by jidez007: 5:56pm On Aug 05, 2017 |
Took me about 5 minutes C++
|
Re: Weekend Challenge For Practice: RLE Encoding by Nobody: 6:18pm On Aug 05, 2017 |
Awesome one bro https://ideone.com/Stbs0f Am waiting for others to post theirs if interested, the goal is to get everyone acquainted with challenges so that when interviews start it will be easy to be in that state of mind. |
Re: Weekend Challenge For Practice: RLE Encoding by silento(m): 10:31pm On Aug 05, 2017 |
30 MINUTES c pointer is great and bad at same time http://ideone.com/fzTQgH <script src="http://ideone.com/e.js/fzTQgH" type="text/javascript" ></script> |
Re: Weekend Challenge For Practice: RLE Encoding by MonsieurCoder: 11:49pm On Aug 05, 2017 |
__ |
Re: Weekend Challenge For Practice: RLE Encoding by Javanian: 11:53pm On Aug 05, 2017 |
https://ideone.com/rTAiHh 8 Lines |
Re: Weekend Challenge For Practice: RLE Encoding by Nobody: 7:33am On Aug 06, 2017 |
See my own https://ideone.com/WS6mvr |
Re: Weekend Challenge For Practice: RLE Encoding by Nobody: 10:45am On Aug 06, 2017 |
silento: Am curious why did you go through the route of pointers, because i understand you're allocating the same size as the char, you could easily still use a char , yeah Pointers is cool but sometimes complex. Nice one guys |
Re: Weekend Challenge For Practice: RLE Encoding by silento(m): 10:55am On Aug 06, 2017 |
pcguru1: in c language if you return a regular char[] you will get error. if the function is run twice because the function will be sharing the same memory space but will pointer you will get the error solved |
Re: Weekend Challenge For Practice: RLE Encoding by orimion(m): 2:52pm On Aug 06, 2017 |
Re: Weekend Challenge For Practice: RLE Encoding by Nobody: 4:25pm On Aug 06, 2017 |
orimion: My God what language is this lol |
Re: Weekend Challenge For Practice: RLE Encoding by Nobody: 4:29pm On Aug 06, 2017 |
I took just half a look, fainted, woke up, looked again, almost died and finally crawled away on all fours. . . . .yeah, what a language! |
Re: Weekend Challenge For Practice: RLE Encoding by orimion(m): 4:44pm On Aug 06, 2017 |
pcguru1:Haskell might be my inexperience that makes it look cryptic |
Re: Weekend Challenge For Practice: RLE Encoding by CryptoCoinr(f): 4:46pm On Aug 06, 2017 |
pcguru1: Er, is the challenge language specific? |
Re: Weekend Challenge For Practice: RLE Encoding by jidez007: 5:02pm On Aug 06, 2017 |
I have looked at that code like 10 times and I don't understand anything Na Haskell language I go use now if I wan confuse my enemies. |
Re: Weekend Challenge For Practice: RLE Encoding by Nobody: 5:12pm On Aug 06, 2017 |
orimion: Actually far from it the syntax doesn't come across as familiar at all most times you'd get that c like or Python type but never saw this. |
Re: Weekend Challenge For Practice: RLE Encoding by CryptoCoinr(f): 8:49pm On Aug 07, 2017 |
CryptoCoinr: pcguru1, did you ignore this or you just didn't see it? Either way, here's mine (in JS as usual):
|
Re: Weekend Challenge For Practice: RLE Encoding by Nobody: 9:26pm On Aug 07, 2017 |
CryptoCoinr: 4got to reply |
Re: Weekend Challenge For Practice: RLE Encoding by CryptoCoinr(f): 9:37pm On Aug 07, 2017 |
pcguru1: Okie dokie. I'm glad I googled what RLE was. I actually completed the challenge within ~15mins - 20mins of posting that question but started wondering what we were meant to do if an already tagged character, say "w", occurred after a whole bunch of other characters. Long story short: many hours spent needlessly reiterating. |
Re: Weekend Challenge For Practice: RLE Encoding by Nobody: 10:00pm On Aug 07, 2017 |
^^^that is why you guys are EXPERTS! |
Re: Weekend Challenge For Practice: RLE Encoding by Nobody: 10:06pm On Aug 07, 2017 |
CryptoCoinr: LOL Over-thinking, that way won't be able to track the position of where the text occurred, you get. |
Re: Weekend Challenge For Practice: RLE Encoding by segxyhanxy(m): 11:01pm On Aug 07, 2017 |
a solution of it in java. public static String rle(String data) { String compressedData = ""; int counter = 1; char lastChar = data.charAt(0); for (int i = 1; i < data.length(); i++) { char c = data.charAt(i); if (c != lastChar) { compressedData += data.substring(i - 1, i) + counter; counter = 1; lastChar = c; } else { counter++; lastChar = c; } if (i == data.length() - 1) { compressedData += data.substring(i - 1, i) + counter ; } } return compressedData; } |
Re: Weekend Challenge For Practice: RLE Encoding by Nobody: 8:08am On Aug 08, 2017 |
segxyhanxy: Segzy baba |
Re: Weekend Challenge For Practice: RLE Encoding by deedat205(m): 11:20am On Aug 09, 2017 |
Nice challenge. But who can come up with the RLE string decoding solution.
Eg W4E2H3 should be WWWWEEHHH and A12T3Y4 should be AAAAAAAAAAAATTTYYYY |
Re: Weekend Challenge For Practice: RLE Encoding by Nobody: 1:48pm On Aug 09, 2017 |
deedat205: The reverse of it right. |
Re: Weekend Challenge For Practice: RLE Encoding by orimion(m): 2:04pm On Aug 09, 2017 |
deedat205: here ya go
http://ideone.com/nq33Iy |
Re: Weekend Challenge For Practice: RLE Encoding by deedat205(m): 6:05pm On Aug 12, 2017 |
We have strong programmers on Nairaland my python 3 solution to RLE Encoding a = 'wwwwaaadexxxxxx' a += '!' i,s = 0,'' while i < len(a)-1: c = 1 while a[i] == a[i+1] and i < len(a)-1: c,i = c+1, i+1 s += a[i]+str(c) i += 1 print(s) Solution to RLE decoding import re a = 'A12T3Y4' x = re.compile(r'[A-Za-z]') y = re.compile(r'\d+') p = x.findall(a) q = y.findall(a) z = '' for i in range(len(p)): z += p[i]*int(q[i]) print(z) |
Re: Weekend Challenge For Practice: RLE Encoding by deedat205(m): 6:15pm On Aug 12, 2017 |
There is a stubborn challenge I want you guys to try out on Hackerrank https://www.hackerrank.com/challenges/separate-the-numbers/problem The challenge was rated easy, but I think medium would have been appropriate to describe its complexity The challenge is to determine if a string has numbers that are consecutive with a difference of 1. Example 1234, 91011 and 99100 should all return YES while something like 101113, 2325 should both return NO |
Free Website For Small Business Owners And Ngos / CNC Programming / Learn Programming For Free And Earn Stipends
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 36 |