/dpt/ - Daily Programming Thread

Old thread: Lisp is the most powerful programming language.
What are you working on, Jow Forums?

Attached: lisp.png (2880x1800, 562K)

Other urls found in this thread:

fstarlang.github.io/lowstar/html/Introduction.html
en.wikipedia.org/wiki/Sentinel_value
en.wikipedia.org/wiki/Version_control
twitter.com/AnonBabble

First for erlang

Attached: 1560693105348.jpg (1152x1152, 794K)

{xth | x in 1..5} for vulkan triangles

Attached: yesh.jpg (911x636, 52K)

get better error messages

Fuck off Jean

better not be using SFML, SDL, or GLFW

92
of course not

99
prove it

>9.5 MB
for one gay triangle?

Attached: a523c90df954c60bb327dfac20b65022.jpg (754x721, 63K)

9th for OS dev in Coq

bth for aircraft software written by outsourced indians in C

Some one post some programming challenges so we can compare our edic.. I mean code.. God the last dpt was so boring
Pic unrelated

Attached: 1553282423922.jpg (1080x1080, 91K)

Unironically F*
fstarlang.github.io/lowstar/html/Introduction.html

Lisp is hampered by it's syntax but mainly it's code functions are too minimal and poorly named. It's a fun toy though.

once you use lisp syntax you never want to go back, except maybe to ML syntax.

just change the syntax

syntax doesn't matter
t. employed c++ chad

Lisp syntax is the best part though. It's the only language with good metaprogramming.
You can also name the functions differently if you want.

Until you have to debug your first ((((()))))((())))(())))))))) error because you fucked up a paren

Indentation + editor support
They're still too noisy imo, but I don't get the argument that they're actively bothersome

you sound like someone who hasn't debugged lisp code

Given an array of size n, find the majority element. The majority element is the element that appears more than n/2 times.

e.g
Input: [3,2,3]
Output: 3

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

what is your specification for more than one majority?

what is there is no majority?

print no majority

print the smallest

Any good resources/frameworks on developing a distributed ledger type system? I can't search for it because all I get is Blockchain shit, and I don't need that since there will still be a central server and authentication. I just need a system that allows multiple people to create/edit/delete diffirent types of documents even when offline and allow them to sync when they go online again, along with handeling any conflicts. Asking here because this is too advance for /wdg/.

>distributed ledger type system
so a database?

actually i didn't read the sentence before your code snippet so nevermind

Hey Anone~ How about we... learn JavaScript together... just you and me?

Attached: 5394eeae36c0defa10efa8e0a6eecefe.jpg (1365x2048, 349K)

>n a elements
>Lol what happens when you have more than one group of n/2+1 elements in it!
Learn math

about half goes into the vulkan instance and the other half the logical device
can't do anything bout that boss

Attached: 1562423520372.jpg (750x600, 69K)

no

easy, just use the quicksort trick to find the median and then check that it actually occurs more than n/2 times. O(n)

#define HASHSIZE 101
static struct nlist *hashtab[HASHSIZE]; /* pointer table */
Does this mean its allocating 101 entries to the table or the linked list?

Not really, but the back end will be a database.

>a block chain isn't a database
lol

read up on paxos

wrong pic

Attached: Capture.jpg (715x42, 8K)

>iron curtain
NEIN NEIN NEIN

Just because something is something else doesn't mean it's the same thing, you are a retard, but retards arnt you.

prime := prime_bigger_than(n)
hasmap := [[]; prime] #array of arrays
for v in Input:
mod := v % prime
if hashmap.has(mod):
if hashmap[mod].has(v):
return v
hashmap[mod].push(v)

forget the first if statement tho

