THESE FORUMS NOW CLOSED (read only)

  • 28 Mar 2024, 04:45
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 3 [4]   Go Down

Author Topic: A programming thread!  (Read 42536 times)

ankhtahr

  • GET ON THE NIGHT TRAIN
  • *****
  • Offline Offline
  • Posts: 2,700
  • A hacker spathe night owl
Re: A programming thread!
« Reply #150 on: 01 Sep 2014, 01:17 »

I think I understand how the composed search terms are supposed to work, but I'm not getting anywhere. Besides, I have a terrible headache and feel sick. I definitely need to sleep, but I mustn't before I finished this task. Damnit.
Logged
Quote from: Terry Pratchett
He had the look of a lawn mower just after the grass had organised a workers' collective.

Loki

  • comeback tour!
  • *****
  • Offline Offline
  • Posts: 5,532
  • The mischief that dwells within
Re: A programming thread!
« Reply #151 on: 01 Sep 2014, 01:20 »

Cannot help you there, unfortunately, except through moral support :(
Logged
The future is a weird place and you never know where it will take you.
the careful illusion of shit-togetherness

pwhodges

  • Admin emeritus
  • Awakened
  • *
  • Offline Offline
  • Posts: 17,241
  • I'll only say this once...
    • My home page
Re: A programming thread!
« Reply #152 on: 01 Sep 2014, 03:00 »

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?
Logged
"Being human, having your health; that's what's important."  (from: Magical Shopping Arcade Abenobashi )
"As long as we're all living, and as long as we're all having fun, that should do it, right?"  (from: The Eccentric Family )

ankhtahr

  • GET ON THE NIGHT TRAIN
  • *****
  • Offline Offline
  • Posts: 2,700
  • A hacker spathe night owl
Re: A programming thread!
« Reply #153 on: 01 Sep 2014, 03:07 »

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?

No, not really. I just didn't really think of such a solution. I've done basically everything in this task with regular expressions, so I only thought about regular expressions here as well.

I've managed to get a tiny bit further, which should give me at least a few points more, and now I'm so tired that I'll probably leave it at that and go to bed.

My horrible code can be found here if anybody feels like torturing themselves. I started out alright, but it got messier and messier with every hour. Now it's a trainwreck.
Logged
Quote from: Terry Pratchett
He had the look of a lawn mower just after the grass had organised a workers' collective.

ankhtahr

  • GET ON THE NIGHT TRAIN
  • *****
  • Offline Offline
  • Posts: 2,700
  • A hacker spathe night owl
Re: A programming thread!
« Reply #154 on: 14 Sep 2014, 11:52 »

So I'm now working on the second final task. Admittedly, I started very late (I have to be finished in 17 hours), but so far I don't see any big problems with it. It's a nice task. We have to model Conway's Game of Life with some variations. I'm considering throwing some design patterns on the task, but I don't think I really need to.
Logged
Quote from: Terry Pratchett
He had the look of a lawn mower just after the grass had organised a workers' collective.

Masterpiece

  • Older than Moses
  • *****
  • Offline Offline
  • Posts: 4,364
  • No time for Claireification
Re: A programming thread!
« Reply #155 on: 14 Sep 2014, 12:25 »

I've done Convay's Game of Life before and I can give you some basic guidelines if you want.

ankhtahr

  • GET ON THE NIGHT TRAIN
  • *****
  • Offline Offline
  • Posts: 2,700
  • A hacker spathe night owl
Re: A programming thread!
« Reply #156 on: 14 Sep 2014, 12:27 »

Nah, don't worry, I've got this so far. And my modelling seems to work well for once  :mrgreen:
Logged
Quote from: Terry Pratchett
He had the look of a lawn mower just after the grass had organised a workers' collective.

ankhtahr

  • GET ON THE NIGHT TRAIN
  • *****
  • Offline Offline
  • Posts: 2,700
  • A hacker spathe night owl
Re: A programming thread!
« Reply #157 on: 14 Sep 2014, 20:33 »

Yep, for once my modelling didn't completely blow up in my face. I'm finished with 7.5 hours to go. My solution did work right on the first try. I was a little bit suspicious, but even more testing didn't show any real problems, except for one small OutOfBoundsException, where I had swapped two parameters. It seems like I can go sleep now. I didn't expect that to happen.
Logged
Quote from: Terry Pratchett
He had the look of a lawn mower just after the grass had organised a workers' collective.

ChaoSera

  • Scrabble hacker
  • *****
  • Offline Offline
  • Posts: 1,405
Re: A programming thread!
« Reply #158 on: 15 Sep 2014, 01:11 »

So, I don't suppose anybody knows how to connect TRACE32 PowerView to a GDB-Server, so I can use remote debugging from Eclipse?
Logged

Pilchard123

  • Older than Moses
  • *****
  • Offline Offline
  • Posts: 4,131
  • I always name them Bitey.
Re: A programming thread!
« Reply #159 on: 17 Oct 2014, 13:29 »

Trying to learn my way around WCF. I left the book I've been using at work.

EDIT: I just wrote a method for copying a file that you can't select to a location that you can't change, using three different assemblies. For some reason I am proud of this.
« Last Edit: 18 Oct 2014, 14:00 by Pilchard123 »
Logged
Piglet wondered how it was that every conversation with Eeyore seemed to go wrong.

Pilchard123

  • Older than Moses
  • *****
  • Offline Offline
  • Posts: 4,131
  • I always name them Bitey.
Re: A programming thread!
« Reply #160 on: 18 Oct 2014, 06:29 »

TIL that if you import antigravity into a python program, xkcd #353 is opened in the default browser.
Logged
Piglet wondered how it was that every conversation with Eeyore seemed to go wrong.

Schmee

  • Pneumatic ratchet pants
  • ***
  • Offline Offline
  • Posts: 349
  • ( ͡° ͜ʖ ͡°)
Re: A programming thread!
« Reply #161 on: 18 Oct 2014, 22:13 »

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));
}
Logged
work it ᕙ༼ຈل͜ຈ༽ᕗ harder 
make it (ง •̀_•́)ง better 
do it ᕦ༼ຈل͜ຈ༽ᕤ faster 
raise your ヽ༼ຈل͜ຈ༽ノ donger

