/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

strawpoll.me/12023125
pastebin.com/DUTqcR3M
jsfiddle.net/vjLvwyy1/
twitter.com/SFWRedditVideos

Thank you for using an anime image!

can someone PLEASE explain me how this works?

ranking = sorted(d.items(), key=lambda value: value[1], reverse=True)

I'm an absolute beginner. I know that the sorted() function can sort a simple list, and that in this example, a list of tuples is passed in a descending order based on the value of the dictionary. But how does it work? I fail to understand how lambda works.

thanks!

Text editor poll continues
strawpoll.me/12023125

Minor fixes to my flash card game and added a bunch of decks.
It works really well for a toy program.

That is Python, btw

...

sorted can sort any kind of data structure, but for creating an order, you need to map the space of your structure to an orderable space (like real numbers). That's why you pass a function (that lambda).

this, and you can treat lambda expressions simply as anonymous functions with arguments given before colon in python

java

triggered...

...

how would i go about making a c function that given an int array and a "shifter", it would shift the elements of the array after the shifter pos to the left?

for example given the array { 1, 2, 3, 4, 5 } and the shifter 3, it would become { 4, 5, 1, 2, 3 }

C# is CUTE!

Finding optimal paths: Given initial and final position and velocity what direction of acceleration minimizes the time between the two points.

>Jaba but by Microsoft

shift n xs = take (length xs) $ drop n (xs ++ xs)

rewrite in C

it's less popular so Sup Forumstards can relate to it as the underdog

wut

How in the world would that work? Why not go to Haskell if you want something unpopular?

because some people want tool that's actually functional

Quick /dpt/, post feminine code in your favorite language!
I'll start:

use std::mem::transmute as crossdress;

struct Boy;
struct Girl;

fn main() {
let hime: Girl = unsafe { crossdress(Boy) };
}

This post speaks on more levels than you intended, methinks.

doesn't work

...

haskell is also popular in /dpt/

wtf is this shit

if someone is bored and wants to help, is it possible to do it without creating a second array in the function?

You need one (1) spare space in order to do that.

I'm a writing a mpd notification thing in Ruby using libnotify and mpc but I can't program for shit. What I made so far works fine, but my code and how I actually made work is probably bad and I can't tell because as I said, I can't code for shit.

pastebin.com/DUTqcR3M

Any tips on how to improve it? Also, I can't solve the notify-send cache thing.

That's where the "feminine" part comes in, I think.

X := X(Shift_Amount..X'Last) & X(X'First..Shift_Amount-1);

Call this function from your c program, senpai

...

so... should I learn c or c++? Is c++ really that hard?

How hard would it be to make my own music player? I'm not an experienced programmer.

loop through it using modular arithmetic for the array index

but for performance i would use a second array and memcpy

What do you want to do with the programming language?

Super easy with any modern language + GUI framework.

You could spin one up in WPF in a day or so for barebones functionality if you know C#.

i just want to make video games to play
i went to computer science because i wanted to program video games like crysis and blackops

Oh boy, you're in for a rude awakening.

You and the other 70% of dropout would-be programmers.

Start with C.

learn C++ it's what games use and it's not hard if you're not retarded, if you start with C you'll easily get stuck in a retarded neckbeard mindset and you'll never be able to use the more advanced C++ features probably

>What I made so far works fine
That's the most important thing: make it work.
Why did you choose Ruby instead of Bash?

well, i'm merely a beginner for now, I only know some thigs whith python.
I just wanna do simple programs (but still useful, mike browsers, text editors, simple classic games ...) for now, just to learn.
Maybe create an OS when I'm way more advanced but I could learn both by then.
I'm not interested in game making.

If you don't know C learn it.

wait, you're not me

in that case you could learn C

>computer science
Why did you think these words meant 'productive software developer'?

Just learning visual c# that's about it.

Might start working on a reader app/program soon but we'll see

Can we trade degrees?
Mine's a worthless games programming degree, and I'd rather go into CS

computer science isn't directly relevant for making games but especially for programming game engines and game dev tools it's almost required to have some sort of a compsci background

Using VBO with opengl/c++

Do I have create/compile a new fragment shader for every different color I want to use when drawing primitives?

>i went to computer science because i wanted to program video games like crysis and blackops
Is this the part where the lines between reality and fiction start blurring REALLY hard? I swear this is the "neo-typical CS freshman" description almost verbatim.

no, use attributes/uniforms/textures

tfw you're hijacked ;_;

im either too new or too dumb to understand what youre trying to tell me

so please just help me out and tell me why doesnt this work