(define (majority-element l)
(let ((tbl (make-hash-table 1024))
(len 0))
(for-each (lambda (v)
(hash-set! tbl v (1+ (hash-ref tbl v 0)))
(set! len (1+ len)))
l)
(car (hash-fold (lambda (k v acc)
(if (and (> v (cdr acc)) (> v (/ len 2)))
(cons k v) acc))
(cons 'none 0)
tbl))))

why even bother with let forms when you just have define?

now do it in O(1) space

from collections import Counter
Counter(l).most_common(1)[0]

>since there will still be a central server and authentication
Then stop searching "distributed"; it doesn't apply in your case. You just want client/server architecture.

>reading comprehension

Ok!
What should we start with?

Why haven't you embraced Almost Always Auto yet, /dpt/?

Attached: 1535056135136.png (644x251, 31K)

I just noticed that I could just stop when I find an element with a count greater than half
(define (majority-element l)
(let ((tbl (make-hash-table 1024))
(len 0))
(for-each (lambda (v)
(hash-set! tbl v (1+ (hash-ref tbl v 0)))
(set! len (1+ len)))
l)
(call/cc (lambda (return)
(hash-for-each (lambda (k v)
(if (> v (/ len 2)) (return k)))
tbl)
'none))))

Does anyone know what in the world CLRS are talking about when they mention a "sentience" card for MergeSort? Lines 8 & 9 in the Merge function specifically. I get that they are the end of the left and right piles but what do they mean by sentience?

Attached: mergewtf.png (409x328, 18K)

do you mean sentinel?

sentinel*

Yes, mind slip there.

So what do you call it them? Client server is obviously too broad for it.

en.wikipedia.org/wiki/Sentinel_value

Are there any general purpose languages that use R syntax? I love it.

en.wikipedia.org/wiki/Version_control
Seems to be what you want.

>first source is TAOCP
Should I take the red pill and read it?

Have you ever heard of the game 24? It's usually used in youth math classes to train kids on basic arithmetic. The games goes: given 4 integers greater than 2 and less than 13, find a way to use all four numbers and addition, subtraction, multiplication, and division to get the result of 24. The majority of combinations are valid. Find all the invalid combinations (or the number of them).

[~]$ python
Python 3.7.3 (default, May 11 2019, 00:38:04)
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>>

Attached: 1560675173181.jpg (1031x876, 145K)

There is A LOT, and it can be pretty dry, but it is excellent. Read the first chapter then you can piece-meal the rest as you are interested. I really hope he finishes 4 before he kicks the bucket.

it looks very gay
you are likely to have the gay user

>it's real

Attached: wizard_domain.webm (480x480, 2.54M)

>it can be pretty dry
The dryer it is, the slower I have to read because it usually means the work is pretty dense. I've already spent 3 sessions just reading chapter 2 of CLRS alone. I wonder how long it'll take me to *properly* read TAOCP. Maybe I should start with SICP first.

>Explicit is better than implicit.
>dynamic typing
what did Tim mean by this?

def median(arr):
def partition(lo, hi):
if hi len(arr) // 2:
return arr[m]
return "no majority"

>>> quit()

how the fuck is it always the tech field that attracts these people

Attached: file.png (1355x627, 1.31M)

SICP is not worth the read is you are already a competent programmer.

So I should just skip over it then? I guess I'd define myself as a competent programmer (I work professionally as a softwar eengineer).

The handy "should i read SICP guide"
You want to learn Scheme -> yes
You don't want to learn Scheme -> no

So SICP is basically a "learn programming with scheme" kind of book? What is TAOCP then?

>not enough hours in the day to do what i need to do
>these people spend time wondering what gender they are and putting on makeup

>What is TAOCP then?
The same only with MIPS assembly :^)

it's not a beginner's book no.
It's more of a brush-up/exercise for intermediate programmers who'd like to try Scheme and have a structured book to apply it with.
Haven't read TAOCP so i can't give an opinion.

>What is TAOCP then?
something to display on your bookshelf to show how leet you are

>It's more of a brush-up/exercise for intermediate programmers
If you're coming into fresh as a MIT student, particularly with a math background, you would've done ok. It wasn't really meant for mass public consumption.

Here's an O(n) solution which works on any type of input.

def majority(xs):
# xs := list of elements
# a := majority element candidate
# n := majority element count
# returns: the majority element a if it exists, else None
a = ''
n = 0
# Find majority candidate, O(len(xs))
for x in xs:
if a == '':
a = x
n = 1
elif a == x:
n = n + 1
elif a != x and n > 1:
n = n - 1
else: # a != x and n < 1
a = ''
n = 0

# Confirm candidate is true majority, O(len(xs)
if xs.count(a) > len(xs) / 2:
return a
else:
return None

what if the list contains empty strings

Don't like python but this is pretty sexy

That is true. I should replace '' with None. I could also check if the counter is greater than half the max size of the list and break early.

TAOCP is a reference text for numerous important algorithms in computer science. It also includes practice problems to use those algorithms and force the user to improve their own knowledge of computer science.

This is pretty clever.

idk, lists can contain None too
I think you could change it to something this:
# handle x == []
a = xs[0]
n = 1
# Find majority candidate, O(len(xs))
for x in xs[1:]:
if a == x:
n = n + 1
elif a != x and n > 1:
n = n - 1
else: # a != x and n < 1
a = x
n = 1

should be xs == [] in the first comment

Because it makes code far less readable.

It's too verbose. What you need is a macro.
#define a auto


Just don't name anything a.

i just wrote a sudoku solver. please tell me im not worthless

I hope you'll find love, user.

good job, user. i'm proud of ya.

Attached: congratulations.jpg (1569x564, 726K)

i love you, my fellow humanoid

>i love you, my fellow humanoid
Y-yes, I am a humanoid. Thank you fellow human.

Attached: oct.gif (480x430, 2.81M)

What IDE do you use for C/C++?
Tried using VSCode for it but I don't know if it can properly index files/libraries and debugging doesn't seem great. Maybe I'm not doing it right.

Also can't find a torrent for pic related for Mac so I'm fucked at the moment.

Attached: 1880219_0[1].jpg (630x630, 34K)

nvim + ycm + clangd + ale + clangtidy + clangfmt

how do I program my own text editor?

Attached: 1562408625863.jpg (620x640, 33K)

Install emacs

get your eyes checked m8, this isn't your search engine tab.

i already use emacs
i want to write my own tools from now on
fuck off dweeb lmao

>load file into buffer
>manipulate buffer
>write buffer to file

Attached: 1562305550594.jpg (907x778, 72K)