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
Contero
Mar 28, 2004

I've used svn in groups for smaller programming projects, but it's never been very organized and I honestly don't know a lot about how to manage a repository. I'm about to start working on a new project and I want to make it a bit more organized.

I want to set up the repository so that each person working on the project can work on their own branch that might be a bit experimental and can incorporate their changes back into the trunk version after a certain amount of QA is done. The only problem is I have no idea how to do this and even if I messed around with it I have no idea if I'm doing it right. So what's the right way to accomplish this?

Adbot
ADBOT LOVES YOU

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Fruit Smoothies posted:

Edit: It seems like the program wants to put more than two things in a box.

Yeah, I was only solving for a general case; you'd express size limitations in that guard function. If your problem is really just this trivial then I don't see why a program is needed.

I mean, let's say you have 12 elements in 6 pairs:
pre:
 A A'
 B B'
 C C'
 D D'
 E E'
 F F'
And you want to assign them to 6 boxes, such that no box contains both elements of a pair and every box contains two elements, then you can trivially construct a solution by hand. Just take that right column and rotate it:
pre:
 A B'
 B C'
 C D'
 D E'
 E F'
 F A'
If there's more to this problem that makes it harder, then I certainly didn't code for it. What, precisely, are you trying to do?

Avenging Dentist
Oct 1, 2005

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

Contero posted:

I've used svn in groups for smaller programming projects, but it's never been very organized and I honestly don't know a lot about how to manage a repository. I'm about to start working on a new project and I want to make it a bit more organized.

I want to set up the repository so that each person working on the project can work on their own branch that might be a bit experimental and can incorporate their changes back into the trunk version after a certain amount of QA is done. The only problem is I have no idea how to do this and even if I messed around with it I have no idea if I'm doing it right. So what's the right way to accomplish this?

We already told you in the C++ thread: use git.

Scaevolus
Apr 16, 2007

Contero posted:

I've used svn in groups for smaller programming projects, but it's never been very organized and I honestly don't know a lot about how to manage a repository. I'm about to start working on a new project and I want to make it a bit more organized.

I want to set up the repository so that each person working on the project can work on their own branch that might be a bit experimental and can incorporate their changes back into the trunk version after a certain amount of QA is done. The only problem is I have no idea how to do this and even if I messed around with it I have no idea if I'm doing it right. So what's the right way to accomplish this?
Mercurial is another good choice, comparable to git with perhaps a better interface. It also has better Windows support.

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

ShoulderDaemon posted:

What, precisely, are you trying to do?

It really is complicated to explain, but the best way to think of it is like adjectives/words. The trouble is, they're not as simple and easily paired as with "hot" and "warm" for example.

Some words can be paired with around 6 others, while some can only be paired with three. This means that doing manually nearly always results in not knowing how to pair up the difficult ones. I'm not even sure if there is a solution to this data set.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Fruit Smoothies posted:

It really is complicated to explain, but the best way to think of it is like adjectives/words. The trouble is, they're not as simple and easily paired as with "hot" and "warm" for example.

Some words can be paired with around 6 others, while some can only be paired with three. This means that doing manually nearly always results in not knowing how to pair up the difficult ones. I'm not even sure if there is a solution to this data set.
Maybe some sort of genetic algorithm that has a fitness function based on the number of valid pairs?

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane

Fruit Smoothies posted:

It really is complicated to explain, but the best way to think of it is like adjectives/words. The trouble is, they're not as simple and easily paired as with "hot" and "warm" for example.

Some words can be paired with around 6 others, while some can only be paired with three. This means that doing manually nearly always results in not knowing how to pair up the difficult ones. I'm not even sure if there is a solution to this data set.

There's 66 possible pairs formed from 12 categories. Make a list of them, and remove any from the list that are invalid. Then, use a backtracking algorithm to recursively insert them one box at a time while ensuring you aren't inserting a duplicate into the list.

tef
May 30, 2004

-> some l-system crap ->

Dijkstracula posted:

If you don't mind getting your hands dirty with a backtracking logic language like Prolog, this sounds like a good constraint programming problem.

:toot:

(refresher: Variables start with a capital, and atoms (string constants) start with a lowercase letter, and statements end with a period).

in foo.pl:
code:
 
