/dpt/ - Daily Programming Thread

Previous thread: What are you working on, Sup Forums?

Other urls found in this thread:

tour.dlang.org/
wiki.dlang.org/Books
dlang.org/blog/2017/04/28/automem-hands-free-raii-for-d/
wiki.dlang.org/Libraries_and_Frameworks#Alternative_standard_libraries_.2F_runtimes
pastebin.com/Y3gjiDp
youtube.com/watch?v=xxcZRrpicGU
pastebin.com/Y3gjiiDp
tutorialspoint.com/design_and_analysis_of_algorithms/design_and_analysis_of_algorithms_01_knapsack.htm
libgen.io/ads.php?md5=7B60D3F530EC04E64236BE737D706053
mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_1.2.2
youtu.be/52sqUj6JEWc
youtube.com/watch?v=N8elxpSu9pw
thebookofshaders.com/
twitter.com/SFWRedditVideos

Rewriting Rust in Presburger arithmetic.

Second for both Rust and C suck

How would ada feel about revisionist feminists disregarding her (dubious) contributions to mathematics and misrepresenting her as the inventor of programming?

What does this image have to do with programming?

Absolutely nothing. It's just some bitch.

Threadly reminder that dlang-chan has RAII; she's quite fast in execution and compilation; and she's super duper cute! Say something nice about her, /dpt/!
Also, Andrei's a cool guy.

>Tour
tour.dlang.org/
>Books
wiki.dlang.org/Books
>GC
dlang.org/blog/2017/04/28/automem-hands-free-raii-for-d/
wiki.dlang.org/Libraries_and_Frameworks#Alternative_standard_libraries_.2F_runtimes

Working on that thicc ass, if you know what I mean

haskell!

Do you guys watch any programming YouTube channels?

programming videos are boring
the ones made by people who actually have any skill run way too fast and you gain nothing.

#include stdio


struct llist[T] {
//_ means it's only visible inside llist and doesn't affect identifier
struct _lnode {
T data;
lnode *next;
};
lnode* head;
void append(llist* this,T x) {
lnode *current = this.head;
while(current.next)
current++;
lnode *temp = new lnode;
*temp = x,nil;
current.next = temp;
}
T operator[](llist* this, int at) {
//muh unsafe, don't care
lnode *current = this.head;
for(int i = 0; i < at; i++, current++)
;
return current.data;
}
lnode *operator++(lnode *n) {
n = n.next;
return n;
}
};
//it would be more readable to keep everything out of struct, but I wanted to remark the type relation of polymorphic type between //llist[T] and llist::append(T)

void main() {

llist[int] x;
x.append(1);
//equivalent to append(&x, 1);
x.append(7);
x.append(10);
int y = x[2]; //y = 10;

}


Give me feedback, /dpt/. I'm looking for simplest and most elegant possible form. It's meant to be a C-like language.

I have a problem that I am trying to solve:

>10 columns of varying height
>30 pieces make up those 10 columns
>find the order of those pieces to fill those columns

This is not homework, it's for my house. At the moment I am doing this by randomising the pieces and just checking if they fit. But is there a better system?

My code is here:
pastebin.com/Y3gjiDp

C++: When to use pointers over references and vice-versa for passing stuff around between functions?

Pointers only useful when passing arrays/objects across.

Reference is cleaner but you don't have pointer arithmetic.

Im thinking of making a simple launcher for some of my games. Whats the easiest way of launching an exe on Windows with java or C#?

#include
#include
#include

