/dpt/ — Daily Programming Thread

Previous: What are you working on Jow Forums?

Attached: anime.png (1200x900, 563K)

Other urls found in this thread:

learnxinyminutes.com/docs/python/
twitter.com/SFWRedditImages

ur mum

second for c

I'm thinking of making a molecular visualization package with Unreal 4. All the current visualization software look like ass and run even worse.

trying to implement the CryptoNight (Monero) hashing protocol in OCaml for use with Lwt

It's not looking good for me

>c is minimal 173cm
>shell is bloated shit 60cm
how though?

>not posting full image
kys

Jow Forums thread downloader in C.

Thats neat. Why though?

Making a text editor library in C so I can create a text editor later. Kinda like GNU Zile.

bash is too good.

Rewriting the Linux kernel in C

>Physics fag
>Only use FORTRAN
>Job search "fortran", 7 results
>Job search "C++", 60,000 results

I hate my life

That's a good idea. I'm amazed they didn't use C in the first place, it's kind of ridiculous

what field of phyics? the telescope by my old house is still given it's programming with FORTRAN I believe. You've got a good chance to work with some interesting machinery.

why do you fortranners always UPCASE THE LANGUAGE NAME

Thanks this is really helpful. In the third bit of code, you don't have f() defined anywhere. I think this is what confuses me about headers, because I basically understand the need for function declaration, as in f.h, and I also understand that a function definition can serve as a declaration (as long as it's above where it's being called).

It seems that people don't define functions in header files, rather they just declare them. So you would need to define them above main in main.c anyhow, in which case that definition would serve as a declaration.
Hope I'm making sense.

Oh fug
>the only difference will the the fact that the body of f will be in another file.
I missed this, okay. So declarations in headers, definitions in some other file, and then the use of functions in main.c?

what language should I learn to make an AI waifu

APL

Attached: space-cadet_keyboard_6.jpg (1024x616, 183K)

Prolog or Forth.

#include
#include

#define NUM 9
#define BOX 3
#define SQR 81
#define COLOF(x) ((x)%NUM)
#define ROWOF(x) ((x)/NUM)
#define BOXOF(x) (((x)/BOX)%BOX + 3*((x)/(BOX*NUM)))

//#define DEBUG
int globpuzzle[] = {5,3,0, 0,7,0, 0,0,0,
6,0,0, 1,9,5, 0,0,0,
0,9,8, 0,0,0, 0,6,0,
8,0,0, 0,6,0, 0,0,3,
4,0,0, 8,0,3, 0,0,1,
7,0,0, 0,2,0, 0,0,6,
0,6,0, 0,0,0, 2,8,0,
0,0,0 ,4,1,9, 0,0,5,
0,0,0, 0,8,0, 0,7,9};

int solve(int* puzzle)
{
int columns[NUM][NUM] = {0};
int rows[NUM][NUM] = {0};
int boxes[NUM][NUM] = {0};

int tmp;
int digit;
int unsolved = 0;

for (int i = 0; i < SQR; i++)
{ if (puzzle[i])
{ columns[COLOF(i)][puzzle[i]-1] = 1;
rows[ROWOF(i)][puzzle[i]-1] = 1;
boxes[BOXOF(i)][puzzle[i]-1] = 1;
};
if (!puzzle[i]) {unsolved = 1;};
}

for (int i = 0; i < SQR; i++)
{ tmp = 0;
digit = 0;
if (!unsolved)
#ifdef DEBUG
;
#endif
{ if (puzzle[i] == 0) {printf(".");} else{printf("%d", puzzle[i]);};
if (!((i+1)%9)) printf("\n");
} else if (!puzzle[i])
{ for (int j = 0; j < NUM; j++)
{ tmp += (columns[COLOF(i)][j] ||
rows[ROWOF(i)][j] ||
boxes[BOXOF(i)][j]);
}
if (tmp == NUM-1)
{ for (digit = 0; columns[COLOF(i)][digit] ||
rows[ROWOF(i)][digit] ||
boxes[BOXOF(i)][digit]; digit++)
;
if (!puzzle[i]) {puzzle[i] = digit+1;};
}
}
}
#ifdef DEBUG
printf("\n");
#endif
if (unsolved) {return solve(puzzle);} else {return 0;};
}
int main()
{
int mutpuzzle[SQR] = {0};
memcpy(mutpuzzle, globpuzzle, sizeof(int)*SQR);
solve(mutpuzzle);
}

rate my sudoku solver

Because they know it's an ACRONYM

Is it optimal solution to general finite case?

Attached: 1512672101196.png (500x500, 178K)

> In the third bit of code, you don't have f() defined anywhere.
Yes, you do. #include simply copypastes the contents of that file into this one. So after the copypaste job (the preprocessing phase) the declaration will be part of the .c file.
>So declarations in headers, definitions in some other file, and then the use of functions in main.c?
Yeah. You may also need to define types in headers depending on whether any functions depend on them.

Porting Herb Sutter's deferred heap library to rust. Haven't done anything with GCs before, so using it as a learning exercise.

