Open Side Menu Go to the Top

04-22-2012 , 07:26 PM
Quote:
Originally Posted by clowntable
Well recursion is just "split a task into repeatable steps and know when you're done". Conceptually that's pretty easy as well and actually pretty similar to loops except that your shifitng the focus to what the actions/end conditions are and not how often they are repeated (imo).
The dragon story teching recursion from whatever that Lisp book I read it in is pretty good imo

I feel like this should be tested on some people that have never programmed before. Teach half of them recursion and the other half loops and then let them figure out the other one later and see who struggles more or something.

Edit: pretty much what gaming_mouse said
The closest I can come is that I TA'd both a first year university CS class that taught students Java and one that taught students Scheme. Even among students with no programming background there were definitely fewer questions understanding loops in the Java class than there were questions understanding recursion in the Scheme class.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
04-22-2012 , 07:29 PM
jj,

do you have a phd in cs?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 07:48 PM
There is a software program for the card game bridge.

It saves "deals" as .ppl file extensions. I would like to import these deals into my own flashcard type training program but I am not sure how to get this in a usable format. Is there any way to figure out or convert this file type to something usable?

Thanks
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 08:00 PM
Short answer. Yes.

Longer answer: it depends on what format the files are in. What do the files look like if you open them in a text editor? If they're in plain text it'll be relatively straightforward. If they're binary it's probably going to be much tougher.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 08:02 PM
Quote:
Originally Posted by Neko
Short answer. Yes.

Longer answer: it depends on what format the files are in. What do the files look like if you open them in a text editor? If they're in plain text it'll be relatively straightforward. If they're binary it's probably going to be much tougher.
It's pretty much gibberish.

Spoiler:
andy K  $ 0 à€ €h
 H   55555555555555555555555555555555555555555555555555 55 ÿÿÿ
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 08:07 PM
I would send an email to the company that produces the program and ask if they'll provide you with the file format specification...otherwise you're going to be stuck trying to reverse engineer it which can be pretty tough.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 08:32 PM
what about ifstream with the binary flag on? (shot in the dark from a noob)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 09:04 PM
Quote:
Originally Posted by gaming_mouse
jj,

do you have a phd in cs?
Nope. I thought about it (actually I thought about getting a Masters, I only have my Bachelors degree) but once I got use to the pay of a real job I never really looked back.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 09:56 PM
Quote:
Originally Posted by Neko
Try breaking up the problem into smaller bits. First write a function:

Code:
f :: Eq a => a -> [a] -> [a]
f a xs = ????
so that

f "b" "aaba" gives "aaa"

Once you've got that working your problem just becomes a matter of applying that function to a list of inputs.
this is really annoying me (sorry for tarding this thread up with haskell problems!)

so obv what you said there working on one list is

Code:
r1:: Eq a => a -> [a] -> [a]
r1 n [] = []
r1 n (x:xs) | x /= n = x : r1 n xs
                | otherwise = r1 n xs
but working on two list is annoying me! i thought it would be something like

Code:
r1:: Eq a => a -> [[a]] -> [[a]]
r1 n [] = []
r1 n (x:xs) | x /= n = r1 n x : r1 n xs
                | otherwise = r1 n xs
thought this would take the head of the first list. if it doesnt equal n, then it would look in the list of the head and check whether the values equals to n or not. And does this for each individual list. but apparently not =/
This is seriously frustrating me so much! should be so easy aswell!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 10:28 PM
Quote:
Originally Posted by Burnss
this is really annoying me (sorry for tarding this thread up with haskell problems!)

so obv what you said there working on one list is

Code:
r1:: Eq a => a -> [a] -> [a]
r1 n [] = []
r1 n (x:xs) | x /= n = x : r1 n xs
                | otherwise = r1 n xs
but working on two list is annoying me! i thought it would be something like

Code:
r1:: Eq a => a -> [[a]] -> [[a]]
r1 n [] = []
r1 n (x:xs) | x /= n = r1 n x : r1 n xs
                | otherwise = r1 n xs
