This blog no longer exists.
You will be redirected to something cool.
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Monday, December 24, 2012

Secret Code Programming Puzzle

I'm trying to solve a mathy programming problem. (I came up with the problem a couple of years ago, but it's still preying on my mind.)

There is a secret code (which you're allowed unlimited guesses at) => a string 12 characters in length. Each character can be either a number or a letter (a-z, 0-9) and it's not case-sensitive (A == a).

After every hour, a character in the secret code is revealed.

For example:
Hour 1:
_ _ Q _ _ _ _ _ _ _ _ _

Hour 2:
_ _ Q _ _ _ _ _ _ _ 4 _

Hour 3:
_ _ Q _ _ _ _ 7 _ _ 4 _

Hour 12:
1 C Q 8 2 V V 7 J B 4 9

I want to write code that solves the code before a human can. I figure a human can realistically start manually entering combinations at around hour 10. I would like my program to solve it before then.

What should the program do when another hour goes by and another secret character is revealed? I was thinking of starting out with an array of all the possible combinations, but populating and storing the array would take an immense amount of time and resources. I was thinking about storing this array and when a new character is revealed, rejecting ALL strings from the array that don't have the new secret character in the exact position.

At a worse case scenario of making guesses with all 12 characters left unrevealed, we're left with awful time complexity:
36 numbers and letters, 12 mystery characters
36^12 == somewhere considerably longer than I have remaining in my lifetime given however long it takes in a single-threaded program to make a guess. Still too long in a multi-threaded program on the world's best computer.

However, this goes down significantly after each hour. So I have several questions to answer:

Should I start my program at a certain hour? If so, would there be any benefit to at least STARTING to populate an array before said starting hour? Would I even need to populate a massive array?

Friday, November 30, 2012

The Course Schedule Program

My school lists the course schedule as pictured. The search functionality is deficient in that it offers little customization in the "advanced search."


I would like to "pull" the entire schedule and do the following things to help me choose classes:

1.) Have an option to compare it to a list of classes I'm required to take, classes I HAVE taken, and any classes I'm currently schedule to take in order to finish school and return ONLY those that,
  a.) I haven't yet taken.
  b.) count toward major.
  c.) fit within my current schedule in terms of times and dates
  d.) I'm qualified to take. (In terms of pre-reqs.)

2.) Have functionality that allows me to see the maximum number of classes I can take during a semester. Preferably order combinations of classes in such a way that the schedule combo with the highest number of credit hours in listed first and the one with the least is (obviously) listed last. This would prevent crappy schedules that have weird times slots that make finding other required classes difficult.

3.) Allow me to see the professor score for a class section as reported by (ratemyprofessors.com.) I won't need this to be searchable, but it would be nice to be able to see that data.

4.) Have functionality that allows me to prevent certain classes from showing up. For example, if I don't want to take AD 123 (even if it DID count toward my major), I would like to prevent it from showing up.

5.) Functionality to ignore the requirement that a class should count toward my major. This would be particularly helpful if I couldn't find a course within my major that would properly fit in my schedule.

(Perhaps this functionality would be the default behavior of the program and it the program would score class combinations based on relevance to requirements. In order to keep things from getting weird, create a credit hour limit for schedules of 19 credit hours.)

6.) Functionality to consider a "must-have" class (or two or three...) into the schedule. If I HAVE to take Awesome 101, section 4, with Professor Cool, I want to see potential schedules built around this.

7.) If I don't care for a professor, I would like to exclude him/her from my potential schedule.

How would I best achieve this?

I'm considering using Ruby (since that's what I'm most comfortable with), but I'm open to whatever (even Perl.)

My first instinct is to programmatically open the schedule with something like open-uri, and pull all course data. I was thinking of using nokogiri to search the data, but I think that throwing everything into a database and then querying the database would be a MUCH faster and MUCH better option.

My question is this:
What technologies would be best suited for this project? I literally have zero experience with databases except for a tiny bit of relational algebra (not enough to help me out in any way.)

It's probably also important to note that I would like to make this available for use on CodeGurl (mainly as a 'look ma, no friends' type thing), where a student can upload a spreadsheet containing classes they've already taken, classes they're required, and any must-haves, so any technologies related to deploying this would be helpful too. I've never deployed or packaged anything.

