/dpt/ - Daily Programming Thread

Artificial ants edition

Old: What do you think about swarm intelligence and metaheuristics Sup Forums?

Other urls found in this thread:

byorgey.wordpress.com/2010/07/19/typed-type-level-programming-in-haskell-part-iii-i-can-haz-typs-plz/
extremetech.com/gaming/133824-valve-opengl-is-faster-than-directx-even-on-windows
g-truc.net/post-0547.html
a.4cdn.org/'
i.4cdn.org/'
twitter.com/SFWRedditImages

Way too fucking early edition

Sage is your friend

have an upboat le sire

Sup Forums is so full of morons who didn't even read 4chanettique lolol

together we will destroy le spammers xD

(copied from earlier thread)

How do websites like strawpoll prevent duplicate votes? Evercookies?

probably ip+cookies

But wouldn't that prevent two people on the same IP (two different computers) from both voting? I think it allows that. (can't be done with just cookies because those can be cleared)

TRY TO USE THIS CODE BY ENTERING THE NUMBER 78568765 AND DEFY MATHSdef prime(n):
for x in range(2,n):
if n%x==0:
return "NOT PRIME"
return "PRIME"
def palindrome(n):
n_str = str(n)
if n_str == n_str[::-1]:
return True
else:
return False
def search_palindrome(n):
count = 0
print "Number entered: " + str(n)
while True:
count += 1
n_str = str(n)
n_rev = n_str[::-1]
r = int(n_rev)
n = n + r
print n_str + " + " + n_rev + " = " + str(n)
if palindrome(n):
break
print " "
return 'Palindrome "' + str(n) + '" found in ' + str(count) + " steps."
def prime_2(n, count):
hip = str(n) + " - 1 = " + str(int(n-1))
if prime(n) == "NOT PRIME":
print str(n) + " " + "NOT PRIME"
return prime_2(n-1, count + 1)
else:
# Recalculate the original value
original = n + count
count += 1
print str(n) + " " + " PRIME"
return "Number " + str(n) + " is prime found in " + str(count) + " steps, starting from the number " + str(original)
x = int(raw_input("Enter a number: "))
print prime(x)
print " "
print search_palindrome(x)
print " "
print "Number entered: " + str(x)
print " "
print prime_2(x, 0)

how am I defying math? what is your search palindrome method supposed to be doing, it looks like retarded code to me.

Bumping because metaheuristics!
>> TFW just had to forcefully reboot computer because the GA you ran wouldn't shutdown

It checks if your entered number is palindrome or not, if not it will add the number entered with the palindrome of the number entered, if the result of that shows a palindrome then it will stop and if not it will keep going on calculations until it finds a new palindrome.
If you think this is retarded then you must be a real genious.

do it on the python thing for windows, you can kill it without rebooting

Programming in Python - Rule 1:
Never implement algorithms in Python ever and if you do at least use something like CPython or Numba or pypy or whatever is trending atm.

i want to make a game but the thought of learning c# makes me feel dirty

What kind of game? 3d, 2d? Genre?

depends

Do C/C++ instead. There's tons of engines/frameworks.

Do it in html5

the code works with other numbers so i dont see the problem

SFML is comfy but why it uses camelCase? Literally retarded.

Unity isn't the only option mate.

2d i have a few things in mind
i was to learn c++ i'd go for unreal, but it's too overwhelming for someone learning it i think even though i know java and c.
i was thinking monogame desu

Maybe it grabs your MAC Address?

it's fucking retarded

>2d i have a few things in mind
With 2d it's actually pretty realistic to build an engine on your own. You could use C++ or even just C and SDL2 and build something. There are some very simple tutorials on this. I once build a very primitive 3d shooter à la doom with it in C, it's fun as hell.

The other thing about 2d is that performance probably won't be a limiting factor, so you might as well build it with HTML5 and javascript or whatever people do these days.

I'd recommend Anura (very good) or Magnum (graphics library).
Really for 2D you don't need much. You can write it from scratch really.
I've used Angel2D and felt it was rather comfortable when I was new. It's abandoned by devs pretty much.
>monogame
Looks good. Haven't tried it.

>What do you think about swarm intelligence and metaheuristics Sup Forums?

I think this is interesting field of research. Global optimization is cool.

Well it says right here.
You could do that. Been a long time since I took my network course but I think that'd be very similar to an IP ban because of NAT? Or maybe NAT encapsulation doesn't contain a mac address. Doesn't make much sense out on the web anyway.

Why don't you go with lua/love2d, user? It is pretty fast and way more convenient to program in.

I know C++ and I wouldn't use it to write a 2d game. I'd go with lua because I have better uses for my time than debugging C++ segfaults/memory leaks.

Has all list of engines. But all the thread just recommends is unity and gamemaker because they're scrubs.
Love2D is nice. A bit bare bones imo.

>Source isn't a real engine!