thought this would take the head of the first list. if it doesnt equal n, then it would look in the list of the head and check whether the values equals to n or not. And does this for each individual list. but apparently not =/
This is seriously frustrating me so much! should be so easy aswell!
Code:
r1:: Eq a => a -> [a] -> [a]
r1 n [] = []
r1 n (x:xs) | x /= n = x : r1 n xs
                | otherwise = r1 n xs
Assuming that part works then you've already finished the hardest part! Now you can just do:

Code:
r2 n [] = []
r2 n (xs:xss) = r1 n xs : r2 n xss
or using a list comprehension:

Code:
r2 n xss = [r1 n xs | xs <- xss]
The idea being that you start by creating functions that do isolated bit of the problem and use those little functions to compose bigger functions.

So your r1 n xs performs the meat of the problem (i.e. removing the unwanted elements from a list), and then you just use r2 to apply r1 to each sublist within your list.

edit: I'm sure it can be done in just one function, but splitting it up like this makes it easier to comprehend imo!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 10:37 PM
Quote:
Originally Posted by tyler
from xhad import fib
lol, one reason I haven't uploaded a lot of my solutions to MrWooster's github is because I'm already doing this with my prime sieve and some related stuff

Quote:
Originally Posted by NoahSD
http://en.wikipedia.org/wiki/Fibonac...orm_expression I think there might be some even faster methods as well.
FWIW I've known about Binet's Formula for years; I only made it fibonacci because that's what we were talking about, but PE has plenty of problems like this where my solution really was just "figure out how to memoize the brute force solution"

Quote:
Originally Posted by tyler
Reason: trying to decide if passing in cache when calling fib(n-k) is desirable and/or if python scoping weirdness fixes that
I'm not 100% certain on this, but I think the default parameters are just sitting in a common dictionary so the cache isn't actually passed except by reference. This is the same reason for that "mutable defaults wat" discussion we had in this thread awhile back. (try running my fib function on a value > 1, then check the value of fib.__defaults__)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-22-2012 , 10:59 PM
Quote:
Originally Posted by jjshabado
The closest I can come is that I TA'd both a first year university CS class that taught students Java and one that taught students Scheme. Even among students with no programming background there were definitely fewer questions understanding loops in the Java class than there were questions understanding recursion in the Scheme class.
Isn't this a little unfair?

I'm not well-versed in Java, but I know it has various looping constructs built-in: while, do-while, for, etc, right?

Assuming you used R6RS and not PLT/Racket, Scheme has no looping constructs built in. Well, you can argue that the R6RS built-in for-each is a looping construct, but I would respectfully disagree.

In most (used?) languages, there is a specific and non-ambiguous LOOP-style construct, whereas in Scheme, the idea of iteration is visibly implemented by adding a counter variable in some nested or helper function, and if you don't get that small piece of the puzzle, you're likely to think of it as just another form of recursion. Why? Because recursion can easily be generically defined as "calling a function over and over" but alas, to make iteration in Scheme, you are "calling a function over and over." In Python, at least, the generic definition holds true. Can you make a recursive function that is actually iterative in Python? Sure, but the details of that is abstracted away so you only have to use the built-in looping constructs so that sticking to the generic definition and surely there is no issue with this in Python, thus in most cases: "Loop == iteration" and "Call function over and over == recursion" is true and true.

This little difference is where Scheme, as a learning language, expresses it's power if you approach the language as it is presented in SICP: data and procedures begin to intermix and the lines start to blur, and small decisions, though visually not apparent, can radically change the power and expressiveness of what you are building.

Each language is equally expressive if you understand the code, the catch is understanding the code.

Visually, this is much easier to understand, using Python:

Code:
def my_fun(x)
    for i in range(x):
        <procedure>

def my_recursion(x)
    return my_recursion(<new variable>)
