News:

The moderation team is holding a poll on the topic of the site's connection to Scratch. More details can be found here. Your feedback is appreciated.

Main Menu

The Code Golf Game

Started by Europe2048, Jun 02, 2024, 02:00:10 AM

Previous topic - Next topic

Europe2048

Post a solution to the LeetCode problem with the number one more than the previous (unless rule 7 says otherwise), in a language x chosen by the user.
Rules:
  • No double-posting!
  • The x of a post may not be the same as the x of the last post.
  • The next solution's length (in characters) must be shorter than that of the previous.
  • The x may not be an esolang made by you, or an esolang made to solve the problem in the fewest characters. If the language supports custom libraries, don't make a library to solve the problem in the fewest characters. In other words, no cheating.
  • Please state the programming language you used and the number of the problem solved in the message.
  • The code must be written in a function called sol, whenever possible.
  • If a problem is only for premium and you don't have it, don't waste your money. Skip that problem.
  • If you think it's impossible to advance, restart from Problem 1 (Two Sum).
  • If you think it's impossible to advance with the O(___) restriction given, ignore that restriction.
I'll start.

Python (1)
def sol(nums):
        a = []
        for i in range(0, len(nums)):
            for j in range(0, len(nums)):
                if i == j:
                    pass
                elif nums[i] + nums[j] == target:
                    a.append(i)
                    a.append(j)
        return list(set(a))

PkmnQ

#2
Haskell, 179 chars (2)
s 0 [] ys = ys
s 0 xs [] = xs
s c [] ys = s 0 [c] ys
s c xs [] = s 0 xs [c]
s c (x:xs) (y:ys) = let z = x + y + c in if z < 10 then z : s 0 xs ys else z - 10 : s 1 xs ys
sol = s 0
Try it online!

Could've made it shorter, but it's already short enough anyway
I chose Haskell because I couldn't bother finding another linked list implementation
Also, is J allowed? It's not an esolang and I don't think it was made to be as short as possible, but it's also ridiculously good at being short due to its syntax
And what about double posting? I probably won't do it that much but I will for bumping

For convenience: https://leetcode.com/problemset/
Quickly, I must save the Q's!
Project EAPIDTOTT2TTNO's current target: 4n topic
A cool kid quietly measures the distance in the banquet (5). :/ B)
On a journey to a new domain full of enrichment, With auras and curses for your entertainment, The concept of collectibles spent to unblock your path, Is stretched far to create an interesting aftermath. The ideas start simple at their most plain, Followed by golden power breaking constraints, Along with barriers to check you've cleared things out, Although double vision puts their power in doubt. Why raise up when you can instead replace, And why take just some when you can completely erase? Replacing with nothing may sound like obliteration, But there's a good reason for its differentiation. Special colors that melt, fortify, and wash, And blockages not even gold can squash, A loft rumored to be haunted by a certain curse, And a metal whose purity demonstrates its worth. You've just reached amounts less than none, One thing is clear: It has only just begun.
Tip: Use c͢ombining cha͊racters, because ye᷂s.
Quine list

Threads that I think should be played more: link chain Pre-posted Destruction
Scripts: The sky is the limit

Gilbert189

#3
You want brief? I can brief.
APL (Dyalog Extended), 70 bytes (3)

sol←{≢⊃(⌽/∘i)(∪≡⊢)¨(i←{⍵⊂⍛⌷s}¨{↑,/⍵{(⍺-⍵-1)({¯1+⍳⍺}+⊢⍤/)⊂⍳⍵}¨⍳⍵}≢s←⍵)}
Try it online!

If I was smarter on the trains, I could probably shave 3 or 4 bytes or something.

Edit since misconceptions are imminent: FYI, both the APLers and most of the esolangers never considered APL an esolang, and I'm not sure if "writing concise code" was what APL was made for or just a side effect of being so rich in features

Europe2048

#4
To PkmnQ: Yes, J is allowed. J is not that kind of esolang where you type a number to solve problem number n.

(This reply has no effect on gameplay)

PkmnQ

[ngv]This is definitely possible (ignoring the O(_) restriction), but I think I chose possibly the most painful option that it's possible to do with[/ngv]
Quickly, I must save the Q's!
Project EAPIDTOTT2TTNO's current target: 4n topic
A cool kid quietly measures the distance in the banquet (5). :/ B)
On a journey to a new domain full of enrichment, With auras and curses for your entertainment, The concept of collectibles spent to unblock your path, Is stretched far to create an interesting aftermath. The ideas start simple at their most plain, Followed by golden power breaking constraints, Along with barriers to check you've cleared things out, Although double vision puts their power in doubt. Why raise up when you can instead replace, And why take just some when you can completely erase? Replacing with nothing may sound like obliteration, But there's a good reason for its differentiation. Special colors that melt, fortify, and wash, And blockages not even gold can squash, A loft rumored to be haunted by a certain curse, And a metal whose purity demonstrates its worth. You've just reached amounts less than none, One thing is clear: It has only just begun.
Tip: Use c͢ombining cha͊racters, because ye᷂s.
Quine list

Threads that I think should be played more: link chain Pre-posted Destruction
Scripts: The sky is the limit