[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: 24
>>54109606

What are you working on /dpt/?
>>
first for C#
>>
>>54116487
second for C++
also

I have the following

class Node
{
virtual int function();
};
class N2: public Node
{};

now i already know i can later on say

int Node::function(){
return 9;
}

but can i do

int N2::function(){
return 2;
}

without having to state it in the N2 class?
>>
C# + C++ = all the languages needed ever
>>
Third for these threads getting deleted until we have an anime OP image
>>
>>54116557
I don't think so but I'm not 100% sure. Just try to compile it, shouldn't take long.
>>
File: sponza_3_exp7.png (925 KB, 798x510) Image search: [Google]
sponza_3_exp7.png
925 KB, 798x510
Path tracing large scenes is expensive :^)
I think I'm gonna spend the summer making a very optimized version of my path tracer, cause this shit is not exactly interactive.
>>
>>54116597
What programming language is that m8?
>>
Can you finish this function, /g/?
 
int is_odd(int n) {}

Thanks
>>
>>54116610
i'm not doing your homework nigga
>>
>>54116620
>implying you can even figure it out
>>
>>54116610
 return n / 2 * 2 == n; 
>>
>>54116610
require('is-odd-integer')
>>
Do you use C# or Java and why did you decide to use that language over the other.
>>
>>54116633
you are fucking retarded if you think something as simple as checking whether a number is odd or even is something hard.
a literal donkey can find the answer in 5 seconds, why can't you?
>>
>>54116620
>homework

Yeah I'm sure it's homework, autist

int is_odd (int n) { return (unsigned int)n&0b1 }
>>
>>54116648
>return n / 2 * 2 == n;
really now? can't you do any better?
>>
>>54116597
>Echo chamber > other ideas
>>
>>54116696
Doesn't work for all numbers
>>
>>54116713
give an example where it breaks

>>54116704
not without resorting to inline assembly and doing fancy shit
But I don't really think it get's much better than >>54116648
>>
>>54116610
int is_odd(int n) {
return ((n % 2 == 1) ? 1 : 0);
}
>>
>>54116671
no matter what your opinion is about java, you're retarded if you don't think C# is worse than java.

C# is literally a botched cargo-cult clone of java with massive feature-creep due to a load of dunning-kruger pythonesque "features" tacked onto it that you aren't even supposed to use

>many of the drawbacks of java
>many of the drawbacks of C++
>few of the benefits of java
>few of the benefits of C++

java is good for its simplicity and its ability to scale to large applications. if you don't need simplicity you may as well use C++ instead. the "low level features" in C# still give you shit performance.
>>
>>54116724
>give an example where it breaks

Negative ones compliment ints that have no positive counterpart
>>
>>54116610
int is_odd(int n) { return n % 2 != 0; }


Now go ahead and make weird unreadable "optimised" implementations, autists.
>>
>>54116610
N℅2
>>
>>54116731
Wrong and stupid
>>
>>54116743
all negative ones compliment ints have positive counterparts ffs
>>
>>54116610
int is_odd(int n) {
char s[20];
sprintf(s, "%d", n);
n = strlen(n) - 1;
return n == 1 || n == 3 || n == 5 || n == 7 || n == 9;
}
>>
>>54116762
whoops

should be
n = s[strlen(n) - 1];
>>
>>54116743
Give an example.
Asuming it will not try to convert but just work on raw values coerced by type it works on all numbers.
Which irrc it should do, but I haven't done to much of casting between signedness lately
>>
>>54116671
C# is vastly superior. Java is designed by committee, which explains why they are so much slower adopting features, while C# evolves fast and keeps up with the latest paradigms. For example, soon we'll have pattern matching in C#. Java will probably make a half-assed copycat in 2025, like they've done with generics, lambdas, LINQ and so on. Also Visual Studio is much better than any Java IDE out there, especially in speed.
>>
>>54116610

>n & 1
returns true if odd, O(1)
>n % 2
O(1)
>n / 2 * 2 != n
O(3)
>>
SQL noob from yesterday back again

Let's say have a column named hobbies (that accepts varchars)

How can I list the "hobby" that has the most entries?

Would something like MAX(COUNT()) be what I'm looking for?
>>
>>54116759
Don't just call it "wrong", give a counter example.
Otherwise everyone will asume you are wrong and stupid.
>>
>>54116759
Thanks :*, You sure are smart.
>>
>>54116791
>O(3)
such a thing doesn't exist, fagtron
>>
>>54116801
>>54116798
Negative numbers
>>
>>54116743
it has a cast to unsigned int, it works regardless of the bit representation of the int
>>
>>54116610
How's this
int counter = 0;
for(int i = 0; i < n; i++){
counter++;
}
if(counter % 2 == 0){
return 0:
}
else{
return 1;
}
>>
>>54116791
With landau symbols constants are usually discarded, since they are about asymthotical runtime.