% base case - the pairs of an empty set of elements is the empty list
all_pairs([],[]).
% recursive case
all_pairs(Elements,Pairs):-
    pair(Elements, LeftOver, Out), % make one pair
    all_pairs(LeftOver, NewPairs), % make pairs from the leftovers
    Pairs = [Out|NewPairs]. % add out to the front of new pairs

% find one valid pair
pair(Elements, LeftOver, Out) :-
    Elements = [X|E1],  % take the first item
    select(Y, E1, LeftOver), % take any other item
    can_pair(X,Y), % try to pair them
    Out = [X,Y].

% items can pair if they are in the same group.
can_pair(X,Y) :- 
     element_group(X,T),
     element_group(Y,T).

element_group(hot, temp).
element_group(cold, temp).
element_group(cat, animal).
element_group(dog, animal).
element_group(black, colour).
element_group(white, colour).
in the prolog interpreter:
code:
$ swipl
Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 5.6.64)
Copyright (c) 1990-2008 University of Amsterdam.

?- [foo]. % or use consult('foo.pl').
% foo compiled 0.00 sec, 2,180 bytes
true.

?- all_pairs([hot,cold,cat,dog],Boxes).
Boxes = [[hot, cold], [cat, dog]] ;
false.

?- halt.
$
You should be able to add new rules based on can_pair/2 and element_group/2.

You can add new rules like can_pair(foo,Y) :- member(Y, [abacus, zebra, foxtrot]). to say goo can pair with abacus, zebra or foxtrot.

Edit: This is a simple generate and test program. It is possible to optimize this significantly.

tef fucked around with this message at 16:22 on Mar 30, 2009

shrughes
Oct 11, 2008

(call/cc call/cc)

huge sesh posted:

I don't think you really want to try to implement the logic backend that Haskell has in Pascal.

What? Haskell doesn't have a logic backend.

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

tef posted:


Edit: This is a simple generate and test program. It is possible to optimize this significantly.

So this simply tells if a set of boxes is allowed or not, based on the constraints of the allowed pairs?

Prince John
Jun 20, 2006

Oh, poppycock! Female bandits?

I'm pretty stuck on this, so if someone is able to shed some light that would be very helpful! The Excel megathread looks like it is no longer live, so hope this is the right place to put it.

Background

The spreadsheet I'm working on contains data on several companies used for comparative purposes. Row 1 contains the company names (column A, B, C etc) and the data for each company is contained in row 3 and below, as in the mock-up:

code:
   A                  B             C             D
1 Name              Company A     Company B      
2 Selected?         Yes          <blank>      <Median calculation>
3 Revenue           1m            500k        <Median calculation>
4 No. of entities   10            20          <Median calculation>
We can 'turn on' companies by adding a 'Yes' into row 2, in the appropriate column - the range of responses in row 2 has been named 'Selection'.

The median calculation for revenue, for example, would be
code:
{=MEDIAN(IF(Selection="Yes",(B3:C3),""))}
which only calculates a median for those companies which are selected.

The problem

I'm trying to do a more complicated formula - I want to go along row 4 and count only those cells with a value of, say, equal or less than 15, but only if those columns have been selected.

The basic formula I had been using was this, which worked fine, but doesn't take into account whether the company is 'selected' or not:

code:
=(COUNTIF(B4:C4,"<=15"))
Trying to incorporate selection, I end up with something like this:

code:
{=COUNTIF(IF(Selection="Yes",B4:C4,""),"<=15")}
which returns #VALUE. Numerous variations on the theme just returned 'incorrect formula' errors. Does anyone have any idea where I am going wrong or an alternative way to do this? Thanks in advance!

tef
May 30, 2004

-> some l-system crap ->

Fruit Smoothies posted:

So this simply tells if a set of boxes is allowed or not, based on the constraints of the allowed pairs?

No. It's *generate* and test.

By passing a variable in, it will search for a value that is a valid set of pairs from the given elements:

code:
?- all_pairs([hot,cold,cat,dog],Boxes).
Boxes = [[hot, cold], [cat, dog]] ;
false.
This is generating all the possible combinations of the set [hot, cold, cat, dog].

The trick with prolog is that you simply state what you want, and then prolog finds it for you.

