Thoughts of a geek

25 May 2019

Fairy light controller

Filed under: Computers, Electronics — Tags: , , , , , — qwandor @ 12:34 pm

One of my housemates has a lot of fairy lights. Most of them were battery powered, each by a little pack of 3 AA batteries, which seemed somewhat wasteful. They are great for parties, but turning them all on and off individually is kind of a pain too, so I wanted to make them mains powered, and controlled from Google Home. And as I mentioned in a previous post, I’ve been playing with ESP8266s recently, so I built a controller based on the D1 mini board.

The first version I prototyped with a dual H-bridge board I had sitting around, using each half-H separately so it could control 4 strings of fairy lights, just twisting some wires around the battery terminals. It was a bit messy though:

First prototype, fairy light controller V1

So next I made a somewhat neater version on some stripboard, using a dual H-bridge chip I had sitting around, but with a pair of screw terminals per output rather than just a single ground connection to make it easier to use. I also added some header sockets that could be used to put a resistor in series with the output easily. This meant that rather than being quite so hacky with wires twisted around the battery terminals I could cut the battery box off entirely, unsolder the resistor from there and put it into the socket on my board, and then just connect the wires from the lights themselves to the screw terminals. This made things a bit neater:

Fairy light controller V2, H-bridge chip on stripboard

I also happened to have a bunch of power darlington transistors sitting around, so I made an open-collector output version with them. This let me add the option of using a separate power supply for driving higher voltage loads, rather than just using the same 5V USB power supply as the D1 mini. It was also a bit smaller. (The white terminal block on the left is the power supply input, and the jumper next to it connects it to the 5V from the USB power supply instead.)

Fairy light controller V3, open-collector outputs and an optional separate power supply.

This worked well and was certainly an improvement, but stripboard is still a bit messy, so I decided to make a proper PCB for it. I also found a handy chip with 7 darlington drivers, so I used that. 4 channels still seemed enough so I hooked 3 pairs up together in parallel for higher current capacity. I designed the board on EasyEDA (link at the end if you want to order some for yourself) and ordered 10 copies from JLPCB in China (PCB prototyping services are amazingly cheap these days!) along with the parts, and a few weeks later they showed up.

Fairy light controller V4, all soldered up neatly.

It was indeed neater, so I think this will be the final version. It works well, controlling the fairy lights in the living room.

On the software side, I was able to share a bunch of common code (for the web admin interface and so on) with my previous smart button project. For integration with Google Assistant and Google Home I went via Sinric, which provides a server that the board can connect to, and then can connect to the Google Smart Home API. It’s still a wee bit of a hack at the moment unfortunately, as the Sinric Google Home integration isn’t properly launched so you can only use it in developer testing mode, but other than that it works well. You can track the status of the Sinric launch on GitHub.

If you’d like to make one for yourself, you can find the schematic and PCB design here on EasyEDA ready to print, and the source code and setup instructions here on Gitlab. (See the ‘Smart switch’ / qSwitch section.) And there are a few more photos here. Let me know how you get on!

[edit] Oh, and if I know you / you live in London, I have 9 spare boards and most of the parts available, so if you’d like one let me know. You’ll just have to get your own D1 mini and terminal blocks. Happy to help get it working too.

Advertisements

11 May 2019

Balfolk May Weekend

Filed under: Photos, Travel — Tags: , , , , — qwandor @ 2:37 pm

I went to Krakow last weekend for the first edition of the Balfolk May Weekend, a lovely little festival that some friends of mine organised. There was lots of good music, good friends, good dances and good hugs. I like small festivals, I find them more friendly, and there’s less of a problem of not having enough time to dance with everyone. This one had around 80 people at the bals, and fewer at the workshops.

I stayed on a couple of days afterwards to spend time with some friends and hike a little nearby. And it turned out that there was a blues dance event on the Monday night, with a great live band, so I ended up going along to that too, as did a bunch of other people who were still in town from the festival, as well as some of the local balfolkies. It also happened to be in the same venue as the festival, so it was almost like a continuation of the weekend, though without all the decorations.

As usual, I took some photos, so check them out for more details.