int main()
{
char *wires[3] = {"blue", "red", "white"};

int index = 2;
int swap_index;
char *tmp = NULL;

/* Fisher-Yates shuffle algorhitm */
while(index > 0) {
/* Seed the pseudo-random number generator
* with processor time used by the program */
srand(clock());
swap_index = rand() % (index + 1);

if(swap_index != index) {
tmp = wires[index];
wires[index] = wires[swap_index];
wires[swap_index] = tmp;
}

index--;
}

char *buffer = NULL;
int read;
size_t len;
int i = 0, j = 0;

/* Game narative :) */
printf("\nA terrorist has planted a bomb, and your mission is to defuse it!\n");
printf("As you study the bomb you conclude that there are three wires to cut: red, blue and white.\n");
printf("Cutting them in the right order only will it defuse the bomb.\nGood luck!\n\n");

while(i < 3) {

read = getline(&buffer, &len, stdin);

/* Because getline takes the newline character into the buffer,
* it's cleaner to remove it from our string when comparing it
* with the values in the array */
while(buffer[j] != '\n')
j++;
buffer[j] = '\0';
j = 0;

if(strcmp(buffer, wires[i]) == 0) {
if(i == 0)
printf("Wheew.. cut the next wire?\n\n");
if(i == 1)
printf("Whoow.. one more wire left!\n\n");
if(i == 2)
printf("THE BOMB WAS DEFUSED AND YOU ARE THE HERO OF THE DAY!\n\n");
i++;
continue;
} else {
printf("\nBOOM! (the bomb explodes with massive blast radius and many victims...)\n\n");
break;
}
}

return 0;
}

You may compile it on a gnu/linux system using the gcc compiler
also youtube.com/watch?v=xxcZRrpicGU

>pastebin.com/Y3gjiDp

Page is removed.

paste no workie

Shit sorry guys, missed an i!

pastebin.com/Y3gjiiDp

You started the thread without anime again, god bless my friend.

Messing with raymarching in GLSL

name that site

>how do I do X in this language?

>no you don't. You want to do Y. Use third party libraries A,B, and C.

Stackexchange.

>tfw no cute countess bae to fuck around with babbage machines

holy shit john carmack replied to me on twitter
why am i being so fucking gay about this

He's an idiot.
>here let me just violate software patents from my previous employer
>oops i got caught
>google "how do I format hard drive"
>defendant was caught GOOGLING "how do I format hard drive" before evidence was subpeona'd.

he's worshiped for making games back when they could be made by two people and didn't require a team of dozens of professionals
what did you expect?

dumb frogposter

tell him to join us at Sup Forums.org/g/dpt !

