/dpt/ - Daily Programming Thread

Old thread What are you working on?
What do you think DAT BOI would be working on?

Other urls found in this thread:

docs.oracle.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String, int)
stackoverflow.com/questions/678254/what-should-i-do-if-two-libraries-provide-a-function-with-the-same-name-generati
en.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations#Matrix_algebra
book.pythontips.com/en/latest/index.html
en.wikibooks.org/wiki/Haskell/Lists_and_tuples
twitter.com/NSFWRedditImage

how long should it take to invert a 256*256 matrix

...

About 2-3 hours on modern GPUs

I'm really having trouble grasping that. But what I would like to add is that it has to split on certain points.
An example of what I get would be:

"timer 10 minutes 20 seconds"


This has to split into:

array[0] = timer
array[1] = 10
array[2] = minutes

and so on.

It's a weird form of C++, and copy pasted code doesn't work.


My idea is to for loop through the entire thing, counting the amount of spaces. Then create an array of that size, for loop it again, and substring the string into that array. But that just feels horribly inefficient.

fuck off with this shitty meme

You know, people complained about the trap thing being posted.

But this,

This is infinitely worse.

Minimum requirements for a modern programming language:

>dependent types
>higher-kinded types
>typeclasses
>effects/IO
>tail call optimization
>type inference
>trampolining

yourString.split(' ', -1)

is that a dude

JavaScript?

I miss the Norway /dpt/ thread.

split does not exist.

docs.oracle.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String, int)

Use jQuery

I'm writing code for Arduino. I mentioned that on previous board, sorry.

Me too, man, me too.

det gör inte jag

Why not, Swedebro?

...

fuck all scandinavians, southern europe is true europe

hi, i made this C# script for a 2d game, and i got some issue for the walljump, i want it to jump vertically, but he only jump on the y axis for some reasons, i tried to remove the things that makes my character move on the x axis and it worked, but then i couldn't move on the side so yeah.. any advices ?

>southern 'europe'
>moors
>unemployment
>denbts
>catholics

the code from using UnityEngine;
using System.Collections;

public class PlayerControllerScript : MonoBehaviour
{
public Rigidbody2D Body;
public float maxSpeed = 10f;
bool facingRight = true;
public float jumpForce = 700f;
public float walljumpForce = 700f;
Animator anim;

bool walled = false;
bool grounded = false;
public Transform wallCheck;
public Transform groundCheck;
float wallRadius = 0.1f;
float groundRadius = 0.2f;
public LayerMask WhatIsWall;
public LayerMask WhatIsGround;

void Start () {
Body = GetComponent ();
anim = GetComponent ();
}

void FixedUpdate()
{
grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, WhatIsGround);
walled = Physics2D.OverlapCircle (wallCheck.position, wallRadius, WhatIsWall);

anim.SetBool("Ground", grounded);
anim.SetBool ("Wall", walled);

anim.SetFloat ("vSpeed", Body.velocity.y);

float move = Input.GetAxis ("Horizontal");

anim.SetFloat ("Speed", Mathf.Abs (move));

Body.velocity = new Vector2 (move * maxSpeed, Body.velocity.y);

if (move > 0 && !facingRight)
Flip ();
else if(move < 0 && facingRight)
Flip ();
}
void Update ()
{
if (grounded && Input.GetKeyDown (KeyCode.Space)) {
anim.SetBool ("Ground", false);
Body.AddForce (new Vector2 (10, jumpForce), ForceMode2D.Impulse);


}
//x axis doesn't work
if (!grounded && walled && Input.GetKeyDown (KeyCode.Space)) {
Body.AddForce (new Vector2 (77, 77), ForceMode2D.Impulse);
walled = false;
//fuk you x axis
}
}
void Flip ()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1f;
transform.localScale = theScale;
}
}

Im just shitposting but i hope u like this image

fuck off

Your idea would work. If you didn't want it to be terribly inefficient: instead of substringing just make a char* array and set each index to point to the start of each word. You will have to place a NUL after each word where the spaces start. No copying, more efficient.

>2d game
>unity

Anyway I can override C stdlib functions in a source file to use safer or more efficient versions of the functions?

