[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 320
Thread images: 20

File: OOP strikes back.jpg (67KB, 1006x692px) Image search: [Google]
OOP strikes back.jpg
67KB, 1006x692px
What are you working on, /g/?


Previous Thread: >>59258691

Sorry for not using an anime image
>>
Rust
>>
>>59260749
That is one demonstration of disgusting font rendering
>>
File: 1481833978974.jpg (263KB, 636x900px) Image search: [Google]
1481833978974.jpg
263KB, 636x900px
SECOND FOR CUTE
>>
File: OOP will never be good.png (50KB, 525x829px) Image search: [Google]
OOP will never be good.png
50KB, 525x829px
Oh shit, I used the wrong image
https://github.com/yegor256/eo
>>
>>59260710
>And most male programmers are utter retards, the only female programmers that make it are the ones who are actually good.
Now who is using confirmation bias?
>>
>>59260762
This

RUST OR BUST
>>
In terms of programming ability:

women > men who crossdress > men who don't crossdress
>>
>>59260786
men who are from india > women > men who crossdress > men who don't crossdress
>>
>>59260786
>men that crossdress and sit on a dildo > women > men that crossdress > men who dont
>>
>>59260719

Please halp
>>
>>59260801
Sorry, I can solve the problem using D and Rust only
>>
>>59260801
I'll do it for BTC
>>
>>59260772
It's not confirmation bias, it's simply sturgeons law.
>>
Should /dpt/ start giving wrong solutions to homework questions?
>>
>>59260786
People with autism > People with no autism
>>
>>59260825

I'll give you 117 dogerinos and 343 koinye
>>
>>59260771
>we don't tolerate mutability and also constants
>we don't tolerate mutability but we want to build in transactions
>>
>>59260801
study your language's libraries, anon. I don't know about C, but I would definately use std.range: repeat in D

'*'.repeat(n)

Where are you stuck
>>
>>59260847
Give me a blowjob
>>
>>59260856
Look at his youtube channel, look at his blog and his articles.

He is a fucking retard
>>
File: 1486428981152.jpg (111KB, 420x550px) Image search: [Google]
1486428981152.jpg
111KB, 420x550px
>>59260771
>we hate constants
Hitler did nothing wrong
>>
>>59260773
Rust IS Bust.
>>
>>59260899
OR*
>>
>>59260914
CL-USER> (type-of 'rust)
BUST
>>
>>59260786

university trained males > university trained females > males > females > r/learntocode > crossdressers from /g/
>>
If your language doesn't let you do Prolog in the type system, it's worthless.
>>
>>59260899
*HAS
>>
>>59260749
The Java labs I work have an assignment that I'm pretty sure does exactly this
>>
>>59260954
What languages let you do Prolog in the type system? Besides Prolog.
>>
>>59260950
reverse traps > traps

>>59260961
Haskell, Scala
>>
>>59260950
university trained *nu-males
>>
>>59260771

>flow control statements (if)
You see, this kind of shit is going to be needing a lot more explanation than everything else.
>>
>>59260830
> i tried that, but it didn't work. Are you trolling me?
>>
>>59260975
tbf haskell doesn't have those built into the language
because they're library features

>inb4 "if"
if was a mistake
>>
>>59260984
If we keep doing it they'll go away.
>>
Building this video server so I can use my phone as a remote for VLC and watch my Mongolian silk weavings from my couch. I'm stalled at making the controls look better because >wdg.
>>
Real talk time. Why do so many of you use languages that make you do work that the compiler/interpreter could be doing for you?
>>
>>59260950
>university trained males > university trained females > males > females > r/learntocode > crossdressers from /g/
*university trained males that majored in anything STEM, not CS > university trained males who majored in CS

Prove me wrong.

Pro tip: You can't.
>>
What does R.U.S.T stand for?
>>
>>59260995
You can try, but if someone posts a question in my favorite language, I'll do my best to genuinely help them.

And there's nothing you can do about it.
>>
>>59261016
I use a type inferred language
>>
>>59261016
But I don't, anon.
>>
>>59261022
I'll invent problems in your solution to scare the anon away.
>>
>>59261020
RELIABLE
ULTIMATE
SECURE
TESTED
>>
>>59261020
Rust
Unites
Socially-minded
Transvestites
>>
>>59261020
rust
>>
>>59261020
Rust Uses Safe Transformations
>>
>>59261036
Not really applicable to most solutions in the language I use.

Maybe that's possible with Haskell memes.
>>
>>59261020
robust
unbreakable
secure
tested
>>
>>59261016
i'm inseCure
>>
>>59261072
More like I am a C.uck
>>
>>59260994

>if was a mistake
A language without if is more or less useless.
>>
>>59261016
Because it is good to know what is actually going on behind those compiler optimizations. You end up understanding your programs a lot better by going through all of that hard work.
>>
>>59261095
>it is good to know what is actually going on behind those compiler optimizations
Yes, and once you know you can stop using inferior languages and use better ones instead.
>>
>>59261093
myFunction True = x
myFunction False = y
>myFunction b x y
>if b then x else y
>>
>>59261020
Rust
uses
safe
templates
>>
According to the png spec (http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html)
all pngs have the following decimal values at the beginning:
> 137 80 78 71 13 10 26 10

But when I open a png with text edit, I get closer to the thing in pic related... How can I actually view the decimal values in png? (I tried to open a png in emacs, atom, and sublime, but they all displayed the image instead of the text.... Can I configure them to show me the data?)
>>
>>59261095
Maybe if you're an undergrad.

At some point, unless you're doing systems programming, you decide you need to be productive and actually get things done.
>>
>>59261157
Use a hex editor. xvi32 is pretty good.
>>
>>59261157
Open it in a hex editor
>>
>>59261016

Offloading work onto a compiler is fine, although it is important to realize that the compiler is not omnipotent.

Offloading work onto an interpreter is retarded.
>>
>>59261173
HxD will kick xvi32s shitter
>>
>>59260997
>video server
What?

>so I can use my phone as a remote for VLC
Just use anyRemote.
>>
>>59261108

For large enough programs, writing code like that will get annoying as hell.
>>
>>59261207
ifThenElse True t _ = t
ifThenElse False _ f = f


...

ifThenElse b x y
>>
>>59261020
Retarded
Useless
Shitty
Tosser
>>
>>59260899
(defun bust (g)
(eq g 'rust))

(deftype rust ()
`(satisfies bust))
>>
I always type in the number '5' and sometimes it will print invalid input, and sometimes it won't.
  int a;
while ((a = (getchar() - 48)) <= 0 || a > 9)
printf("invalid input, try again.\n");


Shouldn't it evaluate the left expression first, and never enter the while?
>>
>>59261212

Congrats, you invented the ternary operator!

Now why do we use if statements when the ternary operator exists? Maybe it's because we want something like...

if (condition1) {
thing1();
thing2();
mutate variable y;
thing3();
} else if (condition2) {
thing4();
} else {
thing5();
thing6();
}
>>
>>59261292
Ruby, what's happened to OSGTP? Did you two fall out?
>>
>>59261292
This is why we have COND.
>>
>>59261279
When in doubt, more parens.
>>
>>59261292
Monads.
>>
std::unordered_map<std::uint32_t, fpu_context, std::hash<std::uint32_t>, std::equal_to<std::uint32_t>, locked_pool_allocator<>> contexts;

who the hell thought it was a good idea to make the allocator the last template argument?
>>
>>59261279
Cause a has no initial value you moron.
When you int a and then set a > 9. It's value is determined by whatever garbage is inside the memory the compiler defined. Hence why it is random.
>>
How old are you fags?
>>
>>59261323
Go away NSA
>>
Rust is a goddamn pain in the ass to use. I guess I'm not patient enough to deal with all that lifetime bullshit.
>>
>>59261337
Use Lisp.
>>
>>59261326
Genuinely curious.
>>
>>59261321
Weird. I thought it would assign it before any comparison.
>>
>>59261181
Ruby chan, do you have experience in qemu aarch64 virt?
>>
>>59261341
Why would I be using d*namically """typed""" garbage?
>>
>>59261300
He's chilling in the Discord, and I still see him posting in the thread from time to time.

>>59261306
I see no reason why one cannot have a keyword if, if one is allowing cond/match to exist.

>>59261309
Cool. Keep it baked into the language so I can:
if condition do
thing1;
thing2;


No throwing away my keyword.
>>
>>59261368
in Haskell this is just

when condition $ do
thing1;
thing2;

the only keyword is "do"
>>
Since you can access pointers in C, can you access memory that is in use by other programs?
>>
>>59261367
(defun equidimensional (a)
(or (< (array-rank a) 2)
(apply #'= (array-dimensions a))))

(deftype square-matrix (&optional type size)
`(and (array ,type (,size ,size))
(satisfies equidimensional)))

Say what?
>>
>>59261388
Generally not.
>>
File: consider-suicide-2.jpg (21KB, 460x276px) Image search: [Google]
consider-suicide-2.jpg
21KB, 460x276px
>>59260749
That's among the most disgusting code I've ever laid mine eyes upon.

If you wrote this, please follow the pictured advice.
>>
>>59261388
No
The OS will stop you
>>
>>59261388
That depends on the OS. You can't do that if there's address space isolation.
>>
>>59261355
Parentese doesn't work that way when used in the way you did. Try assigned a outside the conditional.
>>
>>59261377
in Lisp this is just
(when condition
thing1
thing2)
>>
@milk, come back to dpt discord

>>59261402
oop is a blight upon the world
>>
>>59261445
of course, since lisp is trash and doesn't have monads.
>>
>>59261309
conio.h is my favorite monad :^)

>>59261388
That's implementation defined
>>
>>59260749
I love how this OP pic is obviously from somebodies first ever Java assignment, and OP uses it as some sort of attack on OOP.
>>
>>59261388
Not directly. If you are on Windows look at ReadProcessMemory and if you are on Linux look at process_vm_read if you want to read memory. Ones for writing are similarly named.
>>
>>59261475
There is existing work on monads with Lisp.
https://common-lisp.net/project/cl-monad-macros/monad-macros.htm
>>
>>59261355
Compilers don't necessarily read left to right.
>>
>>59261388
No.
>>
Will c++ modules finally allow circular dependencies?
I'm stuck on one right now.
>>
>>59261279
This is so retarded.
Is there something about getchar() I don't understand?
I keep getting invalid input even when I type values that are between 1 and 9.
  char a = getchar();
while (a <= '0' || a > '9')
{
printf("invalid input, try again.\n");
a = getchar();
}

char b = getchar();
while (b <= '0' || b > '9')
{
printf("invalid input, try again.\n");
b = getchar();
}

char c = getchar();
while (c <= '0' || c > '9')
{
printf("invalid input, try again.\n");
c = getchar();
}



It'll never do it on the last while, though. So, this gives invalid input on a and b, but not c. Take away c, and it'll do it only on a. Take away b and c, and it won't do it at all.
>>
Where can I find good programming exercises? Not the bullcrap infographic meme that a random /g/ tard made.

I want CS200-300 level exercises
>>
>>59261616
Wait, are you fucking serious? Are you seriously trying to compare chars with < and >? You can't even do that shit in Python. You need to convert that shit to ints.

Also, put the braces on the same line like
  char a = getchar();
while (a <= '0' || a > '9') {
printf("invalid input, try again.\n");
a = getchar();
}


It's much more aesthetic.
>>
>>59261616
>comparing chars by their values
Lord have mercy on your soul. Please convert them to int first.
>>
>>59261688
while ((char a getchar()) <= '0' || a > '9') {
printf("invalid input, try again.\n");
a = getchar();
}

I don't even like C(ancer)
>>
>>59261723
ignore the last statement a = getchar() in line 3
>>
>>59261616
What's happening is you're getting a character but there's still a newline in the buffer. So the next getchar absorbs that newline as the next char.

>5\n
is your actual input, after the first getchar your buffer is like this
>\n
and your next getchar reads that. Clear the buffer with
>while ((c = getchar()) != '\n' && c != EOF);
>>
File: 1461528655252.png (378KB, 1450x1080px) Image search: [Google]
1461528655252.png
378KB, 1450x1080px
>>59261685
most of the exercises on the "bullcrap infographic meme" are above the CS2-300 level. Examples of shit you'd do in a typical 200 level CS course:
- implement merge sort in C or Java
- write a simple client-server program that sends strings back and forth
- implement a queue as a linked list

Are you looking to have your hand held with a step by step tutorial? If you're looking for a challenge, pick one of the "hard" challenges of this list and start doing some research.
>>
I just started CS and my Uni teaches us C# and Java for our two first programming courses.

What's /g/'s opinion on this?
>>
>>59261723
Doing a variable initialization and assignment like that when the variable is being used elsewhere in the statement at theoretically the same time is very poor form.
>>
>>59261688
>>59261707
I thought they would just compare by their decimal ASCII value.

>>59261736
There we go, thanks.
>>
>>59261745
>while
>merge sort
>not CS100 level
>>
>>59261745
roll
>>
>>59261761
well most universities can't keep up with your super advanced mind anon
>>
File: bowl.webm (1MB, 1280x720px) Image search: [Google]
bowl.webm
1MB, 1280x720px
>>59261745
roll
>>
>>59261749
you know goddamn well what /g/ is going to say about this you fucking troll
>>
File: triggered-1.png (167KB, 390x360px) Image search: [Google]
triggered-1.png
167KB, 390x360px
>>59261496
>conio.h
>>
>>59261757
>I thought they would just compare by their decimal ASCII value.
That's exactly what it should do. Don't listen to those anons.
>>
>>59261749
That's not MIT
>>
>>59261749
I'm so happy for you Anon! These are the best!
>>
>>59261795
merge sort is 100 level though, learned it in high school ap cs
>>
>>59261501
>Linux
>process_vm_read
The only Google results I can find on that are from Windows. I think you're looking for ptrace().
>>
>>59261811

No I seriously don't, I just started browsing this place since I just started programming.

Are they bad? Why? My professor said that if you learn these you'll get a job 100%.
>>
>>59261831
lol who the fuck needs to reinvent the wheel, there are tons of sorting libraries available
>>
>>59261757
You can, you can also assign in the while loop like in the beginning.
>>
>>59261745
>ranking difficulty of code based on tediousness
>>
>>59261833
Learning a certain language does not guarantee jobs.
>>
>>59261831
I'm so proud of you.
>>
>>59261824
MIT teaches python now senpai
>>
asm ("fxrstor %0;"::"m"(*context.data()));

>Error: invalid instruction suffix for `fxrstor'
how does this work? am I supposed to use some special constraint?
>>
>>59261836
nobody says "I'm going to implement a better version of merge sort today!". it's as a learning exercise, and to improve one's skills as a programmer.

also yes, merge sort is trivial. yes you have a huge cock and brain because you did merge sort in assembly when you were 6 years old.
>>
>>59261851

Actually 99.2% of the graduates get a job instantly. Some even get a job before finishing their degrees.
>>
>>59261857
thanks dad
>>
>>59261749
>mfw the I learned C first, then Python, and then Lisp and Assembly my third semester
I was an EE major, though.
>>
>>59261883
Not sure exactly how that works, but it could be requiring "fxrstor (%0)".
>>
>>59261934
>Learnt C
>Learnt Assembly
>Learnt Python for my final year project
>Working a job that does Java now
EE major as well.
>>
>>59260749
I'm a beginner, I've been learning Python as my first language. Is it a bad idea for me to read SICP? I've been following along just fine so far, and LISP seems pretty simple to understand, but I'm not sure if it's a bad idea for me to get so accustomed to LISP when I'm still learning the basic of another language. Could someone with experience give me insight?
>>
>>59262023
Just move on to lisp if you prefer coding in Lisp compared to Python.
>>
>>59262023
I would advise you stop learning Python and move to something else as quickly as you can. Python is great for non-programmers who need to write simple programs, it's terrible for everything else.
>>
>>59262023
There's absolutely nothing wrong with getting accustomed to Lisp. Just jump ship entirely if you like it.
>>
>>59262023
It's better to learn a lot of different stuff since your brain isn't locked into one way of thinking yet. A lot of retards here seem to have problems with that.
>>
>>59262023
Program in what you like. If you like Lisp, use Lisp. I prefer Common Lisp, but Scheme is easier on the eyes at times. I never read the book, but instead picked up Lisp through reading Practical Common Lisp, On Lisp, and reading the Common Lisp HyperSpec. Common Lisp the Language 2nd edition is handy as well.
>>
>>59262062
>Python is great for non-programmers who need to write simple programs, it's terrible for everything else.
>Working in GIS field
>Have to use Python cause Industry leaders set the standard
Simply fucking ebin.
>>
>>59262062
>Python is great for non-programmers who need to write simple programs, it's terrible for everything else.
That's not actually true, though. I've written semi-large (5000+ lines) programs in Python, and it's absolutely fine for some programs. Not my favorite language, but there are far worse ones.
>>
>>59262087
Yeah, like Haskell.
>>
>>59262087
The worst part I discovered about Python is making stand alone distributions. Sure a 500 line program using stdlibs and commonly used libraries will work with PyInstaller but anything more or using more uncommon libraries. Lmao, that shit is breaking 100% for sure.
>>
>>59262103
Certainly, but not all programs need stand-alone distributions. Or uncommon libraries.
>>
>>59262087
It is true, just because you CAN use it for larger programs doesn't mean you should. Pick the right tool for the job.
>>
>>59261599
Do you use forward declarations?
>>
>>59262118
My point was that Python was a reasonable tool for those jobs, though. I can't immediately think of another language that I would have preferred for those particular tasks.
>>
>>59262117
It will be great to compile stand alone distributions. The way python hacks it together doesn't sit well with me.
>>
>>59262141
What is *really* the difference between a Python program requiring installed modules, and a C program requiring installed SO files, though?
>>
File: bait-17.jpg (22KB, 627x626px) Image search: [Google]
bait-17.jpg
22KB, 627x626px
>>59262098
>>
>>59261962
That doesn't seem to work, also tried [%0]. I think the brackets are implied already when using the "m" constraint. By the way I'm using -masm=intel.
>>
>>59262017
kek
>>
>>59262156
No problem with Python required installed module. I am lamenting the methods that are currently available to make stand alone distribution for Python programs. They are incredibly hackish to me.
>>
>>59262125
Yes but you can't forward-declare everything. eg. if you have functions in one struct that use functions in another and vice-versa.
The whole forward declaration thing is a mess anyway. I don't like to say it but this is one thing C# got right.
>>
>>59262205
>By the way I'm using -masm=intel.
Then I've absolutely no clue how it might work.
>>
>>59262220
>eg. if you have functions in one struct that use functions in another and vice-versa.
You just declare the structs first, and the function bodies separately afterwards.
>>
>>59262212
I haven't even tried using them myself (never had a use for them), but from what I know there's at least one tool that just compiles an executable with a Python interpreter and adds the given Python files to the data segment with an import loader that can find them there. I don't think there should be anything wrong or hackish about that solution.
>>
What language should I spend my nights reading about and perfecting /g/?
>>
>>59262254
Common Lisp.
>>
>>59262254
C, obviously.
>>
>>59262252
>but from what I know there's at least one tool that just compiles an executable with a Python interpreter and adds the given Python files to the data segment with an import loader that can find them there. I don't think there should be anything wrong or hackish about that solution.

It basically freezes the script but has a lot of issues when it comes to importing modules. Read >>59262103
>>
>>59262264
Seconded.
>>
>>59262265
No. C is cancer
>>
>>59262284
XDD ebin maymes, m8
>>
>>59261450
This isn't even a fault of OOP, whoever wrote it is just stupid. This is either a beginner programmer or some weird, self-taught programmer from a third-world shithole.
>>
lto1.exe: internal compiler error: in add_symbol_to_partition_1, at lto/lto-partition.c:202
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper.exe: fatal error: g++.exe returned 1 exit status
compilation terminated.
collect2.exe: fatal error: lto-wrapper returned 1 exit status
compilation terminated.

did... did I break it?
>>
>>59262291
C is for cucks
>>
>>59262272
I dunno. If your code has trouble with that, I'd be inclined to think it's your code that is hackish, rather than the distribution system.
>>
>>59262220
It is true the build system in C and C++ is not very flexible. Thankfully I always managed to get around it with forward declaration, let me know if you find a fix it might come in handy.
>>
>>59262222
asm ("fxrstor [%0];"::"r"(context.data()));

Moving the pointer to a register seems to work too. Good enough I guess.
>>
>>59262316
Lmao. No. Don't believe me. Install these 2 program and try it yourself. Install Gdal and Pyinstaller.

Try create a standalone dist from this file.
import gdal


The program immediately breaks and can't import the module.
>>
>>59260749
Class puzzle:
def __init__(self, boarda, board):
boarda = Matrix( [[a1,a2,a3],[b1,b2,b3],[c1,c2,c3]])
self.width = len(board[0])
self.board = board

Class moveset:
def move_up(state):
new_state = state[:]
index = new_state.index( 0 )
if index not boarda[3:0, 2]:
for i,j in itertools.product(range(self.width),(range (self.width)):
direcs = {'U':(i+1,j)}
return new_state
else:
return none

def move_down(state):
new_state = state[:]
index = new_state.index( 0 )
if index not boarda[3:3, 2]:
for i,j in itertools.product(range(self.width),(range (self.width)):
direcs = {'D':(i-1,j)}
return new_state
else:
return none

def move_left(state):
new_state = state[:]
index = new_state.index( 0 )
if index not boarda[0:3, 0:3]:
for i,j in itertools.product(range(self.width),(range (self.width)):
direcs = {'L':(i,j+1)}
return new_state
else:
return none

def move_up(state):
new_state = state[:]
index = new_state.index( 0 )
for i,j in itertools.product(range(self.width),(range (self.width)):
direcs = {'U':(i,j-1)}
return new_state
else:
return none

def legal_moves()

boarda[0:3, 2:3]
#cannot go right
boarda[0:3, 0:3]
#cannot go left
boarda[3:0, 2]
#cannot go up
boarda[3:3, 2]
#cannot go down

class solver:
def create_node(state, parent, operator, depth, cost, path)


def expand_node( node, nodes ):
expanded_nodes = []
expanded_nodes.append( create_node( move_up( node.state ), node, "u" node.path, node.depth + 1, 0 ) )
expanded_nodes.append( create_node( move_down( node.state ), node, "d" node.path, node.depth + 1, 0 ) )
expanded_nodes.append( create_node( move_left( node.state ), node, "l" node.path, node.depth + 1, 0 ) )
expanded_nodes.append( create_node( move_right( node.state), node, "r" node.path, node.depth + 1, 0 ) )
expanded_nodes = [node for node in expanded_nodes if node.state != None] #list comprehension!
return expanded_nodes
>>
Thinking of starting to learn some graphics programming in C++. Should I go with SDL or SFML? SFML looks a little easier to understand at first glance, but SDL seems more widely used. Would I actually get more out of SDL, or does it not really matter?
>>
>>59262353
def legal_moves is not finished as of yet

def bfs(initialstate, goaltest)
returns success or failure:
frontier = queue.new(start)
explored = set.new()
while not frontier.isempty():
state = frontier.dequeue()
explored.add(state)
if goaltest(state):
return success(state)
for neighbor in state.neighbors():
if neighbor not in frontier U explored:
frontier.enqueue(state)
return failure

def dfs(initialstate, goaltest)
returns success or failure:
frontier = stack.new(start)
explored = set.new()
while not frontier.isempty():
state = frontier.pop():
explored.add(state)
if goaltest(state):
return success(state)
for neighbor in state.neighbors():
if neighbor not in frontier U explored:
frontier.push(state)
return failure

def ast(initialstate, goaltest)
returns success or failure: /*cost f(n)=g(n)+h(n)*/
frontier = heap.new(start)
explored = set.new()
while not frontier.isempty():
state = frontier.deletemin()
explored.add(state)
if goaltest(state):
return success(state)
for neighbor in state.neighbors():
if neighbor not in frontier U explored:
frontier.insert(state)
else if neighbor in frontier:
frontier.decreasekey(neighbor)
return failure
>>
>>59262353
>>59262368
im not even sure if this is close, it's supposed to be a 8puzzle solver, been working on it for a little bit
first project with python and it's pretty dope and easy language, but still tough
>>
>>59262322
>It is true the build system in C and C++ is not very flexible.
You're smoking. Out of the 20+ languages I know, I know no build system that is more flexible than C. The flexibility in building code is perhaps one of its greatest advantages.
>>
trying to make go fish in python. here's some code simplified i was having trouble with.

playerdeck = ['Five of Spades', 'King of Clubs', 'Nine of Hearts', 'Two of Spades',
'Nine of Diamonds', 'Jack of Hearts', 'Four of Clubs']

cards = ['King', 'Queen', 'Jack', 'Ace',
'Two', 'Three', 'Four', 'Five',
'Six', 'Seven', 'Eight', 'Nine',
'Ten']


while True:
for i in playerdeck:
x = input("> ")
if x in cards[0:13]:
print("yes")
elif x not in playerdeck[0:6]:
print("no")
else:
print("yes")


i'm trying to get the user input to only return "yes" if they input the type of card that is in their deck. in this case, five, king, nine, two, jack, or four should return yes. something like six(which they do not have in their deck) would return "no", but i'm having trouble with it. can anyone help?
>>
>>59262485
Small design note: I would make a suits table, then your playerdeck could contain tuples made up of both the suits and the cards tables, like so:
playerdeck = [('Five', 'Spades'), ('King', 'Clubs'), ... etc]
>>
>>59262485
Cards has 13 elements and should go from 0:12 not 0:13.

Also x in cards should be fine. Not need for x in cards[0:13] since you are searching the entire list anyway
>>
Trying to figure out how the fuck to get grub on the disk in Arch.
>>
>>59262579
This is the programming thread, friendo. But if you must know,
grub-install /dev/sda
>>
>>59262559
well in the full script, that list is made up of 7 random objects from another list(deck of 50 cards) but thanks anyway.

>>59262564
it works either way, but the problem i am having is that it will return yes if the user inputs any object from the list "cards", however i only want it to return "yes" if something from the list "cards" is in the list "playerdeck".
>>
>>59262602
Oh I know the command, I'm getting an error.
I thought it was to show what we were working on. I'm working on installing arch.
>>
>>59262626
>262626
Ah, I see. Well, since you're here, what is the error?
>>
>>59262603
>the problem i am having is that it will return yes if the user inputs any object from the list "cards

Well what the fuck do you think these lines of codes were going to do?
if x in cards[0:13]:
print("yes")


>however i only want it to return "yes" if something from the list "cards" is in the list "playerdeck".

So check if the input is in the cards and the playerdeck at the same time?
>>
>>59262639
It either can't find efi directory, or it fails to find a canonical path.
>>
does anyone have experience implementing particle collision detection for hundreds of thousands of particles/millions? I've implemented a quad tree but it is still too slow, is there anything better? This isn't even rendering its just a simulation.
>>
>>59262650
>So check if the input is in the cards and the playerdeck at the same time?
have thought of this but i'm not sure what would do this. i'm pretty new to python and programming. something like this doesn't work:

if x in cards and x in playerdeck:
print("yes")
>>
>>59262681
Well, the strings of your cards and playerdeck arrays are all different from one another, so x will never be in both at the same time. I suggest you reformat your arrays so the naming is consistent in both, like I suggested in >>59262559.
>>
>>59262681
That is cause your string of cards and player deck list don't match one another. in doesn't search the string within the list for you. in must match the string 1 for 1 for it to be true. What you can do is this >>59262724 or

if x in cards and any(x in s for s in playerdeck):
print("yes")


Which is basically creating another for loop to parse through all elements of a string searching for your string.
>>
File: nicecupofgrin.jpg (161KB, 477x494px) Image search: [Google]
nicecupofgrin.jpg
161KB, 477x494px
>>59262724
thanks, i'll keep this in mind in the future.
>>59262749
this worked, thanks a lot.
>>
>>59262805
Its okay to ask for help so long as you understand how it works in the end. Hope you learnt something today anon.
>>
>>59261745
roll?
>>
>>59262851
i
>>
anyone else ever decide to make a game, glue 100 libraries together and make it work, then drop it because they can't make art assets worth shit?
>>
Updating visual studio
>>
>>59262993
>he can only program
>he can't do anything artistic
>>
>>59262993
I'm waiting for source2.

>>59263014
Programming is a form of art.
>>
>750 pages book
Oh boi
>>
>>59262993
Fuck no... That has literally never happened since computers were invented.

Game artists (2D and 3D) are a dime a dozen. I guarantee you that any developer who gets far enough that the art was the only missing piece can easily find an artist. In fact, you can probably find artists willing to work for free, just to build their portfolio, because that's how bad the artist glut is. Art is easy, programming is hard.

If you take on a free artist, will your game look like shit? Maybe. But there is no way a game wouldn't get made at all because of a lack of art.
>>
>>59260749
thank you for using an anime image
>>
>>59263103
Art is not easy, otherwise you wouldn't have people like >>59262993 posting here complaining about it.
>>
>>59263103
Have you done this before? Where do I find free artists?

I have an "isometric rpg" engine/campaign totally finished.

I also have a three-dimensional "realistic physics" space combat strategy game finished with no assets.

Was working on an adventure/side scroller/bullet hell game but I stopped because again, I suck at assets.
>>
>>59262828
also, do you have any idea how i would do a random print of this? like, printing a random thing from the list "cards" but only if it is in the other list "playerdeck".
>>
>>59263159
Append all the cards found in player deck to a list.
Then using a random number generator print a random element from that list.
Simple task. All resources are available on the internet and google. You can do it anon!
>>
>>59263145
You could start over on /3/ or maybe /gd/ for 2D art. Just know that you're going to get what you pay for. You could always try the old trick of offering some percentage of your game's profits, but that's pretty much a meme at this point.
>>
>>59263144
Art is easy. Good art is a little harder, but easy enough that it's still 100 to 1 artists to programmers. That guy is only complaining about not being able to find artists because he hasn't bothered to actually look.
>>
>>59263263
I'm the guy you are talking about
I looked for free artists but they literally make trash or start delivering assets then stop after like 3 models.

Its hard to find someone to give consistent looking assets for an entire game where you need several hundred.

The people who can all want huge piles of cash which I don't want to pay for what is effectively a hobby.
>>
>>59260749
Doing this relatively simple problem and going way overboard because I can.
https://www.hackerrank.com/challenges/between-two-sets

Is there a way faster than integer factorization to find the LCM and GCD of a set? I know there is Euler's algorithm for GCD, and it seems intuitive that you could run a GCD reduce operation on the set to find the set GCD. But LCM is interesting. With two numbers LCM(a, b) = a * b / GCD(a, b), but that would not work for n numbers. You would probably have to use a recursive operation like
LCM(a, b) = a * b / GCD(a, b)
LCM(a, rest) = LCM(a, LCM(head(rest), tail(rest)))

That being said Euler's algorithm is still in the same complexity class and I would have to factor the GCD and LCM anyways for the next part.

I already have a fancy factorization function written in Python, but I'm trying to run it in Lua, and I'm really not looking forward to re-writing that function. Where to go...
>>
>>59263225
well i tried this:
newlist = cards in playerdeck
print(newlist)

but it returns false.
>>
File: 1476540793957.png (34KB, 657x527px) Image search: [Google]
1476540793957.png
34KB, 657x527px
Noob here.
How come my Euler's Sum of PowersConjecture algorithm executes much faster in C than in Python?
>>
Micro controllers, IoT devices, and Node
>>
Hey, so I'm a lazy cunt.

They're making me use Java again. I've already learned Java 3 times, and each time promptly forgotten about everything in the language b/c shit. Obviously I get the basics, and I'm alright in C++ (better than Java, fuck), so do any of you have, like, a reference or crash-course document you like to refer to to pick up on the weird, Java-specific stuff when this happens to you? I can't be the only one, and I don't feel like teaching myself on some Pajeet-tier Java-mill tutor website or based on the errors the compiler spits at me for trying to write code that's actually good.

Cheers.
>>
>>59263426
No. Append it to a new list.
Basically check every element of the playerdeck against your cards and then add to new list. The psuedo code should be something like
for card in playerdeck:
if card in card: (Remember if they don't match 1 for 1 you have to do something about it)
Append all found cards to a new list

Create RNG number from 0 to X where X is the length of the list (Google it)
Print(New List[x])
>>
>>59263468
Since you can program in both C and Python, you should already know the answer to that question.

Stop baiting froggo
>>
>mfw reading Numerical Recipes
>>
in c++ how do you reference an argument written like this
bool Class::randomFunction(const Class&) {
insert const Class& property x here
}
why would someone even written as const Class&?
>>
>>59263707
a const reference is a reference that can't change but the value pointed to can, this is undefined behavior afaik.
>>
>>59262292
While whoever wrote it is retarded, I do feel OOP is over used, and coercing everything into a class hierarchy with getters and setters often over complicates aspects of a program that could have been written in a procedural manner.
>>
>>59263721
What do you mean can't change when i write the main program i can call randomFunction a hundred times with different classes?
>>
>>59262626
Why are you even installing grub? Just have efi boot your kernel.
>>
File: oracle.png (138KB, 221x191px) Image search: [Google]
oracle.png
138KB, 221x191px
The truth has been spoken.
>>
>>59263759
When you call randomfunction you pass it a class by, it takes a reference to this class, AKA, a pointer to the class in memory, this pointer's value can't change because it is const. But you can change the values contained in the class, so you have a const reference, but a mutable object.
>>
>>59263774
But of course the pointers value can't change as the Class I will have passed through it will have already been created before.
>>
>>59263803
It is undefined behavior because const denotes immutable behavior, but the function can modify the contents of the class.
>>
>>59263809
What do you mean by denotes immutable behavior.
>>59263774
>>59263803
I mean to say, I create a class, and therefore its memory location is already solidified in the RAM.
Why would a pointer to this location ever change anyways? When I pass a class through randomFunction who cares if the parameter only takes const Class&?
>>
https://www.youtube.com/watch?v=dl9W7HYS6OY
>very knowledgeable about C
>uses vim
is this /our/ girl?
>>
>>59263768
Uh buddy I don't think God approves of those fancy 24-bit colors...
>>
>>59260768
Quick question, what does this have to do with programming?
>>
>>59263838
I second this inquiry.
>>
>>59263828
you aren't supposed to modify the const reference, if you change values in the class or struct that you got in a function by a const reference it is undefined behavior. If you don't get it I can't help you.
>>
>>59263863
Ok. I understand now what you mean by undefined behavior.
Last question:
bool Passenger::canTravelWith(const Passenger& x) const{
if (this->m_departureDay == x.m_departureDay){

}
After I've written this would it work for any class passed into canTravelWith?
Ex.
classy.canTravelWith(classx)
classz.canTravelWith(classv)
>>
>>59263916
mainly im concerned with the x.m_departureDay and const Passenger& x
>>
>>59263916
using const references to look at values is fine, just don't modify them.
>>
I want to play around with audio in C++. What library is good nowadays? fmod? libsoundio? Or do they not really matter?
>>
>>59263838
What does something which is defined as programming have to do with programming? That's a pretty good question, by which I mean it's retarded.
>>
>>59264021
>C++
Didn't read any further.
>>
>>59263975
>just don't modify them.
isnt that the whole point of const reference, so that the compiler yells at you if you try?
>>
>>59264132
I don't believe it will yell at you if you modify fields with function calls inside a const reference function.

const is for readers, not for compilers... it really doesnt do much.
>>
>>59264030
>something which is defined as programming
Random anime pictures are defined as programming? My mistake.
>>
>>59264251
Anime itself. But yes, you are correct.
>>
struct alignas(0x10) fpu_context {/*blah*/};
fpu_context current_context;
std::clog << "alignof=" << std::hex << alignof(fpu_context) << " ptr=" << (int)&current_context << '\n';

>alignof=10 ptr=24ba28

Am I crazy or is gcc completely ignoring the alignment specifier?
>>
>>59263480
https://learnxinyminutes.com/docs/java/
>>
>>59264030
>>59264275
le animeme xDDDDDDD
>>
>>59264318
>C++ iostreams
Jesus Christ. How do people defend this shit?
I don't know about meme++, but in C, alignas doesn't work on types like that. They only work on individual variables.
GCC even warns about useless alignas'.
>>
>>59264405
is this some new plebbit meme?
>>
>>59260994
if-then-else is built into Haskell, but they could be implemented as a library (with slightly different syntax)
>>
>>59264494
oh, didn't see your second comment, sorry
>>
>>59264417
Doesn't seem to do anything even on the variable itself. It's supposed to work with types though: http://en.cppreference.com/w/cpp/language/alignas
Guess I'll have to do my own alignment then if I can't rely on gcc supporting basic language features...
>>
>>59260771
>EO (stands for Elegant Objects or ISO 639-1 code of Esperanto) is an object-oriented programming language.
autism
>>
>>59264551
It werks for me.
It's probably because you're casting a pointer to an int, and that loss of precision is causing you to print the wrong result.
It wouldn't even let me compile code that had that cast.
>>
>>59264589
It's crashing hard because SSE instructions need the 16 bytes alignment, and the variable is only aligned to 8 bytes. I don't think casting a pointer to int has anything to do with that (how would that lose precision anyway?)
>>
>>59264626
>how would that lose precision anyway?
On my system at least, a pointer to 64 bits, and an int is 32 bits.
If you ever need to cast a pointer, you should ALWAYS use (u)intptr_t. But since you're just printing it, I don't think you even need to cast it.
>>
>>59263834
kek
>>
>>59261745
I never liked 2.0 personally
but whatever im bored
>>
Why is cmake never working?
99% of the time, it fails to find a package, it doesn't matter if the files is in /usr/share or /usr/include or /usr/local
>>
>>59265147
>C
>working
Top kek, m8
>>
@59265259
>>>/r/ibbit
>>
59265288
>>>/out/9gag
>>
>>59265259
what font and color scheme?
>>
>>59265259
I said cmake.
It is a tool everyone uses to compile stuff and automatically find packages, except it never finds packages
>>
>>59265333
Checked

Fira mono, Monokai
>>
I'm new to Python. Is there a way to subtract all the elements from one list from another?

Say I had [1,2,3,4,5] and [1,2,3]; could I do something that leaves the first list with [4,5] remaining? sorry this is basic but I couldn't find stuff on google
>>
>>59265427
apply yourself
>>
http://www.phoronix.com/scan.php?page=news_item&px=Ada-Doom-3
>rewriting doom3 in ADA
lol
>>
>>59265477
>>> list=[1,2,3,4,5]
>>> list2=[1,2,3]
>>> list-list2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'list' and 'list'


mom i tried
>>
>>59265427
for i in listb:
lista.remove(i)
>>
DAILY REMINDER THAT THE THREE ESSENTIAL PROGRAMMING LANGUAGES ARE:

0. C
1. Lisp
2. Javascript

This covers literally ALL bases and there is no reason to learn anything else
>>
>>59265504
What the fuck are you even thinking?
>>> lista = [1, 2, 3, 4, 5]
>>> listb = [1, 2, 3]
>>> listb.remove(3)
>>> print(listb)
[1, 2]
>>> listb.append(3)
>>> print(listb)
[1, 2, 3]
>>> for i in listb:
... lista.remove(i)
File "<stdin>", line 2
lista.remove(i)
^
IndentationError: expected an indented block
>>> for i in listb:
... lista.remove(i)
...
>>> print(lista)
[4, 5]
>>
Mozilla
>made js
>SJW politics
>made rust
Is mozilla trying to drown us in shit or what?
>>
>>59265529
>>59265506
this is exactly what I needed thank you sorry I have no experience in python
>>
>>59265547
wtf i hate mozilla now
>>
File: FoCpG.jpg (185KB, 890x670px) Image search: [Google]
FoCpG.jpg
185KB, 890x670px
>>59265506
>>59265504
>>59265529
l=l[3:]
>>
>>59261279
Are you flushing the buffer?
It might be getting a \n from the previous read and using that to evaluate
>>
>>59265617
if I were writing a sudoku solver and was trying to check the constraints for the smaller 3x3 boxes would there be a more clever way of doing it than basically what that pic has

I've been drawing a blank for awhile now but I feel horribly guilty writing
if a <= 3 and b <= 3
squarelist = [prob_easy[i][0:3] for i in range(0,3)]
elif a <= 3 and 3 < b <= 6
squarelist = [prob_easy[i][3:6] for i in range(0,3)]
elif a <= 3 and 6 < b
squarelist = [prob_easy[i][6:9] for i in range(0,3)]
elif 3 < a <= 6 and b <= 3
squarelist = [prob_easy[i][0:3] for i in range(3,6)]
elif 3 < a <= 6 and 3 < b <= 6
squarelist = [prob_easy[i][3:6] for i in range(3,6)]
elif 3 < a <= 6 and 6 < b
squarelist = [prob_easy[i][6:9] for i in range(3,6)]
elif 6 < a and b <= 3
squarelist = [prob_easy[i][0:3] for i in range(6,9)]
elif 6 < a and 3 < b <= 6
squarelist = [prob_easy[i][3:6] for i in range(6,9)]
elif 6 < a and 6 < b
squarelist = [prob_easy[i][6:9] for i in range(6,9)]
>>
>>59265617
Cause that removes all elements in one list from another.
>>
>>59261757
They do use the decimal values, the other anons are probably java Indian monkeys who don't know jack shit about C
>>
>>59265617
Are you fucking dense? That doesn't even come close to removing the contents of one list from another.
>>
File: steve-jobs.jpg (34KB, 1100x644px) Image search: [Google]
steve-jobs.jpg
34KB, 1100x644px
>>59265655
>>59265702
i didn't actually read that post, i saw two lists and it just clicked, what can i say, i am a genius
lb = [x for x in lb if x not in la]
>>
>>59264151

>I don't believe it will yell at you if you modify fields with function calls inside a const reference function.

Test.cpp:
struct Foo {
int x;
int y;
};

void ModifyFoo(const Foo& foo)
{
foo.x = 2;
}


Attempts to compile:
rubyist@Overmind:~/cs/scratch$ g++ -std=c++14 test.cpp
test.cpp: In function ‘void ModifyFoo(const Foo&)’:
test.cpp:8:8: error: assignment of member ‘Foo::x’ in read-only object
foo.x = 2;
^
rubyist@Overmind:~/cs/scratch$ clang++ -std=c++14 test.cpp
test.cpp:8:8: error: cannot assign to variable 'foo' with const-qualified type 'const Foo &'
foo.x = 2;
~~~~~ ^
test.cpp:6:27: note: variable 'foo' declared const here
void ModifyFoo(const Foo& foo)
~~~~~~~~~~~^~~
1 error generated.
>>
>>59261745
>Typing speed calculator
>Fizzbuzz
>Unit converter
>fib sequence
>factorial
>Given an IPv4 address and subnet mask, compute the network, broadast and forst/last host addresses
Some of these aren't like the others.
>>
File: 1486678895770.png (122KB, 262x207px) Image search: [Google]
1486678895770.png
122KB, 262x207px
Is anime POSIX compliant?
>>
>>59265652
squarelist = [prob_easy[i][((b - 1) // 3) * 3:(((b - 1) // 3) + 1) * 3] for i in range(((a - 1) // 3) * 3:(((b - 1) // 3) + 1) * 3)]

That should work for 0 < a,b < 10.
>>
>>59265510
C is trash
>>
>>59265547
>Made JS
>Made Rust
Best languages
>>
>>59265510
>0.
Wow! Are you a hacker? It's so cool that you count from zero!
>>
>>59260749
I've been working on this in my spare time when I'm not stressed out from my day job.

https://github.com/suiginsoft/hebimath
>>
>>59265902
whats with the cringy webm?
>>
>>59265916
Fuck you that music is pretty comfy
>>
>>59265864
Can you explain what's going on here? I'm a bit dense and don't quite follow

I tried running it as is and it threw a syntax error and my python is straight garbage
>>
>>59265902
what anime was this from?
>>
>>59265916
It was some joke content for the community I used to belong to (the backup site for the old world4ch /prog/ text board), but the site for it died the other day because the admin got bored I guess. Need to find a new home.
>>
>>59265735
In Lisp, this is just
(set-difference x y)
>>
>>59264379
This is great, thanks.
>>
>>59265979
are you from plebbit?
>>
>>59265974
I accidentally put a colon in the range function.

Anyways, I'm assuming a and b are coordinates in a 9x9 sudoku board, and that you're trying to address each 3x3 inner square (called a nonet in case you were wondering). Because you're code had a and b equaling the upper bound of a square (for example b <= 3) I assumed your coordinates went from 1-9, and not 0-8 like array indexes normally do.

So, as far as what my code attempts to do, you need to get the address range of the nonet the point you are given falls into, 0-2, 3-5, or 6-8.

Because it appears that a and b are 1-9 and not 0-8 like the array is, the first thing I did was subtract these values by 1 so that they look like array indices; 0-8. then, to get the lower bound of the nonet it is in, I did integer division (*Note* this is different between Python 2 and 3. I'm using Python 3, which requires // to force integer divison. If you're using Python 2, replace each // with /.) on the index by 3. This gives a number of the corresponding nonet, because 0-2 equals 0, and so on for 1 and 2. I then multiply this number to get the starting value, 0, 3, or 6. For the ending value I go through the same process, but add one before multiplying by three to get 3, 6, or 9. I then repeat all of this for the other value.

I originally wrote this algorithm for a sudoku game/solver I wrote in C++, and just quickly translated it to fit the code you provided.
>>
>>59264494
It is built in, but its just syntactic sugar for
case expr of
True -> thenbranch
False - > elseBranch
>>
>>59261745
>Scorched Earth clone
>That fucking nostalgia
>>
const uchar4* const rgbaImage


What's this in C? why is const twice?
>>
>>59266150
It's a constant pointer to a constant uchar4
>>
>>59266163
What's a pointer? Sort of like an object?
>>
>>59266171
Yes.

It's exactly like an object.
>>
>>59266171
It's a variable that holds an address in memory.
>>
>>59266117
This was fantastically helpful, thanks a bunch! I'd buy you a drink. I knew there had to be a better way than the mess I churned out
>>
>>59266179
Thanks
>>59266191
How is that an object?
>>
>>59266198
>How is that an object?
What definition of object are you going on?
In terms of C, and objects is basically anything which requires storage.
>>
>>59266206
I'm from an OOP background.
>>
>>59266198
It's not. But Object variables in Java are stored and passed around in a similar fashion.
>>
>>59266219
Oh, so it's sort of like a library then?
>>
New thread:
>>59266231
>>59266231
>>59266231

>>59266230
No. He's probably giving you misleading information deliberately.
Just google "what is a pointer" or some shit. There was a handy image explaining it for beginners, but I don't have it saved.
>>
>>59266196
BTW you can repurpose your solver as a random state scrambler. Most fags scramble with random moves but random moves does not guarantee a random scramble. Random moves make easier scramble show up more often. It's not as a big deal when working with 8 puzzles but when doing 15 puzzles it's noticeable and pain obvious on higher order ones.
For scrambling:
>generate random state
>check parity to see if it's possible to solve
>if impossible go to step 1
>else solve it
>print out the inverse of the solution as the scramble
>>
>>59266230
Why do OOP people always have such extreme trouble understanding pointers? They're not exactly rocket science.
>>
>>59267107
>OOP people
>people
mate...
>>
>>59260801
Can you put your code into a pastebin?
Thread posts: 320
Thread images: 20


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.