Algorithm for competing cells of 0s and 1s. Can it be made faster?

I’m working on a practice algorithm problem, stated as follows:

There are eight houses represented as cells. Each day, the houses compete with adjacent ones. 1 represents an “active” house and 0 represents an “inactive” house. If the neighbors on both sides of a given house are either both active or both inactive, then that house becomes inactive on the next day. Otherwise it becomes active. For example, if we had a group of neighbors [0, 1, 0] then the house at [1] would become 0 since both the house to its left and right are both inactive. The cells at both ends only have one adjacent cell so assume that the unoccupied space on the other side is an inactive cell.

Even after updating the cell, you have to consider its prior state when updating the others so that the state information of each cell is updated simultaneously.

The function takes the array of states and a number of days and should output the state of the houses after the given number of days.

Examples:      input: states = [1, 0, 0, 0, 0, 1, 0, 0], days = 1     output should be [0, 1, 0, 0, 1, 0, 1, 0]     input: states = [1, 1, 1, 0, 1, 1, 1, 1], days = 2     output should be [0, 0, 0, 0, 0, 1, 1, 0] 

My solution:

def cell_compete(states, days):     for _ in range(days):         prev_cell, next_cell, index = 0, 0, 0         while index < len(states):             if index < len(states) - 1:                 next_cell = states[index + 1]             elif index == len(states) - 1:                 next_cell = 0             if next_cell == prev_cell:                 prev_cell = states[index]                 states[index] = 0             else:                 prev_cell = states[index]                 states[index] = 1             index += 1     return states 

I originally thought to take advantage of the fact they are 0s and 1s only and to use bitwise operators, but couldn’t quite get that to work.

Can I improve the efficiency of this algorithm? Any ideas on the “optimal” solution?

Appreciate any feedback, thanks!

200,000 SER GSA back links for increase links juice and faster index on google for $7

200 k SE R GSA Back links For Increase Link Juice and Faster Index on Google Way to massive exposure for your Websites from various social media This is great for higher search engine ranking as well as best way to do SE O for your website and high authority websites, usually known as high quality “Link Juice”. Wondering how to optimize your website for higher search engine ranking? Here is a shortest SE O guide for you about understanding the process of back links building: Level *3 ====== *** This level assist you to increase your Level*2 websites link juice, as well as GSA SE R back links will help you to optimize your website for Google and other major search engines. Level*2 ====== *** Add “Level#1” link to various social media sites ### Crafts more relevant articles and add “Level#1” link on buffer sites ### Add “Level#1” link to various websites like Wiki, Article Directory, Forums and ETC Level*1 ====== ### Links from quality traffic websites *** Links from aged & established websites *** Links from relevant pages ### Links from Unique C Class IP s *** Links from high DA, PA, T F pages Accept for per order: ### 1 to 100 Keywords (should be one topic) ### 1 to 100 URLs Important: We will use randomly all keywords on all URLs (if you have more than 1 URL) The most recent statistics on Search Engine Optimization process are mind-blowing thanks for your order sir.

by: Eyasin9
Created: —
Category: Link Building
Viewed: 253


Rank Your Website 4x Faster With High Authority Manual Link Building Service for $38

Ultimate Keyword Ranking + Links Diversity Package 100% Manual Link Building 100% Safe Rank your keyword and surround it with natural looking backlinks for maximum diversification and power What you get exactly: 1 High quality PBN ( Real Handwritten Unique 500 word post) – PBN looks like a real site with about us page, tos, contact us, etc. – No footprints – hosted on premium host like hostgator and Godaddy – 35+ Referring Domains – The PBN has its own social media profiles – like real websites – Relevant Image or video 1 Web 2.0 ( Real Handwritten Unique 300 to 400 word post) High DA & PA Relevant Image or video Unique Design 1 High Authority PDF or Doc link ( Real Handwritten Unique 300 to 400 word post) 1 High Authority Do-follow Profile ( Real Handwritten Unique 200 to 300 word post) Logo submission and content filled. 1 High Authority Social Bookmark 1 Quora Answer 2 Blog comments ( We will actually read the posts and place engaging comments related to the post and try to get you some extra free relevent traffic ) 100% Manually done 1 Tumblr Share on aged account with more than 700 followers 1 Pinterest Share on aged account with 4.2k monthly viewers 1 Facebook Shared on aged fan page with more than 2500 fans How Does it Work? Basically we ask you for only 1 keyword and 1 url. Step 1 – We place your keyword on our high quality pbn to give you a boost in ranking. Step 2 – We manually build for you high quality high DA backlinks and profiles with unique handwritten content on web 2.0, profile account, pdf, social bookmarks. Step 3 – We share your link on aged social media accounts to give you some social signals Step 4 – We search for a relevant question on Quora related to your topic, do some research and place an engaging or helpful comment and try and get you some little but extra free traffic. Step 5 – We repeat step 4 but we use two relevant websites, we read the full post and place an engaging or helpful comment. Step 6 – Sit Back Relax and watch your ranking get a boost from our pbn, mixed backlinks for links diversification, social signals, and relevant comments. F.A.Q Q – What is the TAT (Turn Around Time)? A – 4 to 7 days Q – How many keywords per order? A – 1 per order per url, We use your main keyword on the PBN only and the rest of the links will be placed as naked url or generic to diversify your link portofolio. Q – How is the content placed and accounts created? A – 100% manually and handwritten content will be used. No Bots, No Spinning just pure manual high quality. We provide what we use for our own money sites. Q – What niches do you accept? A – We accept all niches except, adult, pharma and casino related websites. Why should you trust me with this service? I have been developing, ranking and marketing websites for my clients for over 8 years. Don’t just take my word for it, check below yourself who bought my services on other platforms and their testimonials: Superstar SEO himself – Founder of Legiit ⇧ SEOMG from Gigs That Work ⇧ And Many More below