You can also call it with a set and a list of pairs to see if it is a valid combination.

Or call it with a list of pairs and find out the set of elements.

Or call it with two variables to enumerate all possible sets of elements and pairs.

Edit: To give a simpler example: Every prolog expression is really a question:

code:
% is foo a member of the list [foo,bar,baz]
?- member(foo,[foo,bar,baz]).
true . % yes

% is X a member of [foo,bar,baz]
?- member(X,[foo,bar,baz]).
X = foo ; % yes, if X = foo
X = bar ; % yes, if X = bar
X = baz ; % yes, if X = baz
false.    % there are no more ways this can be true

% is foo a member of the list X?
?- member(foo,X).
X = [foo|_G269] ; % yes, if X is a list where foo is the head, and some variable is the tail
X = [_G268, foo|_G272] ; % and so on....

% is X a member of the list Y ?
?- member(X,Y).
Y = [X|_G284] ; % etc, and this also goes on
You write questions in prolog, and write rules to deduct information.

I wrote rules to say that a list of elements and a list of pairs is valid if
it could make one pair, and the rest of the elements could be made into pairs.

The prolog interpreter searches for a possible case where the rule is true. By supplying variables, I can enumerate cases where the rule is true.

The program itself is very trivial and basic prolog, if you can write up the rules
in a pastebin or link to them, I can try to add it to the example I wrote above.

tef fucked around with this message at 16:24 on Mar 30, 2009

chocojosh
Jun 9, 2007

D00D.

Col posted:

I'm pretty stuck on this, so if someone is able to shed some light that would be very helpful! The Excel megathread looks like it is no longer live, so hope this is the right place to put it.

Background

The spreadsheet I'm working on contains data on several companies used for comparative purposes. Row 1 contains the company names (column A, B, C etc) and the data for each company is contained in row 3 and below, as in the mock-up:

code:
   A                  B             C             D
1 Name              Company A     Company B      
2 Selected?         Yes          <blank>      <Median calculation>
3 Revenue           1m            500k        <Median calculation>
4 No. of entities   10            20          <Median calculation>
We can 'turn on' companies by adding a 'Yes' into row 2, in the appropriate column - the range of responses in row 2 has been named 'Selection'.

The median calculation for revenue, for example, would be
code:
{=MEDIAN(IF(Selection="Yes",(B3:C3),""))}
which only calculates a median for those companies which are selected.

The problem

I'm trying to do a more complicated formula - I want to go along row 4 and count only those cells with a value of, say, equal or less than 15, but only if those columns have been selected.

The basic formula I had been using was this, which worked fine, but doesn't take into account whether the company is 'selected' or not:

code:
=(COUNTIF(B4:C4,"<=15"))
Trying to incorporate selection, I end up with something like this:

code:
{=COUNTIF(IF(Selection="Yes",B4:C4,""),"<=15")}
which returns #VALUE. Numerous variations on the theme just returned 'incorrect formula' errors. Does anyone have any idea where I am going wrong or an alternative way to do this? Thanks in advance!

First result from google: http://www.ozgrid.com/Excel/count-if.htm

A less elegant approach that I've seen would be to create a hidden column, and then for each row use the formula (not tested): =IF(AND(B4="Yes",C4<=15), 1, 0)
Then sum the values in the hidden column

Fruit Smoothies
Mar 28, 2004

The bat with a ZING
I guess what I don't get about any of these bits of code, is when the program stops, and where it starts. I have realised a good example of this problem is that of the numbers 1-12. If you add a constraint that prime numbers can't be paired with each other, you very quickly end up with an interesting set of allowed pairings:

code:
1,4   4,12
1,6   5,6
1,8   5,8
1,10  5,10
1,12  5,12
2,4   6,7
2,6   6,8
2,8   6,9
2,10  6,10
2,12  6,11
3,4   6,12
3,6   7,8
3,8   7,10
3,10  7,12
3,12  8,9
4,5   8,10
4,6   8,11
4,7   8,12
4,8   9,10
4,9   9,12
4,10  10,11
4,11  10,12
      11,12
