[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 341
Thread images: 22

What are you working on, /g/?

Old thread: >>59342491
>>
OOP is comfy, COMFY!
>>
>>59348653
It doesn't fit most real world problems well. OOP is a forced meme.

Inheritance was invented to save disk space in the 80's.
>>
>>59348632
Forth = Lisp > Python > Malbolge > C > C++ > Idris > Haskell > every other language
>>
/r/ layers of abstraction java pic
>>
>>59348682
>Inheritance was invented to save disk space in the 80's.
I guess you're the kind of guy that doesn't call functions either.
>>
File: matrix.jpg (43KB, 471x318px) Image search: [Google]
matrix.jpg
43KB, 471x318px
How would you print in console pic related?

I seriously don't know how to approach this problem, i can't find an algorithm that works
>>
File: 1189020701069.jpgc200.jpg (19KB, 200x200px) Image search: [Google]
1189020701069.jpgc200.jpg
19KB, 200x200px
>>59348632
beginner here, where should i start with Oracle Java?
>i don't know a thing about programming
>>
>tfw every project idea you think of has already been done by someone else
>>
>>59348913
Try this
http://mooc.fi/courses/2013/programming-part-1/
>>
>>59348904
+--+--+--+--+
| 7|11|14|16|
+--+--+--+--+
| 4| 8|12|15|
+--+--+--+--+
| 2| 5| 9|13|
+--+--+--+--+
| 1| 3| 6|10|
+--+--+--+--+
>>
>>59348904
Loop through rows and columns?
>>
>>59348938
No shit. I declared 2 dimensional array but i don't know how to write a path which will populate the array

I think it can be done in O(n), there's no need for 2 loops, but i don't know how exactly
>>
>>59348894
I use OOP like everybody, but my opinion is that it's shit.
>>
>>59348980
You have to access every array element. That's n^2, if you count n as the side length
>>
>>59348980
>O(n)

Two loops doesn't make it O(n^2) you stupid nigger. You're not iterating n elements in both loops, you're only iterating 4 by 4, and guess what n is fucking 16.

Anyway, it's matter of fucking arithmetic. Start in the lower left and work your way diagonally upwards and then right. Or do it the mongoloid way, start with position (0, 0) and then do (1, 0), (1, 1) and so on and then just rotate it to the left.
>>
>>59349019
I clearly meant nested loop

I know where i should start and how to populate until i reach biggest diagonal. After that when things start to lower i don't know what to do
>>
>>59348632
working on my library
>>
>>59348980
There is nothing wrong with nesting loops. Don't let the morons on /g/ tell you otherwise. If you must, consider the following: each row is [width] long, and each element is at position [row] * [width] + [column].
>>
What books should one read to master modern C++14 far beyond knowing the syntax?
>>
>>59348924
Make an AI Waifu
>>
>>59349036
>I clearly meant nested loop
That doesn't make it O(n^2) either.

// n = 16
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j)


This is clearly O(n).
>>
>>59349036
Think of it more like traversing the edge.
>>
>>59349036
Nigga count array acceses not loop depth
>>
File: mods-are-gay.png (52KB, 613x410px) Image search: [Google]
mods-are-gay.png
52KB, 613x410px
/g/ clearly doesn't understand big-O notation. Pic related.
>>
>>59349046
Effective Modern C++ by Scott Meyers.
>>
File: 1474531095761.gif (27KB, 358x200px) Image search: [Google]
1474531095761.gif
27KB, 358x200px
>>59349066
And the n grows at m^2 pace, given a matrix m*m.
>>
>>59348721
Lisp > Forth > OCaml > Everything else
>>
>>59348632
I'm learning Python and I don't know why
>>
>>59349066
No, that's clearly O(n^2). There are cases where nested loops can have O(n), but this isn't one of them.
>>
>>59348894
>you only use functions to save disk space
No. They're incredibly useful for optimization purposes. And the convenience they offer that's next to free (and overall its probably to your benefit) shouldn't be ignored.
>>
>>59349164
>getting banned for pointing out that binary search is O(log2 n)

I've completely lost faith in this place.
>>
File: dog_without_sanity.png (451KB, 706x690px) Image search: [Google]
dog_without_sanity.png
451KB, 706x690px
>>59348934
I really appreciate it senpai
>have a pic of a happy doggo for your help
>>
File: 1437981269896.jpg (67KB, 654x539px) Image search: [Google]
1437981269896.jpg
67KB, 654x539px
>looking for an OOP language to implement TUI through ncurses
>don't want to go the C++ route
>in any other language it's necessary to learn how to wrap up the C headers
I could just reinvent OOP in plain C with macros magic during the all time I spent getting ready to start my project.
>>
>>59349164
Wow. Mods are assholes.
>>
>>59349255
>No, that's clearly O(n^2)
There are 16 elements. n is 16.

n^2 would be 256, 4*4 is 16.

>>59349259
No, I use functions to avoid code duplication. Just like I would use inheritance when two types share most properties and have the same interface.
>>
>>59349282
>wrapping a library is time consuming
Not really anon. It's boring but not time consuming
>>
File: sol01.png (25KB, 523x506px) Image search: [Google]
sol01.png
25KB, 523x506px
This is what's called a magic hexagon. It's filled with numbers from 1 to 19, and each three numbers in every direction sum up to the same number (except for the middle).
What would be the best way of finding every possible solution to this puzzle?
>>
>>59349298
Dense anon, most problems such as >>59348904 state something like: Create an array with N sides where N is declared as user input

That way your N isn't 16, it's 4 and your loops are O(n^2)
>>
>>59349298
Wrong. The number "16" doesn't appear anywhere in your code, except as a comment, while the number 4 actually is used in your code. So the ACTUAL n of your algorithm is 4.
>>
>>59349066
The problem is defined for square matricies
Aka nxn matricies
Aka O(n^2)
Is this your first algorithm analysis?
>>
>>59349298
>I use inheritance when objects share fields
Anon if you don't care at all about performance that's fine. But just go ahead and state that. Learn a functional language instead, they're much more productive.
>>
>>59349324
The matrix has 16 fucking elements, are you unable to count to fucking 16?

>create an array with N sides
Now, how does an array have a "side" in the first place?
>>
>>59349340
>"if you care about optimizations..."
Enjoy 1 gb of data every second that's immediately garbage collected
>>
>>59349313
>best way
What are you optimising for?
>>
>>59349350
time
>>
>>59349341
Matrix is an array with sides, you moron.
>>
>>59349331
It refers to anon's example, a 4x4 matrix of numbers.

>>59349335
Big O doesn't care at all about fucking matrices you stupid cunt. It cares only about the number of elements. The number of elements is 16.
>>
>>59349350
well, honestly, whatever as long as it doesn't take 4 hours to solve
>>
>>59349341
Ok so do it for a 2d array where n=17 then :^)

