26 prisoners and a light bulb logic problem in python

I was sent a interesting logic problem by samsamsam which is as follows (or very similar):

Q: How can the prisoners tell, with certainty, that all 26 of them have visited the central living room with the light bulb.

26 prisoners are in solitary cells, unable to see, speak or communicate in any way from those solitary cells with each other. There’s a central living room with one light bulb; the bulb is initially off. No prisoner can see the light bulb from his own cell. Everyday, the warden picks a prisoner at random, and that prisoner goes to the central living room. While there, the prisoner can toggle the bulb if he or she wishes. Also, the prisoner has the option of asserting the claim that all 26 prisoners have been to the living room. If this assertion is false (that is, some prisoners still haven’t been to the living room), all 26 prisoners will be shot for their stupidity. However, if it is indeed true, all prisoners are set free. Thus, the assertion should only be made if the prisoner is 100% certain of its validity.


I won’t explain the solution in words as that might ruin it if you were planning on figuring it out, instead I have posted some python code that calculates the probability of number of days it will take.

# -*- coding: utf-8 -*-
from random import randint


# Loop 
for i in xrange(0,50000):


	# Create a set of prisoners with value 0 or 1
	# for having visited the room when light is off
	for i in range(0,nopris):

	# Until all prisoners have switched light on and have
	# been counted
	while count<nopris-1:
		# First person to be picked is the counter
		if days==0:
		# Counter adds one if light is on and resets it
		elif x==counter and light==1:
		# If light is off and prisoner hasn't turned light 
		# on before he does so
		elif p[x]==0 and light==0:

	# Expand our bin if it isn't big enough
	while days>len(bin)*binstep:

# Just chucking data into a histogram type layout
# to speed up processing afterwards (I'm crap at
# openoffice stuff)
for i in range(0,len(bin)):
	print i*binstep+binstep/2,",",bin[i]

For 50k iterations I got the following output:

$ python
25 , 0
75 , 0
125 , 0
175 , 0
225 , 0
275 , 0
325 , 2
375 , 31
425 , 162
475 , 636
525 , 1659
575 , 3492
625 , 5448
675 , 7134
725 , 7755
775 , 7103
825 , 5758
875 , 4341
925 , 2884
975 , 1701
1025 , 909
1075 , 511
1125 , 255
1175 , 124
1225 , 63
1275 , 25
1325 , 4
1375 , 2
1425 , 1

Which shown as a histogram looks like:

Histogram for the 26 prisoners problem (50k iterations)

Histogram for the 26 prisoners problem (50k iterations)

Let me know how you’d improve this method or any other cool logic problems I can have a go at 🙂

Read More

Orange San Francisco (ZTE Blade) for £87.10 with cashback

Orange are offering a really nice large screen android phone for a great price, so I picked one up for my dad and flashed a custom rom onto it. They have dubbed the device the San Francisco, but it is otherwise known as a ZTE blade (specs on wikipedia)

How to get it for £87.10

  • +£12 Go through a cashback website like quidco and click through to the orangeshop
  • Once at the website goto orangeshop student select PAYG and enter your NUS code or just enter 000000000000000 they don’t verify it!!! for a 10% discount (this was a tip off from someone at droidcon, but I didn’t manage to catch name please let me know if it was you and you can have the credit)
  • £99 + £10 Topup Select San Fransisco in Gray or San Fransisco in White
  • -£9.90 Your 10% discount will now be applied ^_^ Choose which tariff you want, I chose dolphin as you get free internet and 300 texts when you topup £10
  • Total £87.10, win!

It’s a good phone and it’s very easy to flash a custom rom onto if you don’t like the orange one. I got the rom and followed the guide at modaco.

Read More

Review of day 2 of droidcon uk 2010

Following on from the review of the previous day at droidcon uk 2010, Here is a brief review of the second day at the conference. Apologies for the terrible photos and some fragmented text!

