Page 2 of 2 [ 29 posts ]  Go to page Previous  1, 2

Spudz76
Tufted Titmouse
Tufted Titmouse

User avatar

Joined: 18 Aug 2009
Age: 48
Gender: Male
Posts: 41

19 Nov 2013, 5:04 pm

Thanks for the backup on Javascript. Much of the erroneous code snippets out there are simply trying to force an asynchronous event-based language to be synchronous and more linearly predictable, which is an instant red-flag of a bad example. However once you get used to the "callback" nature of things you will wonder why anyone uses synchronous languages. It's more like delegating tasks to workers and letting them get back to you with the result (things might happen out of order, but you just set up a function to receive the result(s) from source(s) and have it continue processing once the "packages are all delivered"), than micro-managing them through the entire process (terse, rigid, ultimately predictable flow). Of course a multi-lane highway of processing is tougher to "wrap your head around" and control than a single lane one-way road, but which one gets there first? Always, the highway. The "exit" or final result would be at the bottom (top? if you consider it as "bubbling up" instead of "funneling down") of the nest of callbacks, somewhere in the middle of the code, rather than at the very end. If you poison yourself with sequential/synchronous languages now, it will only be tougher to grasp the asynchronous stuff later (and since browsers use it... you'll never avoid it).



superluminary
Toucan
Toucan

User avatar

Joined: 4 Nov 2013
Age: 49
Gender: Male
Posts: 274

20 Nov 2013, 5:09 am

enigmeow wrote:
chapter 1, programming c++
chapter 2, social engineering and manipulating the people around you...


Chapter 3. Introduction to automated robotic weaponry
Chapter 4. Bunker hacking for beginners.



Kurgan
Veteran
Veteran

User avatar

Joined: 6 Apr 2012
Age: 36
Gender: Male
Posts: 4,132
Location: Scandinavia

20 Nov 2013, 3:24 pm

ruveyn wrote:
khaoz wrote:
I have been trying for months to learn code at code academy Python), but just cannot seem to grasp it. I think it is an issue of not understanding when to put something in quotation marks or in parenthesis. Whatever it is, I just cant figure it out. Its making me feel like I have the IQ of a street lamp, but seriously, it cant be THAT hard.

what am I doing wrong? Anyone can help me understand this better?


Python, or C, or PERL are languages. They are no substitute for learning the basic underlying logic and theme of this or that particular algorithm.

Without resorting to a programming language tell me how to sort a deck of cards first by suit and then by rank within suite, King high Ace low.

ruveyn


C is a pain in the ass to use without classes and objects, though. :P



ruveyn
Veteran
Veteran

User avatar

Joined: 21 Sep 2008
Age: 88
Gender: Male
Posts: 31,502
Location: New Jersey

20 Nov 2013, 5:11 pm

You haven't done the exercise I suggested. If you can tell me how to sort a pack of cards in plain words, then you can code in ANY fancy computer language.



Kurgan
Veteran
Veteran

User avatar

Joined: 6 Apr 2012
Age: 36
Gender: Male
Posts: 4,132
Location: Scandinavia

20 Nov 2013, 5:37 pm

This is really no big deal, if you mean sorting them by value. In non-object oriented languages, you create a struct with the desired attributes. You then add them to an array (or a datastructure like an ArrayList or a LinkedList) and sort them with qsort(). In an object oriented language, swap the struct for a class instead.

In a non-object oriented language, it's time consuming compared to an object-oriented language, though.



aaronzx
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 21 Nov 2013
Age: 33
Gender: Male
Posts: 66
Location: Australia

26 Nov 2013, 3:44 am

try Khan academy. They also have Python tutorials now.

https://www.khanacademy.org/science/com ... er-science

I haven't tried these videos yet but for other topics I really find Khan's explanations to the point.



kx
Emu Egg
Emu Egg

User avatar

Joined: 27 Nov 2013
Gender: Female
Posts: 5

29 Nov 2013, 12:39 am

The Pragmatic Programmers have published a book called "Learn To Program", which teaches the basic ideas of programming using Ruby. It doesn't really matter that it's Ruby -- once you understand the basic idea, it applies to a lot of languages, including Perl, Python, Java, PHP, C#, C++, Go, JavaScript, etc. Each language has quirks and their strengths lie in different areas, and there will be other concepts that you'll need to learn, but understanding the building blocks will take you a long way.

You can buy the book anywhere, but there's also an earlier version available on for free on the author's website (google chris pine learn to program).

I really like exercism.io, because it gives you an automated test suite that tells you when your code works, and then people help you improve the code by discussing other ways of doing things, or how to make your code more idiomatic in the language you're working in. They have Python, Ruby, JavaScript, and several other languages available. I learn a lot from the discussions there, and it seems like it caters both to beginners (because people help you figure out how to get better and learn stuff) and experienced programmers (because they get to discuss best practices and trade-offs).

I've heard really good things about teamtreehouse but I've never used it myself.



wbport
Sea Gull
Sea Gull

User avatar

Joined: 16 Sep 2012
Gender: Male
Posts: 222

01 Dec 2013, 8:36 pm

I would also suggest something like Javascript since you don't need to buy a compiler, but you do need to buy a book--looking up every new topic on line gets be be old in a hurry.

You might be able to learn from other websites or other coders/programmers. If you are interested in how round robins work, you can go to Round Robin Scheduling and press Cntl/U (most browsers) to see the code behind the Cyclic algorithm demonstrator, but if you are interested in White and Black (rather than shades of pink/red) or Home and Away or in "seating" the players so they will be meet their opponents in order, it is much easier to modify existing code than to start from scratch. There are also forums to answer questions such as Javascript Forum, but lurk before posting.

