This blog no longer exists.
You will be redirected to something cool.

Monday, December 13, 2010

Why Computer Science?

I've always had an interest in things computery. When I was 13, my life goal was to work for Microsoft, but I never was particularly encouraged to do so. Also at 13, I wrote a LOT. My family saw this and urged me to pursue something along the lines of language. I'd tossed around this idea in my head and thus listed out the different "majors" one could have that related to linguistic ability.

I could pursue English as a major, but I never found it interesting to compose large pieces of writing. Creative writing would also be required somewhere along the line which would be enough to make me panic! I often say that I haven't an artistic bone in my body. While this is a slight exaggeration, it is just that: slight.

I did find foreign languages extremely fascinating, but I found that in taking foreign language courses the most fun was had in finding cognates. Not only cognates between language X and English, either. I would search for cognates between languages that were not my own. The problem I had with majoring in a foreign language was that I couldn't learn several at once. I didn't want to major in French because then what about German? And Italian? Russian? Japanese?

I know it is common for foreign language majors to major in more than one foreign language, but I wanted to learn more than just one or two languages. And then I realized it: It's not the languages themselves that interest me. It's the relationships between languages. It was linguistics that interested me: the problems with pragmatics and the translations of historic texts, the different types of morphemes, etc. These things fascinated me, but I always wanted to DO something with them.

I couldn't create a language... well I could, but why? I didn't want to study something that I felt the sole purpose was to teach it to other people. And I do know that linguistics has MAJOR applications, but nothing that interested me.

Learning to program and writing programs... these things make me feel like I do when I am reading something on linguistics. From what I've seen of programming thus far, there are similarities between it and linguistics. And, of course, one being the passion I feel in searching for an answer, trying to figure something out, and reading something new. Yes, I'm new at it, but here I am at 4:57 in the AM (still awake from learning more programming) typing out my thoughts on linguistics and the relationship it has with programming. I could go into depth with the nerdy guts of WHAT it is about linguistics and WHAT it is about computer science that make them similar in my eyes, but perhaps I will do that another time.

Saturday, December 11, 2010

Holy Crap, I Learned Recursion!

After an extensive (about a week) amount of time I decided to go forth into the unknown and learn: recursion. It was VERY confusing to me at first. VERY! But... I finally got it.

I may need to review what I have learned, but I think I have it down. It was a scary adventure and I may eventually write about recursion down the road as I get comfortable using it so that those who do not understand it can possibly learn it from me. Recursion seriously had to be pounded into my head several times before I got it. At one point I was pretty sure I would never figure it out and wanted to give up learning to program.

I have to remember that no matter how hard a problem is... I will likely always make it to the other side. So, we'll see what other things programming throws at me. Hopefully nothing too scary, but we'll see.

I am very excited to create some programs and already have some programs in mind that I could write given a little more persistence and knowledge. I can't wait until I actually have a cool web app up and running that I can show the world!

Monday, December 6, 2010

The Hangman Program

While this program was difficult for me to write, I learned a lot of new things while writing it such as a do while loop. There was a way to avoid creating a do while loop, but it was good to learn something new so I'm glad I used it. Creating this program has really shown me that there are a large number of things you can do to arrays. This is also the first time where I've really experience the fact that in programming there are more than one ways of doing something.

The hangman program can be found here:
https://gist.github.com/728851

Sunday, December 5, 2010

War Game Program

It was actually fairly easy for me to write, but with the help of a friend who writes awesomely in Ruby on Rails, I was able to learn a better way to write this program. The program can be found here:
https://gist.github.com/724880

Tuesday, November 30, 2010

First to 100 Game Program

This one was monumentally more comfortable to write than the lottery program although it uses similar elements. I have a few questions that I will ask about things I can do to make the program smaller, but I am still proud of this program despite its size.

The url: https://gist.github.com/721398

The Lottery Program

So you may have noticed I haven't posted for a while. Why? The lottery program. Yeah. It was a dreaded horrible beast. I saw there for weeks, really, staring at the lines of code I'd spewed forth, stressing, rewriting, throwing things (okay, not really.) And then I was told to take a break. I did... a long one. It would be just fine if I could just write every program in the book just not this one. It was impossible and a stupid task.