Again as this is quite a long post here is a mini table of contents to speed it up:

Excellence in the Android User Experience

Romain Nurik talks about creating applications with great UX and great UI, this follows on from a similar presentation he has posted up on slideshare.

Roman Nurik making android pretty

Roman Nurik making android pretty

Android reuse models

Mark Murphey discussed some of the ways in which we can reduce lots of android developers reinventing the wheel everytime we need something. There are a few methods that a developer can use for distributional:

  • Souce Code
  • As an Application
  • As a jar
  • Library
  • Combine the two above methods, and distribute a jar in a library. As we don’t live in a perfect world source code cannot always be distributed (Remember to create a licence)

Libraries can be used to solve problems for people who want free and paid versions of the app, and don’t want to maintain two versions of the code. Google have shown a google example by creating the LVL code as a library for app developers to use.

Resource name collisions can still be a problem, but this can be solved by using a prefix that is unlikely to be used by the child application. Mark shows an example of this in his color mixer widget that uses “cwac_colormixer” as a prefix. You can find lots of mark’s cool projects on his github: githubcom/commonsguy

Mark went on to discuss that we need a place to collect code to reuse and mentioned building a community website for this purpose, also saying “I can’t write a website to save my soul, I ain’t doing it!”

During the talk/questions, a great open source view was mentioned Swipe view by @jasonfry which is like view flipper but the animations between the views are not static and more like the home screen.

Make it fun

This was basically a demo of using the Unity 3D framework for creating applications that can be run on iphone/ipad/android/wii/computer. Seemed to have some cool features but I will let them do their own sales talk.

Monetize your apps in emerging markets

This was an interesting talk by a guy from movend who discussed the concept of marketing your apps to emerging markets. For a lot of people in emerging markets the phone is the only access to the internet, social networking, and gaming/entertainment device.

He had some intersting statistics on mobile phone payments. Asia Pacific accounts for $62.8 million in mobile phone payments and the rest of the world only accounts for $45.8 million. The market for mobile app revenue is estimated at $135million for 2009 and at $4 billion for 2010.

Market is extremely fragmented, android market does not exist in certain countries/handsets. Try to get your application pre-loaded onto a phone and target what specific users like. Apparently the Chinese like to play mmorpg the most. Micro-transactions are a great was to add value to a free application.

Android has a “dude” problem

Lady geek and ladygeektv

This presentation started with a great slide:

Ladygeek android penis

Ladygeek android penis

Only 5% women want an android phone whereas 50% want an iphone. She goes on to discuss why we as developers should care. Apparently women buy more gadgets than men, and between the ages of 25-39 there are more female gamers than men!

She then used this awesome droid advert as a demonstration of how android is currently marketed which contains the awesome quote of “Race horse duct taped to a scud missile, fast”

Android behind the scenes

Sony Erricson sharing some behind the scenes information about how they work on android.

They were constantly trying to remind developers that they are very open and are contributing changes upstream to the android project. They are interested in decoupling applications from android so that signature apps are built on top rather than into android. I believe they said this was the case for their sexy timescape view:

Sony Ericsson Timescape

Sony Ericsson Timescape

Sony Erricson want to be very in touch with devs and they don’t believe creating seperate communities will help anything and instead will provide support in current communities such as stackoverflow and google groups.

They briefly mentioned the Ericsson application awards 2011 which has a theme of “Connected things” and has 4 prizes of 15,000 each with phones awarded throughout different stages of the competition. They will also provide live beta testers to evaluate your application.


We had a quick play on some of the cool new android tablets.

Android Tablet

Android Tablet

There were some free android usb sticks, which someone said were from orange but there was no branding on or nearby them.

Android 2gb usb stick

Android 2gb usb stick

Read More

Review of day 1 of droidcon uk 2010 (barcamp sessions)

