Open Side Menu Go to the Top

10-11-2013 , 05:56 PM
Wow you guys still on this? This is the simplest way I can think of (I haven't checked, no Java here):

Code:
public static int countRepeats(int [] a)
{
   int count = 0, last = 0;
   for (int i = 1; i < a.length; i++)
   {
      if (a[i] != a[last]) last = i;
      if (last + 1 == i) count++;
   }
   return count;
}
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
10-11-2013 , 06:05 PM
You always increment count on i = 1, did you mean to do that?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2013 , 06:08 PM
Quote:
Originally Posted by kerowo
You always increment count on i = 1, did you mean to do that?
It doesn't if a[1] != a[0]
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2013 , 07:22 PM
I like candybar's solution. I think it might be my favorite.

For clarity I would rename last to "indexAtLastChange" or something similar in meaning but shorter.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2013 , 07:47 PM
I like candybar's too, although it took me a while to figure out what it was doing. I had one with a similar structure but using a boolean flag (see below).

I agree with the more descriptive variable name. Also change the second if to an else if for efficiency.

Code:
public static int countRepeats(int[] a) 
{
  int count = 0;
  boolean lastRepeated = false; 
  for(int i=0; i < a.length-1; i++ ) 
  {
	if (a[i] != a[i+1])
	{
	    lastRepeated=false;
	}
	else if (!lastRepeated)
	{
	    count++;
	    lastRepeated=true;
	}
  }
  return count;
}
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2013 , 07:49 PM
Quote:
Originally Posted by candybar
It doesn't if a[1] != a[0]
doh!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2013 , 07:51 PM
yeah, that's an improvement. the boolean is clearer than the index.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2013 , 09:50 PM
Ha! jaytorr had me wondering if Java was some crazy language where that inner loop had some different meaning than I thought it did. What I was attempting to describe was O(n) time and certainly should not have had two loops. I should have just wrote it in semi-real code, I guess.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2013 , 10:54 PM
Quote:
Originally Posted by daveT
I should have just wrote it in semi-real code, I guess.
Target language is java, so this is not possible ZING
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2013 , 11:44 PM
Team Leader: "Mr Cracker, you've shown an incredible talent and we've decided to expand into the mobile market with an intense focus on the Android platform. We would like you to take the helm on this project."

t_c: "I'm sorry, what programming language will we use?"

Team Leader: "Uh... JAVA? Wtf?"

t_c: "**** you."

Team Leader: "We'll pay you 2x the moneyz."

t_c: "**** you."

Team Leader: "Well pay you 3x the moneyz."

t_c: "**** you."

Team Leader: "Then you're fired."

t_c: "Thanks!"
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2013 , 01:10 AM
daveT,

I tried to keep it as close as possible to what you wrote, which did have the two loops. Both solutions are still O(n) though, one pass through the array, although I realize now that wasn't clear.

BTW I share the sentiment about java, it was the first language I attempted to learn and let's just say that was a mistake.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2013 , 01:20 AM
Quote:
Originally Posted by derada4
adios-

What do you mean specifically by

I'm naturally a very productive/hard worker and have always taken pride in my work...especially if it's something I find interesting. Do you mean consulting the manager periodically about how I can be more productive, asking him to review my productivity, or do you mean consulting him and saying "hey look how productive I am"?
Just get a status from your manager periodically to make sure that you're both on the same page and you're meeting/exceeding his/her expectations.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2013 , 01:46 AM
dave,

java is above the bar of "**** i'm willing to put up with for $$$"[1][2], but otherwise it's like you were a fly on a wall in san mateo circa november 2004 .

[1] java isn't even the worst thing i've accepted money to work on. that honor goes to (and it sounds pedestrian, but let's keep it real) windows in general, and the vs2005 build "system" in specific.

[2] little known fact: `$$$` is valid perl for currency manipulation.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2013 , 02:01 AM
Quote:
Originally Posted by tyler_cracker
[2] little known fact: `$$$` is valid perl for currency manipulation.
And here I thought $$$ is valid Perl for regex, declaring variables, passing variadic arguments, declaring types, writing generators, returning undeclared, calling user input. Well, what do I know?


Quote:
Originally Posted by jaytorr
daveT,

I tried to keep it as close as possible to what you wrote, which did have the two loops. Both solutions are still O(n) though, one pass through the array, although I realize now that wasn't clear.
jaytorr, I was thinking of something similar to this in my description, but in Python because I can't figure out a better way to describe it. Not exactly how I'd like to write it, but its easy enough to read:

Code:
def countDupes(stack):
    if len(stack) <= 1:
        return 0
    candidate = stack.pop(0)
    counter = 0
    tf = False
    while len(stack) > 0:
        if candidate == stack[0] and tf is False:
            counter += 1
            tf = True
        else: 
            tf = False
        candidate = stack.pop(0)
    return counter
and the set-notation one, though more "Pythonic":

Code:
def countMoreDupes(oL):
    A = {i for i in oL[::2]}
    B = {i for i in oL[1::2]}
    return len(A & B)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2013 , 06:37 AM
Quote:
Originally Posted by derada4
woo hoo, they met my salary requirement...just signed the deal =D

I'm thinking of starting a thread/blog chronicling my journey into the development world from ground zero. Something like a "Diary of a Junior Developer".

I would have loved to read something like that when I was deciding to take CS up in school/apply for jobs.

Sound interesting?
Talk to you new employers before doing that or at the very least be very careful what you write about.

Good luck with the new job

Edit: Would be interested in what strongly/statically typed languages people prefer and actually use over Java. Main thing that bothers me about Java is the strange naming of stuff in general. It does have a pretty sick infrastructure of pretty much any stuff imaginable though.
I generally enjoy weak/dynamic typing more but like I said I want to work on my Java a bit because I want to be at least fairly comfortable in one statically typed language. Guess I could just go with Scala instead (or Groovy as it also has static type checking via annotations or something slick iirc)...I'd actually be open to suggestions here. I do kind of want to keep the whole Javaland infrastructure and be as compatible to it as possible and pick up a statically typed language.
My current plan is to ramp up the Java a bit and then check and see once Java 8 becomes mainstream (mostly compare to Scala)

Last edited by clowntable; 10-12-2013 at 06:54 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2013 , 07:59 AM
There's always Go for a statically typed language. It can infer types really well too.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2013 , 11:29 AM
There's also typed clojure. (Though I don't use it or know much about it.)

Here's one team that's using it in production:
http://blog.circleci.com/supporting-typed-clojure/
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2013 , 12:44 PM
We have a pretty big code base of both Python (Web Server) and Java (Task processing ****) . Any significant refactoring of Java is about 1/4 the time of the equivalent refactoring in Python.

Even though Python is clearly better for small stuff I don't think I would use it for a medium/large size production project again.

I don't love Java but I love most of the tools that exist that make working with it pretty easy. I' d also like to hear about other options though.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2013 , 12:59 PM
I feel like my choice will end up being Scala assuming it's basically "hotswappeable" with Java. There's a decent sized Java codebase that I'd like to rewrite and opensource eventually so that would be a good project to learn whatever language I pick (which may be Java in the end, stuff will be rewritten from scratch more or less regardless).

Quote:
Even though Python is clearly better for small stuff I don't think I would use it for a medium/large size production project again.
I've seen it used in a pretty large project and it worked fairly well. Even with some not so neat trickery (monkey patching quite a bit) everything was fairly manageable and clear. Performance was good enough for corporate use as well.
I can see how stuff could go wrong pretty quickly though if you're not careful and/or quite experienced with Python (if say I started a bigish project from scratch I'd run into many issues I'd guess).

Last edited by clowntable; 10-12-2013 at 01:14 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2013 , 04:55 PM
Quote:
Originally Posted by jtollison78
There's also typed clojure. (Though I don't use it or know much about it.)

