/dpt/ - Daily Programming Thread

Functional edition

Previous thread: Resources͟:
Functional Programming Language Concepts
>Structure and Interpretation of Computer Programs
>mitpress.mit.edu/sites/default/files/sicp/full-text/book/book.html

Erlang
>Learn You Some Erlang for Great Good
>learnyousomeerlang.com/content

Haskell
>Learn A Haskell for Great Good
>learnyouahaskell.com/chapters
>Real World Haskell
>book.realworldhaskell.org/read/

Ocaml
>Real World OCaml
>v1.realworldocaml.org/v1/en/html/index.html

What are you working on Jow Forums?

Attached: home_dpt.png (581x1133, 616K)

Other urls found in this thread:

paralleluniverse.co/quasar/
en.wikipedia.org/wiki/H-index
en.wikipedia.org/wiki/Mercury_(programming_language)
twitter.com/SFWRedditVideos

Can I be advertised in the OP too next time?

Attached: 1547875971957.jpg (1052x1342, 402K)

OwO

Rate solution to Project Euler #112
(defun increasingp (n)
(let ((n (write-to-string n)))
(apply ' r w)
(setf e c)
(go again))
(t (return c)))) ; => 1587000

Cute girl

please for the love of god someone help me i'm pulling my hair out i cannot figure out what the fuck i'm doing wrong

Attached: popsicle.png (337x302, 71K)

OK: increasingp decreasingp bouncyp
OK in isolation: %bouncy
WTF fuck this lang: the rest
bad: looks like you're recalculating bouncyp over and over again for the same ranges of numbers

I can't tell if this is ironic

I honestly just want Erlang's lightweight threads and message passing model combined with a normal statically typed language that's multi-paradigm and not just functional only.

Attached: 1529978869214.jpg (821x869, 98K)

yeah

I could use meoization, but that's too much.

Lisp is the most powerful programming language.

Go? It's a bit shit but does what you need.

Maybe it's Unity's fault?

I’m running a simulation through a genetic algorithm to tune some parameters and I’m finding that the same parameters to the simulation sometimes leads to different fitness levels.
The simulation itself is deterministic. Am I somehow running into the fact that Intel chips aren’t 100% reliable for floating point operations?

Ada's concurrency resembles a static Erlang, with rendezvouz instead of message boxes so that you can control how long the sending thread is blocked for, with message-passing resembling object-oriented function calls.
I know that sounds nothing at all like Erlang, but it looks/feels a lot like Erlang.
No OTP at all though. No shell. No operating system.

I dunno about this stuff but wouldn't the while loop possibly call update a few times and then render only once resulting in a skip like you see?

you could also use a running calculation, with no need for even memoized recalcs.

You're right, I should've just done a loop to infinity,
it seems faster to calculate, let me try that.

paralleluniverse.co/quasar/
For JVM languages.

Do you autists program every single day? There are days where I don't want to do it at all. It would probably be different if someone paid me, but still

>For Pajeet languages
no thanks

The only shame is Ada Tasks are kernel threads so not that lightweight. Ada 202x is getting lightweight threading though but I think it's much more restrictive from what I've read.

GET FUCKED DICKHEAD

I'M NOT FUCKING USING UNITY

THAT'S WHAT THE LERP FUNCTION IS FOR

Attached: 1470000499748.png (374x208, 17K)

>multi-paradigm
Why did you have to ruin your comfypost

>There are days where I don't want to do it at all
that's what /dpt/ is for.

Does anyone know what this is seg-faulting?

chess::chess(){

//SPACE_COUNT -- FOR WHILE LOOP CONTROL; COUNTS HOW MANY BAORD SPACES MADE
int space_count = 1;
char x = 'A'; char y = 0;

board_node *first_space = new board_node();
board_node *current_space;
current_space = first_space;
// SPWANS BOARD
while(space_count < 65){
current_space->set_next(new board_node());
current_space = current_space->next();
space_count++;
}

current_space = first_space;

while(current_space != NULL){
current_space->set_coordinate(x,y);
current_space = current_space->next();
x++;
if (x=='I') { x = 'A'; y++; }
}

}

