/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: 1986_10200492964830340_809177045_n-2.jpg (557x704, 84K)

rust is disgusting

you're not supposed to eat it

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.

Example 1:

Input: [3,0,1]
Output: 2


Example 2:

Input: [9,6,4,2,3,5,7,0,1]
Output: 8

p.s. Your algorithm should run in linear run time complexity. Could you implement it using only constant extra space complexity?

indecisivie, stubborn fag here from previous thread. I'm trying to decide how to declare my major/minor, and I'm not sure whether to go with math/cs, cs/math, math/stats or cs/stats.

I need to decide in under two months. I'd like to keep options open for post grad stuff, but also be employable with just a bachelors. The pros/cons as far as I can tell:

math/cs
>+math is cool
>-less immediately employable right out of the gate

cs/math or cs/stats
>+can immediately find a job, basically
>-i have no idea if I could tolerate programming as an employee day in, day out

math/stats
>+with a side github portfolio, this might open up a lot of data jobs
>-i would have to really prove I know how to program, or translate models into programs

oh shit
you do a bunch of swaps jumping around don't you? like start off, see 9, swap it into position 9, then go wherever the one you swapped goes, etc
until something, haven't thought that far

Hoi, Anone! Came over for the JavaScript lesson. Let's begin!

Attached: dfe7339a06dc5d91cf6f7e9d05e05f6a.jpg (640x1024, 66K)

I tried to teach someone with python and failed miserably. Holy shit python is an ugly language

Go into EE and Math.
CS degrees are worthless these days.

Attached: 1561785717929.jpg (658x678, 169K)

how do I make a more informed decision here? it's driving me crazy guys. I just want to know the fucking trade offs.

also, the biggest risk with math major is ending up an employable loser. That's a pretty big risk when compared to the degree price tag.. Biggest risk with CS is ending up with a career I hate. I have no idea how I'd take to coding for 8 hours a day for someone elses projects, in a team, under a manager.

Go into EE and CS.
Math degrees are worthless these days.

does Computer Science as a degree still exist? I thought it was dividen into Software Engineeing and IT

Ever notice how all programmers are white?

Is +Infinity a constant?

Isn't it just
def f(n):
return n*(n + 1)/2

def missing(l):
return f(max(l)) - sum(l)

I assume n can't be missing.

It does, but it's so over-saturated and completely devalued.

Yes, but it focuses exclusively on the abstract math. Most professors can't even code.

and what do they teach in Computer Science? How to defrag a hard disk and change CPu? Because I can't imagine

How is the array implemented?

data = [9, 6, 4, 2, 3, 5, 7, 0, 1]
print(set(range(min(data), max(data) + 1)).difference(data))

Attached: dont thread on me.png (267x189, 7K)

>and what do they teach in Computer Science?
foundation and theory of computers and how they work
some math
light programming in java/python

They teach theoretical horseshit like automata and computational complexity.

