Have to learn how to use arrays and methods in python by next month

>have to learn how to use arrays and methods in python by next month,
Who else /failing college/?

Other urls found in this thread:

mochadoom.cvs.sourceforge.net/viewvc/mochadoom/mochadoom/src/m/DoomRandom.java?view=markup
i-programmer.info/programming/python/3942-arrays-in-python.html
clhs.lisp.se/Body/f_bt_and.htm
clhs.lisp.se/Body/f_boole.htm
clhs.lisp.se/Body/f_logand.htm
twitter.com/NSFWRedditVideo

...

Good luck learning how to use an array in python

kek

Kill yourself, you fucking retard.

Only brainlets fail college

>have to write 100 word essay on bitwise operators in lisp for next week

You kidding?
This is bait.
REEEEEE

>tfw have to learn how to declare variables in javascript by next year

HOW do you DO it programmerbros???

>have to submit the numerical value of the sum of all primes under 2 million by the end of the month or mommy is revoking my GBP
>literally can't stop playing video games and masturbating to anime
what's the easiest way to commit suicide?

I WISH I AM IN THE MOOD TO KID

>have to read data directly from memory addresses using Scratch

I'll bite.

When it comes to methods, what exactly are you struggling with?
When you say "arrays", do you mean the built in sequence types (lists, tuples etc.) or numpy arrays?

like how to use methods what they do and i don't know about the last part that you said but arrays

coding is more a philosophy to me. a way of life.

you sound like too much of a brainlet to be in college anyway

make my coffee you pleb

A method is a function that does not return a value. Im not going to write python code because I fucking hate the syntax.

void doSomething( String text )
{
text.concat("Add shit to text");
print(text);
}

A function is the same shit but it returns a value. When you use the function in your code, its treated as a value.


String doSomething( String text )
{
text.concat("Add shit to text");
return text;
}


Arrays are used to store shitloads of the same data types inside a single variable

Instead of doing


int number0 = 0;
int number1 = 10;
int number2 = 200;
int number3 = 3000;


you can do


int[] numbers = new int[4];

numbers[0] = 0;
numbers[1] = 10;
numbers[2] = 200;
numbers[3] = 3000;


If you cannot grasp these concepts, you will never become a programmer.

OP, ignore this entirely.

thanks but I don't understand what language is that is that c++ or cHash?

its almost C but the print function is made up and I dont remember if that's how one declares arrays, you shouldnt need to care about that.

Are you literally retarded? I learned in an hour.

yes well I am not a fucking cyber space wizard like you am I??

Don't you mean lists?

>Seriously
He must mean lists.
OP what don't you understand about lists?

Don't thank him he's misled you

I know this feel. Pic related, spend literally all day trying to solve this yesterday, and failed.
>find the max path of a binary tree
Literally impossible as far as I'm concerned.

>;o)
class dropped

turn it into a binary search tree then take the rightmost path

gg ez

A method is literally just a function in a class

class MyClass
def thisIsAMethod():
return "and it returns this"

>gg ez
>no code, not even pseudocode
Don't lie, you can't do it.

Currently learning about recursion in java and drawing it's stack trace. Pain in the ass for such a simple code.

r u srs m8?

DO I LOOK LIKE A FUCKING JOKE TO YOU?

Can't you just use dijkstra's algorithm? Then you just have to find a way to structure the data

Fucking brainlet retard.

Sort each row and add the first item of each row?
>i tried

I just finished a program which adds 2 matrices using multidimensional arrays

Are all of you people actually retarded? I'm not even getting a CS degree and I know all this stuff.

haha retard they're called nested for loop 2d array

The problem is from Project Euler, and:
>published on 31st May, 2002
It was a different time. Millennial twerps like you wouldn't understand the internet 15 years ago.

>> Have to learn BRST currents and loop integrals with Fadeev-Popov ghosts by next month.

STFU.

Use a dynamic algorithm.

>check each row
>find largest number in row
>is it a valid path ?
>no, check again using second largest num
>repeat until a valid path is found

literally this

>A method ist a function that doesn't return a value
No. Thats a procedure.

Method is an OOP term

Ah, but how would you check that it is a valid path? And does finding the largest number in the row save you any time algorithmically?

What if you select a high number in the upper layers and start ascending a path that only has low numbers? What if selecting a low number near the top takes you to a route that includes really high numbers? Like this:

1
2 1
1 1 9
1 1 1 9

You would be better choosing the 1 on the second row to gain access to the 9's.

Try again lads :^)

>I have to ___ in Python
>a problem

Post the exercise in text?

>find largest number in row
How do you deal with duplicates? E.g. row 15 has 98 twice. So how do you deal with 98 twice, and find its multiple indexes?
My code here starts from bottom and finds 98, the index of which is 2, which leads it to veer to the left. If I write to to go from top down, it goes down middle, but the path isn't max. So it's clear the first few largest numbers of any given row are misleading in predicting the max path.
TRIANGLE = [
[75],
[95, 64],
[17, 47, 82],
[18, 35, 87, 10],
[20, 4, 82, 47, 65],
[19, 1, 23, 75, 3, 34],
[88, 2, 77, 73, 7, 63, 67],
[99, 65, 4, 28, 6, 16, 70, 92],
[41, 41, 26, 56, 83, 40, 80, 70, 33],
[41, 48, 72, 33, 47, 32, 37, 16, 94, 29],
[53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14],
[70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57],
[91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48],
[63, 66, 4, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31],
[ 4, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 4, 23]]
x, x2 = 0, len(TRIANGLE[14])
MAX = 0
for i in TRIANGLE[::-1]:
j = 0
for ii in i[x:x2]:
j = ii if ii > j else j
MAX += j
index = i.index(j)
x2 = index + 1
x = index - 1 if index - 1 > 0 else 0
print(MAX)

yes, see

>class was being taught the basics of C++ functions
>I was still stuck on how to do arrays

And that's how I learned I was more creative than logical.

Don't the numbers have to be adjacent? I assumed you just had to compare 2 indexes equal to or equal + 1 of the next array to determine a path.

a = []
a.append('OP')
a.append('IS')
a.append('A')
a.append('FAGGOT')
for x in a: print x

Pretty sure a method is a function that belongs to a class.

> :^)
No bully

>Try again
I'm trying.
>Don't the numbers have to be adjacent?
Yes, that's what [x:x2] slices control. So it first finds the max of the last row, which is 98. list.index() returns the first index, so 98 is index 2, and next row is sliced [1:3], which is adjacent to 98 if it were represented as a binary tree/triangle. Then the next max is 66, then 91, at which point it's stuck on the left or [0:1]. This path isn't the max, so wrong. The problem is maybe the second index of 98 is the right path. I suppose I have to enumerate the rows.

What does this do. I'm OP

Python is so confusing gives me a headache lol

FUCK OFF I AM NOT OP

I heard self administered bullets work incredibly well in combating headaches

>Have to write equation to figure out all prime numbers from 0 to 20 by next year

I MEAN YOU ARE NOT OP

>tfw can't understand java object primitives

IT'S LIKE THEY WANT US TO FAIL

I never did CS, but wouldn't you just have to make a triangle of the same size, made out of empty values, and fill that triangle with the maximum possible value that you can get at each point? Then, if you have another triangle made out of "L"s and "R"s, you could store the optimal path as well for the end? This way, you only have to deal with the original next row, plus the one you built where you already know the most best way to get to the next set?

In the example triangle at the top, you'd get:

3
10, 7
12, 14, 13
20, 19, 23, 16

L, R
LL, LR, RR
LLL, LRL, LRR, RRR

Then you'd pick the largest value from the bottom set and figure out how to get to it by looking at the other triangle you made with L's and R's, so in this case, 23 which is made by going left, right, right. I guess you could make it more memory efficient by only having two arrays of the maximum size, where each step increases the number of spots taken by 1, does the adding to the existing things in the array and adds a character to the other one, and each of the lines above is really the state of the array as you take the next line of the triangle in.

This is how I learned what arrays are: reading about a cool application - pseudo random number generator tables. You create a table of random numbers (in this case Doom uses 256 numbers, sometimes they repeat) and have a function (P_Random) that advances the index by 1, then you slap that function in various parts of the code that runs in a constant loop.

mochadoom.cvs.sourceforge.net/viewvc/mochadoom/mochadoom/src/m/DoomRandom.java?view=markup

The random function provided by C compilers differs in behaviour, depending on which compiler and processor you use. That would cause a major desynch in multiplayer gaymes between computers of different specs.

>600 word essay due on thursday
>haven't even started

