So a few days ago I came across this video on Digg discussing a programming question sometimes used in interviews, code the game FizzBuzz.  I've never had to do this since I've applied for a programming job, but I liked the idea of trying to figure out how many ways I could code FizzBuzz in Swift.  To make this a bit more fun I gave myself an hour to try and come up with the most convoluted and the simplest solutions I could.

The Rules

  1. Print the numbers 1 through 100, one number to a line
  2. If the number is divisible by 3, print "Fizz" instead
  3. If the number is divisible by 5, print "Buzz" instead
  4. If the number is divisible by both 3 and 5, print "FizzBuzz" instead

The Loop

So the first part of this game is a simple loop and there were really only two options available a for and a while loop.  They would look something like this.

var counter : Int = 1
let counterLimit : Int = 100

//While Loop Option
while counter <= counterLimit {
    //Do Something
    counter += 1
}

//For Loop Option
for i in 1...counterLimit {
    //Do Something
}

Running The Tests

The rest of the program just requires that we test the number to see if it is divisible by 3, 5 or both.  The sequence of our tests matters because doing things backwards would require more tests to cover the same scenarios.

//Requires fewer tests
for i in 1...100 {
    if i % 3 == 0 && i % 5 == 0 { print ("Fizz Buzz") }
    else if i % 3 == 0 { print ("Fizz") }
    else if i % 5 == 0 { print ("Buzz") }
    else { print ("\(i)") }
} 

//Requires more tests
for i in 1...100 {
    if i % 3 == 0 && i % 5 != 0 { print ("Fizz") }
    else if i % 5 == 0 && i % 3 != 0 { print ("Buzz") }
    else if i % 3 == 0 && i % 5 == 0 { print ("Fizz Buzz") }
    else { print ("\(i)") }
}

Simple

The simplest solution I could think of was the same as what was presented in the video, although you could get "fancy" using an array to capture the results instead of just printing them out.  But that may not be as efficient from a resources perspective.

for i : Int in 1...100 {

    var output : String = ""

    if i % 3 == 0 { output += "Fizz" }
    if i % 5 == 0 { output += "Buzz" }
    if output == "" { output = String(i) }

    print ("\(output)")

}

Convoluted

My complicated answer just does a lot of work that can be simplified through the use of the modular (%) operator.  There are clearly better ways of doing this.

//Function to determine remainder equals 0 (true)
func remainder (number : Int, divideBy : Int) -> Bool {
    let result = number % divideBy
    if result == 0 {
        return true
    } else {
        return false
    }
}

//Loop
for i in 1...100 {

    if remainder(number: i, divideBy: 3) && remainder(number: i, divideBy: 5) {
        print ("Fizz Buzz")
    } else if remainder(number: i, divideBy: 3) {
        print ("Fizz")
    } else if remainder(number: i, divideBy: 5) {
        print ("Buzz")
    } else {
        print ("\(i)")
    }
}
Posted
AuthorLee B Wilson

If we're going to have a conversation on productivity a definition is probably as good a place as any to start this conversation. While its a bit cliche, let's see what Mirriam-Webster define productivity as

the quality or state of being productive and they define productive as having the quality or power of producing especially in abundance

These certainly aren't the only definitions out there, but they were the first listed. What I found interesting was that they implied that abundance was necessary in order to be productive and made no reference to quality or time. This definition may be more applicable to manufacturing, but if I think about fields like IT abundance isn't always desired, especially when you're building a solution for a single client. This definition is therefore too generic for me so let's try to construct an updated definition which we can apply to our conversations going forward.

In my mind productivity is composed of three separate components

  1. Quality
  2. Time
  3. Repeatability

Quality is pretty straightforward and refers to the characteristics of the output. For example, how many bugs exist in a piece of software or how many units of your new electronics device are returned because of physical defects. The catch with quality is that it's subjective, not everyone will encounter your software bugs, or receive a broken electronics device and you can suffer from a vocal minority's opinion.

Time I'll define as how long it takes to do something, however we're not referring to just clock time. When we discuss time it will often be necessary to understand how many steps are required to complete a project or manufacture a product. It is also important to remember that less time or fewer steps doesn't always lead to better productivity, sometimes those seemingly unnecessary steps are there for a reason.

Repeatability is just that, can we consistently and accurately perform the same steps over and over. This is where we'll get into the topic of automation. In electronics manufacturing it makes sense to use automation because the steps to build a cell phone are always the same. However, if you're a woodworker hand crafting a table, automation may not be as useful. It's important to recognize when tasks can be automated to improve productivity versus where manual repetition and practice makes us more efficient in performing a task and therefore more productive.

Given these factors I would start to define productivity as

The ability or power to repeatably perform a task or create something while balancing the time (steps) to completion and overall quality

I'm sure this definition will change as I learn more, but I feel comfortable that it's a good starting point, and see where it takes us from there.

Posted
AuthorLee B Wilson

As is the current fashion in Hollywood, every franchise gets a reboot. So if Hollywood gets to reinvent itself with fancy new graphics and a marginally different storyline then why not do the same with my personal blog?

This website has had several reboots before, none of them successful, but in the past I really didn't care. The reason being that plwodi.com wasn't meant to be an important place. This site was really a place for experimentation and learning. A place for me to learn about Content Management Systems (CMS), HTML, CSS and other web technologies without bothering to manage my own server. Could I have done it cheaper, yes, but because squarespace.com sponsors so many of the podcasts and online content I enjoy it seemed right to support them as well, so here I am.

