/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: cs-grad-combination.png (1500x680, 102K)

Other urls found in this thread:

github.com/nlohmann/json
my.mixtape.moe/aycxep.7z
rosettacode.org/wiki/Combinations_with_repetitions
lkml.org/lkml/2015/9/3/428
users.telenet.be/vdmoortel/dirk/Maths/PermVarComb.html
twitter.com/SFWRedditImages

my mental health problems

Turned down a Haskell job today in favor of a C++ job.

>things that never happened

how would Jow Forums solve it?

Ideas for c/c++? I want to work on something useful.
Is there any particular program or feature that you want done?

I did my own binary data encryption program in C

Fuck CUDA

Is it military grade?

I've always wanted a progran that told me I am a brainlet in at least thirty different languages.

Probably not. But it will probably be good enough to stop most amateur hackers from bothering to crack it. I could post an encrypted file if anyone wants to try.

(,,) ['A'..'C'] ['A'..'C'] ['A'..'C']

Why doesn't c standard have macro like zero that's basically
#define zero(p) memset(p, 0, sizeof(*(p)))

>refused yet another job offer
keeping my sweet employment virginity for a haskell job.

Attached: 1492554590171.png (718x718, 600K)

>t. asshurt amdjeet

Attached: 1499400580700.jpg (568x612, 66K)

take something not useful and add anime and tiddies to make it more useful

>company puts new job ad
>"we highly encourage females apply because we want more even gender distribition"

Isn't this like exteremely sexist? So they will hire a less experienced female just to force 50%

Because it was made almost two decades ago and back then nobody thought it would be a good thing to have.

>that pic
I know the guy who wrote that code. He dropped out of CS and did Software Engineering instead. He's an employed C++ code monkey now.

as if any female will complain about it.

Is it you?

doesn't even give a solution for the puzzle,
there's 12 "questions"

sequence $ replicate 12 ['A'..'C']

>Is it you?
N-no. I'm a CS gradute. Honest...

Attached: e7db9e4e33592de521b23e955084488e.jpg (601x508, 34K)

Remember kids, it is perfectly alright to enjoy mems like haskell, brainfuck or functional programming. Just don't put it on your CV if you don't want to get it thrashed instantly

>not wanting to stay NEET

sure go ahead

>Isn't this like exteremely sexist?
Yes, it's just toxic masculinity trying to assert its superiority and to put women down again. This is why we need more female CEOs to institute such measures instead.

I'm can't think of any other way to solve this in C++ except by recursion. I'll leave the brainlet meme implicit

Tuples[{A, B, C}, 12]

Its actually true, though.

how does that translate to python though?

can you use itertools?

Post the position and we'll see

>t. i put template metaprogramming fizzbuzz on my CV
I'm sure they'll call you back. Any day now.

It was posted a couple threads ago.

Attached: cs-grad-units.png (750x1050, 183K)

JSONStruct converter that doesn't suck

Why are low-IQ "coder" brainlets always so proud about their illiteracy and lack of education?

>JSONStruct converter that doesn't suck
>in C++
Basically never going to happen in a trashlang like that.

because that's what's what all the ads told them to do.

what's the non pleb way to solve this?

>that's what's what all the ads is of tellings they be of doings
What did she mean by this?

What are the criteria for "doesn't suck"?
github.com/nlohmann/json

Here it is
my.mixtape.moe/aycxep.7z

count from
000000000000 to
222222222222
in base 3, and print out the strings with 0-2 mapped to A-C.

>why are lonely kissless virgins living in their mother's basement so proud about their autistic behavior, repulsive personality and disgusting appearance ?

>Every type can be serialized in JSON, not just STL containers and scalar types. Usually, you would do something along those lines:
ns::person p {
j["name"].get(),
j["address"].get(),
j["age"].get()
};

>It works, but that's quite a lot of boilerplate... Fortunately, there's a better way:
ns::person p2 = j;
// that's it
assert(p == p2);

>To make this work with one of your types, you only need to provide two functions:
void to_json(json& j, const person& p) {
j = json{{"name", p.name}, {"address", p.address}, {"age", p.age}};
}

void from_json(const json& j, person& p) {
p.name = j.at("name").get();
p.address = j.at("address").get();
p.age = j.at("age").get();
}

Oh my fucking sides... The absolute, irrecoverable, mind-boggling state of C++ and its """programmers""".

Attached: 729.gif (340x340, 137K)

Because a lot of time the size isnt exactly sizeof and C programmers aren't afraid to type an additional 10 characters when they memset.

Because that's almost always incorrect?

Trying to get a chess program working in Java. My logic for check is wrong yet I can't see the problem.
>Not sure if my knowledge of chess is bad, or my programming is bad.

Recreate useful libraries from other languages and choose to selfishly keep them to yourself or become a hero and release them for free.

well what is the problem?

>tfw want to post my github but do not want to get doxxed/affiliated with Jow Forums irl

yea you better not post it bitch

rosettacode.org/wiki/Combinations_with_repetitions

protect your hyperlink with military grade rot13 encryption. only the true programmers among us will be able to decode it.

That library crashes with invalid json. It is horrible to work with

>rot13
Isn't that the encryption the French special forces us?

>military grade rot13
lol

Crashes or throws an exception? Very different things

uggcf://tvguho.pbz/junggurshpxvfguvfohyyfuvg

literally don't know the difference senpai. it just stops working

oops I that second map should be applied the the result of the first one, not inside...

yea, everyone knows there's no Haskell jobs.

didn't know about that function

nice

solution:
from itertools import combinations_with_replacement
n, k = 'A B C'.split(), 12
for i in (list(combinations_with_replacement(n,k))):
print (''.join(i))

