• Login
  • Register
  • Dolphin Forums
  • Home
  • FAQ
  • Download
  • Wiki
  • Code


Dolphin, the GameCube and Wii emulator - Forums › Offtopic › Delfino Plaza v
« Previous 1 2 3 4 5 6 ... 64 Next »

Programming Discussion Thread
View New Posts | View Today's Posts

Pages (67): « Previous 1 ... 6 7 8 9 10 ... 67 Next »
Jump to page 
Thread Rating:
  • 4 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Modes
Programming Discussion Thread
11-12-2012, 11:31 AM (This post was last modified: 11-12-2012, 11:39 AM by Shonumi.)
#71
Shonumi Offline
Linux User/Tester
**********
Administrators
Posts: 6,513
Threads: 55
Joined: Dec 2011
Have a look at this mostly psuedo-code. Similar to what NV suggested, but you don't check each character 52 times :p Look up the documentation to hash maps and look at some examples if you're still confused. This one is pretty cut and dry.

Code:
Mapz = new HashMap();


For loop to iterate over ever character you want to check - Grab one at a time (let's call it Character)

    If Character is a letter (use isLetter()) AND Character already exists in the HashMap (use containsKey()) - Then
        Some Integer = Mapz(Character); //Grab current value from hashmap
        Some Integer++;
        Mapz.put(Character, Some Integer); //Replace old value from hashmap with updated value

    Else If Character is a letter AND Character does NOT already exist in Hashmap - Then
        Mapz.put(Character, new Integer(1)); //Add new entry into hashmap, value of 1 since it's first time we encountered the letter

End For loop

Write HashMap to CSV file

Note, this will include upper and lower cases. If you wanted just characters in general, just convert all the characters to one case e.g. using toLower() or toUpper() before checking the values in the hashmap.

EDIT: Got ninja'd while posting. Basically it's like shuffle said, but it's got a bit of Java for you. Haven't programmed in that language for years, but you'll get the idea.
Website Find
Reply
11-12-2012, 11:44 AM
#72
AnyOldName3 Offline
First Random post over 9000
*******
Posts: 3,533
Threads: 1
Joined: Feb 2012
That's not ideal for me to do, as the text may have lowercase characters which I need to skip (It's to help me decrypt ceaser shift and affine shift text, and the convention is that plaintext is in lowercase. There may be a situation where I lose my frequency table having already solved several letters, so won't want frequencies of these letters, as this could get confusing.)
OS: Windows 10 64 bit Professional
CPU: AMD Ryzen 5900X
RAM: 16GB
GPU: Radeon Vega 56
Find
Reply
11-12-2012, 12:03 PM
#73
Shonumi Offline
Linux User/Tester
**********
Administrators
Posts: 6,513
Threads: 55
Joined: Dec 2011
(11-12-2012, 11:44 AM)AnyOldName3 Wrote: That's not ideal for me to do, as the text may have lowercase characters which I need to skip (It's to help me decrypt ceaser shift and affine shift text, and the convention is that plaintext is in lowercase. There may be a situation where I lose my frequency table having already solved several letters, so won't want frequencies of these letters, as this could get confusing.)

So you want to skip lowercases altogether? Just change the two conditional statements:

Code:
If Character is a letter (use isLetter()) AND Character already exists in the HashMap (use containsKey()) AND the character is Uppercase (use isUpper()) - Then
        ...
        ...

    Else If Character is a letter AND Character does NOT already exist in Hashmap AND the character is Uppercase (use isUpper()) - Then
        ...
        ...

Or do you mean you need to skip specific lower case characters? For that, just check that the characters aren't the ones you don't want. The conditional statement could get quite long, nothing wrong with that though (unless it's a ridiculous amount...)

Code:
If Character is a letter (use isLetter()) AND Character already exists in the HashMap (use containsKey()) AND the character is not blacklisted (e.g. != "a" or != "b")
        ...
        ...

    Else If Character is a letter AND Character does NOT already exist in Hashmap AND the character is Uppercase (use isUpper()) AND the character is not blacklisted (e.g. != "a" or != "b") - Then
        ...
        ...

You mentioned having trouble grabbing just one character from a string to do comparisons, right? Use the charAt() function:

Code:
String many_letterz = "words are words";

if(many_letterz.charAt(0) == "w") { System.out.println("Yeah, 1st character is w"); }
else { System.out.println("Nope, not w"); }
Website Find
Reply
11-12-2012, 12:05 PM
#74
AnyOldName3 Offline
First Random post over 9000
*******
Posts: 3,533
Threads: 1
Joined: Feb 2012
That'll probably be enough for me to get something working, thanks. I'll try and write it tomorrow.
OS: Windows 10 64 bit Professional
CPU: AMD Ryzen 5900X
RAM: 16GB
GPU: Radeon Vega 56
Find
Reply
11-12-2012, 12:19 PM (This post was last modified: 11-12-2012, 12:32 PM by shuffle2.)
#75
shuffle2 Offline
godisgovernment
*
Project Owner  Developers (Administrators)
Posts: 698
Threads: 17
Joined: Mar 2009
http://stackoverflow.com/questions/4363665/hashmap-implementation-to-count-the-occurences-of-each-character

I came up with this: http://ideone.com/edaq3X
(Note that I haven't used Java for a long time, and I hate it's guts...this exercise reminded me just how much it sucks)
Code:
import java.util.*;
import java.lang.*;

class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Map hitcounts = new HashMap();
        String uppercase_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        
        for (char uppercase_char : uppercase_alphabet.toCharArray())
        {
            hitcounts.put(uppercase_char, 0);
        }
        
        String input_string = "Make This WhatEveR input You Want";
        
        for (char character : input_string.toCharArray())
        {
            if (hitcounts.containsKey(character))
            {
                hitcounts.put(character, (int)hitcounts.get(character) + 1);
            }
        }
        
        System.out.println(hitcounts);
    }
}

