/dpt/ - Daily Programming Thread

Old thread: What are you working on, Jow Forums?

Attached: 1557820968571.png (1734x2454, 2.43M)

Other urls found in this thread:

jsfiddle.net/XBfzn/
en.wikipedia.org/wiki/PID_controller
skulpt.org/
pypyjs.org/
pastebin.com/XBGirk0u
pastebin.com/HAA29Yzp
man7.org/linux/man-pages/man3/pthread_create.3.html
pastebin.com/vUCfLWgn
pastebin.com/xhYg1Lrm
twitter.com/NSFWRedditGif

Ugh I hate anime!
Anime is for gross loser pedophiles!
I'm certainly not just baiting you to post delicious cute 2D girls at me or anything!
I'm warning you! Don't do it!

would be better if she were shopped with black skin.

>What are you working on, Jow Forums?
Rewriting some old Lua scripts in C.

I'm trying to get in c and I'm trying to figure out how to clean this bit of code up:
If((x[1] & y[0] == false) || (x[0] & y[2] == false) || (x[2] & y[1] == false))
Basically I'm looking for a short hand way of getting rid of == false. With out it thinking I'm trying to equate the two.

This isn't a valid C program. Post the full program so we know it doesn't abuse UB.

/* if (x == false) { ... } */
if (!x) { ... }

Is rust a good language to learn? Is it too verbose like Java?

Attached: 1555803728332.jpg (500x375, 54K)

Rust is an even bigger clusterfuck than sepples.

Since this is part of a C program, I am assuming it invokes UB.
Thus a shorter cleaner way of writing this would be:

Yeah I just figure that out thanks friend.
I feel dumb
I just typed that up so you dont see my poorly named variables... what about it for I mess up

Thinking of writing a transpiler to C++, purely just to improve the syntax.

Im rewriting my Java based ffmpeg complex filter generator in scala. It basically allows me to easily generate ffmpeg complex filters to do things like create a 4x4 matrix of movies. I use it mostly for generating porn collages *shrug*

You'll still have the terrible compile times

Not an issue.

i want to nakadashi akarin

I want akarin to nakadashi me

based and akapilled

what are some good ideas for projects in C?

So how bad is it? Finding the mode of a sorted list.
for (int i=0; icount2) {
mode=current;
} else {
mode=oldcurr;
}
}

What's the non-pajeet way to do it?

Linuxlet here, we're gonna have one of the graduating students to explain us about git at school. should I seize the opportunity and ask her to teach us something else? I was thinking of Bash, it seems quite useful. maybe just general Linux stuff like aur

just read the linux pocket guide from Oreilly

Ask her to read the interjection copypasta

Will do, thank you

I'm gonna lick your eyeballs

Attached: images (9).jpg (588x522, 31K)

web scraper

template
T& sortedMode(std::vector v) {
if (v.empty()) throw std::runtime_error("vector is empty");
T &mode = v[0];
std::size_t count = 1, best = 1;
for (std::size_t i=1; i best) {
best = count;
mode = v[i];
}
}
return mode;
}


Why not just have her teach git?

That was lame, I left in a continue from before I changed it to use else if. You can ignore that line

Why is ijk often chosen for indexes?

old thread still only page 7 with 400 posts, why would you ruin this OP. i hate Akarin now.

i for index
j comes after i
and so on
but i j k notation is ubiquitous in engineering as well

Old thread was awful. Better to start fresh.

i for index and j and k directly follow it.

>but i j k notation is ubiquitous in engineering as well
Isn't this for some imaginary number stuff or vector stuff though?

i for index j for JUST and k for kill myself

yep, for different stuff other than indexing

400 posts is a lot, I see people use their "new thread" post to hit the bump limit

And engineering originally gets it from mathematics, which used it in summations (which work kind of like for loops). They called it the index of the summation, thus i. In a burst of creativeness, we named the ones that came after that j and k. And now our quaternion symbols totally overlap and it sucks

There are only 26 letters in this alphabet and people freak out when they see greek so there is bound is to be some overlap.

i is used for complex numbers by mathematicians and physicists, electrical engineers use j because i is already used for current.

>400 posts is a lot, I see people use their "new thread" post to hit the bump limit
>"people"
they aren't human unless they wait for 310

Thanks, that's a lot better. Realized my shitty solution was broken, only worked some of the time probably purely by chance lol.

Practice makes perfect, eventually this kind of thing will be more automatic.

I want to finally get out of the house and maybe see if I can enjoy life. There's a company I think would be good to work at but the job listings are all for specific fields and not just generic programmer. I don't have any experience so am I fucked? What kinds of stuff could I do in my free time to look good for jobs like "Game Engineer"? It's a japanese company as well so I'm probably fucked from my lack of proper japanese either way but I'm not doing anything else so I may as well try.

Not sure where else to post this. Please respond.

Attached: 1396571416586.jpg (278x278, 37K)

(you)

