/dpt/ - Daily Programming Thread

What kind of trouble are you up to?

Old thread:

Other urls found in this thread:

reddit.com/r/dailyprogrammer/comments/6y19v2/20170904_challenge_330_easy_surround_the_circles/
reddit.com
stackoverflow.com/q/3611760
twitter.com/NSFWRedditGif

>trouble
How to stop procrastinating

Isn't Java deprecated in education now? I read a headline but cba to read it.

trying to make a babies first botnet

I'm reading a HTML tutorial on w3schools.

...

trying to figure out this stupid shit for uni but the -1 on the range(len fucking ruins it

remember - you can make your code cute by using lambdas.

In python the expression (and thus scope) isn't evaluated until it is called so you can do things like
Niggr = lambda x: i*x if x > 3 else i*3

for i, j in enumerate(something()):
print(niggr(j))


CUTE

What's so funny?

If I'm developing a multi-user networked application with support for thousands of simultaneous users and I use MySQL (MariaDB to be exact), should I write a database server into a separate application, or directly connect to the database from all the servers that serve users?

python lambda syntax is disgusting.
even java does it better

you're a nigger

First
>>>/wdg/
Second, use Mozilla's reference and tutorial on HTML.

user, remember your fundamentals.

jesus christ and I just realized the point you were making with i's scoping. that's gross, even javascript doesn't allow that

I'm a fan of writing a database access API for the app
this way you precisely control what the clients can do (no arbitrary sql queries), because you only create a handful of API calls for what they actually need
you also get to verify the fuck out of each parameter that is sent in

Java's lambda syntax isn't that bad though.

Working with Java
public class Solution {
public List groupAnagrams(String[] strs) {
if (strs == null || strs.length == 0) return new ArrayList();
Map map = new HashMap();
for (String s : strs) {
char[] ca = s.toCharArray();
Arrays.sort(ca);
String keyStr = String.valueOf(ca);
if (!map.containsKey(keyStr)) map.put(keyStr, new ArrayList());
map.get(keyStr).add(s);
}
return new ArrayList(map.values());
}
}


Working with Javascript
function groupAnagrams(strs) {
let map = {};
for(let s of strs) {
let key = s.split('').sort().join('');
(map[key] = map[key] || []).push(s);
}
return Object.values(map).map(a => a.sort());
}

I was thinking of just making an API instead. So you would not make a separate application for the database, then? Just do all queries from main program, but through the API.

>First
>Second
Third, you write like an asshole.

I would make a separate application
the client application doesn't have to know anything about the database really, it doesn't even have to know a database exists
it just has to know where to send requests and how to parse the responses

I see. I might do try that, then.

>Third, you write like an asshole.
How old are you?

No, javascript allows that, look up variable hoisting

Old enough to be your father kid, stop watching chinese cartoons. They make you stupid.

This is what I have to choose from, if I write it

diagonal = []
last_column = len(matrix) - 1
for row in range(len(matrix)):
diagonal.append(matrix[row][last_column- row])

it works perfectly but I can't take the fucking -1 out of the "range(len(matrix)" part so it cuts the last number

Actually, a little bit better is this one
function groupAnagrams(strs) {
let map = {};
for(let s of strs.sort()) {
let key = s.split('').sort().join('');
(map[key] = map[key] || []).push(s);
}
return Object.values(map);
}

I'm actually employable now that I'll be finishing up college, and am curious how prevalent is C# in the current job market? I've been using C++ for years and am very comfortable with it, but I seems like Microsoft is giving more attention than ever to C# and it seems like there's more and more frameworks popping up that use it.

>chinese
It's vietnamese actually, pa
And yes, I'm a paedophile just like every other anime poster!

Although admittedly it has slightly worse time complexity when all your strings are one anagram.

working with python
from collections import default dict
def groupAnagrams(strs):
handler = lambda: ''.join(sorted(s.split('')))
keys = defaultdict(list)
for s in sorted(strs):
keys[handler()].append(s)


We win again

I knew it because I'm actually your lost and forgotten twin. It's good to see you after all these years brother.

Yeah you can't beat Java's verbosity. And you can still get reasonable static assertions with TypeScript.

Although you probably want to return keys.values()

Er, meant to say different anagrams.

>I'm actually employable now that I'll be finishing up college

Oh ho ho, maybe not as much as you think.

More than others I guess? I have a GitHub with plenty of contributions and a sizable open source program made for editing Halo 2 .map files. I mean, I've never been through the process, but I hope they don't look at me like every other shit that just plopped out of college (spoiler: they will)

This should tell you that one of your other answers is wrong then.
Think, user, think. I believe in you!

Link your github, fag.

I have less than 30 minutes left to turn it in and I've been stuck on it for the past 2 hours.
I don't want to give up but this is fucking ridiculous, I found a way that works but because some dickhole that wrote this shit thinks it has to be more complicated than it is, my answer is wrong

ArrayList groupAnagrams(String[] strs) {
Map new ArrayList()).add(s);
}
return new ArrayList

