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 448941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:43:12+00:00 2026-05-12T21:43:12+00:00

I have started to do the questions on Project Euler regarding lists of names

  • 0

I have started to do the questions on Project Euler regarding lists of names which need to be replaced with their corresponding position in the alphabet. In Problem 22 I need to replace, the letters with numbers:

names = ["MARY","PATRICIA","LINDA"....
replace = ??????
char2num a = map replace a
score (a,b) = a * (sum $ map char2num b)
answer = sum $ map score (zip [1..] (sort names))

What I cannot find is how to replace the characters with their place in the alphabet. How would I go about making something to do the replace function (preferably not regex)?

  • 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-12T21:43:12+00:00Added an answer on May 12, 2026 at 9:43 pm

    The ord function in the Data.Char module gives an integer code for each character. Given that, this would be the function you’re looking for:

    import Data.Char
    
    replace :: Char -> Int
    replace c = ord c - ord 'A' + 1
    

    I’m not sure if ord c will return the ASCII code for a character, or the unicode codepoint, or if the result is machine dependent. To abstract from that, we simply subtract the code for 'A' from the result, and add 1 because we want the alphabet to start at 1 instead of 0.

    An easy way to find to find such a function is Hoogle.
    There you can search for functions in the standard Haskell packages by entering its type. In this case ord is the second result when searching for Char -> Int.

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

Sidebar

Related Questions

I've started some problems on Project Euler . One of the questions: The prime
I've started using Project Euler to improve my objective-c coding and have worked through
I've started using Enterprise Library and have the following questions: 1)How do I add
OK, I know there have already been questions about getting started with TDD ..
I have started using Linq to SQL in a (bit DDD like) system which
I have recently started a new C++ project and I intend to make it
I have a project that I have recently started working on seriously but had
I'm fairly new to MVVM, and I have recently started a project cleaning up
I'm just getting started with Visual Studio (2010 Beta) and have some basic questions
I'm new to EF, and I've just started a new project. I currently have

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.