/dpt/ - Daily Programming Thread

What are you working on?
Previous:

Attached: wc.jpg (900x1000, 180K)

Other urls found in this thread:

spring.io/guides/gs/gradle/
youtube.com/watch?v=s1i-dnAH9Y4
stackoverflow.com/questions/40382487/copy-a-list-of-list-by-value-and-not-reference/40382592
stackoverflow.com/questions/28684154/python-copy-a-list-of-lists
youtube.com/watch?v=vhiiia1_hC4
twitter.com/NSFWRedditGif

First for C++ is better than all the other garbo languages out there.

Attached: 1534702413534.png (368x394, 293K)

why can't there be a good language that is suitable for environments with very little runtime support, memory, compute overhead that is also supports metaprogramming?

learning struct,i know how to pass it in a function but dont know where to place the function prototype because i dont understand if any of that can be in main so w/e.
dont have much time to dedicate programing because long work days.
going to bed now

I am such a fucking moron, why cant i use Spring/IntelIJ properly? I try another guide for example spring.io/guides/gs/gradle/ i have code and now should i use ./gradlew bootRun... but how? its a unix command! There is error when i try to run it in cygwin and i dont see build option in IntelIJ gui, its not even properly documented. Jesus christ, am i idiot or this shit is needlessly obtuse and disorienting?

Attached: brainlet shooo.jpg (903x960, 45K)

Just finished a python script to backup, collect and push my configs

Fuck each and every compiler that requires you to list source code files in order.

Attached: cni.jpg (1857x963, 373K)

Thank you for anime thread :)

Rust?

findMax([],_,_) :- !.

findMax([X | Rest],Max,Res) :-
X < Max,
Max1 is Max,
findMax(Rest,Max1,Res).

findMax([X | Rest],Max,Res) :-
X > Max,
Max1 is X,
{1} Res is X,
findMax(Rest,Max1,Res).

This works for findMax([3,2],0,X) but not for findMax([2,3],0,X)... I've followed the code 10,000 times and I don't get the error. Apparently {1} is what returns false on its second call with the [2,3] set for some reason unknown to me.

I don't see what makes monads special
isn't it just an ordinary typeclass?

to be a good c++ programmer do I have to be a good c programmer first? also, is this list of books good to learn c++ if I already know programming?
>acelerated c++
>effective modern c++
>ds & algos in c++ by drozdek
>professional c++

>do I have to be a good c programmer first?
No. Sometimes good C code is bad C++ code.

Fair enough. C knowledge still might clear some things up for you. Besides, everybody should do at least some C programming.

Been trying to learn Python so I've been writing little games and scripts to figure it out. Currently I'm only really fluent in PHP, SQL, and JS.
I saw from the last thread so I decided to make rock paper scissors.

import random

print("Welcome to rock-paper-scissors.");
print("The game is simple - type r for rock, p for paper, or s for scissors.")
print("You're playing the computer. Best 2/3 rounds wins.")

compscore = 0
userscore = 0

while (userscore != 2) and (compscore != 2):
rpsarray = ['r','p','s']
comprps = random.choice(rpsarray)
userrps = input("Rock, paper, or scissors: ")

if (userrps == 'r' and comprps == 's') or (userrps == 'p' and comprps == 'r') or (userrps == 's' and comprps == 'p'):
print("You win!")
userscore += 1
if (comprps == 'r' and userrps == 's') or (comprps == 'p' and userrps == 'r') or (comprps == 's' and userrps == 'p'):
print("Computer wins!")
compscore += 1
if (comprps == userrps):
print("Tie!")

if compscore == 2:
print("Computer wins the game!")
elif userscore == 2:
print("You win the game!")


What else should I write?

Attached: 1520878614544.gif (250x194, 13K)

Please do not use an anime image next time, thanks.

But it is our custom

awful post

Please do not use a book other than SICP next time, thanks.

what you think about the list of books to learn c++, anons?

C Programming Language is more iconic

So I just started reading a programming book and the intro talks about the ENIAC computer and what the fuck? How can an entire room's worth of tech be condensed into a microprocessor you can fit between your thumb and forefinger? I've never done drugs before but I imagine contemplating this is what it feels like to be stoned.

Which one do you prefer?

int result;
if (!parseInt("54", &result)) {
// error
}

std::optional result = parseInt("54");
if (!result) {
// error
}

Learning machine learning with R :)

now make it asynchronous

The electrical components have been scaled down by about 8 orders of magnitude since then.