and the second and third have a somewhat linear runtime against width of the datatype.
>>
>>54116798
he is right about it being stupid, why the fuck are you making an if statement there, just return the value of the condition statement,
and the == 1 is also unnecessary.
these kinds of things affect performance
>>
>>54116743
Don't be retarded. Unsigned int range is twice the positive sign int range.
>>
>>54116798
literally the first example on wikipedia

https://en.wikipedia.org/wiki/Modulo_operation#Common_pitfalls
>>
>>54116776
>>54116760
Conversion from signed to unsigned does not necessarily just copy or reinterpret the representation of the signed value. Quoting the C standard (C99 6.3.1.3):

>When a value with integer type is converted to another integer type other than _Bool, if the value can be represented by the new type, it is unchanged.

>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.

>Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised.

For the two's complement representation that's nearly universal these days, the rules do correspond to reinterpreting the bits. But for other representations (sign-and-magnitude or ones' complement), the C implementation must still arrange for the same result, which means that the conversion can't just copy the bits. For example, (unsigned)-1 == UINT_MAX, regardless of the representation.
>>
>>54116819
what's
 -3 % 2 
?
>>
>>54116814
>>54116830
i guess you are both right.
i need to revise them.
>>
>>54116850
-1
>>
>>54116845
yes so the code fucking works, the bit representation doesn't matter
>>
>>54116855
No, retard. -1 is odd, in ones compliment UINT_MAX is even
>>
>>54116743
Kek
>>
>>54116885
You fucking retard
>>
https://youtu.be/6I1-r1YgK9I
>>
is there something similar in c++ like string.equals(otherString) ?

== operator seems to only work with single chars.
i wanna have endless input which stops if one types in "Stop".
>>
>>54116901
Congrats. That is not ones compliment. Once again you are retarded
>>
>>54116914
Just make a boolean char loop function. With str.length() it should be easy.
>>
>>54116610
return n % 2;
>>
Hey C-fags found something for you:
https://github.com/vurtun/nuklear
>>
>>54116935
You're a fucking retard

if n = 0 you're dividing by zero
>>
>>54116920
Why the fuck would you be using one's complement in the first place retard? It's not a number you come across, you'd have to convert it to ones complement using the bitwise operator ~. Your scenario is retarded and unrealistic
>>
>>54116956
0/2 is different to 2/0.
>>
>>54116956
LOL WUT
>>
>>54116968
no it isn't, you're still dividing and there's a 0 in there
>>
>>54116962
>Why the fuck would you be using one's complement in the first place retard?

Because the C standard requires numbers are represented in one of three different ways. And ones compliment is one of them. Just because your code works with some C implementations doesn't mean it works with C
>>
>>54116830
that got me thinking though.
saying n&1 gives an answer in time t=1
saying n%2 should give an answer in time t=1
while the last should give an answer in a t=3

lets say the function is set inline and is used 1 million times, wouldn't it have been the right choice to choose either of the top two, ofcourse disregarding that negative numbers cause the second to fail.

and can you explain what you meant with your second statement please?

this was a rather infromative experience.
>>
>>54116956
(You)
>>
>>54116988
>you're still dividing
but not by n.

0%2 = 0
>>
>>54116796
I don't know who you are but that is not enough information to provide help. In any case, you should do SELECT * on all relevant tables and post some screen shots here. Alternatively, post the schema directly.
>>
>>54117035
Well, I think I figured it out

SELECT hobby FROM hobby_table
GROUP BY hobby
ORDER BY COUNT(*) DESC
LIMIT 1;


Let me explain a bit, anyway

There's a table called hobby_table that has a field called hobby (which is a varchar)
I'm trying to list which repeated hobby has the most repetitions (Which one has been entered the most times)
>>
>>54116914
The == works with std::string but not with char array, as expected.
>>
a raspberry pi strapped to a camera that uploads images to dropbox as they're taken.
>>
>>54117066
>LIMIT 1

NO
NO
NO
NO

Typical beginner mistake. What if you have several hobbies? You need the HAVING() clause for this kind of query.
>>
>>54117032
no
2 % 0 = (division by 0)
>>
>>54117104
the code never does 2 % 0. instead, it'd be 0 % 2
>>
>>54117101
I'm really only trying to find the most "used" hobby, is LIMIT 1 not OK for that?
>>
>>54117124
it's still division by 0 tho
>>
>>54116956
>I share the board with these retards
>>
>>54117161
do you consider 0/2 division by zero?
>>
>>54117161
No, it's zero divided by something, which is zero.
>>
>>54117172
yes since there's a 0
>>
>>54117144
Don't blame me, kid. SQL sucks.
LIMIT 1 will not find the correct solution. Consider the following table:

table hobby_table
------------------------------------
Joe | Swimming
Tony | Swimming
Marcus | Jogging
Tiffany | Jogging
---------------------------------------


LIMIT 1 will get either Swimming or Jogging. But they're both equally popular.
>>
>>54117182
how many times can two fit into zero?
>>
>>54117161
lel. k tard
>>
File: 1460676268409.png (741 KB, 829x966) Image search: [Google]
1460676268409.png
741 KB, 829x966
>>54116487
>>
>>54117195
Ah, I see
So how would I use the HAVING statement withing this context?
>>
File: map.png (52 KB, 1063x492) Image search: [Google]
map.png
52 KB, 1063x492
whats the best way for defining figures to render in opengl?
>>
>>54117161
holy fuck, i never seen anyone with a thicker brain.
get a calculator out and try it. you nigger.
>>
>>54116796
Look up group by. I think what you're looking for is something like: select hobbies, count(*) from table group by hobbies order by count(*) desc;
>>
>>54117261
just feed the vertice to vertex buffer? and have them as float arrays or whatever (just like you do on the screenshot)
>>
>>54117277
So pretty much what I have except I just remove the LIMIT 1 line?
>>
>>54116610
int is_odd(int n) {
return n & 1;
}
>>
>>54117264
How is it not obvious that he is trolling? Maybe you're the dense one
>>
>>54117303
Wrong
>>
>>54117306
it's pretty clear, but i'm enjoying it anyway
>>
>>54117161
A * (B/C)
this says
for every C in A, replace it with B
1 * (2/1)--->(1)
2 * (2/1)--->(1+1) * (2)--->(2+2)
0 * (2/1)--->(NONE)*(2)---> 0
>>
>>54117320
Ah, so you're only pretending to be retarded
>>
>>54117317
how is it wrong?
>>
>>54117261
Write a data format and a loader. No need to specify all that crap by hand.
>>
File: WATTTT.jpg (23 KB, 799x698) Image search: [Google]
WATTTT.jpg
23 KB, 799x698
>>54117292
it just looks so godawful.
>>
>>54117317
how so
>>
>>54117338
Doesn't work for negative ones compliment, see >>54116993
>>
>>54117353
>Doesn't work for negative ones compliment
what ?
https://en.wikipedia.org/wiki/Ones'_complement
>>
>>54116791
>O(3)
>I can't into O notation
>>
>>54117349
well you could always just make the figures in a modelling program and use obj or w/e files and just load these at runtime
>>
>>54117367
Notice that negative odd numbers have a 0 LSB
>>
>>54117353
Who cares x86 doesn't use ones compliment

>>54117371
O(3) = O(1) just like O(3n) = O(n) dumbass
>>
>>54117349
If your goal is to make something nice looking, then you shouldn't be using raw opengl.
>>
>>54117381
x86 doesn't respect my freedoms http://mail.fsfeurope.org/pipermail/discussion/2016-April/010912.html
>>
File: denied.jpg (46 KB, 799x694) Image search: [Google]
denied.jpg
46 KB, 799x694
>>54117349
so for it to have semi-realistic lighting, I have to subdivide large figures into smaller ones so lighting can be interpolated properly. How would you guys accomplish this? My current solution is pretty ugly (codewise). I added spacing between the subsections here to illustrate how its split up.
>>
>>54117241
The HAVING clause is the same as the WHERE clause, only better.
SELECT x FROM table WHERE x = 1 GROUP BY x HAVING x = 1

HAVING is the same as WHERE except it's processed after the GROUP BY clause and can be used for exactly what you want. I'll let you google the rest. PROTIP: it's a very common issue.
>>
>>54117296
Yeah. I just saw the rest of that conversation. What the other anon is talking about is putting "having count(*) = num" at the very end, where num is the most popular hobby count. You'll probably have to create a subquery to find that.
>>
>>54117381

>Who cares x86 doesn't use ones compliment

But some old mainframes that may or may not still be in use do. The world doesn't run on x86 alone.
>>
>>54117471
For god sakes someone show me an implementation that works with one, two, and sign complement

I've been trying to figure out a solution
>>
File: cubes.png (7 KB, 708x121) Image search: [Google]
cubes.png
7 KB, 708x121
>>54117429
I currently allocate a huge float array for every cube that needs to be broken up. (4 points for every sub-rectangle, 3 coordinates per point, 6 sides to the cube, n*n squares per side. Thus 72*n^2
>>
>>54117497
N%2 != 0
>>
>>54117497
see
>>54116935
>>
>>54115852
>lambdas
Depends: with or without Java's semantics are an arbitrary fuckmess anyway so...
Litterally the most useful thing in the world. Ever heard about "shortening your feedback cycle"? (Don't take it to the dick) it sounds like an agile (tm) memeword at first, but the concept really does exist and thrive in the real world. Provided that you can Read (an expression), Eval (the aforementionned), and Print (the result in a meaningful way), you can interact with the system like in an oral dialogue, with quick, concise answers that either confirm or refute the assumptions you make about the behavior of a certain combination of functions and data. And you get the Loop part for free. Obviously, an entire project is more like a static written essay and there's nothing wrong with that, but it can't be right if you deliberately let go an opportunity to cooperate orally with the person you're working with, can it?

In Java, programmers are supposed to have the entire language stuffed into their heads in advance. They are supposed to regurgitate the right pattern for the problem, without thinking too much, like slaves. There's no interactive trial-and-error, or anything that would drive them closer to being humans, rather they are replaceable robots.

A programming language should be a versatile and elegant way to express humanly flawed ideas, anon. Join us on the path to Λight!
>>
>>54117432
>>54117440
Thanks m80s
>>
>>54117548
http://www.javarepl.com/console.html

Lamda is shit. Use polymorphism instead
>>
>>54117581
iirc java 9 is supposed to have a repl too
>>
>>54117471
even before C only a few products used one complement.
>>
File: giphy.gif (1017 KB, 468x356) Image search: [Google]
giphy.gif
1017 KB, 468x356
>>54117581
>>
Is it wrong to hate MySQL?
>>
I might drop out of CS because I suck at math

Should I go into IT or IS for programming?
>>
>>54117646
Why do you hate it
>>
>>54117629
Ohh great another tripfag Ruby and OSGTP were more than enough
>>
>>54117698
If you suck at math so much you can't get through required CS classes than what are you doing programming? InfoSec is probably the closest you can get.
>>
>>54117703
you can always block me : 3
>>
>>54117720
Did alright in math in highschool

Barely passing classes now
>>
>>54117737
or you can get rid of your trip... fag
>>
>>54117749
Which math are you struggling with explain
>>
>>54117749
What math classes are you in now lmao?

It gets easy past calc II.
>>
>>54117754
This is true. I promise to think about it : 3
>>
>>54117559
PROTIP: It's because MAX(COUNT(*)) is illegal.
PROTIP 2: OracleSQL actually can handle MAX(COUNT(*)) and the solution is trivial. All other SQLs suck in comparison.
>>
>>54117508
>>54117429
Good grief. Use lightmaps. Many modelling tools can bake you lightmap atlases you can use. If you don't need light bouncing (ie. radiosity), you can write a basic direct-light lightmapper in a day from scratch (assuming you know the math, of course).
>>
Java professional here yet again willing to help any fellow anons with their homework or assignments
>>
so how the fuq do you use traits in rust?

i know how they work i just can't switch my brain from inheritance to traits
>>
>>54117768
Probability mostly. I just don't understand any of it. The methods seems counter intuitive and I have no clue which formulae to apply to word problems.

Calc is okay but it takes a lot of time outside of lectures to fully understand.

>>54117771
Probality I, Calc I and physics.
>>
>>54117866
>traits
traits are only interesting with dynamic typing. rust is a total failure of plt.
>>
>>54117976
Ouch. That shit is easy. Calc II is where your dick gets ripped off. Then it's easy from there.
>>
>>54117976
https://www.khanacademy.org/math/probability
>>
>>54118020
I have an option to do applied linear algebra instead of Calc II, which is supposedly easier, but then I have to do an arts course to make up the credits.

>>54118029
Thought khanacademy was more for highschool stuff. Didn't know they had a probability section. Thanks m8.
>>
>>54117833
Everything has to be able to move with user inputs. Is this compatible with a dynamic scene?
>>
>>54118169
It's for high school, college, and university math.
>>
>>54116610
int is_odd(int n) {
return !is_even(n);
}
>>
File: happystallman.jpg (58 KB, 645x430) Image search: [Google]
happystallman.jpg
58 KB, 645x430
R8 my Clojure FizzyBuzzy, beloved programming literate!
(doseq [i (range 1 101)]
(println
(case [(zero? (mod i 3)), (zero? (mod i 5))]
[true, true] "FizzBuzz"
[true, false] "Fizz"
[false, true] "Buzz"
[false, false] i)))
>>
>>54118199
 int is_even(int n){
return !is_odd(n);
}
>>
>>54117700

It's fucking shit.
>>
>>54118178
It is if you optimize it properly. Games had dynamic lightmapping in the 90's already. They didn't have shadows, but these days you have enough computing powers to have shadows too.

If you want to be a pro, store the lightmap data of each surface in a quadtree, so you can subdivide it when needed. Then you don't waste computing shadows in places that don't have them. Fast fast fast.
>>
File: che.png (4 KB, 445x175) Image search: [Google]
che.png
4 KB, 445x175
is this right?
>>
>>54118331
it's not as good as mine:
i=0
while 1:i+=1;print'FizzBuzz'[i%~2&4:12&8+i%~4]or i
>>
>>54118331
First, you should be using Python 3.

Second, you can replace the third if statement with
if not rootbeer:
>>
>>54118390
>le single line meme
>>
>>54116750
>if I don't understand it, that means it's weird and unreadable
int is_odd(int n) { return n & 1 == 1; }
>>
>>54118442
but it's two lines
>>
>>54118470
I perfectly understand it, but it's still retarded.

Mathematical definition of odd = An integer that is not divisible by 2.

Sorry if the only way you have of feeling smarter is to "optimize" trivial functions son.
>>
>>54118470
It's understandable, it's just a wrong implementation
>>
>>54118470
perfect except
int is_odd(int n) { return (unsigned int)(n)&0b1; }


ONES COMPLEMENT IS IRRELEVANT
>>
>>54118612
What do you mean? Your code works fine with ones compliment
>>
>>54116750
I'd argue n % 2 == 1; is more readable but whatever.
>>
I'm learning java in my computer science courses. I also want to begin creating personal projects. Is it worth it to learn a second language on my own? My thought process is that ruby, for example, would make my ideas more reachable since it requires a lot less code.
>>
>>54118655
It's incorrect though
>>
>>54118657
learn something thats easy to play with on the side, but do not cripple yourself by avoiding strongly typed languages.
>>
>>54118634
In one's complement
-7 = 0b1000

This would return false for an odd number, however, one's complement is irrelevant.
>>
>>54118674
Nope.
>>
>>54118657
By that logic, you should learn APL
>>
>>54118683
sorry; what I posted here is ambiguous. I meant to say don't avoid languages with static type checking. Its a blessing and a curse.
>>
>>54118470
You messed up your order of operations. Should be
return (n & 1) == 1
>>
>>54118685
But you cast it in your code.

>>54118686
Doesn't work for half of the fucking odd numbers, retard
>>
Lagrange interpolation polynominal

'use strict';

const sin = Math.sin;
const cos = Math.cos;

let findNodes = (start, end, n) => {
let nodes = [];

let findKsi = (k) => -cos(((2*k + 1) / (2*n + 2)) * Math.PI);
let findNode = (k) => ((end + start) / 2) + ((end - start) / 2) * findKsi(k)

for (let i = 0; i <= n; i += 1)
nodes[i] = findNode(i);

return nodes;
}

let findPoly = (nodes, func) => {
let values = nodes.map(func);

let omega = (x) => nodes
.map(y => x - y)
.reduce( (prev, curr) => prev * curr, 1 );

let getSubsTableRow = (n) => {
let prod = 1;
for ( let i = 0; i < nodes.length; i += 1)
if ( i != n )
prod *= (nodes[n] - nodes[i])
return x => prod * (x - nodes[n])
}

return (x) => omega(x) * values.map( (y, i) => y / getSubsTableRow(i)(x) ).reduce( (p, c) => p + c );
}


let f = (x) => 1 / (x * sin(x))
let g = (x) => x * x

let fPoly = findPoly(findNodes(0, 1, 100), f)
let gPoly = findPoly(findNodes(0, 1, 100), g)
let sinPoly = findPoly(findNodes(0, 1, 100), sin)
console.log( fPoly(0.5), f(0.5) )
console.log( gPoly (0.3), g(0.3) )
console.log( sinPoly(0.2), sin(0.2) )


on scale from 0 to shit how shit is my code?
>>
>>54118686
-2 % 1 return -1 in C.
>>
>>54118470
Newbie here, can someone explain this please?
>>
>>54118715
Oh does that fix the complement? I guess it would, right?

Some jackass was trying to say it wouldn't.
>>
>>54118763
bitwise operators

The last number of a binary string (LSB) always determines whether it's odd. ANDing that bit will return a 1 if odd and a 0 if even.
>>
>>54118766
It makes the number unsigned. Obviously there is no such thing as unsigned ones compliment
>>
>>54118763
https://en.wikipedia.org/wiki/Least_significant_bit
>>
>>54118791
Wrong
>>
>>54118844
It's not wrong you fucking retard
>>
>>54118854
It's completely dependent on how you use bits to represent numbers.
>>
I have a C program 500 or so lines atm, uses a course specific library.

I don't understand how to loop the exit of the program correctly. Main calls this function which contains the primary program loop. Within this function I need a way to exit smoothly, but currently I have it exiting when a condition hits 0, asks a question and waits for a reply. But this reply isn't taken in properly. I may just be too tired atm.



void GameWrap () {

//initiate structure
GameStats gameStats;

//set up sprite, values for game
SetUpAll(&gameStats);
DrawAll(&gameStats);

//start game loop
while (!gameStats.over){

int key_code = get_char();

//quit game pressing 'q'
if (key_code == 113) {

gameStats.over = true;
}

//reset game pressing 'r'
else if (key_code == 114) {

//clear screen, revert stats (time, lives etc), move play/first block
//to start & remove other blocks

SetUpAll(&gameStats);
DrawAll(&gameStats);

}

//game loop
else {

//get updates from move functions - do play last the death check will be there?
bool playerMoves = UpdatePlayer(&gameStats, key_code);
bool safeMoves = UpdateSafeBlock(&gameStats);
bool killMoves = UpdateKillBlock(&gameStats);


if (playerMoves || safeMoves || killMoves) {
DrawAll(&gameStats);
}

if (gameStats.remainingLives == 0) {

//RestartGame(&gameStats);
gameStats.over = true;
bool finalQuit = false;

while (!finalQuit) {

draw_string (25, 30, "Game over.");
draw_string (25, 31, "To restart press r");
draw_string (25, 32, "To quit press q");

int gameLost = get_char();

//quit game pressing 'q'
if (gameLost == 113) {

finalQuit = true;
}

//reset game pressing 'r'
else if (gameLost == 114) {

//GameWrap(); //baaaaaaaad
gameStats.over = false;
//from here needs to loop back to start of this while loop
}
}
}
}
}
}
>>
>>54118930
Print out key code to make sure it is what you expect
>>
for i in 1..101 {
let x = &i.to_string()[..];
println!("{}", match (i % 3, i % 5) {
(0, 0) => "Fizzbuzz",
(0, _) => "Fizz",
(_, 0) => "Buzz",
_ => x
});
}
>>
>>54118993

Might not have been completely clear.

It's in the remainingLives == 0 statement where things break down. The initial key_code and rest of program works. Sorry. It's that after displaying the Game Over text is basically locks and I have to spam q for it quit. So yes, it's in some way still accepting input.
>>
>>54118930
can you not just use "continue"?
>>
>>54119052
Why would it not? You're basically drawing the text then calling get_char() which blocks until it gets the char.
>>
>>54116610
inline int
Is_odd(int n){ return ~(n&0xFFFE);}

Untested, and typed on a small touch screen during a regular power black out. But should be faster than your nifty conditionals ;)
Regards from Syria :)
>>
>>54118924
Every representation except one's complement it's true, so fuck off retard.
>>

public class NumChecker {
boolean [] nList;

public NumChecker (){}

public boolean isEven(int n){
n = Math.abs(n);
nList = new boolean [n+1];
nList[0] = true;
for (int i = 1; i<n+1; i++){
if(nList[i-1]){
nList[i]=false;
}else{
nList[i]=true;
}
}
return nList[n];
}

public boolean isOdd(int n){
return !isEven(n);
}

public boolean isPos(int n){
return (0<n);
}

public boolean isNeg(int n){
return !(0<n);
}
}


Been going at it HARD today! This required some serious thought but I think I got it down finally. Any suggestions on how to improve my coding??
>>
>>54119100
>Not fixing portability issues in your code
very pleb.
>>
>>54119058


}
continue;
}
//continue;
}
//continue;
}
//continue;
}
//continue; errors here because no longer in a loop
}