int my_abs(int x) {
return x < 0 ? (-x)-1 : x;
}
int fun(int* a, int n) {
for(int i = 0; i

Dont know if this works but...

If I sum all the unique numbers of the array O(n)
then I can lookup a precomputed table which tells me what number is missing O(1). This requires O(n) memory

void Main()
{
var inputs = new []
{
new [] { 3, 0, 1 },
new [] { 9, 6, 4, 2, 3, 5, 7, 0, 1 },
};
foreach (var input in inputs)
Console.WriteLine(gauss(input.Length) - input.Sum());
}

int gauss(int n) => n * (n + 1) / 2;

cute.

that's the same as
data = [9, 6, 4, 2, 3, 5, 7, 0, 1]
print(set(range(min(data), max(data) + 1))-set(data))

>passing arrays by value
bruh just use std::span

huh?

template
auto solve(std::array array) -> std::optional
{
std::vector bools(N + 1, false);
for (int n : array) {
bools[n] = true;
}
for (int i{}; i

>c++
nope

ok, i think im going math then, boyos. Probably math/stats, too. Stats is so important. I like it more anyway, I'll figure out employability later, but any tips on how to prove I know undergrad cs stuff? Maybe supplement degree with some online school crap or what?

sirs, how i get good at the oop programming?

i doubt this run linearly.
min()
max()
range()
difference()

My GF is teaching me OCaml

tnx m8

Attached: funny-pug-dog-man-hands-showing-thimbs-up-checkered-shirt-pointing-you-over-grey-background-69878311 (240x160, 10K)

It's neither O(n) runtime nor O(1) memory.

It don't, but it can return any set of numbers missing, not just one. Flexibility at the cost of speed.

>flexibility
never do what they don't ask

What makes Javscript so popular and in demand /dpt/?

Attached: thinking.jpg (881x356, 29K)

ok, my bit about jumping was bullshit. this is based around 's idea
expSum n = (n * (n + 1)) `div` 2

totMax = foldr (\x (total, maxm) -> (total + x, maxm `max` x)) (0, 0)

missing xs = if total == expTot then maximum + 1 else expTot - total
where
(total, maximum) = totMax xs
expTot = expSum maximum

the only O(n) bit is calculating the total and maximum (at once)

the web

You are not my boss

>waste time on "flexibility"
>miss deadline
>contractee fucks you in the ass
:D

webshits, wrong thread.

so once you have the total and maximum, you just compare it to the expected total for that maximum (n(n+1)/2, n is maximum)
if it's the same then it has to be n+1 missing
otherwise it's the difference between the total and expected total

what the fuck? some computers reverse the order of bits? that is so retarded i just wasted 5 fucking hours figuring out why the number i sent was not the one i recieved, and it turns out that for some retarded random reason the other device just reverses the byte order

generic?

Some WASM testing with 《RUST yeah sorry cop boys

>implying javascript is web

how does this detect if 0 is missing?

little endian and big endian

Attached: 8nRqoXW.jpg.png (800x729, 48K)

shit
add a third state for "has zero been detected", if that's false then 0 is missing, otherwise the normal stuff

function missing(arr) {
var sum = 0
var targetSum = 0

for (var i = 0; i

in JS this is just
const solve = array => {
const { length } = array;
const sum = length * (length + 1) >> 1;
return sum - array.reduce((a, b) => a + b);
};

expSum n = (n * (n + 1)) `div` 2

totMaxZero = foldr (\x (total, maxm, zero) -> (total + x, maxm `max` x, zero || (x == 0))) (0, 0, False)

missing xs = if zero then (if total == expTot then maximum + 1 else expTot - total) else 0
where
(total, maximum, zero) = totMaxZero xs
expTot = expSum maximum

fixed version.

>const { length } = array
lol what
why not use array.length?

>reduce()
js don't have sum()?

totMaxZero is prettier (and probably more efficient and performant) using the foldl package
totMaxZero = fold ((,,) L.sum L.maximum L.elem 0)

what langfu is this?

Haskell

haskell

here's my JS abomonation
missing = (arr) => ( (arr.length+1)*arr.length/2 - arr.reduce((i,j)=>i+j) )

(algorithm executing at actual speed)

Attached: dij4.gif (574x481, 1.75M)

Nice visualisation

reduce is more flexible and arrays tend to be for complex types more often than not

>sum += arr[i] || 0
what is this for?
why not sum += arr[i] ?

I bet you like cpp

Because it's for faggots

sepplesfags and rustfags are like peas in a pod

Rustfags are infinitely more insufferable.

modern cpp is acutally pretty

Lisp is the most powerful programming language.

it's as ugly as fucking rust

You have a scat fetish.

i decided that i wanted to make a real time streaming framework in go
how long until i give up and cut myself in the bathroom?

I'm trying to learn to use memoize. Why does not dpt work as nicely as noob-dpt?

(def dpt
(memoize (slurp "boards.4channel.org/g/thread/71981259"))

dpt;; => #function[clojure.core/memoize/fn--6862]

noob-dpt ;; => "

it'll probably only take like 30 lines of code then

what do you mean by nicely?

noob-dpt outputs the page html as expected, but dpt just gives me #function and so on.
How do I get the saved html?

I know jackall about lisp but I have a feeling this should be
(def memoized-slurp
(memoize slurp))

(def dpt
(memoized-slurp "

you assigned to dpt a memoized function. you assigned to noob-dpt the result of calling slurp. apples and oranges essentially.
to get the value, call dpt like a function e.g.
(dpt)

How would I write a mySQL constraint checking to make sure that the values of one column are not present in another column in a separate table?

Impressive that you can just figure that out without knowing anything about lisp, works perfectly!

Like so? (def dpt
(memoize (slurp "

What thinkpad should I get as a secondary computer to travel to school/work with? What specs are needed to just werk smoothly enough?

thinkpads are just chinkshit

do not pay the lenovo tax

use triggers?

(defun missing (numlist)
(let ((size (length numlist)))
(loop for x from 0 upto size
do (if (not (find x numlist)) (return x)))))

oh, i'm retarded, is correct

sir
>Your algorithm should run in linear run time complexity

O(n^2)

>What thinkpad should I get as a secondary computer to travel to school/work with? What specs are needed to just werk smoothly enough?

I think you have to provide more information.
What level are you on?
What editor are you using?
What languages do you code in?
How much do you code?

and so on

what do you recommend for 300 euro then

I just use visual studio, visual studio code and netbeans for java mostly on my w10 gaymin pc.
Im only a student idk what enviornment the work Ill do will be in. This second machine will prob have a linux distro tho.

please do the needful

can someone explain to me what am i doing wrong

Attached: i think im dumb.png (801x713, 33K)

>>> def lmao():
... global a = input('lol')
File "", line 2
global a = input('lol')
^
SyntaxError: invalid syntax
>>> def lmao():
... global a
... a = input('sdf')
... return a
...
>>>

you declare globals separately it seems global var
var = ...

>Konrad
the fuk