Install Android Studio on Ubuntu

Ubuntu

Android Studio is a great development environment and is available on Ubuntu. I’m using Ubuntu Mate 16.10 “Yakkety Yak”.
 
First install a Java Development Kit (JDK). OpenJDK is pre-installed or you can use Oracle Java 8 (there is a great guide here). I don’t wish to argue over your choice – I need to use the latter (my tutor does). Download Android Studio here. – I extracted it to /opt; ran the installer; and used my home folder for the SDK. If you are using 64 bit, you need the 32 bit GNU standard C++ library:
sudo apt install lib32stdc++6

For Arch you need to enable “multilib” repository:

<code><span class="pln">sudo pacman </span><span class="pun">-</span><span class="typ">Syu</span> <span class="pun">&amp;&amp;</span><span class="pln"> sudo pacman </span><span class="pun">-</span><span class="pln">S multilib</span><span class="pun">/</span><span class="pln">lib32</span><span class="pun">-</span><span class="pln">libstdc</span><span class="pun">++</span><span class="lit">5</span><span class="pln"> multilib</span><span class="pun">/</span><span class="pln">lib32</span><span class="pun">-</span><span class="pln">zlib</span></code>

Virtualisation support is interesting. I read two tutorial and Google’s guide. The former makes reference to command line options not in version 2.2.2. These posts suggest this is a bug, but it may now be default behaviour. First enable that virtualisation in BIOS (check if enabled using “kvm-ok”).

sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
sudo adduser dougie kvm
sudo adduser dougie libvirtd

This results in an error.
screenshot-at-2016-11-25-21-16-19

Using the system version of libstdc++.so.6 works. Add the following to /etc/environment:

ANDROID_EMULATOR_USE_SYSTEM_LIBS=1

It seems snappy but with no feedback I’m unsure if accelerated.

So I now have a development environment set up for my project. The next hurdle is to choose a title. So far it is a: development project; distributed application; and uses Android.

TM470

After a false start when The Open University opened the TM470 module site, we got back on track on Wednesday. Although the module doesn’t start until February, I need to decide a project to assign a tutor.
 
I read the study guide and project choice pages. Self development is key, by being a reflective practitioner.
 
My project can be research, development or evaluation. It should develop knowledge acquired at level three, where I took:
  • Developing Concurrent Distributed Systems (M362),
  • IT Systems Planning for Success (TM353) and
  • Software Engineering (TM354).
I also want to use:
  • Algorithms Data Structures and Computability (M269) as I enjoyed the subject and
  • Web Technologies (TT284) as I enjoyed mobile application development and gained a distinction.
Developing a mobile application with a software engineering approach makes sense. There are techniques and approaches from TM353 that help. For TT284 I used MIT’s AppInventor but would like to use Google’s Android Studio. I worked through the tutorials and it offers a comprehensive suite of tools and runs on Ubuntu.
 
The trick is to be find an achievable solution to a defined problem. I have ideas but have lots of research ahead of me. I am writing down ideas in a notebook as I get them and aim to decide in the next few weeks.
 
Throughout I am going to blog, more for myself than anything else. I’ve noticed students reaching out for support on Twitter. While being careful about plagiarism, thought’s trigger conversations we wouldn’t otherwise have.

Forget everything you knew about coding (or perhaps remember, depending on your age)

This Christmas I’m going to embrace the past.

COmmon Business Oriented Language (COBOL) 85 standard was the first language I was taught. Napier University was a feeder into the banking and insurance industries in Edinburgh at the time and they had sizeable COBOL farms. It proved profitable too, as a number of students I knew went to the US to alleviate Y2K bugs in thousands of legacy applications. COBOL had fallen out of favour in US colleges.

Continue reading Forget everything you knew about coding (or perhaps remember, depending on your age)

MT254 TMA 01

First TMA on MT264 (Designing applications with Visual Basic) got returned today – 96%. I’m very pleased with that and exceptionally lucky given that I read the material in a week, attended one on-line tutorial and wrote the assessment in a couple of days.

I’ve seen complaints on the module forum that tutors aren’t getting assessments back to quickly enough. The cut off was the 15th (I submitted on the 13th) and it was returned on the 27th, I don’t really see what the problem is.

Nested selection reared its head again but I didn’t lose any marks for it. In every programming module I’ve been picked up for using Else If so I played it safe and used nested If statements. So I was advised to use Else If proving I can’t win!

 

Café

Well that was emotional, the TU100 forums opened yesterday. My poor co-moderator Nicky got thrown in to the deep end (I was at a mess top table).

I checked in before work, and there were a few posts (about two dozen) so I thought we’d be OK. Checked in earlier and there’s several hundred!

I’m studying for MS221 and MT264 but it’s clear I’m going to have to put some time in this weekend reading through TU100’s material – especially with Sense, which seems to have captured student’s imaginations.

Sum of all the primes below two million

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

Seemed pretty straight forward, loop through all numbers up to 2,000,000 – if they’re prime add them to a tally.

