• What Most Schools Don't Teach - Short Film (staring Gaben)
    99 replies, posted
[QUOTE=Protocol7;39763607]you won't be saying that when you're proficient with recursion I wrote this recursive function to transverse an adjacency matrix in like 15 minutes: [cpp]template <typename T> int matrix<T>::solve(int x, int y) { int current_row = x; int current_row_cell = x; int steps = 0; if (this->*grid[x - 1][y - 1] == 1) { steps++; return steps; } else { if (x > y) { --current_row_cell; if (this->*grid[current_row][current_row_cell] == 1) { ++steps; steps += solve(current_row - 1, y); } else return steps; } else if (x < y) { ++current_row_cell; if (this->*grid[current_row][current_row_cell] == 1) { ++steps; steps += solve(current_row + 1, y); } else return steps; } else return 0; return steps; } }[/cpp] it's a little gross because I never bothered to clean it up but you'll see it's very recursive it's all about return cases[/QUOTE] im on video 28 out of 76 of c++ easy spoonfeed, and i think my brain just died reading that. BUT, on a good note, i do unerstand that you are declaring integer variables, and how to use if else statements, and all that. Which, up until a week ago, was complete gobblygook to me. [I]progress[/I]
[QUOTE=account;39766756]Functional languages can help boatloads with understanding recursion[/QUOTE] I find it vastly easier to understand how a recursive function works in Java than in F#.
[QUOTE=alien_guy;39771980]I find it vastly easier to understand how a recursive function works in Java than in F#.[/QUOTE] I don't know about F#, but Haskell has just really simple pattern matching that makes each case obvious
I started wondering why did I stop taking programming classes in my high-school, then I noticed this one. [QUOTE=Protocol7;39763607]you won't be saying that when you're proficient with recursion I wrote this recursive function to transverse an adjacency matrix in like 15 minutes: [cpp]template <typename T> int matrix<T>::solve(int x, int y) { int current_row = x; int current_row_cell = x; int steps = 0; if (this->*grid[x - 1][y - 1] == 1) { steps++; return steps; } else { if (x > y) { --current_row_cell; if (this->*grid[current_row][current_row_cell] == 1) { ++steps; steps += solve(current_row - 1, y); } else return steps; } else if (x < y) { ++current_row_cell; if (this->*grid[current_row][current_row_cell] == 1) { ++steps; steps += solve(current_row + 1, y); } else return steps; } else return 0; return steps; } }[/cpp] it's a little gross because I never bothered to clean it up but you'll see it's very recursive it's all about return cases[/QUOTE] Then I remembered: It's confusing as shit... I still want to re-learn it, though.
It's only confusing because a) you didn't write it yourself, and b) it's complex. Here's some lua code of about the same length from a gmod gamemode of mine. [lua]function V.I.ContainerReset( ent ) if( ent:GetContainer() > 0 ) then V.I.CheckInvent( ent ); if( #ent.Inventory > 0 ) then return end local preset = V.I.ContainerPresets[ent:GetContainer()]; local items = V.I.ContainerPresetItems[ent:GetContainer()]; for i = 1, preset[2] do local a = table.Random( items ); local rarity = a[2]; local c = math.random( 1, rarity ); if( c == rarity ) then V.I.GiveItem( ent, a[1], 1 ); end end end end[/lua] This is what most code looks like that isn't utility functions (for example, finding the transverse of a matrix).
I personally find that recursion makes sense when it's applied to problems that make sense to solve recursively. A lot of explanations to recursion come up with contrived examples.
Is it just me, or do so many freshmen start as Comp Sci majors and almost immediately change to another major? It seems to get a lot of interested students, then they quickly switch majors for one reason or another. That was my experience throughout this past freshman year - so many people started Comp Sci, then said "this isn't for me," and did something else.
Like in the video, yes it would be glamorous working for super rich companies like Valve or Twitter that can piss as much money away as they want on their employees with nice offices (free food, gyms, arcades yada yada "dream job") but they are the elite programmers. Most people who program will end up in shitty office cubicles working over time 24/7 developing some serious back problems. Propaganda video, would like to see the reality of people working as programmers for companies that are not global powers. All those kids who dream of making games when they are older, the turn over rate of programming staff in 90% of the developers is insane, just look at all the people who got the sack recently at Gearbox. I can understand why there will be a shortage of 1 million programmers, it's fucking soul destroying. [video=youtube;Fy3rjQGc6lA]http://www.youtube.com/watch?v=Fy3rjQGc6lA[/video]
[img]http://i.imgur.com/sJg1TfZ.png[/img] [editline]4th March 2013[/editline] I GOT THE MOVES LIKE JAGGER
Sorry, you need to Log In to post a reply to this thread.