/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: 1533228106322.png (787x830, 733K)

Other urls found in this thread:

fun-mooc.fr/courses/course-v1:parisdiderot 56002 session03/about
docs.python.org/3/library/stdtypes.html#str.title
cs.cmu.edu/~112/notes/notes-strings.html#looping
code.woboq.org/userspace/glibc/sysdeps/posix/tempname.c.html
cs.cmu.edu/~112/schedule.html
datasciencecourse.org/lectures/
billthelizard.com/2009/12/sicp-exercise-114-counting-change.html
tangiblesoftwaresolutions.com/product_details/cplusplus_to_java_converter_details.html
twitter.com/SFWRedditImages

First for OCaml.

Go about to be BTFO by ya boi rust

Attached: IMG_20181129_084737.jpg (1200x862, 137K)

JavaScript rocks!

Attached: js-rocks.png (1000x494, 369K)

>gopm
what is it? i thought go didn't have package management just shitty https import

>writing a toy os for a platform without one
>only available emulator doesn't emulate memory protection, impossible to debug real hardware outside of printing to console
this is gonna be a pita

Yes but how many of those 'crates' are compatible with and totally unusuable otherwise? Not that I hate Rust, it's the best going right now for webAssembly hacking, just the absolute fucking state of the programming working group that is in charge of breaking changes every X months.

Attached: stallman.jpg (499x360, 35K)

>FILE * tmpfile ( void );
>Creates a temporary binary file, open for update ("wb+" mode, see fopen for details) with a filename guaranteed to be different from any other existing file.
How does this work? How can they guarantee the filename is unique?

tfw when I was 1 day late registering for the OCaml mooc fun-mooc.fr/courses/course-v1:parisdiderot 56002 session03/about

Attached: noooooooo.gif (220x164, 251K)

Nobody uses tools like gopm.

i just found out about dummy blocks in c.
my mind in blown

It should be noted that you have to write your own crates for everything in Rust (or use an existing one) as it doesn't have a standard set of libraries like GoyimLang does. So there is a crate for literally everything

imagine calculating your language's success by the amount of packages the community produces.
Imagine actually using a lang with no std of its own.

>Imagine actually using a lang with no std of its own.
Standard library? It's not really a big issue if the language has a good package manager and build system like Rust does. C and C++ on the other hand suffer greatly from this.

>Given a column title as appear in an Excel sheet, return its corresponding column number.
>A -> 1
>B -> 2
>C -> 3
>...
>Z -> 26
>AA -> 27
>AB -> 28
>...
>ZY -> 701
>AAAA -> 18279

my solution
int titleToNumber(char* s) {
int re = 0;
while (*s) re = (*s++ ^ 64) + re * 26;
return re;
}

>It's not really a big issue if the language has a good package manager and build system like Rust does
have fun trying to build anything and one dependency blows up and topples the tower.

Currently writing a posix ed implementation in c as a learning project.
I'm stuck at parsing addresses from the input line, but I have to admit that I haven't had much time to dedicate to this

