Permutations without Recursion

I remember when I was in college, a very tricky quiz was to convert recursive code to a non-recursive one. I have always found it very challenging.

Permutation can easily be solved with recursion. So I tried to solve it without recursion. It was a fun exercise.

alpha = 'xyz'

def main():
    n = list(alpha)
    while n:
        print n
        n = next(n)


def next(str):
    str.pop()
    # loop to find a upgradable tail
    while str:
        tail = str[-1]
        # search for an upgrade to the tail
        new_tail = [i for i in alpha if i > tail and i not in str]
        if not new_tail:
            str.pop()
            continue
        str[-1] = new_tail[0]
        # fill the rest
        return str + [i for i in alpha if i not in str]

Posted

Why ChromeCast is not AppleTV

If you read the Google Cast API, you know exactly why it is called ChromeCast: the receiver device simply runs a boiled-down version of the Chrome browser and listens for commands sent by sender applications. It seems to also be able to run custom applications as the receiver in the device, as long as it is not resource intensive and it's a regular web application. So the important take-away is that there will be two applications at play, most likely maintained in two separate code bases (not to mention the number of programming languages involved).

Saying there is no SDK for AppleTV is misleading: it's true that there is no way to create custom applications to run on AppleTV (yet), but there is an API to use AirPlay/AppleTV as a second screen. The emphasis is on second screen: there is only one app that simply render content to two screens. The app just sees a second UIWindow instance and renders views on to it as usual, and the system takes care of the rest. It's inherently simple, and there is one codebase and most likely one programming language involved. Apps like Real Racing 2 HD and the Redfin app are taking very good advantage of this well-documented feature. With Mavericks, users can set up an AppleTV as a regular external monitor at the system level, so it's even simpler for developers: if your Mac app can deal with dual monitors, you can utilize AppleTV. Compare this to a Google Cast application: to use the receiver device as a second screen, you either create a dedicated receiver application and get the main app to communicate to it by commands, or you have to roll out your own implementation of a virtual screen: have your UI code draw to a virtual screen, encode the screen pixels as video stream and get receiver to play that stream. The former method is too limited and latter is too cumbersome (and likely infeasible without hardware support).

Also, AirPlay != AppleTV. There are plenty of third party stereos that can sit at the receiving side of AirPlay. With iOS in the Car, car makers can make their in-car display as AirPlay-compliant and allow Maps and other apps to display custom UI on it. I believe we would have seen third-party AirPlay-capable TVs by now if Apple did not have plans of building its own TV sets.


Posted

My take on Samsung vs Apple

My reply to the argument that all inventions should be commoditized.

I am all for all inventions must eventually become a commodity. However, if you look at the long term instead of just getting innovation to become cheap commodities available to everybody as soon as possible, some protection should be provided to the inventor so while cool new progressive "stand on the shoulders of giants" changes can keep coming, risky groundbreaking innovations can also emerge once in a while. Without effective patent protection, everybody will resort to do safer small-step improvements instead of spending years and billions to build (and market) something vastly different from what people are familiar with. In other words, with zero patent protection, you will still see cars getting better mileage, but you won't see an electrical car. You will also see more equivalent of pharmaceutical companies becoming more interested in making toothpaste instead of medicine.

If we want to argue for patent reform, we need to focus on the true patent trolls. Apple is not a patent troll and arguing against this will push many people to the other side of patent reform debate.

Posted

Draw - Google Correlate

Check out this website I found at google.com


My first thought was how is this useful? After reading the thread on HN, I realized I am the one who has totally no imagination. Draw a down-curve and find flash? Draw an up triangle and see Windows Mobile? Man, this thing is full of insights!

Posted

Google to pay $500 million over Canadian pharmacy ads

Google has agreed to forfeit $500 million generated from Canadian pharmacies targeting US customers through its AdWords program, the US Department of Justice announced today. The money represents revenue received by Google from the pharmacies as well as from unlawful sales made by the pharmacies to customers in the US.

Generally, it is illegal for pharmacies "to ship controlled and non-controlled prescription drugs into the United States from Canada," the DOJ states. Google acknowledged this as early as 2003, and yet allowed Canadian pharmacies to entice US customers to buy prescription drugs from their sites via AdWords advertising.

Transactions like these, with rare exception, violate the Federal Food, Drug, and Cosmetic Act because the shipped drugs are not FDA-approved. The problem is compounded by the fact that Canadian pharmacies shipping drugs to the US aren't even subject to Canadian regulations, so the pharmacies can sell drugs from countries other than Canada that meet neither Canada's regulations, nor the FDA's.

