This is an old revision of the document!
I learned a lot so far. Not just an intro of compiling C, but I also learned how to make a console program through C. I learned how to compile C into an executable on pretty much any OS. Although, I still do have a lot of questions, such as, how would I go about making an OpenGL program on Windows? How would I make an OpenGL program on other OSes such as Linux and Mac OS X? How do I even use OpenGL? With the Windows Objective-C compiler, what headers can I import in? Would these headers be the same as Apple's on Mac OS X? And to what version? Can I do some evil with pointers such as specify specific memory addresses and get the value of what's in said memory addresses?
I have a lot to learn…
We did a C project where we made a program that used a trick to square two-digit numbers that ended in 5. In the trick, we left “25” at the end, and, from the first digit of the number (n) that was input, we got the hundreds place like so: ((n / 10) * ((n / 10) + 1) * 100).
This trick might be able to work with any set amount of digits by changing what's appended and what the first digit is. My question is, we have powerful computers, and they would use a lot less power if they had simply multiplied out the numbers. They are machines, not humans. I'm not sure if it's optimized more for the computer to use the human trick of two-digit squaring with numbers ending in 5, but, it's there…
Update to reflect reflection
- The trick will work with 3 digits. For example, 105 ^ 2 = 11025.
((105 / 10) * ((105 / 10) + 1) * 100
= (10 * 11) * 100
= 110 * 100
= 11000
. Add 25 and you will get 11025.
- The trick will also work with 4 digits. For example, 1005 ^ 2 = 1010025.
((1005 / 10) * ((1005 / 10) + 1) * 100
= (100 * 101) * 100
= 10100 * 100
= 1010000. Add 25 and you will get 1010025.
I didn't even know the day of the week mental math procedure before this project. I think it's a really neat trick. I believe now it is a ton easier to figure out what day of the week that January 1st will be. The programming for a script to calculate it becomes much easier when a programmer not only uses if
and switch
statements, but also when a programmer is able to exploit the native C int
type for their advantage.
When dividing two int
s, C will truncate (cut off) the decimal. When people, for example, punch in 3 / 2
into a calculator, the calculator will output 1.5
. However, 1.5
is a floating-point decimal number. In C, to get an integer from the number 1.5
, the computer will cut off the decimal in order to get the number 1.5
into an integer that's able to represent it. In this case, if we decide to, say, run this code…
int a, b, c; a = 2; b = 3; // set start values c = b / a; printf("%d", c); // print out c
Then we end up with 1
in stdout
when most people would expect 1.5
to be rounded to 2
. Please note: This is roughly equivalent to using floor()
without importing any external libraries.
As a secondary example: For the step in the calculation where we have to get the biggest fitting multiple of 7 to subtract from the end of the year multiplied by 1.25, most would resort to this code:
multof7 = floor(eoy125 / 7) * 7;
I switched my code to this and abused C's integer truncation:
multof7 = (eoy125 / 7) * 7;
In addition: I also used the modulus operator (%
) to return the last two digits of the year, rather than simply subtracting 2000. Meaning mine might be accurate for years that aren't in the 21st century. Some of us might live in the past, and some of us might live in the future.
UPDATE
This is not true. Days in the 20th century are consistently a day off. However, it is accurate for every 4th century after the 1st (0-99 AD, 400-499, 800-899, etc).
I'm honestly at a loss for how the algorithm works for years where the end two digits of the year are 0.
It took a long while, but my prime number script is about as optimized as I'm going to get it. Here's what I did:
- Found that all primes mod six are either 1 or 5. Any result that's even is either even or divisible by 3. - Found that no even number (except 2) is prime, so it iterates by 2. - Found that no number ending in 5 is prime, since it's divisible by 5. If the iterator is divisible by 5, it increments by 2 again. - Since arrays allocate memory in order and array elements are faster to access than variables, I used those. - I used prefix increments instead of postfix, because those are quicker - I store primes in an array to use Sieve.
I've tried redefining square root and found that I can instead check if the number times itself is greater. If it's equal, it's not prime.
This sort of computational skill is not only fun to me, but it can be useful in the future in order to speedup currently implemented system implementations. I like puzzles like this. Give me more.
We got ourselves a little bit more acquainted with the machines. Although the class has an IRC chat, I have no idea where the server is located. It is probably in the next room. With that being said…
echo “Hello, world!”
The IRC chat is nothing if you don't know how to use it proficiently. It can be a help to those that know how to use it, but, if you don't know how to use the IRC, good luck. Luckily /help command
is a thing on Irssi, and it's a very nice thing at that. What threw me off for a good couple moments was how to be able to connect to Lab46's IRC server, because that wasn't explained very well, in my honest opinion.
IRC helps, but, without documentation, it's useless. As with any piece of software. I'm talking about you here, Apple, with your out-dated non-ARC using Objective-C documentation for doing simple stuff that would be required in your new-fangled games… ugh. Your documentation sucks, Apple. To say the least.
In our latest project, we explored how to make, add files to, and compress an archive using Gzip, Tar, and Zip on UNIX/Linux systems. Using that, we took out four files from an archive and re-arranged the text in them to form a forward-facing Mudkip, or the LAIR Image Calabration System Test Image (LAIRICSTI). In order to submit a compressed tar archive (tarball), we had to archive it using tar, and then compress it with gzip.
My assumption is, tar archive files can optionally be compressed into a file with the .tar.gz file extension using gzip, but, if corruption among the network is a worry, then they can upload the uncompressed file over a secure TCP connection.
At least, that is one benefit of sepearating archival and compression into two different formats. Now, the Internet is pretty reliable and not corrupted, so we don't have to worry about corrupted compressed file uploads.
So in UNIX, you can change the end of a file name so it doesn't fit convention. For example, you can neatly name your zip archive “mytextfile.mp4” and watch IT get more and more confused. It's fun to do, in all honesty. As far as the puzzlebox project went…
In each respect, that lab was one of the most fun ones I've had yet, and I only hope to have more like it!
The second lab, Puzzlebox NEXT (pbx1
) wasn't as much of a challenge as the first Puzzlebox was. It was simply using uudecode
, unzipping a file, and re-arranging four parts of a text file to get ASCII art of a bat out of it. I figured there would be more to the lab, but that was it.
In class today, we got started with using vi as a text editor. It looks to be really useful with editing code in C, and, even though I already sorta use Vim on my Mac for some stuff, I can use it to write code in C in OpenBSD. Speaking of OpenBSD, I would partition a flash drive to be able to boot OpenBSD on it, but the computers here have, oddly enough, a password-locked BIOS on them.
Even I think that's weird that the Windows 7 computers have a locked BIOS and that you can't boot from a flash drive or an external hard drive, but, I guess it's so IT can have that amount of control over the computer, or, if someone decides to yank the USB drive while it's running, it's so they don't have to deal with the possibility of hardware failure.
My guess is that, in addition, it would interfere with the DeepFreeze software that goes and re-images Windows 7 every time the computer boots up. Either way, it's strange, but I guess it helps with security.
Web pages were actually how I got into programming. The web based adventure was easy to me for that reason. When I was around 10, I read books on HTML 4.01. I had a website coded and up when I was in 6th grade, and now I forget the credentials to access that domain. Coding HTML was always fun for me, and the web based adventure was a cinch in that matter.
I could've tried to use more advanced CSS to make it fancier, but I didn't quite have the time to do that. I had other priorities at the time I worked on it, such as calculus, sociology, the optimized prime number calculator, and, of course, forgetting about the Opus, somehow, for a full month. I'm not even sure how that one even happened. I've been working on programming for a good while now. I know there was a break for a week in February, but I'm still unsure of how I forgot to do an Opus entry, yet I remembered to program a lot. Oops.
Hopefully this month, I'll fix it.