473,378 Members | 1,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 1600
po***********@gmail.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***********@gmail.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.programming -- 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_Keith) 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***********@gmail.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.com, 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***********@gmail.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*********************@o13g2000cwo.googlegroups. com>, po***********@gmail.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
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...
113
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...
45
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...
17
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...
1
by: thanam | last post by:
hi all, Can anyone help me wit the C codes of DES Algorithm in Linux platform ?
3
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,...
0
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...
1
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.