/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

github.com/nickwilliamsnewby/ephemGravityWrapper
gen.lib.rus.ec/search.php?req=Grokking Algorithms&lg_topic=libgen&open=0&view=simple&res=25&phrase=1&column=def
gen.lib.rus.ec/
twitter.com/NSFWRedditVideo

first for OOP is shit

first for D

"raise an error" is okay but "lower an error" sounds stupid

>grokking

fuck you esr and your retarded legacy and forced memes you fucking down syndrome lolbertarian deformed adult fetus reject nigger faggot

raise / check?

panic

Who?

>grok
>Origin
>1960s: a word coined by Robert Heinlein (1907–88), American science fiction writer, in Stranger in a Strange Land .

there is absolutely nothing wrong with throw/catch

"raise an error" and "handle an error" maybe?

this is kicking my ass

>There are two sorted arrays nums1 and nums2 of size m and n respectively.
>Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).

it either infinitely would recurse when it had two arrays of length 2, or it just doesn't work in some cases when the first list has values that range on both sides of the other

import math

class Solution(object):
def findMedianSortedArrays(self, nums1, nums2):
l1 = len(nums1) # length 1
l2 = len(nums2) # length 2

# check ending conditions
# if list 1 is empty, return the median of list 2
if nums1 == [] and nums2 != [] > 0: return median(nums2)
# if list 2 is empty, return the median of list 1
if nums2 == [] and nums1 != []: return median(nums1)
# if list 1 and list 2 have the same median, return it
if median(nums1) == median(nums2): return median(nums1)
# if list 1 = [x] and list 2 = [y], return (x+y)/2
if l1 == 1 and l2 == 1: return math.floor((nums1[0] + nums2[0])/2)

