/dpt/ - Daily Programming Thread

I need more programming pictures edition

What are you working on, my dudes?

Other urls found in this thread:

pastebin.com/p7viNijY
pastebin.com/FHFtt4du
akaribbs.mooo.com
gitlab.com/bollocks/libbokerface
c-sharpcorner.com/members/rajeesh-menoth
en.wikipedia.org/wiki/English_numerals
ideone.com/OFB3uT
twitter.com/AnonBabble

First for D

Second for D is shit.

third for you should try d

Third for D is dicks

Can't argue with those double dubs, guess I'm a #rustacean now

A game where you are Pajeet and you run from evil western men who want to control your defecation preferences in ARM assembly

Stumbled upon this program I wrote a while back, interested to see if anyone can do it better
pastebin.com/p7viNijY

You could do the same by piping /dev/rand straight into memory

I'm getting the following error:

Cannot implicitly convert type 'void' to 'System.Collections.Generic.List'

from this code (too long to post here): pastebin.com/FHFtt4du

on line 26. What am I doing wrong?

>pastebin.com/FHFtt4du

`AddMovie(ref Movies);`

Is it not obvious that you are attempting to assign data from a function that returns void to a variable?

poo in loo rajeesh

New to C#. I'm writing a poker app. Just got the randomized deck working. Gonna start on the players and card strengths next. Would love some advice and critique. How would you guys handle the players?

public class card
{
public string value { get; set; }
public string suite { get; set; }
}

class Program
{
static void Main(string[] args)
{
var deck = getDeck();

int count = 0;
int total = deck.Count;

foreach (var card in deck)
{
Console.WriteLine("{0}/{1} {2} of {3}",++count, total, card.value ,card.suite);
}

Console.ReadKey();
}

static List getDeck(bool shuffled = true)
{
List cards = new List();

string[] suits = new string[4] { "Hearts", "Clubs", "Spades", "Diamonds" };
string[] faceCards = new string[4] { "J", "Q", "K", "A" };

foreach (var i in suits)
{
for (var j = 1; j < 10; j++)
{
card c = new card();

c.suite = i;
c.value = (j + 1).ToString();

cards.Add(c);
}

foreach (var f in faceCards)
{
card c = new card();
c.suite = i;
c.value = f;

cards.Add(c);
}
}

if (shuffled)
{
Random rng = new Random();
var count = cards.Count;

while (count > 1)
{
count--;
int k = rng.Next(count + 1);
var value = cards[k];
cards[k] = cards[count];
cards[count] = value;
}
}
return cards;
}
}
}

I'm still working on my C message board!
akaribbs.mooo.com

There's another guy working on a message board as well, right?

I didn't think that changing a value by reference in the method counted as a return value. It didn't mention that in The C# Player's Guide.

When I change 'void' to 'List' it tells me that not all code paths return a value but that's what the Movies parameter is and it only ends with Movies.Add(movie).

Hope you're working on QR right this second.

Unions are literally perfect for cards, what the heck are you doing.
Why don't you represent cards from 1-12, Ace to King?

C# is fucking trash

Oh wait, Jesus Christ I'm an idiot. I see what the problem is now. I need to go to bed.

Is this your first programming language?

Do you understand the purpose of passing a ref to Movies?

You're fucking trash.

You mean 1-13?

Yeah, sure senpai.

It's my first 'real' language. Coming from Python. I've realized my stupid mistake and what you were talking about though now. This was pure stupidity on my part.

Not familiar with Unions. I'll look it up. Thanks!

your mom gets piped by randoms every night

>Unions are literally perfect for cards
how so? are you talking about enums or..?

post'd

why do you seem to keep falling for /dpt/ memes? you shouldn't give a fuck about what people ITT think. most of these fags are elitists college kids with no real world experience

I'm trying to create a function that:
>creates unique outputs based on input
>creates the same output regardless of input order, i.e. abc = bca

Can anyone point me in the right direction?

No, enums are essentially programmer-friendly aliases for encoded data.

A Union (as in C/++) is the concept of a datatype that is multiple types at once. You declare that a certain type is an "int, double, float, string" all at the same time.

But that was actually wrong.

See, there are actually multiple ways to do this.
A dictionary is the simplest way. You can translate a key to a value, or a value to a key.
So you can go from int to string.

