In my first couple of years in college I used to eat out a lot. One of the first programs I made in college was for my buddies and I to pick a place to eat. It's was a rather simple program. Took in a list of places to eat from a text file and chose one randomly.
I think it's about time for a slight upgrade though. Today's problem will be to implement the random food picker program and to also make sure that the same place isn't selected twice in a row. This means that your program will need to remember what it chose the last time it ran. Either via text file, HTML5 localstorage, database, etc.
Comments:
Carlos - 10 years, 8 months ago
Java code is always huge, so there's that. Pretty straightforward problem, just use the last line in the folder, or the first, to save the last place you were.
reply permalink
Carlos - 10 years, 8 months ago
The method pickPlace() is actually wrong, since i'm going for static variables, it should clear whatever was remaining on the other variables
Also, the file should look somehting like this for this solution (they have '/n's):
There; The other one; Everywhere; Xing Xong; Kunt Pao; Lagostas; Doritos; The other one;
reply permalink
Jt - 10 years, 8 months ago
C#, also I learned that I don't know how to spell restaurant.
reply permalink
Mre64 - 10 years, 6 months ago
I cannot spell "definitely" without spell check for the life of me. No idea why its such a hard word for me...
reply permalink
Hueho - 10 years, 8 months ago
Over-engineering to the max (Ruby)
reply permalink
Pegleg - 10 years, 8 months ago
Simple text file input/output seperated by whitespace, I.E Ruby Tuesdays 0 Chipotle 1
import random import os import sys dictz = {} if os.stat('res.txt').st_size==0: print 'abort! file is empty' sys.exit() file = open('res.txt', 'r') for line in file: temp = line.split() dictz[temp[0]] = int(temp[1]) file.close() choice = random.choice(dictz.keys()) while dictz[choice] !=0: choice = random.choice(dictz.keys()) print 'We choose', choice, '!' file = open('res.txt', 'w') dictz[choice] = 1 for k,v in dictz.items(): if v == 1 and k != choice: v = 0 file.write(k + ' ' + str(v)+ '\n')
reply permalink
Pegleg - 10 years, 8 months ago
My apologizes vim copy and paste... How do I clean up the formatting :-X also this was in Python
reply permalink
Max Burstein - 10 years, 8 months ago
The site uses github flavored markdown so you can just post your code like this https://help.github.com/articles/github-flavored-markdown#fenced-code-blocks
The preview comment button will also allow you to see how it will be formatted before you post.
reply permalink
Pegleg - 10 years, 8 months ago
FIXED, bahaha thanks! I'll be better next time
reply permalink
Walker Crouse - 10 years, 8 months ago
So here's something a bit different. I built this Java program with a Java wrapper around Google Places API that I wrote a few months ago.
It picks takes a zip-code, radius (m), and max and min price to select restaurants and then picks a random one from that. Every time one is picked it is put in a text file and compared to make sure two places cannot be picked multiple times in a row.
Sample Output:
reply permalink
Mre64 - 10 years, 6 months ago
BRILLIANT WORK !
reply permalink
Karl T - 10 years, 8 months ago
This took me about 4 hours to make (no regrets!) and I'm pretty proud of the result (even if it's way more complicated than it needs to be).
Stores the list in a text file and stores the last-eaten-at place in a separate text file to avoid having to re-write the potentially long list each time (though this could be stored to registry if really needed).
Has the ability to get a true random number from random.org! :D
Feedback very much requested!
reply permalink
Mre64 - 10 years, 6 months ago
/* Mre64 6/9/14
*/
import java.util.Random; import java.io.*;
public class FoodPicker {
}
reply permalink