Google even provided customer support to the Canadian pharmacies, advising them on how to effectively place their AdWords ads. The company is now taking responsibility for the prescription drug rabbit hole it dug, and will forfeit a total of $500 million to cover both its own and the pharmacies' offenses.

"Google acknowledged this as early as 2003, and yet allowed Canadian pharmacies to entice US customers to buy prescription drugs from their sites via AdWords advertising." Why does this sound so familiar?

Posted

Jonathan's Card

There is a beautiful story named Jonathan’s Card listed on hacker news today. It is about an experiment on sharing a starbucks card – everybody can buy a coffee on this card, and everybody can also chip in if he wants. It has been interesting to see the balance up and down throughout the day.

Then there is an even more beautiful story on good infection.

My girlfriend and I were graduating from pharmacy school and she was applying for residency positions (yes, they have those for pharmacists). Well, she found out she got the one she really wanted and so that night we went out to a nice dinner to celebrate. We did it up like you would expect a happy couple to – nice bottle of wine, share an appetizer and dessert, etc. We were still living on loans at the time and so in my head I was keeping track of about how much the meal was going to run me at the end of the night (for better or worse – keep in mind we were in college at the time). We had easily cleared a hundred bucks (quite the meal for college students who usually eat $7 sandwiches or more likely cook for themselves!), and when it was time for the bill, our waitress told us “The couple that was sitting over there paid for it.”

And some people pay for bridge toll for more than just themselves.

Posted

Google's six-front war

Google is fighting a six-front war, and some are saying Google is sitting comfortably in their search advertising castle, and playing guerrilla warfare everywhere else. I don’t think so.

Don’t ever think Google is playing guerrilla warfare just to poke fun at the other guys while sitting on a pile of cash. The reason Google is attacking these companies is simple: they have become clear threats to Google’s core business – not search, but targeted advertising on the web. Apple’s race to dominance to the mobile space with its walled-garden approach was threatening the whole web-based and ads-driven model; Microsoft’s stronghold on browser market with an ancient browser was holding the web hostage and killing the potential of web as a service serving platform; Facebook keeps valuable information that is not accessible to Google bot and may even be able to develop the next big thing to replace search, not to mention that it is sucking the best talent; and it has been very clear that local advertising is where the future growth of targeted advertising will be from.

Google is being offensive and aggressive, and they are not comfortable about it when their core business – not search but serving ads – is being threatened.

Posted

On Native Apps

GitHub released its Mac client. It’s very top notch, and has a very modern feeling. rjh29 on HN wonders why GitHub would create one native app for one platform rather than basing on something like Qt to build a native app that works on as many platforms as possible. And I argue,

The definition of native app has changed. It’s no longer a synonym for compiled binary; or using native widget. It is not as simple as coding your UI in a cross-platform toolkit. In these days, a native app means something that feels like the built-in apps: it’s beyond skinning and appearance and is more about how the app as a whole interacts with the user to get the job done. As the platforms diverge, it’s now really hard – if not impossible – to make a cross-platform native app. Among Performance, Cost, Time, Scope, you can only pick three. GitHub sacrifices the scope.

catch23 else pointed out an interesting story on the use of cross platform widget set,

Reminds me of when Intuit was building out Quicken — most of their versions were built using cross platform tools, but inside the code it became a big mess and most recently they decided to scrap the whole thing and re-write the mac client in native objective-c instead of c++

After many years of pushing the concept of platform independence, we finally come to realize that it is not an excuse for end user independence. We should not favor developer convenience over user experience.

Posted

C++0x introduces a standardized memory model. But what does it mean?

People have been creating multi-threaded application in C++ for decades. What does a standardized memory model mean?
By coding rigidly to the spec, you can be certain that your code will compile and run without modification on any system with a compliant C++ compiler, whether today or 50 years from now.

Very well said generally about standards.

Posted

The Dangerous Mr. Khan

In The Wall Street Journal, Paul Boutin writes, “As we become increasingly dependent on the Internet for our view of the world, and as the Internet becomes more and more fine-tuned to show us only what we like, the would-be information superhighway risks becoming a land of cul-de-sacs, with each of its users living in an individualized bubble created by automated filters—of which the user is barely aware.” 
via nas.org

 

Posted