ev4n

  • Scrabble hacker
  • *****
  • Offline Offline
  • Posts: 1,328
  • Shameless Shamy Shipper
Re: A programming thread!
« Reply #162 on: 20 Oct 2014, 11:34 »

If it works, that seems ok?

I can think of performance improvements, or ways that are more elegant, but I'm not sure why one would want to spend more time on improving a working solution without a good reason.

Sorry, maybe I'm being too cynical.
Logged

ev4n

  • Scrabble hacker
  • *****
  • Offline Offline
  • Posts: 1,328
  • Shameless Shamy Shipper
Re: A programming thread!
« Reply #163 on: 24 Oct 2014, 08:31 »

Wait, Ecplise thinks that to run any kind of debugger, the top level make associated with the current workspace needs to be run?

What kind of moronic idea is THAT!?!?!?!
Logged

osaka

  • Scrabble hacker
  • *****
  • Offline Offline
  • Posts: 1,438
Re: A programming thread!
« Reply #164 on: 24 Oct 2014, 08:47 »

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));
}

I'd go with something a bit more nested, but that's just me:

Code: [Select]
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);

Some hacking in here with ascii tables and how C handles pointers/arrays, but it should work. You can always define result as char[]

EDIT: I just noticed that that doesn't take into account the possibility of the value being less than 30. Also, I found a way to express it in 1 line with ternary operators, just for funziez.