25 April 2019

Jordan

Filed under: Photos, Travel — Tags: , , , , , — qwandor @ 10:46 pm

Seeing as Google+ is no more, I’m going to try posting links to photos on here again. I recently went to visit Jordan for a week, to visit some friends and sightsee for a bit. This post will mostly just be links to photos, so do follow through to the albums and see the captions there for more details.

Some of the time I stayed with a couple of friends (Karin and Laura) in Amman, and explored a bit of the city.

With Karin, we caught a 6:30 am bus to Petra, and spent two days exploring. The first day it was raining on and off, and then pouring from mid-afternoon so we had to cut our visit a bit short. The second day was a bit cold and windy but otherwise fine, so we had a full day to see everything we wanted to see. We stayed two nights in Wadi Musa (the modern town just outside Petra), and then caught another early bus to Wadi Rum the next day.

We spent one day and one night in the Wadi Rum desert on a tour. The first few tourist sites were full of people, but climbing the bigger rock arch was a nice quiet hour each way and a fair scramble.

We just spent a few hours in Aqaba after leaving Wadi Rum before catching a bus back to Amman. There wasn’t that much to see.

Back in Petra we took a number of day trips, starting with a day going to Mount Nebo, the baptism site of Jesus, the Dead Sea, and Madaba.

On the Friday all three of us joined an organised hiking group doing a section of the Jordan Trail, from (near) King Talal Dam to Rmeimeen. Sadly it was mostly on roads.

The final day trip was to the old Roman city of Jerash, and Ajloun Castle nearby. Many parts of it were impressively well preserved!

24 December 2018

Smart homes and ESP8266s

Filed under: Computers, Electronics — Tags: , , , — qwandor @ 11:42 pm

I’ve recently been playing with a bunch of smart home stuff, based around the Google Home ecosystem. I have a Google Home, Google Home Hub and JBL Link View in various rooms, a Chromecast and Chromecast Audio, a Nest thermostat, a bunch of cheap smart light bulbs, and some Sonoff switches for the ceiling lights. It’s pretty cool: I can control the lights and music all around the house by voice, from the smart displays, or from my phone.

But there are a few things missing. As cool as voice control is, sometimes I just want to press a button and have it run some preset action, like turning all the living room lights off late at night when I’m heading up to bed (without waking up my housemates), or turning on all the fairy lights for a party (when the background noise is too loud for voice control to work reliably, and it’s a bit awkward anyway).

Happily, AliExpress has lots of ESP8266 dev boards from as little as £1.70. The ESP8266 is a little microcontroller with a WiFi stack and fairly low power requirements that makes creating WiFi-attached gadgets pretty easy. It can be programmed (among other options) in C++ with with the Arduino libraries. For a nicer development than the standard Arduino IDE I used PlatformIO, which adds a proper IDE and dependency management.

My first approach was a stand-alone button. This can be battery powered, and stays in a low-power standby state (or entirely off, with a little extra support circuitry) until it is reset, at which point it starts up, connects to WiFi, sends a command, and goes back into standby (or powers down). This works well, though I didn’t get as far as finding a nice way to package it up. Without making custom hardware it’s a little bulky, with the battery and everything.

An ESP8266 dev board connected to a Li-ion battery.
An ESP8266 dev board connected to a rechargable battery.

So I tried a different approach. The Sonoff RF Bridge is widely available on AliExpress and elsewhere for under £10. It contains an ESP8285 (basically the same as the ESP8266 but with built-in flash) and a 433MHz remote transmitter and receiver controlled by a separate microcontroller, connected over the serial port with a documented protocol. With the stock firmware it can clone your existing remotes to control whatever devices you may have controlled by 433 MHz remotes, which was not very useful to me. However, the firmware can easily be replaced by simply opening the case (4 screws) and soldering on a 4 pin serial header to the labelled row of holes on the PCB. AliExpress also has lots of nice wall-mounted 433MHz RF buttons that look like normal light switches and can last a long time on a small battery.