Youre the reason I have job security as a programmer btw
>>
>>59348980
>>59349002
>>59349019
>>59349066
>>59349255
>>59349298
Big O is meaningless in this case you faggots, as n is not growing over time.
>>
>>59349346
>garbage collected
I don't use a garbage collector so I don't see how that'd be possible.
Why you'd heap allocate data that's thrown away all the time is beyond me. I generally don't allocate something I don't aim to keep for quite a bit. Worst case I use a pool allocator for temporary data that'd get cleaned up once I'm done with it. Takes approximately 2-3 cycles.
>>
>>59349341
>Now, how does an array have a "side" in the first place?


Are you fucking retarded or what?
>>
>>59349353
>time
Who's time? Your time, user time, Cpu time? Can we do this offline and pack it? You're not giving anyone enough information to work with here.
>>
>>59349378
Big O is always relevant, its just these guys are fucking retards.
To "do an action to every element in this collection" is always at minimum O(n)
>>
>>59349335
>>59349255
>>59349324
So let me get this straight, you two think that this is O(n^2):

for (i = 0; i < 4; ++i) {
for (j = 0; j < 4; ++j)
printf("%3d ", matrix[i][j]);
printf("\n");
}


And this is O(n):
for (int k = 0; k < 16; ++k) {
print("%3d", matrix[k / 4][k % 4]);
if (k % 4 == 0 && k> 0)
printf("\n");
}


>>59349373
See above

>>59349380
Name a single functional programming language that doesn't use garbage collection.
>>
>>59349397
>Who's
It "Whose", my dear anon :^)
>>
>>59349340
>I don't use inheritance so my code is sooper optimized

Protip: Sepples still uses a vtable even though you're not using any inheritance.
>>
>>59349410
>literally does not understand mathematics
>>
>>59349413
>name a functional language that doesn't use GC
But you don't care about performance? You made it perfectly clear you don't so why half ass it was my point. You're saving developer time by using functional languages.
I don't generally get such luxuries but you do. I'm encouraging you to embrace your environment and be free.

So why is 1gb of garbage even a concern? It's probably faster than whatever junk you're currently writing if you're doing inheritance for that reason.
>>
>>59349413
>So let me get this straight, you two think that this is O(n^2):
Correct

>And this is O(n):
Correct

I don't see how this is difficult? In the first case n is 4 (and you've nested the loop, so it is 4^2) and in the second it is 16 (and there's no nested loops so it's n).
>>
>>59349446
See >>59349428

Also
>reusing functions is optimization
>reusing base class definitions is not

You're a retard. What do you think is the most optimized? Allowing the CPU to cache a single method shared by multiple derivative classes or having multiple functions doing the exact same thing for different types being flushed out of the cache all the time?
>>
>>59349413
Yes
>>
>>59349446
>1gb of garbage
That's 1gb of garbage PER SECOND
>>
>>59349438
>literally does not understand Big-O notation
It doesnt matter if your specific use-case is only ever going to have a set length, it's still an O(n) function.
>>
>>59349471
Then you are a moron.
>>
>>59349428
True, but I wouldn't expect anyone to cripple themselves by using virtual. Any oop programmer with integrity would run his own inheritance and polymorphism system if he was forced to use C++. I'm sure there's libraries for this if you're lazy.
>>59349470
Absolutely brain dead interpretation of what happens from someone who cannot have written a real program.

Please stop commenting on what's more optimal before you've profiled your code at least once.
>>
>>59349363
>It refers to anon's example, a 4x4 matrix of numbers.
4x4 = N^N = N^2

>>59349378
Big O has nothing to do with ``time"

>>59349413
>So let me get this straight, you two think that this is O(n^2):
>And this is O(n):
Yes, because you're changing what "N" refers to. It's possible for an O(n^2) to be just as fast as an O(n) algorithm for small inputs, but that will change when you increase the size of input.
>>
>>59349492
Irrelevant since we've already thrown any hope of decent performance out the window.
I've made it perfectly clear I'd object to it but if you don't care you don't care. I can see that point of view.
>>
>>59349514
>"i'll just implement my own type system within my C++ runtime instead of using the language one"

