/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

en.wikipedia.org/wiki/Dependent_type
hackerrank.com/challenges/torque-and-development
github.com/search?q=interesting, small projects
coursera.org/learn/progfun1
msdn.microsoft.com/en-us/library/79b3xss3.aspx
sourceof.net/#mscorlib/system/int32.cs,148
pastebin.com/x2uKiZAg
github.com/DmitryHetman/gentoofetch
twitter.com/SFWRedditGifs

leggings make you code better

C was a mistake
ML was robbed

It didn't have to be like this

>mfw compiling a 100 LoC JS """app""" takes twice as long as compiling my 12k LoC C++ project

When did everything go so wrong?

C was decent choice at the time.
Lisp was robbed.
ML was created afterwards and still doesn't support native threads.

When C became the de facto standard systems programming language instead of Pascal.

Is inference for dependently typed systems generally the same as with Haskell/ML-like type systems?

speak English, doc

I don't think I can make that post more English.

he means dumb it down you fuckin' child prodigy

I replied to that right here

yes

I know you wanted to sound cool, but this is all readily available on wikipedia.

en.wikipedia.org/wiki/Dependent_type

no

maybe

>I know you wanted to sound cool
What makes you think so?
>but this is all readily available on wikipedia.
What I asked isn't there.

can you repeat the question?

you asked if the way these languages determines type is similar, how are you not able to extrapolate that from that page and subsequent links? Also, what sort of boring ass question is that? "hey guys do other languages infer types like Haskell hwufaw look at me i'm asking the smart questions".

What do you guys think about the people that go into cs because they think it's easy big money?

>you asked if the way these languages determines type is similar
I didn't ask that.
>how are you not able to extrapolate that from that page and subsequent links?
How would I be able to do that if the information isn't there?
>"hey guys do other languages infer types like Haskell hwufaw
If you thought that this is even slightly similar to my post, you lack basic reading skills.

That they're right.

the definition:
Type inference refers to the automatic deduction of the data type of an expression in a programming language

are you fucking retarded?

hi how was ur day

Fuck off you fucking faggot

"determine types" is pure nonsense.
>are you fucking retarded?
You are fucking retarded. A comment that stupid doesn't even deserve a proper response.

I got trips tho

I don't give a shit

> "determine types" is pure nonsense.
just because your reading comprehension is at a pre-grade school level doesn't mean it's nonsense you fool. Let me make it easy for you:

Inference:
a conclusion reached on the basis of evidence and reasoning.

Determination:
the process of establishing something exactly, typically by calculation or research.

again, are you a fucking full on retard?

hmmm check em

nice trips dog

Hurr muh repeating numbers
Fucking Sup Forumstard

>just because your reading comprehension is at a pre-grade school level doesn't mean it's nonsense you fool
Are you being retarded on purpose?

>a conclusion reached on the basis of evidence and reasoning.
This implies prior rules.
>the process of establishing something exactly, typically by calculation or research.
This does not say anything about prior rules.
Only a double-digit could possibly think these two things are the same.

>again, are you a fucking full on retard?
Go calm yourself, and maybe tomorrow you'll be able to speak to me properly and respectfully.

edgy

Going through "C++ primer" by Lippman, but there's an example i don't fully understand and the explanation doesn't cover my doubts:
// returns the index of the first occurrence of c in s
// the reference parameter occurs counts how often c occurs
string::size_type find_char(const string &s, char c,
string::size_type &occurs)
{
auto ret = s.size(); // position of the first occurrence, if any
occurs = 0; // set the occurrence count parameter
for (decltype(ret) i = 0; i != s.size(); ++i) {
if (s[i] == c) {
if (ret == s.size())
ret = i; // remember the first occurrence of c
++occurs; // increment the occurrence count
}
}
return ret; // count is returned implicitly in occurs
}


Why is variable occurs of type size_type and not just unsigned int? What is the purpose of the second nested if (ret==s.size)? Isn't ret always equal to s.size since it's set that way in the first line of the function?

I just solved the roads and libraries problem on Hackerrank ( hackerrank.com/challenges/torque-and-development ) with a hand-rolled algorithm. Here's my code, am I doing it right?

use std::io;
use std::collections::HashMap;

struct GraphComponents {
arr : Vec
}

impl GraphComponents {
fn new(n : usize) -> GraphComponents {
let arr = (0..n).collect();
GraphComponents {arr : arr}
}

fn true_parent(&self, mut i : usize) -> usize {
while i != self.arr[i] {
i = self.arr[i];
}
i
}

fn add_edge(&mut self, mut i : usize, mut j : usize) -> usize {
let tpi = self.true_parent(i);
let tpj = self.true_parent(j);
let tp = std::cmp::min(tpi,tpj);

while i != tp {
let parent = self.arr[i];
self.arr[i] = tp;
i = parent;
}

while j != tp {
let parent = self.arr[j];
self.arr[j] = tp;
j = parent;
}
tp
}

fn reduce_parents(&mut self) {
let size = self.arr.len();
for i in 0..size {
let parent = self.arr[i];
self.arr[i] = self.arr[parent];
}
}

fn count_components(&self) -> HashMap {
let mut h = HashMap::new();
for &val in self.arr.iter() {
*h.entry(val).or_insert(0) += 1;
}
h
}
}


