/dpt/ - Daily Programming Thread

Old thread: What are you working on, Sup Forums?

Other urls found in this thread:

pastebin.com/Y7CzrqQ9
twitter.com/NSFWRedditImage

How the hell does this work? REE, I have been failing to do SICP exercises 3.23 for hours because of stupid shit like this. The concept behind the question is easy (double sided queues).

(define x (cons 1 2))
(define r (cons 1 0))
(set-car! r x)
(set-cdr! r x)
r = ((1 . 2) 1 . 2)
(set! x 0)
r = ((1 . 2) 1 . 2)

I would have expected r = (0 0)

And also

(define x (cons 1 2))
(define r (cons 1 0))
(set-car! r x)
(set-cdr! r (car r))
r = ((1 . 2) 1 . 2)
(set! x 0)
r = ((1 . 2) 1 . 2)
(set-car! r 0)
r = (0 1 . 2)

I would have expected r = (0 0) when x changed to 0. And eve after that, I would have expected r = (0 0).

Guy trying to learn how to sort here. I implemented pretty much exactly what was said in the other thread and still no bingo. Can anyone see anything wrong with this?

for i in range(0, len(list_to_sort) - 1):
for j in range(0, len(list_to_sort) - 1 - i):
if list_to_sort[j] == 0:
list_to_sort[j], list_to_sort[j+1] = list_to_sort[j+1], list_to_sort[j]
elif list_to_sort[j] > list_to_sort[j+1]:
list_to_sort[j], list_to_sort[j+1] = list_to_sort[j+1], list_to_sort[j]
return list_to_sort

Actually, you need to make sure that the argument being compared to in the elif bit isn't zero.
elif list_to_sort[j+1] != 0 and list_to_sort[j] > list_to_sort[j+1]:

Not him but if if list_to_sort == 0 then the elif statement isn't executed.

The first if deals with the "left" argument (j). That check deals with the "right" argument (j+1), so that when some other value is being compared against zero, it won't get swapped.

Guy sorting here, makes sense, cheers mate.

Does figuring out things like that come easier the more you program?

I just tested this and it doesn't work. It just sorts in complete ascending order in Python3.

>(set! x 0)
The variable is a mutable cell in itself. You are making x point to 0, you aren't magically transforming the cons cell into an integer. That never happens in Scheme. Scrap your whole code off and try again.

list_to_sort = [20, 7, 9 ,15, 0, 2, 0, 16, 5]

for i in range(0, len(list_to_sort) - 1):
for j in range(0, len(list_to_sort) - 1 - i):
if list_to_sort[j] == 0:
list_to_sort[j], list_to_sort[j+1] = list_to_sort[j+1], list_to_sort[j]
elif list_to_sort[j+1] != 0 and list_to_sort[j] > list_to_sort[j+1]:
list_to_sort[j], list_to_sort[j+1] = list_to_sort[j+1], list_to_sort[j]

print(list_to_sort)
[2, 5, 7, 9, 15, 16, 20, 0, 0]
werks for me.

Is Rust a dialect of C?

reposting from last thread

I'm trying to cut out the individual panels of a comic strip, I've already detected the panels themselves using openCV but how do i go about cutting them out?

No

Rust is the arrogant and naive grand-son.

Yeah a list of integers works for me too. My bad.

Strange though, I just opened a program that had a list of dictionaries that I sort by value of a specific key and it doesn't push the zeros to the back on that list.

ImageMagick

Rust is the son of C that wants to be a girl.

More like the daughter that identifies as black gay man.

def sort(dict_list): #Bubble sort
for i in range(0, len(dict_list) - 1):
for j in range(0, len(dict_list) - 1 - i):
if dict_list[j]['happy_ratio'] == 0:
dict_list[j]['happy_ratio'], dict_list[j+1]['happy_ratio'] = dict_list[j+1]['happy_ratio'], dict_list[j]['happy_ratio']
elif dict_list[j+1]['happy_ratio'] != 0 and dict_list[j]['happy_ratio'] > dict_list[j+1]['happy_ratio']:
dict_list[j]['happy_ratio'], dict_list[j+1]['happy_ratio'] = dict_list[j+1]['happy_ratio'], dict_list[j]['happy_ratio']
return dict_list

