Questions tagged [pset3]

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

302 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
0
votes
1answer
133 views

Init for fifteen.c

For fifteen, I tried to make init in another tab so I could check to see if I have it right. Also, I'm not sure if I swap 1 and 2 in the init function or in the move function. My code so far is: /** ...
0
votes
1answer
52 views

Direction on Find/Helpers.c

I am really struggling to get started on the first part of Pset 3. I was able to do the commenting for generate.c (though without getting a deep understanding of srand and drand functions, which I ...
0
votes
1answer
37 views

Fifteen- Pset3: Weird error that is not my fault - help

Well my Fifteen doesn't compile because get_int but I included cs50 library. What I am missing? Check the screen shot please. Thank you!
0
votes
2answers
49 views

Pset3, Game of Fifteen, won, game keeps winning!

for the final part of fifteen, my game wins automatically upon start up and I'm not sure why, please help, thanks. my code is as follows: bool won(void) { //for each row for (int i = 0; i < d; ...
0
votes
1answer
33 views

pset3/fifteen/issue with board

I have an issue making my board in fifteen, i think im doing well but it shows something i can't explain. Can anyone help me? why my board numbers shudenly do this weird thing: My code: void init(...
0
votes
1answer
48 views

Check 50 for find

I have gotten most of my code to work for the search and sort, but I still have a few issues. One is i my for loop, I have it set to less than 100, though I need to make it less than log n, but I ...
0
votes
1answer
67 views

Pset3 Move Function “Illegal Move”

my code is notifying me with "Illegal Move" every time I test it. I was wondering if someone can help figure out what is wrong with my code? bool move(int tile) { // TODO int i, j; int swap; //rows ...
0
votes
1answer
28 views

Binary search recursing issue

I've been working on a binary search of pset3 find, and I'm having an issue when I call the function again recursively. I believe that I know what the issue is, I'm just not sure how to fix it. When I ...
0
votes
1answer
132 views

How does one print out all existing integers in an int array?

The code below generates the following error: format specifies type 'int' but the argument has type 'int *' [-Werror,-Wformat] printf("%i", array); include include int main(void) { int ...
0
votes
2answers
104 views

Help finding segmentation fault

In my code, I get a segmentation fault some, but not all of the times that I run it. Sometimes, it sorts the code and finds the needle, sometimes it doesn't sort correctly and ends with a segmentation ...
0
votes
0answers
37 views

Pset3, fifteen.c!

In the game of fifteen, I couldn't figure out a way to view the under-score sign "_" , I tried these lines of code: if (board[i][j] == 0) //checking if value is 0 to print a blank tile. these are the ...
0
votes
1answer
15 views

Pset3, fifteen.c

In the game of fifteen, I couldn't figure out a way to view the under-score sign "_" , I tried these lines of code: if (board[i][j] == 0) //checking if value is 0 to print a blank tile. ...
0
votes
1answer
45 views

Help fixing bubble sort

I've been working on implementing a bubble sort, and I can get it to swap one time through the list, but I can't get it to run more than once, and I'm not sure how to implement it. I also know that ...
0
votes
1answer
42 views

Is this a correct way of implementing bubble sort?

I made a bubble sort code, but I want to make sure that my code is correct. My code is void sort(int values[], int n) { if (n == 1) { return 0; } int swapcount = 0; ...
0
votes
1answer
28 views

In find, I print the array before sorting it, The last number it prints out is always consistent but unrelated to the problem

It continuously prints 2147483647 as the last number of the haystack, even when I use a different seed or no seed at all. Does anyone know why?
0
votes
1answer
75 views

pset3 find, failing half the checks!

so currently doing pset3 & i think my sort function is all good (i've printf'd each value & it's all in the right order), but when trying to implement binary search it's failing half the tests ...
0
votes
2answers
373 views

pset 3 - finding the needle problems!

I need some guidance. I had a problem with infinite loops (which I think I've corrected) and some problems on my sort algo as a user here pointed out (I think I've corrected the sort problem too). Now,...
0
votes
1answer
34 views

pset 3 - killed by server problem

I understand my problem is with infinite loops but I would like some guidance on solving it. I am not sure if I should use a for - as I tried doing on comments - or if there is a better/more efficient ...
0
votes
2answers
29 views

Fifteen.c/PSTE3 MOVE FUNCTION NOT SHOWING EXPECTED OUTPUT

Though my program fifteen.c/pset3 compiles with the int,draw,move function but the tiles are not moving at all. Here's my code as well the output.Kindly check and any suggestions will be appreciated. ...
0
votes
1answer
86 views

PSET3 helpers.c

:( finds 42 in {42,40,39,41} \ expected an exit code of 0, not 1 What can I make out of this error message. Here's my code for binary search,selection sort:
0
votes
0answers
83 views

pset3 why did this cause a segmentation error but only sometimes with same input?

So I was running into an issue with my counting sort algorithm throwing segmentation errors sometimes. The offending code: while (count < n) { while (counting_array[j] > 0) { ...
0
votes
1answer
206 views

How do I make comments in generate.c program in PSET3?

In the "understanding" section of find/PSET3 in CS50 2017 how do I open the file generate.c so that I can make (TODO) comments in that. I have ran all the commands for "downloading" section which ...
0
votes
1answer
443 views

Sort Race - check_flag function?

the problem set i'm having issues with can be found here: http://docs.cs50.net/2016/x/ap/problems/race/race.html i'm struggling to implement the check_flag function which is a simple check that ...
0
votes
1answer
127 views

Segmentation fault on pset3 (find : more comfortable)

My program got a problem when I used this command './generate 1000 50 | ./find 127' which generating random number to run it. It shows "Segmentation fault", but it works fine when I type the input ...
0
votes
1answer
29 views

Everything's working in manual testing, but cs50 says 4x4 not working (pset3 fifteen)

Source code for init: void init(void) { int k=(d*d)-1; for(int row=0; row<d; row++){ for(int col=0; col<d; col++){ board[row][col]=k; if((d%2==0)&&(k==3)){ ...
0
votes
1answer
28 views

Move function only moving underscore to the left and not replacing?

My move function is only moving right and also not replacing my tile with the switched tile. The relevant code looks like: bool move(int tile) { for (int row=0; row < d; row++ ) { ...
0
votes
0answers
35 views

Strange print out for fifteen?

To print out the grid, I used this code: void init(void) { int k = d*d - 1; for (int i=0; i < d; i++ ) { for (int j=0; j<d; j++, k--) { board[i][j] = k; } } board[d][d]= ...
0
votes
0answers
50 views

Result doesn't match expected output

I just finished the helpers.c pset, where you have to implement a counting sort and then a binary search. I havent made it recursive yet but it works in all of my own test cases. I also ran the ./...
0
votes
1answer
62 views

pset3 Segmentation fault ./generate 1000 50 | ./find 127

the generate.c file compiles and runs well and the find.c also compiles and runs well but i don't know why is i can't test them together
0
votes
1answer
26 views

pset3 search function declaration must stay the same?

Sorry for asking a probably repeated question, but I wanted to commit to a community! So the search implementation part of pset3 states: "You may not alter the function’s declaration. Its prototype ...
0
votes
0answers
46 views

Scramble doesn't find all the words in dictionary

I have implemented the lookup function but somehow it only finds most of the words but not all of them in the dictionary. Here is the code bool lookup(string s) { int min = 0; int max = WORDS ...
0
votes
1answer
35 views

why is binary search return false for everything

Here I have implemented the binary search in 2 ways, the iterative way, and the recursive way, but I get the same error for both ways, I also have implemented a insertion sort which works. but I am ...
0
votes
0answers
39 views

Problems with testing linear search function in helpers.

I am trying to write a simple linear search function within the helpers.c file with the following code: bool search(int value, int values[], int n) { // TODO: implement a searching algorithm ...
0
votes
1answer
11 views

pset3 move function takes illegal moves

Alright, so I've had a go at this for a very long time, and haven't been making much progress. My problems is with this move function. It doesn't accept some illegal moves, however, some illegal moves ...
0
votes
1answer
18 views

Breakout / pause(function) slows the paddle

When I add pause(5) to the while loop, pause function makes the ball not zip around, it also seems to slow down the paddle responsiveness. What do I have to do to get around that? I do understand why ...
0
votes
1answer
68 views

My game of fifteen doesn't work

void init(void) { // TODO int fill = ((d * d) - 1); int brow = d; //fill entire grid except the bottom for(int i = 1; i <= d; i ++) { for(int j = 1; j <= d; j ++)...
0
votes
0answers
214 views

PSET3 \ expected an exit code of 0, not 1 (find.c)

I successfully built my program and went on to check it using check50 only to discover this :) helpers.c exists :) helpers.c compiles :) finds 42 in {42,43,44} :) finds 42 in {41,42,43} :) finds 42 ...
0
votes
1answer
32 views

pset3 'fifteen' - init function only works for small grids

My init() code works beautifully for grids of 3, 4, or 5, but chokes with larger grid of 6, 7, 8, and 9. It looks almost like an integer overflow or floating point imprecision problem, but I can't see ...
0
votes
1answer
25 views

Haystack not found

Hi can someone help me out the code "./generate 1000 50 | ./find 127" doesn't find the haystack. And I even removed the "./find 127" and went through the generated numbers but still didn't see the ...
0
votes
1answer
96 views

pset 3 fifteen log.txt file not matching board

My code for fifteen.c works and solves the test inputs of the 3x3.txt file and the 4x4.txt file. However the check50 fails for the following. :) fifteen.c exists :) fifteen.c compiles :( init ...
0
votes
1answer
38 views

Sort Function not changing haystack

The array gets sorted inside the sort function but the haystack doesn't change. How do I pass haystack by reference without changing the function prototype? void sort(int values[], int n) { int ...
0
votes
3answers
131 views

FIFTEEN works perfectly but doesn't pass Check50

My program works perfectly. Though, my Check50 says that my program only compiles and runs, nothing else. I think this has to do with my draw function, but I can't spot the mistake Can anyone help me ...
0
votes
1answer
63 views

linker comman failed with exit code of 1 in find.c

I was about to submit pset3 and pset4 which I have completed, but in the process of keeping my house in order by checking every code before submission, I discovered that helpers.c has developed issues....
0
votes
1answer
43 views

pset3 - game of fifteen, problem with 0

I am only getting problems while I am choosing a zero as an extra tile. Every other value works fine, it passes the piped games as well:) Unfortunately can not understand where is the flaw:( I am ...
0
votes
0answers
91 views

pset3 move function

I have been banging my head against a wall for the last few days trying to figure out the move function. January 1st is fast approaching and I want to finish this pset and submit it before they ...
0
votes
1answer
33 views

Defining array[i] as a macro

I'm getting the following error: helpers.c:25:12: error: called object type 'int *' is not a function or function pointer if (MIN < MAX) ^~~ helpers.c:20:24: note: ...
0
votes
1answer
166 views

Game of fifteen: everything works perfect until winning move breaks game

I've gotten pretty much everything working in fifteen. The tiles move correctly, the redraw works with a board of any size, et cetera. So I pasted in the ./fifteen 3 < ~cs50/pset3/3x3.txt the pset ...
0
votes
1answer
155 views

Game of Fifteen PSET3: CS50 - won function and check50

Hi I have yet another question about game of fifteen. I seem to have implemented by 'won' function correctly. Before this check50 was running and I was getting a pass for everything, excluding the '...
0
votes
1answer
81 views

Guys,my code runs perfectly right with check 50 for binary search but doesn't show right output for ./generate 1000 50 | ./find 127.Please help

bool search(int value, int values[], int n) { int middle=(int)((n-1)/2); if(n<0) { return false; } else if(values[middle]==value) { return true; } else if(...
0
votes
1answer
97 views

game of fiteen doubts in code and in check50

have a look at my game of fifteen code at: http://pastebin.com/gpZnkTPp it is showing errors in check50 , but i don't know what's wrong with my code check50 2015.fall.pset3.fifteen fifteen.c :) ...

1 2 3
4
5
7