/dpt/ - Daily Programming Thread

Old thread: What are you working on, Jow Forums?

Attached: hidamari_dpt_waifu2x_traps.png (1618x1308, 1.95M)

Other urls found in this thread:

archive.is/mnbNo
eskimo.com/~scs/cclass/notes/top.html
markburgess.org/CTutorial/GNU-ctut.pdf
icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf
news.ycombinator.com/item?id=18348873
docs.python.org/3/howto/sorting.html#the-old-way-using-the-cmp-parameter
wiki.installgentoo.com/index.php/Programming_languages
twitter.com/NSFWRedditVideo

Transitioning into a real woman

first for C

Attached: 1492832377473.png (1052x1342, 769K)

Numpy & scipy stuff for university. Some things are ridiculously easy with these, but easy things in normal programming are usually fucking fuck shit. nparrays are failed datatype I fucking swear.

Attached: 1540016690718.jpg (931x714, 55K)

first non-degenerate post

You'll never be a cute anime girl.

Lisp is the most powerful programming language.

C++ is the most powerful programming language.

>sorry, unimplemented: non-trivial designated initializers not supported

Aren't all Turing Complete langs as powerful as each other? Or is there something beyond that

for me, it's zig

Attached: 2.png (386x122, 8K)

Can't even make a simple text editor with it.
archive.is/mnbNo

Attached: 1540128938864.png (860x585, 365K)

In theory, but low level access, memory mananger,concurrency mechanisms,type systems,metaprogramming capables.

Theoretically, yes, in that they can all compute the same functions / recognize the same language. But some will be faster, more expressive, do more with less syntax, etc.

Imagine computing with Rule 110 cellular automaton vs. python for instance.

Yes, in a somewhat unintuitive sense. For example, you could write an operating system in Assembly and C that runs on real hardware, but you can't do that in Python. However, you can still use Python to write a program that is indistinguishable (in terms of mapping input to output, i.e. as a mathematical function) from running that OS in a VM.

Does lisp have no gtk binding?

A big part of it is also what the ecosystem allows you to do. The standard library, utilities, base tooling, what type of low-level/high-level features are baked into the language, and compiler/interpreter features play into how "powerful" a language is.

What's a good textbook to learn modern c? I will of course read this along with it.

C programming a modern approach, and the other usual complementary books

emacs

what this user said this is good supplementary material for K&R:
eskimo.com/~scs/cclass/notes/top.html
the GNU tutorial goes into some of the common utilities of glibc:
markburgess.org/CTutorial/GNU-ctut.pdf

Emacs is written in Rust

Hey guys, need some help. I'm doing this assignement where I have to count the amount of prefixes in words passed from stdin. I gotta use Java. Right now I'm passing most test cases, but for some of them, my code is too slow. I was wondering if there was a way to get a String view in java, to avoid allocating all those substrings?
Commented for your convenience:
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();

// the amount of words in this batch. Up to 100_000 words
int words = Integer.parseInt(line.split(" ")[0]);

//the maximum lenght of the prefixes that I'll be counting
//(different from lenght of longest word). Up to 100 chars
int max_len = Integer.parseInt(line.split(" ")[1]);

//prefix_count[i] is the number of prefixes of lenght i
int[] prefix_count = new int[max_len + 1];

//store the actual prefixes here to check for duplicates
HashSet set = new HashSet();

for(int i = 0; i < words; i++){

line = br.readLine();

//Try all possible prefixes, starting with the whole word and
//removing a char at a time
for(int j = Math.min(line.length(), max_len); 0 < j; j--){

//if the prefix is a new one we register it and count one more
//of it's lenght
if(!set.contains(line.substring(0, j))){
set.add(line.substring(0, j));
prefix_count[j]++;
}
//if we already saw a prefix, all it's prefixes are trivially
//already in the set so we stop checking for this word
else{break;}
}
}

for(int i = 1, top = (max_len + 1); i < top ;i++){

System.out.print(prefix_count[i] + " ");
}
}

