Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Alcool Tue
Nov 6, 2009

by Ozma

covener posted:

not so sure what you're expecting, but here's 3 things to play with

code:
gnome-terminal -e 'bash -c "cd /***"'
gnome-terminal -e 'bash -c "/your/script.sh"'
(cd /*** &&  gnome-terminal -e 'bash')

Just trying to save myself the trouble of navigating to my USB drive every time I want to test some python.

(cd /*** && gnome-terminal) did it just fine, thanks buddy.

Adbot
ADBOT LOVES YOU

FamDav
Mar 29, 2008
Have a (probably amateur) question about C++:

When I run the code below with test input:

input posted:

123456
123321

I get output:

output posted:

!123456!
!654321!
Not a Palindrome
!123321!
!123321!
Not a Palindrome

I of course am of the opinion that the first is not a palindrome while the second is. Any reason why this isn't working?

code:
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

int main() {
	
	stringstream ss;
	string input, revput, mirput;
	int size;
	bool even;
	bool pal;
	bool mir;
	string x, y;
	int z;
	
	input.clear();
	while (cin >> input) {
		size = input.size();
		if (size % 2 == 0) even = true;
		if (size % 2 != 0) even = false;
		
		
		revput.resize(input.size(),0);
		mirput.resize(input.size(),0);
		if (even) {
			for (int i = 0; i <= input.size(); ++i) {
				x.push_back(input[i]);
				z = input.size() - i;
				revput.replace(z,1,x);
				x.clear();
			}
			
			
			cout << "!" << input << "!" << "\n" << "!" << revput << "!" <<  "\n";
			if (input.compare(revput) == 0) {
				cout << "Is a Palindrome";
			}
			else {
				cout << "Not a Palindrome";
			}
			
			cout << "\n";
		}
	}
}

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

FamDav posted:

I of course am of the opinion that the first is not a palindrome while the second is. Any reason why this isn't working?

The strings compare different, so they're different. They do print the same, however, which implies that they differ only in some unprintable character, which is very likely to be '\0'. The code does not modify input except using library routines, so the difference must be that revput has extra characters in it. How many characters are you adding to it?

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

FamDav posted:

I of course am of the opinion that the first is not a palindrome while the second is. Any reason why this isn't working?
Are you sure you're loop an appropriate number of times?

Here's some output from gdb...maybe this will help you get off on the right foot

Dijkstracula fucked around with this message at 07:42 on Jan 7, 2010

FamDav
Mar 29, 2008
Ah, thanks to both of you I figured out that I was create a string with an extra undefined space at the beginning. Once I fixed that, everything flowed.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
Is there a generic name for a system that... Has a model or computes some sort of ideal number/goal... And then as you add/subtract certain constraints, the system adapts and continues to advise or warn you that your constraints make the desired projection improbable...

Expert systems?

Merrack
Sep 15, 2007
Prolog? :v:

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Triple Tech posted:

Is there a generic name for a system that... Has a model or computes some sort of ideal number/goal... And then as you add/subtract certain constraints, the system adapts and continues to advise or warn you that your constraints make the desired projection improbable...

Expert systems?

"Computing some sort of ideal number/goal" sounds like you mean optimization; linear programming is a common subfield.

Finding solutions given a guess (the previous solution) which you believe to be "nearby" the correct solution in some space is "local search".

You may also want to look into constraint satisfaction and satisfiability, and general NP-complete solver techniques.

But your question is so incredibly vague that it's hard to give you any better pointers than that.

RussianManiac
Dec 27, 2005

by Ozmaugh
Does anybody know how to exclude anything STL related from doxygen's collaboration diagrams output?

I tried adding std and std::vector to exclude symbols but its not working :(

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
This could apply to any number of spaces like Warcraft specs or poker or more specifically stock portfolios... So if I have a model for the ideal balanced portfolio given no constraints, the system is like fine, do this. But what if we add some parameters like I am unwilling to target large losses, but I want huge returns, and I want to include this in my portfolio because someone gave me a hot tip. So then the computer will go beep bop and spit something else out. Or, it will tell you something like asking for a low-risk high-yield simulation is like 3% likely to happen.

A recommendation engine?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
Economic simulations and other decisions-made-over-time-with-incomplete-information fields are typically built using techniques from game theory and control theory. It's a well-studied area, but I think what you're asking for is beyond the current state of the art.

Poker is shockingly hard to model in the real world, especially when you admit the possibility of player collusion. It uses game theory, but doesn't share as much as you'd think with economic modeling.

Modeling item specs in Warcraft would seem to be a straightforward optimization problem; not really the same problem domain at all.

If you want software that can do all of that, you probably want Hard AI.

haveblue
Aug 15, 2005



Toilet Rascal

ShoulderDaemon posted:

Modeling item specs in Warcraft would seem to be a straightforward optimization problem; not really the same problem domain at all.

If you want software that can do all of that, you probably want Hard AI.

Or you could try the Google approach and mine a gigantic number of decisions made by humans based on varying values of your parameter set for patterns and trends, but that's not really feasible for one man and especially one man in his spare time.

tef
May 30, 2004

-> some l-system crap ->
After reading this http://www.venge.net/graydon/talks/mkc/html/mgp00001.html presentation, I'm tempted to try ocaml again.

Does anyone have any recommendations for books or tutorials?

Edit: it seems like this book an introduction to objective caml might be a good start, as well as http://www.ocaml-tutorial.org/

I'm still open to a nice book I can leaf through.

tef fucked around with this message at 15:48 on Jan 11, 2010

Richard M Nixon
Apr 26, 2009

"The greatest honor history can bestow is the title of peacemaker."
Apologies if this is too specific to go here, but this seems like a good place.

I am trying to make a script that will download my school's course availability page and notify me if a class I want has a spot open up. The problem for me is getting the page onto my computer in the first place. There is a javascript function that occours when I click on a course that brings me to the page that shows open seats, but I cannot simply download that page, as it will not have any variables passed to it. There is a form that I can submit where when I enter in the course's unique ID, I will be returned with a page that I want to download and parse with a bash script. That page is: http://catsweb.txstate.edu/app/inq-open-classes

Inspecting the page, I find the basic HTML form code
code:
http://catsweb.txstate.edu/app/inq-open-classes
And the specific input box's code
code:
<input type="text" onfocus="select()" maxlength="6" value="" size="6" name="iqocs_csnid"/>
I can modify the input box to have its value permanently set to the course's ID (361834), but I am still at a loss as to how I can submit the page and then download the returned page automatically, every 5 minutes.

I am really unsure how to phrase the question, so I apologize if I have been unclear, but I am just looking for a way to either automatically click the submit button on the modified form, or some cool wget hack I don't know of to pass form variables.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Richard M Nixon posted:

post form and scrape

I did something similar using Python and a library called BeautifulSoup. I understand there might be more effective libraries now, but here's what I did.

code:
import datetime, urllib, urllib2
from BeautifulSoup import BeautifulSoup

# url is the action attribute of the <form>
url = http://catsweb.txstate.edu/app/inq-open-classes
# for the dict below, the keys are the name attributes of the <input> tags
postdata = urllib.urlencode({'iqocs_csnid': 361834})
soup = BeautifulSoup(urllib2.urlopen(url, postdata))
Now, assuming there's one table on the result page, and each row is an offering of the course (with two columns for the instructor and number of open seats):

code:
for row in soup.table.findAll('tr'):
    instructor, seats = row.findAll('td', recursive=False)[:2]
    print "As of %s, there are %d seats open in %s's offering." \
          % datetime.datetime.now(), seats, instructor
The BeautifulSoup documentation and the above should give you a good start. If you do go with Python and have further questions, check out the Python megathread here in CoC.

Richard M Nixon
Apr 26, 2009

"The greatest honor history can bestow is the title of peacemaker."

pokeyman posted:

Making soup with codes

That looks incredibly useful, I can't believe there is a toolset for doing just this. I'll check it out. Thanks, goon!

Edit: gently caress me, your avatar is creepy.

causticfluids
Dec 25, 2006

Congratulations on not getting fit in 2011!
I am attempting to implement a linked list. I've tried to write a recursive version, because recursion rules. I think the print_list method works, so I'm guessing I am adding a node to my list incorrectly. The code should just add a node to an empty list and accept an input value (an int), then print that value. (ie printing the node.) Complete code:

code:
#include <stdio.h>
#include <iostream.h>

struct node {
  int value;
  node * nxt;
};

int add_tail(node * current_node);
int print_list(node * current_node);

int main()
{
  node * start = NULL;

  add_tail(start);
  print_list(start);
  //delete_list would go here, etc...
  
  return 0;
}

int add_tail(node * current_node)
{

  if( current_node == NULL )
  {
    node * temp = new node; 
    cin >> temp->value;
    temp->nxt = NULL;
    current_node = temp;
    delete temp;
  }
  else
  {
    add_tail(current_node->nxt);
  }

  return 0;
}

int print_list(node * current_node)
{
  if(current_node == NULL)
  { 
    cout << "End of List\n"; 
  }
  else
  {
    cout << "\n" << current_node->value;
    print_list(current_node->nxt);
  }

  return 0;
}

causticfluids fucked around with this message at 06:39 on Jan 12, 2010

awesmoe
Nov 30, 2005

Pillbug

causticfluids posted:

Code

Think about how assignment works when you're dealing with pointers, and what new and delete (especially delete) do with the arguments they're given. Giving specific fixes is pointless but this will get you in the right direction hopefully. Good luck :)

causticfluids
Dec 25, 2006

Congratulations on not getting fit in 2011!
Whoas! Major typo with the delete start. I'll nix the whole thing. I think what my problem is, is that I can't delete temp in add_tail because it removes the object in memory and not just the pointer.

Edit: Solved. I see! I didn't even think about the fact that I would need the memory address of the original pointer! Geez.
code:
int add_tail(node ** current_node)
{

  if( (*current_node) == NULL )
  {
    node * temp = new node; 
    cin >> temp->value;
    temp->nxt = NULL;
    (*current_node) = temp;
  }
  else
  {
    add_tail( &((*current_node)->nxt) );
  }

  return 0;
}

int print_list(node * current_node)
{
  if(current_node == NULL)
  { 
    cout << "\nEnd of List\n"; 
  }
  else
  {
    cout << "\n" << current_node->value;
    print_list(current_node->nxt);
  }
  
  return 0;
}
The above works fine. Though I know there has to be a way to write &((*current_node)->nxt) more nicely, but I'm too tired to think of it. Maybe. Thank you for the help.

causticfluids fucked around with this message at 07:00 on Jan 12, 2010

awesmoe
Nov 30, 2005

Pillbug

causticfluids posted:

Whoas! Major typo with the delete start. I'll nix the whole thing. I think what my problem is, is that I can't delete temp in add_tail because it removes the object in memory and not just the pointer.
Yup, that's right. When debugging stuff like this I find printing the values of the pointers (ie, the address they point to rather than the contents of what they point at) makes it clear what's going on.

Zombywuf
Mar 29, 2008

Richard M Nixon posted:

That looks incredibly useful, I can't believe there is a toolset for doing just this. I'll check it out. Thanks, goon!

Edit: gently caress me, your avatar is creepy.

lxml is better at parsing tag soup HTML (yes I know it sounds like it shouldn't). It also lets you run xpaths with regexes, such as tr[rx:match(., 'foo.*bar').

tef
May 30, 2004

-> some l-system crap ->

Zombywuf posted:

lxml is better at parsing tag soup HTML (yes I know it sounds like it shouldn't). It also lets you run xpaths with regexes, such as tr[rx:match(., 'foo.*bar').


If it's just for personal fun, beautiful soup suffices, but you can get better results with lxml in terms of speed and output. Also, pycurl is scarily better than urllib2. BeautifulSoup can be a bit clunky to use sometimes, and slow.

However, if you're used to some css selectors, there is an lxml wrapper called pyquery: http://pyquery.org/

Zombywuf
Mar 29, 2008

tef posted:

BeautifulSoup can be a bit clunky to use sometimes, and slow.

And doesn't always parse as you'd expect.

BizzyLimpkits
May 20, 2001

Who's that coming down the track...
This one has been annoying me for the last couple hours. I'm sure there is a simple answer, but I am just not seeing it.

code:
__int64 foo = 8; // nice simple example
int i;

for(i = 0; i < 64; i++){
    // add a space every 8 bits
    if((i > 0) && (i % 8 ==0)){
        printf(" "); 
    }
    if((foo & (1 << i)) > 0){
        printf("1");
    }else{
        printf("0");
    }
}
printf("\n");
I would expect for this to output
code:
00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
but instead it produces
code:
00010000 00000000 00000000 00000000 00010000 00000000 00000000 00000000
This is on a x64 machine using visual studio to compile.

Any ideas? Something blindly obvious I'm missing?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

BizzyLimpkits posted:

Any ideas? Something blindly obvious I'm missing?

What is sizeof(1 << i)? (When you can answer this, you have achieved enlightment.)

BizzyLimpkits
May 20, 2001

Who's that coming down the track...
:suicide:

God I hate/love coding.

DoctorTristan
Mar 11, 2006

I would look up into your lifeless eyes and wave, like this. Can you and your associates arrange that for me, Mr. Morden?
Silly complexity question, is the worst-case cost of merging n sorted lists (each of size O(1) ) into a single sorted list O(n log n)?

Obviously this can be done in O(n log n) time by running your favourite O(n log n) sorting algorithm, but I wanted to double-check that I wasn't being stupid and overlooking some better way.

DoctorTristan fucked around with this message at 20:55 on Jan 13, 2010

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Suppose we're merging N sorted lists of size K. Concatenating them and then re-sorting takes time O(NK log(NK)). Recursively pairwise merging takes T(N,K) = N/2*2K + T(N/2,2K), which is O(NK log(N)).

There's an obvious limitative result here. Singleton lists are trivially sorted, so if you could merge N sorted lists of size O(1) in time faster than O(N log(N)), you could sort anything faster than O(N log(N)).

rjmccall fucked around with this message at 21:34 on Jan 13, 2010

DoctorTristan
Mar 11, 2006

I would look up into your lifeless eyes and wave, like this. Can you and your associates arrange that for me, Mr. Morden?
Once you lay it out like that it's obvious. Thanks.

Jo
Jan 24, 2005

:allears:
Soiled Meat
I'm looking for an algorithm or the formal name of this problem. I've tried googleing for permutations of 'point cloud similarity'. Given n sets, each with any number of points and a starting set m, select the set which is 'closest' to m.

This is as much a computer vision thing as a computational geometry one. I'm not sure it's a problem that has been solved, as it's drat close to shape similarity, but pointers would be appreciated.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Jo posted:

I'm looking for an algorithm or the formal name of this problem. I've tried googleing for permutations of 'point cloud similarity'. Given n sets, each with any number of points and a starting set m, select the set which is 'closest' to m.

This is as much a computer vision thing as a computational geometry one. I'm not sure it's a problem that has been solved, as it's drat close to shape similarity, but pointers would be appreciated.

You just calculate your "closeness-error" function for each set, and select the minimum? It's O(n*f) where f is the complexity of your error function.

Or are you trying to decide which error function to use?

Jo
Jan 24, 2005

:allears:
Soiled Meat

ShoulderDaemon posted:

You just calculate your "closeness-error" function for each set, and select the minimum? It's O(n*f) where f is the complexity of your error function.

Or are you trying to decide which error function to use?

If I have three sets of points as described below:
pre:
(a)        (b)        (c)
o  o  o     o o  o    o o o
                      o o o
o  o  o    o   o o    o o o
                  
o  o  o     o o o
I would argue (a) more closely resembles (c) than it does (b), even though the error (as determined by Euclidean distance) is bigger for (c) than for (b).

I'm looking for a metric for determining closeness like this, or (more likely) the formal name for the problem.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Jo posted:

I'm looking for a metric for determining closeness like this, or (more likely) the formal name for the problem.

If you just want scale-invariant error, then you can do something like calculate for each point in a set the distance to each other point in that set, but store those distances divided by the average distance. Compare sets by sum-of-error comparison on the sets of normalized distances. That gives you decent scale-invariance and rotation-invariance. It's expensive though; O(n^2) to classify a single n-feature set.

In image recognition, you'd have distinguished features that you can attempt to pair up in a comparison; with two distinguished pairs, you can trivially arrive at a transformation to apply to one of the sets so that you get a "best possible" comparison between those two sets. If you can't agree on the distinguished pairs, you'd probably use some heuristic to sort likely distinguished pairs, then try several candidate comparisons and choose the best, but that again moves you to the very-expensive domain.

Finally, you can do some trivial scaling correction by just taking the convex hull of each set and prescaling so their areas and centers are all the same; that won't give you any rotation invariance at all, but it will give you reasonably cheap scaling if it's easy for you to get hulls.

But really, the question of what makes two sets "similar" is highly application-specific and something you need to answer yourself. It sounds like you haven't formalized for yourself what makes two sets more or less similar very well, and that's why you're having problems. You probably won't find a lot of well-known error functions that aren't trivial, because most recognition algorithms each have their own highly-specific idea of similarity that isn't very portable; users are expected to choose the recognition algorithm that best recognizes their particular features.

If you have an informal idea of similarity but you don't have a good formal model, you might be able to get away with local search, GA, or neural network error functions so that you can train a recognizer that provides the error scores you want. But that's going to be a lot of work and you're likely to wind up with a somewhat glitchy error function.

tef
May 30, 2004

-> some l-system crap ->
A possible metric (but it's late so take a with a pinch of salt):

If you have a number of transformations/deformations ranging from general (zooming, rotations, affine transformations) affecting all points, and more individual actions (moving a specific point). Each with an appropriate cost (e.g. cost being inversely proportional to the amount point affected), you could use a* search or similar to work towards the smallest set of transformations between two point sets.


edit: what he said.

Jo
Jan 24, 2005

:allears:
Soiled Meat

ShoulderDaemon posted:

If you just want scale-invariant error, then you can do something like calculate for each point in a set the distance to each other point in that set, but store those distances divided by the average distance. Compare sets by sum-of-error comparison on the sets of normalized distances. That gives you decent scale-invariance and rotation-invariance. It's expensive though; O(n^2) to classify a single n-feature set.

In image recognition, you'd have distinguished features that you can attempt to pair up in a comparison; with two distinguished pairs, you can trivially arrive at a transformation to apply to one of the sets so that you get a "best possible" comparison between those two sets. If you can't agree on the distinguished pairs, you'd probably use some heuristic to sort likely distinguished pairs, then try several candidate comparisons and choose the best, but that again moves you to the very-expensive domain.

Finally, you can do some trivial scaling correction by just taking the convex hull of each set and prescaling so their areas and centers are all the same; that won't give you any rotation invariance at all, but it will give you reasonably cheap scaling if it's easy for you to get hulls.

Yes! Excellent idea. This is a good starting point.

ShoulderDaemon posted:

But really, the question of what makes two sets "similar" is highly application-specific and something you need to answer yourself. It sounds like you haven't formalized for yourself what makes two sets more or less similar very well, and that's why you're having problems. You probably won't find a lot of well-known error functions that aren't trivial, because most recognition algorithms each have their own highly-specific idea of similarity that isn't very portable; users are expected to choose the recognition algorithm that best recognizes their particular features.

I'm not sure that similarity can be formalized in the larger sense. If anything, the point-level comparison is a simplification of contour correlation. I'll try these and file a trip report. Thanks for the input.

tef posted:

A possible metric (but it's late so take a with a pinch of salt):

If you have a number of transformations/deformations ranging from general (zooming, rotations, affine transformations) affecting all points, and more individual actions (moving a specific point). Each with an appropriate cost (e.g. cost being inversely proportional to the amount point affected), you could use a* search or similar to work towards the smallest set of transformations between two point sets.

And this.

Contero
Mar 28, 2004

I'm trying to make an editor.

I'm planning on lexing the whole buffer in order to do syntax highlighting, brace matching and whatever. When the user types into the editor, I obviously don't want to rescan the entire document, but how do I know what I need to rescan?

Here I obviously only need to rescan the tokens surrounding the cursor(#) (which has just typed the letter t:

code:
function myballs(cont int# thing) {
But what if I have say a dangling /* earlier in the buffer and the user suddenly closes the comment block hundreds of lines below?

code:
/*
... 100+ lines of code ...
blah bla */#
How do I know how far I need to go back in the document to rescan? I can't really think of a universal solution here.

Danith
May 20, 2006
I've lurked here for years
C# question.. Sorry, this is a stupid question but it is bugging me and I didn't see a C# megathread to ask this and my programming experiance is AutoIt and a little python :). From my searching it seems it could be instantiating an object but I'm unsure of it.. and how it works.

code:
HttpWebRequest  request  = (HttpWebRequest)
			WebRequest.Create("http://www.mayosoftware.com");
What is that "HttpWebRequest request = (HttpWebRequest)" doing and how is the "webrequest.create" applying to it? (shouldn't it be something like request.webrequest.create("http://www.mayosoftware.com"); )?

Flamadiddle
May 9, 2004

I don't know what kind of object WebRequest.Create() returns, but it's being cast to an HttpWebRequest object by the (HttpWebRequest) bit, which is in turn assigned to the reference "request".

yippee cahier
Mar 28, 2005

Danith posted:

C# question.. Sorry, this is a stupid question but it is bugging me and I didn't see a C# megathread to ask this and my programming experiance is AutoIt and a little python :). From my searching it seems it could be instantiating an object but I'm unsure of it.. and how it works.

code:
HttpWebRequest  request  = (HttpWebRequest)
			WebRequest.Create("http://www.mayosoftware.com");
What is that "HttpWebRequest request = (HttpWebRequest)" doing and how is the "webrequest.create" applying to it? (shouldn't it be something like request.webrequest.create("http://www.mayosoftware.com"); )?
Python isn't strongly typed like C# so your first problem might be understanding the typing system. That's a little beyond a small programming questions. In this case, request is of type HttpWebRequest.

WebRequest is an abstract class, and the Create method could return an object of a type other than an HttpWebRequest object (say you passed in an FTP address to Create). In this case you know it's going to be HTTP, so the code treats it as one. Otherwise you'd have to check what was returned and handle each case accordingly. The benefit of treating the returned object as an HttpWebRequest instead of a generic WebRequest? Compare the members of each:

http://msdn.microsoft.com/en-us/library/system.net.webrequest_members.aspx
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest_members.aspx

Adbot
ADBOT LOVES YOU

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

sund posted:

Python isn't strongly typed like C# so your first problem might be understanding the typing system.

Python is strongly typed. The word you're looking for is "statically".

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply