/dpt/ - Daily Programming Thread

Good algorithms edition.

Previous thread:

Attached: myman.jpg (750x500, 77K)

Other urls found in this thread:

en.wikipedia.org/wiki/RdRand
blog.cloudflare.com/randomness-101-lavarand-in-production/
forum.dlang.org/post/[email protected]
theregister.co.uk/2013/09/10/torvalds_on_rrrand_nsa_gchq/
youtube.com/watch?v=gXbqJwtFC8c
edutopia.org/blog/dont-listen-music-while-studying-david-cutler
github.com/rust-lang/rust/pull/49255#issuecomment-375368749
github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
github.com/rust-lang/rfcs/blob/master/text/1951-expand-impl-trait.md
twitter.com/SFWRedditImages

programming is gay

Hashmap is the motherfucka most gangta data structure. /eom

thanks for the advice, I was wondering why my error was such shit
I eventually found some mailing list archive that suggested adding a "kill-buffer t" to it and it worked

I'm trying to remember why I started programming in the first place.

Attached: 1521227660589.webm (1280x720, 632K)

Pharo smalltalk is really comfy.

Attached: pharo.png (1366x768, 107K)

>be young and optimistic and want to make cool video games and shit
>realize that you're now working full time programming some boring project for your livelihood

if I want a class with two slightly different behaviours, is it better to use branching (if statements) or to create two classes?

Because the more I knew the more I could make the computer do. When I found out that people would pay me to make one do what they needed it to do, I was delighted.
Personal projects for the win, user.

>Personal projects for the win, user.
Those are nice, but it's hard to get motivated about doing more programming in my downtime

F U C K O F F , Y O U ' R E G A Y
U
C
K

O
F
F
,

Y
O
U
'
R
E

G
A
Y

It doesn't have to be more programming, or even in the same realm. I relax from dealing with making SCADA systems by by dicking about with a DSLR and image processing tools.

>Define a macro swap(t,x,y) that interchanges two arguments of type t.

#define swap(t,x,y) \
t temp = (x); \
(x) = (y); \
(y) = temp


Is this right? It works, just seems weird.

>Define a macro
stopped reading there

>C macro
>not even wrapped with do/while
you disgusting subhuman

Talking about algorithm,
How does random number generation algorithm works in C++?
std::random_device will generate a random number nicked from /dev/urandom or another random number source in the system,
then std::seed_seq able to generate unbiased random number sequence / array.
there is also random number engine, which basically an algorithm to generate random number,
and there is also a random number distribution, that takes random number and distribute it depends on their type evenly and randomly.

If every part is able to generate random number, then why most implementation use all of them in chain?
Why don't just use std::random_device to generate a random value, then pass it to distribution class directly?

to generate and random-er random

c#

what about it

Julia + Juno is comfier.

This is what you get for using a language with no generics.

Random number begin a fucking hell.
Every algorithm random number begin pseudorandom and had flaw, only hardware had better methods as special Intel instructions, but because fear Intel hardware begins tricked by NSA, libraries use multiple random number generators to build secure,slow random numbers and fast random number to simulation or initiation algortihms.

I made a program that does pic related~
Inspired by .
Any novices wanna try to make one? Mine is really.. Sloppy.

Attached: square.png (212x144, 20K)

awesome! I like it

Attached: 1520651715715.png (3840x2160, 1.61M)

I still need to fix mine, it looks fucked when there's punctuation

man::I.sure{ do::love, { [ sepples ](){} } };

Attached: Screen Shot 2018-03-22 at 10.11.59 PM.png (1066x1214, 246K)

what the fuck, why?

god ive always fucking hated '::'

Sooo...
Have you heard of Rust?

Attached: memory clock 1.webm (616x476, 1.78M)

I mean, almost everything here has a purpose except the stuff that was just lazy copy-paste.

Isn't a dedicated hardware seeder able to generate almost truly random number, and therefore will generate far less predictable random number than any algorithm based rng?

do you have access to the whole ram?
if so, what happens if you change something at random?

emulator

replied to wrong post rip

Attached: box-script.png (544x433, 17K)

I bet that thing would look like a fucking lgbt parade with proper syntax highlighting

Surprisingly not that bad, but still ugly. I want to try out semantic highlighting at some point but Sublime is pretty dumb (which is also why I use it).

Attached: Screen Shot 2018-03-22 at 11.26.10 PM.png (1056x1130, 227K)

Yes, but Intel and NSA
en.wikipedia.org/wiki/RdRand

Cloudflare had nice system.

blog.cloudflare.com/randomness-101-lavarand-in-production/

Turns out my code from the previous thread didn't work at all. I did a few modifications with the help of gdb.

#include

int main(){

int histogram[] = {1, 0, 1, 3, 2, 4, 5, 4, 1, 2, 0};
int hLength = sizeof(histogram) / sizeof(histogram[0]);

int width, height, area;
int rWidth = 0, rHeight = 0, rArea = 0;

for(int y = 0; y < hLength; y++){
printf("%d ", histogram[y]);

for(int x = 0; x < histogram[y]; x++){
printf("@");

width = x+1;
height = 0;
for(int y2 = y; y2 < hLength; y2++){
if (width > histogram[y2]){
break;
}
height++;
}

area = width*height;
if (rArea < area){
rArea = area;
rWidth = width;
rHeight = height;
}
}
printf("\n");
}

printf("\nBiggest rectangle: %dx%d\n", rWidth, rHeight);
printf("Area: %d\n", rArea);

return 0;
}

>be young and optimistic and want to make cool video games and shit
>learn how to code cool video games and shit

The problem is you lost direction.

Where were you when D was EEEing the C programming language?
forum.dlang.org/post/[email protected]

Well it's even more verbose than C++ so I guess he'd rather not want to look at it.

>unhygienic macros
macroexpand this
int temp = 0, x = 1;
swap(int, x, temp);

If RdRand is compromized, then why don't they use any earlier method of random number generation?

No, just jaded

oh wow that's similar

Attached: out.png (811x244, 144K)

Using several methods and RdRand but avoid using only one hardware base method.

>We use rdrand as _one_ of many inputs into the random pool, and we use it as a way to _improve_ that random pool. So even if rdrand were to be back-doored by the NSA, our use of rdrand actually improves the quality of the random numbers you get from /dev/random. Really short answer: you're ignoran

Linus answered.

theregister.co.uk/2013/09/10/torvalds_on_rrrand_nsa_gchq/

Hey guys, looking to learn this shit since I want to do it for a living and all.
What's a good place to start learning until classes start up? Also, best first language for someone who wants to work at a place like nVidia?

[How do I get started on making an iOS app? I have moderate experience in Java and C#.]

Stanford class videos and official book swift 4, both free on iTunes and iBook.

Attached: print-box-cl.png (580x350, 20K)

Attached: 1482104872256.png (420x420, 263K)

Yes, I know, I'm not dealing with out being NIL, happy now?

Attached: print-box-cl.png (608x416, 24K)

>SDL_event
Why do things this way if you already have SDL? You're still gonna have the SDL event loop right? Why isn't this just handled there? Seems unnecessarily complex.

>defmethod
Why?

Any expert python writers: Help me decipher this class member. I am looking at the source code of ccxt and cannot figure out how or where this member is defined.

Its not just visual studio being a cock. I cant find it anywhere in the base class or the imports. wtf?

Attached: Untitled.png (557x342, 19K)

Do find in files first.

Also I forgot to mention that the invocation does indeed work.

fug

Attached: Untitled.png (917x319, 25K)

Stepping into the source code shows that the method isnt located in any loaded module.

Attached: Untitled.png (407x239, 5K)

Is it supposed to be marketGetOpenOrders instead? Looks like you missed a capital O on Orders

I just copied the sources name. plus its a case insensitive search.

it's prob is from some compiled (.pyc) python file or a python windows library 'dll' (.pyd) file

C#

I have an int variable foo, a nullable int bar, an IEnumerable man, and an const int Chu. I want to assign a value to foo as follows:

If bar has a value, assign that. Otherwise, if man is not empty or null, assign the first value in it. Otherwise, assign Chu.

What is the most concise expression for this? I have:
int foo = bar ?? man?.FirstOrDefault () ?? Chu.

but that assigns a value of zero if bar is null and man is non-null and empty.

Hard types, obviously, that way a nonstring doesn't even get into print-box

Attached: print-box-cl.png (790x1026, 100K)

Then I'd have to put all the code for event handling into the event loop, rather than where it is most relevant. Also this is backed by an event "loop" that's invisible to the rest of the code because the rest of the code doesn't need to know how events are detected, just that they are.

Attached: Screen Shot 2018-03-23 at 1.37.49 AM.png (1142x1072, 196K)

why it gotta be concise senpai just make it clear t b h

Attached: vomit.jpg (650x650, 90K)

What do you guys listen to while /dpt/ing?

youtube.com/watch?v=gXbqJwtFC8c

Attached: 1482721002570.jpg (3000x3000, 1.51M)

>edutopia.org/blog/dont-listen-music-while-studying-david-cutler
just binge on music after work

>Then I'd have to put all the code for event handling into the event loop, rather than where it is most relevant.

Attached: 1512706439464.png (644x443, 10K)

t-that's just like, you're opinion man

>hard types
(defun print-box (text ...)
(declare (type string text))
...)

or
(declaim (ftype (function (string ...) nil) print-box))
(defun print-box (text ...)
...)


(defun print-box (text ...)
...)

You aren't even doing any type-based dispatching, an explicit check with a meaningful error text or/and a proper type declaration would be both more efficient and convey what you mean in a more reasonable manner.

How could we possibly answer that for you without knowing more about your project. But you sure as hell do not want to put an if in every method of your class, that's retarded as fuck.
Just do what you think would be the easiest to extend and maintain in the future.

Is a easy/standard way to serialise methods that take primitive values as parameters and changes some program state in a human readable form like XML or json for later execution? I did the following, but it has a lot of boilerplate more than doubling every method i want to be serialised (in c#). I want to keep type safety and performance btw, so no dynamicInvoke and other shit.
>Each method is defined as 2 static methods in a class
>Add(...) which takes a set of stacks and the parameters of the method
>Front end calls Add and adds methods Pushes parameters to a relavent stack, one for methods containing class Type, one stack for each primitive datatype
>Set of stacks can then be serialised and deserialized
>back end has dictionary of methods containing class Type as key and ref to the second method Do(...) As value
>Do takes program state and set of stacks, pops the relavent parameters and executed the methods
The problem is that each method now needs 2 methods, containing a line to push each parameter and another line to pop every parameter. Any way to get rid of this boilerplate?

Does everyone who learned to program with a programlet language like Python feel dumb when learning something like C?

C is a LOT easier to understand if you look at how memory is handled first. Learn about the stack, memory, pointers, and C makes a lot more sense.

I don't think there's a good way to do it, when I need that I use an extension method T FirstOr(this IEnumerable list, T default) that checks if list has more than 0 items, if it does use the first if it doest use default. Then it's bar??man?.FirstOr(Chu)

There's nothing wrong with Python. C is just something you're not used to yet. It will take a little bit of time.

It's normal to feel dumb when learning a second language, it gets much easier aftwr that.

heres my current code

class usingcase {
public void run() {
//Frontend
CommandStacks commands = new CommandStacks();
TestCommand.Add(commands, 1, 3, true);
TestCommand.Add(commands, 3, 1, true);
TestCommand.Add(commands, 1, 1, false);

// V pass commands
//Backend
Dictionary dic = new Dictionary();
State state = new State();

dic.Add(typeof(TestCommand), TestCommand.Do);

foreach (var c in commands.Commands) {
dic[c](state, commands);
}
}
}

class TestCommand {
//_____________________________________________VVVVVVVVVVVVVVVVVVVVVVVVVV
public static void Add(CommandStacks commands, int x, int y, bool falling) {
commands.Commands.Push(typeof(TestCommand));//< get rid of entire body
commands.ints.Push(x); //< get rid of entire body
commands.ints.Push(y); //< get rid of entire body
commands.bools.Push(falling); //< get rid of entire body
}

public static void Do(State state, CommandStacks commands) {
int x = commands.ints.Pop(); //< get rid of this
int y = commands.ints.Pop(); //< get rid of this
bool falling = commands.bools.Pop();//< get rid of this

if (falling) { //<
state.Dosomething(x, y);//<
} //<
}
}

/*What id like:
public static void TestCommand(State state, int x, int y, bool falling) {
if (falling) {
state.Dosomething(x, y);
}
}*/
class CommandStacks {
public Stack Commands; //< want int/enum instead of Type
public Stack ints;
public Stack bools;
public Stack strings;
}

class State {
public void Dosomething(int x, int y) {
}
}

github.com/rust-lang/rust/pull/49255#issuecomment-375368749
>impl Traits have been stabilized
Noice.

how can sepples even compete

Attached: 1493056246102.png (398x299, 4K)

explain like everything I've written in rust is fizzbuzz tier

>There's nothing wrong with Python.
t.rajesh

github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md

(You)
This too has been stabilized apparently: github.com/rust-lang/rfcs/blob/master/text/1951-expand-impl-trait.md

In C++
If I have
struct Meme
{
...some code...
Meme(...some code...)...some code...

You're fucked.

I'd create a class with the methods you want to use. Then I would inherit from that class and override those methods depending on my needs.

If you use gcc i suggest you do this
#define swap(x, y) {typeof(x) t = x; x = y; y = t;}
You should also check that x and y have the same type but it gets a little bit harder.

>tfw OP doesn't ask you what you are working on
I am not feeling well tonight, just dicking around with some shaders. Hopefully tomorrow I feel better and can make some better progress.

Attached: dpt.png (1058x824, 333K)

HELP!!!

Why the fuck are there so many conferences in this shithole called poland ? Is this what they do with all their gibs ?

Attached: IMG_20170922_141425.jpg (680x834, 68K)

That's a script not a program. Python isn't even coding it's so easy and abstracted away that it's like having a GUI to design software.

Meme arr[n];

doesnt work, error:
no matching function for call to Meme::Meme()

std::array = { ... }

That's because you haven't defined a zero-arg constructor. Either add one or initialize your objects explicitly.
struct Foo
{
Foo(int);
};

void bar()
{
Foo arr[3] = { Foo(1), Foo(2), Foo(3) };
}

>for(int x = 0; x < histogram[y]; x++){
>>width = x+1;

absolutely disgusting.

#include

int main(){

const int histogram[] = {1, 0, 1, 3, 2, 4, 5, 4, 1, 2, 0};
const int hLength = sizeof(histogram) / sizeof(histogram[0]);

int width, height, area, last_width = 0;
int rWidth = 0, rHeight = 0, rArea = 0;

for(int y = 0; y < hLength; y++){
printf("%d ", histogram[y]);

for(int x = 0; x < histogram[y]; x++){
printf("@");
}
width = histogram[y];
height = 0;
if(width < last_width)
goto skip;
for(int y2 = y; y2 < hLength; y2++){
if (width > histogram[y2]){
width = histogram[y2];
}
height++;

area = width*height;
if (rArea < area){
rArea = area;
rWidth = width;
rHeight = height;
}
}
skip:
last_width = histogram[y];
printf("\n");
}

printf("\nBiggest rectangle: %dx%d\n", rWidth, rHeight);
printf("Area: %d\n", rArea);

return 0;
}