Questions tagged [pset3]

The problem set for Week 3 asks students to write code for a classic puzzle game in the C programming language.

Filter by
Sorted by
Tagged with
0
votes
0answers
80 views

Why won't my won function return true?

I'm having an issue my won function to return true. When I use the 3x3.txt file I get an Illegal Move message when won should return true. Not really sure what I'm missing here. Here is my code: ...
0
votes
2answers
197 views

All my moves entered are shown illegal, though code doesn't seem wrong… (PS3 - fifteen)

I have checked draw() and init() and they seem to be right. However, the problem lies with the move() portion of the code. After I run the code, every move entered is named Illegal.... I have no clue ...
1
vote
4answers
458 views

Pset3 fifteen.c - Move function allows invalid moves

To implement the move() function I divided it into three functions, one to find the tile inputted by the user, one to check if the move is legal, and one to actually move the tiles. At first it looked ...
0
votes
1answer
114 views

Why my won routine does not return true even if the game is completed?

I've been struggling with the final stage of fifteen programming. So far up to move, my coding is working OK. In my 'won' routine, I'm checking all of the tiles are in the ascending order. The blank ...
0
votes
2answers
3k views

Pset 3 - Find and Helper.C

Question about find and helpers.c. When I run check50 on my code, I get the following error below: :( doesn't find 42 in {39,40,41} \ expected an exit code of 1, not 0 :( doesn't find 42 in {39,...
0
votes
0answers
135 views

I can't get search to work when value == value[n]

I'm trying to implement a recursive binary search in helpers.c. When checking my code with check50, everything works except: :( finds 42 in {40,41,42} :( finds 42 in {39,40,41,42} So obviously ...
0
votes
2answers
420 views

pset3, move function

Here's my move function. The problem here is i know im not following the instructions. Because i don't understand why do i need to track and how to track the blank tile. My function works as expected. ...
1
vote
1answer
229 views

Global variables to store the position of the blank space?

I tried to implement a leftward movement in game of 15. I encountered a problem. The program can only call move function once and it doesn't work after that. I use 0 to as the representation for the ...
0
votes
2answers
149 views

Selection sort does not sort the unsorted portion once no swapping position is reached?

I've been struggling with this bug for almost 2 days, but so far no success. If anyone could point out what is wrong with my code, I would appreciate it very much. Using my own random numbers (100, ...
0
votes
1answer
190 views

Trouble with binary search

Using gdb, I found the problem is when the left_values is not there because if I try print left_values right after declaring it, it tells me No symbol "left_values" in current context. after ...
0
votes
1answer
362 views

Got an expected expression error on strlen ( values[] )

I'm working on CS50 pset3 helpers.c, trying to implement my own search algorithm (first TODO in the helpers) like the following: Make helpers came back with the following error message. Values[] is ...
0
votes
2answers
669 views

What's wrong with this binary search implemented using recursion?

This is pset3 and I've tried making it work for numerous hours. It always returns false whether the 'needle' is found in the 'haystack' of arrays or not. When typing this in the command window: ./...
0
votes
1answer
98 views

Values for tile locations are 0 in gdb

I'm not getting whats going wrong with my move and draw functions. When I trace the program through gdb I'm getting the 0 values for tile locations.
0
votes
1answer
290 views

Cannot implement swap function for fifteen pset3

I managed to write a swap function before attempting "fifteen" , but within the context of writing the "move" function, I just can't get it to work, despite following the same format. When I swap, it ...
0
votes
1answer
334 views

pset-3 move function

bool move(int tile) { int hold; for(int i=0 ; i < d ; i++) { for(int j=0; j<d; j++) { if(board[i][j] == tile) { ...
0
votes
1answer
58 views

pset3 - fifteen - /move - trouble moving the largest number

So, I can locate the blank tile and the called number to swap, swap them (although through a number of steps), and then print the new board. The problem arises when I move the largest number. The ...
0
votes
1answer
157 views

pset3- fifteen printing _

void init(void) { int i,j; for(i=0 ; i < d ; i++) { for (j=0 ; j < d ;j++) { do { board[i][j] = GetInt(); if(...
0
votes
0answers
1k views

What does clang's “undefined reference” error mean?

What do the following compilation errors mean and how can I fix them? jharvard@appliance (~/Dropbox/pset3/find): make helpers clang -ggdb3 -O0 -std=c99 -Wall -Werror helpers.c -lcs50 -lm -o ...
2
votes
1answer
147 views

check50 error: CERT_HAS_EXPIRED

I'm using check50 to check my linear search algorithm in pset3, and it doesn't seem to be uploading or checking at all. Instead I get the message: Uploading.. CERT_HAS_EXPIRED and the second time: ...
0
votes
1answer
80 views

`./generate 1000 50` generates different list of numbers for pset3

In the section Searching of this page of edx, in the last part where students recommended to check their programs by looking for number 2008, is a bug - there is no number 2008 among the numbers ...
0
votes
0answers
162 views

Move won't swap tiles

Both init and draw run perfectly fine, but no matter what I try with move, any number I give the program returns "Illegal move" My code was (i thought) running through each row and column until it ...
0
votes
1answer
177 views

“Expected expression” error in my Game of Fifteen code

My Fifteen code won't compile because of these two "expected expression" errors in my "won" section. fifteen.c:254:15: error: expected expression while (n !== d*d) ^ fifteen.c:...
1
vote
1answer
234 views

Debugging sort code

I've been trying to write code for the sort function. It's not working properly and going through gdb isn't helping. When trying to sort 5 numbers, it seemed to go fine in gdb, but still printed out ...
1
vote
2answers
543 views

Cannot unzip pset3.zip: “End-of-central-directory signature not found.”

Here is my input and the output. Any thoughts? I have downloaded other copies so don't think it is due to a corrupted file. Archive: pset3.zip End-of-central-directory signature not found. ...
0
votes
1answer
459 views

How to compile Game of Fifteen framework?

I'm off to a very poor start on Game of Fifteen. The first task mentioned in "The Game Begins" is: "Go ahead and compile the framework. (Can you figure out how?)" I haven't been able to, and would ...
0
votes
1answer
217 views

Why won't my nested for-loops compile?

I'm trying to use nested for loops in the "init" part of Game of Fifteen and can't figure out why my code won't compile. Here's the code: for (i = 0; i < d; i++) { for (j = 0; j < d; j++) ...
2
votes
1answer
460 views

Why does accessing an out-of-bounds array element not cause a segmentation fault?

I tried to access an array element greater than which was passed in the search function but it did not cause a segmentation fault. Here is the code in which I was trying to access the element: bool ...
0
votes
2answers
362 views

Binary search algorithm only works for smaller arrays

I can't figure out what I'm doing wrong. My algorithm works for smaller arrays, but once the number of values increases, the program stops and I have to hit Ctrl + C. I thought maybe it was an issue ...
1
vote
1answer
510 views

Void init(void) or void init(int d)?

Why is the init function in fifteen not declared as void init(int), since it uses the integer d?
0
votes
1answer
102 views

Is it okay to check my code against a reference book?

Alright, so I've been having trouble making binary search (I think I either made an asymptote, or it degrades too quickly.), so I decided to see if my reference book had anything on Binary Search. It ...
1
vote
1answer
227 views

Piping generate pset3

I just wondering if some one can confirm for me that I understand what exactly is going on here when a file gets piped into another program. Generate is producing a certain number of random numbers ...
0
votes
0answers
77 views

Header files in helpers pset3

What is the rationale for the header files in helpers.c? For example there is cs50.h but not stdio.h even though the functions are all stdio except for bool which is in neither CS50 nor helpers. And ...
0
votes
1answer
168 views

How can I implement binary search without changing the search() declaration?

I am struggling to implement the recursive binary search function: We are not supposed to change the search() declaration, so I thought I will have to implement a separate recursive function for ...
0
votes
1answer
512 views

Linear Search not working

Alright, so, I'm not quite sure what's going wrong here, but maybe you people could help. My implementation of linear search in pset3 will return false no matter what (well, specifically I've only ...
0
votes
0answers
123 views

segmentation fault in pset 3

i have written init and draw function in init i have made 2 nested loops and given value to each element starting from position (0,0) = d*d-1 till the last element and i have printed the given ...
0
votes
1answer
731 views

Binary search question

I'm currently struggling with the binary search in pset 3 and I think I already found out how to implement it. I just really can't understand why, after return res;, the program does not leave the ...
0
votes
1answer
324 views

How and where to write code to check around tile? Pset3, Game of Fifteen

Been killing my head for too long with this. I get that we check around the tile when we find it in our loop, but then what? I understand completely, conceptually... yes, check around the tile for ...
2
votes
1answer
169 views

Pset3 search: can't seem to find the last number

Everything else in check50 works, but my program can't find 42 in {40, 41, 42} and {39, 40, 41, 42}. I don't think it's sort's fault, and I've implemented search in the correct way (I think, at ...
-2
votes
2answers
840 views

How to set up the board using init and draw functions

I am working on PSET3 Fifteen and am really unsure of what I am doing with the init function. I have a nested for loop – but I don't know what to do with the values. I then move on down to draw and I ...
1
vote
1answer
474 views

Swap 2 and 1 after looping, pset3, Game of Fifteen

I don't know why my positions at 2 and 1 in my odd numbered tiles are not swapping. Here is a mix of pseudo code plus my swap conditional. See anything that is wrong? Thanks. // board, whereby ...
0
votes
0answers
114 views

what's wrong with my linear search?

I don't get this. I did a whole lot of debugging with gdb, and somehow move returns false automatically just after this simple search for the tile. int p=0,q=0; for(i=0;i<d ;i++) { for(j=0;j<...
0
votes
0answers
300 views

Swap function in helpers.c file

I have successfully completed the linear search and sort functions in the helpers.c file for problem set 3. I included the swapping steps within the sort function directly and everything worked ...
0
votes
1answer
1k views

pset3 fifteen won function isn't working?

I've been trying to write the won function for days, but it has never worked correctly. I can't find any flaws in my logic, so can somone help me figure out what I'm doing wrong? ebool won(void) { ...
0
votes
1answer
134 views

control may reach end of non void function in move [duplicate]

This is my code for move: for(i=0;i<d;i++) { for(j=0;j<d;j++) { if(a[i][j]==tile) { e=i; f=j; } ...
4
votes
1answer
496 views

pset3 find INT_MAX

In find.c, there's a conditional that references a constant called "INT_MAX". I looked through all the pset files and couldn't find any reference to this constant. What is it, what does it represent,...
1
vote
1answer
180 views

Pset3, After haystack values typed, just blank on the Command line

I am almost done with my Binary Search and yet when I test it, it does this strange thing. I run ./find (some number) and it prints out the haystack[] values one by one as I enter numbers for those, ...
2
votes
1answer
2k views

Selection sort seems right, but the values are not sorted

I have been running gdb on this, and it's true, the values are not sorted. But my logic seems fine. This is the selection sort, anyone know what I am missing? int min, hold, i, j; for (i = 1; i &...
3
votes
2answers
27k views

How to solve “control may reach end of non void function” error

When I try to compile my code, I get an error message that says "control may reach end of non void function." What does this message mean and how can I avoid this error? Here is the function that's ...
1
vote
1answer
589 views

Search function always false, haystack doesn't print a value

I feel like I am close, but not sure why my haystack values are not printing. I am trying to write linear search code for the search() function in helpers.c, and this is what seems to me to be the ...
2
votes
1answer
1k views

How does find.c know to use functions from helpers.c?

I've been beating my head trying to understand the second assignment for pset 3. It states in part: Notice that find.c calls search, a function declared in helpers.h. Unfortunately, we forgot to ...