Below is a short overview of some of the stuff that I saw a droidcon today (Day 1: Barcamp), I was hoping to write more but it’s late and I can always update this post. Apoloigies to those who I did not manage to get the names of, I can update this post when I find out who you are 😛

As this is quite a long post here is a mini table of contents to speed it up:


Barcamp schedule (sorry for crap pic)

Barcamp schedule (sorry for crap pic)

Git on android

This was a really surprising talk, just by the name it’s a little confusing as to why this would be useful but it was a really good talk. A guy from who works at the guardian (need to find name) walked through all the problems he came across when trying to use git on android and how using open source goodness he could simplify a lot of trouble by simply extending pre-written code and even create work arounds for troublesome bugs.

It was a very interesting talk just to see how everything had fitted together and to see a demo of some sexy git-based syncing, including using some ssh agents securely.

Swing me

Draft still…too tired to write.
A single UI widget toolset that can easily be ported to other operating systems. Uses guestures pinch zoom all the things you would be used to. Non-android specific code and can specify protocols nicely to cooperate with different devices. Removes hassle on behalf of developer, debug using xml, then switch to binary mode for performance
Difference between keys on certain phones… assign buttons, like “back” as a button on phones with dedicated back buttons ie nokia soft key hidden and at bottom, android will hide it and use android hardware back button. IE. unhidden back button not hidden (good solving of problem)

Problems with accessing core bits of anroid but private/protected stuff. Radio easy but problem with tick box.
Missing clipboard (almost finished, work on android, symbian, desktop… lol @ apple)
Still use native android based stuff

Google Bootcamp 1

So there were four google guys present to answer the questions and complaints of the developers and one to pass the microphone around.

Google Barcamp 1

Google Barcamp 1

Someone asked when Gingerbread was going to be released and Reto Meier answered by not confirming anything regarding the release date, be it this year or next. He even went as far as to say that he couldn’t confirm gingerbread’s existence, despite the rather large statue outside building 44

Roman was asked a question about the Action bar and if it was going to become a standard widget in the android apk, he said that it wasn’t currently part of the widget set and couldn’t confirm when it would be added.

Reto mentioned about in app purchasing and said google was looking into other method to monetise can’t comment on specifics. However in app purchasing currently is against the google TOS, so you might want to be careful if your app has this and is distributed via the google market. Of course this is fine to do if released on to another app store such as and app, doubtful that orange and vodaphone app stores would be so generous.

Google tv was mentioned and how to write android on it. Currently only html 5 / web stuff but as it is based on android the plan is to be compatible. So we are waiting for compatability hopefully sometime next year. The google tv’s should receive market via OTA updates so there will probably be no need for OEM manufactures to get in the way. Media server such as a upnp server, status is currently unknown.

In app google analytics was mentioned and another barcamp talk was refered to which unfortunatly I missed, if anyone went to this and has written it up I am happy to add the link in here.

In app logic – services/content providers global = bad, shared prefs, instance state mainly for UI shiz. setters/getters saved pref/database on logic. check if its been set etc. roman/reto

Someone briefly asked about adverts without using the internet permission and instead using an addon/plugin which did access the internet. Currently it seems this is not possible at the moment but is something they may look into in the future.

Have I missed off any of the other topics discussed during this bootcamp, if so let me know!

Alternative Markets

Draft still…too tired to write.
Vodaphone – incentive – random draw to win a htc legend. 30 70 split
Orange – 30 70 again (yawn) want good apps, as many as possible pay via phone bill, no registeration, france/uk last year. need several countries/languages arabic/african etc.
Nokia – no alternative operators, content agregator, locilzation/adaptation/uploads etc… Sensing, in app billing

Individual / OS devs fetching market data/pulling to diff apps sotres as we dont have the time to move to diff places

App stores share with other stores, very nice
Orange apps tied to network you lose them if you move 🙁

Meta-Market Model