Commented each one individually, all gave the same results.

>>54119069

I honestly don't know. But when it fails and I press r multiple times it just holds. Press q it resets and moves everything a single frame before becoming unresponsive (not crashing, but having to spam q to exit). Shits weird.
>>
>>54119100
Doesn't work with zig-zag encoding
>>
>>54119129
>portability
Yeah gotta look out for those one's complement processors those are surely plentiful

I even doubt there's a maintained OS that considers one's complement
>>
>>54119154
When you decode zigzag it becomes a normal int, so you're again wrong.
>>
>>54119100
If a new representation came along your code would be useless. For example, with quantum computing your code is obsolete. I.e. you're a bad programmer that sacrifices portability just to save one or two CPU cycles.
>>
>>54119183
Changing any signed representation to twos compliment makes it work. What is your point, retard?
>>
>>54118930
add finalQuit = true; to both branches of that last part.
>>
>>54118930
you may need another getchar there to eat up a newline

also what's with it being get_char instead of getchar
>>
File: expert_CS_coding.png (88 KB, 890x670) Image search: [Google]
expert_CS_coding.png
88 KB, 890x670
>>54116610
>>
>>54119203
>new representation
>quantum computing your code is obsolete

That would also mean the other implementations are incorrect. What is your point?

>>54119207
So you just disproved your own point. Good job.
>>
>>54118738
If that's the case that's fucking insane. Modulus returning a negative is ridiculous.
>>
>>54119244