Take a sceenshot of each combobox then like you did here I or some other fag will give you an answer.

>tfw 4 month streak of no code written

Could you please delete your image? It's late at night and I'm tucked in bed all snug but it's so spooky when I saw it uhm well now I have to get up and change my sheets and pajamas...
Please take the image down now, please and thank you...

All the boxes have the same choices

>I'm actually employable now that I'll be finishing up college
Wait, does this mean you have no chance without a degree?

No.

reddit.com/r/dailyprogrammer/comments/6y19v2/20170904_challenge_330_easy_surround_the_circles/

import std.stdio,
std.algorithm,
std.string,
std.conv,
std.array;

void main()
{
float[] x_max, x_min, y_max, y_min;

char delim = ',';
string input;
while ((input = readln().strip()) !is null){
//C++ cucks can suck my fucking cock
float[] vals = input.split(delim).map!(to!float).array();
x_max ~= vals[0] + vals[2];
x_min ~= vals[0] - vals[2];
y_max ~= vals[1] + vals[2];
y_min ~= vals[1] - vals[2];
}

float max_x = x_max.maxElement();
float min_x = x_min.minElement();
float max_y = y_max.maxElement();
float min_y = y_min.minElement();

writefln("(%s, %s), (%s, %s), (%s, %s), (%s, %s)", max_x, max_y, min_x, max_y, min_x, min_y, min_x, max_y);

}

I'd rather not, identifiable information there. Though I could clear it up for a bit I guess.

No, it doesn't. But I live in a pretty major city where business converge on my school pretty much daily looking for talent. It's just a good place to network and build a resume with research.

Please, user, it's really spooky...

>reddit.com

>java lambdas
still waiting for Java 8 to hit

>We win again
I threw up a little

def groupAnagrams(strs)
strs.group_by { |s| s.chars.sort.join }
end

Well that's better user. Still bigger and uglier than JS/Python though. I'll forgive that you omitted the class/imports to make Java look less verbose.

But... can you beat this functional programming?!

import qualified Data.Map as Map
import Data.List

