473,805 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Any good codes for this algorithm?

I have a line of binary codes such as 1 1 1 0 0 0 1 1 1
I'd like to change the number of consecutive 0s to be even.
is there any good algorithm in C?

Thanks

Nov 15 '05 #1
5 1629
po***********@g mail.com writes:
I have a line of binary codes such as 1 1 1 0 0 0 1 1 1
I'd like to change the number of consecutive 0s to be even.
is there any good algorithm in C?


You should probably define the algorithm itself before you try to
implement it. It is not obvious how to change the number of
consecutive 0s to be even. Should it be done by inserting or
deleting 0s? Should it be done by changing 0s to 1s or 1s to 0s?
Will there be more than one sequence of consecutive 0s, or just
one? (Are there guaranteed to be any 0s at all?)
--
"It wouldn't be a new C standard if it didn't give a
new meaning to the word `static'."
--Peter Seebach on C99
Nov 15 '05 #2
po***********@g mail.com writes:
I have a line of binary codes such as 1 1 1 0 0 0 1 1 1
I'd like to change the number of consecutive 0s to be even.
is there any good algorithm in C?


Delete all the 0s, or change them all to 1s.

I doubt that that's what you had in mind, but your question really has
nothing to do with C. You might try comp.programmin g -- and be more
specific about the problem definition. Once you have an algorithm, if
you have trouble implementing it in C feel free to come back here and
show us what you've written, and we'll help if we can.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #3
po***********@g mail.com wrote:

I have a line of binary codes such as 1 1 1 0 0 0 1 1 1
I'd like to change the number of consecutive 0s to be even.
is there any good algorithm in C?


if (1 & zerobitcount()) setlastbit();

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 15 '05 #4
po***********@g mail.com wrote on 30/07/05 :
I have a line of binary codes such as 1 1 1 0 0 0 1 1 1
I'd like to change the number of consecutive 0s to be even.
is there any good algorithm in C?

Thanks


You should cleanup your mind.

- An algorithm belongs to the design (phase #2 of a project life). It
has nothing to do with an implementation language. It can be written in
plain <select your spoken language> or in algorithmic langage (AFAICT,
no real standard, but a kind of Pascal is close enough).

- Once you have an algorithm working on a sheet of paper (could be an
electronic one, let's be modern...), you switch to phase #3 (Coding and
test). You translate it into your implementation language (Asm, C, C++,
X--, Y** whatever).

FYI:

Project life:

#1 Specifications (what ?)
#2 Design (how-to ?)
#3 Coding and unit-test (implementation )
#4 Integration (glue the all thing and make it work)
#5 Validation (Does the thing comply with the specs ?)
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"C is a sharp tool"
Nov 15 '05 #5
In article <11************ *********@o13g2 000cwo.googlegr oups.com>, po***********@g mail.com wrote:
I have a line of binary codes such as 1 1 1 0 0 0 1 1 1
I'd like to change the number of consecutive 0s to be even.
is there any good algorithm in C?

Thanks


Output all 1s then there will be an even number of 0s :)

more information please.
possibly something could be done using a precomputes lookup table.

Bye.
Jasen
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2332
by: eyh5 | last post by:
Hi, I'm writing some C codes to run simulations. I'm wondering if there is a website that may contain useful information on how to make one's code run more efficiently and in a computational-time-saving manner. Specifically, what I'd like to know is if there're any useful tips about writing your codes more efficiently. One such useful tip is that we can use the "switch" statement instead of multiple "if-else" statements; another is that...
113
12362
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same algorithm work with strings that may or may not be unicode 3) Number of bytes back must either be <= number of _TCHARs in * sizeof(_TCHAR), or the relation between output size and input size can be calculated simply. Has to take into account the...
45
2424
by: Brett | last post by:
If I do this without declaring a corresponding field, is it considered bad design? What are the advantages or disadvantages to either method? Notice there is not set. public string URL { get { return "www.somewhere.com/test.aspx"; }
17
20507
by: Kermit Piper | last post by:
Hello, I have been searching, Googling, searching. Cannot find a javascript to calc 10, 11 or 12 digit UPC codes. I just need an algorithm that calcs to verify the correct check digit. I have found a few that add the check digit then do the final calc, but I need an input validation that will verify the UPC as being correct with the correct check digit after the user simply enteres the number in one text box. There has to be something...
1
2986
by: thanam | last post by:
hi all, Can anyone help me wit the C codes of DES Algorithm in Linux platform ?
3
4630
by: yinglcs | last post by:
Hi, Can you please recommend any good books for c++ algorithm/data structure implementation? I am looking for book which has code/ explanation for common algorithm in c++ , e.g. search, sort, traverse a tree. Thank you.
0
1479
by: georgerxz | last post by:
Download source code in C for learning Data structure implementation from http://zsoftwares.googlepages.com/CPrograms.html and http://zsoftwares.googlepages.com/DSFPrograms.htm Source codes given on above website are based on - Arrays
1
9871
by: haadung | last post by:
I also the source code for apriori algorithm. I was trying to do the problem.. but i found many errors. Can anyone please give me the code. I'll be very greatful.. Thank you...
1
3117
by: almurph | last post by:
Hi everyone, Concerning the Needleman-Wunsch algorithm (cf. http://en.wikipedia.org/wiki/Needleman-Wunsch_algorithm) I have noticed a possible loop. Inside the algorithm there is an important decision making mechanism. Its a "if, else if, else if" structure like:
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10369
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.