...vs. Scheme, where if you can easily get the confusion that the nested function is a sign of iteration, and that, of course, isn't true:

Code:
(define (my-fun x)
    (define (helper-fun x counter)
         helper-fun <procedure> <new counter variable>)
    (helper-fun x 10))

(define (my-recursion x)
     (<procedure> <variable?> (my-recursion <procedure>)))

;;or

(define (my-recursion x)
     (define (helper-fun x)
         (<procedure> <variable?> (helper-fun <procedure>)))
    (helper-fun x))

In the Python code, there is absolutely no confusion of what is going on in the code, and I imagine that the same holds for Java.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-23-2012 , 02:43 AM
This is my first attempt at Astar... I'm using the Manhattan heuristic and im not using any diagonal tiles and this is what it looks like... Does this look right?

The white is start, red is end, blue is on the open list and grey is on the closed list and black is unwalkable/blocked. I think something is wrong...
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-23-2012 , 03:30 AM
edit: never-mind I found the problem. I had
int HCost = (RowsTraveled+ColumnsTraveled)*10; and changed it to
int HCost = (RowsTraveled*10)+(ColumnsTraveled*10);
sigh
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-23-2012 , 06:15 AM
Quote:
Originally Posted by daveT
Isn't this a little unfair?
It's an anecdote and obviously lol, small sample size. But it was somewhat relevant so I shared it. I have no idea how that can be unfair.

Quote:
Originally Posted by daveT
I'm not well-versed in Java, but I know it has various looping constructs built-in: while, do-while, for, etc, right?

Assuming you used R6RS and not PLT/Racket, Scheme has no looping constructs built in. Well, you can argue that the R6RS built-in for-each is a looping construct, but I would respectfully disagree.

In most (used?) languages, there is a specific and non-ambiguous LOOP-style construct, whereas in Scheme, the idea of iteration is visibly implemented by adding a counter variable in some nested or helper function, and if you don't get that small piece of the puzzle, you're likely to think of it as just another form of recursion. Why? Because recursion can easily be generically defined as "calling a function over and over" but alas, to make iteration in Scheme, you are "calling a function over and over." In Python, at least, the generic definition holds true. Can you make a recursive function that is actually iterative in Python? Sure, but the details of that is abstracted away so you only have to use the built-in looping constructs so that sticking to the generic definition and surely there is no issue with this in Python, thus in most cases: "Loop == iteration" and "Call function over and over == recursion" is true and true.

This little difference is where Scheme, as a learning language, expresses it's power if you approach the language as it is presented in SICP: data and procedures begin to intermix and the lines start to blur, and small decisions, though visually not apparent, can radically change the power and expressiveness of what you are building.

Each language is equally expressive if you understand the code, the catch is understanding the code.

Visually, this is much easier to understand, using Python:

Code:
def my_fun(x)
    for i in range(x):
        <procedure>

def my_recursion(x)
    return my_recursion(<new variable>)
...vs. Scheme, where if you can easily get the confusion that the nested function is a sign of iteration, and that, of course, isn't true:

Code:
(define (my-fun x)
    (define (helper-fun x counter)
         helper-fun <procedure> <new counter variable>)
    (helper-fun x 10))

(define (my-recursion x)
     (<procedure> <variable?> (my-recursion <procedure>)))

;;or

(define (my-recursion x)
     (define (helper-fun x)
         (<procedure> <variable?> (helper-fun <procedure>)))
    (helper-fun x))

In the Python code, there is absolutely no confusion of what is going on in the code, and I imagine that the same holds for Java.
Dave - I don't know if I'm understanding your point. But I was actually comparing Java For-Loop students to Scheme Recursion students (and not Java Recursion to Scheme Iteration or anything like that).

But compare:

Code:
def palindrome(myString):
    print(myString)
    if len(myString) == 0 or len(myString) == 1:
        return True
    elif myString[0] == myString[-1]:
        return palindrome(myString[1:-1])
    else: return False