How come when I do something stupid like list(itertools.permutations('"insert 100 digit long str", 8)) and it starts eating up all my RAM and starts swapping, mashing Ctrl+c doesn't abort and it continues building the list and causes kernel panic?

ctrl+\

I don't really know what you mean by pieces but it sounds like it might be an instance of the knapsack problem:
>tutorialspoint.com/design_and_analysis_of_algorithms/design_and_analysis_of_algorithms_01_knapsack.htm

If so then one solution is:
1. Sort the objects by ratio of value to weight
2. Repeat until the knapsack overflows:
Remove highest value-to-weight object from set, and place entirely in knapsack.
3. Take out the last object placed in knapsack, and slice off just enough to fill
knapsack.
from P. 4 of the architecture of symbolic computers
>libgen.io/ads.php?md5=7B60D3F530EC04E64236BE737D706053

It also might be similar to the counting change program in SICP:
>mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_1.2.2

>and didn't require a team of dozens of professionals
they still dont need this.
Croteam make AAA games at a fraction of the people.

>why does it eat up my ram
you are trying to generate a list of length 7,503,063,898,176,000
>mashing Ctrl+c doesn't abort and it continues building the list and causes kernel panic?
kek, python sucks I guess?

um
youtu.be/52sqUj6JEWc

It is, and I'm aware of the knapsack problem. But I am not sure how to implement that in multiple instances.

I can not cut the pieces at all.

Effectively think of a column. That column is say 10 units high. I have a variety of pieces that are say, 2 units, 3 units, 4 units and 5 units.

I want to randomise those pieces and try and fit it. Maybe first time I take 2, 3, 4 which gets me 9, but the 5 unit piece will make it way too big. That 5 unit piece will become the first part in column 2.

So at the end, it'll be incorrect. So now I go ahead and randomise things round, this time getting 5, 2 and 3, which is correct for column 1, and unit 4 becomes the first part of column 2,

I have 11 columns though and 32 pieces that should make those columns.

Talking about our Lovely Countess, I asked myself some questions today, and I realized I couldn't answer them because I do not have enough knowledge of...
... the history of computers.
What's a good book or source to learn from?

handmade hero

time to time i search for "postmortem game"

also like to watch dev timelapse. for example youtube.com/watch?v=N8elxpSu9pw

Most of those are irrelevant to the core game. Their team is still smaller than most though.

Seconding this
Any books anons?

I preferred the old Dlang-chan.

to cut down your search space, consider the following: every solution must have one column with length 285.5. how many ways are there to generate a column of length 285.5? when you're done with that, what pieces remain? how many ways are there to generate a column of length 281.5 from the remainder?

right now your search space is 30! = 265252859812191058636308480000000 which is rather large. oh by the way, ints cant ever become larger than 10000000000000, google "max int size"

The Devil's Dictionary by Ambrose Bierce

what I dont like about these videos is how fast they are and how no mistakes are made. they programer seems to have the implementation preplanned and essentially has a macro run to generate the text file

She's on the Build Your Own Lisp cover.

How do I write GTK applications without using an IDE?

Using a text editor.

>Lisp
What does that have to do with programming?

Prefer references if possible. Only use pointers when somehow needed. Unlike pointers, references don't have a null value, which is a useful guarantee to have. If your object does have a natural 'null' or 'invalid' state, then pointers might be a better fit.

>#include

>object
And what if I'm not retarded?

Lisp is the most powerful programming language.

that's fucking awesome, i really need to learn GLSL

First of all, what is a "powerful programming language"? And why is Lisp a "powerful programming language"?

Are you saying only retards use 'objects'?

I don't know, you tell me.

Because programming is disgusting shit, programming languages range in quality from worse than shit to shit. Lisp is the most powerful programming language, which means that it is equal to shit quality. All other programming languages are worse than shit.

Welcome to /dpt/ where hating on OOP makes you look cool and edgy.

>hating on
>cool and edgy

>Lisp is the most powerful programming language, which means that it is equal to shit quality
Assuming being powerful is actually an indicator of quality.
And you didn't explain what it even means for something to be "powerful".

Wrong.

This is a great starting point for doing so, although is still being made.

thebookofshaders.com/

programing challenge!

only using addition, subtraction, multiplication, and division, write a fucntion that can compute a square root to n decimal digits of accuracy

For example:
>sqrt(9, 0)
3.1
>sqrt(9, 1)
3.01
>sqrt(9,2)
3.001

please do it in your favorite programing language. thank you and have a good day!

cheers

Makes you wonder, eh?

t. brainlet

What's it like reading programming materials and documentation in other languages?
Does your language have native equivalents for all those computing terms, or do they keep defaulting to english loanwords?

Most mathematical terms come from French or German so it's not too hard translating the new ones. As for the more practical stuff, I could describe how the Linux OS works in French but probably would still use English terms in the mix since I'm not that used to use those from my language. So yeah, they have native equivalents but are not always used in non-formal settings.

>have native equivalents for all those computing terms
for a lot of them, da

your code is retarded. in your examples you input n as an argument and get n+1 decimal spaces... you tell it squareroot 9 with 2 decimal places and you get squareroot 9 with 3 decimal places.

Also, square root 9 is not greater than 3.

Easy solution in python
def OP_Is_Faggot(x,n):
return str(x**0.5)[:n+2]


>>> OP_Is_Faggot(3,3)
'1.732'
>>> OP_Is_Faggot(13,7)
'3.6055512'

to be clear, you can be more accurate than n if you wish

you need to be accurate to the nearest 10^n, so the first n digits must be accurate. There is no need to truncate after n+1 digits if you choose not to.

only using addition, subtraction, multiplication, and division please!

You're not as smart as you think you are.

Both of them are cute in my opinion. The benefit of dlang-chan v2.0 is that she's not from any copyright other than that of the author's implicit one.

Is /dpt/ the last haven for cute anime girls on Sup Forums?

>Does your language have native equivalents for all those computing terms, or do they keep defaulting to english loanwords?
I wouldn't know. I don't read programming resources in it. Probably a lot of English loanwords though.

I've started reading this book and it's shit desu

pic related

As of right now, yes. But it will most certainly change after the anime coup.

>tfw tools are more complicated than the actual game, and the game is already a labyrinth beyond the comprehension of any single person.

>this as explicit argument
no

(((member functions)))

algorithm blatantly ripped off from scip. please do not pass it negative numbers :)
sqrt x digit_accuracy = go (x/2) x digit_accuracy
where
go guess x digit_accuracy
| is_good_enough guess x digit_accuracy = guess
| otherwise = go (improve guess x) x digit_accuracy

is_good_enough guess x acc = (abs (( pow guess 2 ) - x)) < 1 / (pow 10 acc)
improve guess x = (guess + ( x / guess )) / 2
pow a b | b == 0 = 1
| otherwise = a * pow a (b - 1)

>ada was the first programmer
Someone explain this bullshit to me. How can you say with a straight face baggage made a machine couldn't actually use? How the fuck would he even know how to design it?

What would it take for D to be anything but an interesting curiosity, bros? I feel like I am taking crazy pills whenever I hear people seriously say c/c++ is a better language.

Can somebody tell me why SBCL is bitching?
Error makes no sense to me.
sanitize.lisp
(defvar com ">>918279213
I really hope you die you fucking faggot.
>implying
>>>Sup Forums")

(defconstant +ampersands+
'(("#039" . #\')
("quot" . #\") ;"
("lt" . #\)
("amp" . #\&))))


sbcl stdout
(load "sanitize/sanitize.lisp")

debugger invoked on a SB-C::INPUT-ERROR-IN-LOAD in thread
#:
READ error during LOAD:

unmatched close parenthesis

Line: 8, Column: 19, File-Position: 334

Stream: #

Money and manpower. The foundation behind dlang-chan does actually have some decent money according to Andrei, but you can never have enough. Languages like Rust, Golang, and Swift have big organizations behind them. dlang-chan needs one of her own to get more momentum. Once that happens, people will follow, and PRs and patches will come flooding in to help further dlang-chan's evolution. Sadly, this is a classic case of the chicken and the egg problem.

The analytical engine was never actually built, and ada's claim to fame was some hobbyist stuff she did where she wrote a program for this theoretical machine, people claim this was the first computer program, and it casts this idea that babbage never knew how to use the machine that HE invented.

tell me user, what's it like programming while illiterate?

I'm a C/C++ shill but I'd say by just being a "better C++" it actually doesn't cater to any real demographic. People who need C++ need it for very specific purposes where D didn't have the occasion/ability to prove its superiority (game development, operating systems, etc...).

Babylonian approximation:
double sqrt_babby(double x,int n)
{
double y = x;
double y_temp = 1.0;
double tolerance = pow(10,-n);
while(fabs(y_temp - y) > tolerance)
{
y_temp = y;
y = 0.5 * (y_temp + y/y_temp);
}
return y;
}

Gaussian integral
double gamma(double x)
{
double sum = 0.0;
double ds = 0.0001;
int max = 10000;
double epsilon = 0.00000001;
if(x >= 1)
{
epsilon = 0;
}
for(n=0;n

Also since it's so old now it didn't have a surge of popularity from the hipsters like Go or Rust did since back in the days, they weren't in the programming industry.

There parenthesis are matched though.

the compiler doesn't lie, user-kun.

user only the multiplication operator twice:
that falls within guidlines

...

Bumping.

your parenthesis-matching is the problem. vim detects the unmatched ending paren just fine, just pay attention to what the compiler says is wrong.

Lmao this is how I'm supposed to detail the char "
(char "\"" 0)