[{'route_number': '12', 'happy_ratio': '4'}, {'route_number': '235', 'happy_ratio': '0'}, {'route_number': '123', 'happy_ratio': '7'}, {'route_number': '567', 'happy_ratio': '3'}, {'route_number': '459', 'happy_ratio': '1'}, {'route_number': '555', 'happy_ratio': '6'}, {'route_number': '666', 'happy_ratio': '0'}, {'route_number': '354', 'happy_ratio': '5'}]



[{'route_number': '12', 'happy_ratio': '0'}, {'route_number': '235', 'happy_ratio': '0'}, {'route_number': '123', 'happy_ratio': '1'}, {'route_number': '567', 'happy_ratio': '3'}, {'route_number': '459', 'happy_ratio': '4'}, {'route_number': '555', 'happy_ratio': '5'}, {'route_number': '666', 'happy_ratio': '6'}, {'route_number': '354', 'happy_ratio': '7'}]

For reference if anyone else wants to run it.

Why do all these literally who languages have toolchains to create pc and android GUI applications?
>ec with ecere sdk
>pascal with lazarus
>d with DlangUI

and the good languages like Common Lisp and Ocaml at best have bindings to gtk+ and maybe unmaintained bindings to QT?

>good languages like Common Lisp and Ocaml

What about Clojure?

Yeah, what about it?
It's not even lisp.

>It's not even lisp.
delet this

Convert them to floats and it works.

why do you have two if statements that do exactly the same thing?

why are you even handling zero specially?

You can build a GUI and use lots of parentheses.

>use lots of parentheses.
No you can't because clojure forces you to use [] and {} everywhere.

>It's not even lisp.
Which is a good thing. Sadly it's too much like Lisp so it's still fucking trash.

How can a language "force" you to do something?

Try to write function definition in clojure without using [].

I guess you can always use a macro to fix that.

How does this answer my question? Me trying to do it on my own already implies it wasn't forced.

You literally can't though because lol clojure

Can't do what? Write macros?

Well I think it's fair assumption that if you program you are going to write function definitions.
Having to use certain characters in that defition kind of forces you to use them.
Off course you could write a fucking transpiler like every hipster is doing it with javascript or program without functions but that's the kind of retardation that you would do, not me.

The lambda definitions uses them also and at that bind it becomes pretty impossible.

>Having to use certain characters in that defition kind of forces you to use them.
Nope. You are free to not use that piece of trash.

How would I go about implementing a function where whenever you right-clicked a tile on a grid it would change colour & not allow you to left-click it until you right-click it again in Java through using Swing

BTW here's the code for marking that tile.