Thanks for the help. I also found this textbook: icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf I'll get right to it know.

Please do not use an anime image next time. Thank you.

Do I need to know Lisp fully to read SCIP?

No

Would it be stupid to be able to destructure an improper list like so
'(1 2 4 5 6 . 7)

A prefix cannot be the entire word so you only need to search for the longest prefix.

>public static void main(String[] args) throws Exception
the absolute state

ok, first, take these lines
int words = Integer.parseInt(line.split(" ")[0]);
int max_len = Integer.parseInt(line.split(" ")[1]);

and replace them with something like this
int[] spl = line.split(" ");
int words = Integer.parseInt(spl[0]);
int max_len = Integer.parseInt(spl[1]);

the way you're doing it, the entire string splitting algorithm happens twice, which is inefficient.
other than that, your algo runs roughly in O(n) assuming individual words are much shorter than the number of words entered. Also, since it's a hash set, checking if something in the list is redundant. It's a set in the mathematical sense, so each element is already unique IIRC

Attached: 1460515560181.jpg (852x973, 475K)

I have 2 images, one is the original and one is blurred by a 3x3 filter. I want to subtract the blurred image from the original one, how do I do this in python?

I assume I have to convert both images to arrays (numpy) and then subtract the blurred image array from the original image array, but i'm having trouble converting my images to arrays.

Help a brainlet out?

For this dumb ass assignement, if the lenght of the word is less or equal to the maximum lenght of the prefix, then the whole word can be considered a prefix. I know, weird, but I don't have logic errors. I just need speed.

PIL

I have to do it manually, don't ask why.

>His language doesn't have ADTs
YIKES
news.ycombinator.com/item?id=18348873

Can so LISP guru help me?
I have two syntax rules, but the second one isn't working.
I'd like to be able match against improper lists like the one I'm replying to.
Pic related

Attached: 2018-11-01-003633_365x196_scrot.png (365x196, 6K)

>he writes userland programs in C
>he thinks this makes him a better developer
>can't even name 1 (ONE) benefit C has
Holy shit. Are there people like this here? Please tell me this is not you

Attached: Girls.png (449x401, 490K)

>the first 2 things
You are right, but thats just laziness. i'm not THAT retarded,
>Also, since it's a hash set, checking if something in the list is redundant
Damn that's quite obvious, thanks. Was about to say that I needed to know if the element was in the set to be able to skip shorte prefixes, but then realized that add returned a boolean just for that, lol.
Sadly, this didn't work for the slowest cases, but definitely shaved some time in the others.

Anyway, solved it: turns out I had to initialize the set with a fuckhuge initial capacity. 12 million did the trick.

Easy interfacing with low level API, for one.

I don't do any C though.

>12 million did the trick.
so it begins. move to india pls.

Windows programming. The Win32 API is just a collection of .dll's written in C.

Nevermind, turns out the first one is contained withint the second one.

I'm thinking of doing some game programming and it's mostly C++. What's some good resources on using C++ without the shitty parts? I see a new meme is writing C and compiling as C++ but that seems stupid.

why kind of retarded question is that. your doing game programming so your going to base your coding style after whatever API you are using.

I'm trying to print PRETTY_NAME from /etc/os-release. In that file it says PRETTY_NAME="Gentoo/Linux"

I want to print "Gentoo/Linux"

How to do this in python?

Attached: 1537902533781.jpg (1280x720, 806K)

iterate over the file, startswith(), rsplit() and strip() as needed

21st Century C is nice, it goes over a lot of the modern tools and language features.

how do i exit a shell script properly when its finished, or, how do i properly execute shell scripts? my script runs to the completion but then hangs and control isn't returned to the shell once its complete despite there being an exit command.

post kode

sorted(d.items(),key=lambda t: t[1][1])
what the fuck are these indexes on lambda function and why doesn't anybody describe them

how the fuck am i supposed to know

i think that just accesses the element in each d item with which you want to sort all items
an item in d could be a list of lists for example, and each item gets input into the lambda and then sorts according to the output