This talk tied in very nicely with problems regarding using alternative markets discussed in the previous talk. Mark Murphey (Commonsware) discussed an alternative to writing open letter to google (as was discussed via email) about the android market. He created a brain stroming session on the market problems and what can we can do as a community to help improve this for ourselves (devs) and for users.

Mark Murphey Meta Markets

Mark Murphey Meta Markets

Some of the good problems highlighted by people were:

  • Comment spam, and no way to “Reacting to punters” or dealing with users who are “dissing” all apps
  • Not enough screenshots / descriptions / add videos etc…
  • Searching the market is terrible (My contribution)
  • Analytics
  • Email messages about cancelled users every time
  • Refund policy too leaniant
  • Option to explain the reason behind each permission as users don’t know what’s going on when you can’t fit an explanation in the description
  • Better rating levels, UI/UX etc.
  • Downloads don’t work

The market on android is improving at a “Glacial pace” and even though there was some sexy stuff demonstrated at Google IO 5 months ago we are still waiting to see the improvements, such as a web based market that can push applications to devices.

There was also a good discussion about the websites that scrape data from the android market (appbrain, cryket, androidzoom)which is kinda sketchy territory as it is probably against TOS of android, kinda counting as pirated data. There is even a google code project to fetch the data from the android market.

Data goes in data doesn’t come out
Pirated data not supported by data cant rape data from market.

So what makes this presentation more than just a compaint about the android market?
Market is a closed club, OEM’s who don’t agree to the rule book don’t have access. And simply creating a app store for each carrier/OEM etc. isn’t a viable solution which Mark summarised with a brilliant quote: “those who complain about fragmentation you ain’t seen nothing yet”.

So Mark has come up with an idea about having a single open feed of android applications that all the market applications can hook into. So this would work as some sort of extended atom/rss feed (just add namespace) with open access which could benefit from the standards introduced and the maturity of the software already written. This sounds like a great idea but will obviously need a large amount of momentum to succeed, Mark is obviously a major player in the android field and this proposal was backed up by the developer of AndAppStore.

Mark also mentioned that even market owners who were unwilling could be worked-around using a firefox plugin to remove most of the leg work. So this would mean that developers can have a single place where they have the app description, screen shots, all the minimums required for android market but more for those who support more.

To wrap up mark said that instead of us complaining at google to fix the market we should fix the market problems ourselves. At the end of the session Mark was collecting email addresses to create a mailing list with regards to the start of this process.

How I do it

Kevin McDonagh of Novoda gave some brilliant tips and tricks for writing android applications. I’ve written some of them up, but hopefully he will publish his whole list online (hint hint…)