But alas, I could not excuse myself from the project so I sat down to it. Ever have one of those moments when you feel like one synapsis fires, and then thus another one, and then it's just a cascade of just everything working... it puts you on quite a roll. That's what happened. I HATED this program for the longest time, but as I was finishing the program, I just felt so on top of everything. It felt really good, empowering or something.
I created a new GitHub... actually I just changed my sn over there.

This is because I'm going now... this is what I've always wanted to do growing up and no matter how many walls I face how many tall, towering lottery programs I face, I will cower like a big baby, cry about it, and then face my problem head on. Below is the link to my completed lottery program. Yeah, there are better ways to write it, but as I learn those ways, I will come back and improve upon the program. I think showing these changes would be better viewed on github than here, but I will continue to document my journey here.

The program:
https://gist.github.com/707654

Tuesday, November 2, 2010

Dice Game: Ifs & Loops

I had a little fun with some 'ifs' and 'while loops' with this program. When I first started the program I became somewhat frustrated. I stopped and slept on it. When I came back to the code, it was sooo easy to piece together. The break was a really good idea. The code:
count = 0
count2 = 3
guess = 0

while guess <2 || guess >12
  puts( 'Pick a number 2-12: ')
  guess = gets.chomp.to_i
end

dieTotal = 0

while dieTotal != guess && count != 3
  count = count + 1
  count2 = count2 - 1
  die1 = rand(6)
  die1 = die1 + 1
  die2 = rand(6)
  die2 = die2 + 1
  dieTotal = die1 + die2
  input = ''
  puts( 'Type roll to roll the dice: ')
  input = gets.chomp

  while input != 'roll'
    puts( 'Type roll to roll the dice: ')
    input = gets.chomp
    puts( 'I don\'t understand. ')
  end
  puts  
  puts( "Your guess is #{guess}.")
  puts( "You rolled #{die1} and #{die2}. For a total of #{dieTotal}.")
  puts

  if dieTotal != guess && count2 > 1
  puts( "You have #{count2} rolls left.") 
  puts
  elsif dieTotal != guess && count2 == 1
  puts( "You have #{count2} roll left.")
  puts
  elsif dieTotal != guess && count2 == 0
  puts( "You have no rolls left.")
  puts( "Sorry, you lose.")
  else
  puts( "Congrats! You win!")
  end
end

Friday, October 29, 2010

Quiz Program (Loops)

This one was difficult for me, but not as much as the last time I encountered loops. I think after a few more small programs with loops I'll feel more comfortable with this. I created a quiz about me. Feel free to run it and take it. (It's in Ruby.)


