Friday, October 4, 2013

Project Euler Answer Codes 6-10

# Problem 6

Sum square difference

I luckily came across the formula for sum of the squares of consecutive numbers which goes like this 1^2 + 2^2 + 3^2 + ... + (2n)^2 = (n(2n+1) (4n+1))/3 Then using the equation for fo sum of a series, you can get the equation for square of the sum 1 + 2 + .... + m = (m/2)(1+m) (1 + 2 + .. + m)^2 = ((m/2)(1=m))^2 Since m=2n, we can substitute and write down the difference of the 2 equations as difference = (12(n^4) + 4(n^3) - 3(n^2) - n)/3 and here n = 50

# Problem 7

10001st prime

In matlab just run factor(n) on a loop of odd numbers and increment a counter everytime you find a number with only one factor(i.e. it is a prime number). Stop when 10001st prime number is found(counter reaches 10001).

# Problem 8

Largest product in a series

Simplest and laziest way

y = ['73167176531330624919225119674426574742355349194934' ...
'96983520312774506326239578318016984801869478851843' ...
'85861560789112949495459501737958331952853208805511' ...
'12540698747158523863050715693290963295227443043557' ...
'66896648950445244523161731856403098711121722383113' ...
'62229893423380308135336276614282806444486645238749' ...
'30358907296290491560440772390713810515859307960866' ...
'70172427121883998797908792274921901699720888093776' ...
'65727333001053367881220235421809751254540594752243' ...
'52584907711670556013604839586446706324415722155397' ...
'53697817977846174064955149290862569321978468622482' ...
'83972241375657056057490261407972968652414535100474' ...
'82166370484403199890008895243450658541227588666881' ...
'16427171479924442928230863465674813919123162824586' ...
'17866458359124566529476545682848912883142607690042' ...
'24219022671055626321111109370544217506941658960408' ...
'07198403850962455444362981230987879927244284909188' ...
'84580156166097919133875499200524063689912560717606' ...
'05886116467109405077541002256983155200055935729725' ...
'71636269561882670428252483600823257530420752963450' ];
n = 1;
length(y)
max = 1;
while n < 997

     prod = str2num(y(n)) * str2num(y(n+1)) * str2num(y(n+2)) *  str2num(y(n+3)) * str2num(y(n+4)); 
     if max < prod
         max = prod;
     end
     n = n +1;
end
max



# Problem 9
No idea when this went



# Problem 10

Sum of primes below 2e6

Scala code: 


/**  * Created by Administrator on 6/6/2017.  */object Problem10 {

  //find the sum of primes below 2 million
  def main(args: Array[String]): Unit = {

    var total:Long = 0;
    var n = 0;
    var break: Boolean = false;

    for (x <- (2 to 2000000)) {

      n = (math.sqrt(x.toDouble)).toInt;
      
      break = false;

      while (n > 1 && !break) {
        if (x % (n) == 0) {
          break = true;
        }
        n -= 1;
      }

      if (!break) {
        total += x;
      }


    }
    println(s"total : $total")
  }
}



Saturday, September 28, 2013

Project Euler Answer Codes 1-5


Solutions for problems at http://projecteuler.net/problems written using the online compiler http://py-ide-online.appspot.com/

# Problem 1   :

Multiples of 3 and 5

tot5 = 0
x = 0
print "start"
print "fives"
while x <= 1000:
  tot5= tot5 + x
  print x
  x=x+5
x=0
print "threes"
while x <= 1000:
    if x % 5 <> 0:
        tot5=tot5+x
        print x
    x= x+3   
print tot5

# Problem 2 

Even Fibonacci numbers

tot5 = 0
x = 0
y = 1
temp = 0
temp1 = 0
print "start"
while y < 4000000:
  if y % 2 == 0:
    tot5= tot5 + y
  temp = y
  temp1 = x
  x = y
  y = temp1 + temp
print tot5

# Problem 3

Largest prime factor

I think i found the shortest way to do that. Written in Matlab
target = 600851475143;
f = factor(target);
max(f)

# Problem 4

Largest palindrome product