void chess::test(){

board_node *current = first_space;
int count = 0;

while(current != NULL){
cout

What paradigm would you want it to be if functional isn't an option?

; caught STYLE-WARNING:
; undefined function: IOTA

bad: not SBCL

Just "regular" procedural. I haven't used it, but Rust seems to get it right.

Just did it, it worked but its actually slower than the binary search method.

(defun increasingp (n)
(apply '

>new
functional declarative logical useless message-passing compile-time natural-lang eso macro-oriented

(ql:quickload 'alexandria)
(require 'alexandria)
(use-package 'alexandria)

Rust is multi-paradigm tho. C would be more like "regular" simple procedural.

what's wrong with using new?

Erlang, like Emacs, is basically a self contained operating system designed specifically for that. It's not simple to bring that to other languages.

Threadly programing challenge: we're going to compute the h-index of professors! See pic related for a description or Wikipedia for additional info.


en.wikipedia.org/wiki/H-index

>For example, if we have a researcher with 5 publications A, B, C, D, and E with 10, 8, 5, 4, and 3 citations, respectively, the h-index is equal to 4 because the 4th publication has 4 citations and the 5th has only 3. In contrast, if the same publications have 25, 8, 5, 3, and 3 citations, then the index is 3 because the fourth paper has only 3 citations.

Attached: Screen Shot 2019-08-12 at 5.09.46 PM.png (1450x760, 176K)

>Rust is multi-paradigm tho
Yes, so my point is that I would like functional as far as possible and procedural where needed.
Maximum comfy is functional only

Actually, to be fair, I did start from 150000, not from 1

>try to get into c#
>operator overloading
Fuck it.

Attached: scared.jpg (496x224, 23K)

just a static function with `operator` modifer and a symbol as a name.

>not liking overloading
>not wanting map to work with lists, strings, vector, etc

well too bad enjoy your choppy game

come on
there's gotta be something i'm doing wrong
can seriously no one figure it out?

Attached: 1446694124180.gif (500x284, 441K)

Hint: there's a solution in O(n * log(n)) but its possible to do in O(n) speed.

>tfw only now find out that Erlang's creator is dead
i can't believe i missed it

learn to debug. log every operation to see what's happening.

if you don't find a solution change the strategy

only you can solve this issue and you'll learn a great deal if you manage to fix it

>“I mean, they say you die twice. One time when you stop breathing and a second time, a bit later on, when somebody says your name for the last time.

I hate how damned finnicky project euler problems are. don't get the right answer with this:
:- module bouncy.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int, float.

main(!IO) :-
io.print_line(find_bouncy_pct(0.99): int, !IO).

:- pred increasing(int::in) is semidet.
increasing(N) :-
(
N < 10
;
A = N `mod` 10, B = Rest `mod` 10, Rest = N / 10,
B =< A,
increasing(Rest)
).

:- pred decreasing(int::in) is semidet.
decreasing(N) :-
(
N < 10
;
A = N `mod` 10, B = Rest `mod` 10, Rest = N / 10,
A =< B,
decreasing(Rest)
).

:- pred bouncy(int::in) is semidet.
bouncy(N) :- not (increasing(N) ; decreasing(N)).

:- func find_bouncy_pct(float) = int.
find_bouncy_pct(Pct) = find_bouncy_pct(Pct, 10, 0, 9, 9).

:- import_module string, list.
:- func find_bouncy_pct(float, int, int, int, int) = int.
find_bouncy_pct(Pct, N, Bouncy0, Inc0, Dec0) = R :-
( if increasing(N) then
Bouncy = Bouncy0, Inc = Inc0 + 1, Dec = Dec0
else if decreasing(N) then
Bouncy = Bouncy0, Inc = Inc0, Dec = Dec0 + 1
else
Bouncy = Bouncy0 + 1, Inc = Inc0, Dec = Dec0
),
( if float(Bouncy) / float(Inc + Dec + Bouncy) >= Pct then
R = N
else
R = find_bouncy_pct(Pct, N + 1, Bouncy, Inc, Dec)
).

cringe

That's Haskell?

Live, Laugh, Love

nah

en.wikipedia.org/wiki/Mercury_(programming_language)

Looks like a Prologesque language. Not like Haskell in the slightest.

see

So I bullshitted my first 2 programming fundamentals in C++ classes a few years back.

Is it possible for me to catch back up within the span of a semester? Wanna get a Bachelor's, but I'm scared of being too behind and fucking up the subsequent classes...

is this efficient as fuck?
how long does it take to find the answer?

>what's wrong with using new?
it's your problem sherlock

Use Scala. It has Akka, which is inspired by Erlang.

>Scala
might as well just use Erlang at that point.

it's just a brute force loop starting at 10 and counting up.
it gets an answer of 1587891 (which is wrong) in 147 ms.

How else should I do it then?

God I hate floats

But it fits everything that was specified in the OP.

Scala is a functional language. You may as well keep using Erlang.

gets the correct answer with this definition of find_bouncy_pct/1:
find_bouncy_pct(Pct) = find_bouncy_pct(Pct, 0, 0, 0, 0).
i.e., start at zero, and count zero. fuck off Euler.

Scala is also OOP which fits the multi paradigm aspect of the OP.

www.sololearn.com/Course/CPlusPlus/

three words: posits

post tits

Stop using deltaTime to move objects. Move them as if they were on a fixed framerate then use deltaTime to compensate slow frames by running the game logic more than once.

Attached: maxresdefault.jpg (1280x720, 71K)

I disagree partially. His game logic should be running at a fixed rate in the background. The renderer should be a separate system entirely that infers minimally with the game logic's resources.

are you initializing the default values of ->next() correctly?

Lol your time step is mega fucking tarded dude. I can see the stuttering built right in to your while{} statements. Try something different.

why do you have 2 while loop?

-while (running )
--while (accumulator)
----update logic
-render

whats happening is probably update logic moving the box too much
idk why the FUK u did it that way, /v/ermin

again, i have dont your source code, but why are u using multiple delta times? have a single one so they are all the same

Are you sure it's not just caused by rounding of pixel positions?

I think maybe the second while loop, the end of the list is not set to null, so it tries to keep going.

it's 2019
you're supposed to use smart pointers, std::make_unique and std::make_shared and not raw new and delete

Anyone have any ideas as to why my text surface isn't blending properly here? The code looks like this:
SDL_Surface *src = TTF_RenderText_Blended(font, str, color);
// set up rectangles...
SDL_BlitSurface(src, &src_rect, dst, &dst_rect);

'dst' is an 8-bit indexed bitmap, if that makes any difference.
Using 'TTF_RenderText_Solid' works fine, but looks like ass.

Attached: alpha1.png (640x400, 229K)

It looks like I did?
class board_node{

public:
board_node(){
next_link = NULL;
previous_link = NULL;
}

char get_coordinate() { return x_coordinate, y_coordinate; }
board_node *previous() { return previous_link; }
board_node *next(){ return next_link; }
void set_next(board_node *nxt) { next_link = nxt; }
void set_coordinate(char x, char y) { x_coordinate = x; y_coordinate = y;}

char get_xcoordinate(){ return x_coordinate; }
char get_ycoordinate(){ return y_coordinate; }

private:
enum piece { empty, w_pawn, w_bishop, w_knight, w_rook, w_queen, w_king,
b_pawn, b_bishop, b_knight, b_rook, q_queen, b_king };
bool white;
char x_coordinate, y_coordinate;
board_node *previous_link, *next_link;
};

where exactly did it crash?

But in the node constructor next_link gets set to NULL automatically?

When test gets called, it outputs the first coordinate than seg-faults.

Do any of you know about signature scanning? Ive got the address and signature im looking for. I can read the memory addy and get the value but if I try to find the addy with a sig scan its not finding it.

the `first_space` in `test` is not the same one as in the constructor
you likely have a member variable with the same name
and the one inside chess() ctor shadowed that one.
hence, the one in your test is not updated.

>zoomer_case
cringe.

So you think I should just make a bunch of filler programs to get a higher grasp of understanding?

Actually, now that I think about it it doesn't really make sense to blend ARGB onto an indexed bitmap because the source surface doesn't have a palette. I guess SDL is trying to map the ARGB pixels to the destination palette and doing a really poor job of it.

I want to build a virtual desktop application on windows 7, is this possible or is this not in the API?

Use lisp-case.

Python problem I'm stuck on:

Write the function longestDigitRun(n) that takes a possibly-negative int value n and returns the digit that has the longest consecutive run, or the smallest such digit if there is a tie. So, longestDigitRun(117773732) returns 7 (because there is a run of 3 consecutive 7's), as does longestDigitRun(-677886).

Only allowed to use for and while loops, no arrays.

schizophrenic_case-masterRace

that's easy as fuck, buddy.
just think about it.

Thanks senpai. My schedule got fucked up last semester and I didn't take any c++ classes hence I haven't done this in 8 months and I totally forgot what 'going out of scope' was. I'm doing this mini side-project to get caught back to speed. Also how would I call game.test() from main if I need to send *first_space as an argument?

I mean I can solve it if I define 10 different variables, one for each digit between 0-9, but I don't want to do that as it seems inelegant.

The way brain thinks about it is like this:
def longestDigitRun(n):
for i in range(1, digitCount(n) + 1): # digitCount defined previously
if (n%10 == (n//10)%10):
dynamicallyCreatedVariable[x] += 1 # where x = n%10, the current digit
n //= 10
return largestDynamicallyCreatedVariable


i have a feeling my psuedo code is gonna get fucked up, how do i keep indents?

Trying to figure out how to parse json iteratively in nim

same way you parse it recursively but with a stack

You stop what you're doing and use yacc and lex like a normal human being.

declare a member variable that will store the first_node, assign it with the first node you created in the constructor and NEVER modify it.
so you can call it from anywhere within the object