<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JosteinB &#187; quiz</title>
	<atom:link href="http://josteinb.com/tag/quiz/feed/" rel="self" type="application/rss+xml" />
	<link>http://josteinb.com</link>
	<description>The blog with the awesome slogan</description>
	<lastBuildDate>Fri, 26 Mar 2010 17:31:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Simple quiz-program in Python</title>
		<link>http://josteinb.com/2009/05/simple-quiz-program-in-python/</link>
		<comments>http://josteinb.com/2009/05/simple-quiz-program-in-python/#comments</comments>
		<pubDate>Fri, 01 May 2009 11:42:33 +0000</pubDate>
		<dc:creator>Jostein</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[quiz]]></category>
		<category><![CDATA[studying]]></category>

		<guid isPermaLink="false">http://josteinb.com/?p=56</guid>
		<description><![CDATA[When we were studying for exams, Tobias and Peder1 decided to make some tools to help us study.  This is Tobias&#8217; version, written in Python. &#8220;The program is fairly simple. You select a text file containing lines with topics you want to learn, and then you have to type inn all of them. The program [...]


Related posts:<ol><li><a href='http://josteinb.com/2009/05/simple-quiz-program-written-in-java/' rel='bookmark' title='Permanent Link: Simple quiz-program written in Java'>Simple quiz-program written in Java</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>When we were studying for exams, <a title="saiboten" href="http://saiboten.com" target="_self">Tobias</a> and <a title="truben" href="http://truben.no/journal" target="_self">Peder1</a> decided to make some tools to help us study.  This is Tobias&#8217; version, written in Python.</p>
<p>&#8220;The program is fairly simple. You select a text file containing lines with topics you want to learn, and then you have to type inn all of them. The program writes how many topics are left, and can also give you hints if you need it. You are finished when you have written all topics, or have given up by typing “stop”. Then it writes out how long time you used.&#8221;</p>
<p>Read more for the code</p>
<p><span id="more-56"></span></p>
<pre lang="Python">import time
import os

avail_topics_in_file = []
topics = []

#Traverse folder
for root, dirs, files in os.walk("."):
    for file in files:
        #Check if file ends with .txt
        if file.endswith(".txt"):
            avail_topics_in_file.append(file)

#print topics
print "Select topic:"
for i in range(0,len(avail_topics_in_file)):
    print i+1,avail_topics_in_file[i]

#find topic
selected_topic = int(raw_input())-1
chosen_file = avail_topics_in_file[selected_topic]

print "You have selected",chosen_file.split(".")[0] + "."

#Run through file and add each line to topics
f = open(chosen_file)
for line in f:
    topics.append(line.strip())

#Save answer to answer-variable
answer = topics
topics_len = len(topics)

#Initialize array and number of found topics.
found_topics = []
found_topics_len = 0

#Save number of hints used, and how many character we show for each hint
used_hints = 0
helpchars = 2

start = time.time()

#Function which print strint with the title function
def print_title(x):
    print x.title()

#Function which prints all entries in the list.
def print_all_from_list(list):
    map(lambda x: print_title(x),list)

print "To recieve a hint, please type \"hint\"."

#Loop which runs until all topics are found or user breaks it by typing "stop"
while True:
    print "Here are your currently solved words:"

    #Check how many hints are left
    if 5-used_hints &lt; 0:
        hint_text = 0
    else:
        hint_text = 5 - used_hints
    print "You have " + str(hint_text) + " hint igjen."

    #Print all found topics
    for i in found_topics:
        print "-" ,i

    #print number of found topics / all topics.
    print found_topics_len , "of" , topics_len

    #Get new input
    input = raw_input().lower()

    #check if input is one of the answers, and remove it if it is.
    if input in topics:
        for i in range(0, topics_len):
            if input == topics[i-1]:
                topics.pop(i-1)
                break

        #Increase number of found topics, and add it to the found_topics-list.
        found_topics_len += 1
        found_topics.append(input)

        #Reset the helpindex
        helpchars = 2

        #Check if all topics are found and print some information
        if found_topics_len == topics_len:
            print "\nHurray! You won the game!"
            time_used = time.time() - start
            print "You needed " + str(used_hints) + " hints and used" ,
            str('%.2f'%(time_used))  + " seconds in total.\n"
            print "Here are the answers:"
            print_all_from_list(found_topics)
            break
    #user wants a hint.
    elif input == "hint":
        if(used_hints &lt; 5):
            print "\nHint:" , topics[0][0:helpchars]
        else:
            print "Du er tom for hint!"
        helpchars += +2
        used_hints += 1

    #user wants to stop.
    elif input == "stop":
        print "You gave up. Poor you. Here's the answers:"
        print_all_from_list(answer)
        break
    else:
        #Word is not found.
        print "Word not found. Sorry"
    print "\n"</pre>


<p>Related posts:<ol><li><a href='http://josteinb.com/2009/05/simple-quiz-program-written-in-java/' rel='bookmark' title='Permanent Link: Simple quiz-program written in Java'>Simple quiz-program written in Java</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://josteinb.com/2009/05/simple-quiz-program-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple quiz-program written in Java</title>
		<link>http://josteinb.com/2009/05/simple-quiz-program-written-in-java/</link>
		<comments>http://josteinb.com/2009/05/simple-quiz-program-written-in-java/#comments</comments>
		<pubDate>Fri, 01 May 2009 11:30:07 +0000</pubDate>
		<dc:creator>Jostein</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[quiz]]></category>
		<category><![CDATA[studying]]></category>

		<guid isPermaLink="false">http://josteinb.com/?p=64</guid>
		<description><![CDATA[This is Peders version of the quiz program for studying.  it takes textfiles with the extention .pugg as input import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Pugge { public static void main(String[] args) throws IOException { Map wordLists = new HashMap(); File f = new File("."); for(String filen [...]


Related posts:<ol><li><a href='http://josteinb.com/2009/05/simple-quiz-program-in-python/' rel='bookmark' title='Permanent Link: Simple quiz-program in Python'>Simple quiz-program in Python</a></li>
<li><a href='http://josteinb.com/2009/03/prepared-statements-in-java/' rel='bookmark' title='Permanent Link: Prepared Statements in Java'>Prepared Statements in Java</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This is <a title="truben" href="http://truben.no/journal" target="_self">Peders</a> version of the quiz program for studying.  it takes textfiles with the extention .pugg as input<br />
<span id="more-64"></span></p>
<pre lang="java">
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Pugge {

	public static void main(String[] args) throws IOException {

		Map<string, Map<string,Boolean>> wordLists = new HashMap<string, Map<string,Boolean>>();

		File f = new File(".");
		for(String filen : f.getCanonicalFile().list()) {
			if(filen.endsWith(".pugg"))
				wordLists.put(filen, getWords(filen));
		}

		System.out.println("Velkommen! Hva vil du pugge?\n");
		int tell = 1;
		for(String s : wordLists.keySet()) {
			System.out.println(tell++ + ". " + s.substring(0, s.length()-5));
		}
		Scanner inn = new Scanner(System.in);

		System.out.print("\nSkriv inn valg: ");
		String tema =  (String) wordLists.keySet().toArray()[Integer.parseInt(inn.nextLine())-1];
		String temaEase =  toProperCase(tema.substring(0, tema.length()-5));

		Map<string,Boolean> ord = wordLists.get(tema);

		System.out.println("Da skal vi pugge " + temaEase + ". Vi har " + ord.size() + " ord i listen vår!\n");

		int hints = 0;
		int forsok = 0;

		long startTid = System.currentTimeMillis();

		while(true) {
			System.out.println("Ord du har klart til nå:");

			// Skriver hvilke ord du har fått til
			int klart = 0;
			for (String ordet : ord.keySet())
				if(ord.get(ordet)) {
					System.out.println(" - " + toProperCase(ordet));
					klart ++;
				}

			// Skriver ut status
			if(klart == ord.size()) {
				System.out.println("\nGrattis! Det gikk fint. \"Bare\" " + hints + " hint og " +
						forsok + " forsøk i løpet av " + (int)((System.currentTimeMillis() - startTid)/1000) +
						" sekunder.");
				break;
			}
			else
				System.out.println("\nDu har klart " + klart + " av " + ord.size() + "\n");

			// input
			System.out.print("$ ");
			String linje = inn.nextLine().toLowerCase();

			// Om det er en kommando
			if(linje.equals("/h")) {
				for (String ordet : ord.keySet()) {
					if(!ord.get(ordet)) {
						int start = (int)(Math.random()*(ordet.length()-1));
						int stopp = (int)(Math.random()*(ordet.length()-start)) + start+1;
						System.out.println(ordet.substring(start, stopp));
						hints++;
						break;
					}
				}
				continue;
			}
			else if(linje.equals("/q"))
				break;

			// Riktig eller galt
			if(ord.get(linje) != null)
				ord.put(linje, true);
			else
				System.out.println("Fant ikke den...");

			forsok++;

		}
	}
	private static String toProperCase(String inputString) {
		StringBuilder ff = new StringBuilder();

		for(String f: inputString.split(" ")) {
			if(ff.length()>0)
				ff.append(" ");

			ff.append(f.substring(0,1).toUpperCase()).append(f.substring(1,f.length()).toLowerCase());
		}

		return ff.toString();
	}

	private static HashMap<string,Boolean> getWords(String filename) throws FileNotFoundException {

		Scanner s = new Scanner(new File(filename));
		Map<string,Boolean>  ord  = new HashMap<string,Boolean>();

		// Leser inn ord. Et per linje
		while(s.hasNextLine()) {
			ord.put(s.nextLine().toLowerCase().trim(), false);
		}
		return (HashMap<string, Boolean>) ord;

	}

}
</pre>


<p>Related posts:<ol><li><a href='http://josteinb.com/2009/05/simple-quiz-program-in-python/' rel='bookmark' title='Permanent Link: Simple quiz-program in Python'>Simple quiz-program in Python</a></li>
<li><a href='http://josteinb.com/2009/03/prepared-statements-in-java/' rel='bookmark' title='Permanent Link: Prepared Statements in Java'>Prepared Statements in Java</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://josteinb.com/2009/05/simple-quiz-program-written-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