Say I start with the first allowed pair (1,4) and then move to the next allowed pair (2,6) etc; (3,8)(5,10)(7,12)... Where would the program go from here? It's reached the end of the list, and there are no more allowed pairs? Of course, this example strikes me as impossible, because the pairs are pretty much restricted to odd-even. This would work if 2 wasn't a prime number. (Correct me if I'm wrong, here)

(1,4)(2,6)(3,8)(7,10)(9,12)

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane

Fruit Smoothies posted:

I guess what I don't get about any of these bits of code, is when the program stops, and where it starts. I have realised a good example of this problem is that of the numbers 1-12. If you add a constraint that prime numbers can't be paired with each other, you very quickly end up with an interesting set of allowed pairings:

code:
1,4   4,12
1,6   5,6
1,8   5,8
1,10  5,10
1,12  5,12
2,4   6,7
2,6   6,8
2,8   6,9
2,10  6,10
2,12  6,11
3,4   6,12
3,6   7,8
3,8   7,10
3,10  7,12
3,12  8,9
4,5   8,10
4,6   8,11
4,7   8,12
4,8   9,10
4,9   9,12
4,10  10,11
4,11  10,12
      11,12
Say I start with the first allowed pair (1,4) and then move to the next allowed pair (2,6) etc; (3,8)(5,10)(7,12)... Where would the program go from here? It's reached the end of the list, and there are no more allowed pairs? Of course, this example strikes me as impossible, because the pairs are pretty much restricted to odd-even. This would work if 2 wasn't a prime number. (Correct me if I'm wrong, here)

(1,4)(2,6)(3,8)(7,10)(9,12)

Look up backtracking algorithms and the n-queens problem, I think it would be the best solution for your current problem.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Fruit Smoothies posted:

I guess what I don't get about any of these bits of code, is when the program stops, and where it starts.

We're using programming paradigms that don't have as strictly-defined concepts of execution as you're used to.

Fruit Smoothies posted:

I have realised a good example of this problem is that of the numbers 1-12. If you add a constraint that prime numbers can't be paired with each other, you very quickly end up with an interesting set of allowed pairings:

code:
1,4   4,12
1,6   5,6
1,8   5,8
1,10  5,10
1,12  5,12
2,4   6,7
2,6   6,8
2,8   6,9
2,10  6,10
2,12  6,11
3,4   6,12
3,6   7,8
3,8   7,10
3,10  7,12
3,12  8,9
4,5   8,10
4,6   8,11
4,7   8,12
4,8   9,10
4,9   9,12
4,10  10,11
4,11  10,12
      11,12
Say I start with the first allowed pair (1,4) and then move to the next allowed pair (2,6) etc; (3,8)(5,10)(7,12)... Where would the program go from here? It's reached the end of the list, and there are no more allowed pairs?

You decide that an earlier decision must have been wrong, so you back up and try something else. This is hidden in the List monad in Haskell, and in the unification algorithm in Prolog.

Fruit Smoothies posted:

Of course, this example strikes me as impossible, because the pairs are pretty much restricted to odd-even. This would work if 2 wasn't a prime number. (Correct me if I'm wrong, here)

There are six primes and six nonprimes in the range 1..12 (assuming you count 1 as prime) so the solution is quite straightforward.

(1,4),(2,6),(3,8),(5,9),(7,10),(11,12)

And, obviously, any substitution of the above where primality is preserved.

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

ShoulderDaemon posted:

And, obviously, any substitution of the above where primality is preserved.

I counted 9 as prime :doh:

Would it be true to say that starting at every point in the list, and considering all of the other items' compatibility would solve this problem? Although it would be inefficient?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Fruit Smoothies posted:

I counted 9 as prime :doh:

Would it be true to say that starting at every point in the list, and considering all of the other items' compatibility would solve this problem? Although it would be inefficient?

I'm not exactly sure what you mean...

An inefficient but easy-to-verify solution to the general problem is:
code:
FindPairs:
  given l, a list of unpaired elements
  choose an element a from l, and consider l' the other elements in l
  choose an element b from l', and consider l'' the other elements in l'
  if (a, b) is a valid pairing
    ps <- FindPairs l''
    return ps + (a, b)
  otherwise
    find the most recent choice for which there are alternatives we have not considered
    backtrack to that choice, and choose something else
It doesn't matter which choice you make first, because this will always find a solution if one exists. But in most cases (such as the prime number case) there are far better solutions which minimize or eliminate backtracking by picking in the "best" order according to some heuristic. For example, in the prime number case, if we always try to pick a prime number for a and a nonprime for b then we are guaranteed to find a solution without backtracking, if one exists.

tef
May 30, 2004

-> some l-system crap ->

Fruit Smoothies posted:

I guess what I don't get about any of these bits of code, is when the program stops, and where it starts.

In mine it starts by taking two items, trying to pair them, and then moves onto the rest of them.

It stops when it runs out of items to pair, or if it can't pair the remaining items.

In the latter case, it will not produce a solution.

huge sesh
Jun 9, 2008

shrughes posted:

What? Haskell doesn't have a logic backend.

Sorry, I was confused.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
I have no point here, I just like saying "Curry-Howard isomorphism".

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Not as cool as the Curly Howard isomorphism.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
http://www.youtube.com/watch?v=c8Zl0a2-wqw

Prince John
Jun 20, 2006

Oh, poppycock! Female bandits?

chocojosh posted:

First result from google: http://www.ozgrid.com/Excel/count-if.htm

A less elegant approach that I've seen would be to create a hidden column, and then for each row use the formula (not tested): =IF(AND(B4="Yes",C4<=15), 1, 0)
Then sum the values in the hidden column

Many thanks, I had missed this with my search terms. In the end, something similar to this works fine:

code:
{=COUNT(IF(Selection="Yes",IF(B10:U10  < 15,B10:U10,"")))}
A surprisingly simple answer in the end.

Thanks again.

newsomnuke
Feb 25, 2007

I'm having a problem with a bison grammar. It's meant to accept variable declarations and assignments such as:
code:
const var x = 6;
MyClass mc;
global g_x = 5;
etc, where variables types are either 'var' or the name of a class, and scope and access qualifiers can be left blank. Typical stuff.

code:
program
	: var_statement
	| scoped_identifier
	;

access_qualifier
	:
	| KEYWORD_MUTABLE
	| KEYWORD_CONST
	;

scope_qualifier
	:
	| KEYWORD_LOCAL
	| KEYWORD_GLOBAL
	;

variable_declaration
	: KEYWORD_VAR IDENTIFIER
	| IDENTIFIER IDENTIFIER
	;

var_statement
	: access_qualifier variable_declaration ';'
	;

scoped_identifier
	: scope_qualifier IDENTIFIER
	;
It gives a reduce/reduce conflict between scope_qualifier and access_qualifier, but I can't think of any input which would actually lead to this, or how to get around it without introducing extra tokens. Ideas?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
When it's trying to parse a program, and it can read "" from the head of input (i.e. always), it doesn't know whether to treat that as an access_qualifier or a scope_qualifier. This sort of thing is an excellent reason to strongly avoid empty productions.

The easiest solution is to pull the empty productions out of those two symbols and duplicate their users, like so:

code:
var_statement
	: variable_declaration ';'
	| access_qualifier variable_declaration ';'
	;

scoped_identifier
	: IDENTIFIER
	| scope_qualifier IDENTIFIER
	;

newsomnuke
Feb 25, 2007

rjmccall posted:

When it's trying to parse a program, and it can read "" from the head of input (i.e. always), it doesn't know whether to treat that as an access_qualifier or a scope_qualifier.
I guess I misunderstood how it worked. I thought that when it found an empty production it pushed that onto the stack somehow, and then resolved the conflict by looking at the next token.

Your solution was spot on, thanks.

astr0man
Feb 21, 2007

hollyeo deuroga
How hard is it to transition from verilog to VHDL? For my internship this summer I'll be doing fpga poo poo but it will be in VHDL. I have no VHDL experience since my school uses verilog instead.

mlnhd
Jun 4, 2002

This is the code that's executed when you "Show Containing Folder" in Firefox's Download Manager on Windows.
code:
NS_IMETHODIMP
nsLocalFile::Reveal()
{
    // make sure mResolvedPath is set
    nsresult rv = ResolveAndStat();
    if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND)
        return rv;

    // use the full path to explorer for security
    nsCOMPtr<nsILocalFile> winDir;
    rv = GetSpecialSystemDirectory(Win_WindowsDirectory, getter_AddRefs(winDir));
    NS_ENSURE_SUCCESS(rv, rv);
    nsAutoString explorerPath;
    rv = winDir->GetPath(explorerPath);  
    NS_ENSURE_SUCCESS(rv, rv);
    explorerPath.Append(L"\\explorer.exe");

    // Always open a new window for files because Win2K doesn't appear to select
    // the file if a window showing that folder was already open. If the resolved 
    // path is a directory then instead of opening the parent and selecting it, 
    // we open the directory itself.
    nsAutoString explorerParams;
    if (mFileInfo64.type != PR_FILE_DIRECTORY) // valid because we ResolveAndStat above
        explorerParams.Append(L"/n,/select,");
    explorerParams.Append(L'\"');
    explorerParams.Append(mResolvedPath);
    explorerParams.Append(L'\"');

    if (::ShellExecuteW(NULL, L"open", explorerPath.get(), explorerParams.get(),
                        NULL, SW_SHOWNORMAL) <= (HINSTANCE) 32)
        return NS_ERROR_FAILURE;

    return NS_OK;
}
http://paste.ifies.org/426
Basically, it calls explorer.exe directly in order to pass some flags on the command line that make the file selected automatically.