Get back to me when you have to learn C in under one month.....

>Then, if you have another triangle made out of "L"s and "R"s
There are 13684 possible roots for the 15-row triangle in the example. How would you do this? If the triangle is even larger, all possible routes are non-computable on current consumer hardware.

this wouldn't even work. Even if he wrote code it would be wrong.

A 15 row triangle would have 15 items in the largest row. Why would you make all the paths? You only need to know the best way to get to each of the ones on the row you're working on, so when the 15th row is consumed, you'd have an array of strings that is 15 strings large, and each string would be 14 characters long. That seems entirely computable.

Look at the example I made again:

L, R
LL, LR, RR
LLL, LRL, LRR, RRR

which is really being made like this:

[NULL, NULL, NULL, NULL]
[L, R, NULL, NULL]
[LL, LR, RR, NULL]
[LLL, LRL, LRR, RRR}

The maximum value and path to get that value at any point in the triangle isn't going to change the next time you look at it, so keep the string and values you had calculated before.

TRIANGLE = [
[75],
[95, 64],
[17, 47, 82],
[18, 35, 87, 10],
[20, 4, 82, 47, 65],
[19, 1, 23, 75, 3, 34],
[88, 2, 77, 73, 7, 63, 67],
[99, 65, 4, 28, 6, 16, 70, 92],
[41, 41, 26, 56, 83, 40, 80, 70, 33],
[41, 48, 72, 33, 47, 32, 37, 16, 94, 29],
[53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14],
[70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57],
[91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48],
[63, 66, 4, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31],
[ 4, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 4, 23]]
lst = []
n = 0 # Initial index
for i in TRIANGLE[14]:
MAX = i
print(i, '

>cHash
>>>>cHash
If you mean C#, then just write C#. And it's pronounced C-sharp, you utter fucking moron.

Ok, I changed my mind. This can't not be bait.

Try A* search, a good heuristic is the sum of the largest numbers from each row starting with the one below the current one.

i-programmer.info/programming/python/3942-arrays-in-python.html

You're welcome. It's not really that hard to be honest, you got it homie.

Underrated

>When your browser saves the name you were fagging with yesterday even though you were sure you had removed it

REEEEEEEEEEEEEEEEEEEEEEEEEĂˆEEEEEEEEEEEEEEEEEEEE

>Can't not
>Grammarfag
Tripfag BTFOS himself

>tfw have to learn how to change directory in linux by next year
Step it up

>tfw know about as much java as a poo in loo codemonkey and only have a rudimentary understanding of python

still know more than three quarters of this board

>Why would you make all the paths? You only need to know the best way to get to each of the ones
I don't understand: isn't finding out the path in your example finding all the paths? Thinking about this logically honestly hurts my head.

>200 word HTML assignment
>due tomorrow
>haven't started yet

What's wrong with the grammar? It cannot not be bait, i.e. it can only be bait.

Learn English before posting on an English website.

>Start on the second to last row
>max between two numbers under it added to each iteration
>repeat till you get to the top

Different user, seriously, wouldn't an A* search work? Or literally any other proper graph search algorithm. It seems like a trivial planning/maximisation problem.

Consider this part of the example:

Converting from: [L, R, "", ""]
to: [LL, LR, RR, ""]

We had to pick "LR" for the second item, instead of "RL", even though both would be paths to get to that point, only "LR" is acceptable, because LR is 3 + 7, whereas "RL" is only 3 + 4.

For any future calculation we do, it won't matter that we COULD go RL, that's not the best way to get to that point in the tree, and if the best path involves getting to that point, then we should be getting there by going LR. We don't know that it's the best way in general, but to get to that point, there is no better way. There could be something later on that makes a path that starts with "R" better, but we don't care about that right now.

When we take the next step, we only try out "LRL" and "LRR", because starting with "RL" isn't the best and there would be no point. That's how it's not calculating all the paths.

Don't ask me, I don't know.
>There could be something later on that makes a path that starts with "R" better, but we don't care about that right now
But how do you figure this out? That's seem like the final answer would be probabilistic, but what's the use of that if you can't be certain? Because in your example, you find out all paths and determine LR is largest. But if you didn't know RR was smaller, you'd be wrong. And LR misses out on RRR, which could also be larger than anything on the LR path.

Just drop out you fucking failure.

Are you fucking kidding me? Use the console. It's not trivial if you have never used a programming language but, if you have used any programming language before that's like a twenty minute deal.

>probabilistic
I don't think so.

That's why you still do RR. RR is unrelated to getting to the point that LR and RL get to. RR is a different point.

It works by calculating the best way to get to each point. In order for there to be a better path, you would have had to have made a mistake earlier. If the tree had gone:

3
7, 4
2, 4, 10000
8, 5, 9, 3

Then that point would still have an optimal value of 14, but RR would have a value of 10007. When you take the next step, the 10007 will clearly defeat 14. The value you're calculating is only the best for that very point in the triangle.

Yeah that's how I was thinking about it. Each number is a node, each adjacency is a directed path, each value of the number is an edge weight. The only change from Dijkstras is you are looking for the "highest" weighted path not the least

clhs.lisp.se/Body/f_bt_and.htm
clhs.lisp.se/Body/f_boole.htm
clhs.lisp.se/Body/f_logand.htm

Bro, you are going to want to sit down. You've been trolled pretty hard.

>have to learn how to draw a circle in GIMP by next 10 years
AAAA HELP MEEE

triangle = [
[75],
[95, 64],
[17, 47, 82],
[18, 35, 87, 10],
[20, 4, 82, 47, 65],
[19, 1, 23, 75, 3, 34],
[88, 2, 77, 73, 7, 63, 67],
[99, 65, 4, 28, 6, 16, 70, 92],
[41, 41, 26, 56, 83, 40, 80, 70, 33],
[41, 48, 72, 33, 47, 32, 37, 16, 94, 29],
[53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14],
[70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57],
[91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48],
[63, 66, 4, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31],
[ 4, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 4, 23]]

directions = ["","","","","","","","","","","","","","",""]
values = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

triangle.each_with_index do |row_array, outer_index|
directions_clone = directions.dup
values_clone = values.dup

row_array.each_with_index do |inner_value, inner_index|
if inner_index == 0
if outer_index == 0
directions_clone[0] = '-'
else
directions_clone[0] = directions[0] + "L"
end
values_clone[0] += inner_value
next
end

previous_index = inner_index - 1

if values[previous_index] > values[inner_index]
values_clone[inner_index] = values[previous_index] + inner_value
directions_clone[inner_index] = directions[previous_index] + "R"
else
values_clone[inner_index] = values[inner_index] + inner_value
directions_clone[inner_index] = directions[inner_index] + "L"
end
end

directions = directions_clone
values = values_clone

p "#{values}"
end

p "The highest value is: #{values.max}"
p "To get there, go: #{directions[values.find_index(values.max)]}"

>people actually having trouble with this problem

vector pyramid =
{{75},
{95, 64},
{17, 47, 82},
{18, 35, 87, 10},
{20, 04, 82, 47, 65},
{19, 01, 23, 75, 03, 34},
{88, 02, 77, 73, 07, 63, 67},
{99, 65, 04, 28, 06, 16, 70, 92},
{41, 41, 26, 56, 83, 40, 80, 70, 33},
{41, 48, 72, 33, 47, 32, 37, 16, 94, 29},
{53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14},
{70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57},
{91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48},
{63, 66, 04, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31},
{04, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 04, 23}};

main(int argc, char *argv[]) {
for(int level = pyramid.size() - 2; level >= 0; level--){
for(int index = 0; index < pyramid[level].size(); index++){
pyramid[level][index] = pyramid[level][index] + max(pyramid[level+1][index], pyramid[level+1][index+1]);
}
}
cout

How long does it usually take to get good at a programming language, I already took 2 classes of pure JS, I still think I'm a beginner-intermediate programmer, am I fucked

>class learning while loops in c++
>still stuck on cout and cin

Holy shit. 1 weekend is enough for that shit, OP. If this isn't bait, do literally any Python intro program online.

Won't this only find the greedy path through the triangle?

If I'm right, that doesn't even solve the optimal path for ending on the 8th item in the bottom row. Your answer gives 1064, but the best value for that position is 1068, by going 75->RRLLRLLRLRLRLR:
75+64+82+87+82+75+73+28+83+47+43+73+91+67+98 = 1068

vs. what I think yours does:
75+95+47+87+82+75+73+28+83+47+43+73+91+67+98 = 1064

I'm pretty sure the optimal is 1074 by going: 75->RRLLRLLRRRRRLR