/dpt/ - Daily Programming Thread

What are you working on?
Previous:

Attached: 1527722726562.jpg (500x341, 105K)

Other urls found in this thread:

pastebin.com/JqaHGztT
dlang.org/articles/lazy-evaluation.html
twitter.com/SFWRedditImages

mathematics are gay

I'm trying to figure out how to calculate how much power to give to each thruster on a floating craft to achieve either a given acceleration vector with no or minimum rotation, or a given rotation with no or minimum acceleration.

is for a videogame?

Same, having a difficult time with it so far.

Yes, specifically a Roblox game.
Which makes the maths much easier since Roblox has such versatile vector and matrix classes, but it doesn't make the algorithms any easier.

I don't know what's so hard about getting prime numbers. This code does it fine.
def _(__):
_______,________,_________,__________,___________=1,0,2,3,-1
___,____,_____=[____________ for ____________ in range(__________,__+_______,_________)],________,________
while _____!=___[___________]:
_____=___[____]
for ______ in ___[____+_______:]:
if ______%_____==________:___.remove(______)
____=_______+(____*(_________+___________))
___.insert(________,_________)
return ___

print(_(1000000))

real 0m1.435s
user 0m1.288s
sys 0m0.040s

getting to structs and such in my slow C learning
// (1) I think this is an anonymous struct given a typedef of complexMaker
typedef struct {
int a;
int b;
complex C;
} complexMaker;

// (2) this struct has a name, and the typedef has a name
typedef struct hello {
char hi;
short int number;
} hiStructTypedef;

// (3) define a "struct audience", create variable "convention" of that type
struct audience {
int headcount;
char* location;
} convention;

// now we have two variables of type "struct audience"
struct audience concert;


I thiiiiiink I sort of see, at least #3 for sure. I have read a few times that #2 is better than #1 because of forward declaration, but I have to play with that to have it come to me naturally. I have also read that in #2, having both the struct name (hello) and the typedef name (hiStructTypedef) be the same is a common idiom. (also am I right saying struct name is hello, typedef name is hiStructTypedef?)

#include
#define TRUE 1
#define FALSE 0
#define digitarraysize 10

int assembleinteger(int integer[]);
int power(int base, int exponent);