Explain yourself Haskell
{-# LANGUAGE TemplateHaskell, OverloadedStrings, OverloadedLists, GADTs #-}
{-# LANGUAGE MonadComprehensions, ParallelListComp, TransformListComp, RecursiveDo #-}
{-# LANGUAGE UnicodeSyntax, LambdaCase, MultiWayIf #-}
{-# LANGUAGE BangPatterns, ViewPatterns, PatternSynonyms, TupleSections #-}
{-# LANGUAGE RankNTypes, TypeFamilies, MultiParamTypeClasses, ExistentialQuantification #-}
{-# LANGUAGE DeriveFunctor, DeriveGeneric, DeriveFoldable, DeriveTraversable, DeriveTraversable #-}

Haskell pioneered puzzle-oriented programming paradigm. It is a language that attracts attention of autistic-but-not-bright users that happen to like to solve puzzles while programming.

A wide variety of incompatible language extensions is like a set of additional puzzle levels. An infinite timesink.

I just want a

{-# LANGUAGE EVERYTHING, NOKITCHENSINK #-}

SFML is alright.

from what I've seen in past agdg threads most of the people don't even make games/know how to program they just post there or someshit.

The place has gone down the shitter. But there's people who know what they're doing there. They're probably the worst gamedev forum I know of aside form places like stencyls forums (Scratch-type language game engine, literal pre-teens there).

But they're ready to offer opinions and if you ask for help you generally get answers from people who have some experience.

What the fuck Python.
I have a website from which I need to get some JSON data.
Making a simple requests.get() locally gets me the data immedietely.
cURLing locally gets me the data immedietely.
cURLing on a remote machine gets me the data immedietely.
Making a simple request.get() on the same remote machine takes 3 minutes.

Riddle me this.

QJsonDocument jsonData = QJsonDocument::fromJson(strData.toUtf8());
QJsonObject jsonObject = jsonData.object();
qDebug()

Your algorithms are pretty cool, it's a funny definition for palindrome.

protip: You can just return the conditional at the end of palindrome, i.e.

return n_str == n_str[::-1]

I really like the code though, looks like it was fun to write.

data = json.loads(subprocess.Popen(['curl', url], stdout=-1, stderr=-1).communicate()[0])

Another thing, to improve runtime, you can reduce calls to prime(n) by short-cutting any even numbers, and any numbers divisible by 5.

Add me on steam as Necro Magno and explain me there (i didnt understand that part and im a noob on python so i need tips and i dont know what other instant message place to say for you to leave me a message) please

PYTHON IS FUCKING RIDICULOUSLY SHIT FUCKING KILL YOURSELVES

calm down

not haskell the problem's with fucking GHC

post cringe
byorgey.wordpress.com/2010/07/19/typed-type-level-programming-in-haskell-part-iii-i-can-haz-typs-plz/

Can you make a living off freelance programming?

i swear drinking coffee is not worth it in the long run

maybe if you need to be alert at a specific point in time like during working hours and then you can pay off the "debt" in your spare time

but not for drinking all the time to try to boost your total productivity. in fact i vaguely recall that there was a study that suggested coffee drinkers were less productive overall.

or had a decreased ability to focus or something

If I don't drink at least 2 cups of coffee a day, I'm ready for bed by 7pm. A few cups and I'm ready to stay up until 2-3 am.

Caffeine is the best.

There's a study out there to prove anything causes anything if you look hard enough.

you hit a wall, you end up with the same problem that ADHD people get where coffee just makes you sleepy and it makes you sleep ridiculous amounts

desu coffee doesnt affect me in the least. maybe that's cause i do have adhd, never heard of that before though

Is vulkan to the point where its better than opengl and dx11 yet
Considering making some 2d games and figured I might as well learn vulkan while Im at it.
Otherwise Ill just use dx11 though Id like to stay modern.

vulkan is a meme use dx11 or modern opengl

but opengl is slower than vulkan and way slower than dx11. Unless its been updated since I last looked at it.
I know khronos wants vulkan to not replace opengl so its possible they finally made it faster.

well it looks like they definitely made it competitive to dx11

are you thinking of ancient fixed function opengl or something

extremetech.com/gaming/133824-valve-opengl-is-faster-than-directx-even-on-windows

is it possible to use VS without having to log in constantly?

ok opengl seems a bit slower than dx11

g-truc.net/post-0547.html

How do i even begin to make a tank simulator? Not super super simulator tier (ie: simulating all the way to the engine) but like getting the transmission, tracks, suspension, etc to all work as they should

What's the easiest way to get a integer from a string in c++, where every string has a specific format?
For example
const char *hn = "HouseNr 10";
const char *fl = "Floors 3";

use a physics engine like box2d

can that actually simulate rotation everything of tracks, etc?

So vulkan then

...

yes

Yes. CHeck it. Also check OpenDynamicsEngine.

ok. Another follow up. The Sup Forums json is nested so I tried this.
QString strData = (QString)reply->readAll();
QJsonDocument jsonData = QJsonDocument::fromJson(strData.toUtf8());
QJsonObject jsonObject = jsonData.object();
QJsonValue value = jsonObject.value("posts");

qDebug()

Those are C """strings""" not C++ strings.

*Those are C strings not C++ """strings""".

mate your 2d games should run at ridiculous framerates no matter which one you use

Incorrect placement of quotation marks, buddy.

My mistake.

Those are C strings not C"""++""" strings.

>ld -lmapm --verbose
...
attempt to open //usr/local/lib/libmapm.so failed
...
>ls -l //usr/local/lib/libmapm.so.0
-rw-r--r-- 1 user anon 90872 Jun 5 00:01 //usr/local/lib/libmapm.so.0

Redesigned the UI for my r/a/dio program. Having a rounded progressbar is too much of a problem with WPF.

>ldconfig -v | grep mapm
/sbin/ldconfig.real: Path `/lib/x86_64-linux-gnu' given more than once
/sbin/ldconfig.real: Path `/usr/lib/x86_64-linux-gnu' given more than once
/sbin/ldconfig.real: /lib/x86_64-linux-gnu/ld-2.23.so is the dynamic linker, ignoring

libmapm.so.0 -> libmapm.so.0

looks like shit anyway

Search backward through the character array for your delimeter, get the pointer to the start of the number, run stoi() with the pointer argument.

ty bb

No Im only using the 2d games to learn and practice some algorithms I made up. So learning vulkan while Im at it would help me later down the line when I get to 3d methods.

Nobody ever experience this?

Is it readable by your user?

And why are you using pam from /usr/local instead of the system libpam? That's kind of shady, right there.

oh I remember this shitshow

I fixed it, hol up let me find it

libpam? Look again.

Ack, sometimes I think I'm getting dyslexic in my old age.

Turns out I hadn't built the shared library correctly? I used a different recipe in the makefile and had to add -fPIC to get it to work on loonix.

it was with twitch api, but I guess it should be the same, sendrequest part
QJsonArray MainWindow::sendRequest(QString reqe) {
QJsonArray array;
// create custom temporary event loop on stack
QEventLoop eventLoop;

// "quit()" the event-loop, when the network request "finished()"
QNetworkAccessManager mgr;
QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));

// the HTTP request
QNetworkRequest req;
req.setUrl(QUrl(reqe));
QNetworkReply *reply = mgr.get(req);
//connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateDownloadProgress(qint64, qint64)));
eventLoop.exec(); // blocks stack until "finished()" has been called

if (reply->error() == QNetworkReply::NoError) {
QString strReply = (QString)reply->readAll();

//parse json
//qDebug()

card Hand[] = new hand[13];
Can I set do this?
Hand[1] = null;

i made a Sup Forums scraper.

rip it apart and tell me what i could do better

import re # Regex filtering for url parsing
import json # Extracting info from Sup Forums api
import requests # HTTP requests
import urllib.request # Downloading images
import os # Creating directories
import sys # Input stuff
import time # To ensure 1 request per second


def getBoard(url):
board = re.findall(r'org/(.*?)/', url)
return board[0]

def getThreadID(url):
id = re.findall(r'/thread/(.*?)/', url)
return id[0]


if len(sys.argv) < 2 or not sys.argv[1]:
print('ERR: No URL given!')
print('Usage: python scraper.py ')
sys.exit()

thread_url = sys.argv[1]

print('Parsing JSON data...')

board = getBoard(thread_url)
id = getThreadID(thread_url)

json_thread_url = 'a.4cdn.org/' + board + '/thread/' + id + '.json'

r = requests.get(json_thread_url)

print('Gathering image names...')

imagenames = []
for key in r.json()['posts']:
if ('tim' in key):
imagenames.append(str(key['tim']) + key['ext'])

print('Creating directory at ' + os.getcwd() + '/' + board + '/'
+ id + '...')
if not os.path.exists(board + '/' + id):
os.makedirs(+ board + '/' + id)

print('Downloading images...')
for i in range(len(imagenames)):
filename = board + '/' + id + '/' + imagenames[i]

print('Downloading i.4cdn.org/' + board + '/' + imagenames[i])
urllib.request.urlretrieve('i.4cdn.org/' + board + '/'
+ imagenames[i], filename)
time.sleep(1)

hehe I did a project just like this for my foothill college class! Are you a student here or maybe de anza?

proof C is weakly typed

>python
>3 no less
get out

>anything but python
>anything but 3

lol k stay in the past grandpa

I don't think anyone has said otherwise

Why the last line?
Why set what was just deleted to null?

Also
str = 5[\code]
should throw an error

testing

use urlparse instead of regex to parse urls.
use string.format instead of concat
is request in standard library yet? if not, stick to urllib2 to minimize dependencies on small scripts.

So you don't have a dangling pointer?

Dereferencing nullptr will always give a fatal error.

Arguably you should wrap that in a debug ifdef or whatever.