Here's one team that's using it in production:
http://blog.circleci.com/supporting-typed-clojure/
That article reads like a 14 year-old girl's trip report to a One Direction concert. Makes me not want to use Typed Clojure at all.

I know all 20 or so real-deal Clojurians in LA (and a handful are very important to the ecosystem of the language), and as far as I can tell no one is using it yet. The first issue is that no one is sure how Rich Hickey feels about the current state of the project. The second issue is that the syntax is plain awful. The third is that it isn't complete yet. All of these elements combined causes some hesitation: what will it look like in 6 months when it is done and RH + co. calls for syntactic and functionality changes?

There is no denial that typing, in the correct context, is an improvement over type-hinting and reflection, but currently, Clojure is in constant flux, so no one really rushes to adopt things early. In fact, there are tools that allow you to "try" something before installing it as a dependency.

One thing that was brought up, and as far as I know is incorrect, is that there is a possibility that the *entire* code-base would have to be typed, and if that is true or ends up being true, then there is about zero chance that this would be adopted on any meaningful scale.

There is also the Prismatic library for typing, which looks very clean.

My main issue is admittedly an ad-hominem. Ambrose is some kid doing this for his school thesis. That doesn't mean he doesn't know what he is doing, but I would prefer it if it was someone who uses the program day-to-day with a team.

From what I've seen, those that use Clojure here in the day-to-day are brilliant programmers. It would take them using it before I would start to adopt it.

Last edited by daveT; 10-12-2013 at 05:04 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2013 , 05:16 PM
http://jsfiddle.net/hwd96/ well this shockingly works like total crap on mobile so that was a big waste of time
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2013 , 05:46 PM
Quote:
Originally Posted by derada4
woo hoo, they met my salary requirement...just signed the deal =D

I'm thinking of starting a thread/blog chronicling my journey into the development world from ground zero. Something like a "Diary of a Junior Developer".

I would have loved to read something like that when I was deciding to take CS up in school/apply for jobs.

Sound interesting?
Maybe... just be careful you don't jeopardize your job and future opportunities. Blogs can bite you in the ass in multiple ways.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2013 , 06:36 PM
Yeah from yours and clowntables response I'm sort of leaning towards not doing it now. Thanks for the heads up.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-13-2013 , 01:40 AM
Quote:
Originally Posted by Grue
http://jsfiddle.net/hwd96/ well this shockingly works like total crap on mobile so that was a big waste of time
weird.... i'm curious why its so bad. i tried it on my ipad and really it should be capable of rending that smoothly.

you should post on SO about it.

also, if you don't mind the limited support for older browsers, you may have better luck with using svg for this. it wouldn't be much harder to do
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-13-2013 , 05:25 AM
I actually think that keeping a technical/selfdevelop blog is a really good idea. Just be aware of the potential issues.

It improves your writing and thought process and if you set a shedule for posts also your time management and tracks your development (which is surprisingly helpful for future jobs)

I'd suggest settling in maybe taking some notes during the first couple of month and then eventually blogging.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m