by: HugeGorilla
Created: —
Category: Link Building
Viewed: 252


How to run Ubuntu faster?

I installed Ubuntu 19.04 and it’s running a lot slower than Windows 7. I have 7.5Gib on an AMD Athlon ii x2 250 processor, and 64 bit.

I still have Windows 7 on my pc and I went back and Windows still runs a lot faster than Ubuntu. Please help!

Build 10,000,00 Gsa Backlinks For Faster Website Ranking for $5

Are you wondering about how will help GSA backlinks for faster Google ranking!!! I’m offering my tested 10,000,00 GSA backlinks which definitely reflect for your business improvement. GSA backlinks help you to increase link juice to your sites for make your Tier#1 backlinks are stronger better than anything. So why waiting??? This service only for following platforms, not for main website:- – For multi-tiered link building – For YouTube video SEO – For Amazon listing SEO – For Ebay listing SEO – Web 2.0 sites – Facebook pages – Article sites – 301 redirecting URLs Important & Remember:- If you use this service to your main site so it’s your own responsibility, not mine. If you have any questions feel free to send us a message by press contact button.

by: CrushSEO
Created: —
Category: Link Building
Viewed: 179


1000 Worldwide traffic cheap and faster delivery for $1

Are you looking for the easiest way to get a huge traffic boost on your website? seogabriel is here to meet your needs! We can deliver traffic from worldwide, targeted for your site category, from as low as $ 1 per 1,000 visitors. That’s right, our cheap traffic will bring you targeted visitors, customers, rankings improvement and most importantly real web traffic. Your site will be the proud recipient of a steady flow of website visitors, and this will finally lead to your success as a site owner. There are plenty of businesses online that offer to buy website traffic, but not all of them are going to be beneficial to your website. We offer top level visitors to your site for the best prices and we will not fail you. How does our web traffic work? The source of our cheap traffic is a vast inventory of specific websites and domain names, all of which attract millions of website visitors each day from search engines and advertising networks. We have over 400 niche markets to make sure you get targeted traffic. The popularity of your website will get a great boost leading you to the essential sales you need to succeed. Yes, we can ensure that your website visibility will be improved considerably. Features of Traffic: 1. Targeted Traffic Over 400 niche markets, and the choice between worldwide. 2. Cheap Prices From as low as $ 1 per 1,000 visitors. 3. Real and unique website traffic Your website is seen by good visitors. 4. 24/7 Live Statistics Monitor your campaigns through a detailed statistic. 5. Fast Progress Fast progress traffic.

by: seogabriel
Created: —
Category: Traffic
Viewed: 87


VideoCapture.read() using OpenCV. Why is USB Camera faster than CSI Camera? (NO GPU)

I am using NanoPi Duo 2 for the real-time image acquisition project.

I have noticed a significant performance (speed) difference between using CSI camera and USB camera.

The performance difference is as follows, Time for OpenCV VideoCapture.read()

CSI_OV5640_Camera = ~0.04s (40 ms) USB_Logitech_HD_C270 = ~0.009 (9 ms) 

As far as I know, I understand that NanoPi Duo2 does not have any GPU and CSI camera will be handled by CPU (Same as USB Camera).

Using $ htop both CSI and USB cameras shows 100% @ one of 4 cores.

For background,

OpenCV 3.4.6 Build Output

Video I/O  - libv4l/libv4l2    NO  - v4l/v4l2          linux/videodev2.h 

$ v4l2-ctl –get-fmt-video

Format Video Capture:         Width/Height      : 640/480         Pixel Format      : 'YV12'         Field             : Any         Bytes per Line    : 960         Size Image        : 460800         Colorspace        : Default         Transfer Function : Default         YCbCr Encoding    : Default         Quantization      : Default         Flags             : 

One interesting thing Performance of using numpy ndarray from CSI and USB are ALSO different

pyzbar.decode() calculation CSI_OV5640_Camera = ~0.43s (430 ms) USB_Logitech_HD_C270 = ~0.19s (190 ms) 

I am thinking that encoding of the VideoCapture.read() are different but all I see is same sized (640×480, 3 colors) numpy ndarray with similar looking values.

Thank you for reading my question.

What is the smallest value of n such that an algorithm running at 100*n^2 operates faster than 2^n ? [How to figure out without brute force]

Okay, so I needed to find the smallest value of n such that algorithm 100*n^2 is faster than 2^n.

[what I have tried]

So, I instantly thought ‘0’. But, I then realized it can’t be 0, 0 implies that there are no digits being entered in the algorithm, it also implies that the program does not run or terminate.

I typed in 2^32 and got a number over 4 billion. Okay, this is good, I’m finding numbers that have 100*n^2 being faster than 2^n.

I halved that, n = 20.

I kept inserting values counting down until I got to n = 15.

I also counted up from n = 10, the answer is undoubtedly n = 15, but I have a problem . . . .I solved this using brute force and that isn’t good. What if I was given a bigger number and a larger bredth of numbers?

[What I need]

I need a way of finding the value instantaneously by only doing the math, I tried using logarithms, but my answer was wrong, my knowledge of logs is a bit rusty and I need a little help.

Think of it as a student trying to solve a question on an SAT or having a timer for a test.