Doppleganger challenge

  • (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4

55 Replies - 13479 Views - Last Post: 03 September 2012 - 02:25 PM Rate Topic: -----

#46 anonymouscodder  Icon User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

Re: Doppleganger challenge

Posted 29 July 2011 - 11:45 AM

javascript
Spoiler

This post has been edited by anonymouscodder: 29 July 2011 - 11:47 AM

Was This Post Helpful? 1
  • +
  • -

#47 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Doppleganger challenge

Posted 29 July 2011 - 02:30 PM

Lua and Javascript too? This is madness!
Was This Post Helpful? 0
  • +
  • -

#48 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Doppleganger challenge

Posted 29 July 2011 - 06:22 PM

F#
open System.Linq;;
let xs1= [ 2; 5; 5; 5; 8; 3; 3; 12 ]
let xs2= [ 12; 5; 5; 1; 3; 3; 3; 4 ]
let re=xs1.Intersect(xs2)

Was This Post Helpful? 0
  • +
  • -

#49 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4577
  • View blog
  • Posts: 8,019
  • Joined: 08-June 10

Re: Doppleganger challenge

Posted 29 July 2011 - 06:37 PM

Well, yeah. Most of these languages already have a built in Intersect method. The point was to do it yourself. Like when the teacher makes you write a sort algorithm.

Also, you can use Set.intersect as well, and skip importing the Linq namespace.
Was This Post Helpful? 0
  • +
  • -

#50 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5932
  • View blog
  • Posts: 12,854
  • Joined: 16-October 07

Re: Doppleganger challenge

Posted 30 July 2011 - 05:11 AM

Given our current legion of languages, this seemed like a glaring omission.

ANSI-C
Spoiler

Was This Post Helpful? 1
  • +
  • -

#51 Nallo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 255
  • Joined: 19-July 09

Re: Doppleganger challenge

Posted 30 July 2011 - 07:30 AM

I felt like doing a different Algorithm in Python, using an AVL tree. So again it is n log n + m log n.

Spoiler

Was This Post Helpful? 0
  • +
  • -

#52 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Doppleganger challenge

Posted 30 July 2011 - 11:28 AM

This could be my most successful challenge ever:

note to self, include all languages in challenges from now on :)



thanks to everyone who participated!!

This post has been edited by atraub: 30 July 2011 - 12:13 PM

Was This Post Helpful? 0
  • +
  • -

#53 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4577
  • View blog
  • Posts: 8,019
  • Joined: 08-June 10

Re: Doppleganger challenge

Posted 30 July 2011 - 08:31 PM

View Postatraub, on 30 July 2011 - 01:28 PM, said:

note to self, include all languages in challenges from now on :)


Even if you don't, we'll probably still pop in and drop them on you. :P
Was This Post Helpful? 0
  • +
  • -

#54 xGeovanni  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-September 12

Re: Doppleganger challenge

Posted 03 September 2012 - 01:17 PM

Everything must be one line.

def commonElements(listA, listB):
    return [elA for elA in listA for elB in listB if elA == elB]


Was This Post Helpful? 0
  • +
  • -

#55 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2153
  • View blog
  • Posts: 3,313
  • Joined: 21-June 11

Re: Doppleganger challenge

Posted 03 September 2012 - 02:16 PM

View PostxGeovanni, on 03 September 2012 - 10:17 PM, said:

Everything must be one line.

def commonElements(listA, listB):
    return [elA for elA in listA for elB in listB if elA == elB]



That way commonElements([1,1], [1,1]) will return [1,1,1,1].
Was This Post Helpful? 0
  • +
  • -

#56 xGeovanni  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-September 12

Re: Doppleganger challenge

Posted 03 September 2012 - 02:25 PM

View Postsepp2k, on 03 September 2012 - 02:16 PM, said:

That way commonElements([1,1], [1,1]) will return [1,1,1,1].


Fine.

def commonElements(listA, listB):
    return [elA for elA in listA if elA in listB]



Got a problem with that one?
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4