With that in mind, I built some replacement firmware for the Sonoff RF Bridge, that lets you pair it with many such buttons, and associate each one with a different command to send. This works really well! I have the RF bridge sitting plugged into USB power somewhere out of the way, connected to my WiFi, and waiting for signals from the buttons I now have mounted around the house to send commands.

A Sonoff RF Bridge connected to USB power.
My RF Bridge glowing happily in the corner.

What I haven’t mentioned so far is how I send commands. Google Home doesn’t yet have a proper API to connect buttons like this, but what there is an API for is sending Google Assistant commands from other devices. These can be either voice or text; of course in this case I went with text. So when one of the buttons is pressed, I can send an arbitrary Google Assistant command, like “turn off the living room lights”. It takes a couple of seconds to respond, but otherwise works pretty well.

If you’d like to try either of the above, you can get the source code here, along with some more documentation of how to set it up. Once you’ve flashed it onto your device there’s a web interface which should make it easy to connect to your WiFi, authenticate your Google account and set up whatever commands you want.

If you do try it, please let me know if it’s useful! Or if you have any trouble getting it working or find any bugs, let me know too.

Next up (and in the same repository above, if you can’t wait), how I control lots of fairy lights. Until then, have fun, and Merry Christmas!

17 January 2016

Christmas and New Year

Filed under: Photos, Travel — Tags: , , , , — qwandor @ 5:13 pm

I spent Christmas in London this year, so it was pretty quiet. I still find Christmas in winter weird, it’s all cold and miserable, and I find London winters hard. The afternoon of Christmas Day I went over to my friend Matthew’s place for Christmas dinner, which was nice. His parents and some of his siblings were visiting from Paris (they are originally from NZ, more or less), and there were a few other kiwis too.

I took the 3 days between Christmas and New Year off, and the Monday after New Year, and went away for just over a week to Bratislava, Vienna and Brno. The main point of the trip was to go to the Vienna Folk Marathon, but the flights worked out cheaper (and I thought it would be interesting to visit a couple of new cities) to fly into Bratislava on the Monday morning, spend the afternoon exploring the city, and catch the bus to Vienna that night. In Vienna I stayed with Thi, a university friend from Wellington who now lives there with her boyfriend, which was nice as I hadn’t seen her in ages. After the Folk Marathon I caught a train to Brno on the Sunday afternoon and spent a day and a half sightseeing there (and touring the cafes as it was too cold outside, -7°C with snow and wind most of the time) before flying back to London on the Monday night. My flight back was delayed almost an hour for de-icing, which meant I finally arrived home at about 1:00 am Tuesday morning.

On the whole it was a good trip, but cold. I caught one cold just before Christmas, which I was just getting over as I arrived in Vienna, then caught a second cold towards the end of the Folk Marathon, which made everything less fun. The other annoying thing was that it is still legal to smoke in bars and so on in Austria, and although most of the venues were supposed to be smoke-free for our events, there were still people smoking in almost all of them, which several times forced me to leave. I’d like to go back to Brno sometime warmer, as there was more to see which I didn’t because I was too cold and couldn’t stay outside any longer.

For more, see the photos: Bratislava, Vienna and Brno.

14 November 2014

Much dancing

Filed under: Me, Photos — Tags: , , — qwandor @ 5:23 am

I spent two recent weekends at two quite different folk dance festivals, neither of which I had been to before.

The first was Dance Around the World at Cecil Sharp House in London, and was quite varied. It ran all day Saturday and Sunday, with three streams of workshops plus one of performances during the day, and dances in the evening. It attracted mostly an older crowd, though a bunch of young people too, varying a lot from workshop to workshop. Some had 8 people, some 50. A few friends (including Jenny) also attended some or all of it. Highlights of the workshops for me were Irish Set, English Clog, Latvian and Greek, though the others were interesting too. (I also did the Polish, Lithuanian, Bulgarian, Bolivian, Tango, French, Caribbean Quadrille, Nineteenth Century Quadrille and Jamaican Quadrille workshops.)

