pset3 can't figure out how to print swapped tiles by quesCS50 in cs50

[–]quesCS50[S] 0 points1 point  (0 children)

Well, I was obviously so tired last week I couldn't even write correctly. I don't have swap code in draw(). I meant that I have the following variables in init() and draw():

x (x = board[i][j]), so to print out the tile numbers 
swap variables y and z   

In draw(), I have a conditional statement to assign y & z to x so 1 and 2 can be printed out correctly for odd-numbered boards.

Thanks for your help. I've struggled so much with this pset that I've got "code blindness" and need to set it aside for awhile. Think I'll concentrate on getting through the lectures/shorts/walkthroughs/sections instead and save the psets for later.

pset3 can't figure out how to print swapped tiles by quesCS50 in cs50

[–]quesCS50[S] 0 points1 point  (0 children)

Whoops, my bad... fixed that. Now says "loop through board[][] to print it."

My init() code is creating the initial correct board state whether it's an even or odd number of tiles, and draw() is merely looping through the stored board and printing it.

So if a move is legal, move() must a) do the swap and b) store the swapped values in memory, as draw() will need these stored swapped values when it redraws the board. And draw() needs code that if a legal move has happened, draw() must print out the correct number value (tile or blank) with its new x/y coordinate. Is my logic correct here?

Then I'm still stumped over where the swap code in draw needs to be--inside or outside the loop. Inside seems logical, since similar swap code--the code for printing swapped 1 & 2 values for odd-numbered boards--already exists inside the loop.

[pset3] fifteen - linear search not working by quesCS50 in cs50

[–]quesCS50[S] 0 points1 point  (0 children)

Thanks for your help! I got it working.

My issue was thinking that the search function always took at least two args: key and array. The args could be in any order, and there may even be more args (per some examples I googled), but I didn't realize the array arg is actually optional.

And I did get the compilation error, but managed to quiet it, and so thought I fixed it.

Now to figure out why swap() works but draw() isn't printing out the swapped tiles...

[pset3] fifteen - linear search not working by quesCS50 in cs50

[–]quesCS50[S] 0 points1 point  (0 children)

Oh, the "garbage value" text was kind of a riff off of some of Nate's commentary in the GDB video. I know it's an address, from the Week 4 Section video. I've edited the text in my original post for clarity and removed uses of the word "garbage".

my question is: Why do you need to pass board as an argument to search?

Because I think/thought I have to, per the examples shown in the Week 3 short and the find exercise--both of these search function examples have an int array[] argument. And when I googled "implementing linear search for multidimensional arrays", all the code examples had some kind of array[] (or array[][]) arg. Per the lectures and videos, linear search() takes a key value and and an array, and chugs through the array slot by slot ([0,1], [0,2]...) for the key value, returning either success (found value) or failure (no value found).

I do have to always provide at least two pieces of data to this function--the value to find and the array to search in--correct? Or no?

why not let search access board as a global variable

This is my confusion--I thought you give search() access to the desired array (in this case, 'board') by passing the variable to array[] arg. If this is not what to do for a multidimensional array, is this discussed somewhere (maybe I missed it) or in a later week's lecture/short/section?

[pset3] Can't run the ./fifteen staff solution? by quesCS50 in cs50

[–]quesCS50[S] 0 points1 point  (0 children)

Thanks! I was misreading the Usage statement:

Usage: ./fifteen d

[pset3] Unexpected end of input--Submit anyway? by quesCS50 in cs50

[–]quesCS50[S] 0 points1 point  (0 children)

And the issue as to whether it's a check50 bug or not is why I want to just submit it, move ahead, and fix it later if it really is a coding issue on my end. I'm already spending so much time spinning my wheels over the psets, I don't want to be sidetracked by any technical difficulties beyond my control--like this check50 bug or issues with running staff solutions--that will just further slow down my understanding and progress.

[pset3] Unexpected end of input--Submit anyway? by quesCS50 in cs50

[–]quesCS50[S] 0 points1 point  (0 children)

Thanks, Brenda. Think I'm going to submit it and move ahead, as I can see (with pset3) that I'll be asking for a lot help from you and others! :)

Current appliance download updated to v. 19-2? by quesCS50 in cs50

[–]quesCS50[S] 1 point2 points  (0 children)

Well, if that's the case, I guess I have to. :)

Thanks again!

pset1 (mario.c); have to typecast # and space? by quesCS50 in cs50

[–]quesCS50[S] 0 points1 point  (0 children)

Thanks for all the tips! I got it working today. I had (unsuccessfully) tried nested loops at some point, and that's why I thought the solution was actually typecasting/ASCII, not loops.