The site however can no longer serve no purpose, which is why this reboot is taking place.

What will this site ultimately be? I have no clue. What I do know right now is that there are topics I'd like to explore and it seemed appropriate to document my journey somewhere so why not here.

The first topic I'll be delving into is productivity, which I'm sure sounds fascinating but is something I spend a lot of time thinking about (more on that in a later post). As for what else I'll be covering that's still to be determined.

Could this be another failed reboot? Yes, it's possible. But I'm hoping that won't be the case. This time I'm going in better aware of the flaws that led to failure in the past and interested in learning what else I can do to be more productive.

I won't promise regular posts just yet, but I can promise there will be a second post. Stay tuned.

Posted
AuthorLee B Wilson
Categoriesnews
Tagsreboot

Last year for Black Friday, Amazon.com had a fantastic deal on an Acer c720 Chromebook so I decided to grab one.  I'd been wanting to test ChromeOS and live "la vida google" for a while.  After 2-3 months I decided that ChromeOS wasn't for me.  I'm an old school computer user, I need a command line, and I need actual applications and not web apps.  This isn't to say that ChromeOS is a bad operating system, it wasn't, and if you live purely online I think it will get the job done.  

That said, I had this c720 which I now needed to find a purpose for.  I had heard that the c720 could be converted into a nice Linux laptop, and so for my maker project in February I decided that I would convert the c720 into an Ubuntu laptop so I could write code, and goof around online.

Here are the steps I followed to make this work.  I'll include the source URLs when I can.

Step 0 : Remove the screw.

SOURCE : http://www.chromium.org/chromium-os/developer-information-for-chrome-os-devices/acer-c720-chromebook

In order to get the c720 to boot consistently into Ubuntu you need to be able to flash the NVRAM of the c720.  There is physical write protection on the motherboard in the form of a screw, URL below has an excellent picture of the motherboard and where that screw is located.  It isn't hard to remove.  Once removed just replace the bottom cover but don't screw in the bottom panel, you'll need to replace the screw later.

Step 1: Enable Developer Mode and Flash the NVRAM

SOURCE : https://wiki.archlinux.org/index.php/Chromebook#Installation

ChromeOS uses a special BIOS and so in order to have a reliable Ubuntu machine you first need to flash the BIOS to get SeaBios running.  

  1. Press and hold ESC + F3 then press the POWER button.  This puts the Chromebook in Recovery Mode
  2. Press CTRL+D to enable Developer Mode and CONFIRM.  The Chromebook will work for a bit and reboot.  Leave it alone for a few minutes while it completes.
  3. At this point you've restored the machine and it has losts its configurations.  When you get to the configuration screen press CTRL + ALT + F2 to bring up the prompt.
  4. Login with the userid chronos.  There is no password.
  5. At the prompt access the superuser shell
    1. sudo bash
  6. Enable SeaBIOS
    1. crossystem dev_boot_usb=1 dev_boot_legacy=1
  7. Reboot the machine

At the white splash screen you can press CTRL + L to boot into SeaBIOS.  Otherwise the machine will boot into ChromeOS if you wait a few seconds.  To make SeaBIOS boot by default we need to run a few more commands.  Return to the ChromeOS superuser shell and run the following.

sudo su

flashrom --wp-disable

flashrom --wp-status

set_gbb_flags.sh

This last command should return the following values (there could be more)

GBB_FLAG_DEV_SCREEN_SHORT_DELAY 0x00000001
GBB_FLAG_FORCE_DEV_SWITCH_ON 0x00000008
GBB_FLAG_FORCE_DEV_BOOT_LEGACY 0x00000080
GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY 0x00000400

Set SeaBios as the default by running

set_gbb_flags.sh 0x489

flashrom --wp-enable

Turn off the c720 and return the screw you removed from Step 0.

With that done you can now install Ubuntu.  Insert your 14.04 install media and install Ubuntu normally.  Make sure to attach an external USB mouse to the c720, by default the trackpad on the c720 will not work with Ubuntu 14.04

Step 2 : Ubuntu

Once installed and online give Ubuntu a few minutes and it will prompt you to perform some updates.  Let Ubuntu update, once done we can fix the trackpad and boot time issues.

SOURCE : http://ubuntuforums.org/showthread.php?t=2223738


First we'll fix the trackpad.  Luckily someone online has written a script to get all the work done for us.  To get started open a Terminal window and enter the following:

wget http://goo.gl/kz917j
bash kz917j

Type in your administrator password when/if prompted and reboot when done.  Make sure not to touch the machine while processing.

To fix the boot time and other issues with the suspend, follow the instructions on this site.  I'm not including them here because it involves editing a couple of files and I like how the author of this site presented the information.

SOURCE : https://philipalban.wordpress.com/2014/04/25/fixing-suspend-in-xubuntu-on-the-acer-c720-a-simplified-guide/

With that done you should have a functional Ubuntu laptop for not a lot of money.  You may need to map some of the volume and brightness keys, but that can be easily done through the System Settings panels in Ubuntu.  In addition, I be careful with any update that involves changes to the kernel and that might break some of these fixes.

Posted
AuthorLee B Wilson
Categoriestechnology