Saturday evening there was a French (Balfolk) dance night which was excellent. Two great bands, lots of cool people, lots of great dances. Sunday evening there was an ‘Anglo-International Barn Dance’ which turned out not to be very interesting, and a swing dance night hosted by Swing Patrol which was alright, though there were not that many people. It was nice to have plenty of space and a nice floor though, and I did get some good dances.

The following weekend was Skint, which was excellent. It runs annually in a parish hall in Ashover, a bit south of Sheffield, and is limited to around 100 people. Tickets sell out in minutes. The name apparently refers both to ‘Scandinavian and International dance’ and the fact that it is really cheap (£45 for the whole thing Friday–Monday including meals and accommodation? Woah!) Dances are primarily Balfolk (French, which I really enjoy) and Scandinavian (which are also interesting, though not so much my thing), though with a mix of other styles as well. Workshops were all taught by volunteers; there were three at once during the day, usually one dance, one music, and the third either another dance or something different. We all took turns to cook and clean and ate all meals together. Each evening the main organised dance ran until around midnight, then there was midnight cheese (an excellent idea!) then more dancing in a smaller room with any musicians who wanted to join in playing whatever they felt like. Probably half the people there played at least one instrument, so there were never any shortage, and often the musicians outnumbered the dancers at the late night sessions. Dancing in the middle surrounded on all sides by a circle of 20 musicians playing all sorts of instruments was magical. There were a lot of great dancers as well, and I had a bunch of switch dances (mostly French schottisches and mazurkas) which was cool, trying to spread the idea. I ended up dancing until about 2:30 am on Friday night and 3:30 am the following two nights, so really did not get enough sleep, but it was worth it.

I took a few photos (also on Facebook) but Ben and David posted some much better photos.

On Saturday I did the Fandango, Contra, Polska, Irregular Waltzes and Sønderhoning workshops. On Sunday I did Playford, the first half of the Swedish waltz workshop, found I was not getting it so gave up and went to try singing Sacred Harp instead, “Out of Body Dancing” (which was a fun experimental workshop about connection and musicality, sort of) and Wallonian / Flemish. Monday did not have any workshops, sadly, mostly just cleaning up. All in all, an excellent weekend, and lots of new friends! I highly recommend it, and will be going back next year.

Skint 2014: Fiddlers in the sun

Now to decide whether to try Copenhagen Folk Marathon, and perhaps some Balfolk events further afield next year…

4 October 2014

Geotagging photos with Google Location History

Filed under: Computers — Tags: , , , — qwandor @ 12:14 pm

When I take photos on my Nexus 5, it automatically geotags them, which is great. However, when I am on holiday, I often use a proper camera with a bigger sensor and lens as it can produce better results. The disadvantage of this is that it does not have a GPS so cannot geotag the photos I take. Fortunately, I have Google Location History enabled on my phone, which records my location periodically. I use digiKam to manage my photos, which has a feature to correlate photos with a GPS track by timestamp. Here is how I use this to geotag my photos:

  1. Enable location reporting and location history on phone. In Android this is under Settings→Location→Google Location Reporting.
  2. Ensure camera clock is correct.
  3. Take photos.
  4. Go to the Google Location history web interface, select the relevant days, and click Export to KML.
  5. Convert the KML file to GPX with this GPS Visualizer tool. Unfortunately the converter has a bug: the KML file has a timezone of UTC-7:00 for all timestamps, but the converter ignores this and treats them all as UTC. We will have to compensate for this in the next step…
  6. Select the relevant photos in digiKam, and click Image→Geo-location from the menu. Load the GPX file you downloaded in the previous step. To compensate for the bug mentioned above, you will need to set the camera time zone option to 7 hours ahead of the actual timezone your camera was set to. So if you were taking photos in UTC+2:00, then set it to UTC+9:00.
  7. Click Correlate. Check that your photo geo-locations look correct. If they look wrong, ensure that you got the timezone right. If they look right but some are missing, try enabling the Interpolate option.
  8. Apply and Close. Done!

1 January 2014

Seven months

Filed under: Me, Travel — Tags: , , , , , , , — qwandor @ 10:14 pm

I really have not blogged much in ages! A lot has happened since May. Other than Morocco, let’s see:

A friends (Emily Swan) was in town for a few days in June, I caught up with her all too briefly for lunch. Wow, that seems so long ago. Briefly saw another friend (Jordan) around the end of June or beginning of July too.

European Blues Invasion was at the end of June, and was amazing. Lots of really great dances, learnt some new stuff (hmm, I suspect I have forgotten most of it by now), and got into switch dancing. Not quite the first time I had done any switching, but the first time I really got into it. Made a few new international friends too.

Sarah was in London for a couple of days in the middle of July. Jen got a group together to go along to the first day of the Ealing Blues Festival, which was fun. Lots of great music, and great weather for sitting out in the sun with a picnic. I think we paid £5 for the day, for probably more than 30 different bands. Babajack were particularly good. Our team offsite to Croatia was straight after that, which was also fun. I got sunburnt on one of my legs because I forgot to apply sunscreen before going white-water rafting, and of course spent several hours facing in the same direction with the sun shining on one side of me.

I enjoyed some of the free outdoor dancing over the summer, though did not make it to as much this year as in past years. I mostly just went to a few of the swing dance ‘picnics’ at the Victoria Embankment Gardens, which had a mix of DJed and live music.

I went to Belgium for a long weekend at the beginning of August; 2 days in Brussels with Aga, and 2 in Bruges by myself. Both were interesting to see. Alex was in London the following weekend; it was good to catch up with him briefly.

Daniel came to stay on his (indirect) way back to NZ from Germany. He was going to stay with some other friends, but they ended up being a long way out of London so he stayed at my place for almost a week instead. He came along on a walk from Salisbury to Stonehenge that a friend from church organised, which was fun. The weather was great, and we even ran into a medieval festival at Old Sarum along the way. We arrived at Stonehenge in the end with only a few minutes to spare, just half an hour before it was closing, as they were letting the last visitors in. An excellent day though: good bunch of people, nice walk, good weather, and a decent pub lunch in the middle. Right at the end of August I went on an ‘Alternative London’ walking tour with some friends and workmates, seeing some cool street art in Shoreditch.

In September I went up to Edinburgh for a weekend, stayed with Karoliina and went for some nice walks up North Berwick Law and along the coast from there, and in the Pentland hills. We found a few geocaches along the way, and sung Simon & Garfunkel songs.

Charlotte and Nicolai were in London, so I got to catch up with them which was nice.

Craig was in town at the beginning of October so came for lunch at Google. My cousin Brittany was in London for a full month, and stayed with me for her first few days, in the second week of October. I had not seen her in years so it was good to catch up. She kept herself pretty busy between sightseeing seeing a bunch of her friends. I went to David & Amber’s wedding, which was good fun. Had a few interesting conversations, and there was a ceilidh. (Strictly speaking they got married some time earlier for immigration purposes, but this was the ceremony to celebrate it properly.) My old friend Daniel was also in the UK in October, for military stuff in Wales, but came to London for a few days as well and stayed with me (overlapping with Brittany actually), so I was able to show him around a bit and catch up. And then Emily visited on her holidays, and we went to Cardiff, Bristol, Cheddar Gorge and Bath for a few days. At the end of October was the Morocco trip, which I have already written about.

Shortly after getting back from Morocco there was another blues dance festival, Blues Baby Blues. It was also good, though not quite on the same level as EBI. Unfortunately I caught something partway through so was not feeling great on the second day of workshops, and had to leave early that evening.

The annual London Jazz Festival was on in the middle of November, and I went to a number of the free gigs on both Friday nights and Saturdays. I managed to drag a few friends along to some of them, and others was on my own. There was a mix of excellent music and weird, but all good fun. I heard something like 12 or so bands in total, which was but a small fraction of what was on offer.

I went to a couple of thanksgiving dinners. One was hosted by Mark from work on Sunday 24th, which funnily enough was full of Kiwis: apparently one of his flatmates and quite a few of his friends are from NZ. About half the party watched the rugby, which I hear was pretty tense, but we won in the end. The food was good. The other was at Amber & David’s place, as one of the regular Thursday night dinners they had been hosting. There was going to be another Thanksgiving party on the Saturday as well at Gareth’s place, but it ended up being cancelled in favour of a belated housewarming party for Rachel and Dan. I grew a small moustache the last week of November for Joanna’s moustache party the same night, but ended up arriving after midnight so it was the 1st of December already.