void shift (int a[], int size, int shifter) {
int b[size];
int i; int j = 0;
for (i=shifter;i

>Why did you choose Ruby instead of Bash?
I'm way more used to ruby and wanted to deal with the actual thing instead of getting lost in what I wrote wrong. I could probably write it in bash later to get more used to bash.

I'm drawing lines..

No, I think this is a form of bait/satire.

a beginner should focus on learning proper algorithmic thinking, the more theory and math focused things, not hardware oriented stuff.
simple languages like python are good for this purpose.

Yes I will continue learning python as well, and now that i know it quite well (better than I implied actually) I thought it might be interesting to become more versatile

That's because you posted non-feminine code

My problem with your script is that it relies too much on the shell. This is common for Bash scripts, but not really for Ruby/Python stuff. Take this for example: `rm ~/.cover/*`. I'm sure Ruby has a nice way of removing all files in a directory instead of spawning a process that does it for your.

Is this Ada?

Fantastic language.

a combination yet-another-archive and way for me to view/search through threads over Gopher

alright im retarded i just had to do j = size - shifter before the 2nd loop ;_;

I work at a college and this is every CS student I meet.

When you ask questions like this you are opening yourself up to being trolled by people who use languages that can do index sliding.

Can you not fill the OP up with links to meme threads nobody posts in like the /fpt/ thread? Thanks.

Is anyone here familiar with gcc4ti? Is long long int declared as 64bit there?

Yes and agreed

There is a lot of way to find it. You can compile an application that print the value of sizeof (long long).

Sorry, I mis-formulated my question. What I meant to ask is if it's 64bit in every calculator, as I only have the 89 titanium to test.

jsfiddle.net/vjLvwyy1/

Think I finally understand what the sin, cos, and tan memes are used for in maths.

They let you find the length of a side of a triangle using one of the angles and one of the side lengths.

Can't remember being taught about it in school, haha.

I hate the calling everything a meme meme.

Is this a troll?

> Think I finally understand what the sin, cos, and tan memes are used for in maths.
You have to be at least 18 to visit this site.

>he fell for the "i hate the 'calling everything a meme' meme" meme

>he fell for the "'he fell for the "i hate the 'calling everything a meme' meme" meme'" meme

You're right. I'll write it in bash as it makes way more sense.

No, genuinely didn't know how to use sin, cos, and tan and I passed maths in school, must have just forgot about them.

Is anyone here good at recursion?

Input
>integer that represents desired sum
>list of integers
Output
>index n where first n elements of the list sum to less than desired sum, and n+1 sums to the desired sum or more

I can get it going from parsing reverse order passed order

Please, stop coding.

so negative numbers are allowed?

>just forgetting about the most basic trigonometric functions
Are you a yuropoor? Amerilard? Fuck, even in Clapistan you don't just "forget" about SohCahToa, they won't let you.

let do_my_homework desired_sum integers =
let rec loop n sum = function
| [] -> failwith "no solution"
| x :: xs ->
let sum = sum + x in
if sum >= desired_sum then
pred n
else
loop (succ n) sum xs in
loop 0 0 integers
;;

No.

I wouldn't have learnt about sin, cos, and tan again if I didn't read that trigonometry was important for graphics/games animation.

>Are you a yuropoor? Amerilard?
Neither, I'm British.

Start at (1, 0) and walk along the unit circle until you make an angle of theta

The x-coordinate of where you end up is the cosine of theta

The y-coordinate of where you end up is the sine of theta

No, just the easiest case

>.gif
>not animated to show the point moving along the unit circle
I'M GOING TO FUCKING THROW UP WHAT THE FUCK

I see, a yuropoor. I thought you fags were supposed to have a better education system than us Amerilards; are you considered a special kind of retard over there?

contragulations user!
one step closer towards being a code wizard

Recommend me books im bored

they're used for literally every geometric problem you will run into lard ass

Calling a Brit a European is like calling them Eurasian, we might be geographically in Europe but we would never identify as European.

Haskell From First Principles

This is the state of education in Britain.

t. Teacher

(I once had to explain what the รท symbol was to a group of 16 year olds; mobile/cell phones have / instead.)

my tutor says this is bad code practise, but I don't know why? could one of you help me pls...

// if a is divisible by b return true
public boolean isDivisible(double a, double b) {
double a2 = 0.0; //stores the division
a2 = a / b; //do division
String stringCheck = answer; //stores string check
if (stringCheck.contains(".")) { // checks for .
return false; // return false
} else { //else...
return true; //return true
}
return true; // return true
}
// end of isDivisible function

Oh and this interpretation is a little more difficult but generalizes to the hyperbolic trig functions:

Start at (1, 0) with a buddy and walk in the positive direction while your buddy walks in the negative direction until the area of the segment is theta

Then your position is blah blah blah

// if a is divisible by b return true
public boolean isDivisible(double a, double b) {
double a2 = 0.0; //stores the division
a2 = a / b; //do division
String stringCheck = answer; //stores string check
if (stringCheck.contains(".")) { // checks for .
return false; // return false
} else { //else...
return true; //return true
}
return true; // return true
}
// end of isDivisible function

template
void shift_aux(std::index_sequence, int (&a)[N]) {
int out[N] = { (a[(I + N - S) % N])... };
std::copy(out, out + N, a);
}

template
void shift(int (&a)[N]) {
shift_aux(std::make_index_sequence{}, a);
}

Kek

Am I being baited here?