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

60%
+1 −0
Challenges Small integer swapping

Vyxal o, 5 bytes ~$"," Try it Online! I'd say this counts, because $ is quite literally "swap the top two items on the stack". Explained ~$"," ~$ # Swap the top two items, but peek inste...

posted 2y ago by lyxal‭

Answer
#1: Initial revision by user avatar lyxal‭ · 2021-08-15T13:19:36Z (over 2 years ago)
# [Vyxal](https://github.com/Vyxal/Vyxal) `o`, 5 bytes

```
~$","
```

[Try it Online!](https://lyxal.pythonanywhere.com?flags=o&code=~%24%22%2C%22&inputs=3%0A4&header=&footer=)

I'd say this counts, because `$` is quite literally "swap the top two items on the stack".

## Explained

```
~$","
~$    # Swap the top two items, but peek instead of pop
  ",  # pair and output
    " # pair what remains and output with the `o` flag
```

But if variables are absolutely needed:

## [Vyxal](https://github.com/Vyxal/Vyxal) `o`, 29 bytes

```
→x→y",←y→temp←x→y←temp→x←y←x"
```

[Try it Online!](https://lyxal.pythonanywhere.com?flags=o&code=%E2%86%92x%E2%86%92y%22%2C%E2%86%90y%E2%86%92temp%E2%86%90x%E2%86%92y%E2%86%90temp%E2%86%92x%E2%86%90y%E2%86%90x%22&inputs=3%0A4&header=&footer=)

## Explained

```
→x→y",←y→temp←x→y←temp→x←y←x"
→x→y                          # put the two inputs into x and y
    ",                        # print [y, x]
      ←y→temp                 # temp = y
             ←x→y             # y = x
                 ←temp→x      # x = temp
                        ←y←x" # print [y, x] (now swapped)
```