(Cont in next post)

How can I find interesting, small projects on GitHub to contribute to?

aaaand i fucked up the layout.

fn read_ints() -> Vec {
let mut s = String::new();
io::stdin().read_line(&mut s).expect("Read error.");
s.split_whitespace().map(|x| x.parse().expect("Parse error.")).collect()
}

fn handle_query() {
let params = read_ints();
let n = params[0];
let m = params[1];
let library_cost = params[2];
let road_cost = params[3];

let mut components = GraphComponents::new(n);
for _ in 0..m {
let input = read_ints();
components.add_edge(input[0]-1,input[1]-1);
}
components.reduce_parents();

let output : usize = components.count_components().values()
.map(|x| library_cost + (x-1)*std::cmp::min(library_cost,road_cost))
.sum();
println!("{}",output);
}


fn main() {
let n = read_ints()[0];
for _ in 0..n {handle_query();}
}


The main advantage of this algorithm is that it should require less space than a more traditional graph search algorithm if the edges are read one by one from an input stream.

>What is the purpose of the second nested if (ret==s.size)? Isn't ret always equal to s.size since it's set that way in the first line of the function?
No, ret is past the buffer at the beginning, so when the first time a character occurs, it's set to the position of that character instead, otherwise it just keeps the first occurence of the character.

github.com/search?q=interesting, small projects

arguing semantics, the last refuge of the mouth-breathing haskell basement dweller.

"calculation' itself implies rules you idiot. Unless free-form jazz math is something knew I haven't heard about yet?

>Go calm yourself, and maybe tomorrow you'll be able to speak to me properly and respectfully.
children have to earn respect from their elders you little punk

Is it

- hello world
- Hello world
- Hello World
- Hello world.
- Hello, world.
- Hello, world!
- Hello, World!
or anything else?

I tend to "Hello, world!".

>Why is variable occurs of type size_type and not just unsigned int?
No idea. It's just confuzing for no clear reason at all.

>What is the purpose of the second nested if (ret==s.size)?
>Isn't ret always equal to s.size since it's set that way in the first line of the function?
except they set it to i in the block to mark the first occurence of c. Then, in subsequent passes, its value will not be changed again by the code.

For me, it's "sdioughdfiguh"

hello to za wurdou

$ python2 -c 'import __hello__'
Hello world...


Python3 isn't that depressive:
$ python3 -c 'import __hello__'
Hello world!

>arguing semantics
Semantics:
of or relating to meaning in language

Why would I not be arguing about that when you can't comprehend basic English?

>the last refuge of the mouth-breathing haskell basement dweller.
I don't use Turing-complete garbage.
>"calculation' itself implies rules you idiot
It doesn't. And that sentence says "calculation and research", which can easily mean constructing new rules and calculating something using these rules.
>children have to earn respect from their elders you little punk
You're going to get your heart broken, you sensitive boy.

Grüß Gott!

Oh shit, I understand now. Thanks!

If i have a List of numbers in C#, say { 1,4,6, 8, 9, 11, 12, 15, 18, 21, 27 ,29} , and i want to make all combinations of 5 numbers, where for example 2 of them are even and 3 are odd, how to do it?

>C#
stop right now

LINQ

That's what i also think, but i can't seem to figure out how to write meaningful command

>>C#
>stop right now
stop right now

Split into odd & even sublists. Then return all pairs of two integers from the even sublist, and all triples from the odd sublist.

> >>C#
> >stop right now
> stop right now
stop right now

Also, i found a good library for combinations, i already can write all combinations of selected numbers, but i can't filter them

The thing with combinations is that you want to filter as little as possible, and generate them cleverly instead. Otherwise your algorithm can easily get pwned by combinatorial explosions.

>Also, i found a good library for combinations, i already can write all combinations of selected numbers, but i can't filter them
how come?

Simple, don't know how to approach

epic

>epic
epic

>It doesn't. And that sentence says "calculation and research", which can easily mean constructing new rules and calculating something using these rules.

welp you're contradicting yourself now.

you do realize that a deductive system (that is how type inference is implemented by the way--though you knew that already right?) is step by step right? How in the fuck do you think the type is inferred if multiple determinations are not first made regarding the evaluated expression?

>You're going to get your heart broken, you sensitive boy.
you misunderstand, I just can't abide fucking useless douchebags coming onto /dpt/ and asking bullshit generic questions with the hopes somebody will rub up against their E-Chode.

SO stats just confirmed C for being a NEET/hobbyist language.

So basically you specify which connected component a node points to by pointing to the first node in that component? And you use a clever algo to update your representation efficiently as you add new edges?

BEHOLD

