old thread: What are you working on, Sup Forums?
/dpt/ - Daily Programming Thread
Other urls found in this thread:
github.com
twitter.com
First for C
Making a python .plist installer.
...
haskell!
About to start working on a C++ Huffman encoder/compressor
How hard is it gonna be?
whats the easiest job to get hired for with a comp sci degree?
1gb/s garbage rate
Trying to build out a LIFX library in Rust so I can make some neat shit.
I have no idea what I'm doing though, because it invovles fucking with UDP packets.
Java
haskell!
...
Huffman is not so hard, lzw fucked me in the head for some reason back in school
>hi, we are looking for experienced java developers with strong skills in the following
>minimum 10 years experience
>35k starting
- every java dev job advert
>//operators
> int add;
> int sub;
> int div;
> int mul;
>could be compacted into a single var called, say, result.
how though?
>System.out.println( (I == add ? "correct" : "retry"));
My book mentions this, apparently it is called the ternary operator.
is i understand it, the statement says:
if I = add is true, then use the string value "correct", elsewise use the string value "retry".
I think i will try that, be back with new code soon.
>"dont mean to be harsh, but..."
dont worry user, im a beginner and expect beginner incompetence from myself.
PC technician/support
IT helpdesk
in what, a call center?
...
Call center, PC repair shop, anything!
>"Hello, here is my degree in CS, I want to take calls"
hmm
pain and suffering
call centers here are where people go to neck themselves, and repair shops typically want tinkerers and the like, not devs.
>pain and suffering
enjoy CS
ITT: Make a Hidden Markov Chain in the language in your choice.
Python:
import hmmlearn
import Data.HMM
public class Math_Master {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Random rng = new Random();
//set random operator selector
int op = 1;
//rand operands
int a, b;
int input = 0;
int result = 0;
//integer variable range
System.out.println("please input numerical range:");
int range = in.nextInt();
for (int t = 1; t != 10; t++){
a = rng.nextInt(range);
b = rng.nextInt(range);
switch (op) {
//addition
case 0:
result = a + b;
System.out.println("please add " + a + " and " + b + ":");
input = in.nextInt();
break;
//subtraction
case 1:
result = a - b;
System.out.println("please subtract " + a + " and " + b + ":");
input = in.nextInt();
break;
//division
case 2:
result = a / b;
System.out.println("please divide " + a + " and " + b + ":");
input = in.nextInt();
break;
//multiplication
case 3:
result = a * b;
System.out.println("please multiply " + a + " and " + b + ":");
input = in.nextInt();
break;
//error message
default:
System.out.println("programming is fucked");
} //switch
System.out.println( (input == result ? "correct" : "retry"));
}
}
}
Haven't ran it but something like that is what I had in mind. Could also print before switch
Is there a sticky somewhere I could look at for resources on learning how to program? I'm taking a summer course for it but having more resources to work on would be nice.
>inb4 Google it yourself faggot
First step in all research is checking whether someone else asked the same question.
Bad girl.
New chair is awesome.
Drink and snack on me. Imma find something for rhe day.
Rather...
..... . ........
...
.try the day dnrink and snack
Dont look at me. Also heres your dick.
What about with no degree?
Barista
C influenced languages get an automatic F in my book.
Yeah, Lisp fortran and SML are the only languages that are good.
here is improved version.
I copied your idea of abbreviating "int a;/int b;" into just "int a, b;"
also took the idea of introducing values of a dn b at beginning of for loop before switch operation.
have to wander what you are diong with the input and result variables. are those really necessary for it to work?
Your book sucks lmao.
Replace Lisp with Forth and you're almost right.
forgot to paste:
ackage Math;
import java.util.Random;
import java.util.Scanner;
public class Math_Master {
public static void main(String[] args) {
//RNG
Random r = new Random();
//set random operator selector
int op = r.nextInt(3);
//random integer values
int a, b;
//Scanner
Scanner s = new Scanner(System.in);
//user input
int I;
//operators
int add;
int sub;
int div;
int mul;
//integer variable range
System.out.println("please input numerical range:");
int range = s.nextInt();
for (int t = 1; t != 10; t++){
a = r.nextInt(range);
b = r.nextInt(range);
switch (op) {
//addition
case 0:
System.out.println("please add " + a + " and " + b + ":");
add = a + b;
I = s.nextInt();
System.out.println( (I == add ? "correct" : "incorrect.\nThe correct answer was: " + add));
break;
//subtraction
case 1:
System.out.println("please subtract " + a + " and " + b + ":");
sub = a - b;
I = s.nextInt();
System.out.println( (I == sub ? "correct" : "incorrect.\nThe correct answer was: " + sub));
break;
//division
case 2:
System.out.println("please divide " + a + " and " + b + ":");
div = a / b;
I = s.nextInt();
System.out.println( (I == div ? "correct" : "incorrect.\nThe correct answer was: " + div));
break;
//multiplication
case 3:
System.out.println("please multiply " + a + " and " + b + ":");
mul = a * b;
I = s.nextInt();
System.out.println( (I == mul ? "correct" : "incorrect.\nThe correct answer was: " + mul));
break;
//error message
default:
System.out.println("programming is fucked");
}
}
}
}
Complete programming/coding/software brainlet here: how hard is it to make a program that detects data patterns? For example, if I had 10 pages of just random number sets, could a program be made that detects the same set over and over again? pls help
Fortran >>>>>>>>>>>>>>>>>>>>> C
You have to be mentally ill to deny this.
Easy. Just use statistics.
I made a minimax AI in my n-length tic-tac-toe game but it is slow. How can it be made faster?
I saw alpha-beta pruning on wikipedia and will try that. I also thought of checking whether a possible move is just a rotation or flip of another move and then not evaluating it.
>no pointer support
excuse the autism but could you explain what you mean?
going to see if i can implement a scoring system after a 2 hour break, then will see if i can figure out how to export the finished product and turn into a fully fledged and downloadable application on GitHub.
adding a scoring system will not be too tough, just a small bit of trial and error. Doing the rest i imagine will be very difficult. It has no GUI so i expect launching it with a cmd console will be the only way.
...
>tfw memed Fortran so much that people are starting to buy my shills
Yes good little goy.
You don't need pointers when you have pass by reference.
Please say it ain't so.
>auto restrict
>/prog/
>picture
Bring back world4ch
>are those really necessary for it to work?
Unfortunately yes, it's one of Java's many small faults and is required to output outside of the switch statement, as input and result are only operated on in an inner, conditional scope. This means Java can't guarantee that the values have been set and Java disallows your using variables that haven't been initialized.
You have the basic idea for sure, and that's what's important. You'll learn clever optimizations/quality-of-life tricks by trial and error and repetition.
A scoring system will be extremely easy, the GUI much less so if you don't have any experience with JavaFX. That said, once you have a basic understanding of JavaFX, making a GUI for a program like this will be trivial as well.
Is there anything that has to be done other than the scoring system and a GUI?
You can use CLI programs for that, no need for any code. uniq can probably do what you want, do man unique
Absolutely any language not influenced by C is better than C.
That's a strange way to say nothing's better than C
...
>not devs.
A CS degree doesn't make you a dev. Not at all.
Most CS students I see, meet and met know jack shit nor burn with enough passion for development to amount to a real developer.
If you want to be a developer, sit down your ass, and have it spanked, bruising and hurting until your farts shit out abstractions.
>Unfortunately yes, it's one of Java's many small faults and is required to output outside of the switch statement
doesn't look like it since i don't seem to recall ever implementing it into my program
>You'll learn clever optimizations/quality-of-life tricks by trial and error and repetition.
leake forgoing the whole result and input variable fiasco?
>You have the basic idea for sure, and that's what's important.
what was the basic idea again? Thanks for the complement but i would appreciate an elaboration on what exactly it is i got.
>the GUI much less so if you don't have any experience with JavaFX
definitely going to forgo the GUI
>Is there anything that has to be done other than the scoring system and a GUI?
as mentioned i still need to attempt to export and distribute. in other words, i need to figure out how to zip the finished package and be able to run it on other computers without much hassle. This skill will be ueful when i start designing proper applicatins or games.
>sit down your ass, and have it spanked, bruising and hurting until your farts shit out abstractions.
that's kinda hot, I feel horny and motivated now
I got my first programming job. 99% of the workday I spend on fixing issues brought up by my nitpicking coworker.
How do I get his nitpicking skills so I don't waste his time, and can deliver code that is first time right?
That's some of the worst advice.
Yes documentation is important but all of school documentation is outdated and probably wouldn't fit with your worksplaces idea of tidy anyway. You learn from what they do at the company.
Like fucking this shit would never fly at my company. That stuff would only be useful if you work on a company where you're expected to have extremely fragmented developer time. If you write every other line of a system or whatever. If you write a significant code chunk you need to provide a good API and document the reasons for the design (i.e. if you find that using a continuous array is better for performance than whatever clever data-structure solution you came up with you write that down). You shouldn't explain how things are done the code does that.
github.com
wtf, why is npm so bizarre
a 6502 reference in man format would be neat but fuck writing man pages is shit
isPositiveInteger(0) // false
Does that imply it's negative, becouse its neither,
0 = ±0
A place where `tralse` would be appropriate.
>doesn't look like it since i don't seem to recall ever implementing it into my program
This is because you choose to output "success/retry" INSIDE the switch statement rather than outside, which obfuscates the code by adding repetitive lines where only one could suffice. The same is done with your input.
>leake forgoing the whole result and input variable fiasco?
No, I was more thinking using a workaround for that "fiasco" in order to make your code flow better and be easier to read.
>what was the basic idea again? Thanks for the complement but i would appreciate an elaboration on what exactly it is i got.
You understand how to program what you need, but what you don't understand is how to program what you need elegantly. Realistically, switch statements are massive and can be hard to decipher compared to just procedural lines of code, so it makes sense to make them as small as possible. Your for loop for example, could be compacted into a much more readable and "pretty" for loop as I'll post in the next comment with the introduction of a string to store the operation word.
Readability is extremely important in programming. If you plan on making a career out of it, it's about as important as making sure the code functions properly. You'll learn that there's a way to do things, and then there's a way to do things properly. The "fiasco" that you say my code introduces is a workaround to make the code readable. It's a small price to pay.
...
String opWord = ""; //"fiasco"
...
for (int t = 1; t != 10; t++){
a = rng.nextInt(range);
b = rng.nextInt(range);
switch (op) {
//addition
case 0:
result = a + b;
opWord = "add";
break;
//subtraction
case 1:
result = a - b;
opWord = "subtract";
break;
//division
case 2:
result = a / b;
opWord = "divide";
break;
//multiplication
case 3:
result = a * b;
opWord = "multiply";
break;
//error message
default:
System.out.println("programming is fucked");
} //switch
System.out.println("Please " + opWord + " " + a + " and " + b + ": ");
input = in.nextInt();
System.out.println( (input == result ? "correct" : "retry"));
} //for
No, zero is neither positive nor negative.
>what is IEEE 754
Man pages are in some ancient format that dates back to the mid 60s, no wonder it's shit.
a standard for floating-point arithmetic, not applicable to integer arithmetic
>Is 10 greater or less than 10
>Neither
>Yeah but it says so right here that it's less than
>isCat(Bird) //false
Does this imply it's a dog?
Kys
Java pajeets.
What the actual fuck does a CS major consist of in the USA?
and you are?
Why not use (x > 0)?
Or is the "is integer" more important part of the deal?
already improved it.
Here it is:
public class Math_Master {
public static void main(String[] args) {
//RNG
Random r = new Random();
//set random operator selector
int op = r.nextInt(3);
//random integer values
int a, b;
//Scanner
Scanner s = new Scanner(System.in);
//user input
int I;
//universal operator
int result;
//score
//int right = 0;
//int wrong = 0;
//integer variable range
System.out.println("please input numerical range:");
int range = s.nextInt();
for (int t = 1; t != 10; t++){
a = r.nextInt(range);
b = r.nextInt(range);
I = s.nextInt();
switch (op) {
//addition
case 0:
System.out.println(a + " + " + b + "=");
result = a + b;
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//subtraction
case 1:
System.out.println(a + " - " + b + "=");
result = a - b;
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//division
case 2:
System.out.println(a + " / " + b + "=");
result = a / b;
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//multiplication
case 3:
System.out.println(a + " * " + b + "=");
result = a * b;
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//error message
default:
System.out.println("programming is fucked");
}
}
}
}
I wish i had the streamlining skills that you do.
I had not though to introduce a string variable to substitute segments of the string.
Going to work on it now, see if i can streamline anything else (though i suspect not).
>Using if clauses insted of using a array of function pointers
Seriously hope you guys don't waste precious memory like
>I had not though to introduce a string variable to substitute segments of the string.
Dysgenics is a real phenomenon folks.
Explain further.
Step 1:
Declare functions that do what you would do in the if clauses
Step 2:
Make an array of functionpointers
Step 3:
Acces the correct function by doing the following
(*array_name[if_val])(inputs)
Only works if you have small sequential values
How does this avoid if clauses?
I feel like he's talking about instruction cache. But I'd say that his advice is retarded because processor wouldn't be able to branch predict with such an array.
hi Sup Forums. I'm new to programming. I am currently trying to learn Java from Michael Fudge from jewtube.
I'd love to hear if you have some material that'd be useful during my studies.
Lets say you want to do x if val == 0 and y if val == 1
You write two functions, one that does x and one that does y
You make an array of their pointers, lets call it arr
Now you can just go arr[val]() without wasting memory on if clauses
tried this.
code is fucked.
there is such a thing as oversimplifying code.
Dont use switch case
Use functionpointers in an array
Let's say I want to do x if val < 0 and y if val > 0.
i take that comment back.
With those streamlining skills the application will likely never work.
So basically, what you meant to say is
>>using switch case instead of using an array of function pointers
because
what do you know so far?
>Most CS students I see, meet and met know jack shit nor burn with enough passion for development to amount to a real developer.
how the fuck can anyone live and breathe programming? i mean its not bad as a job, i certainly dont hate it, but in my spare time ive got other shit i want to do more for the most part.
I will just assume val is a signed 8 Bit Integer
You would have to have a function pointer array of length 256, the 1-127 indexes point to y, 128 - 255 point to x, 0 is undefined
Then you acces that array by
arr[(uint8_t)val]()
give me time and i will write an exemplary omniscript.
this is final product.
as streamlined as it can get without being broken:
package Math;
import java.util.Random;
import java.util.Scanner;
public class Math_Master {
public static void main(String[] args) {
//RNG
Random r = new Random();
//set random operator selector
int op = r.nextInt(3);
//random integer values
int a, b;
//Scanner
Scanner s = new Scanner(System.in);
//user input
int I;
//Universal Operator
int result;
//Operator Name
String type;
//score
//int right = 0;
//int wrong = 0;
//integer variable range
System.out.println("please input numerical range:");
int range = s.nextInt();
for (int t = 1; t != 10; t++){
a = r.nextInt(range);
b = r.nextInt(range);
I = s.nextInt();
switch (op) {
//addition
case 0:
result = a + b;
type = " + ";
System.out.println(a + type + b + "=");
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//subtraction
case 1:
result = a - b;
type = " - ";
System.out.println(a + type + b + "=");
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//division
case 2:
result = a / b;
type = " / ";
System.out.println(a + type + b + "=");
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//multiplication
case 3:
result = a * b;
type = " * ";
System.out.println(a + type + b + "=");
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//error message
default:
System.out.println("programming is fucked");
}
}
}
}
And I will just use conditionals instead.
Fine Pajeet, do what you want
Aren't you asking for input before you ask the question? Try to ask for user input after the switch statement
No, you are Pajeet.
what are you, retarded?
I need to define integers, input, result, etc BEFORE i print the text asking for input. If i do it the other way around then the code is fucked.
You can improve it further. If you going to use a type variable, put the print statements after the switch statements. Not everything has to be inside it.