Karoliina was in London briefly in December, and came to Google to catch up with people which was nice. I saw the new Hobbit movie with some workmates, and a Robin Hood pantomime with Rachel and some of her Morris dancers. We also had a Google eng-lon pantomime again; this year was Cinderella, and it was again very well done, with lots of funny in-jokes. There were two work Christmas parties as usual; the engineering one at the Millbank Tower, and the one for everyone at the Troxy, with a Christmas fun-fair theme. And Cheryl was back from New York for Christmas, so she also organised to catch up with a bunch of Googlers for brunch.

I took the Monday and Tuesday before Christmas off as I had to use the annual leave or lose it, and there were a couple of swing bands playing at the Royal Festival Hall to dance to. They also had the annual swing dance on Boxing Day, though only with recorded music sadly.

My flatmate Carla had her parents and sister visiting over Christmas, and invited me to join them for dinner on Christmas Eve, which was good, though a little hard to communicate as her parents do not speak much English. Went to a friend’s place for Christmas dinner, though did not stay too long as I caught a cold the weekend before and was not feeling great. Saw the New Year’s Eve fireworks with Carla and her sister, saw some of the New Year’s Day parade today (though it was cold and rainy so not many people came, and those who did did not stay long, so I left halfway through), and then here I am. Hoping the cold goes away soon.

Photos are in the usual place, and have a few more stories.

15 December 2013

Morocco

Filed under: Photos, Travel — Tags: , , — qwandor @ 5:32 pm

I planned to write this post straight after I got back, while everything was still fresh in my memory. Obviously that failed: it has now been over a month since I got back on the 4th of November. Anyway, Morocco! It was a great trip. I will see what I can remember. Photos are linked along the way, and tell more of the story…

I went to Morocco for 10 days with 3 workmates: Alberto, Joanna and Monika. We flew into Marrakech on the morning of Saturday 26th October, and spent the afternoon exploring the old town (Médina) and stayed the night in a riad there. Sunday morning until Tuesday we went on a guided trek in the High Atlas mountains (just the 4 of us, our guide Nouredine, a donkey to carry all our bags, and a man named Muhammad to look after the donkey). Our guide was Nour from Berber Travel Adventures, who I would highly recommend — he seemed to know everyone in the area, and was super helpful. The trek was the highlight of the whole trip for me, as we got to see quite a bit off the standard tourist trails. The hiking itself was not especially challenging, but it was really interesting seeing all the little villages. We walked from village to village, stopping to eat at places that I am not entirely whether were guesthouses of some sort or just people’s homes, but either way not anywhere we could have gone without Nour. The first night we stayed in Muhammad’s family home, and the second in a local guesthouse of some sort in a larger town. The accommodations were fairly primitive, but comfortable enough. In the first village we stayed there just so happened to be a wedding happening the night we were there, which we were lucky enough to be able to watch a little of. I think the bit we were able to watch was more of a party after the bride and groom had already left, described somewhat ambiguously by Nour as ‘a folklore’. Whatever it was, we went into the courtyard of a house, packed full of people (with lots up on the roofs around the outside watching as well, mostly women and children). There was a circle of men in white robes singing and dancing, and some watching, while women in colourful clothes and children watched from the other side. Men and women kept fairly separate the whole time.

The second day of the trek we passed by a small primary school in-between two villages, which we were also able to visit. It only had two teachers and two classrooms, so there was quite a range of ages in each class. We had a chat with both teachers, who unlike most of the people we had met up until then spoke fluent English. Unfortunately none of us knew enough French or Arabic to talk to any of the children. One of the teachers described finding it a difficult place to teach compared to the city where he had previously taught.

