So I'm surprised to see that we don't really have a programming thread. We do have one, but it's from 2006.Alas, I don't seem to have much aptitude for programming aside from just enough Perl to keep my systems running properly. Haskell certainly looks interesting, though. I do remember taking a programming class (which I had to drop due to my aforementioned lack of skill in that area) in which another student actually took it upon himself to complete one assignment in brainfuck. I left before I found out as to whether or not he was successful.
I've just started to read "Learn you some Erlang for great good", a Erlang-guide based on the relatively well known "Learn you a Haskell for great good". It's good!
So what obscure programming languages do you enjoy, what anecdotes do you have to tell?
Or maybe Erlang, but who the fuck uses Erlang in a business.
It's fast at not doing anything else useful than writing text. You're shooting yourself in the foot, and slowing your progress considerably if you stick with a text editor.
Seriously, if I was hiring a Java developer, and asked them "what's your IDE of choice", and got a text editor as a reply, I'd show them the door. The amount of speed and utility you get from any IDE is just incredible when compared to plain text, and I'd know I would be getting a lot more and better work from somebody who knew how to use proper tools
Make sure that calling "mvn package" puts the correct main class in the resulting Java manifest. Also set the two settings of the maven-jar-plugin "addDefaultImplementationEntries" and "addDefaultSpecificationEntries" to "true". (This causes the jar which is produced by maven to be executable)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
...
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addClasspath>true</addClasspath>
<mainClass>mainPackage.MainClass</mainClass>
</manifest>
</archive>
</configuration>
...
</plugin>
Write the classes "Point", "Line", and "Triangle". A point is a two-dimensional "double" Vector, a line segment consists of two, a triangle of three points.
For the class "Point" a constructor, that creates a Point out of two "double" values. Also write constructors for the classes "Line" and "Triangle", which create a line segment or a Triangle out of two or three points respectively.
Write a method for the class "Line", which returns the point of intersection between itself and another given line segment, if it exists.
Write a constructor for "Triangle", which creates a triangle out of three line segments.
What do you need to change, if you transfer this into a three dimensional space? Which advantages do you now see in object oriented programming?
Uuuuhrghr Haskell.
Apparently it's not that bad when you learn to write it properly, but I saw one to many "couldn't match the expected type '[[Bool]]' with actual type '[[[[Bool]]]]'" in my half-semester of being taught it. I might try it again. They've got a really great book (Learn You A Haskell For Great Good), and at least it's not fucking Lisp.
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))()())))))))))))))))))))()))))))
)))))))))))))))))))))))))))))))))))))))))))))))())))))))))))))))))))))))))))))))))
)())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))()))))))))))))))))))
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
Intersection between two line segments? Argh. The simplest solution I've found was this (http://ix.io/bZb/cpp) C++ code.
Point get_line_intersection(Line line1, Line line2)
char get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y, float p2_x, float p2_y, float p3_x, float p3_y, float *i_x, float *i_y)
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Triangle other = (Triangle) obj;
if (p1 == null) {
if (other.p1 != null)
return false;
} else if (!p1.equals(other.p1))
return false;
if (p2 == null) {
if (other.p2 != null)
return false;
} else if (!p2.equals(other.p2))
return false;
if (p3 == null) {
if (other.p3 != null)
return false;
} else if (!p3.equals(other.p3))
return false;
return true;
}
Return char? Whut?Code: [Select]char get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y, float p2_x, float p2_y, float p3_x, float p3_y, float *i_x, float *i_y)
My kid is asking to learn some programming again. Really not sure where to steer them.
There's probably an emacs command for that.
Seriously, if I was hiring a Java developer, and asked them "what's your IDE of choice", and got a text editor as a reply, I'd show them the door. The amount of speed and utility you get from any IDE is just incredible when compared to plain text, and I'd know I would be getting a lot more and better work from somebody who knew how to use proper tools. Maybe I'd accepts a pretty heavily pimped Vim, but that's a stretch.
data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
deriving (Enum, Eq, Show)
next :: Day -> Day
next Sun = Mon
next d = succ d
proceed :: Day -> Int -> Day
proceed x y | y == 1 = next x
| otherwise = proceed x (y-1)
*Main> proceed Mon 9
Wed
and what's happening is this:*Main> proceed Mon 9
Tue
proceed :: Day -> Int -> Day
proceed x y | y > 0 = proceed (next x) (y-1)
| y <= 0 = x
ArrayList<Integer> list = new ArrayList<>();
ArrayList<Integer> list2 = new ArrayList<>();
list.add(5);
list2.add(5);
System.out.println(list == list2);
10 LET X = 0
20 PRINT "BASIC turns 50 this year."
30 LET X = X + 1
40 IF X = 50, THEN GOTO 60
50 GOTO 20
60 PRINT "I feel old. This was the first language I learned how to program."
70 END
/**
* Constructs a Triangle from three line segments
*
* @param l1
* The first line segment
* @param l2
* The second line segment
* @param l3
* The third line segment
* @throws GeometryException
* if the three lines does not represent a valid triangle
*/
public Triangle(Line l1, Line l2, Line l3) throws GeometryException {
...
}
public Triangle(Line l1, Line l2, Line l3) {
assert isValidTriangle(l1,l2,l3);
...
}
public static void main(String[] args) {
String s = "This is a pointer to a String";
change(s);
System.out.println(s); //prints "This is a pointer to a String
}
private static void change(String s) {
s = "This makes the local s variable point to a different String";
}
Heartbleed wouldn't have happened had it been written in a higher level language!
I don't know why, but to me C is a lot more intuitive than Java. I tell the computer what to do, it does what I tell it to do, and if it does something wrong, then I can be relatively sure that I made a mistake somewhere.
Ihr code hier
machen Sie das schneller
public class DoublyLinkedList<DataType> {
MyLinkedListNode<DataType> head;
MyLinkedListNode<DataType> tail;
}
public class DoublyLinkedListNode<DataType> {
DataType data;
MyLinkedListNode<DataType> previous;
MyLinkedListNode<DataType> next;
}
public void insertFirst(DataType data) {
DoublyLinkedListNode<DataType> node = new DoublyLinkedListNode<DataType>(data);
head.setPrevious(node);
head = node;
}
public void insert(DataType data) {
map[data.hashCode].addFirst(data);
}
In computer science results of a time-wise expensive operation are often saved to be able to access them faster later on. Such an expensive operation is for example loading of data from the hard drive to the RAM, or the rendering of downloading of map tiles on a GPS. A data structure which allows this is called "cache". Usually the memory in which the data is to be buffered is too small to back up all requests. In this case some entries need to be removed. Which those are is decided by an eviction strategy.
One of the most common stategies is "Least Recently Used (LRU)", where the entry which hasn't been read for the longest time is deleted. To find this entry one can, instead of using timestamps, combine a doubly linked list with a hash table in an elegant way. The following picture shows the schematical setup of this data structure:
<picture here>
Your task is to implement this in Java. Your data structure should implement a method ValueType retrieve(KeyType key) in O(1), which returns the value to a given key. The hashtable contains all cached elements. The doubly linked list displays the age of these elements. A retrieve first checks whether an entry is already cached, using the hashtable. If this is the case, it needs to be removed from it's current position in the list and moved to the front. Else it needs to be read from the background container (expensive!) and inserted into hashtable and chained list. To solve this task use the following data, which can be retrieved from the lecture website:
ContainerInterface.java: An interface for the underlying operations.
SlowRam.java: An example container which implements this interface.
PagerInterface.java: An interface for the Cache.
Pager.java: An abstract class which implements this interface.
LRUCacheTest.java: A JUnit-class which you can use for testing your class. It's also the task your handed in solution will be pre-checked.
Create a Java Class LRUCache in a file named "LRUCache.java". Your class needs to extend Pager. Only upload this single file. You'll receive one point, if you hand in a non-trivial solution, which passes the JUnit test. You'll receive additional three points if you implement the described structure correctly. You'll then receive four additional points if you implement the hashtable and the chained list yourself, so using neither java.util.HashMap nor a list class.
Hint: Questions like this are often being asked in job interviews.
I'd probably want to implement it using java.util.HashMap first, and implement it afterwards.
DoublyLinkedListElement[] table = (DoublyLinkedListElement[]) new Object[11]
with a damn @suppressWarnings("unchecked") beforehand. Because Java.I'm guessing you haven't had generics yet.Code: (java) [Select]DoublyLinkedListElement[] table = (DoublyLinkedListElement[]) new Object[11]
I had to resort to this, because I was getting a "cannot create a generic array".
I'm amused at all this Java shenanigans. When I had to write a cache of this sort (commercially, for money), I sketched it out in pseudocode and then implemented it in assembly language. As I recall it took about 300 bytes. The improvement in OS performance was similar to installing a SSD in modern terms.
This is a pretty good article about how things work: Java is Pass-by-Value, Dammit! (http://javadude.com/articles/passbyvalue.htm)Urgs. Thanks for reminding me why I prefer C++ over Java.
In C++ (gcc), on the other hand, options are after the sources. I think. So then it's the other way around. So the answer to your question is language-dependent.http://linux.die.net/man/1/gcc says the options come before the input file(s). Same should go for gfortran. :?
But the fucking standard is just such unhelpful pile of shit
Php is installed for the browser
It's easy enough to install it on Windows, as well. Only without the Linux bit and with a few language changes too.For a test environment, I could see using Windows. But I never would think of using it for a production environment. The only thing I can think of using a Windows server for is Exchange.
For a test environment, I could see using Windows. But I never would think of using it for a production environment.
The only thing I can think of using a Windows server for is Exchange.
.1.......
.....2...
..3..2...
..3......
4.3.4444.
4....1...
4......22
4........
.........
..1.333..
......XO..
..X.......
......O...
.O.O......
..........
.......O..
...O......
.......O..
..X.......
private int[][] field;
...
public void setCell(int x, int y, int state) throws IndexOutOfBoundsException{
this.field[x][y] = state;
}
private int[][] field;
...
public void setCell(int x, int y, Ship ship) throws IndexOutOfBoundsException{
this.field[x][y] = ship.toString();
}
Ship[] afterAdd = new Ship[this.shipCount + 1];
for (int i = 0; i < this.shipCount; i++) {
afterAdd[i] = this.ships[i];
}
afterAdd[this.shipCount + 1] = new Ship(type, dir, x, y, this);
this.ships = afterAdd;
enum ShipType{
MINENSUCHER(1),
SCHLACHTSCHIFF(2),
GROSSKAMPSCHIFF(3),
FLUGZEUGTRAEGER(4);
public final int length;
private ShipType(int length){
this.length = length;
}
public int getLength(){
return this.length;
}
}
package battleship;
public class Sea {
/**
* A representation of the ships in the coordinate field.
*/
private int[][] shipField;
/**
* A representation of the bomb-runs in the coordinate field.
*/
private String[][] bombField;
/**
* The width of the coordinate field.
*/
private int width;
/**
* The height of the coordinate field.
*/
private int height;
public Sea(int width, int height){
this.width = width;
this.height = height;
this.shipField = new int[width][height];
this.bombField = new String[width][height];
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
this.shipField[x][y] = 0;
this.bombField[x][y] = null;
}
}
}
/**
* Adds a ship to the field. Only works if the ship fits in the field,
* the field is not occupied by another ship, and no bombs
* have been thrown yet.
* @param type The ship type.
* @param dir The direction the ship is facing.
* @param x The x - coordinate of the ship-rear
* @param y The y - coordinate of the ship-rear
* @return Returns true, if the ship could be placed.
*/
public boolean addShip(ShipType type, Direction dir, int x, int y){
// Checking if the ship rear is within coordinate field.
if (x < width && x >= 0 && y < height && y >= 0){
// Checking if no bombs have been thrown yet.
for(int n = 0; n < width; n++){
for(int m = 0; m < height; m++){
if(this.bombField[n][m] != null){
return false;
}
}
}
// Getting the ship length.
int shipLength = type.getLength();
// A helper variable used in the for-loops.
int iterator;
switch(dir){
case NORTH:
// Checking if the ship fits in the coordinate field.
if((y - shipLength) >= 0){
// Checking if no other ship occupies space.
for(iterator = 0; iterator < shipLength; iterator++){
if(this.shipField[x][y - iterator] != 0){
return false;
}
}
// Placing ship.
for(iterator = 0; iterator < shipLength; iterator++){
this.shipField[x][y - iterator] = type.getLength();
}
return true;
}else return false;
// Rinse and repeat for every direction.
case EAST:
if((x + shipLength) < this.width){
for(iterator = 0; iterator < shipLength; iterator ++){
if(this.shipField[x + iterator][y] != 0){
return false;
}
}
for(iterator = 0; iterator < shipLength; iterator ++){
this.shipField[x + iterator][y] = type.getLength();
}
return true;
}else return false;
case SOUTH:
if((y + shipLength) < this.height){
for(iterator = 0; iterator < shipLength; iterator++){
if(this.shipField[x][y + iterator] != 0){
return false;
}
}
for(iterator = 0; iterator < shipLength; iterator++){
this.shipField[x][y + iterator] = type.getLength();
}
return true;
}else return false;
case WEST:
if((x - shipLength) >= 0){
for(iterator = 0; iterator < shipLength; iterator ++){
if(this.shipField[x - iterator][y] != 0){
return false;
}
}
for(iterator = 0; iterator < shipLength; iterator ++){
this.shipField[x - iterator][y] = type.getLength();
}
return true;
}else return false;
default:
return false;
}
}else return false;
}
/**
* Places a bomb on the field. Sets {@link #bombField} to X or O,
* depending on whether a boat is hit.
* @param x X-Coordinate of the bomb hit.
* @param y Y-Coordinate of the bomb hit.
* @return Returns true if a ship has been hit.
*/
public boolean dropBomb(int x, int y){
// Checks if the field is occupied, and if it is, lays an X.
if(this.shipField[x][y] != 0){
this.bombField[x][y] = "X";
return true;
}else{
this.bombField[x][y] = "O";
return false;
}
}
/**
* A method that returns true if all the ships that were
* placed in the field were sunk.
* @return True if all ships are down.
*/
public boolean allShipsSunk(){
/* Helper Variables. Ship counter counts
* every cell with a ship and sunk counter
* counts every cell with a hit mark.
*/
int shipCounter = 0, sunkCounter = 0;
// Iterate over field
for(int x = 0; x < this.width; x ++){
for(int y = 0; y < this.height; y ++){
// If cell contains ship
if(this.shipField[x][y] != 0){
// Increment shipCounter
shipCounter ++;
// If cell contains hit marker
if(this.bombField[x][y].equals("X")){
// Increment sunkCounter
sunkCounter ++;
}
}
}
}
// If shipcounter and sunkcounter are the same,
// every ship has been sunk.
if(shipCounter == sunkCounter){
return true;
}else return false;
}
public String toStringWithShips(){
String stringWithShips = "";
String concat;
for(int y = 0; y < this.height; y ++){
for(int x = 0; x < this.width; x ++){
if(this.shipField[x][y] == 0){
concat = ".";
}else{
concat = String.valueOf(this.shipField[x][y]);
}
stringWithShips.concat(concat);
}
stringWithShips.concat("\n");
}
return stringWithShips;
}
public String toStringWithBombs(){
String stringWithBombs = "";
String concat;
for(int y = 0; y < this.height; y ++){
for(int x = 0; x < this.width; x ++){
if(this.bombField[x][y].equals(null)){
concat = ".";
}else{
concat = this.bombField[x][y];
}
stringWithBombs.concat(concat);
}
stringWithBombs.concat("\n");
}
return stringWithBombs;
}
}
Sometimes you just want to throw your notebook against a wall…How on earth did you manage to get Linux to do that? I've only ever gotten a kernel panic when I had screwed up something royally...
(http://i.imgur.com/Usseuz1.jpg)
So I guess I won't get the bonus points. I won't sit here for another three hours, when I should be sleeping, only to do work I already did.
Aah, I'm more Apache and MySQL on Linux, myself. Although I'm a bit of a recent (4 years) convert to Linux after I switched from OS X.For a test environment, I could see using Windows. But I never would think of using it for a production environment.
There's nothing like a good set of blinkers! (I run Apache, Tomcat, PostgreSQL, etc on Windows at work, and the same plus Deluge and Kerio Connect at home. But I use Open BSD for firewalls).
The only thing I can think of using a Windows server for is Exchange.
.,;:_-?!
Words which are connected with a hyphen are considered one word. (e.g. this-is-all-one-word) A word may contain numbers and umlauts, but must consist of at least one letter. My current regex for that is this one:[A-ZÄÖÜ]+[^.,;:_?!\ ]*
(I use CASE_INSENSITIVE of course)String toGetWords = "a long string of tokens that blah blah blah blah blah"
String delimiters = "a string containing all the delimiter characters"
StringTokenizer st = new StringTokenizer(toGetWords, delimiters)
while(st.hasMoreTokens()){
String token = st.nextToken();
//Trim trailing hyphen, or discard the token if the trailing hyphen disqualifies it.
//Then use a regex to check if the token contains [A-ZÄÖÜ], case insensitive.
}
\d*[a-zäöü]+([a-zäöü0-9]|\-[a-zäöü0-9])*
Anyone here who knows their (Java) regexes better than I do?
I need to extract every "word" from a very long string (the strings may only contain the symbols mentioned in the description here). A word delimiter is either a space or any of the following symbols:Code: [Select].,;:_-?!
Words which are connected with a hyphen are considered one word. (e.g. this-is-all-one-word) A word may contain numbers and umlauts, but must consist of at least one letter. My current regex for that is this one:Code: [Select][A-ZÄÖÜ]+[^.,;:_?!\ ]*
(I use CASE_INSENSITIVE of course)
I still need a way to cut off a hyphen at the end of a word. I tried it with a "-?" at the end, putting the rest in parenthesis, but that doesn't work of course, because the "not these special characters" is greedy.
[A-ZÄÖÜ]+[^.,;:_?!\ ]*
(gonna call this block "word" from now on)<word>[-<word>]*
Basically saying "must have one word, but can have multiples as long as subsequent words start with a hyphen".
I think I understand how the composed search terms are supposed to work, but I'm not getting anywhere.
I think I understand how the composed search terms are supposed to work, but I'm not getting anywhere.
Well, I have no idea about what framework you have available in modern programming, which may suggest or impose a particular technique; but I would have seen this as a very simple compilation problem: parse the command string into a tree structure, then walk that in reverse-Polish order doing the required tests and thus generating the answer. Or have I missed the point of where your problem lies, through being so out of date?
if (temp_spl>90.0){
printf("9");
} else if (temp_spl<30.0) {
printf(" ");
} else if (((int)floor(temp_spl))%10 >= 5) {
printf(" ");
} else {
printf("%d",(int)floor(temp_spl/10.0));
}
So I'm doing an assignment in C, and for one part of it I have to print a specific character depending on the value of a double, temp_spl.
Basically, if temp_spl is between 30 and 35 I print a 3, 35 and 40 I print a space, and so on up to 90.
The solution I have currently is here, but it seems really clumsy. Is there a better way?Code: [Select]if (temp_spl>90.0){
printf("9");
} else if (temp_spl<30.0) {
printf(" ");
} else if (((int)floor(temp_spl))%10 >= 5) {
printf(" ");
} else {
printf("%d",(int)floor(temp_spl/10.0));
}
char* result = "9";
if(temp_spl < 90.0 && temp_spl > 30.0){
if(temp_spl % 10 < 5){
result[0] = (int) floor (temp_spl/10) + 48;
}else{
result[0] = 32;
}
}
printf("%s%n", result);
(temp_spl > 90.0) ? printf ("9") : ((temp_spl < 30.0) ? printf (" ") : ((temp_spl % 10 < 5) ? printf("%d", (int)floor(temp_spl/10.0)) : printf(" ")));
//"a ? b : c" stands for "if a, do b. Else, do c". a has to be a boolean or an expression that returns a boolean.+
//Example: Max(a, b) as ternary operation: a > b ? a : a < b ? b : a == b ? a : b;
private ImageIcon scaleFiltered(BufferedImage filtered){
double scale = (screenHeight - HEIGHT_SCREEN_PADDING) / filtered.getHeight();
// scale = 0.5;
return scaleImage(filtered, scale);
}