int foo(string A) {
auto n = A.length();
int value = 0;
for (auto i=0; i

For me, it's R.

Attached: tryR.jpg (220x220, 10K)

python
titleToNumber = lambda s: reduce(lambda x, y: y + x * 26, [ord(a)^64 for a in s])

>be me
>brainlet still learning to code
>have to create a function in python that takes a string and capitalizes the first letter of each word
>spend 20 minutes trying to do it regularly
>it keeps stopping after the first word
>re write function like 10 different ways
>do some googling and turns out theres a .title() method that does it for me


im not gonna make it, bros.

Attached: sadapu.jpg (619x453, 57K)

I'm guessing it actually wants you to implement the function, and not just make a silly wrapper function. But it's Python, so who knows.
But you can easily do that regardless with a list and map

That's alright, fren. You could learn a lot more by implementing it than using the method. Use the method for performant code, though.

it's a bit broken though:
>>> "user's a brainlet".title()
"user'S A Brainlet"

you want capwords from the string module instead

Are you trying to learn programming or googling?

how do i learn without using the internet?

memorising all methods doesn't make you a good programmer, it's just convenient

crates.io archives every version and Cargo lets you freeze a dependency at a given version.

Like the people who build the internet, or those who build anything else before the internet was actually usable.
Docs and books

>Docs and books

don't be silly

the internet is >>> all the docs and books that anyone has

post your code loser.

hey guys.
im 31 years old and have wasted a lot of time.
I keep saying I'm going to learn programming, but just get lazy about studying.

Maybe I'm just not interested, but do you guys think it's possible for someone my age to dedicate themselves to this craft and get to a point where I can live comfortably?

No, too late for you grandpa.

Sure, but it'll be pretty soul-crushing to be a junior-dev at 30 something.
So it ultimately depends on what kind of work you actually want to do.

def uppercase_words(string):

for word in string:
return string.replace(word[0], word[0].upper())

help me

This is what I was afraid of.
I make a modest living now, almost 70k a year (not a lot in NYC). If I could land a junior-dev gig and make the same salary or close to it, I wouldn't mind it. I just want to work with computers .

i also tried creating a new string then adding the capped word to that string but the string keeps going and doesnt stop after its gone through the string once

def uppercase_words(string):
return string.title()

Probably not. If you haven't grown out of your laziness by now you probably never will.
Stick to flipping burgers or whatever it is you do now.

no shit

This is appacademy's tutoral problem right?

learn regex.
here's my quick and dirty brainlet solution.
auto word = ctRegex!(`(? word[0][0].toUpper ~ to!string(word.hit.drop(1)) ) (str,word);

A tiny, feature-incomplete Haskell implementation in C

no i just saw some guy on yt doing it on codewars and i wanted to try it for myself

ty user. gonna study regex next i guess.

By reading documentation and testing code instead of modifying someone's else example
docs.python.org/3/library/stdtypes.html#str.title

what language is that?

it's really easy, as negative/positive look-behinds/aheads will solve 90% of basic regex problems. And if you want to go balls deep you can learn more advanced stuff.

SML here...

D
a full example would be
void main()
{
import std.stdio: writeln;
import std.regex: ctRegex, replaceAll;
import std.conv: to;
import std.ascii: toUpper;
import std.range: drop;

auto word = ctRegex!(`(? word[0][0].toUpper ~ to!string(word.hit.drop(1)) ) (str,word);
str.writeln;
}

You could use regex or you could just loop through and use ascii numbers, if number is > this (meaning lower case), add X amount to make it uppercase cs.cmu.edu/~112/notes/notes-strings.html#looping

This is how everybody learns actually.
Before we had MOOCs or books (meaning, they were expensive and nobody had access to them), you basically just through trial and error, going off illicit photocopies, tried to figure out how to modify a program you were using, like a shitty pascal game loader or kernel modifications. With each error and wall hit, you learn something new and repeat until you get it.

Think back to those guys who didn't even have access to a computer, they had to write it on paper, refine their paper program and then had 30mins alloted time at a terminal to enter and run it. They didn't give up after their toy compiler written in assembly failed to run.

>1. Generate random file name
>2. Check if the file exists by trying to create it
>3. If the new file is created, return the pointer to it
>4. If the new file fails to be created, go to step 1.
code.woboq.org/userspace/glibc/sysdeps/posix/tempname.c.html

Currently sitting on a fucking bus, normally my commute is about an hour but tonight it's looking like it's gonna be more like 2.5 hours. I was hoping to put in a bunch of time in on some projects tonight, but I guess that's fucked now. Fuck snow.

>what is std
It's small, but considering static linkage is the de facto standard in Rust, that's kind of a good thing. I do wish I didn't have to be online to use something as simple as relaxes, though.

It's partly facilitated by your OS, most likely. That's a POSIX standardized behavior, so it's going to work that way regardless of how it's implemented.

SICP has this exercise.
(define (count-change amount)
(cc amount 5))
(define (cc amount kinds-of-coins)
(cond ((= amount 0) 1)
((or (< amount 0) (= kinds-of-coins 0)) 0)
(else (+ (cc amount
(- kinds-of-coins 1))
(cc (- amount
(first-denomination kinds-of-coins))
kinds-of-coins)))))
(define (first-denomination kinds-of-coins)
(cond ((= kinds-of-coins 1) 1)
((= kinds-of-coins 2) 5)
((= kinds-of-coins 3) 10)
((= kinds-of-coins 4) 25)
((= kinds-of-coins 5) 50)))
Draw the tree illustrating the process generated by the count-change procedure of section 1.2.2 in making change for 11 cents. What are the orders of growth of the space and number of steps used by this process as the amount to be changed increases?
I got space O(n) from the book saying that the space required is proportional to the depth of the tree and observing that the path to the lowest node in the tree always goes through (cc n 1). There's always 4 nodes above (cc n 1) and exactly n nodes below it, so 1 + 4 + n = n + 5 for depth and therefore O(n) for space.

I'm lost on the steps required, don't even know where to start.

for word in string.split(" "):

Also you should change return to yield, or do something with the uppercase words.

>NYC
A million 'jr data engineer' jobs are there analyzing finance shit.

Start here:
cs.cmu.edu/~112/schedule.html
Half way through do this at the same time:
datasciencecourse.org/lectures/

By do, that means finishing all the assignments, no matter what. A daily slog, may take you a week to figure out how the requests library returns a list inside a dict inside a list and how to parse that shit. Eventually you will get faster and faster at these assignments.

When you're done go on stack exchange website job search and look up NYC data engineer or just go on upwork and be a freelancer until you have a big enough portfolio to be a jr data 'engineer'.

google the exercise number, it just wants you to draw the tree on pen and paper. billthelizard.com/2009/12/sicp-exercise-114-counting-change.html

>or just go on upwork and be a freelancer
and then realize that this is the optimal way to work, find a few long term clients, and never get a "real" job

A significant part of learning programming is learning googling.

I've got 5 functions that can be applied to a string here, I drew a truth table for all the possible combinations.

Is there any elegant solution to implementing each of these 32 cases without using nested for loops?

Attached: function problem.png (255x743, 7K)

So folder path is part of the file name?

I seem to recall that generating truth tables was np complete from uni

The explanation on that page actually got me to understand. I did google it but I only looked at the scheme wiki solutions (which were all shit and some of them just incorrect). Gonna use this site from now on.

Attached: 1531982452321.jpg (1000x800, 45K)

We haven't learned that stuff yet.

As of current I have a bunch of nested for loops - the only other option I can think of is 32 lines of code, so for the last line for example, the code would apply F1 F2 F3 F4 F5 to the string.

if the first letter is already capitalized, this makes it lower case
nice try, C-

29 yo here.

Don't ask Jow Forums, they're a bunch of kids.

What are you trying to generate? Is it 1 string to 32 modified strings, or do you need to decide which set of functions to apply based on the string's contents?

A single for loop with bitwise operations.

create a list, array, vector or whatever you want, and fill it with one pointer to each function
create a lookup table that returns true or false if the current selection of functions is valid
then do a for loop from 0 to 31 inclusive. this value represents the currently selected combination of functions (binary 00000 to 11111)
you can use this value to look up if it is a valid combination in the truth table and also to call the functions from the array of function pointers

F1 to F5 are 'string modifier' functions, so like, F1 could be replacing all 'a's with a '4', and so on.

When it's a 1, I apply that function to the string, so the 2nd to last line for instance generates a new string that has F1 F2 F3 F4 but not F5 applied to it.

It will result in 32 new strings - each of which is generated according to which functions are being applied.

I'm trying to google this

yea, ;_;

Lisp is the most powerful programming language.

Did you start late?

Then this is where to start. Loop counting from 0 to 31, each time test the bits in the counter to see if a function will be called this time around or not.
What language?

What's inelegant about nested for loops? Simplest solution, and it's pretty clear what you're doing.

java, trying to make sense of how to do that

nothing, it just seems like what I did is inefficient is all

i don't understand what you're trying to do
you're saying that you have a set of booleans, and for each boolean set true you call a corresponding function on a string?
if that's the case, then you could store those booleans as a bitflag enum and do something like this:
int flag_checked = 1;
for(int i = 0; i < 5; i++)
{
if((e & flag_checked)!=0)
str = function_on_string[i](args);
flag_checked

Attached: 1542171005865.png (720x720, 277K)

let's say we are at line 11 in the truth table: 0 1 0 1 1

that means I will call functions 2 4 and 5 on the string (and of course, I will do something similar to every line in the truth table)

that truth table is just all the 'unique' possible outcomes when applying those functions to a string

SICP

I was gonna post the answers to my github but all the answers are online anyway.... kinda lame but most people seem to quit after the first chapter, lmao.

Attached: 3432423423424.png (514x585, 414K)

then you take the code i wrote (translated to your language ofc) and perform it on each of 32 possible combinations (simple loop from 0 to 31)
e will no longer be an enum in this case, just a number taken from the loop

I will try your way and see if it works, thanks

Attached: 1534291697057.jpg (631x1000, 78K)

This course looks great. I think I'll give it a go.
Thanks for posting it.

>there any elegant solution to implementing each of these 32 cases without using nested for loops?
how bout to start with reducing TT?

def upper(word):
return word[0].upper() + word[1:]
def uppercase_words(str):
return ' '.join([upper(x) for x in str.split(' ')])
>>> uppercase_words('op is a faggot')
'Op Is A Faggot'

does the order of the functions' execution matter? either way, it's as simple as some bitmasks and a few if statements.

main problem is that it's a large amount of code doing something trivial

/mu/tant detected

order doesn't matter at all

Is it even worth reading?

this is a lot easier to do in C, since you can have function pointer tables, but since you want to do it in Java, here's a hint that applies to both:
for (int i = 1; i < 64; i

actually, here's a better one for your scenario:
for (int i = 0; i < 5; ++i) {
if (inputnum & (1

Alternatively,
function_list = [lambda x:f1(x),
lambda x:f2(x),
lambda x:f3(x),
lambda x:f4(x),
lambda x:f5(x)]

def map_all_combinations(string, function_list):
output = [string, function_list[0](string)]
for f in function_list[1:]:
output.extend([f(i) for i in output])
return output


essentially starts with the top right of the truth table, then adds the next function applied to all previous possibilities.

shit seems too complicated for the level I'm at rn, but I'll try to make sense of it (will probably just keep my answer as is since it works)

wtf, why do (lambda (x) (car x)) when you can just give give car

def map_all_combinations(string, function_list):
output = [string]
for f in function_list:
output.extend([f(i) for i in output])
return output


I'm probably not explaining it well. In the truth table, the first line is all zeros, the second line is the same but f5 is changed to one. The third and fourth are the same as the first and second but f4 is changed to one. The fifth-eighth are the first-fourth with f3 changed to one. Etc. At each stage the size of the output list has doubled.

Oh Boy! Function pointers

Attached: functional_cpp.png (880x428, 40K)

now if only I knew C++ to translate this to java

>using namespace std

tangiblesoftwaresolutions.com/product_details/cplusplus_to_java_converter_details.html

fun fact, std::function is not a function pointer as it may include state, i.e. when used with std::bind

just loop (unsigned) n = 0 to 32, and take the 1st, 2nd, 3rd, 4th and 5th last bit