I basically need help with figuring out which direction to go with this. I beg you guys not to do the project for me (what would I learn? Nothing. And I'd feel like dirt.) However, any links, lists of technologies (and what problem they solve) would be GREATLY appreciated. Any technologies that are beginner friendly (have a LOT of beginners guides) would be FAB!

-Melanie

Tuesday, February 21, 2012

Disguising Load Times w Information

So I'm writing a script that essentially allows people to enter a url of their writing profile on a particular site. The script will then give them a list of articles that don't meet their own quality specifications and also provides the writer with fun facts about their writing. Users can customize some pre-set specifications. For example, the word count specification, which defaults at 1000 words, can be set to equal 700 words. Then, the user can see a list of articles they've written that are under 700 words. In addition, the script will show users their average word count across their entire account.

I have a few problems with the script. One of the larger problems is that for users with large account (500+ articles), the load times are ridiculous. I would like to kind of disguise the load time by offering information about articles as the script is running. As is, nothing is able to show up until the script has completely run.

I would like the script to show on-page, the current average(changing with each article), the number of articles the script needs to comb (or at least a % complete), and a list of the article that don't meet a particular qualification as it fails.

Currently, my script takes ALL urls and opens them, puts the words into a hash of arrays and does word count calculations from there. Since much of the load time is in opening urls, pulling and cleaning text, my current design does not really allow for giving information during load time.

Here is the current script.

Another problem is the way in which I count words. It's way off. I've got to work on that, but I've already got a solution in mind. I just need to implement it.

Edit: Unfortunately, at this time, HubPages is testing several different layout changes. Because of the way in which I wrote the code (picking out bits of CSS), I've decided to hold off on this project. When HubPages calms down with the design changes, I will continue with the project. See you then! (June 2010)

Thursday, August 18, 2011

Word Length Checker

This tool checks for word length, but instead of pasting text into a box, it's more complicated than that. Here's the problem I was having and why I created this tool:

One of my niche sites has several hundred posts of varying length. Since Panda it hasn't been doing so well, and a huge part of this is the length of each post. The only posts that are doing well are the longer ones. So I wanted to find each of the offending "short" posts and expand on the topic of each. There are several hundred posts, so it's something that will take quite a bit of time doing manually, thus this tool was born.

While there is a better way to do this than by pulling the blog's RSS feed (the feed only hold x amount of information) I decided that this would be the quickest way to get the program up and running. The program is written in Ruby and uses nokogiri & open-uri so that it can retrieve and parse not only the feed, but each post on the feed. It then takes each post and counts up the words. The end result is a list of articles (and their content) which does not pass a minimum word length (which is essentially just a list of blog posts I need to lengthen.)

It's a work in progress, thus the gist over the formal repo, but head on over to the project to check it out!

Wednesday, July 27, 2011

Keyword List Maker

I created ListMaker while I was doing some keyword research. I wanted to check the global monthly searches for something in each US State. Let's say the keyword was "travel destinations." I wanted to check for each:

"Travel destinations in Alabama"
"Alabama travel destinations"

"Travel destinations in Alaska"
"Alaska travel destinations"

And so on and so forth for each US State. Unfortunately there are fifty states and that requires a lot of data entry, so I wrote code that asks:

"What is your keyword?"

"Would you like your keyword to go before (b) or after(a) your state?"

The code will then map each state to "travel destinations" and print the keyword list to a new file. I decided to have the program name the file after the keyword, instead of just some static name, in case I want to map states to multiple keywords.

You can download Keyword List Maker. Or just check out the code.

Thursday, July 14, 2011

MBTI Program - Getting Started

I am starting on the MBTI (Myers Briggs Type Indicator) quiz program that I decided to write. I chose to write this program because I wanted to learn how to write a quiz.

One of the most interesting elements I want to include in this is the ability to hide which answer equals which type. This is to prevent against scraping. I first came across this concept when I was hand-scraping a quiz to see which answers equaled which personality type. One website programmatically writes the IDs for each question and leaves absolutely no information in the other parts of the mark-up that lets users know which answer equals which type.

Tonight I worked on getting the HTML and CSS written for this program. It's extremely plain right now, but I did at least create a minimalistic header for it using an image I found in Google search (very very bad girl) and PhotoShopped (err The GIMPed??) it with a Free For Commercial Use font I found.



















If you are curious about how the markup looks at this point, it is below. I want to remind you, however, that it is very minimal at this point. Click on the image to make it larger.

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