one-liner solutions

Announcements, comments, ideas, feedback, and "How do I... ?" questions
Post Reply
sbluen
Posts: 2
Joined: Thu Dec 23, 2010 9:43 am

one-liner solutions

Post by sbluen »

I'd like to know how many problems we have that have solutions of a length of only one line, especially problems that can be solved with an elegant list comprehension. This is so that I can more easily introduce functional programming to others. So far, I found 3 such problems: 1, 16, and 48.

I am not asking for solutions, but only for the listing of problems that are simple enough to do this with.

User avatar
rayfil
Administrator
Posts: 1403
Joined: Sun Mar 26, 2006 4:30 am
Location: Quebec, Canada
Contact:

Re: one-liner solutions

Post by rayfil »

This obviously depend on which programming language you are targeting. You won't find too many with C/C++ and its derivatives. You could probably find over 100 with APL/J/K.
When you assume something, you risk being wrong half the time.

sbluen
Posts: 2
Joined: Thu Dec 23, 2010 9:43 am

Re: one-liner solutions

Post by sbluen »

I'm targeting scripting languages with syntax similar to the English language, particularly Python. Those languages have some of the capabilities of the languages you mentioned.

User avatar
stijn263
Posts: 1505
Joined: Sat Sep 15, 2007 10:57 pm
Location: Netherlands

Re: one-liner solutions

Post by stijn263 »

Problems between 70 and 190 that allow one-liners in Maple: (this list is by no means complete)
Problem 71 (View Problem)
Problem 72 (View Problem)
Problem 73 (View Problem)
Problem 97 (View Problem)
Problem 131 (View Problem)
Problem 137 (View Problem)
Problem 138 (View Problem)
Problem 145 (View Problem)
Problem 158 (View Problem)
Problem 162 (View Problem)
Problem 163 (View Problem)
Problem 172 (View Problem)
Problem 173 (View Problem)
Problem 175 (View Problem)
Problem 179 (View Problem)
Problem 183 (View Problem)
Problem 190 (View Problem)

For a few of these problems, you can simply copy the problem statement into maple (like 97), but usually it's not so simple (175 being the hardest imo). Have fun :)

wingi
Posts: 1
Joined: Sat May 28, 2011 5:44 pm

Re: one-liner solutions

Post by wingi »

I have done some solutions with python, each in one line. Here the solutions for problem 1, 6, 8, 9, 13, 16, 19, 20, 25 and 29 described.

Edit by hk: spoilers removed.

User avatar
Lord_Farin
Posts: 239
Joined: Wed Jul 01, 2009 9:43 am
Location: Netherlands

Re: one-liner solutions

Post by Lord_Farin »

wingi wrote:I have done some solutions with python, each in one line. Here are the solutions for problem 1, 6, 8, 9, 13, 16, 19, 20, 25 and 29 described.
Edit by hk: spoilers removed.
I am afraid that as this is an open forum, there is a policy that no spoilers on how to solve problems are allowed to be posted. So, could you please edit out the links?
Image

jethrogb
Posts: 2
Joined: Sat May 28, 2011 1:38 am

Re: one-liner solutions

Post by jethrogb »

Using Ruby, I have problems 1, 6, 16, 20, 29 and 30 in one line so far.

Cees.Duivenvoorde
Posts: 1
Joined: Sat Jan 04, 2020 8:35 pm

Re: one-liner solutions

Post by Cees.Duivenvoorde »

I’ve solved problem 89 in a one-liner, in Python with list comprehension.

This includes reading the input file, processing all lines and discerning the different cases in which a gain can be made as well as counting the total gain.

(Only) for those of you who have also already solved 89: you can view my solution in the thread: https://projecteuler.net/thread=89;page=6#316624

Post Reply