I want to change this so that it uses the default handler for Folders -OR- have it call something other than explorer.exe.
I use an XYplorer as a file manager, and I want "Show Containing Folder" to use that instead.

Is this possible to do by writing an extension? Would I have to write a whole new Download Manager replacement to override just this one method?

mlnhd fucked around with this message at 15:54 on Apr 1, 2009

DholmbladRU
May 4, 2006
ht

DholmbladRU fucked around with this message at 22:32 on Apr 1, 2009

csammis
Aug 26, 2003

Mental Institution

Melonhead posted:

[firefox download manager code]

I want to change this so that it uses the default handler for Folders -OR- have it call something other than explorer.exe.
I use an XYplorer as a file manager, and I want "Show Containing Folder" to use that instead.


I don't know about writing an extension to replace the behavior, but you might want to suggest a patch to Firefox to change this behavior because as you've discovered it's not strictly correct. Instead of executing Explorer, one should just ShellExecute the path itself and the shell registered in HKEY_CLASSES_ROOT\Folder\shell\[action]\command will take care of business.

code:
if (::ShellExecuteW(NULL, L"open", mResolvedPath, NULL, mResolvedPath, SW_SHOWNORMAL) <= (HINSTANCE)32)
e: Alternately, because they do some cleverness with automatically selecting the item in Explorer, your patch/extension could just read the registered shell from the registry key mentioned above and execute that with whatever parameters it requires to get the job done.