It's (You) newfag...

;^)

I've been here since 2018 faggot.

Anyone want to solve my challenge today? jsfiddle.net/XBfzn/

The point is to balance the bot by editing the code box at the bottom. You can also score points by reaching the flags on either side.

Attached: 1556392496825.png (181x256, 59K)

>I want to finally get out of the house and maybe see if I can enjoy life
I feel for you user, but if working is your goal, the best way to maintain your quality of life is to pick a good career first and follow your passion as a secondary objective. Gamedev jobs are the kind where everyone is their for their passion, and they don't get paid as much for the same skilled work as they would in other subfields. And basically the whole of Japanese work culture is like that too, the "modern" companies that treat their employees well by western standards are few and far between. You should know that if you're a weeb

Rustaceans rise up

Work on a way to actually turn into Cirno. I don't mean a tranny or even a cosplayer, but actually cirno. I'll hire you.

cutest picture of akari I have ever seen, change my mind

>be a cunt
>expect people to solve your problems
female logic

It's not really a goal but I feel like shit. The worst part is my lifestyle is probably sustainable but I'll just spend decades doing nothing and wanting to die. Maybe working on games and programming would be good for me. It's not like I'll use the money though.

>the "modern" companies that treat their employees well by western standards are few and far between
This is one of those companies.

If I could do that I wouldn't be here.

It's funny because it would take you a month to solve it even if you wanted to.

Attached: 1487228351514.jpg (520x780, 39K)

all the more reason for everyone not to bother

How is enterprise C++ amy better than enterprise Java?

You can't make me use OOP

How are store bought apples better than store bought pineapples?

angry white men vs angry brown men

Idk, I used to think I wanted to go out and work like you, and now I just miss having more free time and hanging out with friends.
Working is a good experience to have done in your life and teaches you a lot but I don't live for work and never will.

Hey, I solved your challenge a while back but I replied late and I think you didn't catch it (or if you did, I missed that)
//hack to allow me to run the program twice
(() => {

reset();

//idea: pid control of robot angle
//have a target x, but doesn't directly control robot
//x versus target x is used to calculate target angle
//PID control is used on angle
class Controller {
constructor(target, speed, P, I, D) {
this.target = target;
this.speed = speed;
this.int = 0;

this.P = P; this.I = I; this.D = D;
}
control (x, dx, ang) {
let xDiff = x - this.target;
let tAng = this.speed * Math.tanh(xDiff / 25);
let err = tAng-ang;
this.int += err;
this.int *= 0.9;

let p = this.P * err;
let i = this.I * this.int;
let d = this.D * (dx + Math.sin(toRadians(angle))*Math.PI);
let throttle = p + i + d;
this.applyThrottle(throttle);
}
applyThrottle(throttle) {
throttle *= 255;
if (throttle >= 0)
goRightAt(throttle);
else
goLeftAt(-throttle);
}
}

let compete = true, left = 100, right = 300, m = 10;

let c = new Controller(compete ? left - m : x, 30,
0.1, 1e-3, -2);


window.mainLoop = function mainLoop() {
c.control(x, dx, angle);
if (x < left) c.target = right + m;
if (x > right) c.target = left - m;
};

})();

Just because you are inept does not mean that everyone else is. 4channel is not one person

>Hey, I solved your challenge a while back but I replied late and I think you didn't catch it (or if you did, I missed that)
I am sorry I missed it! Nice solution. You are the winner! Really nice job!

nobody cares about your challenge, it's js so it isn't even programming related

>nobody cares about your challenge, it's js so it isn't even programming related
>algorithms aren't programming related
OK bud. user-san already solved it and user-san solved it very well. Other user's please try and post results!

Attached: bot_4.png (424x225, 11K)

cringe and bluepilled

Forgot to link user-san. I blew it!

yeah don't listen to that user, people on /dpt/ are rude
come on over to /wdg/ with me, we love js over there!

I agree

Attached: agree.png (778x641, 51K)

>come on over to /wdg/ with me
No thank you user. PID algorithm was originally invented when a programmer was thinking about how a boat's captain attempts to turn a ship..

en.wikipedia.org/wiki/PID_controller

Attached: 800px-Pneumatische_regelaar.jpg (800x826, 159K)

Thanks buddy, I appreciate it.

Attached: tenor.gif (370x300, 332K)

yes but /wdg/ is friendly! and we love love faggy js sooo much

Why are you so mad that I made something that you cannot solve? Disregard the language. Look internally to what is causing you to act this way.

>people on /dpt/ are rude
you are replying to this dude

If I want a function to return a hex code in c++ like 0x140005 what type should I use?

hex is just a representation of a number so just use a normal int. Or use three chars for each color.

sorry bud, but these are language wars threads

What's hilarious is these guys are okay with python but somehow JS crosses the line and they can't stand it