puts( '     <(^.^)> LITTLE KNOWN FACTS O\' MELANIE <(^.^)>')
puts
puts( 'To play, select the letter that corresponds with your answer
then press return')
answer = ''

while answer != 'c'
puts( '#1 Gym class sux. How would Melanie get out of running laps in Elem school?')
puts
puts( 'a. She got a doctors note')
puts( 'b. She refused')
puts( 'c. She hid')
puts( 'd. She got extra help in another subject instead of going to gym')
answer = gets.chomp.downcase
end

puts( 'Correct!')

answer = ''

while answer != 'b'
puts( '#2 Melanie has a scar on her knee from kindergarten. How did she get it?')
puts
puts( 'a. She fell off the jungle gym')
puts( 'b. She was running in flip flops and tripped')
puts( 'c. She got beat up')
puts( 'd. Her brother threw something at her')
answer = gets.chomp.downcase
end

puts( 'Correct!')

answer = ''

while answer != 'a'
puts( '#3 Melanie failed ONE class in high school. Which was it?')
puts
puts( 'a. government')
puts( 'b. business services technology')
puts( 'c. geometry')
puts( 'd. art')
answer = gets.chomp.downcase
end

puts( 'Correct!')

answer = ''

while answer != 'c'
puts( '#4 Melanie is l337 fail at sports. Which sport did she play in high school?')
puts
puts( 'a. basketball')
puts( 'b. cheerleading')
puts( 'c. track')
puts( 'd. volleyball')
answer = gets.chomp.downcase
end

puts( 'Correct!')

answer = ''

while answer != 'b'
puts( '#5 Melanie went on a family vacation when she was 10. Where did she go?')
puts
puts( 'a. Virginia Beach, VA')
puts( 'b. Chattanooga, TN')
puts( 'c. Groton, CT')
puts( 'd. Tell City, IN')
answer = gets.chomp.downcase
end

puts( 'Correct!')

Thursday, October 28, 2010

Random Number Game

It was a little difficult to come up with how to assign the random number to the variable -- it was a durrr moment for sure. So without further ado here is the first part of the program (or problem #2 according to that post I linked to above:)
randomNumber = rand(10)
randomNumber = randomNumber + 1
print( 'Guess my number! Enter a number (1-10): ')
userNumber = gets.chomp()
puts( "Your number is #{userNumber}. My number is #{randomNumber}.
This program is not yet advanced enough to tell you whether you
are correct -- but you should be able to tell.")

Here is problem #3:
# Try to figure out if there is a way to chomp & convert to an integer on
# same line (lines 7 and 8)
# Try to figure out how to print failure message (lines 14-16 & 20-22) for
# both cases in which the user is incorrect without having it in the program
# twice. 

randNumber = rand(10)
randNumber = randNumber + 1
print( 'Guess my number! Enter a number (1-10): ')
userNumber = gets.chomp.to_i()
if userNumber == randNumber
 puts( 'You guessed correctly! You are SOOO smart!')
elsif userNumber > randNumber
 puts( "Your number (#{userNumber}) is higher than my number (#{randNumber}.") 
 print( "You are unable to guess again because you are such a failure. It
has nothing to do with my inability to program this such that you could
guess again.")

else
 puts( "Your number (#{userNumber}) is lower than my number (#{randNumber}.)")
 print( "You are unable to guess again because you are such a failure. It
has nothing to do with my inability to program this such that you could
guess again.")

 end
Update:
I figured out how to fix problem #3 for that error message. Dumbest thing ever... how about a variable? I'm sure we all have those blonde moments, though. Also, got help from a friend on the chomp.to_i thing (that's what you do>> gets.chomp.CONVERSION NOT gets.CONVERSION.chomp.) New code:
randNumber = rand(10)
randNumber = randNumber + 1
print( 'Guess my number! Enter a number (1-10): ')
userNumber = gets.chomp.to_i()
failureMessage = 'You are unable to guess again because you are such a failure. It
has nothing to do with my inability to program this in such a way that you 
could guess again.'
if userNumber == randNumber
 puts( 'You guessed correctly! You are SOOO smart!')
elsif userNumber > randNumber
 puts( "Your number (#{userNumber}) is higher than my number (#{randNumber}.") 
 print failureMessage

else
 puts( "Your number (#{userNumber}) is lower than my number (#{randNumber}.)")
 print failureMessage

 end

Problem #5 was much easier to complete and more fun as I'm getting the hang of loops:
randNumber = rand(10)
randNumber = randNumber + 1
count = 0
userNumber = ()
print( 'Guess my number! Enter a number (1-10): ')

while userNumber != randNumber
  userNumber = gets.chomp.to_i()
  count = count + 1
  failureMessage = 'You did not guess correctly. Guess again:'

  if userNumber == randNumber
 puts( "You guessed correctly! It took you #{count} time(s) to guess.")
  
  elsif userNumber > randNumber
 puts( "Your number (#{userNumber}) is higher than my number.")
 print failureMessage

  else
 puts( "Your number #{userNumber} is lower than my number.")
 print failureMessage

  end
end

Getting in the Groove (Embedded Variables)

Yeah, I'm still on the whole embedded variables thing, but this is SOOOOOO much easier. Today I worked on getting used to doing things this way. It'll take a bit of time to memorize, but in the meantime I created a mad lib to kind of get used to it. Enjoy!

#  Is it customary to start variable counts at one? (ie. noun1) or
#  at zero (ie. noun and the second being noun1) or how else is this
#  handled?

print( 'Enter an adjective: ' )
adjective1 = gets.chomp()
print( 'Enter a verb ending in "ed": ')
verbEd = gets.chomp()
print( 'Enter a plural noun: ')
pluralNoun1 = gets.chomp()
print( 'Enter a liquid: ')
liquid = gets.chomp()
print( 'Enter another plural noun: ')
pluralNoun2 = gets.chomp()
print( 'Enter a famous person: ')
famousPerson = gets.chomp()
print( 'Enter a place: ')
place = gets.chomp()
print( 'Enter an occupation: ')
occupation = gets.chomp()
print( 'Enter a noun: ')
noun1 = gets.chomp()
print( 'Enter a nationality (ie. American or Irish): ')
nationality = gets.chomp()
print( 'Enter a female celebrity: ')
femaleCelebrity = gets.chomp()
print( 'Enter another noun: ')
noun2 = gets.chomp()
print( 'Enter the name of a female friend: ')
femaleFriend = gets.chomp()
print( 'You\'re almost done. Enter another plural noun: ')
pluralNoun3 = gets.chomp()
print( 'Enter a number: ')
number = gets.chomp()
print( 'Enter an adjective: ')
adjective2 = gets.chomp()

puts ( 'Personal Ad:')
puts
puts ( "I enjoy long, #{adjective1} walks on the beach, getting #{verbEd} in 
the rain and serendipitous encounters with #{pluralNoun1}.
I really like piƱa coladas mixed with #{liquid}, and romantic, candle-lit
#{pluralNoun2}. I am well-read from Dr. Seuss to #{famousPerson}. I travel
frequently, especially to #{place}, when I am not busy with work. (I am a
#{occupation}.) I am looking for #{noun1} and beauty in the form of a 
#{nationality} goddess. She should have the physique of #{femaleCelebrity}
and the #{noun2} of #{femaleFriend}. I would prefer if she knew how to
cook, clean, and wash my #{pluralNoun3}. I know I’m not very attractive in
my picture, but it was taken #{number} days ago, and I have since become 
more #{adjective2}. ")

Embedded Variables in Strings

So I'm learning Ruby again, but this time I've got a program in mind. It will take a lot of brushing up and general learning before I will be able to start the program. I already know how to write the program without an interface, but I want to build an interface too, so it'll take a bit of work. I think once I get this particular program coded that I'll know enough about programming to be able to work on other programs so that will be really nice.

Tonight I started reading "The Book of Ruby" which is a big step up from the last book I read, but I think I'm understanding it fairly well considering the difference in difficulty between the two texts.

So tonight's topic was Strings and Embedded Evaluation. The sample code in the lesson is as follows:

print( 'Enter your name: ' )
name = gets()
puts( "Hello #{name}" )

After reading the OTHER book on Ruby I would have programmed this like so:
puts 'Enter your name:'
name = gets.chomp
puts 'Hello ' + name + '.'

However, I learned that by using "print" instead of puts, I can keep the cursor on the same line... which is cool, I don't know what real difference it would make other than aesthetics, but I guess I'll find out later. I did add a period so that I could make it a proper sentence and added the corresponding chomp to make this possible.

What I mostly learned was this whole embedded variables thing. I'm a little confused as to the purpose -- if it's just faster to code like this and less confusing than all the plusses and whatnot from something like 'Words here' + someVariable + 'another string.' I can really see that being the case, however, I'm not going to assume that it is simply for cleaner and faster programming -- until yeah, I am told so.

I also played a bit with "\n" and "\t" which are newline and tab. It took a bit getting used to the whole new way of doing the embedded thing and playing with newline and tab helped me get used to it a bit. Here's the code I created using this newfangled stuff I learned:

# Playing with tab \t and newline \n
puts ( 'How about a sentence of sort?')
sentence = gets()
puts ( "\t #{sentence}\t\t #{sentence}")

I used the sentence "I like rocks and giraffes." (Without the quotes.) And thus, the program spits out this:
I like rocks and giraffes.
     I like rocks and giraffes.
          I like rocks and giraffes.

Definitely some stuff to play around with for a bit. I perhaps I could rewrite this to capitalize the first letter if it is not capitalized and to add a period if there is not one. I think this would be a good project for tomorrow. :P