groupAnagrams strs = map sort $ Map.elems dict
where dict = Map.fromListWith (++) [(sort s, [s]) | s

Fuck ton better than Sup Forums's shitty programming "exercises"

What is it that you guys are trying to achieve?

Java 8 hasn't hit yet?

You're just cheating because your runtime happens to have a group_by function. Which, might I add, python does as well. That's completely irrelevant to the language itself.

It's the same logic as the people amazed by twitter Mathematica programs that just call lots of pre-implemented code.

> //C++ cucks can suck my fucking cock
Why did you bring that up?

Sorry, I had to take shit.
Choose [0,1,2,3,4] for the second combobox.
Step it up, user.

Because he loves using GC

dude GC lmao
Meanwhile no splitter in C++ library, maybe C++26 will fix this

Why are you posting here if reddit is so good? Go back.

I've returned to my mortal body to say thanks to this gentleman for using the superior systems language.

THANK YOU, BASED ANDREI

>Meanwhile no splitter in C++ library
fuckkkk, how will we deal?
idk, maybe google somebody that wrote one or make your own

Thanks but too late, time ran out

I've been programming in Java 8 for over a year now.

nosplitter.webm

>mfw databases TA pronounces SQL as s-q-l and not sequel

Does not.

var nigger = function(x){ return x>3 ? i*x : i*3 };

[1,2,3,4,5].forEach(function(i){
[10,20,30].forEach(function(j){
console.log(i,j,nigger(j));
});
});

This won't work. You can prepend it with var i, or let i, or whatever else, the i inside the function won't refer to the i the loop iterator.

What does this do?

desu, it is kind of strange that when I use C++ I essentially always have to include a header-only text manipulation file I wrote a while back

like, why doesn't have split, or ToLower, or TrimWhitespace
you know, absolutely basic shit that you use all the time in every program that handles text

Rust doesn't have this problem.


It just has other problems.

Fuck. I need to stop eating taco bell, especially at night.
Anyway, I think you might've overthought that problem, user. But even then, you should've brute-forced it.

dumb frogposter

Looks like it's detecting anagrams in input.

["red","oops","der"]

will produce

{
"edr": ["red", "der"],
"oops": ["oops"]
}

>core library is cheating
sure, let's go and implement sprintf every time we use it
def groupAnagrams(strs)
res = Hash.new{[]}
strs.each { |s| res[s.chars.sort.join]

You have to do some of the most autistic gymnastics imaginable just to get buffer input in rust.unwrap().ok()

I've had a shit day and was just trying to have fun I guess. Wasn't a point to it, sorry if it shitted up your day instead.

Sadly no, you didn't write equivalent code. Python has different scoping rules than JS but in this case the functional scoping does the same thing.

Your mistake was you added additional functions, which creates additional scopes. I don't blame you though, var scoping in JS is a clusterfuck and is poorly understood even by professional developers. Thank god they introduced let.

var nigger = function(x){ return x>3 ? i*x : i*3 };
for(var i in [1,2,3,4,5]) {
for(var j in [10,20,30]) {
console.log(i,j,nigger(j));
}
}

same thing the function I replied to it does. Takes a list of strings and groups all the strings that are anagrams into lists, and returns all such lists.

["abc", "cba", "def", "bac"] => [["abc, "cba", "bac"], ["def"]]

No, nothing can beat Haskell.

Employed Haskell programmer here

Except you didn't even do the same thing.
>returns a dictionary
>not sorted lists of anagrams

wanna know how I know you're a dynamic dummy? you didnt even read the type signature

No, no, no, user, you're the dumbo here, your code is not equivalent.

In python, code right before the loop and code in loop are not in the same scope. In python you can't add print(i) right before the loop, and in my code you also can't add console.log(i) right before loops, so my code is equivalent to python; yours isn't - in yours outside and inside of loop are the same scope.

> I don't blame you though
Eat a bag of dicks. If you honestly didn't know you were in the wrong while you were typing your reply, there's no hope for you.

Tell me what the type signature is, then.

I'm trying to wrap my head around SSA so I can use LLVM instead of my slow stack machine VM & bytecode. Then there's the matter of my type system, which operates directly on the syntax tree in the slowest way imaginable...

now i don't know who to trust
this must be why people voted trump
return res.values

That's so cute, Haskell; Here's how real men do it:

sub groupAnagrams(@){
push @{ ($dict{ join '',sort split // } ||= []) },$_ foreach @_; values %dict;
}

consult your mental health professional

>m-muh punctuation

Why can't we all be friends?

>In python, code right before the loop and code in loop are not in the same scope.
You're fundamentally wrong about this. Python doesn't have block scope. I thought you already understood that, and that was the whole point of showing .

Don't believe me? stackoverflow.com/q/3611760

>In python you can't add print(i) right before the loop, and in my code you also can't add console.log(i) right before loops
Wrong about the second one. Due to variable hoisting, i will be declared but set to undefined - it won't error. This is one of the scoping differences. You can literally try it: console.log(i); for(var i;false;); The code I wrote exposes the similarities between python and JS because once the variable is set, when the function is called later, hoisting behavior doesn't matter anymore.

>in yours outside and inside of loop are the same scope.
In both, outside and inside the loop are the same scope. That's how it works in both languages.

Because my opinions > your opinions, and we'll never get along until you accept that.

Putting print(i) before loops in that code snippet causes an error in python, and I did test it. Putting console.log(i) into my code also causes an error. In your code, it doesn't.

can anyone help me out with a little java problem im having. i just started learning java and im trying to compile this program but i keep getting "class, interface, or enum expected"

heres what i wrote

public class MathTest
{
public static void main(String[] args)
{
int value = 3;
value = value - 2* value;
value++;
System.out.println(value);



}
}

Being friends requires state and Haskell people just can't allow such a dangerous thing.

...

Fuck. You almost can't beat code golfing in perl.

I don't disagree with that, it was one of my points

is this the entirety of your file? this compiles and runs

```rust
fn group_anagrams(strs: Vec) -> Vec {
use std::collections::*;

let mut map = HashMap::new();
for s in strs.iter() {
let key: String = {
let mut key: Vec = s.chars().collect();
key.sort();
key.into_iter().collect()
};

let list = map.entry(key).or_insert(Vec::new());
(*list).push(s.to_string());
}

map.values()
.map(|x| {
let mut c = x.clone();
c.sort();
c
})
.collect()
}
```

Your point was that my code is not equivalent to python and that yours is. That's wrong, and is demonstrated by printing i before the loop - my and python snippets cause an error, behaving similarly, your code works, behaving differently from original python snippet.

yes it is. im attempting to compile it and i keep getting the same error.