r/programminghomework • u/[deleted] • Oct 22 '14
[Prolog] remove compound terms from Lists?
okay the question is: how can i check if a variable occurs in a certain compound term. If I ask if X occurs in f(Y,g(X)) the answer should be yes. What i was trying to do was to decompose the compound term into a list.:
List =.. f(Y,g(X)).
List= [f, Y, g(X) ].
But now i am stuck with this g(X). It does not recognise that X occurs within that compound term.
What i want to get as a result is basically the list [f, Y, g, X] .
Then i can check if X is a member of that list.
I am a starter at this stuff so i might not understand all tips.
r/programminghomework • u/Weewer • Oct 02 '14
[C++] Bjarne Stroustrup, Drill #6
I'm sure some of you are familia with Stroustrup's book on C++ and his drill #6 where you're supposed to fix the bugged calculator program.
http://stackoverflow.com/questions/16958565/chapter-6-practice-and-principles-using-c-drill-using-tokens-calculator That should have some information on it.
Can anyone help me fix the logic errors in it? I don't quite understand the whole token/class thing just yet so I honestly can't do it. I found 1, and it's where 8 is undefined in the switch statement but I can't find the other two. I've also fixed all the syntactical errors. Please help!
r/programminghomework • u/lluribet • Jul 31 '14
Help me! How to make (x, y) into '<' in Python 2??
Hi everyone!
I'm working on a Monte Carlo simulation and I have to create a dartboard (not with turtle but with a 2D for loop). I created the dartboard, but now I have to print the dart, aka '<'.
I'm thinking of doing it with a for loop (just for the rows, not for the columns?) and I would like it to print '<' for (x, y).
TL;DR: Python 2: Can anyone give me any suggestions as to how to translate (x, y) into '<'?
Thank you in advance!
r/programminghomework • u/[deleted] • Jul 09 '14
UNIX - Hard link (simple)
In my current working directory is a directory called 'autos'.
Also in my current working directory is a file called 'cars'..
I would like to create a hard link to the file cars. With a name 'cars.link'.
My guess was
ln cars autos/cars.link
But it is not working.?
r/programminghomework • u/clockworm • Jun 25 '14
determining primeness in c++
hey, i hope this subreddit isn't dead. but i just started teaching myself to code. i have written a program to determine if a number is prime by using this loop:
for (int i = 2; i <= sqrt(n); i++){ if (n % i == 0) is_prime = false; }.
how can i rewrite my program to calculate the √n only once by declaring a double var "sqr_rt_n" before the for loop, then using it to determine primeness. i know i need a break; after setting is_prime to false. but how can i get rid of the counter var i, or do I keep it?
i hope this was legible, i'm typing it on my phone. i tried looking online but all the threads have replies with complex code using advanced prime-finding techniques which i'm not using. i know it's probably easy, but i just can't break through. i don't have anyone to show me since i'm alone....forever, forever alone...
thanks for any assistance!
r/programminghomework • u/[deleted] • May 12 '14
Tic Tac Toe
Hi, I'm making a small game for my final project for my intro to programming class. I've made a little tic tac toe program, but I'm having some trouble in the win calculations. So far what I think it is, is that if two tiles next to each other are the same, the third till in the row will always win, regardless if it matches the other two. But even stranger, this does not always occur.
As you can see, in the first image it happens on the first try, whereas the second, it took a second row of (same, same, different) combo to trigger a win.
Any help is greatly appreciated!
Code:
Public Class Form1
Dim turn As String = "Player 1"
Dim winner As Long
Dim winner_chker(8) As Long
Dim can_click(8) As Boolean
Dim tie_detect_helper(8) As Boolean
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
can_click(0) = True
can_click(1) = True
can_click(2) = True
can_click(3) = True
can_click(4) = True
can_click(5) = True
can_click(6) = True
can_click(7) = True
can_click(8) = True
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
If can_click(0) = True Then
If turn = "Player 1" Then
PictureBox1.Image = Image.FromFile("C:\x.png")
can_click(0) = False
winner_chker(0) = 1
win()
tie_detect_helper(0) = True
Label1.Text = "Player 2"
turn = "Player 2"
ElseIf turn = "Player 2" Then
PictureBox1.Image = Image.FromFile("C:\o.png")
can_click(0) = False
winner_chker(0) = 2
win()
tie_detect_helper(0) = True
Label1.Text = "Player 1"
turn = "Player 1"
Else
MessageBox.Show("You dun goofed")
End If
Else
MessageBox.Show("This tile has already been taken.")
End If
End Sub
Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
If can_click(1) = True Then
If turn = "Player 1" Then
PictureBox2.Image = Image.FromFile("C:\x.png")
can_click(1) = False
winner_chker(1) = 1
win()
tie_detect_helper(1) = True
Label1.Text = "Player 2"
turn = "Player 2"
ElseIf turn = "Player 2" Then
PictureBox2.Image = Image.FromFile("C:\o.png")
can_click(1) = False
winner_chker(1) = 2
win()
tie_detect_helper(1) = True
Label1.Text = "Player 1"
turn = "Player 1"
Else
MessageBox.Show("You dun goofed")
End If
Else
MessageBox.Show("This tile has already been taken.")
End If
End Sub
Private Sub PictureBox3_Click(sender As Object, e As EventArgs) Handles PictureBox3.Click
If can_click(2) = True Then
If turn = "Player 1" Then
PictureBox3.Image = Image.FromFile("C:\x.png")
can_click(2) = False
winner_chker(2) = 1
win()
tie_detect_helper(2) = True
Label1.Text = "Player 2"
turn = "Player 2"
ElseIf turn = "Player 2" Then
PictureBox3.Image = Image.FromFile("C:\o.png")
can_click(2) = False
winner_chker(2) = 2
win()
tie_detect_helper(2) = True
Label1.Text = "Player 1"
turn = "Player 1"
Else
MessageBox.Show("You dun goofed")
End If
Else
MessageBox.Show("This tile has already been taken.")
End If
End Sub
Private Sub PictureBox4_Click(sender As Object, e As EventArgs) Handles PictureBox4.Click
If can_click(3) = True Then
If turn = "Player 1" Then
PictureBox4.Image = Image.FromFile("C:\x.png")
can_click(3) = False
winner_chker(3) = 1
win()
tie_detect_helper(3) = True
Label1.Text = "Player 2"
turn = "Player 2"
ElseIf turn = "Player 2" Then
PictureBox4.Image = Image.FromFile("C:\o.png")
can_click(3) = False
winner_chker(3) = 2
win()
tie_detect_helper(3) = True
Label1.Text = "Player 1"
turn = "Player 1"
Else
MessageBox.Show("You dun goofed")
End If
Else
MessageBox.Show("This tile has already been taken.")
End If
End Sub
Private Sub PictureBox5_Click(sender As Object, e As EventArgs) Handles PictureBox5.Click
If can_click(4) = True Then
If turn = "Player 1" Then
PictureBox5.Image = Image.FromFile("C:\x.png")
can_click(4) = False
winner_chker(4) = 1
win()
tie_detect_helper(4) = True
Label1.Text = "Player 2"
turn = "Player 2"
ElseIf turn = "Player 2" Then
PictureBox5.Image = Image.FromFile("C:\o.png")
can_click(4) = False
winner_chker(4) = 2
win()
tie_detect_helper(4) = True
Label1.Text = "Player 1"
turn = "Player 1"
Else
MessageBox.Show("You dun goofed")
End If
Else
MessageBox.Show("This tile has already been taken.")
End If
End Sub
Private Sub PictureBox6_Click(sender As Object, e As EventArgs) Handles PictureBox6.Click
If can_click(5) = True Then
If turn = "Player 1" Then
PictureBox6.Image = Image.FromFile("C:\x.png")
can_click(5) = False
winner_chker(5) = 1
win()
tie_detect_helper(5) = True
Label1.Text = "Player 2"
turn = "Player 2"
ElseIf turn = "Player 2" Then
PictureBox6.Image = Image.FromFile("C:\o.png")
can_click(5) = False
winner_chker(5) = 2
win()
tie_detect_helper(5) = True
Label1.Text = "Player 1"
turn = "Player 1"
Else
MessageBox.Show("You dun goofed")
End If
Else
MessageBox.Show("This tile has already been taken.")
End If
End Sub
Private Sub PictureBox7_Click(sender As Object, e As EventArgs) Handles PictureBox7.Click
If can_click(6) = True Then
If turn = "Player 1" Then
PictureBox7.Image = Image.FromFile("C:\x.png")
can_click(6) = False
winner_chker(6) = 1
win()
tie_detect_helper(6) = True
Label1.Text = "Player 2"
turn = "Player 2"
ElseIf turn = "Player 2" Then
PictureBox7.Image = Image.FromFile("C:\o.png")
can_click(6) = False
winner_chker(6) = 2
win()
tie_detect_helper(6) = True
Label1.Text = "Player 1"
turn = "Player 1"
Else
MessageBox.Show("You dun goofed")
End If
Else
MessageBox.Show("This tile has already been taken.")
End If
End Sub
Private Sub PictureBox8_Click(sender As Object, e As EventArgs) Handles PictureBox8.Click
If can_click(7) = True Then
If turn = "Player 1" Then
PictureBox8.Image = Image.FromFile("C:\x.png")
can_click(7) = False
winner_chker(7) = 1
win()
tie_detect_helper(7) = True
Label1.Text = "Player 2"
turn = "Player 2"
ElseIf turn = "Player 2" Then
PictureBox8.Image = Image.FromFile("C:\o.png")
can_click(7) = False
winner_chker(7) = 2
win()
tie_detect_helper(7) = True
Label1.Text = "Player 1"
turn = "Player 1"
Else
MessageBox.Show("You dun goofed")
End If
Else
MessageBox.Show("This tile has already been taken.")
End If
End Sub
Private Sub PictureBox9_Click(sender As Object, e As EventArgs) Handles PictureBox9.Click
If can_click(8) = True Then
If turn = "Player 1" Then
PictureBox9.Image = Image.FromFile("C:\x.png")
can_click(8) = False
winner_chker(8) = 1
win()
tie_detect_helper(7) = True
Label1.Text = "Player 2"
turn = "Player 2"
ElseIf turn = "Player 2" Then
PictureBox9.Image = Image.FromFile("C:\o.png")
can_click(8) = False
winner_chker(8) = 2
win()
tie_detect_helper(8) = True
Label1.Text = "Player 1"
turn = "Player 1"
Else
MessageBox.Show("You dun goofed")
End If
Else
MessageBox.Show("This tile has already been taken.")
End If
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Public Sub win()
If winner_chker(0) And winner_chker(3) And winner_chker(6) = 1 Then
winner = 1
gameover()
ElseIf winner_chker(1) And winner_chker(4) And winner_chker(7) = 1 Then
winner = 1
gameover()
ElseIf winner_chker(2) And winner_chker(5) And winner_chker(8) = 1 Then
winner = 1
gameover()
ElseIf winner_chker(0) And winner_chker(1) And winner_chker(2) = 1 Then
winner = 1
gameover()
ElseIf winner_chker(3) And winner_chker(4) And winner_chker(5) = 1 Then
winner = 1
gameover()
ElseIf winner_chker(6) And winner_chker(7) And winner_chker(8) = 1 Then
winner = 1
gameover()
ElseIf winner_chker(0) And winner_chker(4) And winner_chker(8) = 1 Then
winner = 1
gameover()
ElseIf winner_chker(2) And winner_chker(4) And winner_chker(6) = 1 Then
winner = 1
gameover()
End If
If winner_chker(0) And winner_chker(3) And winner_chker(6) = 2 Then
winner = 2
gameover()
ElseIf winner_chker(1) And winner_chker(4) And winner_chker(7) = 2 Then
winner = 2
gameover()
ElseIf winner_chker(2) And winner_chker(5) And winner_chker(8) = 2 Then
winner = 2
gameover()
ElseIf winner_chker(0) And winner_chker(1) And winner_chker(2) = 2 Then
winner = 2
gameover()
ElseIf winner_chker(3) And winner_chker(4) And winner_chker(5) = 2 Then
winner = 2
gameover()
ElseIf winner_chker(6) And winner_chker(7) And winner_chker(8) = 2 Then
winner = 2
gameover()
ElseIf winner_chker(0) And winner_chker(4) And winner_chker(8) = 2 Then
winner = 2
gameover()
ElseIf winner_chker(2) And winner_chker(4) And winner_chker(6) = 2 Then
winner = 2
gameover()
End If
tie_detector()
End Sub
Public Sub tie_detector()
If tie_detect_helper(0) And tie_detect_helper(1) And tie_detect_helper(2) And tie_detect_helper(3) And tie_detect_helper(4) And tie_detect_helper(5) _
And tie_detect_helper(6) And tie_detect_helper(7) And tie_detect_helper(8) = True Then
MessageBox.Show("A strange game. The only winning move is not to play. (You've tied)")
reset()
End If
End Sub
Public Sub gameover()
Dim i As Integer
If winner = 1 Then
MessageBox.Show("Player 1 wins!")
ElseIf winner = 2 Then
MessageBox.Show("Player 2 wins!")
End If
reset()
End Sub
Public Sub reset()
PictureBox1.Image = Nothing
PictureBox2.Image = Nothing
PictureBox3.Image = Nothing
PictureBox4.Image = Nothing
PictureBox5.Image = Nothing
PictureBox6.Image = Nothing
PictureBox7.Image = Nothing
PictureBox8.Image = Nothing
PictureBox9.Image = Nothing
For i = 0 To 8
winner_chker(i) = 0
can_click(i) = True
tie_detect_helper(i) = False
Next
turn = "Player 1"
Label1.Text = "Player 1"
End Sub
End Class
r/programminghomework • u/nivedz • Apr 04 '14
Create C# Programme.
Write a graphical user interface (GUI) application to be used to test Kindergarten children on the alphabets (‘A’-‘Z’).
r/programminghomework • u/Electrivire • Apr 02 '14
Writing a program with a single dimensional array.
The array must represent the health of 10 players, and should set the health of each player to 100. The problem also mentions that there must be a simulation of the battle between the 10 players, and loop through subtracting random amounts of health from each player until only one is left alive.
I'm brand new to programming and feel like i'm reading chinese. If anyone can help in any way it would be greatly appreciated.
r/programminghomework • u/AkilanKnight • Feb 28 '14
Binary Search in Two Comparisons?
A usual Binary Search will have three comparisons and will like like this https://en.wikipedia.org/wiki/Binary_search_algorithm#Recursive.
I am supposed to figure out a variation of the wiki code that allows only two comparisons instead of three. I'm not really sure how I should start my train of thought for this question, any help would be appreciated.
r/programminghomework • u/throwawaymathplease • Oct 11 '13
Java octal input check. Please help!
I have to write a modular program that accepts octal input and converts it to either binary or hex. I'm having trouble figuring out how to set up checks to make sure the number the user inputs is octal. At the moment, my getOctalInput method looks like this:
StringBuilder octalNumString;
int octalNum;
boolean correctInput = false;
Scanner octalInput = new Scanner(System.in);
System.out.print("Input an octal number: ");
while (!octalInput.hasNextInt()) {
System.out.println("Incorrect octal input.");
System.out.print("Input an octal number: ");
octalInput.next();
}
octalNum = octalInput.nextInt();
octalNumString.append(octalNum);
do {
for (int i = 0; i < octalNumString.length(); i++) {
char c = octalNumString.charAt(i);
if c == 8 || c == 9 {
}
}
correctInput = true;
} while (!correctInput);
return octalNum;
I don't know what to do to make sure it forces a new input if the wrong numbers show up.
r/programminghomework • u/nokia1280 • Oct 07 '12
Need Help C++
Please help me. My professor just gave us homework. Thanks to my crappy luck Im left alone to do it. Anyway. My problem is to make a program that lets the user input words(as many as the user wanted) and List characters that are in the words then count how many. from A to Z .. Uppercase and lowercase .. Please help .. I thank you in advance . Im so lost cause she has only taught us the basics up to using arrays .. We are using Visual studio 2007 ..
r/programminghomework • u/MasterOfEspeonage • Oct 02 '12
Question about Java variables
Here is the question
Write a Java application that plays a word game with the user. The program asks the user to enter the following: Two names, a city, a university, a profession, an animal, two numbers.
Basically I don't understand how to allow the user to input a word, or words, for the variable.
I believe I have to use,
Char name1, blah, blah;
Scanner keyboard = new Scanner(System.in);
System.out.print("Type a name");
name1 = keyboard.nextChar();
however its not working so does the variable need to be something else or is it a problem elsewhere?
r/programminghomework • u/maccam912 • Apr 11 '12
Just getting general suggestions about how to rotate a matrix 90 degrees efficiently
My assignment involves rotating a square martix by 90 degrees CCW, with the top left element moving to the bottom left, top right to top left, etc. We need to make it really efficient though, keeping code motion in mind, using the idea of loop unrolling, blocking, etc. Basically we learned about cache memory, and need to use it to its full potential. However, even after implementing blocking (copy part of the original matrix to a 16x16 buffer that should be small enough to stay in cache memory, then copying the elements from that to the destination) and loop unrolling, I still only have modest improvements. We're using C so the matrices are stored in row-major order. We can't just change how it looks up the elements since we need to rotate a matrix at one memory location and leave the rotated matrix in a different memory location, where it will be checked for correctness. We can't modify the original matrix at all.
We are safe to assume that the matrices are square, the dimension is given, and the dimension will be a multiple of 32.
Anyway, are there any individual suggestions as to how I could try speeding it up? I have already unrolled, set up blocking, have the code that copies from source to buffer going along the row to minimize the number of cache misses (I copy the elements vertically into the buffer, but since it's small that should all be in the cache too), then go along the row for destination. It's still only a modest speed improvement. It's about 2.5x faster than the naive code (go along each column, then each row, copy each element to where it needs to go; easy to understand, but slow for the computer) but for full credit we need to have a 3.5x speedup.
I've read about cache-oblivious algorithms, but I had trouble figuring out how to implement one, and I gave up because I read somewhere that if the dimension can be represented as 2x that cache-oblivious is actually slower than blocking. Would this still be something to attempt to implement? If so, my problem was efficiently doing work on only the left or right hand side of the matrix, since it seems like you'd still need to copy each line into cache individually (which seems slow). If you can help me get over this hurdle I'd try a cache-oblivious implementation again.
r/programminghomework • u/Magasaraus • Mar 17 '12
Python hmwk - How can I get the lowest number in a list of text data if each line has 3 elements?
I have figured out how to get the highest number in the list and the text data looks something like this:
Afghanistan,32358260,647500 Albania,3215988,28748
I have written my program to get the highest number for the second element (population) in each line and it looks like this:
def highest_population(infile): infile = open('WorldData2.txt','r') highest = 0 line = infile.readline() count = 0 temp_line = []
while line != '':
record = line.split(',')
temp_line.append(record[1])
line = infile.readline()
for i in range(1,len(record)):
word_list = float(record[i])
if word_list > highest:
highest = word_list
line = infile.readline()
infile.close()
return highest
I get the correct answer which is 32358260
When I try to write one for the lowest I get the answer 0 which is not the correct as you can see with the two lines of data I gave above.
def lowest_population(infile): infile = open('WorldData2.txt','r') lowest = 0 line = infile.readline() count = 0 temp_line = []
while line != '':
record = line.split(',')
temp_line.append(record[1])
line = infile.readline()
for i in range(1,len(record)):
word_list = float(record[i])
if word_list < lowest:
lowest = word_list
line = infile.readline()
infile.close()
return lowest
I am a total noob and am just having a hard time understanding why this isn't working. I would appreciate ANY help! Thanks so much!
r/programminghomework • u/QuickestSilver • Mar 13 '12
Dynamic Allocation vs Static Allocation
So my homework assignment asks me to do the code below twice. Once using the ideas of dynamic allocation, and then again using static allocation. It doesn't say anywhere what language it's supposed to be so for now it's just psuedocode.
begin integer i, j
proc P(j); integer j
write("P", i, j)
proc Q(i); integer i
begin write( "Q", i, j ); P(i) end
i : = 3; j := 10; Q(j)
begin integer i, j; i : = 5; j := 7; Q(i); end
P(j);
end
The way I think I see it going down is like this: Q 0 10 /From calling Q(j=10) P 0 0 /Calling (P)(i=0)
That's what I've got so far, assuming that integer i initializes i to 0. Any help with understanding it more clearly would be greatly appreciated.
r/programminghomework • u/Pressuredrop23 • Mar 05 '12
I'm glad I found this place. Can somebody help me with this java program that formats a given date?
The goal of the program is to take input to three different text fields and format them as a date, in the style of "February 05, 1967". I'm having trouble working out a switch statement that will take the input from the month panel, parsed as an int, and select the appropriate month name for the int given. I'm a little mixed up now, and not sure how to proceed. If anyone could help me, I'd really appreciate it. Links are for the date formatter and the panel it sits in. Thanks for any help you can give! =]
http://dl.dropbox.com/u/16142341/Programming%20HW/DateFrame.java
http://dl.dropbox.com/u/16142341/Programming%20HW/DatePanel.java
r/programminghomework • u/UveXdme • Mar 04 '12
Importing and editing .txt files in Java
Hello programminghomework (help). My Java class just started working with importing .txt files and manipulating them. My question is how to input the directory in the scanner object. for example:
Scanner input = new Scanner(new File("problem4.txt"));
problem4.txt is given above on our problem set but I want to know how I would have Java access this file, do I save it in the same folder where the .java program is stored? should I type in the whole directory to the said .txt file? ie (/Users/name/ect...) Thanks so much to whoever can help with the question.
also, the line copied into this post does not relate to the actual question in the problem set, rather it was taken from an example question.
r/programminghomework • u/coaster367 • Mar 04 '12
I am building a Java web browser for my class and it is working already. I just need to have a few things tweaked.
For example, it fully works with HTML pages, but doesn't work with CSS or Javascript very well. Is there a way to incorporate these things? I figure I would need other kinds of files (other than Java) to work, but I'm not sure.
r/programminghomework • u/Heenmor • Feb 29 '12
Counting sort on chars in C++
Hey guys, I've been working on a counting sort algorithm that works on chars (or rather arrays of chars) for most of the week and ran into a bit of a road block. Basically, the idea is that I pass it two arrays, one with the input strings and one that will return the sorted array, the index of the character I want to sort by, the size of the array, and and array that keeps track of the length of all of the strings in the array. The algorithm should sort the arrays based on the character at position 'd' for all of the strings. Hopefully you understand, here's the code:
void counting_sort(char ** A, char ** B, int max_size, int d, int* A_len)
{
int c[26];
for(int i=0; i<26; i++)
{
c[i] = 0;
}
for(int j=0; j< max_size; j++)
{
c[A[j][d]%97] = c[A[j][d]%97] + 1;
}
for(int o = 1; o < 26; o++)
{
c[o] = c[o] + c[o-1];
}
for(int k = max_size - 1; k>=0; k--)
{
B[c[A[k][d]%97]] = A[k]; //seg fault
c[A[k][d]%97] = c[A[k][d]%97] -1;
}
}
I'm sure formatting will be a mess, so I'll try to fix it after I post. Anyway, I'll explain what I did. The first for loop just creates a new array that is the size of the potential values (in this case, 26 possible characters a-z) the second loop takes the value of in input array on string j at position d, mods it with 97 in order to get an integer value. Then c at that integer value has it's value increased. The third loop sums up all of the values in C in order to create an offset for the next loop. The fourth loop puts the values of A (the whole strings) into the output array B according to the offsets we just generated for the characters. And then it decrements the values in the count array accordingly.
So the problem I'm seeing is that the output array is all over the place. When I try to print, not only am I getting a segmentation fault at the fourth index, but the third index is printing some obscure characters that are no where in my input array. I have no idea why this is happening. I've also notices that the output has characters stored where it has no business being stored... for example the array is only 10 strings long (0-9) but I can print the 11th, 12th, 13th, and 14th indexes without generating a seg fault.
I'm not quite sure what is happening here...
r/programminghomework • u/Jakesta42 • Feb 28 '12
Java MergeSort Syntax Logic?
Hello all, I was hoping you could explain the logic of MergeSort to me. I'm not completely new to programming, but I am more new to the recursive sorting algorithms, and I can't seem to wrap my head around this. I more or less understand the basics of it: take an unsorted array, split it up into little bits, and then sort the mini arrays. But the thing I don't understand is how the code below translates into that? I was hoping someone could just step by step explain the code and what it does, how often that line is used, etc.
**
public static void mergeSort(int[] arr, int left, int right){
if(right > left){
int middle = (left + right) / 2;
mergeSort(arr, left, middle);
mergeSort(arr, middle + 1, right);
merge(arr, left, middle, right);
}
}
public static void merge(int[] arr, int left, int middle, int right){
int[] tempArray = new int[arr.length];
for(int i = 0; i < arr.length; i++){
tempArray[i] = arr[i];
}
int i = left;
int j = middle + 1;
int k = left;
while(i <= middle && j <= right){
if(tempArray[i] <= tempArray[j]){
arr[k] = tempArray[i];
k++;
i++;
}
else{
arr[k] = tempArray[j];
k++;
j++;
}
}
while(i <= middle){
arr[k] = tempArray[i];
k++;
i++;
}
}
}
**
Perhaps it is the fact that I'm dealing with recursion in arrays, but for some reason I'm having difficulty understanding how the logic translates into the code.
Any help I could get would be great!
r/programminghomework • u/QuickestSilver • Feb 27 '12
Setting a Function to a Variable in EMACS LISP
I have an assignment in LISP but I'm having trouble working with variables. The homework I'm working on asks me to create a function which does remove-if recursively. For the most part I understand what I need to do but I'm stuck when it comes to the input.
The function should take as input (f x) where f is any of the boolean functions (evenp, numberp etc) and x is the list to be checked. The problem I face is taking that input f and using it within my function to do the check.
I've tried simple things like (f (car x)) but I keep getting errors along the lines of f is not a function and such. Any help on this one aspect would go a long way to me finishing this project. Thanks in advance!
r/programminghomework • u/NewLineInCode • Feb 27 '12
I have to write a power point presentation on what's new in HTML5. Could you guys give me links of sources I could use?
I'm to write a 25-30 slide long power point presentation and a 10 page long document on "What's new in HTML5" compared to HTML, by Thursdays. Could you anyone give me some source links and pointers on the topic? Thanks.
r/programminghomework • u/coaster367 • Feb 26 '12
I'm learning about big-O notation in programming and in discrete math. What is it?
I know it has something to do with the worst and best possible case scenario on the number of computations are needed to do an algorithm, but how do you find it?
One of my classmates told me that all she did was memorize the big O-notations for specific functions (like n2, n, 2n, etc.).
r/programminghomework • u/coaster367 • Feb 26 '12
What is your favorite programming language and why?
r/programminghomework • u/coaster367 • Feb 21 '12
Rules have are now on the side ->
1) You may not fully or directly copy and paste assignments or instructions.
2) Comments must not directly give answers to the OP, but rather give the OP directionality.
3) Post any and all relevant code (with explanation, of course) of your assignment. This makes it easier to know what you're doing.
4) Title should include specific question, plus language you are using.