/dpt/ - daily programming thread

Statistics edition, now that we have done the calculus and linear algebra prerequisites

Old: >tfw will be coding awesome AI stuff after this /dpt/ edition

Other urls found in this thread:

wiki.haskell.org/Monad
learnxinyminutes.com/docs/make/
rg-gosset.co.uk/files/mangaGuides.zip
en.wikipedia.org/wiki/Differential_evolution
twitter.com/SFWRedditVideos

All praise D

Thank you brother

how to be master at c/c++/c99 ?

nth for Go has generics.

Tomohiko Sakamoto's Algorithm

Determination of the day of the week

#include

int dow(int d, int m, int y)
{
int t[] = {0,3,2,5,0,3,5,1,4,6,2,4};
y -= m < 3;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}

int main()
{
const char *days[] = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};

printf("%s\n", days[dow(14 , 6 , 2016)]);
return 0;
}

I like this manga guide trend. Better than faggot anime at least.

Only on built-in functions.

Why not just use jQuery?

>Only on built-in functions.
No.

Explain. Inb4 interface{}

interface{}

What is the purpose of this code found it in a thread a few hours ago?
def numFSM(a):
state='e2'
if a == '':
print('nigger')
else :
a = a.split()
case0 = {i: 'e'+str(i) for i in range(0, len(a))}
#case1 = {#...}
#case2 = {#...}
while a :
for x in range(0, len(a)):
if state == 'e0':
state = case0[x]
print(state)
elif state == 'e1':
#state = case1[x]
print('case1')
elif state == 'e2':
#state = case2[x]
print('case2')

Not type safe. Type assertion/switches are slow.

finite state machine

That's not the point. It has generics.

Dynamic typing != generics

ok, what language is this, never seen something like this:
{i: 'e'+str(i) for i in range(0, len(a))}

Python dict comp

interface{} can be abused as a generic.

main(c){return c ? c*main(c-1) : 1;}

isn't that the Python?

that code is fucking ugly

Surely she must be pretending

But it does not provide zero runtime cost type safe generics, which is what all other people except for you mean by generics.

Wouldn't bet on it, there are many wannabe nerds/low-techs out there.

>wannabe nerds
Why did nerdom ever become cool? I preferred it as a shunned hobby/profession.

can i make a macro like this

#define FOO_0 (foo + 1)
#define FOO_1 (foo + 4)
#define FOO_2 (foo + 2)

#define FOO(X) (FOO_(X))

not sure about the syntax but i hope you get the idea

>Why did nerdom ever become cool?

A lot of people started playing videogames, and because it was formerly shunned, it became cool to be a nerd.

Thank god normies will stay away from muh InfoSec

or do i need to store the values in an array in order to loop through them

Nerdom as itself never really became cool, but somehow the idea that people who do edgy things, browse tumblr/reddit, can 'program' in html, use apple products and go to starbucks are nerds spread across society. I think thats why now everyone wants to be 'nerdy'.

Is Rust good or is it just a meme?

Does anyone know of a site that gives you beginner "practice problems" in Java

You just wait. Right now "dude programming lmao" is the maymay, but "dude security lmao" can't be too far around the corner.

Yeah, most people don't even know that this is a thing, but I'm a bit concerned about the amount of edgy 12yr olds playing this game and installing Kali Linux after it, thinking they are hackers.

I'm blaming Jobs for this too.

also pay attention to the fucked up apt command

What language to learn after Python?

The hope here is that the required low-level knowledge will scare them away.
I'm sure they'll learn how to ddos like every other l33t haxx0r, but not much past that.

F#

C, asm , C++, perl, Lisp, prolog, there are plenty of good languages out there
inb4
> prolog
> good

Probably they'll also find out about metasploit after a while.

Go.

> tfw my interest in infosec, linux system administration and programing started like this.

Why learn that instead of Haskell?

This is right down my alley! I've been coding a regression analysis program, and it can calculate univariate and bivariate regression models. Two questions: One, how do I calculate r and r^2 values for bivariate models? And how do i calculate coefficients for a multivariate model (more than two)?

F# is more friendly, Haskell is more punishing.

Ok, I figured where my problem is, Top->next is NULL when called into the function despite the fact that normally it points to the second element of the list.
Can someone explain why?

I like it hard and rough

Pastebin the relevant code, I want to see how you're building your list

Download GHC and read this every night before you sleep

wiki.haskell.org/Monad

Could someone explain

...

He tried to use apt-cache search to find all packages that involve BlumeDB and Marcus Hollaway. What he does instead is trying to read config file ache.

Here
pastebin.com/4LnWZ7Q8

You have these special preprocessor constructs with hashes... Try
#define FOO(X) FOO_ ## x
If it doesn't work, google some about the preprocessor.

chuckled

I cannot satiate my lust for LINQ
var foo = Directory.EnumerateFiles(@"C:\temp\folder\Folder1");
var bar = Directory.EnumerateFiles(@"C:\temp\folder\Folder2");

var baz = foo.Concat(bar.Where(x => !(foo.Select(y => y.Split('\\').Last()).ToList().Intersect(bar.Select(y => y.Split('\\').Last()))).Contains(x.Split('\\').Last())));

Are any of these manga books any good?

Alright, lads. Going for 1000 triangles and 5000 candidates. This should produce a pretty convincing mona lisa.

This is one with 500/2000.

> for(;;){
printf("%s\n",Top->word);
if(Top->next)
Top=Top->next;
else
break;
}
Pro: Now you know about the for(;;)
Con: That's surprising, and surprising things should be avoided in coding.