I usually go with the second, since I will probably be logging the failure and may use 'result'.

I realize 'result' is probably junk here, but I might print parts of the incomplete result in other situations too.

Calculator's and computers started off as mechanical inventions

youtube.com/watch?v=s1i-dnAH9Y4

Fax predates the telegraph, and in WWII there were suitcase fax machines, suitable for humid and fungal jungles and rugged enough to survive an airdrop.

Finally got it to work, I fucking hate Prolog.

findMax([],Max,Res) :- Res is Max, !.

findMax([X | Rest],Max,Res) :-
X < Max,
Max1 is Max,
findMax(Rest,Max1,Res).

findMax([X | Rest],Max,Res) :-
X > Max,
Max1 is X,
findMax(Rest,Max1,Res).

Do tic-tac-toe. It's a solved game so bonus points for programming perfect play. Even better, add an "easy" mode that randomly chooses squares (unless not choosing a square will cause a loss on the next turn)

Or
def find_max(x):
return max(x)

Might give it a shot. I ain't got shit better to do aside from look for jobs.
Will probably do it tomorrow, I got work in the morning.

>unless not choosing a square will cause a loss on the next turn
That sounds like a lock waiting to happen, but I need to think about.

pls respond

Attached: 13d.jpg (944x960, 73K)

I think he means that the computer will choose randomly unless it needs to choose a particular square to not lose.

>its a unix command!
It's actually just a script. gradlew is a script generated by gradle. There should be another script called gradlew.bat that is a windows equivalent.

anime /dpt/ is canon

number guessing game

Non anime threadstarts are always bad

Unless they're images of Dijkstra

This. X just grabbed a second square. If O chose randomly it would probably make a dumb choice. It should go for the obvious block here.
O| |
--------
X|X|
---------
| |

try (DataInputStream in = requestCacheIndex("crc" + (int) (Math.random() * 99999999D) + "-" + 317)) {

}

Error: Resource specification not allowed here for source level below 1.7


How do I modify this line of code so that its compliant with JDK 1.5 ?
Making a game that runs on computers with very old version of Java installed.

Thanks for this!

you manually call in.close() in the finally block

Why do gcc and clang make an int 32 bits on my 64 bit x86_64 machine?

They have the option? An int only needs to contain at least +32767/-32768. Doesn't need to be any larger.

I know the standard lets them I just couldn't find a rationale for their choice.

Because your C compilers don't care (one bit) about your architecture. 32 bits run fine on 64 bit computers. Why change the size?

What do you guys think of Rust?

I guess that make sense. I'd just prefer the size of an int to be customizable, so that if you were migrating to a different int size you wouldn't necessarily have to change thousands of lines of code.

That exists. Look up the C99 types.

I don't think about it at all. Anyone who implements metaprogramming without sexprs is just retarded and there's no need to examine it further.

>I'd just prefer the size of an int to be customizable
Checkout stdint.h

>

Attached: average-4chan-shitposter.jpg (300x100, 17K)

>CScum grad
>know data strucs, algos, DB stuff
>made a serious 3 tier webdev project
>dont know what i want to do in the job world

I just tell interviewers i want to code and eventually get close to hardware with RTC or embedded systems.

i feel dumb saying that though, but its what i want to do with my ignorant knowledge of the software dev world

I dont think thats it? That wouldmess up the logic of the code.

