This is impossible. The gap between Programming 1 and Programmin 2 is ridiculous.
My first assignment is to make an array of 10 bathroom stalls and have a person (x) fill out a center spot randomly, then fill out another spot either to the left or the right near the middle randomly, etc etc until all the spots are filled.
The second question is to make an arrayList with sequences in order to append/merge/merge without copying two arrayLists.
The third question is to partition any given number. I actually managed to code this one, but instead of my output being:
5 41 311 2111 11111
it is 5 14 113 1112 11111
I don't think anyone in my class is getting this. The difficulty is so much higher, how can anyone expect us to jump so far ahead? Can anyone help me? Any guides? Because I am lost as fuck.
Especially with the whole sequencing, which I'm not even sure what that means.
Or the fucking stalls. I only managed to print the array of empty stalls, so I basically started it only.
Christopher Martin
What language?
Try solving it on paper first then transfer that to code
Julian Long
Java.
What do you mean solve on paper?
I feel like I don't know anything. Literally everything I need to do I've had to look up on the internet where people pull RANDOM SYNTAX OUT OF THEIR ASS
like WTF is a sequence?!!??!?!?!!?!?!?! WHY can't I just print out a sequence? Why does EVERYTHING have to result in an error?
Why am I so shitty at this? How is it that other almost IMMEDIATELy know how to solve a problem.
Like holy shit I can't fucking work in this field this is literally impossible.
Kevin Carter
Professional programmer here. Everytime I've tried to lay out a problem in paper I've failed miserably.
Programming is all about having good intuition for problems, being able to shit out a base program that supposedly does what you want it to do and then you execute it to see if the results are what you want.
When it doesn't do what you want you put a billion breaks in the code and manually check how every variable is behaving.
That google movie where the programmers were scribling shit on windows instead of getting in the fucking computer is nothing but fantasy. Nobody does that.
Jace Thompson
Didnt really pay much attention to what you wrote but seems easy
Jose Martinez
But what the fuck man. How do I get a grasp of even remotely knowing what the fuck I'm doing?
Jordan Ramirez
Im not really sure about the bathroom stall one because i dont understand what you posted. For the partion one why dont you just store the current output in an array, then output the array in reverse order? I know there is a much simpler solution to this if i could see your code but with what you gave us thats the easiest solution i see.
Jayden Brooks
Not sure what you mean with the first one. this code picks a random spot and then starts filling stalls left or right from it.
boolean[] arr = new boolean[10]; int leftIdx=-1; int rightIdx=1;
int start = //random gen shit of choice while(!bathroomsFull()) { switch(//random gen between 1-2) { case 0: //Left if(start+leftIdx < 0) //Out of bounds continue; arr[start+leftIdx] = true; leftIdx--; break; case 1: if(start+rightIdx > 9) //Out of bounds continue; arr[start+rightIdx] = true; rightIdx++; break; } }
private boolean bathroomsFull() { for(int i=0; i
Alexander Lewis
>How do I get a grasp of even remotely knowing what the fuck I'm doing?
That is when intuition comes in. You should always know how a program 'looks like' naturally. If you can't do that then drop out.
I'd help you if I understand what the fuck you are being asked. What does it mean to partition a number ffs?
In what context is sequence being used and why do you need an arrayList?
etc. etc.
Zachary Adams
the break in bathroomsFull should be return false; and the switch should generate 0 or 1 not between 1-2
Ian Russell
Can you explain this code?
Basically it's this: _ _ _ _ x _ _ _ _ _ _ _ x _ x _ _ _ _ _ _ _ x _ x _ _ x _ _ _ x x _ x _ _ x _ _ _ x x _ x _ x x _ _ _ x x _ x _ x x x _ _ x x x x _ x x x _ _ x x x x _ x x x _ _ x x x x x x x x _ x x x x x x x x x _ x x x x x x x x x x
It starts filling the 'middle' spots till they all get filled.
Jose Rodriguez
From the assignment:
Problem #1: Implement a program in Java to generate all of the unique positive partitions of a positive integer. Your program should print only those partitions containing at least one addend equal 1 (one). Example of the program output for the input number 6: 5 1 4 1 1 3 2 1 3 1 1 1 2 2 1 1 2 1 1 1 1 1 1 1 1 1 1 Problem #2: It is a well-researched fact that men in a restroom generally prefer to maximize their distance from already occupied stalls, by occupying the middle of the longest sequence of unoccupied places. For example, consider the situation where ten stalls are empty. _ _ _ _ _ _ _ _ _ _ The first visitor will occupy a middle position: _ _ _ _ _ X _ _ _ _ The next visitor will be in the middle of the empty area at the left. _ _ X _ _ X _ _ _ _ Write a program in Java that reads the number of stalls and then prints out diagrams in the format given above when the stalls become filled, one at a time. Hint: Use an array of boolean values to indicate whether a stall is occupied.
public class MenStall { public static int nextStall(boolean[] stalls) { . . . } public static void printStalls(boolean[] stalls) {. . . } . . . }
Example of the output for the number of stalls = 10 _ _ _ _ X _ _ _ _ _ _ _ _ _ X _ _ X _ _ _ X _ _ X _ _ X _ _ _ X _ _ X _ _ X X _ _ X _ _ X X _ X X _ _ X X _ X X _ X X _ _ X X _ X X _ X X X _ X X _ X X X X X X _ X X X X X X X X X X X X X X X X X X X
Eli Watson
Problem #3: Consider the following class: public class Sequence { private ArrayList values;
public Sequence() { values = new ArrayList(); }
public void add(int n) { values.add(n); }
public String toString() { return values.toString(); } } 3.1. Add a method public Sequence append(Sequence other) that creates a new sequence, appending this and the other sequence, without modifying either sequence. For example, if a is 1 4 9 16 and b is the sequence 9 7 4 9 11 then the call a.append(b) returns the sequence 1 4 9 16 9 7 4 9 11 without modifying a or b. 3.2. Add a method public Sequence merge(Sequence other) that merges two sequences, alternating elements from both sequences. If one sequence is shorter than the other, then alternate as long as you can and then append the remaining elements from the longer sequence. For example, if a is 1 4 9 16 and b is 9 7 4 9 11 then a.merge(b) returns the sequence 1 9 4 7 9 4 16 9 11 without modifying a or b. 3.3. Add a method public Sequence mergeNoDuplicates(Sequence other) that merges two sorted sequences, producing a new sequence in strong increasing order. You must assume that both sequences are in strong increasing order (no duplicates). For example, if a is 1 4 9 and b is 2 4 6 9 16 21 then a.mergeNoDuplicates(b) returns the sequence 1 2 4 6 9 16 21 without modifying a or b.
Jose Howard
>Example of the program output for the input number 6: >5 1 >4 1 1 >3 2 1 >3 1 1 1 >2 2 1 1 >2 1 1 1 1 >1 1 1 1 1 1
What about 2 2 2?
Kayden Bailey
he fucked up on the example. what he meant was:
for 6: 51 411 3111 21111 111111
Landon Campbell
at least I think so, user. If he meant any combination for these numbers, then I didn't even finish the first one and it's in fact EVEN HARDER than I thought.
Should I be solving these questions on the 3rd week of school? My first programming class was harder than most, and I still don't know what the fuck this is.
Jason Flores
I'm in third year of Software Engineering, still thinking about this one lol.
Jaxson Stewart
>public Sequence append(Sequence other) >that creates a new sequence, appending this and the other sequence, without modifying >either sequence. For example, if a is 1 4 9 16 and b is the sequence 9 7 4 9 11 then the call >a.append(b) returns the sequence 1 4 9 16 9 7 4 9 11 without modifying a or b.
There may be a better way to do this but suppose you have two sequences A, B.
Then create an empty sequence C and equal it to A.
I know that in Java everything is pointers but there must be a way to set C = A in the sense that the values A has are transferred to C without C pointing to A.
Then start a for loop that loops through the elements of B and appends them one by one to C.
>3.2
Create an empty sequence and then do a single for loop that first appends the ith element of A and then the ith element of B, all the way to the end.
>3.3
Here it gets a little tricky.
Again you do a single for loop and compare the ith element of A with the ith element of B.
You put the smallest as the first element of C.
Suppose that the smallest was the first element of A.
Then you want to move to the second element of A and check if it is also smaller than the first element of B.
If it is smaller then you put that second element of A into C.
If it isn't then now you put the first element of B into A.
And you repeat this until you have no more digits.
You also want to check strict order '>' not '=>' to avoid duplicates.
Asher Carter
>If it isn't then now you put the first element of B into A.
I meant into C, obviously.
Gabriel Hernandez
is this bait ? you sound like an utter moron
Jeremiah Gutierrez
No bait.
The only people who work on paper are researchers.
I am not working in ground breaking stuff, just useful tools for financial institutions.
Once I tried to describe a problem in paper and I succeeded and then to help my intuition (to code it) I tried an example but the thing is that regardless of what values I picked, the formulas I had described but at some point yield me really small numbers or really big numbers so I had to do a bunch of fucking rational arithmethic.
So I gave up.
Then I tried just saying. Ok, let a and b be my initial values.
Not too long after I was already working with fucking huge rational polynomials and it was also a pain in the ass to do arithmethic with those.
Then I said: Fuck this, I am just going to put it into a computer and then debug.
After that day I became a faster programmer.
Logan Gonzalez
Im this guy but on the Phone. This question is imo more algebraic in nature than programming related. While the bathrooms arent all full, it starts from the Middle and goes left or right randomly and fills the next free stall. This isnt what youre looking for though.
Evan Hughes
How can my professor expect me to program this? I don't know what to tel him. I can't do this assignment I literally can't do it I don't know what to do
Aaron Bell
import java.util.Scanner; public class Problem_1 { public static int userInt;
public void setNumber () { Scanner scan = new Scanner(System.in); this.userInt = scan.nextInt(); }
public int getNumber () { return userInt; }
public void Partition() { int countDown = userInt; userInt--;
while(userInt != 0){
for(int i = 0; i != countDown - userInt; i++){
System.out.print("1 ");
} System.out.println(userInt);
userInt--; } }
public static void main(String[] args) { Problem_1 PartitionNum = new Problem_1(); PartitionNum.setNumber(); PartitionNum.getNumber(); PartitionNum.Partition(); }
}
My code for the first one
Jackson Thomas
Wellicht if youre in uni youre rekt anyway lol. I go to college (or "university of applied science" as they like Calling it)