for(; Top->next; Top = Top->next)
printf("%s\n",Top->word);

You should try Haskell or F#

No. Though I did like the Database one.

>Elem = Elem->next;
Elem = malloc(sizeof(struct list));
lines 58-59

Think about it, about sequence and such. Your problem lies right here.

>bajs

Wouldn't that not print the last string of the list?
Can I do something like (Top->next)->next?
Still, it doesn't solve my problem.
Thanks for your time btw man.

Are you a fucking ant?

It'd take longer if it were bigger

For you

>Wouldn't that not print the last string of the list?
No, it's a shortcut, 100% equivalent to
for(; Top->next; Top = Top->next) {
printf("%s\n", Top->word);
}
I assumed you knew that. The rule is that if there is only one statement in the loop body (or the if body for that matter) then you don't need braces to group statements together because there's only one. It's optional tho, put in braces for clarity and ease of editing if you want.

>Can I do something like (Top->next)->next?
It's possible and you don't need the paren pair, but where and why?

>Still, it doesn't solve my problem.
Yes I know

>Thanks for your time btw man.
You're welcome. Good luck

holy crap, wasnt that on scholastic before

Currently sprucing up my regex-based X12 parser. Pleased with how fast it is, but I can't help but feel like I will regret doing this.

Post progress when done

The loop stops when Top->next stops being valid (==NULL), which since Top=Top->next happens at the end of the loop, Top->next==NULL for the last string so the loop isn't executed for the last string.

Could you elaborate? Is there a problem when using malloc on NULL pointers? Should I set only the last ->next pointer to NULL out of the loop?

Do a van Gogh

van Gogh is pretty based

Does anyone actually understand Makefiles?

I just copy and modify some example code

Somewhat.

I'll try that after this run. I'm on triangle 7 of 1000 and 15 mins of runtime so far.

This will take forever.

This helped me; maybe you'll find it useful.
learnxinyminutes.com/docs/make/

what's the algorithm? this seems like something you should be doing on the gpu with shaders

Anyone else struggling to decide what to work on? I wish there was a repository for current Sup Forums projects to contribute to.

somewhat, kinda deciding to do a project on js, that would be like a addon for a browser, not sure what to do though. What language are you going to base your project on, or plan to

>The loop stops when Top->next stops being valid (==NULL), which since Top=Top->next happens at the end of the loop, Top->next==NULL for the last string so the loop isn't executed for the last string.
M8, I'm so busy parroting I don't even reflect! Yes you're right. It can be fixed EZly tho for(; Top; Top = Top->next)
PriTop: Them CS boyz call the second part of a for, as well as the only part of a while, the /invariant/ for a reason: it is what will by construction invariably be true in the body of the loop. So if you express precisely what you *want* from the loop --- that i is strictly inferior to ARRAY_LENGTH otherwise I'll overflow my array, that Top isn't NULL otherwise I'll dereference it, but Top->next is fine, I won't dereference it in this iteration --- then your condition is the good one. Obviously I failed at my own advice tho.

>Could you elaborate? Is there a problem when using malloc on NULL pointers? Should I set only the last ->next pointer to NULL out of the loop?
No, malloc doesn't even know you're assigning its result on a formerly NULL pointer, it doesn't care. No, outside of the loop would be already too late.

I'll give you this to chew on: it's not only with the last node that there's a problem. With this example program, we have an irregularity already on the second node.
#include
#include
#include

struct list {
/* ... */
struct list *next;
};

int main(int argc, char *argv[]) {
struct list *Top = malloc(sizeof(struct list));
Top->next = NULL;
struct list *Elem = Top;
for(int i = 0; i < 10; i++) { // create 10 nodes because why not
Elem = Elem->next; // your two lines
Elem = malloc(sizeof(struct list));
Elem->next = NULL;
}
assert(Top->next != NULL); // this assertion fails, and it's related to the second node (or rather the first node, depends)
}

Why does this happen?

no

For a total number of triangles, generate a bunch of candidates. Select the one which produces the lowest error value and apply it to the canvas.

I was also thinking JS or Golang, what do you have in mind?

What kind of genetic algorithm?

# Warning - only use TABS to indent in Makefiles, never spaces!

wat

it does not sound like a GA.

I found all the manga guides in a single zip!
rg-gosset.co.uk/files/mangaGuides.zip

>generate candidates
>select the best and apply it

GTP's own™

wat what? Makefiles require tabs.

that is not GA. in GA you don't even generate new candidates other than initial ones

Yes it is
en.wikipedia.org/wiki/Differential_evolution

The page you post says nothing about GA. I think you are mixing GA with evolutionary algorithms.

the algorithm he tells looks more like a hill climbing to me

Differential Evolution is a genetic algorithm

*
Apparently it's not, but it definitely seems like one and appears odd it isn't considered to be one

Ok, I think I figured it out.

Top->next is NULL even in the main function, despite the fact the list is created normally.

I think this happens because I use the Elem pointer to create the list.

/*the Top pointer is created here*/
Elem=Top;
while(...){
Elem=Elem->next;
/*...*/
Elem->next=NULL;
}

I don't think Top->next is connected to the second node, anything else is connected because the Elem pointer is used for all of them.

I'll test it a bit.
Thanks again man, you really helped me a lot.

he is just doing a hill climbing. he has a single solution and iteratively improves it by using best of 1000 triangles