A lower-tech way is to simply make an immutable array of tuples which hold the string and value pair for each card.

For situations where any face card is considered "10", you just floor any value above 10 to 10.

just multiply all the inputs together senpai

the fuck

the card can be an integer and you could look up the corresponding string in an array. why are you even involving unions or dictionaries

I haven't *actually* fallen for a DPT meme. I love Python (and Flask and Django) and would gladly take a job in one of them if they were available in my area. Sadly over the past few months that I've watched job boards there haven't been any Python positions. So I'm learning C# and ASP.NET because that's what I've seen the most. I called it a 'real' language because it's strongly typed and I like to play into DPT memes a bit.

I recommend Python to people in these threads all the time. I can see where you'd get the idea that I fell for the meme though.

>I recommend Python to people in these threads all the time
fucking cancer

>Python (and Flask and Django)
literally

...

>Pointers
allocbuf + ALLOCSIZE - allocp >= n


I can't make sense of that. ALLOCSIZE is just an integer number, aalocbuf is a pointer to the beginning of the array of the same name, then allocp is a pointer at the end of allocbuf.

Looking at the above code I already stated isn't it basically:
memory address + int - memory address >=n


This doesn't make sense to me.

I said that.

The problem with using arrays for card powers is that you have to remember, "oh shit I need to add 1 to get the actual value of the card", or "any face card is worth 10."

It's perfectly fine to use arrays of cards to initialize a deck. But using arrays of cards to translate between ints and strings is fucking ass.

In C# you could simply modify the value property to either get the actual value of the card or 10, if face cards are considered 10.

input 1: 1,1,1,1 = 1
input 2: 1,1 = 1

That will not work user. I need unique values.

poo in loo

Just rearrange the inputs in ascending order and put that bitch through a hash function.

poo poo in da loo, said the shrew who said more than he actually knew

you're clearly a beginner try being a bit more humble for your own sake

"hash function"
"sort"

Of course, it's impossible to create a hash function that is totally unique for every input, but the only functions that fit those criteria are simple transforms like "a + 1"

It's called pointer arithmetic. When you add 1 to a pointer, it increased by the size of the pointed to type.

Say you have 4 byte ints and a pointer to an array of ints.
The memory location of the pointer ('ptr') is 0x100.
So ptr + 1 points to 0x104.
ptr + 2 points to 0x108
etc.

¯\_(ツ)_/¯

Eat shit.
Your stupid array method is pointlessly complicated and unreadable for any sufficiently complex definition of card value.

lol good luck with your programming101 card game

Good luck with your hundredth implementation of fizzbuzz in increasingly obscure languages.

>hash function
I had never heard of that until now, that was exactly what I was looking for, thanks anons. I'm going to use md5.

>the only functions that fit those criteria are simple transforms like "a + 1"
what do you mean by this?

roasted

gitlab.com/bollocks/libbokerface

I'm doing something similar. I'm making an irc bot that will deal poker. It's in C++. So far cards, hands, and hand strength is done. I've built a test that creates every possible hand and sort of proved it correct. It's set up for 5 card hands and I'm going to use it for texas holdem and just brute force the 20 combinations from substituting one or two hole cards.

Look at the TexasHoldem object for how I'm implementing the game. It's 90% done. It's designed to allow the irc client to interface between the protocol and the object. So it's protocol agnostic.

I was able to work the evaluator down to 7ns from about 160ns. I think it's suitable for bruteforcing odds calculations for AI if you want to go that route.

I'm using naked deletes right now because I learned c++ way back when. I'll probably fix that later.

Consider it WTFPL at this point. So take what you liked. I'd appreciate attribution but I'm too lazy to figure out what license I want.

Warning TexasHoldem is poorly commented at this point but that should improve.

samefag

uh huh

>1280x800
kek

that wont save u from looking stupid

When you're wording out numbers, "and" denotes when decimals start.

e.g. "two-hundred and three" isn't 203, but 200.3

Neither will Chromium, tbqh farn

jesus that aspect ratio

his C# app-in-progress is very poor quality you're the ones who look stupid

samefag

who is then retard

samefag

I think I understand.