Module Module1

  Sub Main()
    Dim beganAt As Date = Now
    Dim n As Integer = 2000000
    Dim total As Long = 0

    For counter As Integer = 2 To n
      If isPrime(counter) = True Then
        total = total + counter
      End If
    Next

    Dim endAt As Global.System.TimeSpan = Now.Subtract(beganAt)
    Dim took As Integer = endAt.Milliseconds

    Console.WriteLine(total.ToString + " in " + took.ToString + " ms.")
    Console.ReadKey()
  End Sub

  Private Function isPrime(ByVal thisNumber As Integer) As Boolean
    ' Prime numbers other than two are odd...
    If thisNumber = 2 Then
      Return True
    ElseIf thisNumber Mod 2 = 0 Then
      Return False
    End If

    'Check it isn't divisible by up to its square root
    '(consider n=(root n)(root n) as factors)
    For counter As Integer = 3 To (Math.Sqrt(thisNumber)) Step 2
      If thisNumber Mod counter = 0 Then
        Return False
      End If
    Next
    Return True
  End Function

End Module

Just needed to be careful with data types – VB.Net’s Integer isn’t large enough so I changed to a Long. Gives 142,913,828,922 in 953 milliseconds.

 

 

Pythagorean triplet

Project Euler again, this time its problem 9.

A Pythagorean triplet is a set of three natural numbers, a<b<c, for which:

a^{2}+b^{2}=c^{2}

For example:

3^{2}+4^{2}=9+16=25=5^{2}.

There exists exactly one Pythagorean triplet for which abc = 1000.
Find the product abc.

My first draft is simply brute force checking:

Module Module1

  Sub Main()
    Dim beganAt As Date = Now

    Dim answer As Integer = pythagorean(1000)

    Dim endAt As Global.System.TimeSpan = Now.Subtract(beganAt)
    Dim took As Integer = endAt.Milliseconds

    Console.WriteLine(answer.ToString + " in " + took.ToString + "ms.")
    Console.ReadKey()
  End Sub

  Private Function pythagorean(ByVal thisNumber As Integer) As Integer
    For a As Integer = 1 To thisNumber
      For b As Integer = 1 To thisNumber
        For c As Integer = 1 To thisNumber
          If a + b + c = 1000 Then
            If (a * a) + (b * b) = (c * c) Then
              Return (a * b * c)
            End If
          End If
        Next
      Next
    Next
    Return -1
  End Function

End Module

It takes 375 milliseconds but gives the correct answer.

 

The 10001st prime number

Project Euler time again, I’ve come out of sequence – here’s problem 7:

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10001st prime number?

I’m going to start at the beginning and check if each is a prime, until I find the 10001th.

Module Module1
  Sub Main()
    Dim beganAt As Date = Now
    Dim n = 10001
    Dim prime As Integer = 0
    Dim counter As Integer = 0

    ' Check each number until you've got 10001 prime numbers.
    Do Until prime = n + 1
      counter = counter + 1
      If isPrime(counter) Then
        prime = prime + 1
      End If
    Loop

    Dim endAt As Global.System.TimeSpan = Now.Subtract(beganAt)
    Dim took As Integer = endAt.Milliseconds

    Console.WriteLine(counter.ToString + " in " + took.ToString + "ms.")
    Console.ReadKey()
  End Sub

  Private Function isPrime(ByVal thisNumber As Integer) As Boolean
    ' Prime numbers other than two are odd...
    If thisNumber = 2 Then
      Return True
    ElseIf thisNumber Mod 2 = 0 Then
      Return False
    End If

    'Check it isn't divisible by up to its square root
    '(consider n=(root n)(root n) as factors)
    For counter As Integer = 3 To (Math.Sqrt(thisNumber)) Step 2
      If thisNumber Mod counter = 0 Then
        Return False
      End If
    Next
    Return True
  End Function

End Module

I used a function for finding primes, it keeps coming up. It takes an integer and returns true or false by discounting even numbers except 2 and checking for divisibility up to the integer’s square root. If you consider n=sqrt{n} times sqrt{n} then if you have not found a number that divides into n evenly once reaching sqrt{n}, its factors can only be one and itself. This significantly reduces processing time and appears to be how my HP40gs works out its ISPRIME() function.

It gives the answer 104743 in 125 milliseconds.

Largest prime factor of a composite number

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?

Prime factors are prime numbers that can be multiplied together to make a given number. One way to find them is to start by dividing the number by the first prime (2) and continuing to do so until it cannot be divided, then moving on to the next.

Module Module1
  Sub Main()
    Dim beganAt As Date = Now
    Dim n As Long = 600851475143
    Dim factor As Integer = 2
    Dim highestFactor As Integer = 1
    While n > 1
      If n Mod factor = 0 Then
        highestFactor = factor
        n = n / factor
        While n Mod factor = 0
          n = n / factor
        End While
      End If
      factor = factor + 1
    End While
    Dim endAt As Global.System.TimeSpan = Now.Subtract(beganAt)
    Dim took As Integer = endAt.Milliseconds
    Console.WriteLine(highestFactor.ToString + " in " + took.ToString + "ms.")
    Console.ReadKey()
  End Sub
End Module