>If I want a function to return a hex code in c++ like 0x140005 what type should I use?
You just store those in regular integers like normal. I suggest the fixed width types from . A hex literal like 0x140005 in C++ is really another way of writing an integer. Then if you want to get individual bytes, you use bitwise operations to get it, e.g. hexNum && 0xff

I could program the challenge in C, use any graphical or terminal output that you prefer. Would that make you any more inclined to solve the challenge? Or would a link to a site that is trusted and running a language that runs in the web browser more accessible?

Attached: 1479693295563.jpg (1920x1080, 113K)

>using c in 2k19
no wonder she's dead lmao

One option is to make it in python since somehow that runs under their noses. You've got a couple of options:
skulpt.org/ this one is written natively in js by a human, probably your best bet
pypyjs.org/ this one is compiled from original source by emscripten, very heavy weight and probably has a bad API, but will run python perfectly

Not dead. Just comatouse... and defenseless...

rust will look like a verbose language like java if you are new, but every bit of keyword is meaningful.
many c/c++ programmers that i know of, once they learn of rust, they just wished their projects are written in rust so that should tells you about the future of rust
if there's a new project out there, its likely going to be written in rust because its just so convenient to deal with.

I get what you are saying. I unironically love python. Anyways, time to get back to projects. Is /dpt/ ready for some progress reports?

Attached: 1479089867493.jpg (336x476, 41K)

i just realized its a sorted array, but if its unsorted, one could use hashmap to have O(n) algorithm.

Not going to lie, I love Python too. Python has much more pleasant builtins/syntax than JS.

dude if i can just work on anything, i dont care if im being paid minimum wage if its doing something i like, im living like a homeless person regardless
i just want to program shit that people use man....

Yup, this is a common interview question.

I'm trying to learn c++ now, still a noob at it. I am trying to learn multi threading, and i was trying to implement odd even transposition sort. I'm having some trouble getting inputs to my thread. I'm trying to create a thread for every swap i'll have to do. swap() will check if the element i give it as input is greater than the next one and swaps them if so. all the even swaps will be done in parallel, then all the odd ones, and so on. I can't figure out how I'm supposed to give the array and the index as parameters to the thread tho. could someone help me out?

code:
pastebin.com/XBGirk0u
error message:
pastebin.com/HAA29Yzp

almost half of the "do this in O(n)" algorithm will involve hashmaps

abc isn't void*, just cast it

thanks, but sorry, i don't know what "cast it" means, what should i do?

Matt are you trying to astro turf your next project

Attached: matt_the_turfer.png (1202x664, 145K)

It means that you choose a type for the value and then you tell the compiler that you would like that value to be interpreted as that type.

oh ok thanks
where do i put that? in the function definition for swap? or in the pthread_create statement?
what's the syntax?
I'm sorry if i'm too dumb, i just started learning

>I'm sorry if i'm too dumb.
I'd say it's OK, but it isn't. Oh well. Not everyone is meant to be a whistler.

i tried doing void*(ABC), but then i get the error message
error: request for member 'A' in 'ABC', which is of non-class type 'void*'
if(ABC.A[ABC.n] > ABC.A[ABC.n + 1]){
^
how do i turn it back into the structure?
is there any way to send multiple parameters into the thread function without using structures?

I don't know what does the documentation say?

The compiler is complaining because the parameter of swap is of type abc rather than void*. You need to make its signature void* swap(void *ABC) {, but that won't solve all your problems. Right now what you're dealing with in this program is pointer problems rather than thread problems.

Reading to the pthread docs: man7.org/linux/man-pages/man3/pthread_create.3.html pthread expects you to pass in your ABC parameter as a void pointer. Then the swap function for that particular thread will receive the pointer and convert it back into an *abc pointer. The reason it's a void pointer is because pthread isn't choosing for you what shape of data is getting passed into the thread.

Your use case is a little more complicated though, you want to pass in abc AND an element, so you probably want pthread to actually pass
struct thread_data {
abc *ABC;
size_t elementIndex;
};

which is basically a wrapper object to hold all the stuff you want to pass to the thread.

But I should restate, I think your problems are pointer problems. Rather than fight with complicated thread code, I would do a bunch of pointer exercises to get yourself familiar with them before diving into the deep end.

You're an asshole.

Does this work? You re-point the reference mode. And wouldn't this do a bad on account of returning a local by reference? vector v is passed by value, making it a local copy, and mode is a reference to a value of v, returned by reference.

oh ok i got it i was just fucking up the type conversion, i got it now, thanks
pastebin.com/vUCfLWgn

ok, no i didn't. I didn't get any error, but the function isn't doing any actual sorting. I'm getting the same unsorted input list as the output.
Why is this happening? I'm giving the list i took from main to the oddEvenTransSort() function as a pointer to the first element, and i'm sending it like that to swap() too, so i'm actually sending the reference to the original list and not copying the values, right? shouldn't the swaps done be reflected in the original array when i print it out in main later? what am i doing wrong here?
code:
pastebin.com/xhYg1Lrm