Specific function of the supplied library, it's just what's needed because you can't printf, getch etc. Simply how it's built.

>>54119232

No luck so far, thanks anyway.
>>
>>54119075
Shit. | not &

Corrected version:
inline int
Is_odd(int n){return ~(n | 0xFFFE);}
>>
>>54119327
dafuq are you trying to do. You're over complicating it. see>>54118612
>>
>>54116819
Couldn't you just take the absolute value of a number before you mod two?
>>
>>54119365
abs sometimes returns a negative number
>>
>>54119288
>That would also mean the other implementations are incorrect
But that's not true. Using
return i % 2 != 0;

Would still be correct.
>>
>>54117698
You should fucking learn the math, whatever it takes.
>>
>>54119456
He thinks you can just learn math. Anon some people just don't get math
>>
>>54116557
no? being an internal class isnt inheritance.
>>
>>54119475
Yes you can just learn math, I thought that math is hard beyond primary school level and I thought that I'm just too dumb until I wanted to write a video game, where obviously you need math (to some extent depending on the game type) and I've learned a lot of trig and stuff in the process and now I've got it all memorized now that I've done several projects.
>>
>>54119505
Memorizing math is not "Learning math" Actual math is taking the concepts you learned and applying it not just memorizing everything. Anon please
>>
File: 1337500404802.jpg (3 MB, 3000x4000) Image search: [Google]
1337500404802.jpg
3 MB, 3000x4000
>>54119393
TIL http://ideone.com/TOtFzx
>>
>>54119393
>>54119603