>Absolutely brain dead interpretation of what happens from someone who cannot have written a real program.
Instead of just spouting memes, please tell my how that statement is incorrect (because it isn't).
>>
>>59349505
No. If you write an algorithm that will say copy an input array into a size-80 buffer, and iterate over the entire buffer, then it's constant time, as even if the array it's given has only 4 elements, it's still going to iterate over the entire buffer.
>>
I'm surprised nobody here knows how to present big O to each other. But you're all wrong just from your description (but you may be having the right idea still).
>>
>>59349413
Dude the exact number of elements in array is not important

if you have entered a side of the matraix as N aka 4 and you need to insert every element in it and you use nested loop it's O(n^2), how hard is that to understand. We are all talking relative to the problem and you are being turbo autistic without actually reading what people write
>>
>>59349523
>4x4 = N^N = N^2
In the world of big O, n is the number of elements. Big O doesn't care if the data type is a matrix or a vector or a list or a fucking tree. It only cares about the number of elements.

>Big O has nothing to do with ``time"
It is literally an expression of time-complexity. How is that irrelevant to time?

>Yes, because you're changing what "N" refers to.
Absolutely not. N refers to the total number of elements in the matrix, which in a 4 by 4 matrix is 16.

> It's possible for an O(n^2) to be just as fast as an O(n) algorithm for small inputs, but that will change when you increase the size of input.
This is irrelevant, because the input is the same. An matrix with 16 elements.
>>
>>59349552
>Dude the exact number of elements in array is not important
Lrn2 big-o
>>
>>59349576
>An matrix with 16 elements

THIS IS NOT INPUT YOU FUCKING RETARD

INPUT IS ******A SIDE OF THE MATRIX********
>>
>>59349591
Typing in all caps doesn't make you right, anon. This anon >>59349413 is correct. It's the number of passes on each individual element that matters.

In anon's first example, the algorithm is O(sqrt(n) * sqrt(n)) which, quess what, is fucking O(n).
>>
>>59349505
>>59349523
Big-O has to do with an input size n. If the input size is never changing, it is completely meaningless.
>>
>>59349619
>If the input size is never changing
What if the input is changing?
>>
>>59349545
What statement specifically?
That your compiler would not optimise your function calls? That you'd structure your code in complete disregard for the icache? The first one is simply not true for most compilers. They're pretty darn smart and will ignore your user level types in favor of the underlying representation (you mainly store ints, floats and pointers, the operations are done on types such as these, not your fuckMyShitUp abomination). The second is up to you. I suppose this might be what happens for you but you've made it clear you didn't care about performance so I don't see the issue. Inheritance doesn't save you either way since the cost of all those cache misses will just kill you and it impacts the future operation of your program since you've just took a sledgehammer to the cache. With instructions it's not hard for the cpu to prefetch outside of conditional calls and dynamic dispatch through vtables (absolutely horrible).

But I presumed this to be known. You're in way over your head if it wasn't. Why are we talking about the effects of inheritance in c++ when we don't even know the basics of modern computers?
>>
File: 139830029252.jpg (26KB, 400x562px) Image search: [Google]
139830029252.jpg
26KB, 400x562px
>mfw this thread
>>
>>59349619
Big-O has to do with the computational expense of an algorithm, with relation to size-n
Allow me to repeat
>It doesnt matter if your specific use-case is only ever going to have a set length, it's still an O(n) function.
>>
>>59349614
We are not talking about any matrix, we are talking about specific problem where user inputs a side of the fucking matrix N and the matrix prints >>59348904

If you use nested loop that goes to N both times in the specific problem above that IS O(n^2)
>>
>>59349642
>he thinks the compiler manages the icache
>he thinks the compiler is able to optimize three different function definitions as one function
>>
>>59349619
This is the engineering perspective. Not the computer quack perspective. Big O is for computer scientists.
>>
>>59349655
Where has anyone said anything about inputting a side? (protip: linking to your own posts aren't valid).
>>
>>59349679
about 5 times in the thread already.....
>>
>>59349665
Not what I said at all. The icache is managed by the Cpu. Decent compilers are instruction cache aware and will not inline every function in existence just because they think it's less instructions (no calls).
>compilers can't reason about types
They can though.
If they're vastly different functions then they probably shouldn't be merged. But if they were vastly different functions then why are we talking about them as if inheriting them would solve the situation? The equivalent for inheritance would be three different overloaded functions that do completely different things. Ignoring how mental you'd have to be to write that it's essentially the same thing as writing 3 different non-member functions.
>>
>>59349576
>n is the number of elements.
No. It's the size of the input.

>It is literally an expression of time-complexity. How is that irrelevant to time?
It expresses the number of basic operations required to execute the algorithm. Which has nothing to do with ``time", which isn't even a meaningful concept in mathematics.

>Absolutely not. N refers to the total number of elements in the matrix, which in a 4 by 4 matrix is 16.
False. See above.

>>59349619
Which is about mutability, not time. Saying a variable is mutable does not imply time exists.
>>
>>59349695
Linking to your own posts aren't valid.

Anon asked how you would generate such an array. Why would anyone input a """""side""""" of that array (what the fuck is inputting a side of a matrix even mean).

It stores the fucking elements from 1 to 16 in a zig-zag fashion, you'd do this with a O(n) algorithm.
>>
>>59349363
Ok most of the people disputing you can't explain big O properly so allow me:

Big-O analysis (with concern to time) only cares about two things:
-The "basic operation"
-The "size"

Now let me just clear something up: Big-O analysis is only worried about:
> The function that maps (asymptotically) the size of the input to the number of times that the basic operation will be performed\
It does NOT matter how the loops are rolled or unrolled or written or anything like that, these two algorithms do the exact same thing:
#in pseudocode

for i from 1 to n
for j from 1 to n
print([i][j])

#there is no difference between these two

for i from 1 to n*n
print(array[i/n][i%n])


So if we have to print every element of a list once, the problem size n will equal the length of the list, and
the basic operation (print) will be performed n times. This is a O(n) or "linear time" algorithm.

Now in terms of our current problem, the code you gave as an example does not have any inputs. It has 4s and 16s written write into the code, there are no input variables. The loop in both will *always* run 16 times. This is a O(1) or *constant time* algorithm.

-------------------------

Of course I am just being pedantic by saying that, obviously we are looking for the Big-O for a matrix of arbitrary size, so lets think about this.
The original post with the question only reads "How would you print in the console pic related?". So if you assumed he always wanted to print the same matrix I would of course just recommend he does:
print("7 11 14 16\n4 8 12 15\n2 5 9 13\n 1 3 6 10\n") #with maybe nicer spacing but whatever

And call it a day, but I think it was implied that he wants to do it for matrices of arbitrary size.
We can make one of two assumptions, either that the matrix always has to be square or that the matrix can be any rectangle (which the pattern could easily be fit into as well).
...continued momentarily... (no arguments yet!)
>>
>>59349679
>you don't matter in this conversation
I'm not that guy but that's incredibly rude to say in a discussion. And makes you look stupid.
>>
>>59349713
>Why would anyone input a """""side""""" of that array (what the fuck is inputting a side of a matrix even mean).

End of dicussion. Bye.

Should have known you're trolling
>>
>>59349724
Anon is trying to make his original post sound less dumb by back-pedalling and rephrasing the original problem statement. I'm just pointing that out.
>>
>>59349718
>two things
Well big O is more generic than that but usually that's what's you care about.

But this is a very good explanation anon.
>>
>>59348632
I'm learning python and I don't know why
>>
>>59349736
Nobody talked about inputting a side. WE ARE TALKING ABOUT HOW TO GENERATE THE FUCKING ARRAY IN >>59348904
>>
wow /dpt/ at it again
>>
>>59349749
Shut up. This is better than c-ancer memes and /pol/ shit.
>>
>>59349761
You mean that half of the people failing to understand a basic concept and not willing to admit they're wrong after they've been told why are they wrong is any better than any other shitposting?
>>
>>59349748

The problem says: Insert N which is a number of elements in one side of the N*N matrix that prints the numbers in following pattern

pattern being that matrix above
>>
Ok, I have a serious question. For example, I want to implement an algorithm that has many subroutines, and some of them have subroutines of their own etc. and all of them have their own inner variables, so to speak.
Now, many of those subroutines take a lot of variables of the routine that called them as input, and as the procedure stack grows some of the routines can have a really long signature, and not only that, but some of those need to change their input parameters (mutate them), some don't, and that leaves me with a mess of passing pointers, references or just passing a copy.

How smart or clean is it to make not a function representing the algorithm that then calls other procedures, but a class that has only the algorithm as a public method, all other subroutines as private methods, and their variables as private fields so that I skip the hassle with passing input. The idea is that the sub routines just grab what they need when they need it instead of making long signatures and caring wthere I passed a copy or not etc.

TL;DR Should I stick an algorithm in a class as the only public method and then make every other subroutine and variable used in the process as private methods and fields?
>>
>>59349702
Explain to me how you think the compiler would be able to "merge" these functions

Header file:
struct A
{
int a;
};

struct B;
struct C;

void set_A(struct A& a);
void set_B(struct B& b);
void set_C(struct C& b);


a.cpp
void set_A(struct A& a)
{
a.a = 2;
}


b.cpp
struct B
{
int a;
int b;
};

void set_B(struct B& b)
{
b.a = 2;
}


c.cpp
struct C
{
int a;
float c;
};

void set_C(struct C& c)
{
c.a = 2;
}



The compiler cannot possibly see the different class implementations, nor can it see the different functions.
>>
>>59349718
(continued)

So yes, either we are assuming that we are printing to a X by Y sized matrix where X = Y (square), or an X by Y sized matrix where X doesn't *have* to equal Y (rectangular).

I put forth to you for a moment that the problem size is actually two variables (for now): n & m
(suspend your disbelief as I will explain the rationale)
n = the width of the array to print
m = the height of the array to print

Your counterargument is that the input is simply size n where n is the number of elements in the matrix. That makes sense! However there is a good reason to not consider it as the size,

The first reason is as follows:
n = 1: Ok, we have a 1x1 matrix, that is fine
n = 2: 2x1 or 1x2 matrix, why not?
(skipping a couple number)
n = 5: uh... well this cant make a matrix but whatever
n = 7: neither can this
n = 13: this is getting kinda awkward
...

The second reason, lets say the algorithm isnt just for square matricies but for *any* rectangular matrix:
"Oh id like to do a 3 wide and 5 high matrix!!" says your GF wanting to see Tyour *amazing* algorithm:
What do you put in for n? well 3x5 = 15, but now how does the computer know how to do 3x5 vs 5x3? Combining the sides into one number adds ambiguity into the input.

Now imagine instead the problem size was n & m (or if square, just n because m = n):
n,m = 1,1 fine!
n,m = 7,13 fine!
n,m = 13,7 fine!
n,m work as long as they are both integers >= 1, that is much more general!

Also:
n,m = 7,13
and
n,m = 13,7
Output two distinct results! This is very good too

(one more)
>>
>>59349786
>The problem says: Insert N which is a number of elements in one side of the N*N matrix that prints the numbers in following pattern
This creates an matrix of N*N, so from a big O point of view, n = N*N.

Bot a nested loop where the inner and outer loop goes to N (or sqrt(n)) elements or a loop where k goes to N*N (or n) are linear time you fucking dolt.
>>
>>59349838
(finally)

Now all this wishy washy argument aside, in *actuality* this mostly comes down to the problem statement, which was admittedly vague.

If the problem read *print a list of number of length n in this square pattern* then actually you would be correct.
However the problem didn't "read" at all and so we are left at this impasse.

The only thing I can do is try to show you why the most intuitive solution is to have "n" or "n,m" as the size where they are the sides of the matrix, which would then mean the "print" statement is run n*n or n*m times (O(n^2) or O(m*n)).
If you disagree fine, but at least consider what I've said! : )
>>
Guise
I'm fucking confused.
I'm supposed to write space invaders in C++, but properly, not shitty.
So I have to display my enemies. Whose responsibility is it? Should I keep a list of enemies, who have a pointer to the root window and draw themselves? Or should I let the root window keep a list of pointers to the enemies and let the root window call the visualisation?
>>
>>59349878
I think you should tell people what are you using for drawing the game before anyone can help you.
>>
>>59349878
The computer's responsibility.
>>
>>59348924
if it's anything simple, then yea. where do people get this idea that you can never do throw away projects?
>>
I have a problem with chromedriver on ubuntu.
#!/usr/bin/python3
from selenium import webdriver

print('1')
driver = webdriver.Chrome()
print('2')
driver.get('http://www.google.com')
print (driver.title)


command prompt prints out 1, but then stops and nothing happens
im pretty sure I installed everything correctly
anyone having an idea whats going on?
>>
>>59349955
They can't because they can't. The statement before this one is false.
>>
>>59349878
(I'm most likely rightfully assuming you are doing this in an object oriented fashion)

If it were me (although I am not skilled in game design)
Your "Enemy" class should have a draw method
Your main class or function or whatever will have some sort of list or array or vector or whatever of all the enemies that currently exist
Each "frame" the main class/function should loop through this list enemies and do (pseudo code):
for (int i=0; i<number_of_enemies; i++) {
enemies_container[i].draw()
}
>>
>>59349282
golang? fzf is written in it and has a simple TUI.
>>
>>59349913
That shouldn't matter, because I don't need code examples, I need design examples.
But I realised the root window isn't allowed to draw it at all, since it isn't its responsibility.

Thanks for trying though
>>
>>59349410
when you talk about minimums i think the notation is different, it's theta(n) or omega(n)
>>
File: 20170311_112905.jpg (2MB, 3264x1836px) Image search: [Google]
20170311_112905.jpg
2MB, 3264x1836px
I-I bought this
( ̄▽ ̄)ノ
>>
File: ed_succ.png (37KB, 650x650px) Image search: [Google]
ed_succ.png
37KB, 650x650px
Who here has written a program in fortran?

Name two (2) good fortran books.
>>
>>59350047
Jokes on you, I only read the help from Visual Fortran.
>>
>>59349993
>golang's oop
>anything but abomination
>>
>>59350072
idk, man i've never written a line of golang. it's just a suggestion.
>>
>>59350047
FORTRAN is trash.
>>
I want to split input strings based on when it changes from a number to a letter.

e.g. If I get 10HDZ, I want to split it into 10 and HDZ
Is regex the tool for that? Writing this in C#
>>
>>59350124
It at least has a use case.
>>
>>59350158
Is the input format always a bunch of numbers followed by a bunch of letters or can it vary?
>>
>>59350189
It will either be numbers followed by numbers, with no intermixing (i.e. [0-9]+[A-Z]) or it will be only letters, in which case I only care about the first character.

The latter case is easy enough to deal with, just check the first char and if its not a digit split it at the index.
The former case is where I'm not sure.
>>
>>59348985
>I use OOP like everybody
Speak for yourself, subhuman.
>>
>>59350210
So something like this?
(?<digits>\d+)?(?<letters>[a-z]+)
>>
File: 1473738270724.jpg (8KB, 184x184px) Image search: [Google]
1473738270724.jpg
8KB, 184x184px
>>59350124
Yes, it is. So?
>>
>>59349878
>So I have to display my enemies. Whose responsibility is it?
The renderer.
Submit a list of things to draw to the render system.
Concretely: each enemy is represented by a bitmap, the renderer should have a growable list (array) of things to draw each frame and functions pushbitmap() which adds to the list and flushrenderer() which loops over the list, does whatever it needs to do to draw a bitmap and sets the list to empty.
>>
>>59350210
>it will either be numbers followed by letters
I'm dumb

>>59350222
I assume that's not intended to be valid regex?
But yeah, it'll be like 10HZCD or 8VHJVIX or 9D or 9182ICZJ, etc
numbers then letters.
I guess I could just step through the string until I reach a non-digit character and split it at that index?
>>
>>59350158
>>59350210
>>59350256
C# is shit.
CL-USER> (cl-ppcre:split "([a-zA-Z]+)" "10HDZ" :with-registers-p t)
("10" "HDZ")
>>
>>59350256
([0-9]+)|([a-zA-Z]+)
This will accept either a group of 1..n letters or 1..n numbers but not a combination of both.
In 135kjk153lkj it would capture the groups
135, kjk, 153, lkj
>>
>>59349878
i recommend having a game state/scene manager. that way you have a meaningful abstraction for things like menus, pause screen, and levels/gameplay states. it's much easier to organize the relevant code at that level (and much easier to set up transitions between states) than to manage all your game state directly inside a loop in your main method or something similar. in this case you could have your list of enemies in your level/gameplay states, that way their updating/drawing can be dependent on the update/draw behavior of the state, and their lifetimes will be scoped to the level
>>
>>59350278
So, regex then.
string[] serials = Regex.Split(input, @"([0-9]+)([a-zA-Z]+)");


thanks bucko

>>59350292
gracias
this'll make this codebase so much cleaner
>>
You know what, /dpt/? Tomorrow go find the Dive into python on the web. Don't fucking worry if you get nothing at first. Then navigate to python.org and learn the standard library by bloody hard. Then grind, and I meant it, bitch, you grind the pythonian coding convention PEP8 until you know it by rote. When you write your first own imageboard, picking up html+css in the process, time to download and study any python-based asynchronous web-server. I recommend Tornado or Gevent. By the time you alter your imageboard so that it can at least manage giving off 5k request per second, you'd be ready to move on: the intriguing world of high-load programming at your feed. Apache Hadoop, ultrafast asynchronous key-value storages, MapReduce. It won't be long for you to laugh at the fuck ups of NEETs and poor Slavs that live off by sucking cocks and no longer than in half a year your income will grow to the point when any bitch will get wet from only a mention of your salary.
>>
>>59350256
>I assume that's not intended to be valid regex?
https://regex101.com/r/Pp6lYK/2
>>
daily feels thread when??
>>
>>59350333
Oh. Neat. Didn't know you could name groups like that. This is much nicer than regexr
>>
>>59350324
>Python
Opinion discarded.
>>
>>59350346
Fuck you.
Signed,
Smug Lisp weenie
>>
>>59350308
If you are using my example please note there is a
|
between those two bracket groups
Also I don't think "Split" is the function you want although I could be wrong (I believe in python it would be called "findall" im not sure about in C#)
>>
>>59350371
He is splitting a string. He needs split.
>>
>>59350382
Yes but if he uses that regex for a split it wont return what he wants as
>>
Everytime I run my exe file it quickly closes without doing what I want

How do I run my application outside of an IDE/Terminal
>>
>>59350351
t. NEET
>>
>>59350389
I've already demonstrated in a superior language the split function is what he needs. If his split function cannot do this, the language is shit.
>>
>>59350394
You probably need to put a line at the end that will wait for the user to press enter or something
otherwise once its done it will just close (and most small programs can finish faster than you can see them)
>>
>>59350394
That's intended. If you want to see the input simply open the terminal and run your program through the terminal.
>>
>>59350405
My dude, he just posted a split function using ***MY REGULAR EXPRESSION***, i am simply saying that will not work with ***MY REGULAR EXPRESSION***

I did not say anything about ***YOUR REGULAR EXPRESSION***
>>
>>59350416
Then your regular expression is wrong.
>>
>>59350414
right, but I want to run my program without having to manually do it from the terminal
>>
File: isit.png (43KB, 859x506px) Image search: [Google]
isit.png
43KB, 859x506px
>>59350426
>>
>>59350446
Great, now use this in a split function.
>>
>>59349825
Opinion pls.
>>
>>59350483
Discard OOP.
>>
File: itiss.png (3KB, 406x117px) Image search: [Google]
itiss.png
3KB, 406x117px
>>59350467
test = "135078asikd1357kadf13857kdjgh"
a = re.findall("(([0-9]+)|([a-zA-Z]+))", test)
print("Test String: " + test)
for i in a:
print(i[0])


it is not for a split function, thats all i was saying
there is nothing wrong with yours, he should use yours, why argue?
>>
>>59348904
just oeis your numbers and you'll find the right algorithm eventually.
>>
>>59350495
But what about huge function signatures?
>>
>>59348924
Oh yeah? Where's my waifubot then you lazy fuck?
>>
int i = 5;
i = ++i + ++i;

What's the result?
>>
>>59350596
Demons flying out of your nose
>>
>>59350596
I got it wrong :^)
>>
>>59350629
No you didn't, at least not necessarily. In C and C++ that's undefined behaviour.
>>
>>59350596
i = 12
>>
>>59350596
Rule of thumb is to never do more than one ++ or -- in one declaration, plus never do anything else while you're incrementing/decrementing
>>
I'm having trouble displaying 4chan images in a browser via html. I'm using the <img> tag, but the link
http://i.4cdn.org/g/1450659832892.png
refuses to display while other links work. Can someone offer some advice?
>>
>>59350596
13
>>
>>59350517
To waste your time.
>>
>>59350638
Ah ok, I guessed 13 but 14 is what i got on repl.it
Both make sense I suppose
>>
>>59350543
>>59349053
I will get started ASAP
>>
>>59350676
2shay
>>
>>59350679
Clang and GCC will give different results for example. Enable -Wsequence-point
>>
Languages without totality checkers pls go
>>
File: red_pres_saxlind1.jpg (34KB, 460x574px) Image search: [Google]
red_pres_saxlind1.jpg
34KB, 460x574px
>>59350740
haha aa
>>
>>59350667
https://en.wikipedia.org/wiki/Inline_linking#Server_side
>>
>>59350756
Thank you
>>
I got this algorithm that is used to multiply big numbers faster than the standard grade school algorithm.
It's an algorithm that uses divide and conquer to use as many "cheap" operations as possible to make the algorithm have a better time complexity.
I just don't understand the whole procedure, can someone explain the pseudo code in simple terms.
Algorithm multiply(u,v,threshold)
Input: u, v big numbers stored in an array
threshold - the maximum length where it is "cheaper" to perform ordinary multiply
Output: a big number that is the result of u*v

n ← max(digits(u),digits(v))
if u=0 or v=0 then
return 0
else if n<=threshold then
return ordinaryMultiply(u,v)
else
m ← n/2
x ← u divide 10^m
y ← u rem 10^m
w ← v divide 10^m
z ← v rem 10^m
r ← multiply(x+y,w+z)
p ← multiply(x,w)
q ← multiply(y,z)
return p mult 10^(2m)+(r-p-q) mult 10^m + q
>>
>>59350921
>division
>faster than multiplication
>>
How do I know if I'm autistic?
>>
>>59350746
Languages without fully compile-time IO pls go
>>
File: autism.jpg (137KB, 553x783px) Image search: [Google]
autism.jpg
137KB, 553x783px
>>59350952
>compile-time IO

>>59350940
Pic related
>>
>go to 4chan-x repository
>its fucking coffeescript

How do I convert this clusterfuck back to readable javascript so that it's actually possible to understans what it's doing?
>>
Which reddit memes should I use at my new job to fit in? Most people here seem to love that website.
>>
>>59350952
Languages without read-time IO pls go
>>
>>59351061
>read-time
pleb languages
>>
>>59351042
The ironic racist/misogynist is a surefire way to fit in. Either use a colleague as your ironic ""victim"", or do it to the lunchlady or whatever. It works 100% of the time anyway.
>>
>>59351061
>read-time
>read
>>>/r/ibbit
>>
>>59351061
>IO
extra-pleb
>>
File: king jeremy the wicked.png (263KB, 2488x1348px) Image search: [Google]
king jeremy the wicked.png
263KB, 2488x1348px
hi /g/uys!
what's happening?
i just quit my trucking job to focus on learning to program through the week. gonna be driving for uber on the weekend so as not to starve.
main focus is cross platform app dev, so will be learning c# and xamarin.
>>
>>59351071
>>59351086
>>59351088
>he doesn't do all his computation before it gets compiled
>>
>>59351091
At home
Drawing pictures
Of mountain tops
With him on top
Lemon yellow sun
Arms raised in a V
Dead lay in pools of maroon below
>pearl jam
euphemism for the jism
so anon, you like male ejaculate?
>>
>>59351091
>Xamarin
wew
>>
>language without I/O

What the fuck is this meme?
>>
>>59351123
i actually write proofs for most of my programs by hand before compiling.
>>
>>59351000
https://github.com/decaffeinate/decaffeinate
>>
>>59351144
It's a Haskell meme.

Apparently, I/O is a side-effect.
>>
>>59351142
???
>>
>>59351144
It's not a meme you tard. Any CS student studies plenty of examples of languages without I/O.
>>
>>59351157
I am worried
>>
>>59351144
What isn't clear to you?
>>59351153
Hasklel has IO, retard.
>>
>>59351000
>read-able javascript
nice meme
>>
>>59351161
please elaborate
thanks
>>
>2017
>CPP can only compare integers
why is this allowed?
>>
>>59351162
>Hasklel has IO, retard.
I didn't say it didn't, retard. It uses some stateless burrito combined with heavy mental gymnastics to pretend that it's only the runtime that gets tainted when doing IO.

It's still an Haskell meme.
>>
File: 1483135677975.jpg (189KB, 495x700px) Image search: [Google]
1483135677975.jpg
189KB, 495x700px
>>59350041
>Nobody cares about my cute Japanese programming purchase
>>
>>59351158
Languages such as...?

>>59351153
Sure it is... An absolutely vital one.
>>
>his language doesn't have typeclasses
>>
>>59351171
I don't think .NET works outside of MS environment properly.
>>
>>59351185
The empty language, for example.
>>
>>59351170
I'm used to all the bullshit. Better than shitscript.
>>
>>59351182
I don't know Japanese, gomenne kudasai me, sempai
>>
>>59351191
Does it contain itself?
>>
>>59351188
actually the ubiquitous nature of .NET is the primary draw
>>
>>59351205
Java is more ubiquitous
>>
>>59351182
What is it? The cover doesn't lead me to believe it has anything to do with programming.
>>
>>59351202
Yes.
>>
>>59351180
>stateless
>husklell
Now it's clear you know nothing about the subject.
Also, you're pretty funny for saying "apparently". or did your parents really fail this badly? i'm sorry if that's the case, didn't mean to degrade you or anything.
>It's still an Haskell meme.
Perhaps on some other "website".
>>
>>59351219
.NET = framework
Java = language
i'm just a n00b and i know dishit
>>
>>59351176
what do you mean?
Comparisons is usually
> (greater than)
< (less than)
>= (greater or equal to)
<= (less or equal to)
== (equal to)
!= (not equal to)

In C++ you can do this with anything.
With integers, floating point, strings or your own classes.
>>
>>59351180
>an Haskell
Unless you practice h-dropping, you undoubtedly sound like a moron.
>>
>>59351237
>In C++ you can do this with anything.
Absolutely disgusting
>>
>>59350041
what language does it use?
>>
omg! new discovery!
taco bell packets make cold pizza hut awesome
>>
>>59351234
Java environment, for sure.
>>
>>59351237
C preprocessor my man
>>
>>59351229
Are you severely autistic or is Haskell your waifu or something?

I'm referring to the gazilleon /dpt/ threads where the triggered Haskell and the claims that IO is impure and then someone mentions the IO monad and then suddenly we're discussing states in Haskell and how monads are burrito containers. And then there's usually a couple of guys in the following /dpt/ making claims that they're rewriting X in Haskell and removing IO.

It is a fucking meme, don't take it seriously. That's not what memes are intended for.
>>
>>59351266
the JRE? < .NET;
>>
>>59351271
I learned to program just to shitpost on /dpt/.
>>
>>59351271
It's simple. Replace IO with Free.
>>
>>59351227
Don't you see the huge LLVM on the cover?
It's a japanese programming guide for LLVM (http://llvm.org/) with cute girls on the cover. It was the OP image for /dpt/ a while ago and I had to get it
>>
>>59351249
>sound
Do you read out 4chan posts internally?
>>
>>59351292
LLVM is just the name of a Taiwanese cartoon.
>>
>>59351252
why?
It is very useful.
Say you are implementing an A* algorithm.
You make an object that represents a graph node.
You then need to sort them based on the heuristic and the actual cost.
By making each nodes comparable, you can then use existing sorting algorithms.
Programming is all about describing how computers should solve your problems.
>>
>>59351271
I fucking despise Haskell. I just need to make my compiler self-hosting so I can be done with this I/O-ridden shitlang.
>>
>>59351298
My screen reader reads them out loud for me.
>>
>>59351268
are you saying the pre processor can only compare integers?
>>
>>59351298
Yes, sometimes even out loud in different accents.
>>
>>59351314
So, at least technically, it's actually your screen reader that sounds undoubtedly like a moron?
>>
>>59349413
They're both O(1) since there is no "N" to be bounded by.
>>
>>59351308
See, the meme is already catching on.
>>
File: 20170311_132400[1].jpg (2MB, 3264x1836px) Image search: [Google]
20170311_132400[1].jpg
2MB, 3264x1836px
>>59351300
Should I post pictures from the inside?

>>59351253
Mostly C++, but it looks like it's meant to be used with other languages too because I see some references for Java, etc.
>>
>>59351308
Honestly, if you find IO a pain in Haskell then you're probably a fucking idiot
>>
>>59351334
It does, and this means you also undoubtedly sound like a moron, since what my screen reader produces is merely a facsimile of you.
>>
>>59351362
Lazy I/O is an abomination.
>>
>>59351356
>Should I post pictures from the inside?
Yes, post the anime compiler from within.
>>
SQ:
does anyone actively program in BASIC?
>>
>>59351365
I see.
>>
>>59351368
t. programlet
>>
>>59351362
Not just in Haskell. Actually I find it to be better than almost everything else. It's just that it also pisses me off to no end.
>>
>>59351371
No. Last time I programmed anything in BASIC (Visual Basic) was in 2001.
>>
>>59351368
write a sticken function
>>
If you're using an English programming language, you should name variables, functions, etc. in English too.
>>
>>59351404
I prefer to use Greek letters and math symbols.
>>
>>59351388
>sticken
Gesundheit.
>>
>>59351404
I do
>>
>>59348904
>>59348904
>>59348904
>>59348904


FUCKING FINALLY, I SOLVED IT

int[,] arr2 = new int[n, n];

int CoordX = n-1;
int CoordY = 0;
int incrementorC = 1;
int iteratorX = 1;
int iteratorY = 0;


for (int i = 0; i < incrementorC; i++)
{
if (CoordY == n - 1)
{
arr2[CoordX, CoordY] = incrementorC;
iteratorY++;
CoordY = iteratorY;
incrementorC++;
CoordX = 0;
}

if (CoordX == n - 1)
{
arr2[CoordX, CoordY] = incrementorC;
CoordX -= iteratorX;
iteratorX++;
incrementorC++;
CoordY = iteratorY;
}
if(incrementorC == n*n+1)
{
break;
}

arr2[CoordX, CoordY] = incrementorC;
CoordX++;
CoordY++;
incrementorC++;

}


Now to look for optimization
>>
>>59351417
>>59351404
I'm using a Latin derived programming language, so obviously I'm using Latin.
>>
>>59351371
No, but I actively tend to program in BASIC.
Currently learning Lua.
>>
>>59351425
Disgusting.
>>
>>59351434
Go ahead, write me a better solution
>>
>>59351417
Get out.

æ, þ, ð, and ƿ are permissible under certain circumstances, though.
>>
>>59351432
u wot 8
>>
>>59349413
both are O(N).
You do one print operation for each elements in the matrix.

The second one is slower, but constants are irrelevant when looking at complexity.

Complexity is not just looking at the number of for loops.
>>
>>59351432
>Currently learning Lua.
Why?
>>
>>59351449
Lua is very similar to BASIC, so I want to program in Lua to feel like I'm writing BASIC.
>>
>>59351455
REEEEEEEEEE

IT'S A NESTED LOOP

REEEEEEE

IN THE FIRST N=4

REEEEE

IN THE LAST N=16

REEEEEEEEEEEEEEEE
>>
>>59351455
We already went through it, that post is essentially true but the context (which he wasn't aware of) was that user input is a side of a matrix, not total number of elements in the array
>>
>>59351455
PLEASE NO
>>
>>59351483
It doesn't fucking matter what the side of the matrix is, it's still O(factor of total fucking amount of elements).
>>
>>59351483
int n = atoi(argv[1]);
int array[n * n * n * n * n * n];

for (size_t i = 0; i < sizeof(array) / sizeof(int); ++i)
{
// HURR DURR THIS IS O(n ^ 6)
}
>>
>>59351528
THE NUMBER OF ELEMENTS IS N^2

N SQUARED
POLYNOMIAL
>>
>>59351551
See >>59351544

The ALGORITHMIC COMPLEXITY is not squared. It runs with LINEAR
>>
>>59351528
It does, because you solve the problem using that side, not total number of elements

Essentially you perform calculations on that variable alone
>>
>>59350596
13?
>>
>>59351551
Big O doesn't denote number of elements, it indicates time complexity. In both cases, the time complexity is linear given that the number of elements are the same. O(n) denotes linear time complexity.

>>59351567
See above.
>>
>>59351544
n=1: basic operation performed 1 time
n=2: basic operation performed 64 times
n=3: basic operation performed 729 times
n=4: basic operation performed 4096 times

so how isnt this O(n^6) again?
>>
>>59351551
It is rather O(N*M).
Where N is the number of rows, and M is the number of columns of the matrix.

printing all elements in a structure is a linear operation.
>>
>>59351583
If you don't understand the difference between the variable n and the n in O(n), then you should honestly just commit sudoku.
>>
>>59351583
>basic operation performed N times
Yes, on ***N*** elements. Not on N^(1/N) elements.
>>
>>59351483
>side of a matrix
The correct term is dimension. "Input is a side of a matrix" can mean anything from one row/column or half of the matrix.
>>
>>59351595
 Problem: Write a program, which creates square matrices, the size of the matrices will be read from the console


Are you saying something like this is not O(n^2)?

            for (int row = 1; row <= n; row++)
{
int incrementor = row;
for (int i = 0; i < n ; i++)
{
Console.Write(incrementor + " ");
incrementor+= 4;
}
Console.WriteLine();
}
>>
>>59351605
If the input is the n in >>59351544, then the time grows by input^6. You can test this for yourself and prove it one way or another, rather than have a pissing match though.
>>
>>59351661
>the size of the matrices will be read from the console
Your solution creates a matrix that's much larger desu.

n=4 should create a 2 by 2 matrix, not a 4 by 4.
>>
>>59351674
>believing in the sphere hypothesis
>>
>>59351668
See >>59351625
>>
>>59351268
The C preprocessor can emulate operator overloading? I wasn't aware of that.
>>
Main function is not taking * as arg[2], however if I enter \* it's working.

Strange.
>>
>>59351674
 Problem: Write a program, which creates square matrices, the size of the matrices will be read from the console, for example the matrix with the size n*n 


There, the question remains
>>
>>59351668
It doesn't matter what the input is, user input could be kittens and sharia law for all I care. The loop does a single pass on the entire data set, ergo it's linear.
>>
File: uarstupd.png (18KB, 683x134px) Image search: [Google]
uarstupd.png
18KB, 683x134px
>>59351605
The variable n is the size of the problem
We want to find the number of times the basic operation will be performed as a function of n (asymptotically)

If a function f(n) is in the class of O(g(n)) if it grows no faster than g(n)
that is to say for all n f(n) <= g(n)

There are symbols other than "O" as well for this kind of thing, signifying functions that grow more slowly or at the same rate for example

Saying the asymptotic time complexity is O(n) is saying that as n increases the time it takes for the algorithm to run will not increase at a rate faster than g(n) = n (linearly)

You guys *genuinely* don't understand big O or algorithm analysis

>>59351625
The basic operation is performed an amount of times proportional to n^6, where n is the size of the problem (the input)
This function is therefore in the class O(n^6)
>Not on N^(1/N) elements.
I don't know what you meant by this, although it doesn't really matter cause its apparent you have a core misunderstanding about this topic.
>>
>>59351698
See >>59351703 and >>59351625
>>
>>59351715
Just answer my question >>59351661
>>
>>59351712
>I don't know what you meant by this
The number of elements (AKA the fucking INPUT) is N, not the Nth root of N.

You don't understand that the input to the algorithm is the fucking actual elements, not whatever the fuck the user types into the console.
>>
It must be great being retarded
>thinking n * n = n
>always thinking you are write when you are so preposterously wrong it's insane
>>
>>59351692
I wonder as well.
>>
>>59351722
Given that the variable n is the square root of N, then no, it runs in linear time (aka O(n), not O(n^2)).
>>
>>59351703
N in this context is the input to the algorithm.
>>
>>59351736
>he thinks big O is a notation for number of elements and not for time complexity
>>
>>59351735
ok, i will for now accept you are correct
now show me ANY algorithm that isnt O(1) or O(n) ok?
>>
File: 1442565221722.jpg (69KB, 520x678px) Image search: [Google]
1442565221722.jpg
69KB, 520x678px
>>59351744
You literally can't make a square matrix of non-square numbers. The program would throw an error if you typed in 8, according to your line of reasoning. That is retarded. I worry for you anon.
>>
>>59351749
>N in this context is the input to the algorithm.
No, in this context, the input to the algorithm is the N*N matrix. As any one element of the matrix is only accessed once, the algorithm obviously runs in linear time.
>>
>>59351767
But the user input N, not N^x.
>>
>>59351759
You just don't know how to make square matrices from non-square numbers.
>>
>>59351755
This is what happens when the generation is raised on abstract high level ez mode programming
>>
>>59351757
Bubblesort.

>>59351759
>type in
You don't get it, the input refers to the input to the algorithm (as in the fucking matrix). Not what the actual user types in.

He could type in the words "sixteen by sixteen matrix" and the program could do some processing to determine that it should make a 16x16 matrix.
>>
Working on Project Euler

Just out of curiosity, I know you can use a thing called lambdas in C++, but I was wondering how you would go about writing one...
Let's say I have the following function:
bool fulfillsProperty(int testNum, int index)
{
return (testNum%isDivisible[index] == 0);
}

Is there a way I can make this into a lambda? Also, I heard lambdas are only for one-line functions... Is this true?
>>
>>59351772
It doesn't matter what the user inputs, see >>59351797 . The input to the algorithm is the matrix.
>>
>>59351797
what? how can bubble sort not be linear? there are only n elements in the list anon!
By your definition isnt this linear??
>>
>>59351812
Just because you said it doesn't make it true.
>>
>>59351797
But anon
 which creates square matrices 

you are wrong. You should get help because you can't stop being retarded on purpose.
>>
>>59351813
>there are only n elements in the list anon!
Yes, and bubblesort does n^2 passes. As in, it runs in polynomial time.

>By your definition isnt this linear??
No, as I've already stated. Big O denotes fucking time complexity, not the number of elements you guys seem so fixated on.
>>
New thread:

>>59351833
>>59351833
>>
>>59351797
The size of a matrix is defined by a 2-tuple (length,width) though, not a scalar
Like i said in an earlier post if matrices were defined by scalars then matrix(4) could be:

1 2
3 4

or

1
2
3
4

or

1 2 3 4

>>59351832
You are getting confused, I am arguing with the guy who you are arguing with, I am just being devils advocate
>>
>>59351824
Big O denotes runtime complexity, yes or no? Does it run in fucking linear time or not?

>protip it fucking does
>>
>>59351854
Both posts are me you dolt.
>>
>>59351854
Literally creating a matrix is not defining it's elements you autistic nigger. Let that sink in. I can define A to be a matrix of n by n elements, WITHOUT EVER DEFINING THE ELEMENTS.

Int matrix [n][n]; is literally valid C code which creates a square matrix.
>>
>>59351864
Kek
>profile, this is why smart people define n in a context and your dumb ass didn't.
>>
>>59351661
Complexity is a tool people use to describe how the problem scales.

Some cases, you count the number of floating point operations, some times you use something more abstract.
In matrix operations, you usually look at the actions vs the size of the matrix.
In sorting algorithms, you look at the comparisons.
If you print a single row once for each element in the row, then it would be O(N^2) because N would refer to the number of elements in the row.
If you print every element in the matrix, it is O(N).
It doesn't matter that you print the same number of times in both situations.

It is all about complexity, not the time it would take to do an action.
>>
>>59351891
I didnt say anything about assigning the elements, i am refering to the SHAPE of the matrix
You are not disagreeing with what i said you just didnt understand me
>>
>>59351811
No, lambdas are for
- passing functions as arguments to functions
- nesting functions inside functions

e.g.
#include <iostream>
#include <functional>

// this is a "higher order function"; it takes functions as input
int applyTwice(int inp, std::function<int(int)> fun) {
return fun(fun(inp));
}

// a simple regular function
int triple (int x) {
return x * 3;
}

int main () {
// passing functions as arguments example
// without lambda
std::cout << applyTwice(4, triple) << std::endl;
// with a lambda
std::cout << applyTwice(4, [] (int x) {
return x * 3;
}) << std::endl;

// nested function example
std::string greeting = "Hello";
auto greet = [&] (std::string name) {
// we use & to capture the outside variable 'greeting'
// making the variable 'greeting' part of this function's "closure"
std::cout << greeting << ", " << name << std::endl;
};

// apply the function
greet("Bob");

// modify variables in the closure
greeting = "Goodbye";
greet("Bob");

return 0;
}
>>
>>59351920
You are being an autistic nigger. Read the problem. Reread it again. Reread it again because you are stupid and missing what it says:

  Problem: Write a program, which creates square matrices, the size of the matrices will be read from the console, for example the matrix with the size n*n  


You input a size. Singular input. Of a square matrix. A single number is correct, unless you want the program to throw an error because any matrix that is not square... now stay with me... is not square. It does not define the input. It does not "determine" the shape of the matrix. It is always the same shape. What made you so stupid? Surely you could not have been born this way.
>>
Classes are obsolete when you can use heterogeneous lists and tagged types.
>>
>>59351813
>2017
>being this fucking retarded
Reading each element of a list is O(n), because the time it takes to do so grows linearly with the growth of the list. Have 100 elements? It'll take 100 passes. Have 100000000 elements? It'll take 100000000 passes.

Bubble sort, along with selection and insertions sort, is O(n^2) because for each element you have to compare it to, essentially, every item in the list. For each element in n, you have to compare n times, or n * n, or fucking O(n^2) you fucking mongoloid. Even the fucking Wikipedia page spells this out for you you piece of shit. Technically with bubble sort, there's ways of shortening the actual time it takes, but it's still order n^2 in terms of how long it will take as the data it works on grows.
>>
>>59350366
<3 you
t. smug weenie licker
>>
>>59352055
The list is of size n^2
There are n^2 elements
a square matrix of size 4 has 16 elemeents
a square matrix of size 100 has 100*100 = 10000 elements
The input to the "make square matrix" function is this size, n
what are you missing?
>>
>>59352019
how would you describe an incomplete interface for such a thing if the rows are out of order?
>>
>>59351595
Technically yes, but Big O notation shortens it to just n^2.
>>
>>59352081
It doesn't matter what order the rows are in.
>>
>>59352074
What tyhe fuck are you even talking about? I'm talking about the time complexity of the bubble sort algorithm, which is O(n^2). Big O has nothing to with how users input data, it's a way of describing how the execution time of an algorithm grows as the size of the data grow.
>>
>>59352154
Yes, but it depends on how the function is defined (yes)
if the function is printSquareMatrix(array, n) and n is the side length of a n*n matrix then the function is O(n^2)
if the function is printSquareMatrix(array, n) and n is the number of elements in the matrix then the function is O(n)
>>
>>59352086
No it doesn't.
It would shorten it to O(N).
>>
>>59352230
What? I'm just talking about bubblesort bro. Printing each element of any structure once is always going to be O(n)
>>
>>59351315
>>59351692

#define FOO 1.23
#define BAR 1.23
#if FOO == BAR /* syntax error */
#endif
>>
>>59352517
what does that have to do with C++ only being able to compare integers?
Do you write all your code in the preprocessor?
>>
>>59352609
it's ridiculous that you can't make assertions on defines at compile time if they aren't integers. it's not too much to ask to do #if/#elif etc on floats/doubles and strings
>>
>>59352680
alright i solved it with static_assert. C++ wins again
>>
>>59352680
can you give an example of when it is needed or even a good idea?
You use the preprocessor checks to make sure that the thing you are compiling would work on the system.
Say you have a library dependency, you use the version of the library, there ints work, although it is a bit cumbersome if the library only works with a specific library.
And strings make sense if you need an easier way to describe the scenario, but the name of the variable is enough on most cases.

Can you give an example?
>>
>>59352765
anything that makes assumptions or places restrictions on compile-time input
>>
>>59352832
But can you give an example where you need floating point values or strings to do this?
>>
>>59349834
>he has no concept of an IR or link time optimizations
crazy. Also the fact that you're purposely attempting to confuse the compiler should inform you that you're aiming for an exceptional case.
Thread posts: 341
Thread images: 22


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.