csammis fucked around with this message at 16:11 on Apr 1, 2009

TheSneak
Feb 24, 2009
My friend and I are completely lost on an assembly language program. Its fairly simple, but we are newbs to assembly. Anyway, we are making a calculator that takes in two two-digit values (0 to 48) and adds them together. We are having trouble with A) collecting the input and storing it . . . somewhere B) converting ASCII to binary. Any help would be appreciated. Thanks.

TSDK
Nov 24, 2003

I got a wooden uploading this one

TheSneak posted:

My friend and I are completely lost on an assembly language program. Its fairly simple, but we are newbs to assembly. Anyway, we are making a calculator that takes in two two-digit values (0 to 48) and adds them together. We are having trouble with A) collecting the input and storing it . . . somewhere B) converting ASCII to binary. Any help would be appreciated. Thanks.
You didn't specify processor or execution environment, so here's a complete tutorial for input and output in DOS on an x86.

Lamont Cranston
Sep 1, 2006

how do i shot foam
I'm writing a program that needs to solve a variant on the Traveling Salesman Problem - but instead of the constraint being that every node must be visited exactly once, I only need to make sure that each node is visited at least once. Is this also NP-complete? Is there anything in the literature that could help me out? All I've found through Google are sites dealing with the standard TSP.
edit: This is for a graph of about 470 nodes if it makes a difference, I know for TSP anything above 40 gets pretty crazy

Lamont Cranston fucked around with this message at 17:53 on Apr 3, 2009

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Sadly, no, it doesn't make it easier.

Have you looked into the approximation algorithms? Kruskal's gives you a factor-of-two approximation which can generally be optimized into something quite reasonable.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Changing it to "at least once" has no effect on the problem. Any graph can be transformed into one where the triangle inequality holds (i.e. ∀x∀y∀z: d_{xy}+d_{yz} > d_{xz}), and once that is done the optimal path will obviously not include visiting any nodes twice, as A->B->A->C could be replaced with A->B->C without increasing the length.

Lamont Cranston
Sep 1, 2006

how do i shot foam

Plorkyeran posted:

Changing it to "at least once" has no effect on the problem. Any graph can be transformed into one where the triangle inequality holds (i.e. ∀x∀y∀z: d_{xy}+d_{yz} > d_{xz}), and once that is done the optimal path will obviously not include visiting any nodes twice, as A->B->A->C could be replaced with A->B->C without increasing the length.

I'm not sure I follow - my graph theory's not the best though. Here's a broad simplification of my graph:


Click here for the full 1052x984 image.


How could I traverse this, hitting each node, if I don't do any backtracking? Maybe TSP is less similar than I thought?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
TSP is usually formalized over complete graphs. Usually, we can use infinite-weight edges to make an arbitrary graph complete; the original graph has a Hamiltonian cycle iff the completed graph has a cycle with finite weight. It's still NP-complete.

gold brick
Jun 19, 2001

no he isn't

Lamont Cranston posted:

How could I traverse this, hitting each node, if I don't do any backtracking? Maybe TSP is less similar than I thought?
Just taking a quick look, I don't think you can do it without backtracking. SXBL, DIT, L125, LOR, and QB21 are all terminal unless it's your starting node.

EDIT: I came back to check on this thread and couldn't resist fixing my typo.

gold brick fucked around with this message at 22:59 on Apr 3, 2009

Adbot
ADBOT LOVES YOU

Fruit Smoothies
Mar 28, 2004

The bat with a ZING
Going back to backtracking, the algorithm makes sense. What doesn't make sense is a way of storing the paths, and making it reversible. Below is my latest pseudo-implementation in Delphi.

The whole thing is horribly messy and confusing. I'm half tempted to post in the "small app" thread tbh.

I must be missing something obvious here, as it shouldn't be this complicated.

code:
Procedure FindPairs(Item);
begin


if isEmpty(List) then
  begin
    if parentOf(List) = nil then
      begin
        // We have reached the end, since it has no parent
        // to backtrack to.
      end;
  end
else
  begin
    // Check to see what type of list we're dealing with.
    // An a-list means we're matching a with a generated b-list
    // a b-list means we've back tracked to a place where
    // (a,b) hasn't been exhaused.
    if ListType = a then
      begin
        // Take the first item to be tested in the pair:
        // [Pairs take the format (a, b)]
        //
        a = list[0];
        alist = list;
        // We're trying a, so there's no need for it to be in the
        // list, if it's backtracked to.
        removeItem(a, alist);
        //
        // Now we need to add that list to a list of lists, in-
        // -case we need to backtrack
        // Since this
        ListList.Add(aList, parent = list);
        //
        // Now we need to generate a b-list in order to match (a,b)
        //
        blist = alist;
        repeat
           b = blist[0];
           removeItem(b, blist);
           if IsAllowed(a,b) then
              // We have found a pair

        until (IsAllowed(a,b) or (blist.Count = 0));

        if (blist.Count = 0) and (alist.Count = 0) then
          begin
            // We have reached the end of everything
          end;

        if (blist.Count = 0) and (not IsAllowed(a,b)) and (alist.Count > 0) then
          begin
            // We need to backtrack to an a-list
            //
            FindPairs(parentOf(List));
          end;

      end;
      if ListType = b then
        begin
          //
          // We have gone back to a situation where there are options in
          // a b-list which needed to be covered.
          // The a-value that corresponds to the b-list is stored with the
          // b-list
          //
          a = getaValueFromStorage(blist)
          repeat
            b = blist[0];
            removeItem(b, blist);
            if IsAllowed(a,b) then
                // We have found a pair

          until (IsAllowed(a,b) or (blist.Count = 0));

          if (blist.Count = 0) then
            begin
              //
              //  We have exhausted all values of (a,b)
              //
              FindPairs(parentOf(blist));
            end;
        end;


  end;

end;

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