Two Plus Two Publishing LLC
Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > >

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 09-27-2016, 12:40 PM   #1451
Lattimer
I is smart
 
Lattimer's Avatar
 
Join Date: Feb 2009
Location: New England
Posts: 14,399
Re: Programming homework and newbie help thread

It's something I'm very familiar with because I often deal with checksum algorithms, which utilize various-sized XOR sums.
Lattimer is offline   Reply With Quote
Old 09-27-2016, 03:03 PM   #1452
daveT
S.A.G.E. Master
 
daveT's Avatar
 
Join Date: Jun 2005
Location: La La Land
Posts: 23,211
Re: Programming homework and newbie help thread

hate to be that guy, and asking in full respect, but what is this for?
daveT is offline   Reply With Quote
Old 09-27-2016, 10:36 PM   #1453
hellomynameis
newbie
 
Join Date: Sep 2016
Posts: 16
Re: Programming homework and newbie help thread

Quote:
Originally Posted by ChrisV View Post
One of the bolded assuming you're running Windows or OSX.
ugh I'm so bad at this. I downloaded the zip file, realized it was (both downloaded and unzipped) in the wrong folder, moved it to the R library, still getting the same error.

i thought it was odd that there's an Rcpp 0.12.7 folder with nothing but another Rcpp, is it something to do with the way i moved the file or unzipped it?

LOL i am trying to post the image of what i mean but now 2p2 is censoring the link to that as well, wtf. i can't for the life of me figure out what it's trying to censor but below is the URL minus the spaces (just showing the Rcpp within the Rcpp 12.7, probably not even helpful, idk).

https://posti mg.or g/image/m69znv5dh/
hellomynameis is offline   Reply With Quote
Old 09-29-2016, 01:48 AM   #1454
Ryanb9
Carpal \'Tunnel
 
Ryanb9's Avatar
 
Join Date: Aug 2006
Location: NEVA!
Posts: 7,095
Re: Programming homework and newbie help thread

Say language L = a^n b^n c^n, n >= 0. So strings in that language would be the empty string, abc, aabbcc, aaabbbccc, etc. I'm trying to make an underlying CFG for this (that I will then use attribute grammar on). I'm stuck on the context free grammar part.
Ryanb9 is offline   Reply With Quote
Old 09-29-2016, 01:58 AM   #1455
Ryanb9
Carpal \'Tunnel
 
Ryanb9's Avatar
 
Join Date: Aug 2006
Location: NEVA!
Posts: 7,095
Re: Programming homework and newbie help thread

Welp, I think this should work?

Ax --> a Ax | empty
Bx --> a Bx | empty
Cx --> c Cx | empty

then if I have AxBxCx I can make empty from it. abc from it, aabbcc from it, aaabbbccc from it. Only problem is I can also make abbc from it which shouldn't be part of the language. But this should work for my staring CFG?
Ryanb9 is offline   Reply With Quote
Old 09-29-2016, 10:33 AM   #1456
just_grindin
Pooh-Bah
 
Join Date: Dec 2007
Posts: 4,976
Re: Programming homework and newbie help thread

Quote:
Originally Posted by Ryanb9 View Post
Welp, I think this should work?

Ax --> a Ax | empty
Bx --> a Bx | empty
Cx --> c Cx | empty

then if I have AxBxCx I can make empty from it. abc from it, aabbcc from it, aaabbbccc from it. Only problem is I can also make abbc from it which shouldn't be part of the language. But this should work for my staring CFG?
It seems to me you're making proxies for the fundamental elements of your language which I don't think you're required to do to define your cfg.

What I think makes more sense is for you to express exponentiation in your language and then express a word as exponentiation of your fundamental characters a,b,c or an empty string.

Either that or define concatenation in some way but make it repeatable on single language elements (so that you could concatenate a with as many A's as you need but then also concatenate that with b's etc).
just_grindin is offline   Reply With Quote
Old 09-29-2016, 05:08 PM   #1457
codeartisan
centurion
 
codeartisan's Avatar
 
Join Date: Jun 2008
Posts: 155
Re: Programming homework and newbie help thread

Quote:
Originally Posted by daveT View Post
hate to be that guy, and asking in full respect, but what is this for?
What's a Hamming Code, you mean?

It's way for the recipient of a data transmission to detect and correct errors on a fairly simple level. It can only correct one-bit errors, but it's a step ahead of things like parity checks that can detect, but not correct.
codeartisan is offline   Reply With Quote
Old 10-03-2016, 08:14 PM   #1458
Mavoor
centurion
 
Join Date: Jun 2014
Posts: 150
Re: Programming homework and newbie help thread

Given the following schema:

Code:
CREATE TABLE Classes (
  class varchar(20),
  type varchar(2),
  country varchar(20),
  numGuns int,
  bore int,
  displacement int
);
CREATE TABLE Battles (
  name varchar(20),
  date DATE
);
CREATE TABLE Outcomes (
  ship varchar(20),
  battle varchar(20),
  result varchar(20)
, sunkBy varchar(20));
CREATE TABLE Ships (
  name varchar(20),
  class varchar(20),
  launched int
);
I'm trying to for each class of ships that includes at least 2 ships, find the number of ships sunk by a ship of that class.

I have the following sql query:

Code:
WITH M AS(
  SELECT class from Ships
  GROUP BY class
  HAVING COUNT(class) > 1
)
SELECT ships.class, COUNT(*)
FROM Outcomes, Ships, m 
WHERE Outcomes.sunkby = Ships.name AND M.class = Ships.class
GROUP BY ships.class;
But it only returns info about classes who have sunk at least 1 ship. The where clause causes classes with no sunken ships to be ignored.
I would however like to list also the classes who haven't sunk any ships, and have them displayed as {'ClassName', 0}.

To abstract the question a bit, I'm looking for a way to return also rows that have count = 0, in a count/group by query.
Mavoor is offline   Reply With Quote
Old 10-03-2016, 08:51 PM   #1459
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 24,465
Re: Programming homework and newbie help thread

I would approach this from another direction.

Code:
with x as (
   select ships.name, count(*) as c
   from ships, outcomes
   where ships.name = outcomes.sunkby
  group by ships.name
)
select ships.class, sum(x.c) as sunk, count(*) as class_size
from ships
left join x on (ships.name = x.name)
group by ships.class
having class_size > 1
I assume you are allowed to use outer joins. Left join here means "include all rows in the first table, with nulls for fields in the 2nd table that don't have a match". This lets us make sure that every ship class is represented.

Note that sum(x.c) will, for most databases, be null if there are no qualifying ships in that class. Each database handles this in their own way. Oracle uses NVL, sqlite uses IFNULL, etc. You'd have to look up your particular databases' method.
RustyBrooks is offline   Reply With Quote
Old 10-07-2016, 11:22 PM   #1460
Ryanb9
Carpal \'Tunnel
 
Ryanb9's Avatar
 
Join Date: Aug 2006
Location: NEVA!
Posts: 7,095
Re: Programming homework and newbie help thread

Trying to do a CFG that will accept things like "x = 1.5 + 2;" "y = x * (-3)" "# This is a comment"

Code:
stmt    : assn ';'
        | com
assn    : id '=' expr
expr    : id
        | numb
        | expr opr expr
        | '(' expr ')'
        | '(' '-' expr ')'
numb    : int
        | int '.' int
com     : '#' (string | epsilon)
So you read the above like this: "statement is either an assignment followed by a semicolon or a comment" i guess

int is 0-9, string is any combo of letters, epsilon is empty

Will this work? Sometimes there's some weird recursion spots that will end up accepting things I dont want to accept but I've looked at this for a while and it seems okay, although the (-expr) and (expr) seems a bit redundant like maybe I could solve it with less code in the language but I want to enforce that any negative assignment be inside a parenthesis.
Ryanb9 is offline   Reply With Quote
Old 10-08-2016, 03:30 AM   #1461
daveT
S.A.G.E. Master
 
daveT's Avatar
 
Join Date: Jun 2005
Location: La La Land
Posts: 23,211
Re: Programming homework and newbie help thread

Quote:
Originally Posted by Mavoor View Post
Given the following schema:

I would however like to list also the classes who haven't sunk any ships, and have them displayed as {'ClassName', 0}.
Rusty is right about using left join, but to convert null to 0 you have two options, coalesce and case.

You didn't say what RDMS you are using, so I'll default to giving you the Postgres version of each, though I think both structures are available in pretty much all RDMS's.

coalesce() takes to arguments, evaluating the first argument that is not null.

first arg is not null:
Code:
select coalesce(1, 2);
>> 1
first arg is null:
Code:
select coalesce(null, 2);
>> 2
In your case, you want coalesce(sum(x.c), 0), which will convert all your nulls to 0.

You may also do this with CASE, which looks like this:

Code:
select
case
   when x.c is null 
	then 0
   else x.c
end
from ....
daveT is offline   Reply With Quote
Old 10-08-2016, 08:29 AM   #1462
just_grindin
Pooh-Bah
 
Join Date: Dec 2007
Posts: 4,976
Re: Programming homework and newbie help thread

Quote:
Originally Posted by Ryanb9 View Post
Trying to do a CFG that will accept things like "x = 1.5 + 2;" "y = x * (-3)" "# This is a comment"

Code:
stmt    : assn ';'
        | com
assn    : id '=' expr
expr    : id
        | numb
        | expr opr expr
        | '(' expr ')'
        | '(' '-' expr ')'
numb    : int
        | int '.' int
com     : '#' (string | epsilon)
So you read the above like this: "statement is either an assignment followed by a semicolon or a comment" i guess

int is 0-9, string is any combo of letters, epsilon is empty

Will this work? Sometimes there's some weird recursion spots that will end up accepting things I dont want to accept but I've looked at this for a while and it seems okay, although the (-expr) and (expr) seems a bit redundant like maybe I could solve it with less code in the language but I want to enforce that any negative assignment be inside a parenthesis.
I could be wrong but I was under the impression you had to define things first before you used them to define other things. For example, I thought you had to define assgn and com before their used to define statement.

I'm also fairly certain order might matter here if you actually have to define how addition, multiplication, etc work as there is an order of operations to take into account.
just_grindin is offline   Reply With Quote
Old 10-08-2016, 11:50 AM   #1463
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 24,465
Re: Programming homework and newbie help thread

What language?

In python (which this clearly is not) the resultset has a rownumber attribute. But I probably wouldn't use it, I'd probably just use "enumerate", and for whatever langauge you're in you could just keep a counter.
RustyBrooks is offline   Reply With Quote
Old 10-08-2016, 11:52 AM   #1464
NiSash1337
Carpal \'Tunnel
 
NiSash1337's Avatar
 
Join Date: Dec 2010
Location: Germany
Posts: 9,186
Re: Programming homework and newbie help thread

Ohh you replied so quickly I deleted my post in the meantime and wanted to do it new. It was Java.
NiSash1337 is offline   Reply With Quote
Old 10-08-2016, 11:57 AM   #1465
NiSash1337
Carpal \'Tunnel
 
NiSash1337's Avatar
 
Join Date: Dec 2010
Location: Germany
Posts: 9,186
Re: Programming homework and newbie help thread

Code:
       ResultSet rs = stmt.executeQuery( "SELECT XXX FROM XYZ;" );
	         while ( rs.next() ) 
	         {	        
	         String test = rs.getString("XXX");
	         }
The goal was to have a choicebox in Javafx have all the strings from the database as choices. I wanted to have the method return the "test" string, but then it would obviously quit with the first result. So next try was to have a pointer to rs and recursively call the method but that didn't work. So I guess I have to have a rowcounter and then just return the element in row x.

I guess the easiest way would probably be to count the rows with one method, then with another method return the current row and recursively call that method with row +1.
NiSash1337 is offline   Reply With Quote
Old 10-08-2016, 12:02 PM   #1466
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 24,465
Re: Programming homework and newbie help thread

