Jump to content


Photo

Challenge: BASIC001


  • Please log in to reply
29 replies to this topic

#21 REvolution

REvolution

    the 0ne

  • Members
  • 1 posts
  • Gender:Male

Posted 19 February 2010 - 10:56 AM


So.... Is everyone using C#??

I recognize that <studio.h> header


um, No. most of it is in C

and it's <stdio.h> the Standard C library I/O functions,


void swap(int* a,int* B){

*b=*b+*a;
*a=*b-*a;
*b=*b-*a;

}

#22 SigFLUP

SigFLUP

    SUPR3M3 31337 Mack Daddy P1MP

  • Members
  • 367 posts
  • Gender:Not Telling

Posted 20 February 2010 - 05:20 PM

SigFlup, Could you explain how yours works. I'm curious to know what's happening there.


oh sorry, I didn't really answer that. If you xor something by a number and xor it again you get the same number... so it's kinda like hiding a number inside another number. So we xor one number into another and the other into the first one. Rinse and repeat and you just swapped them.

#23 z3ros3c

z3ros3c

    Will I break 10 posts?

  • Members
  • 4 posts
  • Gender:Male

Posted 18 May 2010 - 12:34 AM

Here's my implementation in Python. I'm kind of surprised nobody did this... It doesn't seem to break the rules at all.

Spoiler

Granted, it's not as cool as doing the XOR trick, but it's a lot shorter code than anyone else has written.

You can also shorten it even further, like so:

Spoiler

Edited by z3ros3c, 18 May 2010 - 12:36 AM.


#24 Lord Wud

Lord Wud

    SUPR3M3 31337 Mack Daddy P1MP

  • Members
  • 423 posts
  • Location:New Jersey

Posted 13 September 2010 - 09:52 AM

Here's my answer with python. I looked around at some other peoples, and I feel like I'm missing something huge though. If I am could someone care to explain?

Spoiler

Edited by Lord Wud, 13 September 2010 - 09:52 AM.


#25 codered22

codered22

    Will I break 10 posts?

  • Members
  • 5 posts
  • Gender:Male

Posted 22 October 2010 - 01:43 PM

This is quite fun. ;)

Spoiler


#26 heisenbug

heisenbug

    Gibson Hacker

  • Members
  • 79 posts
  • Country:
  • Gender:Male

Posted 04 March 2011 - 09:18 PM

Once again Perl is awesome.

Spoiler


#27 pix6ie

pix6ie

    Will I break 10 posts?

  • Members
  • 8 posts
  • Gender:Male

Posted 22 May 2011 - 12:58 PM

In python:

a = 10
b = 20
a = a*2
b = a/2

Is this too simplified??

#28 rainwater_stillicide

rainwater_stillicide

    SUP3R 31337 P1MP

  • Agents of the Revolution
  • 282 posts
  • Location:Scotland

Posted 22 May 2011 - 02:11 PM

In python:

a = 10
b = 20
a = a*2
b = a/2

Is this too simplified??


It's not too simplified (it does take two variables and swap them) but it doesn't do it in a general way, it will only work for certain numbers (i.e., where b = 2a).

Try and come up with a solution which can work for an arbitrary pair of numbers.

#29 heisenbug

heisenbug

    Gibson Hacker

  • Members
  • 79 posts
  • Country:
  • Gender:Male

Posted 22 May 2011 - 03:08 PM


In python:

a = 10
b = 20
a = a*2
b = a/2

Is this too simplified??


It's not too simplified (it does take two variables and swap them) but it doesn't do it in a general way, it will only work for certain numbers (i.e., where b = 2a).

Try and come up with a solution which can work for an arbitrary pair of numbers.


It is just too easy to do in Python. Don't make it too hard on yourself. Here is the easiest way to do it in Python.
Spoiler


#30 s0urd

s0urd

    Will I break 10 posts?

  • Members
  • 2 posts
  • Gender:Male

Posted 09 December 2012 - 06:14 AM

Old thread but...

a = 2
b = 3
print a, b
a, b = b, a
print a, b





BinRev is hosted by the great people at Lunarpages!