Code:
def palindrome(s):
    s_len = len(s)
    for i in range(s_len / 2): 
        if (s[i] != s[s_len - 1 - i]):
            return False
    return True
First, notice that its really no worse than a recursive version. I prefer the recursive version but the iterative version is by no means horrible.

Second, and back to my original point, in the iterative version every variable name refers to only one variable and at any point in time there's only one value for that variable. In the recursive version you have to realize that each execution of the function creates a new instance of myString. For most of us thats not really complex but in my experience its definitely harder for new programmers to grasp.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-23-2012 , 11:08 AM
Quote:
Originally Posted by Ryanb9
This is my first attempt at Astar... I'm using the Manhattan heuristic and im not using any diagonal tiles and this is what it looks like... Does this look right?

The white is start, red is end, blue is on the open list and grey is on the closed list and black is unwalkable/blocked. I think something is wrong...
While not really helping with your problem this was posted on HN recently...pretty fun to play around with:
http://qiao.github.com/PathFinding.js/visual/
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-23-2012 , 12:06 PM
Quote:
Originally Posted by Ryanb9
edit: never-mind I found the problem. I had
int HCost = (RowsTraveled+ColumnsTraveled)*10; and changed it to
int HCost = (RowsTraveled*10)+(ColumnsTraveled*10);
sigh
distributive property for the w--wait, what?

Last edited by tyler_cracker; 04-23-2012 at 12:07 PM. Reason: iow, i don't think you found the problem
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-23-2012 , 12:20 PM
Short notice, but I just accepted a speaking slot at the HN meetup this Thursday in London, if anyone is around and wants to meetup let me know and I will buy you a drink

I'm quite nervous about it lol!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-23-2012 , 04:26 PM
Quote:
Originally Posted by Gullanian
Short notice, but I just accepted a speaking slot at the HN meetup this Thursday in London, if anyone is around and wants to meetup let me know and I will buy you a drink

I'm quite nervous about it lol!
Huge congrats!! What are you talking about? Guessing its about your company, but any area in particular?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-23-2012 , 05:04 PM
Quote:
Originally Posted by tyler_cracker
distributive property for the w--wait, what?
LOL.
What it was was when I had the same F score. I added a tie breaker so if two have the same F score, I use the one with the lowest HCost. Im surprised how well A* works for how simple it is.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-23-2012 , 05:17 PM
Quote:
Originally Posted by MrWooster
Huge congrats!! What are you talking about? Guessing its about your company, but any area in particular?
Still preparing it, I think it's going to be on our startup briefly (ofc) but careful to not turn the whole thing into an advertisement, as well as why HTML5 is the future along with lessons learnt from running our startup.

It's a 10 min talk with 5 mins of questions, I'm a bit nervous about it as my brother is at DevCon5 this week so I'm soloing it, hopefully don't get asked too many difficult questions about the software itself!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-23-2012 , 05:17 PM
Quote:
Originally Posted by clowntable
While not really helping with your problem this was posted on HN recently...pretty fun to play around with:
http://qiao.github.com/PathFinding.js/visual/
Thanks that jump point looks amazing im going to try that next.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-23-2012 , 05:31 PM
Quote:
Originally Posted by clowntable
While not really helping with your problem this was posted on HN recently...pretty fun to play around with:
http://qiao.github.com/PathFinding.js/visual/
this is great
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-23-2012 , 06:54 PM
Quote:
Originally Posted by Gullanian
Still preparing it, I think it's going to be on our startup briefly (ofc) but careful to not turn the whole thing into an advertisement, as well as why HTML5 is the future along with lessons learnt from running our startup.

It's a 10 min talk with 5 mins of questions, I'm a bit nervous about it as my brother is at DevCon5 this week so I'm soloing it, hopefully don't get asked too many difficult questions about the software itself!
What's your company?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-23-2012 , 07:14 PM
Gull + Brother are www.scirra.com, html5+ game creation program
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m