Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

33%
+1 −4
Challenges Small integer swapping

In this simple challenge, create a short program that takes 2 ints as input, output them, swap their places, then output them again. Those 2 integers can't be the same number. The program with the ...

7 answers  ·  posted 3y ago by General Sebast1an‭  ·  last activity 2y ago by south‭

Question code-golf number
#6: Post edited by user avatar General Sebast1an‭ · 2021-08-16T09:36:15Z (about 3 years ago)
  • In this simple challenge, create a short program that takes 2 `int`s as input, output them, swap their places, then output them again. Those 2 integers can't be the same number. The program with the shortest solution wins! Loopholes are banned in this challenge.
  • An example C program for the challenge (mostly ungolfed):
  • ```c
  • #include <stdio.h>
  • int main() {
  • int x, y;
  • scanf("%i %i", &x, &y);
  • printf("%i %i", x, y);
  • int z = x;
  • x = y;
  • y = z;
  • printf("%i %i", x, y);
  • }
  • ```
  • In this simple challenge, create a short program that takes 2 `int`s as input, output them, swap their places, then output them again. Those 2 integers can't be the same number. The program with the shortest solution wins! Loopholes are banned in this challenge.
  • An example C program for the challenge (mostly ungolfed):
  • ```c
  • #include <stdio.h>
  • int main() {
  • int x, y;
  • scanf("%i %i", &x, &y);
  • printf("%i %i", x, y);
  • int z = x;
  • x = y;
  • y = z;
  • printf("%i %i", x, y);
  • }
  • ```
  • You can make 2 answers in one post: 1 with output swapping, and 1 with variable swapping.
#5: Question reopened by user avatar Quintec‭ · 2021-08-16T05:27:49Z (about 3 years ago)
#4: Post edited by user avatar General Sebast1an‭ · 2021-08-16T05:02:06Z (about 3 years ago)
  • In this simple challenge, create a short program that takes 2 `int`s as input, output them, swap their places, then output them again. Those 2 integers can't be the same number. The program with the shortest solution wins!
  • However, you can't do something like:
  • ```
  • print(x,y)
  • print(y,x)
  • ```
  • I'd call that a loophole. Loopholes are banned in this challenge.
  • An example C program for the challenge (mostly ungolfed):
  • ```c
  • #include <stdio.h>
  • int main() {
  • int x, y;
  • scanf("%i %i", &x, &y);
  • printf("%i %i", x, y);
  • int z = x;
  • x = y;
  • y = z;
  • printf("%i %i", x, y);
  • }
  • ```
  • In this simple challenge, create a short program that takes 2 `int`s as input, output them, swap their places, then output them again. Those 2 integers can't be the same number. The program with the shortest solution wins! Loopholes are banned in this challenge.
  • An example C program for the challenge (mostly ungolfed):
  • ```c
  • #include <stdio.h>
  • int main() {
  • int x, y;
  • scanf("%i %i", &x, &y);
  • printf("%i %i", x, y);
  • int z = x;
  • x = y;
  • y = z;
  • printf("%i %i", x, y);
  • }
  • ```
#3: Question closed by user avatar Quintec‭ · 2021-08-16T00:14:02Z (about 3 years ago)
#2: Post edited by user avatar General Sebast1an‭ · 2021-08-15T12:54:28Z (about 3 years ago)
  • In this simple challenge, create a short program that takes 2 `int`s as input, output them, swap their places, then output them again. The program with the shortest solution wins!
  • However, you can't do something like:
  • ```
  • print(x,y)
  • print(y,x)
  • ```
  • I'd call that a loophole. Loopholes are banned in this challenge.
  • An example C program for the challenge (mostly ungolfed):
  • ```c
  • #include <stdio.h>
  • int main() {
  • int x, y;
  • scanf("%i %i", &x, &y);
  • printf("%i %i", x, y);
  • int z = x;
  • x = y;
  • y = z;
  • printf("%i %i", x, y);
  • }
  • ```
  • In this simple challenge, create a short program that takes 2 `int`s as input, output them, swap their places, then output them again. Those 2 integers can't be the same number. The program with the shortest solution wins!
  • However, you can't do something like:
  • ```
  • print(x,y)
  • print(y,x)
  • ```
  • I'd call that a loophole. Loopholes are banned in this challenge.
  • An example C program for the challenge (mostly ungolfed):
  • ```c
  • #include <stdio.h>
  • int main() {
  • int x, y;
  • scanf("%i %i", &x, &y);
  • printf("%i %i", x, y);
  • int z = x;
  • x = y;
  • y = z;
  • printf("%i %i", x, y);
  • }
  • ```
#1: Initial revision by user avatar General Sebast1an‭ · 2021-08-15T12:53:47Z (about 3 years ago)
Small integer swapping
In this simple challenge, create a short program that takes 2 `int`s as input, output them, swap their places, then output them again. The program with the shortest solution wins!

However, you can't do something like:
```
print(x,y)
print(y,x)
```

I'd call that a loophole. Loopholes are banned in this challenge.

An example C program for the challenge (mostly ungolfed):

```c
#include <stdio.h>

int main() {
	int x, y;
	scanf("%i %i", &x, &y);
	printf("%i %i", x, y);
	int z = x;
	x = y;
	y = z;
	printf("%i %i", x, y);
}
```