public void mark(int row, int column) {
this.minefield[row][column].toggleMarked();

>The lambda definitions uses them also and at that bind it becomes pretty impossible.
Ok, so no Clojure. It's your best bet for proper library support.

Sold.

is
if dict_list[j]['happy_ratio'] == 0 or dict_list[j+1]['happy_ratio'] != 0 and dict_list[j]['happy_ratio'] > dict_list[j+1]['happy_ratio']:


Better?

My friend is studying CS and I want to learn programming so I get him to send me his assignments and I teach myself. They have to handle 0 in the assignment.

whats wrong with the obvious solution, making it so the left mouse click event handler does nothing if the tile is already marked?

Why does Lisp REPL highlight the letter d ?

i'm getting fkn pissed off over the lack of documentation and general reference material

how do i take sinc(t), or any function, and plot the frequency response, in
>mathematica

>mathematica
Use maxima or gnu octavia you tool

What Lisp? Sure you havent accidentally done a text search for "d" in your terminal emulator?

....

Do you want my D, user-sama?

I am trying to learn how to make tetris but i stuck at rotation part. Why my code doesn't work can somebody help me please ;_;

here is the code:

pastebin.com/Y7CzrqQ9

>inb4 fuck off gamedev
I am new and programing simple games really good for learning.

ok then how do i take sinc(t), or any function, and plot the frequency response, in
>maxima
or
>gnu octavia

common lisp
it actually happens in sublime / sublimeREPL

idk try this

public void rotateLeft(){
for(int i=0; i

actually its not the letter d, it's atoms called d

100% sincere question, i'm a complete noob who knows nothing 'bout programming.
Whats a smart start?
I'm a pretty fast learner so just rec me a language that's useful for making games.
t. /3/ fag who's starting to lwarn code

>I'm a pretty fast learner so just rec me a language that's useful for making games.
C# over Unity for a noob I guess

You're still gonna struggle if making games is your immediate goal

C++ and i'm dead ass serious don't listen to the neckbeards telling you to learn lisp or haskell or C or python or what the shit

>noob
>C++
>probably never gonna study CS, just tutorials on the net
will crash and burn in less than three months

t. CS Student trying to make something on Ogre3D on the side and struggling

in python tkinter, how do i make the main window fill the entire screensize minus the taskbar?
basically as large as a fullscreen but with the taskbar still visible plus the possibility for other application to appear over mine, like in fl studio

i know it's still a window mode, but i don't know how to tell tkinter "look, the taskbar has this height and you must take it in consideration when creating the root window"

Well my goal is vidya but what are some other worth while things to make, for practice that is

you just don't get it do you

go build a house with brick and mortar
start with little dog sheds then you'll soon be able to build the new World Trade Center

start with some simple opengl scenes like start with a triangle and then a rotating cube etc

Unity will handle that

you'd learn next to nothing

try making a program print hello world before vidya

Why are you so defensive?
If there's something wrong enlighten me on it. I actually want to learn this shit so give me all the advice you got

there's nothing wrong with it they're just newfag brainlets who think game engine and graphics programming is some gargantuan impossible task (for them)

Wow thank you user :3 So what exactly my mistake? I need to work on this topic more.

>I actually want to learn this shit
you don't know that
you want to make games, it's different

>so give me all the advice you got
not gonna spoonfeed you, brainlet babby, the advice was : Unity engine + C#

now take an intro to programming with C# course, once you master the language and programming basics, learn Unity

fuck off now

>newfag brainlets who think game engine and graphics programming is some gargantuan impossible task (for them)
post github faggot

you were setting y to the latest value of x after you had already set x to -y when you wanted the old value of x instead

the unity engine isn't some magic bullet, there is almost no one in who has a passable finished game and some of them have been at it for years

still better than Ogre or LibGDX for a beginner

I could advise him RPGMaker or GameMaker but he'd sperg out
>HURR I WANT TO LEARN THIS SHIT I CAN MAKE THE NEXT DARK SOULS x SKYRIM x DOOM5 x FF15 AAAA+ GAYME

Implementing solutions for differential equations of 1-4th order, currently of 1st. Im doing it with some weird mix of c++ and c... Is there c++ equivalent of fprintf and popen??

>Is there c++ equivalent of fprintf and popen
lol, wait till you find out what you can do with c++

use c functions

>HURR

Recursively define a function for x% compound interest on a principle investment of $y after z years

Not programming.

def compound(x, y, z) as double
if(z == 0) then
return (1 + x) * y
end if

return (1 + x) * compound(x, y, z -1)
end

see

I don't understand

>Recursively define a function
Don't you mean "define a function that uses recursion"?

That shitlang isn't programming.
No. A recursively defined function can be implemented as a loop.

That's true

Currently doing the exercises in this book for school. I hate this book.

What shitlang is it?

A shitlang which uses "def" and the ugly "==" for equality comparison.

How can I get good at algorithms?
I'm a fucking beginner but my homeworks are hard as fuck. I'm not even on undergrad CS course.

Pls help me with easy books

>How can I get good at algorithms?
At which algorithms? Your post makes no sense using the standard definition of "algorithm".

For python or any other language. How to solve problems more efficiently.
I'm just a dumb engineer, I use matlab too if it helps.

this book is pretty good

Just write some fucking algorithms.

>For python
You should be asking in some other thread. Python isn't related to programming.
>How to solve problems more efficiently.
This is too vague of a question. What problems do you want to solve?

Numerical analysis

Jesus fucking christ.
We can't learn for you. You have to do that shit yourself.
If you want help you need to provide a concrete problem a like of (pseudo)code you don't understand or a program that doesn't produce the desired result etc.

Then you should have said so right away. Hopefully someone here is familiar with it and can help you.

Kys yourself

Having to learn Java for second year of CompSci are there any good meme books that are Sup Forums approved?

>Kys
>meme

for java get this book. It has everything you need.

Thanks man

>Java
>computational mathematics
What did he mean by this?

lol that shit is too obscure you have to read math papers n shit no one is going to spoonfeed you anything non-trivial