[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 15
File: DPT.png (389 KB, 934x1000) Image search: [Google]
DPT.png
389 KB, 934x1000
Old thread: >>51832664

What are you working on /g/?
>>
>>51837369
>I'll go with this one

Studying NVidia's Thrust library code atm.
>>
>>51837423
In the section I'm in atm, it's filled with stuff like this
template <typename ForwardIterator, typename T, typename StrictWeakOrdering>
bool binary_search(ForwardIterator first, ForwardIterator last, const T &value,
StrictWeakOrdering comp) {
using thrust::system::detail::generic::select_system;

typedef typename thrust::iterator_system<ForwardIterator>::type System;

System system;

return thrust::binary_search(select_system(system), first, last, value, comp);
}


and this
template <typename ForwardIterator, typename LessThanComparable>
thrust::pair<ForwardIterator, ForwardIterator> equal_range(
ForwardIterator first, ForwardIterator last,
const LessThanComparable &value) {
using thrust::system::detail::generic::select_system;

typedef typename thrust::iterator_system<ForwardIterator>::type System;

System system;

return thrust::equal_range(select_system(system), first, last, value);
}
>>
int avg(int a, int b)
{
return (a & b) + ((a ^ b) >> 1);
}
>>
File: 1408864773877.png (136 KB, 300x300) Image search: [Google]
1408864773877.png
136 KB, 300x300
>trap thread is shitposting
>real thread has actual code
>tfw you know the mods are gonna delete the real thread anyway
>>
>>51837541
>*phones patent lawyer*
>>
>>51837567
k tard. the patent is for a one-cycle circuitry, not the algorithm itself.
>>
>>51837541
>literally the equivalent of (a+b)>>1
Let's change your code for a moment.
int sum(int a, int b)
{
return (a&b) + (a^b);
}

At this why not write (a+b)>>1 and be done with it.
>>
>>51837653
heh, jest messin with ya anon.

>>51837112
BTW, chatbot guy, I recommend you check out FACS, the facial action coding system for some research ideas about emotion display for you're bots avatars. catch you later anon, I'm out.
>>
>>51837698
>At this why not write (a+b)>>1
integer overflow, dumbass
>>
Anyone doing AoC? (Advent of Code) currently working on the python Meme right now
>>
What's a good casual filter?
>>
>>51837773
invert binary tree
anything recursive
>>
File: d.jpg (36 KB, 452x335) Image search: [Google]
d.jpg
36 KB, 452x335
What the fuck do I do
>>
>>51837862
Make L buffer bigger
>>
>>51837873
wut how
>>
>>51837862
Change 0 to 1.
Problem solved.
>>
>>51837910
best advice t b h
>>
Why did they make Rust's syntax so cancerous?

I like the language in principle, but the syntax is absolutely disgusting.
>>
>>51838032
There were probably too many C++fags working on it.
>>
>>51838032
well, you could at least give us a couple of relevant examples.
>>
>>51838106
self.next_table_address(index)
.map(|t| unsafe { &*(t as *const _) })
>>
File: 1449902438494.png (444 KB, 800x600) Image search: [Google]
1449902438494.png
444 KB, 800x600
>>51838152
>>
>>51838152
What alternative syntax would you propose to that? I don't see anything there that you wouldn't have to express some way or another.

Personally, I'm glad there's a modern programming language out there that focuses on more important things than just being pwetty and "simple" yet again. Syntax is just some shit to get used to at the start of learning a programming language, people have had no trouble in the past developing in languages with terrible syntax like C++ and Perl (and Rust's not even close to thse two).
>>
>>51837800
>invert binary tree
Do you mean just recursively swap the leaves? Never heard of this before.
>>
>>51837862
Kek, I was playing Dwarf Fortress and some shitty meme error like this popped up so I debugged it in VS and just told it to execute the asm right after the assert :^)

I am such a l33t h4x0r, lol!
>>
>>51838265
What the fuck? NOTHING in C++ is even close to that abomination of Rust code. Maybe templates, I don't know, I don't use that shit, but the rest is kinda gross but not nearly as horrific as Rust.
>>
>>51837369
(define (ayyy x)
(x (lmao x)))
(define (lmao x)
(x (ayyy x)))
(call/cc (ayyy lmao))
>>
>>51838284
You're not the only one who's confused:

https://twitter.com/mxcl/status/608682016205344768
Reddit comments (of people speculating what the hell it means).

https://www.reddit.com/r/programming/comments/39d0u1/google_90_of_our_engineers_use_the_software_you/

As for me, I'm going to go with reversing the direction of the arrows, so it becomes a directed graph with multiple roots and a single leaf, because fuck these shitty interview questions.
>>
>>51838152
where the ugliness ? everything here look fine and rarely used.
>>
>FPfags can't swap two ints
a ^= b ^= a ^= b;

I shiggy diggy doo
>>
File: 1449770604280.jpg (11 KB, 264x264) Image search: [Google]
1449770604280.jpg
11 KB, 264x264
How the fuck do I multiply a mat by a number with glm? It's just vomiting 500 pages of errors at me.
>>
>>51838342
You mean a scalar multiply?
>>
>>51838352
Yes.
>>
File: sussman shig.jpg (71 KB, 500x375) Image search: [Google]
sussman shig.jpg
71 KB, 500x375
>>51838335
(set! a (set! b a))
>>
Ok /g/ what should you call an arbitrary list in Python? list is a builtin and l breaks PEP8 and the compromises between these sound stupid. a as in array?
>>
Novice here.

http://pastebin.com/9zJzbhZZ

How would I set the input checks to run in sequence until they are all true and then have the code at the bottom run (without nesting if statements within if statements, assuming that there isn't a cleaner way of doing it).
>>
>>51838032
Dunno, but looking forward to someone building a Prolog DSL with its macros.
>>
>>51838489
muh_list
>>
>>51837555
>trap thread deleted
assertEquals(MODS, GODS);
>>
>>51837369
Implementing the WOOT spec in glorious elixir.

defmodule Operation do
import WChar

@type operation_type :: atom
@type operation_client_id :: integer
@type operation_wchar :: WChar.wchar
@type operation :: {operation_type, operation_client_id, operation_wchar}
end
>>
I'm implementing linked lists in C and have a small question: does the use of a sentinel node instead of a null pointer provide any actual benefit? (assuming I always keep pointers to the first and the last nodes in a separate struct)
>>
>>51838491
I should probably ask my questions better.

How would I check each input in order, from top to bottom, and then make a thing specific to that input occur? does using && in an if statement allow me to check which operand has failed so I can throw an error specific to that input?

I'm aware I could nest if statements but that seems like a heavy handed and stupid approach to it.
>>
>>51838563
Well Google'd
>>
>>51838152
Can someone tell me what that abomination is supposed to do? Deciphering esolangs isn't really my thing.
>>
>>51838617
Rust is at the forefront now m8
>>
>>51838563
Not really.
>>
>>51838152
Calls some function on a struct (which probably returns an iterator or Result), then maps it to a raw const pointer.
>>
>>51838669
Forgot to link post: >>51838617
>>
>>51838491
>>51838577
What's the problem with the code in the pastebin? Just add a not to the if so that you don't need a blank if body.

>does using && in an if statement allow me to check which operand has failed
No
>>
>>51838527
For people interested, though you are probably not since you are all neets doing fizzbuzzes:
WOOT is a shorthand for WithOut Operational Transformation.
It's a specification for creating real time collaborative editing.
Google docs use operational transformation but it's really hard to implement and test so some clever guys invented an alternative to implement it more easily and gain better performance.

Here is the research paper: https://hal.inria.fr/file/index/docid/71240/filename/RR-5580.pdf
>>
Is there an equivalent of SQL Server Compact Edition that I can use on not-Windows (database engine that runs in process, on a single flat file).
>>
>>51838723
Well I want to have a piece of code run if all the statements are true, but that would mean making a bullshit nested statement.

If I have a bunch of if's at the top there and they are all met, how can I run my piece of code without nesting the ever loving fuck out of it?
>>
>>51838527
elixir looks gay as fuck.
>>
>>51838779
SQLite
>>
File: 1444964861075.png (307 KB, 500x500) Image search: [Google]
1444964861075.png
307 KB, 500x500
What IS /dpt/ actually working on? I never browse these threads.
>>
>>51837800
>anything recursive
Why? I didn't think they were particularly difficult when I learned about recursion. Am I missing more advanced uses of it?
>>
>>51837369
Using Xlib, how can I get the image of a window even if it is behind another window?

Is that even possible?
>>
>>51838838
Valutron
>>
how do i implement kleene * and +
http://lpaste.net/3022573596653387776
>>
>>51838792
Change positive ifs to negative ones, and use goto if you have common cleanup code.
if (cond1) {
if (cond2) {
if (cond3) {
// stuff
cleanup3();
}
cleanup2();
}
cleanup1();
}

vs
if (!cond1)
goto error1;

if (!cond2)
goto error2;

if (!cond3)
goto error3;

// stuff

error3:
cleanup3();

error2:
cleanup2();

error1:
cleanup1();

This is a pretty common way of coding in C.
>>
>>51838792
If you don't need to do anything else you could return when any of the checks fail. Otherwise you can keep a variable to tell you if anything has failed.
bool all_ok = true;
if (!a) {
// a failed
all_ok = false;
}
if (!b) {
// b failed
all_ok = false;
}

// check everything else ...

if (all_ok) {
// all checks passed, do stuff ...
}
>>
>>51838491
Write a method to DRY up your code, e.g. (changing syntax accordingly, I don't know C#):

def fail_with_message(msg)
txtVersion.Focus();
txtVersion.Clear();
txtVersion.ToolTip = msg;

Then do

if (!Checker.VerNumberCheck(txtVersion.Text)){fail_with_message("Please enter a version number")}

etc. General rule is to put repeated code into a method somehow and then call the method wherever you need it. If you're using a non-shitty language that has first class functions/methods you could associate VerNumberCheck with the error message using a hash.
>>
>>51838838
Implementing mpg123.
>>
I've just completed day13 of AoC, using brute force.
Is that problem NPC?
>>
>>51838887
http://pastebin.com/J5W9fFxB

It's hideously inelegant but it works, I for some reason decided to test it like this instead of creating true/false methods which do that for me, what can you do though, I'm a novice.
>>
>>51838867
It's not hard but casuals claim that it's hard.
>>
>>51838803
I only made some type defs in that module though.
But thanks :^)
>>
>>51839123
What I showed you is pretty simple and straight forward. You do have a lot of repetition in the code so you might want to look at what >>51838911 recommended. Also, don't put more than one statement on a line, it just makes things more difficult to read.
>>
>>51837369
should I learn GANOO/LOONIX for learning C?

i think unix might be viable to work in, especially considering it and linux were both written in C.
>>
>>51839298
Linux won't help you learn C. It's a fun endeavour that will teach you about operating systems and you can use your future C knowledge on it, not the other way around. It's cool to have GCC available just by opening a terminal though
>>
is studying suckless.org software a good place to start if i want to learn about c software?
>>
>>51839298
That's not the point. The GNU+Linux operating system makes it easier for a developer to work in.
>package repo
>bash
>>
>>51839742
>That's not the point. The GNU+Linux operating system makes it easier for a developer to work in.

[citation needed]
>>
>>51839771
Microsoft plz.
>>
>>51839782
>Can't back up his statements
>>
>>51839791
Have fun using MinGW :D
>>
>>51837541
>>51837698
no workee
>>
>>51839854
what input values? worked for me when i tried it
>>
>>51839854
oh the sum function in >>51837698 doesn't work. disregard him he's retarded
>>
In Python, I'm making an IRC bot. Bot fetches data and handles it with an infinite while-loop; however, I want to implement functionality with API polling; this means I'll have to thread, as it'll only need to poll every minute or so, and using sleep() will time out the IRC connection since it'll stop responding to pings.

This means I'll likely have to use threading. Can anyone give me some pointers on how to do this? I've never tried before.
>>
File: 1433270580562.jpg (25 KB, 369x457) Image search: [Google]
1433270580562.jpg
25 KB, 369x457
http://codeblog.jonskeet.uk/2014/07/16/micro-optimization-the-surprising-inefficiency-of-readonly-fields/
>C# masterrace
>>
>>51839958
Can't you just sleep(0)

>inb4 someone bitches about CPU power usage
>suck my balls, spinning on a while loop doesn't cost anything
>>
>>51839811
what's wrong with MinGW?
>>
>>51839900
>tried 2 values
>works for me
classic webtard
>>
>>51839958
>doing something as quality-critical as threading in fucking python
use a different language

>>51840004
idiot
>>
I don't know if I should ask you guys or /sci/, but that place is deader than disco and this thread isn't. Anyway.
I've got a statistics project to do, and part of the question is we have to do Monte Carlo studies on a M/M/3 server, with the distributions being Gamma(6,4 min^(-1)), Exponential(0.3 min¨(-1)) and Uniform(7 min, 12 min).
We have to work with R for this.

My question is: do I simulate each distribution seperately, or should I somehow fuse the distributions together? I'm thinking the first, but I suck such ass at statistics it could be the second.
>>
>>51840020
you fucking retard

i tried it with a bunch of values such as -2000000000 and -2100000000 among others

i asked anon to provide an example of when it wouldn't work because it does work (as far as i know). IDIOT
>>
>>51840004
sleep(0) will not help me in any way; I can't stop the while loop because the connection will die and I can't flood the API with hundreds of requests every second because I'll be blacklisted.

>>51840028
I'm a noob; I'm not looking for a perfect or optimal solution. Just any solution; I need a thread that can sit on an infinite while loop with a sleep(60) in it that will poll the API, and a thread that handles the IRC connection.
>>
>>51840010
http://mingw.org/wiki/Getting_Started
While you could just install Linux.
>>
>>51840056
What? In your while loop, grab the time, check to see if a second, or 2 seconds, or whatever has passed, and if so, issue your request to the API. Otherwise sleep(0).
>>
>>51839287
Yup, moved most of it over to a seperate method now.

At the moment I'm struggling with setting up a list of controls for an animation.

I have List<Control> which will accept most things, but I can't add "Image" because for some reason it's not considered to be a control in this instance, even though it's listed as a control everywhere else.

The fuck am I meant to do about this shit?
>>
>>51840063
all i did was install it and i'm using it just fine in eclipse thank you
>>
>>51839123
>http://pastebin.com/J5W9fFxB
Looks ok functionally, but those multiple statements in single line are absolutely retarded.
>>
>>51840028
IO threading is fine retard
>>
>>51840072
Holy fuck, I actually didn't think of is.

You are a holy beast.
>>
Currently puzzling my way around continuations.
>>
>>51840046
>such as -2000000000 and -2100000000 among others
were -1 and 0 "among others"?
>it does work (as far as i know)
and what you know is shit
now fuck off, css kid
>>
>>51840075
>eclipse
I'm done talking to you.
>>
>>51840084
Eh, I can live with multiple statements on a single line, especially seeing as I moved most of it over to a method.

I usually don't do it but in this case it was a fuckugly mess so having it like this is fine by me.


Also as I said in a post up there, why is an "Image" in wpf a control but not a control. It won't let me place it in a list of controls but it inherits all the properties of a control.

This seems ass backwards.
>>
>>51840095
so was it so hard to answer >>51839900 with -1, 0 fucking retard

i just got it off of stackoverflow, i don't care

this works though:

int avg(int a, int b)
{
return a / 2 + b / 2 + (a % 2) & (b % 2);
}
>>
>>51838314
I was asked this question in a Google interview. They don't just say "invert a binary tree gogogo", they give you a clear specification of what you are to do, with an example. Also, it's really not a hard question. I wasn't aware of the "invert binary tree" meme beforehand, and it's not something I ever studied for. But I was able to solve it pretty easily just by thinking about it on the spot.

The idea that it's just some stupid academic question you study for and then never use is wrong. It's a fairly basic question if you have a reasonable level of knowledge of data structures and recursion.
>>
>>51840129
int avg(int a, int b)
{
return a / 2 + b / 2 + ((a % 2) & (b % 2));
}
>>
>>51840138
this. anyone who calls himself a programmer should be able to do it just fine
>>
>>51840129
>was it so hard to answer
>muh bunch of tested values
>muh copy pasta
that's why you're a retard that should just gtfo of programming threads
>>51840144
and it still doesn't work, you fucking buffoon
if you were remotely competent you'd clearly see it fails for -1 and 1 (and this is ignoring the fact you have no idea about signed numbers representation in C)
please stop trying to come up with a solution by chance if you don't know C worth a shit
if case you haven't figured it out: you're the retard in this discussion
>>
File: u mad tiny.jpg (34 KB, 543x427) Image search: [Google]
u mad tiny.jpg
34 KB, 543x427
>>51840204
>>
>tfw no one knows how to average two ints in C
>>
>>51840224
>muh "I got told" meme
>>
how can i stop the parser if it cant parse anything more?
data Parser a = P (String -> [(a,String)]  
some :: Parser a -> Parser [a]
some v = (:) <$> v <*> (some v) <|> success []
>>
>>51840253
except this big dick playa
>>51839854
>>51840020
>>51840095
>>51840204
>>
>>51840129
>just got it off of stackoverflow, i don't care
>stackoverflow
back to /wdg/
>>
>>51840129
>this works though
got that one from quora now?
>>
>nearly finished implementing mpg123
>aubio already handles audio decoding
REEEEEEEEEEEEEEEEEEE
>>
>>51840072
>>51840086
I've run into a problem: that while loop will only trigger upon receiving a message from the server; if there is nothing for longer than my timeout, the time comparison won't run until there is a message.

while 1: # Be careful with these! it might send you to an infinite loop
# API handler
if (datetime.datetime.now() - apitimer).seconds > 15:
apitimer = datetime.datetime.now()
print(datetime.datetime.now())

ircmsg = ircsock.recv(4096) # receive data from the server
ircmsg = ircmsg.strip('\n\r') # removing any unnecessary linebreaks.
>>
>>51840296
It's not particularly difficult, some hints:
If the numbers have different signs, (a+b)/2 works, can never overflow.
Otherwise you just need to use a form of a+(b-a)/2, flip some signs or swap a and b depending on order.
>>
>>51840432
>branches
disgusting
>>
>>51840432
that's way too difficult for the average fizzbuzz-failing /g/ tard
>>
>>51840451
it can't be done without them
>>
>>51840425
>what is select
>>
>>51840451
In portable C you can't do it without branches, but if you're allowed to assume two's competent for example you can create masks and select one result or the other branchless using bitwise operations - although whether that is actually faster is another matter, becomes a really long dependency chain.
>>
go fuck yourselves with this "average 2 ints" derailing bullshit.
>>
>>51840465
cast to unsigned, take average of that, convert result back to signed
>>
>>51840487
This. Why does anyone think this is an actual issue?
>>
>>51840498
conversion is implementation defined
>>
>>51840471
How would I implement this? Can you give me some pointers? I have zero experience with this.
>>
>>51840487
>>51840506
>we want animu & traps in our dpt
>we're not here to talk about programming
anons...
>>
File: 1449987517752.png (121 KB, 264x257) Image search: [Google]
1449987517752.png
121 KB, 264x257
Hey guys is there any way to call the 4chan api directly from with JS using a Ajax call? I know the official 4chan JSON has Cross-Origin Requests disabled. There is no one out there that has a public wrapper and hooks enabled for Cross-Origin Requests? I'd really like to access that data from the client using JS.
>>
>>51840506
If this was an actual issue, we'd be using GMP instead of complaining about muh overflow.
>>
For the day 5 part 2 of AoC, I did this brute-force code:
http://pastebin.com/xTXttjcw

Now, it didn't give me the right answer, while I did find the right one with python + regex, I'd like to know what is wrong with this. The right answer was 69, this one gives me 66. Does anyone knows why?
>>
>>51840517
use select with a timeout to either be notified when you have something incoming on the socket or the timeout elapsed, in which case you do whatever you have to do periodically
>>
>>51840521
k, now go shitpost about averaging two ints and how no one would have this problem in Python and "C sucks"
>>
>>51840523
>I'd really like to access that data from the client using JS.
I'm pretty sure you can so long as you're running off you local machine.
>>
>>51840524
>web 2.0 generation
>need to add 2 numbers?
>there's an API for that!
>>
>>51840540
>how no one would have this problem in Python and "C sucks"
why? I don't advocate programming for complete brain dead retards
>>
>>51840509
>Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type.
>>
>>51840540
>muh /wdg/
>muh homescreen thread
>muh animoo
>>
>>51840547
no..
>>
>>51840572
>convert result back to signed
are you even trying?
>>
>>51840581
no? In my experience a lot of the security shit is disabled when you're running web shit off your local file system. I guess it lets you do whatever you want when the only place the code can run in on your own machine.
>>
>>51840611
what are you even talking about? The API does not support JSONP
>>
Why is my regex_search on c++ not find any fine string on AoD day 5 part 2?
while (std::getline(File, line)) {
if (std::regex_search(line, std::regex("(..).*\1")) && std::regex_search(line, std::regex("(.).\1")))
good_string += 1;
}

It always gives me 0.
>>
>>51840534
ready = select.select([ircsock]), [], [], 15)


  File "ircbot.py", line 94
ready = select.select([ircsock]), [], [], 15)
^
SyntaxError: invalid syntax


Syntax is exactly as in the documentation...
>>
>>51840654
holy fuck that was retarded

never mind
just

forget about this one
jesus
>>
https://benchmarksgame.alioth.debian.org/u32/compare.php?lang=v8&lang2=python3
why do people use python if v8 javascript is way faster than it
is there anything python does that js can't do
>>
>>51840664
>anything python does
the language is not shit
huge stdlib
assload of 3rd party libraries
>>
>>51840584
(n & INT_MAX) - (n & (UINT_MAX - INT_MAX));

something like that

HOW CAN YOU BE THIS FUCKING RETARDED

it's specifically why i said convert back to signed, not cast
>>
>>51840528
That's an awful lot of code for a simple task.

My C solution was pretty much the same thing except in fewer lines: http://pastebin.com/g6i67WMC
>>
To average two ints in C: (a/2) + (b/2) wouldn't work?
>>
>>51840204
"Im trying to learn, here is what I'm trying right now."

Anon: It's wrong you didnt learn it.

"But I'm still learning, anon"

Anon: Well stop trying to learn bc it's clear you haven't learned.

>They're talking about a formula based on a specific syntax...

I wish you would stop.
>>
>>51840729
ints get truncated. (1 / 2) + (1 / 2) would be 0 when 1 would be the correct result
>>
>>51840729
No, because of overflow.All these autists don't want to just admit that storing the temp value in a long long and then casting back down to int is the right way to go.
>>
>>51840722
Being programming for 2~3 weeks now, if I can use that as an excuse.
>>
>>51840743
then how do you average two long long ints in C
>>
>>51840755
You use floats because your toy program doesn't need to fucking do that accurately.
>>
>>51840635
what kind of string are you trying to match? not everyone knows what the fuck aod is
>>
>>51840770
AoC*
http://adventofcode.com/day/5/input
>>
>>51840722
Btw, you code is great. Learn something good with him, thanks.
>>
>>51840704
>something like that
that's not converting anything
>HOW
looks like you're the retard
>>
>>51840781
I'm not gonna register for that
just post an example string you wanna match
>>
>>51840766
floats are too small
>>
>>51840584
>>51840704
unsigned int nig = (n & (UINT_MAX - INT_MAX));
int nog = nig - (nig != 0);
return (int) (n & INT_MAX) - nig - (nig != 0);
>>
>>51840743
>casting back down to int
>right way to go
for webc᠎ucks maybe
for competent programmers, no
>>
>>51840796
YOU ARE THE FUCKING RETARD

I DIDN'T BOTHER SPELLING IT OUT FOR YOU BUT NOW I DID SO HERE: >>51840807

FUCKING RETARD FUCK YOUR FUCKING FUCK ASS
>>
>>51840807
>int nog = nig - (nig != 0);
as already said: implementation defined
>>
>>51840819
Are you dense? If you average two integers, the result is going to be an integer. You only temporarily store the sum in a long long, then immediately divide the temp value by two and cast back down to an int because it's guaranteed to be less than INT_MAX
>>
>>51840804
mayosiswqqrdiqq
This is supposed to give a good string.
>>
>>51840821
don't get mad when you get told; happens to every retard on /g/
maybe go back to css?
>>
>>51840835
>temporarily store the sum in a long long
which can overflow
>>
File: cuck.jpg (158 KB, 1000x1000) Image search: [Google]
cuck.jpg
158 KB, 1000x1000
>>51840819
>competent programmer
>not using multiple precision arithmetic
>having to assure that for all big calculations there aren't overflows
>>
>>51840804

Because >>51840842 is apparently an autist and can't figure out basic instructions, here's the "challenge":
/*

--- Day 5: Doesn't He Have Intern-Elves For This? ---

Santa needs help figuring out which strings in his text file are naughty or nice.

A nice string is one with all of the following properties:

It contains at least three vowels (aeiou only), like aei, xazegov, or aeiouaeiouaeiou.
It contains at least one letter that appears twice in a row, like xx, abcdde (dd), or aabbccdd (aa, bb, cc, or dd).
It does not contain the strings ab, cd, pq, or xy, even if they are part of one of the other requirements.

--- Part Two ---

Realizing the error of his ways, Santa has switched to a better model of determining whether a string is naughty or nice. None of the old rules apply, as they are all clearly ridiculous.

Now, a nice string is one with all of the following properties:

It contains a pair of any two letters that appears at least twice in the string without overlapping, like xyxy (xy) or aabcdefgaa (aa), but not like aaa (aa, but it overlaps).
It contains at least one letter which repeats with exactly one letter between them, like xyx, abcdefeghi (efe), or even aaa.
For example:

qjhvhtzxzqqjkmpb is nice because is has a pair that appears twice (qj) and a letter that repeats with exactly one letter between them (zxz).
xxyxx is nice because it has a pair that appears twice and a letter that repeats with one between, even though the letters used by each rule overlap.
uurcxstgmygtbstg is naughty because it has a pair (tg) but no repeat with a single letter between them.
ieodomkazucvgmuy is naughty because it has a repeating letter with one between (odo), but no pair that appears twice.
How many strings are nice under these new rules?

*/
>>
Hi I'm trying to learn C# from "C# 6.0 in a Nutshell" and there's this piece of code :
http://pastebin.com/9scffN00
In the main function, we use "Panda" before "p1 = ..." and "p2 = ...", does it refer the Panda class, or to the Panda function inside the Panda class ? What about the "new Panda(...)" ?
>>
>>51840829
NO IT ISN'T I WOULD FUCKING BEAT YOUR SORRY ASS IF YOU WERE WITH ME RIGHT NOW

nig IS UNSIGNED

(nig != 0) IS 1 IF nig IS (UINT_MAX - INT_MAX), 0 OTHERWISE

nog IS INT_MAX IF nig IS "NEGATIVE" (GREATER THAN INT_MAX), 0 OTHERWISE

WHAT IS IT THAT YOU DENSE MOTHERFUCKER DOESN'T UNDERSTAND
>>
>>51840664
why do people use X language if assembly is faster than it
is there anything X lang can do that assembly can't do

Why motivates people to make shitty posts and degrade the quality of the entire board? I don't shit where I eat, I'm smarter than that.
>>
>>51840858
>multiple precision
>having to assure
>fresh 2016 memes came early
>>
>>51840857
How the fuck can a long long overflow from two ints? Are you retarded?
>>
>>51840843
KILL YOURSELF PYTHON BABY
>>
>>51840888
have you read the standard? it says how right there
>>
>>51840888
ints can be as large as long longs
>>
>>51840865
My string is for part 2, man.
>mayosiswqqrdiqq
>pair of any two letters that appears at least twice in the string without overlapping
>qq
>It contains at least one letter which repeats with exactly one letter between them
>sys
Who is an autist now?
>>
>>51840877
>comparing high level scripting languages to assembly
:/
why use python (a scripting language) when there's js (a faster scripting language)
>>
>>51840807
unsigned int nig = (n & (UINT_MAX - INT_MAX)); // n masked off to either (INT_MAX + 1) or 0
int nog = nig - (nig != 0); // INT_MAX or 0
return (int) (n & INT_MAX) - nog - (nig != 0); // n successfully converted back to int
>>
>>51840907
You still, because not only did you misunderstand the guy who was trying to help you twice, but now you've misunderstood the guy who tried to help the guy who tried to help you.

He was asking for more information, and instead of giving him the challenge parameters you told him "HERE IS A STRING THAT SHOULD BE GOOD: "

I called you an autist because only a fucking autist would do that. If you ask for help with solving a jigsaw puzzle and the guy asks to see the puzzle, you don't show him a single fucking puzzle piece and expect an answer -- you need to show him the whole thing.

But I don't expect you to understand this.
>>
File: 1373662916812.jpg (171 KB, 600x400) Image search: [Google]
1373662916812.jpg
171 KB, 600x400
>>51840877
>is there anything X lang can do that assembly can't do
abstraction of machine details
cross platform portability
typing
optimizations
procedure
function
iterator
record/union type
adt
object
pattern matching
...
>>
File: 1414827662616.jpg (54 KB, 300x339) Image search: [Google]
1414827662616.jpg
54 KB, 300x339
>>51840969
Oh. Sorry and thanks.
>>
>>51840961
>return (int)
implementation defined
>>
>>51840704
>it's specifically why i said convert back to signed, not cast
>not cast
>>51840807
>uses a cast
dafuq, m8
>>
>>51840498
>>51840509
>>51840572
>>51840584
>>51840704
>>51840796
>>51840821
>>51840843
>>51840876
>>51840961
>>51841096
>>51841143
>webfag gets told
>webfag gets mad
>webfag gets rekt some more
The classic /dpt/.
>>
>>51840918
Why use V8 when there's LuaJIT?
>>
>>51840918
why use js (a shitty language) when there's python (a better language)
>>
So, guys, how do I find other solutions for stuff like averaging two ints? (example) The solution I'd go straight for was obviously going to be: (a + b)/2 but now I noticed there are several different ways of doing it that are safer.
>>
>>51841358
add r0, r1
ror r0
>>
>>51841358
>safer
it's either correct or not; level of safety is buzzword for "it might work"
>>
>>51841384
mov r0, 3
>>
>>51841391
The correct way, then. I'm a new C programmer and I don't really know how I would figure out these solutions alone if I ever needed.
>>
In F# what do I do when there's a circular dependency between declarations of types?

I've got an enum and want to write a custom JSON.Net converter for it:

type [<JsonConverter(typedefof<OrderTypeConverter>)>] OrderType = limit = 0 | market = 1 | fok = 2 | ioc = 3

type OrderTypeConverter() =
inherit JsonConverter()

override x.CanConvert(t:Type) =
t = typedefof<OrderType>

override x.WriteJson(writer, value, serializer) =
let str = match (value :?> OrderType) with
| OrderType.limit -> "limit"
| OrderType.market -> "market"
| OrderType.fok -> "fill-or-kill"
| OrderType.ioc -> "immediate-or-cancel"
| _ -> ""
serializer.Serialize(writer, str)


If I declare the enum first, the attribute doesn't work because OrderTypeConverter doesn't exist. If I declare OrderTypeConverter first, OrderType doesn't exist so obviously it doesn't work. wat do?
>>
How do I convert Lua bytecode to a native binary?
Here's my bytecode:
1B 4C 75 61 53 00 19 93 0D 0A 1A 0A 04 08 04 08 08 78 56 00 00 00 00 00 00 00 00 00 00 00 28 77 40 01 0E 40 6C 75 61 62 75 69 6C 64 2E 6C 75 61 00 00 00 00 00 00 00 00 00 02 02 04 00 00 00 06 00 40 00 41 40 00 00 24 40 00 01 26 00 80 00 02 00 00 00 04 06 70 72 69 6E 74 04 0E 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 01 00 00 00 01 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 05 5F 45 4E 56
>>
>>51841448
wrap an interpreter around it, use lua_load

http://www.lua.org/manual/5.1/manual.html#lua_load
>>
>>51841458
So I have to manually write a C program every time I want to compile my lua program?

wow
>>
>>51841478
>manually write
>every time I want to compile
>what are compilers
>>
>>51841478

no, you pleb. usuallly you run lua sauce directly via the interpreter. you only touch bytecode if you're doing something hacky.
>>
>>51841572
>>51841556
Are you guys both retarded?

My original question was
>How do I convert Lua bytecode to a native binary?

The answer to this question will never be 'just run the interpreter' because that's not what I'm trying to do. Jesus.
>>
>>51838755
Cool thanks anon.
>>
>>51841621
>I am retarded
>where is /wt/
>>
>>51838882
>gotto
>not simple abstraction
shiggy
>>
>>51841621
>what is jit
/g/ everyone
>>
>>51841621
wat

yes it is. lua bytecode is just that, bytecode. it still needs to be ran via an interpreter. it can't be compiled into anything native to an architecture, unless you count jit (via LuaJIT) as compiling. since there isn't a way to make the standalone interpreter run bytecode, you'll have to use liblua and lua_load to run it.
>>
>>51840038
try both
>>
>>51838882
goto error1;

https://lwn.net/Articles/588369/
>>
Friendly reminder that if you don't know C, you're not a programmer. Maybe a web "developer" in which case /wdg/ might be more appropriate for your level.
>>
>>51840072
>sleep24hrsCSgradguy.jpg
>>
>>51841695
VB fag detected
>>
>>51841668
Okay since you're apparently a bit slow let me explain this to you in simple terms.

Lua comes with the lua interpreter, which reads lua source code and then executes it. It also comes with the luac interpreter, which reads lua source code and then outputs the resulting bytecode. The lua interpreter can read that bytecode just like it can read source code.

This is somewhat similar to how Java operates (source code is 'compiled' to bytecode which is then interpreted). With Java, it is possible to convert the resulting bytecode into a native executable binary through the use of a dedicated compiler, such as GCJ, which interprets Java source/bytecode and compiles it to a program that can be run without the use of any interpreters or virtual machines. Similar compilers exist for C#, another bytecode-based language.


I'm asking if such a compiler exists for Lua. I know it's possible, I just want to know if someone's actually made one yet.
>>
>>51841736
I'm not any of the posters involved in this discussion, but was
>since you're apparently a bit slow
really needed? All you're doing is creating a bad environment, where the guy you're replying to will probably lash out to protect his ego.

Please stop and apologise for being mean.
>>
>>51841736
>luac interpreter
>reads lua source
>outputs the resulting bytecode
>interpreter
the word you're looking for is compiler
>a compiler exists for Lua
yes, luac
>>
>>51841758
fuck off, sjwc᠎uck
>>
>>51841763
>'is there a program that can turn lua code into an executable binary'
>here use this program that doesn't lua code into an executable binary
/dpt/ in a nutshell
>>
>>51841736
Your original question was then horribly phrased. try asking “is there a Lua compiler” next time, instead of delving into bullshit about converting interpreter bytecode to a binary.

So, then, to answer your question: no, there isn't one.

Finally, I didn't know the lua interpreter executable could directly run bytecode. Thanks.
>>
>>51841789
>got told what compiler means
>backpedaling
>meme arrows
>>
>>51841802
Well, okay, ”is there a true Lua compiler that compiles to an actual binary”. The whole luac situation is a mess.
>>
>>51841802
Yeah no problem man.
>>
>>51841815
>pick scripting language
>no native aot compiler
>situation is a mess
educate yourself
>>
>>51841729
retard detected
>>
>>51841776
Me being a sjw or not is completely irrelevant to this discussion. I'm just saying that making /dpt/ a toxic place helps absolutely no one. 4chan is a third space, and should present itself as one, not a place where people have their egos attacked so viciously.
>>
>>51841835
>called out
>muh butthurt
>>
>>51841843
>sjw
>completely irrelevant
CoC detected
>>
>>51841843
>4chan is a third space
the fuck am I reading
>>
>>51841833

I'm well aware of this, my friend. By situation I meant the potential for confusing luac for a AOT compiler (which happened in this thread)...
>>
>>51841843
dude 4chan is obviously a fourth space
it's in the name duh
>>
>>51841860
"Code of Conduct detected"?

>>51841873
https://en.wikipedia.org/wiki/Third_place
You may know it by third place instead. The point is that we're all here because we enjoy each other's company (or at least have something to benefit from it), and that there's no point in senseless namecalling/arguments. Even if we don't know each other's identities, we're all friends on this general.
>>
>>51841845
>
I think I've touched VB only once (1 time), and that was because I needed. I don't even use microsoft shit anymore.

so, yeah, you're a retard. probably projecting your own retardedness

>>51841873
kek
>>
>>51841906
>I've touched VB only once
>because I needed
fucking called it!
>>51841729
>>
>>51841899
> we're all here because we enjoy each other's company
>we're all friends on this general
ram the nicities up your cunt.
>>
>>51841929
this t᠎bh s᠎mh f᠎am
>>
>>51838874
http://lpaste.net/3022573596653387776
someone tell how i can avoid infinite loop in many
>>
>>51837369
4chan image downloader, written in powershell.: http://pastebin.com/84N7Y8kE

How badly did i do? Improvements?
>>
>>51841929
You're just saying that. At the end of the day, you know you appreciate my presence, as you appreciate everyone else's.
>>
>>51841982
I appreciate being able to say or do what I want without refraining from certian words. That's what this entire site is about. Your sjw ass just wants to ruin the fun. Now like I said,
ram it up your cunt, you nigger.
>>
>>51841982
The only way to appreciate /dpt/ is either by having a problem that needs solving and actually getting feedback or being a memeing cunt.
>>
>>51841924
kek, ok tard

>>51842023
>falling for the b8
>>
>>51842044
This guy gets it.
>>
>>51842046
I did. I fell fucking hard.
>>
im trying to scrape data from a soccer prediction website with python but im absolutely clueless to track how accurate their predictions really are (and later to calculate the most profitable combinations, possible wins, whether i should place single, combi or system bets). it should be super easy, but i just cant figure out how to filter so i only get the data i need. i want to get every row of a table that contains a number equal or bigger than 75 in one column and a number equal or bigger than 1.8 in another. can anyone point me to a tutorial on web scraping with python? i mean i could just say fuck it, export the data to excel, sort it and add a few functions and that would do the trick, but i really want to learn something new.
>>
>>51842086
what a mess of a post. sorry, im still hungover.
>>
Averaging two integers in C.

Signed int max <= +/- unsigned int max / 2, so adding two numbers can't overflow. The issue is that after doing a+b the highest bit is put in the 'sign' bit and any further division is signed. This can be fixed by just adding the two numbers and doing the division in an unsigned environment. Then the 'sign' bit (obviously not how two's complement works, it's just a generalization) is push off the end by the addition, so it needs to be reset after the operation.
int avg(int a, int b)
{
unsigned int r = (a+b)/2;
if (a < 0 && b < 0)
return (1<<31) | r;
else
return ~(1<<31) & r;
}


The generated assembly (-O2, so not inlined):
    leal    (%rcx,%rdx), %eax
shrl $31, %ecx
movl %eax, %r8d
shrl $31, %r8d
addl %r8d, %eax
sarl %eax
testb %cl, %cl
je .L2
shrl $31, %edx
testb %dl, %dl
je .L2
orl $-2147483648, %eax
ret

Test results:
avg           1,          -1 =           0 (actual),           0 (calc)
avg 2147483647, -2147483647 = 0 (actual), 0 (calc)
avg -1, -3 = -2 (actual), -2 (calc)
avg -2147483648, -2147483646 = -2147483647 (actual), -2147483647 (calc)
avg 1, 3 = 2 (actual), 2 (calc)
avg 2147483647, 2147483645 = 2147483646 (actual), 2147483646 (calc)
avg 1, 4 = 2 (actual), 2 (calc)
avg -1, -4 = -2 (actual), -2 (calc)
avg -1, 4 = 1 (actual), 1 (calc)
>>
>>51842166
Oops, forgot .L2
.L2:
andl $2147483647, %eax
ret
>>
>>51842166
>Assuming ints have 32-bit length

Into the implementation-defined trash bin it goes!
>>
>>51841300
why use python (a shitty language) when there's F# (a better language)
>>
>>51842303
why use F# (a shitty language) when there's LuaLaTeX (a better language)
>>
>>51841422
You do this:
and OrderTypeConverter() =
>>
>>51842312
>Initial release 2007; 8 years ago
>Stable release No stable releases yet
ayyyy
>>
>>51842354
LuaLaTeX is literally just pdflatex with Lua linked in. There's nothing to not be stable - any bugs on the latex side would be addressed in pdflatex, and any bugs on the lua side would be addressed in Lua.
>>
>>51842274
alright then
(1<<((unsigned)(log(INT_MAX)/log(2))+1))
>>
>>51842312
>dynamic typing
kek
>>
File: 1449170902068.jpg (148 KB, 1000x1000) Image search: [Google]
1449170902068.jpg
148 KB, 1000x1000
nothing

>tfw when lost all my motivation for 4 months now
>>
lol the factorial program in lua's doc doesn't even work right
function fact(n)
if n == 0 then
return 1;
else
return n * fact(n-1);
end
end

print("Enter a number:");
a = io.read("*number");
print(a.."! = "..fact(a));

[~/Devel/Lua/Luabuild] lua luabuild
Enter a number:
55
55! = 6711489344688881664
>>
>>51842406
explain
Thread replies: 255
Thread images: 15

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.