>Why doesn't c standard have macro like zero that's basically
>#define zero(p) memset(p, 0, sizeof(*(p)))
Wonderful idea, lad. Linus would absolutely love this. You should submit a PR.
lkml.org/lkml/2015/9/3/428

>.map({ vals[Int($0)!] })
That shit makes Rust even look pretty.

Crashing would be a segfault or similar because of unsafe code. Throwing an exception means it can be caught and you can handle the error. C++ exceptions and a bit controversial, but in this case you can have a clean interface where the parse function always returns a valid JSON object. If the input isn't valid, the function never returns (it throws and you can catch where appropriate).

let vals = ["A", "B", "C"]
let n = 12
let combinations = Int(Double(vals.count), Double(n))
for i in 0..

>list(combinations_with_replacement
cwr() is a generator, forcing it to a list is retarded

>D

Attached: eyebleach.jpg (450x300, 20K)

yeah you're right
from itertools import combinations_with_replacement
n, k = 'A B C'.split(), 12
for i in combinations_with_replacement(n,k):
print (''.join(i))

In C++
#include
#include
#include

using namespace std;
vector options{ "iced", "jam", "plain" };

void print_vector(vector v, int n, vector s){
for (int i = 0; i < n; ++i)
printf("%s\t", s[v[i]].c_str());
printf("\n");
}

int combination_with_repetiton(int sabores, int bolas, const vector& v_sabores){
sabores--;
vector v;
for (int i = 0; i sabores){
v[i + 1] += 1;
for (int k = i; k >= 0; --k){
v[k] = v[i + 1];
}
//v[i] = v[i + 1];
}
}

if (v[bolas] > 0)
break;
print_vector(v, bolas, v_sabores);
v[0] += 1;
}

return 1;
}

int main(){
combination_with_repetiton(3, 2, options);
return 0;
}

How the fuck do I read multiple lines from a file using istream? I can't figure out shit.

???
import std.stdio, std.range, std.algorithm;

T[][] combsRep(T)(T[] lst, in int k) {
if (k == 0)
return [[]];
if (lst.empty)
return null;

return combsRep(lst, k - 1).map!(L => lst[0] ~ L).array
~ combsRep(lst[1 .. $], k);
}

void main() {
["iced", "jam", "plain"].combsRep(2).writeln;
10.iota.array.combsRep(3).length.writeln;
}

std::getline

>sabores
>bolas
wetbacks pls go

retard alert

The iterative version.

back behind the wall with your mexican excuses

public class Math_E{ //this multiplies out the values within a stored 2-dimensional array against those stored in a vector untill i can do variable-dimension

static void matx2d(int[] L1, int[] L2){
int len = L1.length*L2.length;
int[] products = new int[len];
for(int i = 0; i < len; i++) {
products[i] = (L1[i%L1.length]) * (L2[Math.floorDiv(i, L1.length)]);
System.out.print("i:"+i+"-L2["+Math.floorDiv(i, L1.length)+"]-L1["+i%L1.length+"] -- ");
}System.out.println();//for formatting reasons
for(int n: products) {
System.out.print(n+":");
}
}



public static void main(String[] args) {//main method
int[] L1 = {1,2,3,4};
int[] L2 = {2,4,6,8};
Math_E.matx2d(L1, L2);
}

}


i feel pretty proud of myself, i managed to write a program that multiplies 2 (vectors?) like in matrix multiplication and then stores that in a product array. Please /dpt/, tell me how i can improve.

Also, what's going on with the combination shit? Combinatorics or something?

If I call getline a second time will I get the next line?
I feel retarded

>thinking that is Spanish and not Portuguese.

mutt pls

yea

If you think it's so pretty why don't you marry it

Attached: compile.jpg (1200x1698, 231K)

>tell me how i can improve.
fix your pajeet formatting
>Combinatorics or something
yep, combinations with repetition, called 'variations' in some languages

>spic noises
back to your HUEhole, subhuman

>combinations with repetition, called 'variations' in some languages
hm, this may or may not be true
users.telenet.be/vdmoortel/dirk/Maths/PermVarComb.html

>not knowing about Portugal

sad

go prep the bull, mutt

man this seems ingenious. i can't wrap my head around it

>knowing about Portugalese
there's a difference between knowing the language you br-holes speak, and caring about it

>8 space indentation

>you br-holes speak,
but i'm Portuguese, though.

I don't care which part of br you come from, you all look the same to me

>not doing it like Linus Torvalds (Linux kernel style)

pleb detected

>I don't care which part of br you come from
nice reading comprehension

Attached: mapa-da-europa-portugal.jpg (1200x1076, 209K)

>not using fibonacci indentation

Attached: Cp-PmgcWcAAeX7z.jpg (885x464, 19K)

Attached: kys.gif (397x658, 964K)

>fix your pajeet formatting
for a formatting guide or anything somewhere, how do i format correctly?

huh, who knew the brazilians made spain name one of its states after their shit
for shame, spain

Guess you can always just do this:
#include

#define LEN 4
#define OPTS 3

int next_combo(int *combo, int len, int opts) {
int i;

for(i = 0; combo[i] == opts - 1; ++i) {
combo[i] = 0;
}

if(i < len) {
++combo[i];
return 1;
}else {
return 0;
}
}

int main(void) {
int combo[LEN] = {0};
char answers[OPTS] = {'A', 'B', 'C'};

do {
for(int i = 0; i < LEN; ++i) {
printf("%c", answers[combo[i]]);
}
printf("\n");
}while(next_combo(combo, LEN, OPTS));
}

>yep, combinations with repetition, called 'variations' in some languages
i have a vague idea of how to do that with 1 loop, a modulo operator, and generics.