The Official Programming Thread

Fate

-
Aug 21, 2015
61
0
0
Karachi
I'm also starting Uni so I thought I'd do some learning myself. I already know HTML and CSS a bit, but like Eternal Blizzard said they're a little different from actual programming languages. So I picked up C# a week ago and am currently practicing on C# on Visual Studio.

What books do you guys read for programming? Where can I find some good ones in Karachi?
 

EternalBlizzard

Lazy guy :s
Moderator
Oct 29, 2011
2,732
1,195
129
Attractor Field Beta
Nice share mate.

Currently learning c++ myself with the help of a good book and doing practice programs.

Where are you learning it from ?

Sent from my SM-G935F using Tapatalk
OOP in C++ by Robert Lafore for programming concepts such as inheritance/polymorphism etc. Other than that i just think of a program and start making it in the language i am currently learning. Open up the C++ reference to find the list of functions i can use and just start making my program.

@Fate
for C# check Rob Miles Yellow Book and Microsoft Visual C# Step by Step by John Sharp for some in depth details such as boxing/unboxing and garbage collector.
 

staticPointer

PG LEGENDARY
Dec 7, 2012
3,266
0
41
افغانستان
www.pakgamers.com
OOP in C++ by Robert Lafore for programming concepts such as inheritance/polymorphism etc. Other than that i just think of a program and start making it in the language i am currently learning. Open up the C++ reference to find the list of functions i can use and just start making my program.

@Fate
for C# check Rob Miles Yellow Book and Microsoft Visual C# Step by Step by John Sharp for some in depth details such as boxing/unboxing and garbage collector.

hey man.. i have an image fb but its url is expired.. any way to restore it??? its image btw

check :
Code:
https://scontent-cdg2-1.xx.fbcdn.net/v/t1.0-9/63402_10151509531634754_1048725560_n.jpg?oh=05539b0bde4e400ffafbb7bff409f2cf&oe=57B1E8AC
 

Newton

Well-known member
May 17, 2009
2,223
0
41
Lahore, Faisalabad
i thought we could use only 1 loop. to keep O ( n )

you are nesting loops here. can i nest loops?
 
Last edited by a moderator:

EternalBlizzard

Lazy guy :s
Moderator
Oct 29, 2011
2,732
1,195
129
Attractor Field Beta
I'm trying to use Eternal Blizzards approach over here. Just can't figure out how to code it up.
you could make 1 for loop that iterates over all the coordinates. Make a variable that holds the starting coordinate and a variable that hold this index. Iterate over the array finding slopes between the selected starting coordinate and others. Then make a check at the end if iteration has reached the last element. If it has do a ++ in your starting coordinate index so that it is now the 2nd element. Reset the iteration variable to the starting coordinate index + 1 ( we don't need to find slope between 2nd and 1st as it has already been found the first time). That's what i can think of without nested loops.
 

Newton

Well-known member
May 17, 2009
2,223
0
41
Lahore, Faisalabad
you could make 1 for loop that iterates over all the coordinates. Make a variable that holds the starting coordinate and a variable that hold this index. Iterate over the array finding slopes between the selected starting coordinate and others. Then make a check at the end if iteration has reached the last element. If it has do a ++ in your starting coordinate index so that it is now the 2nd element. Reset the iteration variable to the starting coordinate index + 1 ( we don't need to find slope between 2nd and 1st as it has already been found the first time). That's what i can think of without nested loops.
wouldnt that make it a O ( n*n ) algorithm?
 

Ali Man

Devilz Mafia
Oct 1, 2008
4,955
1
43
Islamabad
you could make 1 for loop that iterates over all the coordinates. Make a variable that holds the starting coordinate and a variable that hold this index. Iterate over the array finding slopes between the selected starting coordinate and others. Then make a check at the end if iteration has reached the last element. If it has do a ++ in your starting coordinate index so that it is now the 2nd element. Reset the iteration variable to the starting coordinate index + 1 ( we don't need to find slope between 2nd and 1st as it has already been found the first time). That's what i can think of without nested loops.
You're saying that the array would be inside the for loop?
I'm still trying to understand how you would calculate the sloop e.g. using y = mx + c
 

EternalBlizzard

Lazy guy :s
Moderator
Oct 29, 2011
2,732
1,195
129
Attractor Field Beta
wouldnt that make it a O ( n*n ) algorithm?
Yar i still don't know how this complexity thing works. If you just have to avoid nested for loops you can reset ur iteration variables at the end of the for loop to make it serve as a nested loop. Does this reduce the complexity? Other wise i would've put that for loop i mentioned inside a while loop. It would do the same work, and save me from the work of resetting iteration variables

@Ali Man
Yes the array will be inside a single for loop. In order to advance our current selected coordinate and iterate over the whole array again and again, you need to reset the iteration variables and update the selected coordinate when the iteration variable reaches the end.
calculate slope using y2-y1/x2-x1 where y is column and x is row. take its arc tangent to get theta


EDIT:-
Wait i get it.. so O( n )means you can only iterate it n times. doesn't mean if you use nested loops or not. Well if that's the case i can't think of any other solution. I don't think you can determine in 1 go whether all the queens intersect any other queen or not.
 
Last edited:

Newton

Well-known member
May 17, 2009
2,223
0
41
Lahore, Faisalabad
Another way is as follows
the board has N rows, N columns and N+N-1 diagonals

Code:
int rowAttack[N];
int colAttack[N];
int diaAttack[N+N-1]


for (all queens)
{
   rowAttack[queen.X] = 1; //keeps a record which row has a queen when another queen comes break the loop
   colAttack[queen.Y] = 1; //keeps a record which column has a queen when another queen comes break the loop
   diaAttack[diagonal number] = 1; //keeps a record which diagonal has a queen when another queen comes break the loop
}
you will need to figure out how to check the diagonal number. the coordinates will help you in doing that.

when i say rows i mean all boxes in a horitonal line like this _
when i say columns i mean all boxes in a verticle line like this |
when i say diagonals i mean all boxes in an inclined diagonal like this /
 
General chit-chat
Help Users
We have disabled traderscore and are working on a fix. There was a bug with the plugin | Click for Discord
  • No one is chatting at the moment.
    faraany3k faraany3k: Tears of Kingdom saal pehle shuru ki thee, ab tk pehle area se nai nikla. Life sucks donkey balls.