abs isn't really doing its job, is it
>>
>>54119603
Cast an unsigned instead
>>
def isEven(p, q = 0):
if p < 0:
return isEven(-p)
if p == q:
return True
elif q > p:
return False
else:
return isEven(p - 1, q + 1)
>>
>>54119594
You need to memorize basic principles and formulas though.
>>
Best way to handle large amounts of constant values? I'm thinking pretty much a database but the data doesn't need to be added to/transformed in any way, so I don't know if there's a better option. Obviously I don't want to pull in an entire GB size table into memory every time I need access it. Is there a better option? Like a bunch of XML files? Or should I just go ahead and have a database implementation?
>>
Instead of going for CompSci I'm doing design classes while keeping my programming up so I can go into a good function immediately and won't be an autist programmer.

Currently have this lists of what to check out and learn, anythign to add or remove from that?

Java, C#, Javascript, PHP, Python, NODEJS, PERL, ASM, C++
>>
>>54119752
arraylist

>>54119792
you are missing SQL the most important one

Remove Python, NODEJS,PERL,ASM
>>
>>54119752
>Like a bunch of XML files
anon
what made you think this is potentially more efficient than a database?
seriously, i want to understand what's going on in your head
>>
Which should I put on my CV?
Worked at { company } as a software developer
a) building applications.
b) creating applications.
c) programming applications.
something else?
>>
>>54119850
d) shitposting on /g/dpt/
>>
>>54119812
I'm thinking it might be faster and more memory efficient to read a small XML file in a directory hierarchy by a procedural URI path instead of iterating through a SQL table with billions of entries.