You don't need to initialize a hashmap, but in this case it doesn't really matter.

Edit: Here is a version that doesn't initialize the hashmap: http://ideone.com/k88VPa
Code:
import java.util.*;
import java.lang.*;

class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Map hitcounts = new HashMap();
        String input_string = "Make This WhatEveR input You Want";
        
        for (char character : input_string.toCharArray())
        {
            if (Character.isUpperCase(character))
            {
                int hitcount = 0;
                if (hitcounts.containsKey(character))
                {
                    hitcount = (int)hitcounts.get(character);
                }
                
                hitcounts.put(character, hitcount + 1);
            }
        }
        
        System.out.println(hitcounts);
    }
}

Note that this time the hashmap will not contain keys with a value of 0. You would need to account for this when accessing the hashmap, or insert the keys explicitly.
Find
Reply
11-15-2012, 04:35 AM (This post was last modified: 11-15-2012, 04:37 AM by AnyOldName3.)
#76
AnyOldName3 Offline
First Random post over 9000
*******
Posts: 3,533
Threads: 1
Joined: Feb 2012
Two things:

a) Now I've made the code into a single method in a larger program, I don't know where to put the
Code:
java.lang.Exception
.

b) I can't work out exactly how to use .get() to make the value of a string (yes it must me a string, at least eventually) the value of a data item under a specific key. Basically, it won't compile when I use:

Code:
    public void formatFrequencies()
    {
        //Formats the data in the HashMap into a .csv file Excell can open.
        frequencyTable = frequencyTable+newLine;
        String currentFrequency = "0";
                for(char currentLetter : alphabet.toCharArray())
        {
            currentFrequency = frequencyMap.get(currentLetter);
            system.out.println(currentFrequency);
        }
    }


This code isn't quite complete yet, but I don't want to add more until I can get this bit working.
OS: Windows 10 64 bit Professional
CPU: AMD Ryzen 5900X
RAM: 16GB
GPU: Radeon Vega 56
Find
Reply
11-15-2012, 09:40 AM (This post was last modified: 11-15-2012, 09:41 AM by AnyOldName3.)
#77
AnyOldName3 Offline
First Random post over 9000
*******
Posts: 3,533
Threads: 1
Joined: Feb 2012
I've changed system to System, and got rid of an error from that. Now Javac only lists one error.

Added a ""+ and got rid of the error. Let's see if it runs.
OS: Windows 10 64 bit Professional
CPU: AMD Ryzen 5900X
RAM: 16GB
GPU: Radeon Vega 56
Find
Reply
11-15-2012, 10:11 AM
#78
AnyOldName3 Offline
First Random post over 9000
*******
Posts: 3,533
Threads: 1
Joined: Feb 2012
i THINK IT MAY BE FINISHED!!!
OS: Windows 10 64 bit Professional
CPU: AMD Ryzen 5900X
RAM: 16GB
GPU: Radeon Vega 56
Find
Reply
11-15-2012, 11:57 AM
#79
ExtremeDude2 Online
Gotta post fast
*******
Posts: 9,318
Threads: 273
Joined: Dec 2010
I sense caps lock :3
Check out my videos (dead)
[Image: sig-22354.png]
Website Find
Reply
11-16-2012, 01:18 AM
#80
Zee530 Offline
Above and Beyond
*******
Posts: 1,747
Threads: 12
Joined: Jan 2011
Whats the best language to use if i have a set of data that i need to be entered into a program and saved to a database?
......?????
Find
Reply
« Next Oldest | Next Newest »
Pages (67): « Previous 1 ... 6 7 8 9 10 ... 67 Next »
Jump to page 


  • View a Printable Version
  • Subscribe to this thread
Forum Jump:


Users browsing this thread: 2 Guest(s)



Powered By MyBB | Theme by Fragma

Linear Mode
Threaded Mode