IDEA supports C and C++?
You can use VB.Net with ASP.Net MVC, but most of the books/tutorials/examples/help you find online will be in C#.
IDEA supports C and C++?
Sub MonteCarlo()
n = Range("Number")
Hits = 0
For Index = 1 To n
If Rnd ^ 2 + Rnd ^ 2 < 1 Then Hits = Hits + 1
Next Index
Range("Estimate") = 4 * Hits / n
End Sub
I've got a VBA question if anyone can help. I wrote a program but I get an error when running it. The error says, "Run Time Error '6': Overflow"
The code for the program is :
Code:Sub MonteCarlo() n = Range("Number") Hits = 0 For Index = 1 To n If Rnd ^ 2 + Rnd ^ 2 < 1 Then Hits = Hits + 1 Next Index Range("Estimate") = 4 * Hits / n End Sub
I'm assuming it's a really easy mistake but does anyone know what it is? Is it because I didn't use dim to declare the variable? I tried that and it seemed to still have issue with the same line. The highlighted line is the line it highlights when I click debug after getting the error. Any help is appreciated.
Been a while since I've done any VBA, but what is "n" when you're debugging? Is it 0? Check your variable values. Actually, put a breakpoint at the top of your method and step through it so you can see what it's doing at every step. If n is zero, then your loop won't execute, Hits will not be populated, and you'll ultimately just not get your desired result.
No joke, I freaked out about this yesterday before we presented. I went back and changed two splash screens that had the misspelling and fixed it in the comments that described the project in the code. I rely on spellcheck way too much sometimes >_>Feud*
I just saved your A+, son.
As disappointed as I was, it really was a great project. Probably the most fun I have ever had with programming. I was really worried that our game was going to be incredibly basic compared to all the other projects but it ended up being pretty much on par with everything else. It was a lot of fun to see what everyone else came up with during their presentations too.Congrats, sounds like good experience. You can always finish it up outside of class. If the project is relevant to your career goals, you'd be able to point out to potential employers how you went above and beyond to polish it up.
Oh, good. Now go enjoy your pi.
Haha, I'd rather have pie.Is VBA pretty easy to learn I guess? Doesn't seem too bad once you get used to the reserved words.
Easy to learn. It will take a while to forget, though. Some things you just can't unsee.
public class ContactList
{
private DoublyLinkedList<Contact> cList = new DoublyLinkedList<Contact>();
int count = 0;
//Temporary variables
String nameFirst, nameLast, nameMiddle, month, cellNum, homeNum, email, addr, city, state,
bday, zip;
public ContactList(String file)
{
//Open the data file
Scanner myFileIn = null;
try
{
myFileIn= new Scanner(new File(file));
} catch (FileNotFoundException e)
{
System.out.println("File: "+ file +" is not found");
}
//Read how many lines
int numRecords = myFileIn.nextInt();
//Read the file
for (int i = 0; i < numRecords; i++)
{
nameLast = myFileIn.next();
nameFirst = myFileIn.next();
nameMiddle = myFileIn.next();
month = myFileIn.next();
bday = myFileIn.next();
cellNum = myFileIn.next();
homeNum = myFileIn.next();
email = myFileIn.next();
addr = myFileIn.next();
city = myFileIn.next();
state = myFileIn.next();
zip = myFileIn.next();
Contact contactName = new Contact(nameLast, nameFirst, nameMiddle, month, bday,
cellNum, homeNum, email, addr, city, state,zip);
insert(contactName);
}
}
public void insert(Contact c)
{
cList.resetCurrentElement();
while (cList.isEmpty())
{
cList.insertAt(c, count);
count++;
}
while(cList.hasMoreElements())
{
if (cList.nextElement().compareTo(c) > 0)
{
cList.insertAt(c, count);
}
else if (cList.nextElement().compareTo(c) < 0)
{
count++;
cList.insertAt(c, count);
}
}
}
public int compareTo(Contact other)
{
String fullName = getFirstName() + getLastName();
String otherName = other.getFirstName() + other.getLastName();
return fullName.compareTo(otherName);
}
So the program works, and you're left with a DoublyLinkedList<Contact> that needs to be sorted? In that case, the code in DoublyLinkedList is the only one that matters.
The problem is, it only takes the first contact and thats ,idk how to compare the firstNode and the next and then add them in the proper order.
The problem is, it only takes the first contact and thats ,idk how to compare the firstNode and the next and then add them in the proper order.
Is the DoublyList your own code? Does it bug out and only take one element? How does the list look inside, is it [element <-> element <-> element <-> ...], "<->" representing a link in both directions?
Depends on your assignment, but typically you would not do it that way. You would just add all your elements into the list then when you are done, call a "sort" method.
With this method just have your value object implement the Comparable interface and then anything that gets added to the list can be sorted generically using the same method and compareTo.
sorted = true
do {
check every element n and compare it to (n + 1) // Special case for the last item, nothing to compare it with.
if (n + 1) < n, switch places. sorted = false
} while !sorted
Just do a simple bubble sort then when the list is filled:
Code:sorted = true do { check every element n and compare it to (n + 1) // Special case for the last item, nothing to compare it with. if (n + 1) < n, switch places. sorted = false } while !sorted
This will repeat until the algorithm manages to go through the entire list without switching items, whereby sorted will remain true and the loop will end. Done.
c = insertion contact
Step through every element n and compare it to c until c < n
Insert c at n's place // I'm assuming the list is implemented to push n forward one position
If you reach the end of the list, insert c at the end (aka the beginning if the list is empty)
Upon insertion:
Code:c = insertion contact Step through every element n and compare it to c until c < n Insert c at n's place // I'm assuming the list is implemented to push n forward one position If you reach the end of the list, insert c at the end (aka the beginning if the list is empty)
public void insert(Contact c)
{
cList.resetCurrentElement();
if (cList.isEmpty())
{
cList.insertAt(c, count);
}
else
while (cList.hasMoreElements())
{
if (cList.nextElement().compareTo(c) == -1)
{
cList.insertAt(c, count + 1);
count++;
}
else if (cList.nextElement().compareTo(c) == 1)
{
cList.insertAt(c, count);
count++;
}
else
{
cList.insertAt(c, count);
count++;
}
}
}
Codejam within an hour and a half. Anyone competing in Round A?
Eclipse keeps stalling on me, gonna restart my computer but does something like this look right?
Edited code, it was infitely looping
Code:public void insert(Contact c) { cList.resetCurrentElement(); if (cList.isEmpty()) { cList.insertAt(c, count); } else while (cList.hasMoreElements()) { if (cList.nextElement().compareTo(c) == -1) { cList.insertAt(c, count + 1); count++; } else if (cList.nextElement().compareTo(c) == 1) { cList.insertAt(c, count); count++; } else { cList.insertAt(c, count); count++; } } }
if (cList.nextElement().compareTo(c) == -1)
3am for me and I've had a few drinks, but why the hell not![]()
shouldn't be there. Let's say you're inserting "5" into a list [1,2,3,4,6,7,8]. Your first compairson will be to compare 1 (cList.nextElement) with 5 (c). 1 < 5, so compareTo will return -1 and 5 will be inserted between 1 and 2.Code:if (cList.nextElement().compareTo(c) == -1)
Only check for the first instance of an element that is higher than the one you're inserting (in this case 6), then insert before that element. Assuming every element has been inserted that way, the list remains sorted.
I dont know how to tell which string is bigger than the other.
Surely there's some sort of 'length' or 'size' method?
I should clarify, not bigger in the sense of size but what comes first alphabetically. I need to compare the concatenation of a last name and first name of two objects. so if ones name starts with "a" and the other "b", the first in the list will be the one with the "a". so for however many I have, the have to be sorted as I build the objects in a doublylinkedlist. so if the first one starts with "v" and the second starts with "a". "a" has to go first, then "v" second. Then the next object has to be sorted between those 2 and so on. My professor did not show us how to do, only adding already sorted objects into a doublylinkedlist.
I remember doing this in java but I forget what we did exactly. I think we turned the letters to numbers and then had it loop and move it up the list if the number was smaller than the number it was comparing to. I can't remember exactly though.
Edit: I think it was compare to that will return an integer and you can then use that to move it? What language are you using? CompareTo doesn't work?
Edit 2: Or compare with charAt?
Java yeah. Have to use CompareTo. I'm just having trouble doing this all dynamically. The constructor reads each contact, and as it reads each one (its in a for loop so I can all the contacts) it has to be sorted after each one. so the first contact has to be sorted, then the second has to be sorted with the first. Then the third has to be sorted between the first and second one, and so on. This all has to be sorted in a doublylinkedlist, which my professor did not describe very well. I can do it fine if the list is already full but we have to do it as it reads each contact.
Yeah its really annoying since there is new shit we have to move onto and theres no time to explain the stuff. Our school decided it would be better to cut 12 hours out of each class for the smemester so they can add more classes without changing cirriculum. so basically 1/3 of the cirriculum is dumped on everyone with 3 weeks left.Ok, I don't think I ever did doubly linked lists so that might be what's throwing me off.
...
for( $count = 0; $count < $numRules; $count++){
while( strpos( $string, $find[$count]) !== false){
$string = str_replace($find[$count], $replace[$count],$string);
}
}
print $string
I should clarify, not bigger in the sense of size but what comes first alphabetically. I need to compare the concatenation of a last name and first name of two objects. so if ones name starts with "a" and the other "b", the first in the list will be the one with the "a". so for however many I have, the have to be sorted as I build the objects in a doublylinkedlist. so if the first one starts with "v" and the second starts with "a". "a" has to go first, then "v" second. Then the next object has to be sorted between those 2 and so on. My professor did not show us how to do, only adding already sorted objects into a doublylinkedlist.
Fuck Prolog.
Hard.
Need ya guys again!
Basically im reading a txt file and making each contact and adding them into the contact list but I have no idea how to properly sort the by name in a doublylinked list.
This is where I am trying to add each contact sorted by name. The teacher gives really bad examples on how to sort and them add them to the doubly linked list. There is some uncompleted code but I cant figure out how to sort then add them.
Collections.sort(listToBeSorted, new StringAlphabeticalComparator());
Not sure I entirely understood what you said, but here's what I got from it.Code:... for( $count = 0; $count < $numRules; $count++){ while( strpos( $string, $find[$count]) !== false){ $string = str_replace($find[$count], $replace[$count],$string); } } print $string
//Eg word pairs: "foo bar", "abc xyz"
// Sub arrays for the words to replace and the replacements
$myAry = array(array(), array());
//Splits the string, put the first word in the first array and the second to the second array.
//(stuff)
//Two arrays that contain the words to be replaced and their replacements.
// $myAry[0] has array('foo', 'abc');
// $myAry[1] has array('bar', 'xyz');
//Then
str_replace($myAry[0], $myAry[1], $paragraph);
No joke, I freaked out about this yesterday before we presented. I went back and changed two splash screens that had the misspelling and fixed it in the comments that described the project in the code. I rely on spellcheck way too much sometimes >_>
As disappointed as I was, it really was a great project. Probably the most fun I have ever had with programming. I was really worried that our game was going to be incredibly basic compared to all the other projects but it ended up being pretty much on par with everything else. It was a lot of fun to see what everyone else came up with during their presentations too.
My major is in Computer Science and my school does offer a game design track but I opted for a more general track called Computer Science Foundations. I'm interested in game design, but I'd have to go back and take two physics courses to get into the classes, and I have already filled my natural science requirements for my degree so going back to take those would just be extra money spent on top.
@pompidu
The way you do sorting in Java is you run Collections.sort() over a Collection (which LinkedList<T> is, and therefore DoublyLinkedList<T> as well). Collections.sort takes two arguments, first the list to be sorted and second a Comparator<Object> (where Object is replaced with the type you want to compare, I guess String?). You will need to implement your own Comparator. So how is that done?
Well, you'll need to make a new class implementing the interface Comparable. Doing so requires you to implement the method compareTo(Object o1, Object o2) (again, replacing Object in both cases with String), which Collections.sort() will use to do the sorting.
compareTo() has the following specification:
- If o1 is "larger" (this can mean anything depending in what you're trying to achieve), then return 1
- If o2 is "larger" than o1, return -1
- If they're "the same" (which in this case means they're the same word), return 0.
When you've completed the Comparator class, you just go:
Code:Collections.sort(listToBeSorted, new StringAlphabeticalComparator());
Collections.sort() doesn't return anything, it modifies the list passed as an argument directly. So that's how you use compareTo, if you need help with the actual comparing then just ask (if you've asked about that above I apologize, didn't have time to read it all).
So since you'll have to do the sorting dynamically, you just run sort every time you add a new element to the list.
I'm so glad my semester is over =D. I kinda liked prolog though. The only thing that bothered me was infinite loop on failure sometimes
prolog: "what if I..."?
NO PROLOG, IT'S NOT GOING TO WORK.
I envy you![]()
I didn't like Prolog that much too. Luckily halfway during the course we switched to Scheme which was much more fun. Plus it was the prof's first time teaching so he generally went easy on us.Fuck Prolog.
Hard.
public void insert(Contact c)
{
int count = 0;
cList.resetCurrentElement();
while (cList.hasMoreElements())
{
if (cList.nextElement().compareTo(c) > 0)
{
cList.insertAt(c, count);
}
else
{
count++;
}
}
System.out.println(cList);
}