After the trek we spent another night in a different riad in Marrakech, then in the morning picked up a hire car to drive around some more of the country. Unfortunately when we got to the car rental agency (Dollar), they refused to give us the car we had booked and paid a deposit for without a much higher insurance excess than the contract we had agreed to said, which was not possible on the credit card we had booked with. After about 3 hours wasted arguing and waiting, we ended up getting a car from a different company for about the same price, which we were assured was four-wheel-drive, but which turned out (to our peril) not to be. Our late start meant we did not have much time for sightseeing on our way Skoura, where we spent our next night. We did however make sure to make time to see Ksar Aït Benhaddou, and spectacular and fairly well preserved old fortified city which is still inhabited by a few families. We also chanced across a great little juice shop in Ouarzazate called ‘Amsterdam’, where we tried some interesting juices after dinner.

The next day we drove up Dadès Gorge, and decided to try taking a 4WD track across to Todra Gorge as mentioned in a guidebook. We had some difficulty finding the track as it was not signposted at all, so took a guide to show us the way, which turned out to be very much for the best. The track was hard to follow in places, and a large section in the middle was completely washed out so we had to drive along a dry rocky riverbed, which was really not a great idea in our car, and we frequently had to stop to clear rocks or build little ramps. We made it through in the end, but many hours behind our overly ambitious schedule, so had to push the rest of our plans back a day as there was no way we would be able to make it to Merzouga in time for our camel trek originally booked for that evening. Anyway, as we were driving down Todra Gorge looking for somewhere to stay, who should we spot but Nour, our guide from the High Atlas trek! He happened to be sitting outside a hotel by the road taking tea just as we were driving past so we stopped to chat, and decided to stay in the same hotel. It turned out he was guiding another couple, and had taken a similar route to us. He gave us some more advice on routes to take for the rest of our trip, and we chatted over dinner.

The next day we made it to Merzouga in plenty of time, after taking a few hours in the morning to walk around Todra Gorge a bit. We joined a group of about 10 other people and rode our camels out into the desert for about 1.5 hours, stopping along the way to watch the sun set over the dunes, until we made it to the semi-permanent camp where we spent the night. We were happy to see it was fairly small, just 4 or 5 tents, unlike some of the much larger camps we had seen along the way. We had more tagine for dinner, chatted to the other tourists, and listened to (and joined in with) some drumming under the stars. The four of us also went over the nearest dune to watch the stars in the darkness, and they were certainly brilliant, but unfortunately by that point the wind had got up a bit so there was a lot of sand blowing in our faces and we did not stay out long. I was still finding sand all through my clothes and shoes weeks later after I returned to London. When we went to our tent to play cards we were surprised by a small bat in the tent, to which Joanna amusingly reacted by alternately cowering in the corner and trying to get up close to take photos.

We got up early the next morning to watch the sun rise, then rode our camels back to the hotel where we set out to take a (very welcome) shower and breakfast. It took several more showers to get rid of all the sand though. From Merzouga we had a long drive to get to Ouzoud Falls, where we arrived at our hostel around 10 or 11 pm only to find that they had not changed our reservation as we had asked, and so had quite some fuss until they finally found us a room with no working hot water various other problems. The next morning we had a walk around the falls, which were nice, then drove to Bin el-Ouidane reservoir for a quick look before heading back to Marrakech to drop Alberto at the airport.

Our original plan of going out to Essaouira to relax on the beach was not possible due to having pushed everything back a day, so we decided instead to spend our last night in the Ourika Valley, not far from Marrakech. We drove out there and looked for somewhere to stay, and were lucky enough to find the nicest hotel of the trip, a somewhat resort-like place with surprisingly large grounds but only 4 rooms (all fairly large, but still), only one of which was occupied. They gave us the largest and nicest room for a good discount. There was even a fireplace, which they lit for us! Fire is always fun. In the morning we had a guide from the hotel show us around some of the villages in the hills nearby, which was interesting, then drove back to Marrakech to catch our flights back to London.

Rather ironically, Monika’s Ryanair flight was on time, while the EasyJet flight which the remaining two of us caught was delayed by 3 hours, finally arriving in London some time after 2:30 am, well after the Gatwick Express for which we had booked tickets had stopped running. Still fighting EasyJet over that for compensation.

15 August 2013

Dwarves and hats