int HighLow(int & CardA)
{
int CardB=rand()%13;
if(CardA==12&CardB==0){CardA=CardB; return 1;}
else if(CardA==0&CardB==12){CardA=CardB; return 0;}
else if(CardACardB){CardA=CardB; return 0;}
else{return 2;}
}

int main()
{
int CardA=0;
int guess, answer;
for(int n=0;n

9 decides what I build this weekend

A mattress fort.

A home for refugees.

A wall.

Why are you saying this ?
unity is gud for 2d game
..i think

a sex robot

see click update
seeyou have to build a meme post generator

I want to make a small game in Android. Any recommendations on an engine? I only need 2D.

>moors
they actually enriched our culture (this was during the time they weren't useless terrorists)

>unemployment
not our fault that the eu juggernaut ruined us

>denbts
see above point

>catholics
best religion

/agdg/ here, use Unity™.

Hey /dpt/, what's the least cpu consuming method of interprocess communication in python?(between different scripts)

We have a winner

>to kill a fly with a rocket launcher

solution 1 - don't include and include "yourlib.h" instead

solution 2 - include both, use stdlib functions where you don't need safer/more efficient variants and use the replacements wherever, making sure to have no name conflicts

solution 3 - have both your lib and stdlib and check stackoverflow.com/questions/678254/what-should-i-do-if-two-libraries-provide-a-function-with-the-same-name-generati

>Using a rocket launcher that is run by John Riccitiello, the man who unlocked EA's true, Jewish potential.

libgdx

pretty sure you can #UNDEF function names

Post of the month

fuck y'all i want more cats hidden in pictures

that might cause problems if any of the functions he's using relies on the undef'd function though (might not be a problem depending on the order of operations of the preprocessor)

en.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations#Matrix_algebra

O(n^2.373), so assuming it's a matrix of something 8 bytes or less it'll be split second

this crap meme is really being forced hard today

>more efficient than C stdlib
The C stdlib should be basically as efficient as it gets, unless your implementation is shit. So, if you still think you can get more performance out of it, you're calling the wrong function prototype, and should rename the function.

>The C stdlib should be basically as efficient as it gets
No. It's poorly coded.

>c stdlib
>poorly coded

The C stdlib is an API which has multiple implementations (with strict rules for how they should be implemented, but I digress). Perhaps the implementation you're using is shit?

glibc is shit.

Almost sounds like he can't use dynamically allocated memory.

Then why not submit a patch to improve it?

thought about getting into cities skylines modding, then decided my mod idea was shit

My (core) language has finite sets. If you have a type Fin(m), its inhabitants are 0..m-1, and they are the basic unit for pattern matching.

Would it be a bad idea to have a subtyping relation on this? I.e. if you have an value of Fin(m), you could directly use it as value of Fin(n) for n > m? It wouldn't be harmful in terms of soundness, just potentially confusing.

>tfw incapable of preventing my code becoming a hacked-together clusterfuck

Do I need to read books about program design or just practice and make lots of mistakes and learn from generating awful spaghetti code?

Because the whole methodology suck.

both

Python is for babies and you are already in a big mess.
Sure you have to learn a lot of things.

Not sure about C++ but in C I'd.

Count the spaces.

Allocate an array of strings but not the strings themselves.

Use strtok to break the string into null separated words.

Set your array to point to each element.

This nice guide is a good base:
book.pythontips.com/en/latest/index.html

Don't hope to develop something good with this little guide only!
The best after that is to read current working code on Github!

Oh hey Orb, how's things?

Not bad thanks. 2 weeks of constipation starting to clear today. Hope I don't block the toilet.

int words(char *str){
int count = 1;
for(;*str;str++)
if(*str==' ')
count++;
return count;
}

char **substr(char *str){
char **toks = malloc(sizeof(char *)*words(str)), **pos = toks;

for(char *tok = strtok(str," ");tok;tok=strtok(NULL," ")){
*pos = tok;
pos++;
}

return toks;
}

>made a program which prints shapes
>can print a triangle and a box
>have to print a star shape
>been trying for 2 hours and it still doesn't work

Who /2 stupid 2 program/ here?

You're a real sinpi.

>get tired of PascalCase
>want to use snake_case
>it's too late to switch

fug

>he doesn't use Visual Studio

Just use whatever is standard in the language.

Just remember to flush regularly. Mid-shit it necessary. Let the water tickle your hole.

>Winshit

>He wilfully compiles 4gig Hello World applications that are owned by Microsoft in an IDE that takes 7 solid hours to open.

I'll try. It's hard to pause mid shit sometimes though.

Lord have mercy on your soul.

That's like saying that photoshop is good for basic image viewing.

#!/usr/bin/env python

import turtle
import math

def star (length, count, step):
def point (i):
a = i * 2.0 * math.pi / count
return length * math.cos (a), length * math.sin (a)
def goto (i):
p = point (i)
turtle.goto (p)
turtle.penup ()
goto (0)
turtle.pendown ()
j = 0
for i in range (count):
j += step
goto (j)

def main ():
star (300, 5, 2)
turtle.done ()

main ()

That was so hard.

>mfw classmates dumber than me are getting internships at facebook and I'm stuck doing QA work for the summer
Why is life so unfair?

It's about who you know, not git and make friends

>internships at facebook
>implying it's a good thing

#!/usr/bin/env python

import turtle
import math

def main (length, count, angle):
for i in range (count):
turtle.forward (length)
turtle.left (angle)
turtle.forward (length)
turtle.right (angle - 360 / count)
turtle.hideturtle ()
turtle.done ()

main (100, 7, 160)

But beware, my code is copyrighted.

#
# Copyright 2016 The people of /dpt/
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
#!/usr/bin/env python

import turtle
import math

def main (length, count, angle):
for i in range (count):
turtle.forward (length)
turtle.left (angle)
turtle.forward (length)
turtle.right (angle - 360 / count)
turtle.hideturtle ()
turtle.done ()

main (100, 7, 160)

That's thief. I'm reporting you to competent authorities.

They told me to not come here, I should have stay on reddit.

I've read that malloc and start should not be used with Arduino.

a cuckshed

"""
Copyright (c) 2016
The Regents of the University of California. All rights reserved.

This code is derived from software contributed to Berkeley.
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by the University of
California, Berkeley and its contributors.
4. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

@(#)shittystar.py 8.1 (Berkeley) 1/4/94
"""
#!/usr/bin/env python

import turtle
import math

def main (length, count, angle):
for i in range (count):
turtle.forward (length)
turtle.left (angle)
turtle.forward (length)
turtle.right (angle - 360 / count)
turtle.hideturtle ()
turtle.done ()

main (100, 7, 160)

en.wikibooks.org/wiki/Haskell/Lists_and_tuples

I'm going through the exercises and I don't understand how they want me to do number 3.

The only way that I can think of since you can only add on the left side is to create a while loop that inverts but they haven't covered loops.

I should specify "
Adapt the above function in a way that 8 is at the end of the list. (Hint: recall the concatenation operator ++ from the previous chapter.)"

Question for you-

Do you think it's better to go through a programming book with pen and paper and take notes with along with it, or to just follow along with a preferred editor?

Both?

Second.

Nevermind I found the solutions page.

>He doesn't know that all programs he compile with Botnet Studio insert a telemetry in the program that make it another botnet.

I always keep notes on paper. It's just nice to have a physical copy.

why does jumping always add a force in the positive X direction, shouldn't that factor in the faced direction/what key is being pressed (move left/right)

Same goes for the wall jump shit

if it has anything to do with the fact that you scale him negatively w.r.t. the x axis, you need to kill this fucking spaghetti now before it gets out of hand.

>WhatIsGround
If you don't know what ground is you need to stop programming

I'm doing intro to algorithms. Not having too much trouble with the procedures themselves but I'm having a hard time grasping the concept of a loop invariant. Any help? Why do I even need this shit it feels like intellectual babble

>not jetbrains
kys

Evening, Sup Forumsentlemen.

I'm doing a group project in Qt. Basically, the issue I'm coming to you guys for is not about programming but more about design.

We have to make a game, and like a lot of games it's got a sort of resource system.
We made a dialog window that lets the player pick which resources he wants to trade in blahblah.

So far, we've done everything via a controller to go along with model/view thinking, but now we're disagreeing. Basically, my partner thinks the data side should use signals and slots to indicate when it wants a widget to be called, when I'm more in favor of determining at some point in the controller that the widget has to be called and then passing info on to the relevant class. I hope I explained that clearly enough.

Which approach do you guys think we should pick?