/dpt/ - Daily Programming Thread

Old one's at bump limit

Previous Thread:
What are you working on, Sup Forums?

Quick question, are there any C++ libraries that will quickly get me the result of "n C r" (from n items, choose r)

Other urls found in this thread:

github.com/vhf/free-programming-books/blob/master/free-programming-books.md
twitter.com/SFWRedditGifs

first for emaKKKKs

It isn't a part of POSIX. Vi in the vast majority of cases will be installed in a unix-like system.

fuck POSIX

UNIX set back computing by half a century.

We need to do away with this trash and build modern-day Lisp Machines.

That's the ONLY way to reliably get over the von neumann bottleneck.

Well, tell it to Intel or whoever, I'd better stick with the old good vim, C and a unix-like system until that.

LOOOOOOOOOOOOOOOOOOOL

Lisp made breakthroughs that are still missing from popular languages, and those machines were truly ahead of that time. Imagine how far we would be if the Lisp Machine won the race. UNIX only became popular because it was enterprise-friendly and adopted by lots of business, not because of technical merits.

I use Linux and OpenBSD and like them both because they are the best contemporary systems available, but that just tells you how far this field has fallen.

Please follow the established OP format. Don't go posting your shit in it.

>automated site access
That's against the global rules, fucko
Reported, enjoy your permaban

Any recommendations for resources explaining methods of determining the prime factors of a large integer in a way a crappy programmer like me can understand?

My first thought was to use something like the sieve of eratosthenes and check different combinations until I find the right one but that seems wildly inefficient.

>Scraping HTML
>Not just using the JSON API
Also, your entire script can be replaced with
#!/bin/bash

curl -s "a.4cdn.org/$1/thread/$2.json" | jq -r ".posts[] | select(.tim) | \"-O i.4cdn.org/$1/\" + (.tim | tostring) + .ext" | xargs curl

Here you go, buddy.
#include
#include
#include

using namespace std;

int choose(const int n, const int r) {
return static_cast(tgamma(n + 1)/(tgamma(r + 1)*(tgamma(n - r + 1))));
}

