Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,209,079 members, 8,004,837 topics. Date: Sunday, 17 November 2024 at 08:25 AM

A Seemingly Simple Logic That Took Me 3 Evening To Code - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / A Seemingly Simple Logic That Took Me 3 Evening To Code (1703 Views)

How To Code Your Own Personal Assistant In Python / The Java Expert Is Back,ethical Hacking Seminars All Over Africa Took Me Away!! / Simple Logic!think U Can Crack This? (2) (3) (4)

(1) (Reply) (Go Down)

A Seemingly Simple Logic That Took Me 3 Evening To Code by ufumes(m): 10:54pm On Jan 27, 2012
I know  that experienced programmers may consider  this logic too simple. But it can prove to be a stubborn nut to crack during the debugging process. That was what I initially thought, but when I started coding for it, it took 3 evenings of my spare time.

The logic splits any text into groups of desired length. The length of the group may be less, equal to but not more than the specified character length.  The main priority is that the length should only be splitted when ever a newline occurs. If a chunk of text does not contain a newline, then the text is splitted into smaller groups based on character counting.

Eg splitting this texts (data) in group of 4 should give the following result. (Result)

Data
Abcde
f
g
Hij
Klmn
Op
Qrstuv
Wxy
Z

Result
Abcd
efg
Hij
Klm
Nop
Qrst
Uvwx
yz

The logical problem is now a thing of the past, to God's glory.

I  am programming with visual studio(vb).
Re: A Seemingly Simple Logic That Took Me 3 Evening To Code by prodam(m): 1:14am On Jan 28, 2012
yeah, it worth it bro,
i once had almost the same stuff with string tokenizer and substring (indexing) java back then, it took me 7nights(9pm_4am everynight),
I see string manipulation as one of the difficult things in programming cos its always treated as a whole entity(object as in Java) in some programming languages,

I would like to know ur algorithm, i will be xpecting urs while I try to devise an algorithm to solve the logic too.
Re: A Seemingly Simple Logic That Took Me 3 Evening To Code by logica(m): 7:32am On Jan 28, 2012
You would have benefited from Regular Expression expertise.
Re: A Seemingly Simple Logic That Took Me 3 Evening To Code by Beaf: 4:52pm On Jan 28, 2012
The problem seems quite straightforward. It is good practice to actually completely design your processes before writing a single line of code; you can do that either on paper or with a diagramming app (if you have one). You will be surprised how easy it makes your task.
Re: A Seemingly Simple Logic That Took Me 3 Evening To Code by lordZOUGA(m): 5:06pm On Jan 28, 2012
I agree with beaf, This problem doesn't look that menacing, The poster overlooked the algorithm design process,
Re: A Seemingly Simple Logic That Took Me 3 Evening To Code by ufumes(m): 8:30pm On Jan 29, 2012
Thanks for your replies.
@prodam, maybe when i am less busy, i would modify the code and post it online.
@ordZOUGA and beaf, I dont overlook the algorithm process. I make serious drafts before embarking on any project. Though i use onenote and hand drawn sketches a lot, I dont have other diagrammatic apps. But some function dont need that planning cos you know exactly what to do. That was exactly what I thought cos this logic is just a microscopic part of a bigger project i am currently working on. The exact point I am trying to make is that I dont spend time drawing up drafts for every simple function. Just like some other programmers, i thought it was a 5min assignment. But it proved otherwise, so i gave it a better attention.
Re: A Seemingly Simple Logic That Took Me 3 Evening To Code by Mobinga: 2:32pm On Jan 30, 2012
@OP Post your code; let's see if an improvement can be made.
Re: A Seemingly Simple Logic That Took Me 3 Evening To Code by delomos(m): 5:55am On Feb 05, 2012
logica:

You would have benefited from Regular Expression expertise.
Abcde
f
g
Hij
Klmn
Op
Qrstuv
Wxy
Z

Result
Abcd
efg
Hij
Klm
Nop
Qrst
Uvwx
yz
Amen to that! Just in case you're solving similar problem in the future, just have parse into the pattern (you might have to fine tune per your language):
A[b-d]+\n[e-g]+\nhig\nKlm\\nNop\nQ[r-t]+\nU[v-z]+\/nyz$

(1) (Reply)

I Need A Developer That Can Create A Website Like This / Research Project Topics/thesis For Computer Science Undergraduate / No longer available.... Gotten what I wanted

(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. 16
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.