Any reason not to create an array of strings and return that? Or to create an interator that returns results one at a time? Either of these is very simple in python, but I don't know anything about java.
RustyBrooks is offline   Reply With Quote
Old 10-08-2016, 12:05 PM   #1467
NiSash1337
Carpal \'Tunnel
 
NiSash1337's Avatar
 
Join Date: Dec 2010
Location: Germany
Posts: 9,186
Re: Programming homework and newbie help thread

I did solve it with an arraylist, but that seemed very inefficent when I got a Database with the data anyways to then save it in an arraylist. It's the first time I worked with Databases and Javafx and was pretty much experimenting.
NiSash1337 is offline   Reply With Quote
Old 10-08-2016, 02:11 PM   #1468
Ryanb9
Carpal \'Tunnel
 
Ryanb9's Avatar
 
Join Date: Aug 2006
Location: NEVA!
Posts: 7,095
Re: Programming homework and newbie help thread

Quote:
Originally Posted by RustyBrooks View Post
What language?

In python (which this clearly is not) the resultset has a rownumber attribute. But I probably wouldn't use it, I'd probably just use "enumerate", and for whatever langauge you're in you could just keep a counter.
No language, its just a context free grammar. oh, nvm you weren't replying to me
Ryanb9 is offline   Reply With Quote
Old 10-13-2016, 12:45 AM   #1469
Mavoor
centurion
 
Join Date: Jun 2014
Posts: 150
Re: Programming homework and newbie help thread

Quote:
Originally Posted by Ryanb9 View Post
Say language L = a^n b^n c^n, n >= 0. So strings in that language would be the empty string, abc, aabbcc, aaabbbccc, etc. I'm trying to make an underlying CFG for this (that I will then use attribute grammar on). I'm stuck on the context free grammar part.
L = { a^n b^n c^n | n >= 0 } isn't a context free language, which you can proof via the pumping lemma for CFL's. It's however easily recognizable by a Turing machine, and probably one of the first examples of a language that isn't context free but can be recognized by a Turing machine.


Quote:
Originally Posted by Ryanb9 View Post
Trying to do a CFG that will accept things like "x = 1.5 + 2;" "y = x * (-3)" "# This is a comment"

Code:
stmt    : assn ';'
        | com
assn    : id '=' expr
expr    : id
        | numb
        | expr opr expr
        | '(' expr ')'
        | '(' '-' expr ')'
numb    : int
        | int '.' int
com     : '#' (string | epsilon)
So you read the above like this: "statement is either an assignment followed by a semicolon or a comment" i guess

int is 0-9, string is any combo of letters, epsilon is empty

Will this work? Sometimes there's some weird recursion spots that will end up accepting things I dont want to accept but I've looked at this for a while and it seems okay, although the (-expr) and (expr) seems a bit redundant like maybe I could solve it with less code in the language but I want to enforce that any negative assignment be inside a parenthesis.
Could you give an example of where this cfg accepts something that it shouldn't accept? I think it looks good at first glance but not sure.
Btw, for completeness I think you should list out all the terminals, that is end symbols. ie create a new rule int -> 0 | 1 | ... | 9, and do something similar for strings (and include epsilon as a string instead of defining it as its own identity)
Mavoor is offline   Reply With Quote
Old 10-24-2016, 04:32 AM   #1470
Ankimo
old hand
 
Join Date: Dec 2010
Location: Somewhere over the rainbow
Posts: 1,961
Re: Programming homework and newbie help thread

Is there no publically available AHK code for scanning cards on Stars? When I google it, the only hit I get is for writing a bot which only explains the concept but no code.
Ankimo is offline   Reply With Quote
Old 10-24-2016, 09:20 AM   #1471
Mavoor
centurion
 
Join Date: Jun 2014
Posts: 150
Re: Programming homework and newbie help thread

Given the following DB schema:

Code:
Human(Id, gender, ...)
Man(Id, ...)
Woman(Id, ...)
Where Id is an unique number within the Man/Woman tables, but not unique within Human (Because a man and a Woman might have the same Id).
{Id, gender} is however Unique within Human because no human can have the same Id as another human of the same gender.
How can I create a relationship between Man/Woman and Human. There is a one-to-one relationship between them, but how can I reference the correct tuple within Human, given information from Man. The Id alone is not enough because I might get information about a woman.
Do I need to store gender information within the Man/Woman tables as well? Or is there another way of doing this?
Mavoor is offline   Reply With Quote
Old 10-24-2016, 12:57 PM   #1472
just_grindin
Pooh-Bah
 
Join Date: Dec 2007
Posts: 4,976
Re: Programming homework and newbie help thread

Quote:
Originally Posted by Mavoor View Post
Given the following DB schema:

Code:
Human(Id, gender, ...)
Man(Id, ...)
Woman(Id, ...)
Where Id is an unique number within the Man/Woman tables, but not unique within Human (Because a man and a Woman might have the same Id).
{Id, gender} is however Unique within Human because no human can have the same Id as another human of the same gender.
How can I create a relationship between Man/Woman and Human. There is a one-to-one relationship between them, but how can I reference the correct tuple within Human, given information from Man. The Id alone is not enough because I might get information about a woman.
Do I need to store gender information within the Man/Woman tables as well? Or is there another way of doing this?
If you have control of the schema then Id should be the unique primary key in each table and then you should have a foreign key in the human' table that matches the primary key (id) in the other tables.

Sent from my SM-G900R4 using Tapatalk
just_grindin is offline   Reply With Quote
Old 10-24-2016, 01:29 PM   #1473
Mavoor
centurion
 
Join Date: Jun 2014
Posts: 150
Re: Programming homework and newbie help thread

How do you create a foreign key that knows which table it should look up against?
An Id can match both tables. The Human table has enough info to know which table it should look up against (gender), but is it possible to define this as part of a db schema?
Mavoor is offline   Reply With Quote
Old 10-24-2016, 02:38 PM   #1474
just_grindin
Pooh-Bah
 
Join Date: Dec 2007
Posts: 4,976
Re: Programming homework and newbie help thread

Quote:
Originally Posted by Mavoor View Post
How do you create a foreign key that knows which table it should look up against?
An Id can match both tables. The Human table has enough info to know which table it should look up against (gender), but is it possible to define this as part of a db schema?
I maybe using the term schema wrong here relative SQL newbie.

I always thought what I described was standard relational data modeling practice. You don't want tables containing duplicate information, especially if it's going to be used to identify the row later (i.e. ids should not be repeated in humans, nor in any other table).

You just define a new column in humans as a foreign key and make sure it matches the Id from the other tables. I think it's relatively easy but not something I could just rattle off because like I said relative newbie and haven't built anything using SQL yet. Pretty small language though and I imagine it wouldn't take long to find it online. I'm sure any number of posters here could tell you outright from memory.
just_grindin is offline   Reply With Quote
Old 10-24-2016, 02:57 PM   #1475
just_grindin
Pooh-Bah
 
Join Date: Dec 2007
Posts: 4,976
Re: Programming homework and newbie help thread

Quote:
Originally Posted by just_grindin View Post
I always thought what I described was standard relational data modeling practice. You don't want tables containing duplicate information, especially if it's going to be used to identify the row later (i.e. ids should not be repeated in humans, nor in any other table).
Just to be a little more clear here I meant that each id within a table should be unique. So no id in each table should be the same and then that would be your primary key to identify a unique dataset in the table.

This then holds true for all tables, but not necessarily across tables, so that the dataset belonging to id 1 in the Humans table can be the same as or different than the dataset belonging to id 1 in the other tables. The foreign key in the humans table is identical to the primary key in the other tables.

You can also insert the primary key of the humans table as foreign keys in the other tables. That way you can query any table and know exactly which record you're looking for.

I'd also be curious why you have 2 separate tables for genders.
just_grindin is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Forum Jump


All times are GMT -4. The time now is 03:46 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright © 2008-2017, Two Plus Two Interactive
 
 
Poker Players - Streaming Live Online