# List 1's midpoint is less than list 2's midpoint
if nums1[l1//2] < nums2[l2//2]:
# use the upper half of list 1
lst1 = nums1[(l1//2):l1]
# and the lower half of list 2
lst2 = nums2[0:math.ceil(l2/2)]
print(lst1, " :: ", lst2)
# and use them in a recursive call
return Solution.findMedianSortedArrays(0, lst1, lst2)
else:
lst1 = nums1[0:(l1//2)]
lst2 = nums2[(l2//2):l2]
print(lst1, " :: ", lst2)
return Solution.findMedianSortedArrays(0, lst1, lst2)

def median(x):
if len(x) % 2 == 0:
return (x[len(x) // 2] + x[(len(x)//2)-1]) / 2
return x[len(x)//2]

I got some great advice in last thread and I made changes and pushed them to github github.com/nickwilliamsnewby/ephemGravityWrapper if you guys could help make my plotting script less shitty too I would be grateful

Anyone got the book in OP?

Eric Raymond was a fan of Heinlein's and repeatedly tried to force that word as "hacker slang".

gen.lib.rus.ec/search.php?req=Grokking Algorithms&lg_topic=libgen&open=0&view=simple&res=25&phrase=1&column=def

It's kinda meh, though.

If you ever need to find ANY book go there
gen.lib.rus.ec/

Can you elaborate what "median of two arrays" means?
Is it the median of a union of both arrays or the average of both medians?

OOP had ADT (interfaces) for decades, what's your point?

nums1 = [1, 3]
nums2 = [2]

The median is 2.0


nums1 = [1, 2]
nums2 = [3, 4]

The median is (2 + 3)/2 = 2.5

wrong kind of adt

I found an excellent car metaphor representation of C++. This is more accurate than the Reliant Robin.

DELETE THIS

Where do i go to pirate ISO standards documents?

You can pretty easily find the working drafts with Google.

I've tried finding the standard for MP3 file encoding (IEC 11172-3), but the best i found was half the document on piratebay.

It's time to stop tolerating most dynamic languages. The vast majority of them offer no benefits. Writing wrong code quickly is not a benefit.

Unless a dynamic language is

>simple
>consistent
>powerful

and furthermore more powerful than the most advanced static languages, then there can be NO JUSTIFICATION FOR ITS USE.

This essentially restricts the set of acceptable dynamic languages to the lisps.

Static languages enable much more powerful, concise, verifiable, and maintainable code than most dynamic languages.

IF YOU ARE USING A DYNAMIC LANGUAGE THAT IS NOT A LISP, THEN YOU ARE A POOR PROGRAMMER. IF YOU DEFEND A DYNAMIC LANGUAGE THAT IS NOT A LISP, THEN YOU ARE INTELLECTUALLY WANTING.

im a noob but

why not just combine both lists and sort the combined list again ? or am I retarded?

ADTs are closed. Interfaces generally aren't. Scala's sealed traits are an exception.

>IF YOU ARE USING A DYNAMIC LANGUAGE THAT IS NOT A LISP, THEN YOU ARE A POOR PROGRAMMER
my salary disagrees

who gave this guy a marker and piece of cardboard?

found the guy who knows what counts

that would be a lot worse than O(log(n+m)) since sorting by itself takes (n+m) * log(n+m)

I see

Having a particular salary does not imply that you have any particular level of programming ability.

Also:
>being a wageslave

so you're just a neet producing nothing of value?
knew your opinion didn't matter

>programming for free

a better metaphor would be if it was a bunch of trailers that you could optionally attach as desired and also most of the trailers are weightless

>working on other peoples' dreams instead of your own

Oh, I'm not a NEET. I'm always learning (i.e. the education part of NEET), but to better myself rather than to become a cubicle cuck.

>had to buy FPGA for class
>class is switching to different platform next semester
>can't sell mine to any students

FUCK

What did they mean by this?

I just finished my last project in my Ideas list and I am out of things to work on. I can't think of shit.

I am a jack of all trades type fag. My list of projects right now is
>IRC Bot with a command system, all in Python
>A C++ Tool which patches the memory of a game to disable mouse acceleration
>A web site written in Django with the Bulma CSS framework

Been programming for about 3 years now, and I've been learning as much as I possibly can from books for a long while now, so I guess I have experience enough to start contributing to open source shit.

So, how do you FIND shit to contribute to?

I once tried to contribute to GZDoom, the open source DooM engine recreation, in the hopes I could find a way to add mod profiles to make it easier to load up mods.

Couldn't even fucking find where the UI was handled. It was way too dense.

Which literal trash school, senpai?

>Java

you don't know what NEET stands for. (NOT in education, employment or training)

Watching java tutorials on Lynda while in bed with my android held up by a bedside phone holder

Gonna make fart apps soon!

java/python/cpp programmers = hacks
art of war = flamewars

Not sure if troll, or if you've actually deluded yourself into thinking you're not a NEET.

>He reads programming books
Nigger.
The only thing you need to do to learn to program well is to program. That's it. You'll learn 100x faster through experience than you will through reading.

It's better for you to write shitty code and then understand why the things you did were shit and how its all fucked up, and then to refactor and make it better, and keep doing that than it is to read
>"o le blah blah bad :^)"
That shit never works. It tells you it's bad, but not why or how. I read that global variables were bad, but I didn't understand how or why, so I kept using them in a particular program, until it just fucking broke. Then I re-wrote it and it was 10x more readable and better. Learn through experience.

The only comp sci books worth reading are security ones and interview ones.

everybody is always learning, more or less. the "education" part of NEET refers to institutional education

Thanks for the advice. I don't just follow the examples though I take a modular approach to applying what I learn. So I have been taking your advice before you said it but it is still good advice for anyone else who reads your post. These books are a reference for what works so that I can always have a jumping point to start from.

Institutional education is a scam invented by the 13 dark lords to coerce young people into drinking at parties and giving up their souls.

I still think this is the top metaphor for C++.

that could be entirely true and it wouldn't matter. it doesn't change what NEET means

>coerce young people into drinking at parties
Yes, because there is so much coercion required for that.

How would I go about dragging a browser tab into a program I've made and having it do something?

cracked open k&r, getting lost pretty quick, 3rd or 4th example when they introduce the for loop
#include
/* print Fahrenheit-Celsius table */
main()
{
int fahr;
for (fahr = 0; fahr

I don't even like java, but that's just a retarded complaint. Why don't you try overwriting malloc fences in C and see how well that works for you.

theres plenty of programs to grab porn videos already

what language?

Yes, I know what NEET stands for. I am in education (yes, a formal program, although I read voraciously on the side too), so I am not a NEET.

I'm teetotal.

delete this now

Check the drag-and-drop interfaces on whatever OS you're using.

It's basically the same as saying
int fahr = 0;
while (fahr

A few things:

Is the test condition fahr

is there EVER a situation when you need a triple pointer or higher?

Yes.

Why is it possible to break math in Java?

I would do it like this.
Compare the 0th index of both arrays to find which to start with, lets say nums1 has the lowest valued term so start with that. Then go through nums1 until you find a term larger than the 0th term in nums2, at which point record the index you got to and go through nums2 etc. until you get to the ( len(nums1) + len(nums2) )/2th term, which is the median of the two arrays.
Remember to get the next term along as well if the combined length of the arrays is even.

If you use a linked list you have to store the address of the first element of the list ( first pointer ) .
If you need to change in that list you need another pointer (two pointers)
If you need to pass your list that you are changing in two pointers and change it in another function you need another pointer(three pointers )
If you need to write a sparse multi-level table

C is shit, too.

what i have now, still doesn't give the correct answer though i think it's more on track
import math

class Solution(object):
def findMedianSortedArrays(self, nums1, nums2):
l1 = len(nums1) # length 1
l2 = len(nums2) # length 2

# check ending conditions
# if list 1 is empty, return the median of list 2
if nums1 == [] and nums2 != [] > 0: return median(nums2)
# if list 2 is empty, return the median of list 1
if nums2 == [] and nums1 != []: return median(nums1)
# if list 1 and list 2 have the same median, return it
if median(nums1) == median(nums2): return median(nums1)
# if list 1 = [x] and list 2 = [y], return (x+y)/2
if l1 == 1 and l2 == 1: return (nums1[0] + nums2[0])/2

m1 = median(nums1)
m2 = median(nums2)

if m1 > m2:
i = l1 - (l1//2)
del nums1 [(l1//2):l1]
del nums2 [0:i]

else:
i = l2 - (l2//2)
del nums2 [(l2//2):l2]
del nums1 [0:i]

return Solution.findMedianSortedArrays(self, nums1,nums2)

def median(x):
if len(x) % 2 == 0:
return (x[len(x) // 2] + x[(len(x)//2)-1]) / 2
return x[len(x)//2]

if you're iteratively stepping through one of the lists it's not O(log(n+m))

I think "programming book" is kind of a bad ambiguity here. Especially more broad books with topics like "compiler design" can be a good read and teach you algorithms as tools for you to use.
It honestly sounds more like your personal bad experience.

Triple pointer for c-strings.
A function takes a ***char and sets a pointer to a string.

If you need to ask, you're not good enough at C yet
t. 10 star programmer

>only 10

plebs out

this belittles actual abominations. if the dog man from the fly 2 could have been fixed by commenting out a couple of includes, he wouldn't have really had much of a problem

>Is the test condition fahr

/dpt/
Please forgive me for I do not know jack shit about programming.

Is it really hard to program a game over to another OS or is it just time and effort that most programmers don't want to do?

I've always wondered why so many games that could work on say a Nintendo product VS just a PS4 or an Xbox.

all considering that Vice city on Android

Because you're not breaking math, but the libraries that make ints polymorphic for passing to printf. Also it's possible to break anything with arbitrary access. With the same thing in C, you can overwrite machine code in functions and "break" their math too.

Any non-shit language will at least have the ability to do arbitrary machine-level things, and then you can break it.

You're implying that it's fine because you can do it in C, too.

C is not fine, and neither is Java.

Are you a cat?

When porting between consoles, it's not just about porting to a different OS. It's about porting to completely different hardware.

See >Any non-shit language will at least have the ability to do arbitrary machine-level things, and then you can break it.

>muh language can break math so it's good

>waaah the gun triggered even when i pointed it at my foot!

There's a big difference between "it's good because you can break math in it", and "it doesn't prevent me from doing anything I want with it".

>not using a gun that won't fire when you point it at yourself or loved ones

Okay, so OS ports in the sense of windows to linux to mac:
That depends completely on the codebase of the game.
Some programmers already code with multi-platform in mind, choosing portable libraries, containing platform specific code to certain files etc. and others don't.

In case of console ports (console to console or console to pc):
This is much harder since you have different input-devices, (if you use the modern controller features), you have the issue that games for consoles are usually tuned for that specific hardware and graphics options etc. don't exist. Other consoles like nintendo's have significantly less graphics power, so that you have to think about using different rendering routines.

I bet you're the kind of manlet who would love a welded hood on your car so that it forces you to bring it to the dealer when something's wrong instead of risking that you might get the idea to fix it yourself.

How are you supposed to learn a new language? I dont want to be told all over again what a integer and stuff is, and I tried codeacademy and that shit is annoying.

What is the best way to learn a new language (not new paradigm) while knowing all the basics? Just doing projects and googling problems?

raise Error;
...
lower Error; //Aka ignore

Looks fine to me. I would also suggest "rise in", as in "rise in rebolution"

>while knowing the basics
Let me guess, you're one of those "all languages are the same!" types?

Why wouldn't you want a gun that allows you to accomplish its intended task, and prevents you from causing yourself harm?

To begin with, it's generally more difficult to port between console than between different PC operating systems, because on PCs you're forced to use an abstraction layer for stuff like GPU access, such as DirectX or OpenGL. If you used the latter, that's much less work when porting. Whereas if you write for consoles, those libraries are generally not available, and even if they are you generally don't want to use them since half the purpose of writing for consoles is to wring everything you can out of the hardware. Porting between DirectX/OpenGL/console hardware can be a major task since it can affect every aspect of your game engine. The "big" engines that support several are severely much more complex for it.

On the other hand, once you've done the work of porting between two different platforms, it's usually much easier to add support for another one, since you've already done the work of abstracting the basic shitthat differ between platforms.

No im the type who knows C, some high level languages and some functional stuff, that i learned in college.

And they pretty much are all the same, except for the functional ones.

you realize how silly that sounds right? Sure anybody would want that but it goes against the very nature of what the gun is. That's why people take classes to learn how to properly handle a gun. It's not the gun's responsibility to make sure you use it right.

>Why wouldn't you want a gun that allows you to accomplish its intended task, and prevents you from causing yourself harm?
There's a reason those don't exist in reality,and it's much the same reason why you don't want it in programming languages. In reality, they end up preventing you from doing things that you want to be able to do, and have good reason to.

NIt him, but all languages are pretty much the same (except pure functional, those are just gilgamesh

I think what he means is he'd prefer a nerf gun

>Just doing projects and googling problems?
That usually the most effective, yes. Check out samples and stuff.

Are you that Rust shill?

Also, find the "reference manual" or equivalent of the new language, which deals with a technical description of the language instead of nub tutorials.

I figured as much as well

I saw someone tweet out about I think Dishonored and the graphics in comparison of BOTW are lower than I expected for an Xbox game. Is it the programming or is it just lower res I'm looking at?
The way you make it sound is as if we can port it over but as the first guy said, hardware is the main concern

Then run Java in sandbox mode. In that case, the example from wouldn't have worked either.