var input = new List { 1, 4, 6, 8, 9, 11, 12, 15, 18, 21, 27, 29 };

input.Where(x => x % 2 != 0)
.MuhCombinations(3)
.SelectMany(x => input.Where(muhDick => muhDick % 2 == 0).MuhCombinations(2), (ayy, lmao) => ayy.Union(lmao))
.Distinct()
.Select(x => string.Join(", ", x))
.ForEach(WriteLine);

And the extension method:
public static IEnumerable MuhCombinations(this IEnumerable elements, int k) => k == 0 ? new[] { new T[0] } : elements.SelectMany((e, i) => elements.Skip(i + 1).MuhCombinations(k - 1).Select(c => (new[] { e }).Concat(c)));

Already know Java & Python, friend came up to me and said "lets make a game for a game jam" and now I wanna learn C++. Looked up some tutorial videos and practice sites. Whats the best resource for learning a new language?

Working on small projects that force you to work with documentation while tackling various topics.

Holy fuck, give me some time to analyze this

Genius

how does one get to this level?

A cheeky marriage of stack overflow and the ability to reason about sets of things.

Also, a blatant disregard for performance if no one says it's mission-critical.

your MuhCombinations makes combinations, but what if i already have a list of all possible combinations?

>what if i already have a list of all possible combinations
A list of all possible even and odd combinations in groups of 3 and 2 respectively, or a full powerset of the raw initial data?

full set of all numbers

It's this season again.

I want to learn some functional language to cleanse my brain from the dirt of imperative CRUD shit I do at work, what would you suggest?

I want a language that is based on either CIL or Java, or at comparable to them (i.e. has a lot of existing libraries, proper threads with no GIL). Preferably with good emacs/vim/ide support

Is F# kawaii? Is there better enterprise-level candidate to learn nowdays?

I don't want to lisp (too old and parenthesisy), scheme(only fast implementation - Stalin - takes ages to work), Haskell (I don't have PhD in functions' endomorphisms) , Ocaml (GIL threads)

i found some library for making combinations, it's literally Combinations listofCombinations = new Combinations(rawList, 5); //for 5 elements in a combination

Then fucking Select over it, it's inefficient but nothing should be blocking you should it?

Scala

Then use that twice to make two lists of combinations; one for your even constraints, one for your odd constraints.

Then get combinations of these sets together.

Then the highest performance algorithm is probably to delete that huge array immediately and generate the combinations in groups of 3 and 2.

If say, 10% of the numbers are odd, splitting into groups give you a thousand-fold improvement.

well, you said functional but said you wanted it based on Java so I'd suggest you try out Scala. It works within the JVM, uses Java styling, and provides support for functional programming.

One of these days I'll be able to LINQ like this.

Currently trying to learn the syntax of a member.

When exactly are you supposed to use "static"?

You're not the boss of me now

coursera.org/learn/progfun1
Been there done that. It's very progressive and you learn a lot of interesting programming patterns you wouldn't have thought of. A good exercise. I didn't do the rest of the curriculum but reactive programming sound exciting.

Depends on the language you CUNT. Also read up, we're not your coach.

>enterprise-level candidate
>functional
I don't understand.

Yes, some functional languages are occasionally used somewhere in an enterprise, but it sure as hell ain't common.

Is this the fabled Sup Forums autism I hear so much about?
You're not obliged to answer my question, user. If your autism is that enhanced, instead of ignoring my post you can hide it.

Also, C#.

I use Scala a lot mostly when working in Spark, while it's definitely OOP most of the parallel computations and stuff that are done on the cluster I'm running my Scala code across is functional but is collected/accumulated into objects.

it's definitely not common in most day to day applications and such but becomes more prevalent in things like analytics or if some aspect of your stack relies on simulations or is heavily computational.

If C was a mistake, then surely someone came up with a better alternative?

>When exactly are you supposed to use "static"?
Google it. I'm not even joking. If you're using Rob Miles' Yellow Book 2016 edition, look in the glossary.

RTFM

msdn.microsoft.com/en-us/library/79b3xss3.aspx

This page literally explains everything in detail, showing you the purpose of a static class (not so common), and the purpose of static members within a non-static class (common).

int.TryParse() is a great example of a static method:
sourceof.net/#mscorlib/system/int32.cs,148

Also, C#

Is this a programming challenge

Join@@@Tuples[Subsets@@@({Select[{1,4,6,8,9,11,12,15,18,21,27,29},#1],#2}&@@@{{EvenQ,{2}},{OddQ,{3}}})]


Here's what it returns
pastebin.com/x2uKiZAg

Right, the explaination I found previously was a bit complicated but I think I get it now.
Thanks.

I believe you forgot your meme green quotation arrow.

THIS IS THE PRICE I PAY FOR TRYING TO FIT IN

Wrote screenfetch-like script for gentoo.

Where's the repo?

You did make this FOSS, right?

it looks cool but makes me sad inside.

github.com/DmitryHetman/gentoofetch
It's written in dash, don't detects nvidia/amd GPU yet.