Code: [Select]
(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;
« Last Edit: 24 Oct 2014, 14:40 by osaka »
Logged
Meh, if you have to run fsck, you're already fscked.

Loki

  • comeback tour!
  • *****
  • Offline Offline
  • Posts: 5,532
  • The mischief that dwells within
Re: A programming thread!
« Reply #165 on: 25 Oct 2014, 09:39 »

What'd you need the third ternary for? Is there any case where !(a&lt;b) &amp;&amp; !(a&gt;b) &amp;&amp; !(a=b)?
Logged
The future is a weird place and you never know where it will take you.
the careful illusion of shit-togetherness

osaka

  • Scrabble hacker
  • *****
  • Offline Offline
  • Posts: 1,438
Re: A programming thread!
« Reply #166 on: 25 Oct 2014, 10:37 »

Consistency. Technically, with the first two you've covered all possible outputs, but you have to define what happens when they're equal.

As a fun fact, that max(a,b) was actually a #define sentence made by a friend for our Operating Systems course. Knowing him, he probably didn't do the third part and either the compiler threw an error or the code segfaulted. So he added the third part.
Logged
Meh, if you have to run fsck, you're already fscked.

smack that isaiah

  • Beyond Thunderdome
  • ****
  • Offline Offline
  • Posts: 564
  • Tell me again what a monster is
    • Igor and the Whale
Re: A programming thread!
« Reply #167 on: 26 Oct 2014, 07:27 »

Am I missing something, or couldn't a max function be done with just one ternary operation?

#define MAX(a, b) ((a > b) ? a : b)

if a is bigger than b, use a; otherwise use b (the otherwise necessarily being "if b >= a")

I think the main reason to use the more fleshed out version that osaka has posted would be if you're using objects which have overloaded the <, >, and == operators where it may not follow that {!(a > b) == (a <= b)} (imo, this means that these operators should never have been overloaded in the first place...).  Since this would be a #define, the types of a and b are not limited to int/double/float/etc.
Logged
Luminous beings are we, not this crude matter

osaka

  • Scrabble hacker
  • *****
  • Offline Offline
  • Posts: 1,438
Re: A programming thread!
« Reply #168 on: 26 Oct 2014, 09:28 »

Indeed it could be done. Once again, this was for Operating Systems, and things tended to get a bit overdone just to make sure.
Logged
Meh, if you have to run fsck, you're already fscked.

Masterpiece

  • Older than Moses
  • *****
  • Offline Offline
  • Posts: 4,364
  • No time for Claireification
Re: A programming thread!
« Reply #169 on: 30 Mar 2015, 07:52 »

I have a problem, and was wondering whether you could help me out:

I have a method that is supposed to return a scaled instance of a Buffered Image I feed it. Since the program needs two different scaled versions of the same image, I first determine a scaling factor for the individual images and then feed that scaling factor to a general scaling method.

I know the scaling works, I also know that the methods propagate as needed. But the methods that are supposed to calculate the scaling factors always return zero. I have no idea why that happens, if I explicitly tell it that scale = 1.0, it works, but if I try to calculate scale as follows, scale will always be zero.

Code: [Select]
private ImageIcon scaleFiltered(BufferedImage filtered){

double scale = (screenHeight - HEIGHT_SCREEN_PADDING) / filtered.getHeight();

// scale = 0.5;

return scaleImage(filtered, scale);

}

any thoughts?

ChaoSera

  • Scrabble hacker
  • *****
  • Offline Offline
  • Posts: 1,405
Re: A programming thread!
« Reply #170 on: 30 Mar 2015, 08:40 »

I suppose screenHeight and HEIGHT_SCREEN_PADDING don't have the same value? Also there might be cast errors if some of the values are integers. Casting from int to double does not always work as good as one might expect.
Logged

Masterpiece

  • Older than Moses
  • *****
  • Offline Offline
  • Posts: 4,364
  • No time for Claireification
Re: A programming thread!
« Reply #171 on: 30 Mar 2015, 08:56 »

The values are not the same.

What would you do instead of casting?

ChaoSera

  • Scrabble hacker
  • *****
  • Offline Offline
  • Posts: 1,405
Re: A programming thread!
« Reply #172 on: 30 Mar 2015, 09:10 »

Declare them as double to begin with, unless you're limited by some external framework. Alternatively cast them explicetly to double, which might help as well.
Another method, although not a pretty one, would be to create Integer objects from the int values and then use the doubleValue() of those objects.
Logged

Sorflakne

  • Duck attack survivor
  • *****
  • Offline Offline
  • Posts: 1,721
Re: A programming thread!
« Reply #173 on: 15 Apr 2015, 18:33 »

So for a final project in my web publishing class, I'm making a Monopoly clone.  However, things...got off to a hairy start.  We were given a base of code to build off of that included the game board, players, and an auto-mover that moves each piece in turn on page refresh.  We have to build the rest of the game.  My partner and I got it to where an actual dice roller is working, but each page refresh not brings back a random number of errors; sometimes only three, sometimes, as the pic shows, only three thousand...



As you can see, I'm still able to make fun of myself, so maybe there's hope.
Logged
If you want to see what God and Satan look like, look in the mirror.

Masterpiece

  • Older than Moses
  • *****
  • Offline Offline
  • Posts: 4,364
  • No time for Claireification
Re: A programming thread!
« Reply #174 on: 15 Apr 2015, 19:42 »

Reminds me of this:

[tweet]484373063077998592[/tweet]

Pilchard123

  • Older than Moses
  • *****
  • Offline Offline
  • Posts: 4,131
  • I always name them Bitey.
Re: A programming thread!
« Reply #175 on: 27 May 2015, 11:56 »

Logged
Piglet wondered how it was that every conversation with Eeyore seemed to go wrong.

Masterpiece

  • Older than Moses
  • *****
  • Offline Offline
  • Posts: 4,364
  • No time for Claireification
Re: A programming thread!
« Reply #176 on: 27 May 2015, 12:29 »

WHAT THE EFF, ORACLE.

cesium133

  • Preventing third impact
  • *****
  • Offline Offline
  • Posts: 6,148
  • Has a fucked-up browser history
    • Cesium Comics
Re: A programming thread!
« Reply #177 on: 27 May 2015, 13:18 »

To be fair, Oracle has always been evil.
Logged
The nerdy comic I update sometimes: Cesium Comics

Unofficial character tag thingy for QC

pwhodges

  • Admin emeritus
  • Awakened
  • *
  • Offline Offline
  • Posts: 17,241
  • I'll only say this once...
    • My home page
Re: A programming thread!
« Reply #178 on: 28 May 2015, 02:44 »

The report is unclear to me - it seems to say that Google was using a bit of the actual Java code to implement the API.  In that case, the copyright issue would lie with the code rather than the API itself, which there would be strong defences over, concerning the natural way to pass information (I was involved in an international software copyright dispute in the 1970s - but there's a lot more law to deal with now, I admit).

As for Oracle - evil?  Probably, just like pretty much any corporation of its size.  Incompetent?  You know how the current version of Java is [1.]8?  And updates for earlier versions are no longer available?  Well, my university's finance and student information systems are written by Oracle, in Java, and both were recently updated - they both will only run with Java [1.]6!  We get privately issued security updates for it (the last public update was #45, we're currently at #94), but there is a currently ongoing argument about whether our licence entitles us to use them!
« Last Edit: 28 May 2015, 02:50 by pwhodges »
Logged
"Being human, having your health; that's what's important."  (from: Magical Shopping Arcade Abenobashi )
"As long as we're all living, and as long as we're all having fun, that should do it, right?"  (from: The Eccentric Family )

Masterpiece

  • Older than Moses
  • *****
  • Offline Offline
  • Posts: 4,364
  • No time for Claireification
Re: A programming thread!
« Reply #179 on: 28 May 2015, 03:22 »

The problem is rather, that Oracle is suing Google because they're using API commands that have the exact same nomenclature in Java. In most cases, the only thing they kept is the method declaration, and changed the method bodies.

Oracle is suing Google because they used the same names for their API. Which I think is ridiculous.

Masterpiece

  • Older than Moses
  • *****
  • Offline Offline
  • Posts: 4,364
  • No time for Claireification
Re: A programming thread!
« Reply #180 on: 28 May 2015, 03:27 »

pwhodges

  • Admin emeritus
  • Awakened
  • *
  • Offline Offline
  • Posts: 17,241
  • I'll only say this once...
    • My home page
Re: A programming thread!
« Reply #181 on: 12 Jul 2015, 17:09 »

Logged
"Being human, having your health; that's what's important."  (from: Magical Shopping Arcade Abenobashi )
"As long as we're all living, and as long as we're all having fun, that should do it, right?"  (from: The Eccentric Family )

hedgie

  • Methuselah's mentor
  • *****
  • Offline Offline
  • Posts: 5,382
  • No Pasarán!
Re: A programming thread!
« Reply #182 on: 12 Jul 2015, 18:05 »

Meh.  Perl or death for me.
Logged
"The highest treason in the USA is to say Americans are not loved, no matter where they are, no matter what they are doing there." -- Vonnegut

cesium133

  • Preventing third impact
  • *****
  • Offline Offline
  • Posts: 6,148
  • Has a fucked-up browser history
    • Cesium Comics
Re: A programming thread!
« Reply #183 on: 12 Jul 2015, 18:07 »

Randomly-generated ASCII characters do not a programming language make.
Logged
The nerdy comic I update sometimes: Cesium Comics

Unofficial character tag thingy for QC
Pages: 1 2 3 [4]   Go Up