>>54119806
Thanks for the answer but I don't want a global struct of a billion nodes floating around, I want this to be able to work on my phone.
>>
>>54119888
SQLite

https://www.sqlite.org/
>>
>>54119806
Thank you
>>
>>54119888
>I'm thinking it might be faster and more memory efficient to read a small XML file in a directory hierarchy by a procedural URI path instead of iterating through a SQL table with billions of entries.
jesus christ
if you can split something up into files you can usually split it up into tables as well
sql uses paging and caching and is likely a lot more performant than any shitty xml driven approach you can come up with yourself (this idea still boggles my mind - why the FUCK would you store shit as xml that might be a gig of data? what the fuck is wrong with you?)
>>
How do I into inspiration? Everything I wanna do has been done
>>
>>54119979
>why the FUCK would you store shit as xml that might be a gig of data?

This is a common as fuck practice captain retard. Never heard of a DACPAC? Or a data-tier application?
>>
File: scrapper.jpg (48 KB, 647x541) Image search: [Google]
scrapper.jpg
48 KB, 647x541
help me please I dont know what im doing

when I run this it just gives me

Traceback (most recent call last):
File "C:/Python27/hcscrapper.py", line 29, in <module>
f.write(requests.get(image).content)
File "C:\Python27\lib\site-packages\requests\api.py", line 67, in get
return request('get', url, params=params, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 53, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 454, in request
prep = self.prepare_request(req)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 388, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "C:\Python27\lib\site-packages\requests\models.py", line 293, in prepare
self.prepare_url(url, params)
File "C:\Python27\lib\site-packages\requests\models.py", line 353, in prepare_url
raise MissingSchema(error)
MissingSchema: Invalid URL 'None': No schema supplied. Perhaps you meant http://None?

what am I doing wrong?
>>
>>54120062
using SOAP is also a common as fuck practice captain retard, that doesn't make it any less fucking retarded
>>
>>54119603
>http://ideone.com/TOtFzx
Read this: https://en.wikipedia.org/wiki/Two%27s_complement

tl;dr: usually abs(INT_MIN) > INT_MAX
>>
>>54120152
what's wrong with SOAP?
>>
>>54120124
Your image variable is None.
>>
When is it best to just scrap your code and start again?
>>
>>54120124
get pycharm
it has a debugger
>>
>>54120259
how do I fix it wise one

>>54120276
ok I will
>>
>>54120317
use print
>>
File: bully.webm (3 MB, 720x404) Image search: [Google]
bully.webm
3 MB, 720x404
Ask your favorite programming literate anything (IAMA)

>>54119997
There always new emerging fields like virtual reality or ai. re-inventing things can be satisfying. ganbatte, anon-chan !

>>54119203
>you're a bad programmer that sacrifices portability just to save one or two CPU cycles.
Well, why would you use C today if not for saving cpu cycles ?

>>54117698
Data scientist.

>>54116993
if you had to care about the standard, binary operators on signed integers is not specified at all.

>>54119603
Note that an implementation if free to use this value as a trap value (for uninitialized variables, returning an error, ...), in this case abs(INT_MIN) would equals INT_MAX
>>
>>54120329
>if you had to care about the standard

When do you not?
>>
>>54120124
It's better to use the api instead of scraping.
>>
>>54120383
When i program in C, it's for all the tricks that the undefined behaviors allow.
>>
>>54120432
I'd use the api but this is the most complicated programming thing I have done so far so I have absolutely no idea how to use the api.
>>
File: qqqqq.jpg (127 KB, 500x500) Image search: [Google]
qqqqq.jpg
127 KB, 500x500
Android dev question here

I have a fragment that is a List but can be multiple sets of information. How should I go about specifying what data to load the list with?
>>
>>54120529
https://github.com/4chan/4chan-API
>>
>>54120320
print debugging considered retarded
>>
What's the difference between Angular and React?
>>
Question: How do Ruby libraries compare to Python's, both in availability and quality?
>>
>>54120664
Strong words coming from a pytard. Can python even invoke breakpoints?
>>
is it often in data related work fields that you will have to create your own B-tree class from scratch as a data structure?
>>
>>54120636
implement the list/base/whatever adapter in code with two ArrayList<yourclass> members and put a control variable and then a if/else check in every mandatory adapter override i.e getcount, getview, getitem
>>
>>54120707

One's for web apps the other is for mobile apps
>>
>>54120713
it's dynamic, you can do the fuck you want.
>>
Holy shit I just found out sublime text can compile applications
>>
>>54120725
So should I do anything in the Fragment class or just implement everything in the adapter class?
>>
>>54116610

You lot are dumb. Start from the top.
What is the expected output? The return type should be a bool.
>>
>>54120822
LOL ever heard of C?
>>
>>54120727
So if I wanted to create an administration panel accessible through a web browser that communicates with my backend server I'd go with Angular to make it a single page app?
Thread replies: 255
Thread images: 24

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.