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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:20:50+00:00 2026-06-13T01:20:50+00:00

I’m trying to solve the square anagram word pair problem of project Euler (

  • 0

I’m trying to solve the “square anagram word pair” problem of project Euler (here) in Haskell, but I’m stucked…

The problem is the following (I shortened it):

  • take one word, say “CARE” and one of its anagram, for example “RACE”.
  • replace each letter of “CARE” by a unique digit, for example C = 1, A = 2, R = 9 and E = 6. It happens to be 1296 and is a square number.
  • replace the anagram’s letters (“RACE”) following the same substitution policy, it generates 9216 which also is a square number !

Given a list of words, what’s the largest square number formed by any
member of such a pair?

I managed to extract all the anagrams pairs from the file and I have them in a [(String,String)] form i.e [(“CARE”,”RACE”)..].

In the next step (map anasquare), and for each pair of words, I want to link the biggest square number that can be generated so it’d look like[(9216,”CARE”,”RACE”)..].

Well, there is a trick (there must be !) to avoid the brute force approach but so far I didn’t find it… Actually the problem isn’t here, let’s say I want to take the brute force approach and check every letter -> digit transformations. I just don’t know how to do it in Haskell. Maybe I’m tired but I’m just dumbstruck in front of this. There must be a short an elegant yet not too obscure way to write it, someone has an idea ?

Here’s what I do, I spare you the anagram searching and the file parsing functions:

-- Read the file -> store the content into a list -> work on that list -> print the output
result98 = do contents <- readFile ".\\resources\\98.txt"
              putStrLn $ (process.words.format) contents

-- Find anagram pairs -> Find corresponding square number -> get the biggest one
process::[String]->String
process = toString . maximum . map anasquare . anagrams
    where toString (a,b,c) = "Yay ! the result is " ++ show a

-- Generate the maximum square number possible, 0 when none exist
anasquare::(String,String)->(Integer,String,String)
anasquare (x,y) = (anasquareValue,x,y)
    where anasquareValue = 0 -- TODO
  • 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-13T01:20:51+00:00Added an answer on June 13, 2026 at 1:20 am

    Though the mathematical insight is useful (especially on project euler), it didn’t help me much on that one since I was missing some knowledge on the ‘how to’ part.

    Without going too much into the details, one solution path would consist in transforming an anagram word ("CARE","RACE") into a pair such as (1234,4213). Straightforward stuff. If a similar pattern is detected in the square number pairs, then there’s a match.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need to clean up various Word 'smart' characters in user input, including but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

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.