Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 214545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:23:05+00:00 2026-05-11T18:23:05+00:00

The newspaper for the Computer Science-line at my school (called readme , it’s norwegian,

  • 0

The newspaper for the Computer Science-line at my school (called readme, it’s norwegian, page 19) had a fun competition to write the shortest possible Java-code for the following problem.

Take in an integer (as a string in the first entry of a string array, since the Java main method only takes a string array) as an argument, and write out first all numbers below this number that are primes, and then all numbers that are not primes. The shortest code wins!

As an answer, I will post the shortest Java-code that won the competition. I wonder if the Stack Overflow Community can make a code that is shorter If you know Norwegian, you will see that you could’ve won a bottle of champagne if you had done it, but unfortunately the last submit date of the competition is over.

How would you have solved this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:23:05+00:00Added an answer on May 11, 2026 at 6:23 pm

    I was already doing it in Haskell before you changed the title to “Java”. Since this is a community wiki, here it is anyway.

    primes n = 
    let sieve (p:xs) = p : sieve [x | x<-xs, x `mod` p /= 0] in 
    let primes = takeWhile (<n) $ sieve [2..] in 
    ([0..n] \\ primes, primes)
    
    *Main> primes 20
    ([0,1,4,6,8,9,10,12,14,15,16,18,20],[2,3,5,7,11,13,17,19])
    

    (edit:) Shortening names and removing whitespace makes it 79 chars:

    p n=let s(p:xs)=p:s[x|x<-xs,x`mod`p/=0];r=takeWhile(<n)$s[2..]in(r,[0..n-1]\\r)
    

    here also the resulting pair’s order is swapped, and n-1 is used, as per the spec.

    Using sub-optimal trial division brings it down to 50 chars:

    p n=partition(\k->all((>0).rem k)[2..k-1])[2..n-1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have OCRed thousands of pages of newspaper articles. The newspaper, issue, date, page
Let say I have complete Image of Newspaper front page i want it make
I need to create a Today's Daily News page for an internal company 'newspaper'.
I have a page in Wordpress that displays posts with a category of newspaper
I'm working on a simple search engine for a newspaper application. When the user
We are currently working on an pdf version of a newspaper at work, we
Advert table, Newspaper column takes integer value. Newspaper 1 2 3 Newspaper table like
I need to create some xaml that shows text in columns like newspaper, something
I have three entities. Author Newspaper Dissertation Newspaper and Dissertation both can have one
I'm not sure how else to describe this, outside of calling it a newspaper

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.