As for sorting a deck of cards:
In an outer loop, vary subscript i from 1 to 51 and
in the inner loop, vary subscript j from i + 1 to 52
if deck[j] < deck[i]
move deck[i] to temp-area
move deck[j] to deck[i]
move temp-area to deck[j]
end-if
end-inner-loop
end-outer-loop

Of course, the syntax would depend on the language and subscripts may start at zero instead of one.

Oops, I just did a print preview and my indentions were blown away. Indent everything from-to-and including word "inner" by two. Indent everything from-to-and including word "if" by two more. Finally, the "move" statements go in two more characters.



Kurgan
Veteran
Veteran

User avatar

Joined: 6 Apr 2012
Age: 36
Gender: Male
Posts: 4,132
Location: Scandinavia

02 Dec 2013, 4:06 am

wbport wrote:
I would also suggest something like Javascript since you don't need to buy a compiler, but you do need to buy a book--looking up every new topic on line gets be be old in a hurry.

You might be able to learn from other websites or other coders/programmers. If you are interested in how round robins work, you can go to Round Robin Scheduling and press Cntl/U (most browsers) to see the code behind the Cyclic algorithm demonstrator, but if you are interested in White and Black (rather than shades of pink/red) or Home and Away or in "seating" the players so they will be meet their opponents in order, it is much easier to modify existing code than to start from scratch. There are also forums to answer questions such as Javascript Forum, but lurk before posting.

As for sorting a deck of cards:
In an outer loop, vary subscript i from 1 to 51 and
in the inner loop, vary subscript j from i + 1 to 52
if deck[j] < deck[i]
move deck[i] to temp-area
move deck[j] to deck[i]
move temp-area to deck[j]
end-if
end-inner-loop
end-outer-loop

Of course, the syntax would depend on the language and subscripts may start at zero instead of one.

Oops, I just did a print preview and my indentions were blown away. Indent everything from-to-and including word "inner" by two. Indent everything from-to-and including word "if" by two more. Finally, the "move" statements go in two more characters.


You algorithm has a running time of O(n^2). By comparison, this has a running time of O (n log n):

public static void quicksort(Comparable[] a) {
quicksort(a, 0, a.length - 1);
}
private static void quicksort(Comparable[] a, int low, int high) {
if (low + CUTOFF > high)
insertionSort(a, low, high);
else {
int middle = (low + high) / 2;
if (a[middle].compareTo(a[low]) < 0)
swapReferences(a, low, middle);
if (a[high].compareTo(a[low]) < 0)
swapReferences(a, low, high);
if (a[high].compareTo(a[middle]) < 0)
swapReferences(a, middle, high);
swapReferences(a, middle, high - 1);
Comparable pivot = a[high - 1];
int i, j;
for (i = low, j = high - 1;;) {
while (a[++i].compareTo(pivot) < 0);
while (pivot.compareTo(a[--j]) < 0);
if (i >= j)
break;
swapReferences(a, i, j);
}

swapReferences(a, i, high - 1);
quicksort(a, low, i - 1); // Sort small elements
quicksort(a, i + 1, high); // Sort large elements
}
}
public static final void swapReferences(Object[] a, int i, int j) {
Object tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}

(Just don't place the pivot at the edges, in which case this is an O(n^2) operation as well. :P)



kx
Emu Egg
Emu Egg

User avatar

Joined: 27 Nov 2013
Gender: Female
Posts: 5

02 Dec 2013, 7:07 am

wbport wrote:
I would also suggest something like Javascript since you don't need to buy a compiler


Most of the languages you will come across these days are free to use, even the ones that require a compiler. C, C++, JavaScript, Java, PHP, Ruby, Python, Go, Haskell, Scala, Clojure, Elixir, Erlang, Rust, are all free. Even the C# compiler is free, though the programming environment (Visual Studio) is not.



Last edited by kx on 02 Dec 2013, 7:57 am, edited 1 time in total.

wbport
Sea Gull
Sea Gull

User avatar

Joined: 16 Sep 2012
Gender: Male
Posts: 222

02 Dec 2013, 7:24 am

Kurgan wrote:
wbport wrote:
I would also suggest something like Javascript since you don't need to buy a compiler, but you do need to buy a book--looking up every new topic on line gets be be old in a hurry.

You might be able to learn from other websites or other coders/programmers. ..snip...

As for sorting a deck of cards:
In an outer loop, vary subscript i from 1 to 51 and
in the inner loop, vary subscript j from i + 1 to 52
..snip for brevity...


You algorithm has a running time of O(n^2). By comparison, this has a running time of O (n log n):
[b]
public static void quicksort(Comparable[] a) {
quicksort(a, 0, a.length - 1);
.. snip whatever ...


Yea, Yea. My career was as a programmer and I know a number of ways to sort. My example was aimed at beginners or the OP, "straight from Intro to Computers 101". Pay attention to your audience and who is in it.



MCalavera
Veteran
Veteran

User avatar

Joined: 15 Dec 2010
Gender: Male
Posts: 5,442

02 Dec 2013, 10:46 am

No one mentioned Udacity?



Kurgan
Veteran
Veteran

User avatar

Joined: 6 Apr 2012
Age: 36
Gender: Male
Posts: 4,132
Location: Scandinavia

02 Dec 2013, 10:48 am

kx wrote:
wbport wrote:
I would also suggest something like Javascript since you don't need to buy a compiler


Most of the languages you will come across these days are free to use, even the ones that require a compiler. C, C++, JavaScript, Java, PHP, Ruby, Python, Go, Haskell, Scala, Clojure, Elixir, Erlang, Rust, are all free. Even the C# compiler is free, though the programming environment (Visual Studio) is not.


If you're a student, Microsoft gives it away for free. I got both Visual Studio 2013, Windows 7 and Windows Server 2008 for free via DreamSpark.