My solution in matlab. One of the slowest method but also one of the most basic method to understand and implement. Most cpu time is spent on the num2str function though. Not my fault. Took 50 seconds to process.

a = 999;
b = 999;
pal = 0;
max = 0;
while a > 100
    found = 0;
    b = 999;
    while (b > 100) && (found == 0)
        inta = a * b;
        stra = int2str(inta);
      if (fliplr(stra) == stra)
         found  = 1;
      end
      b = b -1;
    end
    if pal > max
        max = inta
        a
        b
    end
    a = a - 1;
end 

# Problem 5

Smallest multiple

No programming solution went like this 19 * 18 * 17 * 16 * 15 * 14 * 13 * 11 and the rest would be divisible since the rest are already multiples of these. now 18, 16, 15, 14 are not prime numbers so they are adding multiples useless to the product. We need to remove these multiples. There's 3 hanging in both 18 and 15, remove them/ likewise we have a 2 hanging in 14 and 18. remove them. multiply by the 3 and 2 you removed. 19*3*17*4*5*7*13*11*3*2 Now we cant't remove anything else without loosing our higher multiples.
436 problems to go

Sunday, September 8, 2013

Applying for Jobs online in Mauritius

Having just completed my undergraduate studies, I returned to my country looking for jobs. First I started looking websites with job postings. Here are some websites with offer engineering and IT jobs. Usually you create an online CV and apply for the different jobs available.

www.ceridian.mu - mainly IT jobs, mainly outsourced jobs
www.myjobs.mu - all types of jobs
www.adecco.mu - all types of jobs
www.careers.accenture.com

I shall update the list as I find more.

Here is a sample of my CV I created in word. I am copy pasting the text saved as html here.


Shamloll Divish
SHAMLOLL DIVISH
DoB :20/11/1990  Email : divish007@gmail.com
Address : Shamloll Lane, Royal Road, Laventure
Mobile :  9232830  Home : 4187604
EDUCATION
<![if !supportLists]>l <![endif]>B. Eng in Telecommunication Engineering                                   2009-2013
Huazhong University of Science and Technology, Wuhan, China
<![if !supportLists]>l <![endif]>Cisco Certified Network Assistant (CCNA)                                         2009
Infoclub, Rue Desforge, Mauritius
<![if !supportLists]>l <![endif]>Computing and Mathematics                                               2001-2008
Royal College Curepipe, Curepipe, Mauritius
PROFESSIONAL WORK EXPERIENCE
<![if !supportLists]>l <![endif]>Maintenace officer at SICA Waterpark  (jul 2012) Mauritius
Operating and supervising machinery and guide tourists around the park.
<![if !supportLists]>l <![endif]>IT Support at Synohydro Ltd Mauritius(Jul 2012-Aug 2012)
Assist the network engineer to troubleshoot office network mainly in chinese language
<![if !supportLists]>l <![endif]>Trainee Effect Box Designer at Joyo Ltd Shenzhen, China (July 2013)
Design a sound card-audio-DSP hybrid as a new product for the company.
<![if !supportLists]>l <![endif]>Part-time primary school English teacher Wuhan, China(2010-2013)
Teach 25-30 students from ages 5-15. Received good reviews from parents and students.
PROJECTS EXPERIENCE
Atmel AVR projects on Arduino - Bluetooth comm, simple 4-wheel, portable mp3 player (self)
Xbee Wireless mesh networks - Lights automation, Water tank control , Misc remote controls
Android apps - Wrote a Sound/voice analysis engine, P2P communications system
PHP/MySQL/Django/GoogleApp Engine - Web accessible database system (part of thesis)
Mobile networks research - Measuring smartphone 3G performance of China Carriers(thesis)
C++/OpenGL project - Designed a user-customizable graphing software (school work)
Cortex-M3 programming - Audio and DSP programming at Joyo Ltd(work experience)
Graphic design - Lead graphic designer for Royal College Curepipe annual magazine - 2009
RELEVANT STUDIES AND SKILLS

