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

  • SEARCH
  • Home
  • 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 8247485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:51:47+00:00 2026-06-07T22:51:47+00:00

Using names.txt (right click and ‘Save Link/Target As…’), a 46K text file containing over

  • 0

Using names.txt (right click and ‘Save Link/Target As…’), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.

For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 53 = 49714.

What is the total of all the name scores in the file?

I am getting 863833348 but the correct answer is 871198282. I am not sure what is wrong, I have tried all things but could not figure out the problem.

Code:

public static void main(String args[]) throws IOException {

    String alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    Pattern testRegEx=Pattern.compile("[^\\\"]\\w+[^\\\",]");

    String line;
    String filePath="//Users//painkillerfff//Documents//names.txt";
    BufferedReader readTextFile=new BufferedReader(new FileReader(filePath));

    List<String> nameList=new ArrayList<String>();
    while((line=readTextFile.readLine())!=null){
        //System.out.println(line);
        Matcher matcher=testRegEx.matcher(line);
        while(matcher.find()){
            nameList.add(matcher.group());
            //System.out.println(matcher.group());
        }
    }
    Collections.sort(nameList);

    long sumOfWords=0;
    long namePoint=0;
    long nameRank=1;
    for(String name: nameList){
        namePoint=0;
        for(int i=0;i<name.length();i++){
            namePoint+=alphabet.indexOf(name.charAt(i))+1;
        }
        namePoint=namePoint*nameRank;
        sumOfWords+=namePoint;
        nameRank++;
    }
    System.out.println("The Total Points is: "+sumOfWords);
}
  • 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-06-07T22:51:49+00:00Added an answer on June 7, 2026 at 10:51 pm

    Your regexp is flawed somehow. A count of commas shows there are 5163 names, yet you post there are 5130.

    Help me understand the regexp and we’ll probably figure it out.

    This is my version – no regexp needed.

        while ((line = readTextFile.readLine()) != null) {
            sb.append(line);
        }
        line = sb.toString();
        line = line.replace("\"", "");
        String[] a = line.split(",");
        System.out.println(a.length);
    

    Of course you should use real variable names, not a 😉

    EDIT – I changed your regexp to

        Pattern testRegEx = Pattern.compile("\\w+");
    

    and it returned 5163 names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing Project Euler #22: Using names.txt (right click and 'Save Link/Target As...'), a
I'm trying to save a file to a Sharepoint server using JAX-WS. The web
To create my dotplot I am using the following text file: ## filename difference
Right now, I am using something like copy catfile($PATH1, instructions.txt), catfile($ENV{'DIRWORK'}); individually for each
The perfmon counter is using different NIC names compare to ipconfig/all and c# system
What is the correct way to use pygame.Color names when using unicode_literals ? Python
If one Servlet is mapped twice, using two different names (as shown bellow) how
Using JavaScript I am pulling names out of webpage and stringing them together somehow
i'm using rails3.0.10 def districts @names = Node.where(name like ?, %#{params[:term]}%).limit(5).map(&:name) respond_to do |format|
Using Oracle, how can I find index names and creation dates from systables/information_schema? How

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.