public void onLowMemory(){
// Code to execute on low memory
// Free up unused drawables etc.
  • Use weak references
  • Avoid Generics, use primitives where possible
  • Clean up drawables onPause()
  • Use the heirachy viewer

Kevin also mentioned some stuff which I’m sure I should have come across before but for some reason I was still oblivious to.

Extending styles to avoid having to retype android:height=”wrap_content” etc. on every item.

There was some good discussion on the conventions for android:versionCode and android:versionName and someone mentioned very helpfully that versionName appears in the market description and is limited only to 255 chars, which means you can add additional versioning changes into this (shown below a screen shot of nexus revamped in the market with the versionName highlighted).

android:versionName displayed in android market

android:versionName displayed in android market

Apps for good
Apps for good is a charity that gets a group of people between the ages of 18 and 25 and gives them the resources and skills required to create an application that can benefit society. Once students have finished the course they often go on to mentor the next batch of students.

The apps they have already produced on this scheme are Stop and Search StudentVoice StudioPhly and they discussed a up and coming app they are working on currently so that the balance of an oyster card can be checked via a android device so that you are never caught out.

They are looking for help so if you are feeling charitable I am sure they would appreciate your input or if you know of anyone 18-25 who would like to go on the course, please inform them of the opportunity.

Google Barcamp 2

Ok, so this barcamp was delayed and I think alot of the better questions were already asked, that in combination with my laptop battery dying mean I have less notes and worse memory about this one.

Google Barcamp day 2

Google Barcamp day 2

Bundling several apps into one installer apk, currently not possible. Could be achieved by having a program that sends intents to install other apps, or by having one large app with serveal launcher items in the app menu.

Tips from tech hub:

  • Devs arn’t always design focussed, should assume users are complete idiots and don’t understand anything.
  • Ported apps don’t act in an android style – back button doesn’t close etc, as devs don’t understand application lifecycle

App Circus
So app circus had a bit of a disappointing number of contestants, about 6 I think it was in total hopefully next time there will be more. The winners were

  • 1st: Swiftkey
  • 2nd: — Blind something? Sorry forgot the proper name
  • 3rd: ProductPay


Coding in a hammock and drinking beer

Coding in a hammock and drinking beer

I also met a lot of very interesting people and plan on meeting a whole load more tomorrow!

Read More

Better android keyrings

Woo, got some more android keyrings! This time I went for some extra colors as well as the green ones. These ones are more vivid and slightly smaller than the previous batch which is an advantage because you can now easily thread them through their own hoop. They also look like they will be a little more durable.

multi-color android keyrings

multi-color android keyrings

multi-color android keyrings

multi-color android keyrings

lots of multi-color android keyrings

lots of multi-color android keyrings

Comparison of old and new android keyrings

Comparison of old and new android keyrings

Read More

Android market is expanding paid apps to more countries

Brilliant news from the android market.

Subject: A Message from Android Market
From: Android Market Support
To: android .at.
Date: 25/09/10 00:03:32


We’re writing to inform you about some changes to Android Market that require your attention.

Over the next few weeks, we’ll be adding paid apps support for additional countries. If you have selected to publish your paid apps to all locations and intend to support all new locations as we expand the number of supported countries for paid apps, you don’t have to do anything. If you have selected to publish your paid apps to all locations but intend to only target the currently supported 14 countries, please update your location selections to target these specific countries.

Please look for follow-up emails when we introduce paid apps support for specific additional countries in the coming weeks. At that time, you’ll have the option to target these specific countries.

Thanks, and we look forward to continue working with you on Android

The Android Market Team

Google, Inc.
1600 Amphitheatre Parkway
Mountain View, CA 94043

Email preferences: You are receiving this email to notify you of important changes to your Android Market account.

Read More

Quick Review of Amazon Kindle 3G (plus some images and microscope images)

I recently ordered an Amazon Kindle 3G as I wanted an ebook reader to read papers and some of CommonsWare’s great android books and the kindle seemed like excellent value for money. It arrived today so here is a quick review along with some pictures:


  • Cost – Only ~£150
  • 3G – Free browsing web over 3G (worldwide!)
  • Wifi – For quicker browsing / downloading, works well no hitches.
  • MP3 Player – With speakers or headphone socket
  • Text to speech – So you don’t even have to read your ebooks any more, it even turns the page for you! The voice is quite good sounding only partially robotic; It manages pauses well with brackets, commas, etc. but sometimes doesn’t pause properly between paragraphs. Also some obscure words are mispronounced. I don’t know how good this would be for reading fiction as an audio book but this isn’t likely a feature I will be using much.
  • Viewing angle – due to the technology of the screen (E ink), you can still see the screen irrespective of angle (unless view is physically obscured obviously…)
  • – Screen is visible in direct sunlight unlike AMOLED phone screens
  • Supported formats – Supports MOBI (kindle), PDF, EPUB
  • Fits in my pocket – Just about fits in my pocket, with only a bit sticking out, this would obviously not be suited for long distance but as temporary holding place it is just fine.


  • White is grey – Okay so the background is not completely white, more greyish, but I don’t really care it is still very book-like.
  • Scientific papers – Two column journal papers are a bit awkward to read or navigate using the current zoom settings


  • You could fit about 26,000 into a olymic sized swimming pool


Amazon kindle 3G reading a nice android pdf with images

Amazon kindle 3G reading a nice android pdf with images

Amazon kindle 3G (Experimental settings; Web browsing, mp3 player, and text to speech)

Amazon kindle 3G (Experimental settings; Web browsing, mp3 player, and text to speech)

There is a choice of which country you’d like to view newspapers from and in the UK there is a choice of 5 (Telegraph, daily mail, independent, financial times, and London evening standard notably the Times is missing… what are they playing at?) all of which offer a 2 week free trial of the newspaper or the purchasing of single issues or a monthly subscription (prices vary).

Newspaper subscription on kindle (free 14 day trial on most subscriptions)

Newspaper subscription on kindle (free 14 day trial on most subscriptions)

Daily Mail viewed on the kindle, no crossword or puzzle page though :(

Daily Mail viewed on the kindle, no crossword or puzzle page though 🙁

Microscope images
And as usual when I buy something new and exciting I have to look at it under a microscope 🙂

Amazon Kindle 3G display (No mag)

Amazon Kindle 3G display (No mag)

Amazon Kindle 3G display under microscope (Low mag)

Amazon Kindle 3G display under microscope (Low mag)

Amazon Kindle 3G display under microscope (High mag)

Amazon Kindle 3G display under microscope (High mag)

Read More

Nexus Revamped Pro Live Wallpaper 1.1.16 update #android

Nexus Revamped Pro has just been updated to version 1.1.15 and with that come lots of exciting new features as well as many bug fixes!

1.1.16 Changelog

Minor update to fix a few bugs and add a few more things I did have time to include in the previous update. Should also increase performance and reduce FC/OOMs

  • Added: Particle glow saturation (Particle > Saturation) to control the saturation of the glow around the particles
  • Added: Added a preview of how the particle will look in the saturation dialog
  • Added: Some people prefered the old particle look so I have added two buttons on the saturation to reset these values to either original nexus like (original) or like my previous ones (revived)
  • Moved: More apps and Feedback are now under the Developer option
  • Improved: Parallax and scale are no longer marked as experimental
  • Bug Fix: Particles sometimes not properly aligned to grid on preview
  • Bug Fix: Improved bitmap loading performance loads this should also get rid of most the FC/OutOfMemory errors
  • Bug fix: Battery effects only started working once a battery update was given, now they work instantly!
  • Bug Fix: Particle glow circle was truncated, now fixed!
  • Bug fix: Touch location when using scale is fixed (still need to fix rotation)

New Saturation Options

This is in addition to the other particle options (tail length and custom colors) you can now completely customise how the particles look with the new saturation settings. Some users disliked the change I made to more closely resemble the original design wallpaper by romainguy so I had added an option to choose between one like his particles (original) and like my previous particles (revived).

New saturation options in nexus revamped pro

New saturation options in nexus revamped pro

I have improved the way in which bitmaps are used which should take up far less memory. This will likely prevent the OutOfMemory errors some people were getting and remove the change of a force close. I have tinkered with a few other things which should provide better performance.

I have put off the video until this version was released so this should be along shortly (the first videovideo is very outdated now)

Android Market Links
Either click the following android market links (in android phone) or search the market for nexus revamped.
Pro Version
Nexus Revamped Pro Live Wallpaper (com.stealthcopter.nexusrevampedpro)


Free Version

So the free version is a few versions behind the pro version and some of the fancier features are missing, I am constantly improving both so don’t worry if you don’t want to shell out £0.99 for an app.

Nexus Revamped Live Wallpaper (com.stealthcopter.nexusrevamped)

Download link


I have plans and ideas for the future of this application, please complete the poll below to indicate what you’d like to see in this app or leave feedback (comment) if you have any.

What would you like to be added next to nexus revamped pro?

View Results

Loading ... Loading ...
Read More