how do you use dicts with old comparator functions
i want to query my custom comparator with key values
sorted(d.items(), cmp=customcmp)
how will this know to take in keys and not values from the dict

You should know what items() does

docs.python.org/3/howto/sorting.html#the-old-way-using-the-cmp-parameter

Attached: py_cmp.png (832x588, 41K)

yeah it returns key value pairs
so should i do this
sorted(d, cmp=customcmp)
or this
sorted(d.keys(), cmp=customcmp)

so you're saying i should use that additional function to convert my comparator to key function?
what the fuck is even happening in there and what in the hell s mycmp

If you want a list of key value pairs sorted by the values then you should do what you posted to start with.

So everyone keeps telling me scheme supports bignums, but yet when I type (+ .1 .2) I receive .30000004 as the result

Am I missing something?

no i want to sort it by keys
but keys have their own encoding
if i use a key function it just expects me to return a single value that shows its position wrt others
if i knew that why would i need a custom function
i need to compare a key with other keys to know where it stands in a list so i'm using the old comparator

apparently custom cmp functions can accept a list but when i pass a dict.keys() it's too many values

what does your customcmp look like
post code

def p_cmp(a, b):
if a[:1] is b[:1]:
if a[1:]b[1:]:
return 1
elif a[:1]

C++20 fixes this.

>Le C++XY+3 fixes this meme
Good one.

Attached: 1410157126025.png (273x254, 145K)

wait what python version are you even using
I assumed you were translating from py2 which uses cmp to py3 which got rid of cmp for sorted

>C++ does not have feature
Lmao C++ is useless
>C++ adds feature
Lmao C++ is too complex

You just wait!

Programming newfag here.

Where can I learn what you guys know about history of languages?

I’m looking for a Jow Forums biased blogpost or screencap or something

You can't spell trust without rust.

i'm using py2

Jow Forums is not a reliable source of information, try wikipedia

>I’m looking for a Jow Forums biased blogpost or screencap or something

The ‘install gentoo’ Wikipedia?

sigh... at least it works

Attached: 2018-11-01-043429_1358x748_scrot.png (1358x748, 78K)

Oh wow, I was being ironic but that’s exactly what I was looking for

wiki.installgentoo.com/index.php/Programming_languages

Regex

godbless that user that once rewrote my haskell spaghetti code into a nicer to read form

no i mean you shouldnt listen to anything anyone on Jow Forums says because they're all cs students with stupid opinions

Ew

Why does my function in Python not have access to my variable?

run = True

def start():
print(run) #Works
while run:
_handleEvents()

def _handleEvents():
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
print(run) #Error
run = False


This is the error in particular:
UnboundLocalError: local variable 'run' referenced before assignment

Attached: 1350594293765.jpg (500x500, 111K)

I’m looking into conflicting and balanced opinions.

Enterprise be like: lmaoJustLearnJavaAndSQL.png

kys fucking idiot

Remove the last line or add “global run” in the first line following your function declaration. You can only reference variables read-only if you do not use the “global” keyword, otherwise it is ambiguous whether you are referencing a global variable or a variable local to the function stack.

yikes

That sounds pretty dumb. Python is a weird language.

For some reason, this looks so comfy. I don't even like lisps.

What's a good language for someone who likes sucking tranny cock?

C

Can't spell cocks without C

Thai

Thanks familia
Well, I've burnt out, I'll see if I can refactor that spaghetti code into something more beautiful next week.

C|++

Nobody ever got fired for buying an IBM

Prove me wrong.
Protip: you can't

brb buying IBM Enterprise COBOL

>current year
>not firing that 30 year old boomer who still buys IBM

>windows update breaks several modules of my application all written by different people

Attached: 1416614089987.png (250x250, 50K)

>windows
you asked for it senpai

It's a consequence of not having variable declarations.
It's fucking gay.

i want to make money dammit

Attached: mfw115.jpg (640x480, 81K)

i thought web developers wrote windows applications these days

based middle ages poster