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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:12:31+00:00 2026-05-31T00:12:31+00:00

I’m trying to write a program that converts from Mayan to Arabic numerals and

  • 0

I’m trying to write a program that converts from Mayan to Arabic numerals and vice versa in prolog. Although I’m still running into some trouble I’ve managed to get it mostly working. I’m just wondering how if I read for example:

....| 0 .| |||

from a user input, how can I convert it to a list like this:

L = [ ['.','.','.','.','|'], [0], ['.','|'], ['|','|','|'] ]

I have an algorithm written getting from L to the arabic value, but I have no clue how to convert that string into a list.

  • 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-31T00:12:32+00:00Added an answer on May 31, 2026 at 12:12 am

    Take a look at this answer. The code I’ve written there splits a Prolog string on spaces to generate a list of atoms. With a small modification, you can alter the code to create strings instead of atoms. Here is the relevant code from the previous post, with the necessary modification for your case:

    data([A|As]) --> 
        spaces(_), 
        chars([X|Xs]), 
        {string_to_list(A, [X|Xs])},  %% Using string_to_list/2 instead
        spaces(_), 
        data(As).
    data([]) --> [].
    
    chars([X|Xs]) --> char(X), !, chars(Xs).
    chars([]) --> [].
    
    spaces([X|Xs]) --> space(X), !, spaces(Xs).
    spaces([]) --> [].
    
    space(X) --> [X], {code_type(X, space)}. 
    char(X) --> [X], {\+ code_type(X, space)}.
    

    In your example, you’d take a Prolog string containing your example like "....| 0 .| |||" and run the above code using the built-in phrase/2, like so:

    ?- phrase(data(NumeralList), "....| 0 .| |||").
    NumeralList = ["....|", "0", ".|", "|||"]
    

    Note that I’ve tested this on SWI-Prolog and it works, but if you’re using a different Prolog implementation, it mightn’t support DCGs or the built-ins I’ve used.

    If you were after a result which is precisely like what you’ve described as L above, you can modify the code further to return the list [X|Xs] directly in the data clause (removing the sub-goal {string_to_list(A, [X|Xs])},), and change the last predicate char to the following:

    char(C) --> [X], {\+ code_type(X, space), atom_codes(C,[X])}.
    

    Running this gives:

    ?- phrase(data(L), "....| 0 .| |||").
    L = [['.', '.', '.', '.', '|'], ['0'], ['.', '|'], ['|', '|', '|']]
    

    EDIT: As requested, here is the modified code which generates the above result in full:

    data([[X|Xs]|As]) --> 
        spaces(_), 
        chars([X|Xs]), 
        spaces(_), 
        data(As).
    data([]) --> [].
    
    chars([X|Xs]) --> char(X), !, chars(Xs).
    chars([]) --> [].
    
    spaces([X|Xs]) --> space(X), !, spaces(Xs).
    spaces([]) --> [].
    
    space(X) --> [X], {code_type(X, space)}. 
    char(C) --> [X], {\+ code_type(X, space), atom_codes(C,[X])}.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
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
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.