I have one more question that might not make sense:
int *ptr1 = beginning of array;
int *ptr2 = end of the same array;

Would:
ptr2 - ptr 1 = size of array?

samefag

Yes. But convert them both to ints first.

ptr2 - ptr1 + 1 = length of array = (size of array) / (size of element)

like if you have an array of length 8 and pointers to [0] and [7], 7-0+1=8

Yes, assuming ptr2 points just past the end of the array.

>But convert them both to ints first
That's not true. It's a ptrdiff_t.

>ptrdiff_t
I thought that was only in C++.

If you want to add pointers for some reason, there's also uintptr_t in C++ for both addition and subtraction.

>inb4 why would you add pointers

No, he's right.
You would only omit the "and" in 203 if you were talking slang.
If you want to denote decimals, you denote your decimals in base 10 form.
200.3 would be "two hundred and three tenths"

The more you know

Thanks, Anons.

or two hundred point three

Just moved to VS 2015. Why the fuck does intellisense work when I'm typing literal strings, and how do I disable it?

>You would only omit the "and" in 203 if you were talking slang.

This is actually one of those US vs. UK thing, sort of like math vs maths.

>C# is fucking trash

2016's Sup Forums. God help us.

calm down rajeesh

neat. starred it to save and watch the progress.

>US vs UK
doubt
You're required to put the "and" in checks in the US.

Poo-in-loos use Java and pretty much only Java. You're giving them too much credit if anything.

nice meme retard

c-sharpcorner.com/members/rajeesh-menoth

That's how I usually say it though, except it usually comes out as two-hundred n' three.
Apparently I'm not supposed to do that in American English though, but I don't think I was ever taught that
en.wikipedia.org/wiki/English_numerals

I'd say it's a fair split between c#/++ and Java.

Vindicated

I'm shitty at programming. I just wrote a subtraction function and it worked with very little editing. So now I'm trying to figure out what's wrong with it that I'm not seeing.

thnx

> 110 -> one-one-zero
holy shit brit vernacular is so disgusting. Is this really normal? Are there limey kids in trig classes talking about "tyoo-sevun-zehro" angles?

I suck.

How do I compare a number stored within a variable to the number of a specific slot of an array?

eg:

A variable n is being used to store a given number,
the array in use is as follows:

variable[size] = {x, x2, x3, x4 ...}

if(n == variable[x]
...

the question is for which bus, 117 is the bus number like a code, the angle would be two hundred and seventy degrees

to add onto what the other guy said, performing a conversion to ptrdiff_t before subtracting the start pointer from the end pointer will yield the address difference, which you then increment before dividing by the size of the elements.

do use ptrdiff, its best practice and using int has caused bugs for me

ok. But not two-seventy? Its so natural.

for you

You're not phrasing the question very well, but I think you're talking about
if (n == variable[0])
You access the elements of an array using an index. In your case, 0 corresponds to 'x', 1 to 'x2', 2 to 'x3' and so on.

maybe its because im tired but im not sure i follow.

by "number of a specific slot of an array", do you mean index (ie. the position it is in relative to the start of the array)? or do you mean the element AT that position?

>if(n == variable[x]
in this case, n and x are both variables, x is being used as the index, and variable[x]

what exactly are you talking about?

it crashed my program with no survivors

What I'm trying to do is a complete clock + calendar using
and only using to set up a delay on the loop that I'm going to use to count the amount of seconds, minutes, hours (...)

ideone.com/OFB3uT

The problem is that I'm using the 29/02/2016 date as a test but the program is saying this is a invalid date instead of a valid one.

void main()
int main(). void is not correct.

if (mth >= 1 && mth

Two seventy is retarded.

nvm fixed it

On this line:
if (day == dperm[mth])
You're trying to check if the date falls within the range [1, daysPerMonth], right? You're actually just checking if it falls on the last day of the month.

Some other advice
main always returns an int. your compiler might accept you declaring it as void, but it shouldnt
use abstraction. for each distinct bit of logic (e.g. number of days per month, validating the date, etc), put it into a separate function. this helps a lot because its self documenting-- when you call a function daysPerMonth(), isValidDate(), you know exactly the intent of the code is.

If you want, I'll post functionally equivalent code that demonstrates abstraction reasonably well, and leave the implementation of the functions to you.