Heres the full method...
public final void requestCrcs() {
int delay = 5;
archiveCRCs[8] = 0;
int k = 0;
while (archiveCRCs[8] == 0) {
String error = "Unknown problem";
drawLoadingBar(20, "Connecting to web server");
try (DataInputStream in = requestCacheIndex("crc" + (int) (Math.random() * 99999999D) + "-" + 317)) {
Buffer buffer = new Buffer(new byte[40]);
in.readFully(buffer.getPayload(), 0, 40);
in.close();
for (int index = 0; index < 9; index++) {
archiveCRCs[index] = buffer.readInt();
}

int expected = buffer.readInt();
int calculated = 1234;
for (int index = 0; index < 9; index++) {
calculated = (calculated

>ask a question
>get an answer

Attached: covfefe.jpg (1100x619, 64K)

Attention adop/dpt/ed orphans:
pls help me fix this code
I attempted to solve this problem import random

def draw(boxes):
# randomly select a box and a ball from that box
box = random.randint(0,2)
ball = random.randint(0,1)
color = boxes[box][ball]

if color is not "gold":
return draw(boxes) # redraw
else:
boxes[box].remove(color) # draw the gold ball
return boxes[box][0] # return the remaining ball in the selected box

def draw_n(n, boxes, probability_of="gold", i=0):
results = {"silver": 0, "gold": 0}
while i < n:
ball = draw(boxes)
results[ball] += 1
boxes = [["gold", "gold"], ["gold", "silver"], ["silver", "silver"]]
# how do I avoid having to assign boxes again in Python?
i += 1
result = results[probability_of]/(results["gold"]+results["silver"])
return result

boxes = [["gold", "gold"], ["gold", "silver"], ["silver", "silver"]]

n = 10000
result = draw_n(n, boxes, "gold")
print(result)

As you can see, there is a redundant line at line 20; I'm reassigning the boxes once again. Without it, I get an index out of bounds error. I think this is related to list mutability in Python, but I can't seem to fix it by creating a second list.

Tips?

huh, very cool

Is "How to Design Programs" the new SICP?

Okay, I'm writing tic-tac-toe in python as per 's suggestion.
I'm on the hard part. The win conditions.
So each place on the board is numbered like this, based on places in an array:
0|1|2
-------
3|4|5
-------
6|7|8

So I could do it the pleb-tier way by writing an if-statement for the 8 win conditions, but I really don't want to do that. That's not graceful at all.

What would be the best way to go about this? Speaking of, these are the conditions:
# 0,1,2
# 0,4,8
# 0,3,6
# 1,4,7
# 2,4,6
# 2,5,8
# 3,4,5
# 6,7,8

Thoughts?

Attached: Big Think.jpg (777x704, 57K)

efficient way is to check possible wins on each move. say you place your X in the corner, you would check horizontal, vertical, and diagonal for wins. simple

help

Attached: broom.jpg (250x249, 6K)

Scheme is the most elegant dynamic language in existence.

>fluent in PHP, SQL, and JS
>if or or if if or or if if or or if if if elif or or or if
Nice coding skills. Some fluent shit going here.

Clam down, guy.

Two issues:
Python automatically passes things by reference, not by value, which means that changes go beyond the function you make the change in.
Source: stackoverflow.com/questions/40382487/copy-a-list-of-list-by-value-and-not-reference/40382592

In other words, the way you have it written right now, you will *always* need to perform a copy.

Think of it this way, do you *really* need to remove the color from the box? Couldn't you just simply pick the box that "ball" doesn't correspond to?
I think XOR would be the operation you'd be looking for.

The other issue was that you will always get "result = 0". Do you know why?

Well, give it a couple of seconds of thought, and here's the solution.
def draw_n(n, boxes, probability_of="gold", i=0):
results = {"silver": 0, "gold": 0}
while i < n:
ball = draw(map(list,boxes))
results[ball] += 1
i += 1

result = float(results[probability_of])/(results["gold"]+results["silver"])
return result

Attached: Clam-Animal-Pics-Gallery.jpg (1024x768, 201K)

What would your solution be, mr. smart guy?
Let's see some code golf.

>The other issue was that you will always get "result = 0".
It works correctly as posted, I just don't understand how to fix that redundant line. Let's say I want to keep it as is (I understand that there is better design and that I really don't need to remove the ball)—how do I go about that? I tried adding something like
original_boxes = boxes.copy()
and then
fresh_boxes = original_boxes.copy()
but this does not help

Can you offer any insight into that?

draw = 0.66666666666667

agreed

Hope this is the right place to ask, since I'm not posting any code. I started a /wsr/ thread about my problem forwarding ports in a videogame I wanted to play, and have since then discovered that I may be behind double NAT. Not going to ask for a solution to that, but this is directly related to another question I have.

I was going to write a C# application (let's call it a game, but it wouldn't be much more than just two dots moving on a grid) that would use a p2p UDP connection to connect two computers. Assuming one, or both parties have a NAT they have no control over, are there any techniques I can use to go around it? For example, I saw a technique called "hole punching". Does this work if both parties know the IP address and port number each other is using?

I am new to programming, so I don't even entirely understand what I'm writing right now.

Attached: 1482397646744.jpg (666x720, 286K)

What did he mean by this?

Adding a print(boxes) before line 18 shows:.

[['gold', 'gold'], ['gold', 'silver'], ['silver', 'silver']]
[['gold'], ['gold', 'silver'], ['silver', 'silver']]
[['gold'], ['silver'], ['silver', 'silver']]
Traceback (most recent call last):
....
You can figure it out from here if you haven't already

You might find this useful

Attached: tic_tac_toe_large.png (2040x4614, 2.73M)

This tells me that it's an issue of list mutability but I don't know how to fix it. See: Maybe I'm a brainlet but I could use some hand holding insight given that.

To be clear, I think I should fix it (barring a better design) by making a temporary placeholder array with the original boxes, I just can't figure out why that doesn't work.

I cannot find a single correct explanation of the DFS articulation point algorithm reeeeeeeeeeeeeeeee
They're all wrong in how they explain their logic.
They all say:
>assign numbers to each node by counting up during a DFS
>for each node all lower numbers are parents and all higher numbers are children
>iff a node has multiple children it's an articulation point

In a circular graph, nothing is an articulation point. In a linear graph, everything but the start and end is an articulation point. In both, everything but the start of a DFS and the end(s) has one child and one parent.
The last statement about the algorithm means that there's no distinction between a linear and circular graph though, so the algorithm as everyone explains it is wrong, and everyone is missing the same vital piece of information.
It's surprisingly common for this to happen, for everyone to offer the same information and all be missing the same piece, because they're just echoing each other.

Attached: FURRYIOUS.png (618x558, 326K)

I can't help you but reading your post and then looking at the image you posted made me laugh real hard.

im still fucking working on that god damn photoshop file parser. this fucking format makes no sense at all. padding in different sizes and using them at random, types in types in types in types. just fucking end my suffering

Attached: portrait.jpg (500x335, 19K)

Sorry, I was wrong, there is no way write it without making spaghetti of 15 conditionals and 14 hardcoded values in 5 lines of code))

>im still fucking working on that god damn photoshop file parser
why would you do that

Making fractals with Unity. I'm unemployed so I'm just making trippy druggy degen shit all the time

Attached: youAteMyFractal.png (693x743, 99K)

Creating LibreShoppe of course. The free (as in freedom) open source answer to photo$hop

>It works correctly as posted.
Oh. Okay. I was running it in Python2, not Python3, which handles division differently (because screw backwards compatibility, right?)

If I were to hazard a guess, ti'd be that the "copy" operation doesn't work because "boxes" is a list of lists, and so when you copy them, I think you're only copying the references to the inner list.
This seemed to work fine, though
import copy
/* ... */
ball = draw(copy.deepcopy(boxes))

Son of a fucking BITCH, it was that simple the entire time?

>to create a shitty clone
Why can't freetards into programming?

I'm learning about digital filter design. I want to create software Z-plane filters (e.g. morph between low pass and band pass) like the infamous EMU Morpheus. I'm finally starting to grok what Z-plane actually means and how filters are designed with zeroes and poles.

I don't know... maybe?
Python's a reaaaal fuckin' weird language sometimes, and it trips me up with some of its quirks.
But hey, if it's useful for you, continue using it.

Sounds awesome! Are you learning this from a book/course?

>types in types in types in types
You're using recursion right?

>copy.deepcopy

stackoverflow.com/questions/28684154/python-copy-a-list-of-lists

Why does this work:
Object object = {1,2,3,4};
foo(&object);

But not this:
foo(&{1,2,3,4});

Am thinking of getting a job next month. Any idea what small program to make as portfolio?

Attached: 1506822466904.jpg (300x300, 22K)

>copy.deepcopy
I genuinely don't know what you mean by that

Write an addon to firefox that allows you to browse nhentai.net one handed.

I'm just looking at everything I can find on the subject.

I might be wrong, but it may has something to do with {1,2,3,4} being an array of int (primitive data type) and the other is an object.

And how do I tell my employer what nhentai is?

*while the other

My fault, I'm being a little vague. I just think that deepcopy should be it's own function.

I wrote a bash script that downloads all of the images from r34 paheal based their tags.
Doubt any employer wants to see that though.

Also note that if you're going to try and program the logic to something like this Something similar to a finite state machine might simplify things. I know learning about them has helped me tremendously.

youtube.com/watch?v=vhiiia1_hC4
This video explains how a parking meter doesn't need to calculate how much you've paid. There are only so many states the machine can be in and in each state there is a series of acceptable inputs that will change the state of the machine.

In order to get the address of something it needs to have a location (stack/heap); object is on the stack and thus has an address. {1, 2, 3, 4} is just an array (probably initializer list) that the compiler can do w/e it wants with and isn't guaranteed a location anywhere.

You can read up on prvalue vs lvalue vs etc to get a better understanding.