Reposting this here because the other thread reached bump limit while I was writing it.
Pretty easy to read, good job. The few suggestions I have: I think the body of the inner loop could be simplified from this:
{ for (int j = 0; j < NUM; j++)
{ tmp += (columns[COLOF(i)][j] ||
rows[ROWOF(i)][j] ||
boxes[BOXOF(i)][j]);
}
if (tmp == NUM-1)
{ for (digit = 0; columns[COLOF(i)][digit] ||
rows[ROWOF(i)][digit] ||
boxes[BOXOF(i)][digit]; digit++)
;
if (!puzzle[i]) {puzzle[i] = digit+1;};
}
}
to this:
{ int solution_idx;
for (int j = 0; j < NUM; j++)
{ int present = (columns[COLOF(i)][j] ||
rows[ROWOF(i)][j] ||
boxes[BOXOF(i)][j]);
tmp += present;
if (!present)
solution_idx = j;
}
if (tmp == NUM-1)
puzzle[i] = solution_idx+1;
}
The second !puzzle[i] check isn't necessary, there's no way for it to fail in that place. And we don't need to search for the digit afterwards, the first loop provides us with all of the information we need. I tried following your style (which I'm not a fan of, but that's arguably a matter of taste) in this snippet, feel free to incorporate it and/or point out any mistakes.

>rust
Doesn't the borrow checker make it impossible to express any memory layout that isn't a tree

git commit -m "sudoku"

This is a FizzBuzz written in Brainfuck. Don't ask me how it works, I wrote it a year ago:
++++++++++[-]>++++++++++[-]>++++++++++[-]+
>+[-]+>+[-]+>+[
-]+++>+>+>+[-]+>+[-]>+[-]>>>>>>>>>>>>>>++
>+[-][[-]

>if statements

Shit performance

There is a some unsafe internal to the library that lets me skirt around some borrow checker issues. Externally, all pointers into the garbage collected heap are valid for the entire lifetime of the heap. As long as the client has a pointer, said pointer will be valid. So lifetime-wise it is basically a tree with a depth of 1.

// include/headers.h
int somefunc(int, int);


// src/functions.c
int somefunc(int x, int y)
{
return x+y;
}


// main.c
#include "include/headers.h"
#include "src/functions.c"

int main()
{
somefunc(3,4);
return 0;
}


is this a reasonable/typical sort of structure for a small C project? Is my use of headers, include and src, typical or autistic or what?
I'm aiming at trying to learn C along with best practice with makefile and packaging and stuff

Not that user, but hardly. It does a lot of extra work. An optimal solution would keep a stack of unprocessed known numbers and process them in the same fashion as his initial loop. If it detected that all but one place in a row, column or box was filled, it would fill that place with the missing number and add it to the stack of unprocessed ones. If the algorithm runs out of unprocessed numbers either the entire board has been filled or the initial layout was not deterministic, i.e. there is more than one solution. One could augment that algorithm to return all of the solutions pretty easily too,.

In VerboseFuck please.

Yeah I think they chose to write it in brainfuck for the laughs

>An optimal solution would keep a stack of unprocessed known numbers and process them in the same fashion as his initial loop.
Do you have sauce for proof of this.
I'm pretty interested now.

>is this a reasonable/typical sort of structure for a small C project?
Yes, just add an include guard to your header file:
// include/headers.h
#ifndef HEADERS_H
#define HEADERS_H
int somefunc(int, int);
#endif
Or better yet, use #pragma once:
// include/headers.h
#pragma once
int somefunc(int, int);
This will prevent your header from being accidentally included two times in the include hierarchy. This is important because you would get errors that would be hard to decipher otherwise.

tfw spoiled by short-circuiting logical OR (||)

Oh, interesting. Thank you.

i'd never thought to use this in headers thanks man. this is how i add commands in to all my suckless stuff

Too advanced to to learn what variables are,
but not enough to understand objects and more complex stuff.
How do I start learning programming again after a decade long break? Python.

Modern coding is completely different for person who started with procedural languages.

>Do you have sauce for proof of this.
Each field on the board has to be processed at least once, and that algorithm does just that (not counting the initial phase that will add all of the known numbers which is single-pass as well). Now that I think about it, it could be made more efficient (with the same big O complexity, just better constants.) by keeping an array of bools to see if a number has already been processed or not instead of doing that single-pass at the beginning. That could increase it's memory complexity though (again, same big O, only different constants), so I guess it's a trade-off.

There are books with this kind of person in mind, google something like "python for programmers".
Also learnxinyminutes.com/docs/python/

Do a Python tutorial and skip the first couple segments?

I meant formal proof.

despite all the hate it gets here, Python isn't a bad choice for something to learn. People hire for it (that's more than some superior languages can say).

the only thing i don't like about it is the way it's class methods aren't generic. in clisp you'd have an Apple class, and a generic cut method, in Python, the Apple class itself can have a cut method. in what world does an apple cut itself?

is there a reason that #pragma once is preferable?

Is it possible to write C without using if, just || and &&?

No you fucking retard.
You compile each file to translation unit, that way if you need to edit one file you have to compile only one file again.

you just did meng

Attached: 1525502528632s.jpg (125x97, 2K)