Network setup, administration
Network performance evaluation
Modern Telecommunication Systems
Electronic Circuits of Communication
Microcontroller programming
Matlab and Simulations
Computer and mobile phone repairs
Possess high analytic and diagnostic skill
Understand advanced programming concepts
Able to program in large number of languages
Extensive Android development experience
Work independently within a team framework
Ability to write and converse in Chinese
Excellent oral and written communication skills.

References will be provided upon request.

Friday, August 30, 2013

Java Technology terms


Java 2 has been seperated into 3 parts
Java EE- Enterprise edition for servers and business functions
Java SE - Standard edition for normal applications
Java ME - Micro edition for small/embedded devices

Java beans - to create portable reuse codes

JSP(Java server pages) - it is the java version of ASP basically allowing dynamic pages to be created by allowing generation of pages on server side.

Java applet  runs java bytecode from the internet in a JVM on the client and can appear in a frame in the browser.

Java servlet - counterpart of php and asp.net for extending server side applications and provide dynamic web content. The difference between servlets and JSP is that servlets typically embed HTML inside Java code, while JSPs embed Java code in HTML


Apache Struts - web framework to develop dynamic webpages and uses the MVC(model view component) architecture 

Hibernate to allow manipulation of objects to relational databases with very little code.


Apache Pivot, JavaFX, Swing - UI for java

iPhone 3GS Jailbreaking and Activation

My experience in iPhone unlocking : can be very troublesome for the inexperienced

My problem


I obtained and iPhone 3GS which I decided to upgrade to 6.1.3. Bad idea because after restart the iPhone started activating though wifi and eventually failed. I normally thought that the device required the famous jail-breaking which I proceeded to investigate. I found the program redsnow for this task. You can find it everywhere. It failed me numerous times. 

Here are some problems and solutions


  1. Entering DFU(driver firmware update) mode - just follow the timing to the second precision. no errors allowed here. You will sometimes enter recovery mode. This is because you didn't follow the timing right.Exiting DFU or recovery mode - just press the home and power button for approximately 15 seconds, it should switch on again
  1. IPSW - sometimes you have to get the correct IPSW for the ISO version you are using or redsnow will tell it doesnt have the required keys. You'll find the link to downlood at the end.
  1. Stuck on "waiting for reboot" - you need to use rednow in administrator and compatibility mode for windows sp2 for some reason


After completing the jailbreak it told me to use the "just boot" option every time to start the iPhone.  Seemed weird but finally this too didn't work so I continued my research.


Unlocking(Baseband fixing)


Finally I found advice that just the baseband needed installing actually downgrading. This is because the new installed firmware doesnt work right or something. In the jailbreak option I had the option to "install iPad baseband" but the latter taking too much time I started investigating a solution. I found that it is actually trying to download a 500mb file from apple servers. Given my slow connection I looked for a way to download the files myself and redirect redsnow to the local files. this can be done in a rather lengthy way by installing the apple server program to host the files and change the system32/driver/etc file so as to redirect redsnow to my own server, now testing this option.

I found one pretty good comment from Jheremy explaning the need for jaibreaking and unlocking the baseband:

Hi there…to make it simple,jailbreaking an Iphone is basically allowing users to access third-party softwares and applications that you can’t install on an official Apple firmware.This is due to Apple’s limitations and policies. Unlocking is basically freeing your Iphone from an specific carrier (AT&T or T-Mobile) and unlocking your Iphone means that you can use it to any carrier.Baseband is a software that drives your Iphone signal,including GSM,EDGE and Wifi connections.That’s it.
Installing Cydia

Cydia wasn't appearing on the iPhone even after jailbreak and downgrading the base-band   jailbreaking with the option "Install cydia" checked or unchecked made no difference. i found the solution by trial and error. when selecting the 6.0 IPSW file for jailbreak, it always asked me if my iPhone 3gs had a new boot rom and i always selected "Yes" since I always saw "new br" in the info text when I connect the device. Selecting "No" solved the problem. i now have cydia and can install custom apps. The only problem still is the fact that the firmware installed is 6.1.3 and if I want to be able to run Cydia or Safari, I have to boot it from the the "Just Boot" option from RedSnow.

Also you need to jailbreak the device before unlocking it
Download firmwares : http://www.icj.me/ios