int main(void) {
cout

Thats the thing since I'm so inexperienced.
There's so much stuff to learn about programming, that it becomes really overwhelming. I had no idea JSON even existed. I was writing that script in an effort to more familiarize myself with urllib, beautifulsoup, and regular exressions.

How does Google Captcha work?

I'm fucking tired of these new captchas, is there any way to "force" my browser to use the old text-based ones?

How do I properly abstract out Graphics from a video game with c++?

Like, I'm using pointers to abstract classes of enemies, which get created by a factory that makes the correct enemy based on the visualisation used.
Afterwards you just call the visualisation function, and the correct function automatically gets called, so far I can follow.

But then:
How do the classes know to which window/surface to draw?
Am I supposed to make an abstract window class, which creates the correct window type through a factory, and then send that pointer to the class that needs it in the constructor?
That seems like the wrong way, but I know too little of it to be sure.

Currently implementing a look up table

I don't know jack shit about build tools. I'm competent enough to write simple algorithms and use different APIs, but as soon as my system grows larger than a file or two, I lose it. Best I can do is produce a very shitty makefile, and only for super small projects.
Any helpful links or books on this?

>What are you working on, Sup Forums?

I am supposed to work on a JavaEE project, that is to make a simple mini "forum" like thing.
Have 2 days left and not started, don't even understand why there is so much shit with JavaEE to even get it going.

because lol java and poo in loo and boilerplate and everything is an object, and POO

what exactly does POSIX_ME_HARDER do

>POSIX_ME_HARDER
I don't think that actually exists; it was just joked about.

It really depends what the conditions of being drawn in a certain window are? Like, is it based on position? Are the two windows different views or are they entirely different sets of Actors? I mean most games only ever use one window and even when they use multiple it's usually just a single virtual window that's been stretched out over two display screens.

But in general, the Actors really shouldn't be the ones keeping track of where/if they need to be drawn, but rather the window areas should be the ones keeping track of which actors they need to draw and the various camera states (and then they pass the graphical context to all Actors that need to be drawn in them).

I see what you mean, and I didn't explain properly.
I'm supposed to make a 2D game where we should be able to replace the graphics library easily.
There'll indeed always be one window, and the camera will be in a fixed position (Space Invaders).

My question was more on how to properly separate the graphics from the game for easy replacement.
If I understand correctly, you basically recommend making screens where the actors are linked to, and let the screen handle the drawing?

I thought of that as well, but then I thought it shouldn't be the responsibility of the screen.
Although I have to admit, I didn't think of making multiple screens, just a single one, which is significantly worse.

Oh, that's easy. You just wrap it in an abstract class and pass this wrapper (often called the graphical context) to the Actor in its draw function (the game engine object, whatever you call it, should have access to both the list of Actors and the GraphicalContext object, so it does the passing). Each different graphics engine (say, one written in DirectX, one written in OpenGL) will implement the virtual methods that abstract class defines (methods will be things like "startDraw", "drawPolygon", "setColor", "endDraw", things like that). It can be a bit tricky to try and figure out before hand exactly what methods the graphical context can need in order to provide all the interactions that will be necessary, but it's not like you're releasing it into an environment where the API needs to be strictly define beforehand. You can look up SDL and see what kind of methods it provides since that is essentially what it is: a wrapper for all the various internal graphical libraries.

Thank you!!

Thanks man, I get the basic idea.
I knew this wasn't that hard of a question but stuff like proper design can keep me up all night.

>buy Sup Forums gold to bypass the site's captcha
>dynamically add the old version of captcha to Sup Forums when you visit

Why do you program Sup Forums? I've attempted to learn stuff like python, C, and ruby before but I never stick with any of it. I mainly use linux for my casual usage but I never need to really do anything that would require me to learn stuff. The thing is there aren't any 'problems' I want to solve even if I learned a language or two. There's no applications that I want to make that isn't already being developed if it doesn't already exist. So it might not just be for me. Doing it to get a job wouldn't make me any happy and I have trouble believing companies would hire this NEET who wasted his life doing nothing for two years. So why do you do it? I'm just curious.

Yeah, the words are scarier than the concepts. Everyone already intuitively knows what an abstraction is, they just never thought to call it a virtualized abstract polymorphic class.

Literally the most exciting things happening in the world right now are computational/computer science related. I want to be a part of it. Whether you agree with that, though, is subjective.

Creating something from nothing. Turning analytical thought into tangible, useful tools. We are living in the second Renaissance only this time alchemy is real.

Working on computing 2D Navier Stokes on SciLab (Uni too poor for MatLab) before doing it again in C++

It's fun to make tools / programs that "niche" communities enjoy using.

I want to find a pair of elements in an array that give a given sum.

public bool hasPairOf(int[] a, int sum)
{
for(int i=0; i < a.length-1; i++)
{
if(a[i]+a[i+1] == sum)
return true;
}
return false;
}


How could I make this faster? I'm an amateur programmer, so I wan't to use simple tools that I understand.

You don't.

The equation can be solved with FFT.

If the array is over a certain size you could start allocating new threads for going over it in chunks.

I would calculate how long it takes to setup the multi-threading and calculate what size of array goes over the multi-threading time on a moderate speed PC.

Is the data sorted?

I'm trying to do it the "normal" way, with Poisson, Jacobi iteration etc.
But thanks, I'll take a look at FFT.

They have to be consecutive? That really looks too simple to optimize without digging into the assembly and the compiler might already optimize it anyway.

If it's unsorted then it's O(n).
If it's sorted then it's O(lg(n)).

I have two functions. I expected function1 to be slower than function2 but it turns out that function2 is almost a hundred times slower than function1. I suspect cache misses to be the reason for function2's slowness but I'd like to be sure. What tools can I use in order to find out why function2 is slow?
My project is written in C, I'm using linux with gcc (though I could use clang if need be).

(K)CacheGrind

Fourier Transform is a method to solve the Poisson problem.

They don't have to be consecutive, so I guess mine is wrong?

Thanks user. I think I'm going to go with cachegrind, KCacheGrind has too many dependencies.

22 years old NEET here.

Am I too old to learn how to program?

I didn't know.
Thanks.
Is it more effective than Jacobi ?

No, no one is too old to learn anything. If you have time and a will you can learn anything.

Nope.

>22 is too late to do anything
Are you think only literal autists who stated when they were 7 years old can be programmers or something?

Also, there are people 30-50 years old from pooland who manages to "program", so if they can do it. You surely can do it even better, unless you're a poolander too.

You're looking at a knapsack problem, then.

>Are you think
Do you think*
I was originally going to ask that differently.

Pattern recognition in log files with python.. where do you start?

With the library that wrote the log files.

Do you have a pair of programming socks?

Not at all.

Not just not too old, you have everything to become super competent. But you must get obsessed and learn learn learn and work your ass off.

Is the array sorted or not?

I don't know the actual equation you two are talking about but the FFT is REALLY fast.

It's not sorted.

dt u + u.∇u = -∇P + ν∇u
I have to solve a Poisson equation for P.

Jacobi is a simple iterative method, FFT solves the problem in a transformed space. It depends, I guess, abilities to be scaled and parallelised, computed on GPUs, speed, accuracy, particular conditions of the fluid environment and so on.

I'm not investigated that much, it's just educational exercises of the numerical methods for PDE for me.

I'm still a newbie programmer but part of the reason I'm learning it is because I get a lot of ideas, or small hunches about how I can make certain improvements, and make programs that are somewhat useful to my situation.

for instance: Recently i made a small python script to make an alert signal whenever there's an empty slot on a game server i like to play on, so I no longer have to compete for that slot with other players trying to join.

Then there are some bigger programs im working on like 2d games and stuff. Not super passionate about them but it's something to do.

dont rush it by trying to learn several languages at once. I only know python now and i think it's very good for beginners. Take your time, and try to pursue small projects that you think you can accomplish.

FFT is a divide and conquer algorithm, it's n log n, the earlier DFT implementations were n^2.

What's wrong with Pascal?

For me too it's an exercice for numerical methods.
We code what we learnt in finite differences/elements/volumes.

Anyone got some good advice to brush up on calculus? I left university and started working a few years back and now I'm going back to finish a degree for reasons. I haven't done anything with calc or formal math in years and feel I've probably forgotten it all.

The only calculus I have to take is the very last one, but I've totally forgotten the contents of the previous courses. Does meme-shit like khan-academy work for prepping for (non-shit) university math?

Plan 9 made breakthroughs that are still missing from popular operating systems, and the operating system was truly ahead of its time. Imagine how far we would be if Plan 9 won the race. UNIX only became popular because it was enterprise friendly and adopted by lots of business, not because of technical merits.

What are plan9's breaktrhoughs? I can only vaguely remember that it did some cool shit with the way it networked filesystems and devices.

I have a question regarding txt files.
I have a program for data in files, but I have a problem.
I want it to make it delete all data in a line, move all of the data one line up, then change the ids of the file after the deleted line by -1.
For example.I have ids 1-7, I delete line 4, I then want to have ids 1-6, not 1,2,3,5,6,7. I'm generating ids by the file length

What is the "very last one?" Differential equations?

hey, why do you guys hate OOP?

Because hating on popular things is what the cool kids do.

I've been up to learning lisp, but Emacs makes my whole arm hurt with RSI. Is there any sort of way to create a Lisp enviroment with Vim?

Just switch caps lock and ctrl like it was meant to be.

slimv
Or you could keep using emacs and use evil-mode for vim like bindings.

Yeah I know, and on real world datasets its quick. Whats your point?

My point is that 'quick' is a relative term. We discussed the methods to solve a PDE.

Because it's shit.
I don't think I need to justify hatred for something that is shit.

It's unneeded 99.9% of the time. It's a completely worthless abstraction.
It's great for producing programmers that don't actually understand how computers work.

I dunno. It just seems so useful. You know, it makes it easier to re-use code and all. Plus It seems a little more organized. But I've not looked big time into it tho

Same reason Sup Forums does anything: it's a tradition which they inherited and they have no idea why, but they will parrot it to no end because that's what they latched onto when learning. Like Thinkpads and foobar.

But pretty old and I've been around. The animosity originated from Universities switching their curriculum over from C[++] to Java. Now granted there is some legitimate design issues with Java that were raised about forcing OOP even for the program entry point and about excessively verbose default libraries, but that wasn't the real meat of the issue (C++, after all, was even then considered to be a stylistic travesty of feature bloat, but everyone accepted it). No, the real hatred was over the Java Virtual Machine. Not its concept, no, that was quite sound and quite well implemented, but its closedness. You see, at the time "Free Software" was not some niche gathering of neckbeards and conspiracy nutters, but it was actually a principal that was firmly rooted in the Mathematical origins of Computer Science and which the old guard of Academia tried and failed to preserve. To put it simply, Java marks the point in which Computer Science was ripped out of the hands of Mathematicians and into the hands of corporations, or at the very least that it became no longer a field of study, but rather a trade. And even though the concept of OOP was championed more by C++ and the concept of machine-independence was really what Java brought to the table, because it forced OOP and made porting sequential code redundant and awkward, that's what people latched onto.

And maybe everything I just typed was pure bullshit and just one man's misguided understanding of the situation, but that's my experience.

Anyone got a link to some good collection of free PDF books?

Kinda like this one
>github.com/vhf/free-programming-books/blob/master/free-programming-books.md

>it makes it easier to re-use code and all
No it doesn't. OOP encourages so much damn mutable shared state. If you want to "reuse" an object, you need to drag with whole environment and other mess of objects with it.
An example of true reusable code would be a pure function.

It's not really an issue when it is correctly used.

It's almost never correctly used however, and universities keep throwing it on new programmers.

Okay, here's a thought...

What is the smallest n such that an individual could reasonably argue that there is at least one string of n bytes that has never existed at any time in any computer's memory? Obviously, it's bigger than 4. I can imagine someone has at one point built a program to count from 0 to 4 billion, just to see how fast it could be done. I'd even be willing to argue that it's bigger than 8. But with each byte you add, you multiply the size of the set by 256, and the chance that there is a unique bytestring increases.

Lua or python?
I want to make a website.Will use one language for both front and backend.

It's cruel to give someone false hope. It is a well known fact that at 20, your brain starts to decline. It becomes harder for you to grasp those technical concepts that are commonly found in programming. Even if you think you're becoming good, there'll always be someone who's younger and much much smarter than you.

Nice pseudo-science you have there.

You ever tried r9k? Not the hot mess it turned into but the actual algorithm. Needless to say, even under the extremely small subset of "things people actually say", all strings are cosmically unlikely. I would hazard to guess that the length of n is in the low four-digits

>It is a well known fact that at 20, your brain starts to decline. It becomes harder for you to grasp those technical concepts that are commonly found in programming. Even if you think you're becoming good, there'll
Nonsense.

I'm in it for the money, and because any other career path that I would choose doesn't offer the the flexibility I'm after.
With programming I could go with any career style I want: big corporations, freelancing, entrepreneurship, hacking 13 year olds with viruses and obtaining their mom's credit card info. I doubt any other parth offers that much freedom.

The downside is that it's pretty damn stressful work. I'm a freshman and I've already parted ways with sleep and 3 meals a day just to do some fucking compressed sparse column implementation.

I assume you were documenting your own retardation as a part of this research?

#define FREAD_OR_FAIL(dest, size, num, file) if (fread(dest, size, num, file) != num) return false;

this is a good solution and nobody can convince me otherwise

is there a way to create a table in sql so that
TableA has foreign key to TableB
TableB has foreign key to TableA
without using ALTER? (as in just having two CREATE TABLE statements)

To this shitposter's credit, it's actually a pretty big cliche in Mathematics that analytical intelligence deteriorates at an alarmingly young age, citing a number of historical Mathematical geniuses who did all their best work in their early 20s. But this "phenomenon" is widely apocryphal and completely contradicted by pretty much all work done in this modern era of hyper-specialization.

>Flow control inside macros

(defmacro foo ()
(if bar
`(baz)
`(qux)))