where is my idiomatic kotlin waifu

>You compile each file to translation unit
What does this mean?

>you have to compile only one file again
Isn't this problem handled with an appropriate makefile? I haven't looked too deeply into make but that was my impression

Well, I'm bad at formal proofs. I'm not an academic and I won't pretend I am. But checking if the board is solved in itself requires checking all squares once, so in a common-sense sort of way, I don't see how solving it could be any faster.

Yes.

You could also use only the ?: operator for branches, or only arrays of function pointers.

>wget -r

>You compile each file to translation unit, that way if you need to edit one file you have to compile only one file again.
You don't know what you're talking about, "translation unit" is a term the standard uses to describe an abstract medium storing C code. Which in practice means files on modern systems.

i wasn't sure if you could do it in C, but you can do it in boolean logic

Attached: orandand.png (326x114, 9K)

no name clashes. this is the most important part, because if you have guards with the same name in different files, you're in for some trouble
less code
faster on some compilers, but that's largely not the case with modern ones

oi mate you don't #include .c files

fuck i didn't notice that. yeah never include c files.

yea mate, this fucka is right. declarations go into .h files mate. if you want to have a .c file with function definitions you can compile that separately and then link it into your final executable (to make this job easier, makefiles exists)

correct me if i'm wrong

Lua

Common Lisp

consider this example

add.h
#pragma once
int add(int,int)

add.c //never include .c files
int add(int x, int y) { return x+y; }

main.c
#include
#include "add.h"

int main(void)
{
printf("%d", add(2,3))
}

gcc add.c -o add.o //compiling add.c (no linking, only compilation)
gcc add.o main.c //compiles main.c and the linker knows fuck what to connect right functions to right addresses

>//compiles main.c and the linker knows fuck what to connect right functions to right addresses
//compiles main.c and links add.o into the final executable*

w-wheres python-chan?

boring

>tfw no c milf waifu

Attached: waifu.jpg (563x887, 84K)

Does anyone here have any experience with the libxml++ library? How can I get the attributes of an element? I have a node pointing to a ' and I would like to get the 'name="value"' part.

I need advice.

I want to host a web service written in python (Hydrus Network) and another stack of software written in Java, Go and C#. In other words, I need a VPS.

I will potentially be hosting a lot of data from this site, but I am unsure. This data MAY include data like lewd anime images and similar.

What are my options concerning legality? I don't intend to allow people to upload content, but it will be retrieved via several automated routines.

Can anyone recommend a stable host that'll provide a lot of bang for my buck?

>I want to use all these languages instead of sticking to one package that covers all those at once

This is why web development is in the shitter

Download Java 10 and GHC, then delete System32 and write the name of the attribute to SYS\ADMIN\PASSWD in the windows registry. That should do it.

No srsly this should be basic af and self-evident. Are you even trying?

hledger -> prometheus (-> grafana) system to visualize my accounting, because every other solution sells your data, costs money, AND works like shit
in haskell because hledger is in haskell

It's for MVP purposes. Actual development will use a single language. I'm still going to need a VPS then.

Ok I downloaded Java and tried to delete System32 but Windows gave me some weird warning and wouldn't let me do it so now I'm pretty stumped again.
I seriously don't know what to do please help.

Attached: 1519987247365.png (800x892, 471K)

>milf
>20 year old
>this is what pedos believe
ok

Why do you want to make it public

>for MVP

Then fucking use one language, retard. You're just inflating everything ahead of time and reducing any kind of prototyping.

Attached: 1512989250651.jpg (327x309, 73K)

It has a specific purpose. Gathering of data ASAP, demonstrate the service, before any custom data gathering services are written.

This reduces potential loss of data.

I think you already lost something. your iq

Public may not be the right word, serve it to a specific few individuals.

>Pikachu, use "reading comprehension"
libxml++ doc runs away and leaves an answer behind
>IT'S SUPER EFFECTIVE

ok buddy

So you're going to host child porn?

>posting kiddies
lolicon degenerate, go back to /h/omosexu/a/l

Why the homophobia?

Homophobia is normal

You'd have to be pretty deluded to think everyone is like you, pervert.

>fear of homos is normal
I doubt that's true user.

So is rape.

Have you been living under a rock for all of human history and only come out in a western university in the past 20 years?

Rape is a social construct.

Go suck cock elsewhere

Attached: 1525962625947-g.gif (400x480, 124K)

Heavens no. But like Jow Forums or any other site, it will be posted eventually.

I plan to look into porn-detection software to keep it away.

>reading up on .net WCF for job

Why does all these concepts sound so fucking verbose? I bet you all it is is just queries and tcp/ip back and forth shit.

>No srsly this should be basic af and self-evident

I have the reference documentation opened here and the class Node has absolutely no reference to attributes. The Attribute class contains nothing that would give me a way to retrieve it either. I tried googling and it shows me several results, but all of them don't work in the C++ version. If it's that obvious I would've found it by now.

Homophobia implies i'm afraid of homosexuals, but that's not the case at all. I'm just disgusted by them, in the same way i'm disgusted by necrophilia and shit.

Is there a difference between
int* p;
and
int *p;