main()
{
int SIGN = FALSE;
int i=0, j=0, base=10;
unsigned char c=0;
int integer[digitarraysize];
signed long int sumint=0;
signed long long int finalsum=0;
for (i=0;i= '0' && c

not finished yet, this program computes the sum of two integers, normally this would be a trivial task, but this program has a user interface which adds some complexity to how the program processes its data; one character is retrieved from the standard input, if this character is a digit, convert it into a decimal integer and put it into the array, if it is '-' set the variable SIGN to TRUE (this will be used to preserve the sign of the input), whitespace is interpreted as being the end of a number and so when whitespace is encountered the program makes a call to a function which 'assembles' an integer from a sequence of single digits, this is accomplished by computing the place value of each digit in the array and naturally the numbers fall into their places when summed; i am liking how this program is turning out so i might just turn this into a full-blown calculator program.

What is so hard to understand about 'rewritten' you autistic faggot? Java isn't that cross platform so they switched to C++ to get to consoles and all smartphones and then it bubbled to the desktop version and PE part was dropped.

Someone redpill me on Google's closure js. Google themselves don't even use angular, yet they shill that monstrosity so hard. Looking at all of their succesful apps; search, analytics, keywords, Gmail they use some fancy js framework called closure. Is this based? All their other meme stuff like YouTube, feminists propaganda landing pages, google plus, Google play music uses angular anyway. Inb4 >>>/webshit general. Those fagots are also sheep following the latest meme technologies without second thought and will give me generic answers

Attached: 3041.jpg (1920x1152, 209K)

me second from the right

Will Javascript and "everything is a browser" cancer ever end? Or it won't end and programming will not be the same anymore?

I just read that Microsoft is going to rewrite a lot of stuff using Electron. Fuck...

>Download open source code
>Make small modifications
>Upload to my own github account as mine
Is it seriously this easy?

python in the browser is your saviour

HTML/CSS is the unrivaled king of UI, but webassembly might kick out javascript, so you at least have that to look forward to.

not much of an improvement

I wrote a program that does this automatically, i.e:
def primes_sieve2(limit):
a = [True] * limit # Initialize the primality list
a[0] = a[1] = False

for (i, isprime) in enumerate(a):
if isprime:
yield i
for n in xrange(i*i, limit, i): # Mark factors non-prime
a[n] = False

print list(primes_sieve2(1000000))
becomes:
def _(__):
___ = [True] * __ # ____ _____ ______ list
___[0] = ___[1] = False

for (_______, ________) in enumerate(___):
if ________:
yield _______
for _________ in xrange(_______*_______, __, _______): # __________ ___________ ____________-_____________
___[_________] = False

print list(_(1000000))
Here's a pastebin link: pastebin.com/JqaHGztT

they even make it easy for you, it's called "forking"
what do you think you're getting out of it?

Bonus points with application reviewers who are too lazy or too busy to actually inspect my github projects.

enjoy living in fear of being discovered as a fraud, up until 2 weeks later when you are discovered to be a fraud
enjoy failing any technical tests
enjoy the humiliation of being asked about your github projects and being thanked for your time 5 minutes later

>implying I don't have my own github projects as well
>implying I don't know how to program
>implying they would know enough about them to don't realize I'm bullshitting them when they ask
>implying github projects have any ramifications on the job after you're hired

Attached: 1495617466771.jpg (236x226, 14K)

>Learning haskell
>making simple program to practice
>ends up with C-esque program with haskell's do notation

Well, most practice programs in books for imperative languages don't separate IO and logic in a clean way. You try the same design in Haskell since that's the way you learned how to program. It just requires switching your thinking a bit.

How to fake git commit history? I never upload my projects online and i just commit versions so local commits are rare.

dumb frogposter

wow you really gamed the system bro
thanks for the cool discussion, good luck

Haskell is the best imperative PL.

Chrome running on electron when?

I dreamt in code last night. It was haskell, I couldn't understand it.

dumb frog poster

anyone here code on durgs

Attached: 1523835759158.png (1012x630, 85K)

Im not degenerate

Spent the last evening fighting the borrow checker, apparently it's quite hard to implement relatively simple abstraction without resorting to RefCell, and I'm writing for no-std. My intuition kept telling me there's a simple and correct solution for the problem that the BC would accept, but I failed to come up with one, wasting hours randomly changing lifetimes until the code compiled.

Attached: enough_is_enough.jpg (270x259, 18K)

>i'm not cool

>rustfags will defend this.

I am a Rustfag tho, I do realize no-std(i.e. no allocation) makes abstractions harder to implement. In the end, I kinda stumbled into a (partially) working solution.

>t. Brainlet who need perfoormance enhancing drugs
Stay cool degenerate

Attached: 1528795486506.png (290x352, 78K)

i'm hot and cool

Isn't there a pastebin with a link to coursera videos?

What does haskell do differently in that regard? Does it just sequentially separate input from operation or is it more complicated than that?

Sorry in advance for dumb question.

I have an object, Object obj , and I need to pass it into a class. To prevent needless copying, I want to simply pass in the address of the Object , but I'm running into a conceptual understanding issue:
How would I make sure that the Object I pass in never goes out of scope?

Example:
NewObject nObj [ N_ELEMS ]; //stores a pointer to an object
for(int i = 0; i < N_ELEMS; i++)
{
Object obj = generateObject(i);
NewObject newObj( & obj ); //use the address instead of copying
nObj [ i ] = newObj;
}


Would I be able to call on the Object pointer after the for loop? If not, how would I fix this? Would one of C++'s special pointer classes work?

Ideally you should take the input using impure functions, process it using pure functions and output the result using impure functions. This sequence can either appear in the program once, or many times over for more complicated applications.

Do you plan to store &obj inside newObj? If you do, you should just copy it. If not, it's safe to use nObj after the for loop.

The object pointer will still exist, but using it after it goes out of scope (i.e. after each iteration of the loop ends) will cause your program to read garbage memory. Unpredictable things will happen.

The simplest solution is to allocate an array of Objects outside the for loop, like this.

// Assuming Object has a default constructor so an empty array can be created.
Object objs[N_ELEMS];
NewObject nObjs[N_ELEMS];
for (int i =0; i < N_ELEMS; ++i)
{
objs[i] = generateObject(i);
nObjs[i] = &objs[i];
}
Then your objects will live as long as the outer scope, so pointers to those objects will be valid until you return from that scope.
That might be good enough for these circumstances, but in the general case you will need to use new/delete or those special pointer classes to control exactly when objects go out of scope.

In C++ when declaring an object using the non-default constructor what is the most common way to initialize this object.

This way:
int n1 = 1;
ClassFoo obj1 = ClassFoo(n1);

This way:
int n1 = 1;
ClassFoo obj1(n1);

Or this way:
int n1 = 1;
ClassFoo obj1 = n1;

Attached: 9003929.jpg (818x720, 78K)

The suggestion these days is to use {} everywhere, and to fall back on the () style where it's necessary (i.e. when you want to avoid a std::initializer_list overload).
e.g.
int n1 = 1;
ClassFoo obj1{n1};

C++ is a fucking abomination.

So if I had multiple arguments I would just:

int n1 = 1;
int n2 = 2;
ClassFoo obj1{ n1, n2 };

?

Yeah.

WTF, this doesn't make any sense.
Fuck you!

Attached: xcom3.png (767x372, 65K)

Alright I give up,

What is it?

And why are you making me autistic reee look a graph with mis-aligned ticks?

320 x 240

I am learning perl.
I am doing the exercises from an o'reilly perl book but I am stuck. I want to input digits to the array @lines and use each line, or digit, as an index for the array @names and print them out. This is what I have so far and it doesn't work. Pls help (ignore output format)

@names = qw /bill bob joe/;
chomp(@lines = );
foreach (@lines) {
print $names[$_];
}

That's basically how I write C. With few exceptions.

>I am learning perl.
Why tho? Unless you're forced to, it's a complete waste of time and will only make you a worse programmer.

run before the perl shill notices you

>pearl
And I thought C++ was the ugliest looking language ever conceived.

Attached: 34536547676.png (762x506, 48K)

just a screensaver for now

Attached: 1483899740618.png (600x558, 276K)

is that an HTML REGEX PARSER

Daily reminder that your functions are not pure if you use assignment operators outside of definitions, implicitly or explicitly.
This also includes ++ and -- operators.

Attached: Screenshot at 2018-06-14 12:50:25.png (1245x910, 194K)

D-fags are pathetic, they try to steal all the trendy stuff from the other languages, but fail to implement it anywhere close.

If it has a pure interface (i.e side effects are not observable when treating the function as a black box) it is a pure function.

After at least 6 months of messing around with C today I learned that the order of arguments in the gcc compiler actually matter, I thought it didn't really. I lost too many hours trying to compile my first ncurses program.

You should take a look at their """lazy evaluation""".

Remember: libraries always come after source/object files.

function local mutation is still pure your mong.

I've spent so long trying to figure out a way to send a key repeatedly to a directx game on windows, SendInput/PostMessage/SendMessage don't work, I don't know what the fuck it is but they will either get ignored by the games anticheat or something.

How on earth can I send a emulated keyboard input to act as a real keyboard signal, I cannot write a driver and do all this troublesome redirecting stuff I just need a simple way to do this.

Why can windows "on screen keyboard" work perfectly and act as an actual irl keyboard but nothing in the microsoft user32lib works as everything is just virtualized on some level.

Attached: angry racoon3.jpg (248x250, 41K)

Reminding myself how to write even simple programs in C. Yesterday I realized that a linked list data structure, that I implemented in C at least 4 times without any problems in the past was a hard task, that took me too much time. The observation is that even if you programmed a lot in the past and then had a break, it takes time to remind yourself how to do even very simple things. So if you have a job interview and they'll ask you to write something simple in a language you haven't used for a long time, then take your time at home to remind yourself before the interview. Another factor is writing code on a blackboard in front of people you don't know. There's stress and it makes you forget some important things.

what's wrong with it?

>also am I right saying struct name is hello, typedef name is hiStructTypedef?
Yes

Why the fuck lazy evaluation is considered as a good thing?
The program could suddenly crash because of stack overflow if it needs to evaluate a really long chain of function

>The program could suddenly crash because of stack overflow if it needs to evaluate a really long chain of function
t. no idea what lazy eval is

It completely misses the point of it.

Your strict program would still crash, it'd just crash sooner.

How so?

>The program could suddenly crash because of stack overflow if it needs to evaluate a really long chain of functions

Attached: 1514754118023.jpg (989x1000, 76K)

Lazy evaluation is a way of having infinite data structures that are actually useful.
D's """lazy evaluation""" is just a shitty little "optimisation" that has absolutely nothing to do with infinite data structures.

Honestly, I've spent so much time writing Lisp interpreters that I can't imagine myself struggling with linked lists at this point.
(defun combinations [n . elems]
(let [crutch (fun [n]
(if (= n 1)
(map list elems)
(let [prev (self (- n 1))]
(flatten (map (fun [elem]
(map (cons elem) prev))
elems)))))]
(cond
(< n 0) (raise "negative count")
(= n 0) '()
:else (crutch n))))

thanks, since you took the time to comment on that I'll assume there's nothing that looks like a glaring misunderstanding in my 3 examples/comments

>directx
>windows
>microsoft
>user32lib
I can't imagine why you're having trouble

Ooops meant for

>is just a shitty little "optimisation" that has absolutely nothing to do with infinite data structures.
You've made no valid points my man. How extensively have you actually used d?

>he prounces char like charmander

Attached: laughing.png (1920x1080, 854K)

Anyone know where I get some "programming socks" like this?
Also, anyone got any advice on

Attached: 1498093050557.jpg (2000x1500, 632K)

Please put me out of my misery, I want this done, but it feels like its an impossibility.

Why the fuck can windows on screen keyboard work perfectly, what does it do differently?

Sigh

that's a physics question moi boi
ask on /sci/ (Science & Math)

I have 3 days free drom work i want to do some project but i have no idea what. I wanted to do indexer service that will jndex my drives and server that will host shit in db ao i can just check fdeom phone or whatever where my stuff is. But entire idea looks bit tedious

Write a spellchecker.

Show me how to implement this using D's """"lazy evaluation""""
repeat' x = x : repeat' x

take' 0 xs = []
take' n [] = []
take' n (x:xs) = x : take' (n - 1) xs

-- in GHCI this evaluates to [0,0,0,0,0]
take' 5 (repeat 0)

Depending on where thrusters are imagine aircraft is triangle, convert power to thrust i.e acceleration vector. And for angle just do high school trig i.e atan2 to your target. Add vectors together and voila

Im phoneposting and simple spellchecker is simple and boring project, get word list and just meh...

>take' 5 (repeat 0)
They have a similar example on the lazy page
void dotimes(int count, lazy void exp)
{
for (int i = 0; i < count; i++)
exp();
}
void foo()
{
int x = 0;
dotimes(10, write(x++));
}

dlang.org/articles/lazy-evaluation.html

>similar example
Okay, I confirmed that you have no idea what we are talking about.

// ConsoleApplication10.cpp: Definiert den Einstiegspunkt für die Konsolenanwendung.
//

#include "stdafx.h"
#include /* printf, scanf */
#include /* time_t, struct tm, time, mktime */
#include
using namespace std;

void main()
{
int year, mon, day;
struct tm t = {0};
cout year;
cin >> mon;
cin >> day;
t.tm_year = year - 1900;
t.tm_mon = mon - 1;
t.tm_mday = day;
t.tm_hour = 0;
t.tm_min = 0;
t.tm_sec = 0;
time_t tme = mktime(&t);
cout year1;
cin >> mon1;
cin >> day1;
t1.tm_year = year1 - 1900;
t1.tm_mon = mon1 - 1;
t1.tm_mday = day1;
time_t tme1 = mktime(&t1);
cout

How about you try doing it now, on a piece of paper? Write a function to remove all elements with value given in the argument from the list. Post it here in code tags. Then check for yourself, if you haven't done any stupid mistake. I think this might be a good experience to have.