Filed under: Maths — Tags: , , , — qwandor @ 6:44 am

Well! I have been meaning to post this for quite some time. Here, at last, are four puzzles involving dwarves and hats.

Puzzle 1, perhaps the easiest:
(I heard this one from Josh Baker when we went for a walk in Otari-Wilton’s Bush earlier this year.)

There are 4 dwarves. A goblin (who hates dwarfs, as all goblins do) has buried them in the ground up to their chins, such that they can see directly in front of themselves but not turn their heads. They are in a straight line, but with a tall wall between dwarves 3 and 4. All the dwarves are facing towards the wall, so dwarf 1 can see dwarves 2 and 3, dwarf 2 can see dwarf 3, and dwarves 3 and 4 can only see the wall. Their tormenter has also put a hat on each dwarf’s head, such that they cannot see their own hat.

He then tells them that he has given two of them red hats and two of them green hats, and that if any one of them calls out his own hat colour he will let them all go free. However, if any of them calls out the wrong hat colour, says anything else, or makes any noise or attempt to signal the others, he will leave them all buried to starve.

Assuming the goblin is telling the truth about the hats he has given them, and will keep his promise, what should the dwarves do?

Puzzle 2, along similar lines and also from Josh, but more difficult:
This time 5 dwarves are buried in the ground, but they are in a circle so that they can all see each other. Again, each has a coloured hat which he cannot see, but this time they can all see all hats but their own.

They are told that they have each been given a hat that is either red, yellow, green, cyan or blue. It may be that they all have different coloured hats, or it may be that some of them (or even all of them) have the same colour. This time they must all call out at once what colour hat they think they are wearing, and if any one of them gets eir colour right then they will all be set free. If they all get the wrong colour they will be left to die. What should they do in this case?

Puzzle number 3 came from Emily:
There are 100 dwarves in prison. They were probably falsely accused of their crimes; it is a hard life being a dwarf, and the justice system is all biased against them. Anyway, they have been in prison for a while, and their jailer is getting bored, so she decides to play a game with them. She takes them all into a room, which contains nothing but a single light hanging from the ceiling, and a lightswitch on the wall to turn it on and off, and explains the rules to them:

“Once you leave this room you will all be put in solitary confinement. I will then bring you back in one by one. When I bring you back you may choose to switch the light on or off, or to leave it as it is. You will then go back to your cell, and I will bring the next dwarf in. I will keep on doing this until one of you tells me that e is sure you have all been brought back at least once. If e is right, then I will let you all go free. If, on the other hand, e is wrong and not all of you have yet been brought back to this room, then I will hang you all. I will bring you in in whatever order I feel like, at whatever speed I feel like, and will keep on doing so until one of you says something. I will not touch the lightswitch.”

She then takes them each to their cells, and begins her game. They all have identical grey prison-issue hats.

a) Assuming that the jailer leaves the light on when they leave the room, so it is on when the first dwarf is brought back in, what should they do?

b) If the dwarves do not know whether the light will be on or off initially, what should they do?

Puzzle number 4 is from Christo’s blog (but do not look there until you have solved it, as there are spoilers):
100 dwarves are in a line, so each can only see the dwarf in front of em. Each is hatted in either magenta or brown. They are told that they must each call out their guess at their own hat colour, but they can do so in any order they choose. If any of them says anything other than a hat colour, speaks more than once, or tries to look around or gesticulate e will be immediately defenestrated. Once they have all made their guesses those who got the right colour will be freed, while those who guessed wrong will be defenestrated.

Dwarves like to work together, so what should they do to minimise defenestration?

Interestingly there at least two quite different approaches to this, so see if you can get them both.

Comment below if you want hints or clarification. If you think you have a solution please email me directly so as not to spoil the puzzles for other people, and I will post a comment to confirm you got it. Feel free to post how many dwarves you think can be saved for puzzle 4 though.

(And yes, for all their flaws, these dwarf-haters do like to use Spivak pronouns.)

[Edit 2013-08-15: Corrected typo in puzzle 2.)

Older Posts »

Create a free website or blog at WordPress.com.