The solution to the 16th question posed by the Project Euler website requires a user to parse through a number that is over 300 digits long.
Problem: I need to access each digit in the number. My algorithm returned a value in scientific notation and attempts to retrieve all digits of the number failed as most methods, such as .toPrecision are limited to about 20 digits of precision.
Cause: JavaScript numbers only have 64 bits to use for storage (my number is 1001 bits)
Solution: Use the BigInt.js library, created by Leemon Baird.
I found a calculator that could compute my number and display all the digits using the BigInt.js library and therefore trusted it over other big integer libraries to handle the sizable number in my program. After unsuccessful attempts with the new operator I reread the documentation until I found out how to create a bigInt from a string using the str2bigInt function. Only concern is that this asked for how many bits the number needed, after exploring binary I had a better grasp on why each digit needs about 3 bits, and declared the numbers accordingly. At long last I updated my simple algorithm and submitted the solution.
"Congratulations, the answer you gave to problem 16 is correct.
You are the 127007th person to have solved this problem". . and successfully submit it to the Project Euler website.
Tuesday, March 3, 2015
Monday, February 23, 2015
PhoneGap: Part 2
Bash, Bourne Again SHell, a pun from the Bourne Shell which was the usual shell from Unix. Or at least so says Wikipedia, the source that knows all. Before returning to phonegap I reviewed an UNIX tutorial, to happily find familiar commands (ls, cd) and new concepts such being able to review the rights and running processes.
- My commonly used commands that this tutorial skipped
- $ which : which is looked down on for its inconsistent outputs
- $ open -e file : though I think once I set up the subl binary i'll prefer it
- Important lesson learned
- .profile is best to store environment variables as it is consistent across most platforms, a bash will read .bash_profile first so its best to populate it with a path to the .profile file. I found this superuser forum useful.
- Favorite concept
- the bin is filled with most of the systems commands or programs, also known as binaries, these are precompiled binary code
- Recommendations prep before starting phonegap project
- Familiarize yourself with your shell, where your files are and where you want them to be
- Beforehand Install/Setup: java, node, Android Studio* (not just the tools), cordova, phonegap, ant, avd, $PATH, $ANDROID_HOME
- Download the phonegap app and $ phonegap serve your app out easily for testing purposes
Wednesday, February 18, 2015
PhoneGap: Part 1
How do you build an app both android and ios compatible knowing neither objective-c nor java? Having spent the last month plus learning javascript, phonegap seems the way to go.
The biggest challenges were setting up the required parts, knowing what was needed and where to get it from. First my system needed java, then node, and after downloading the tools package from the android developer website I found it was not sufficient. By the end of the day the $PATH was defined in freshly created .bash_profile's, one in the ~(home) directory and one in the local directory.
Note: This last point is cringe worthy, .bash_profile does not belong in the local directory of the app. This folly exposed that I did not know where the fundamental unix files belong, or the effects of basic commands such as touch.
In the end I had emulated my app, with luck and some understanding of what I was doing. The next step is to review a UNIX tutorial, and traverse this process again.
Questions
The biggest challenges were setting up the required parts, knowing what was needed and where to get it from. First my system needed java, then node, and after downloading the tools package from the android developer website I found it was not sufficient. By the end of the day the $PATH was defined in freshly created .bash_profile's, one in the ~(home) directory and one in the local directory.
Note: This last point is cringe worthy, .bash_profile does not belong in the local directory of the app. This folly exposed that I did not know where the fundamental unix files belong, or the effects of basic commands such as touch.
In the end I had emulated my app, with luck and some understanding of what I was doing. The next step is to review a UNIX tutorial, and traverse this process again.
Questions
- What is npm?
- What is ant
- What is avd
- What is the difference between PhoneGap and Cordova?
Subscribe to:
Posts (Atom)