simple_rosetta

Cookbook

Find Easy Tasks to Submit

Get started with Tier 1 (trivial) solutions:

local
    l_rosetta: SIMPLE_ROSETTA
    l_solutions: ARRAYED_LIST [TUPLE [task: STRING; class_name: STRING; file: STRING]]
do
    create l_rosetta.make
    l_solutions := l_rosetta.solutions_by_tier (1)

    print ("Trivial tasks ready for submission:%N")
    across l_solutions as l_sol loop
        print ("  - " + l_sol.task + "%N")
    end
end

Generate Wiki Submission

Create copy-paste-ready wiki markup:

local
    l_rosetta: SIMPLE_ROSETTA
do
    create l_rosetta.make

    if attached l_rosetta.solution_as_wiki ("Hello_world/Text") as l_wiki then
        print (l_wiki)
        -- Copy this output directly to Rosetta Code wiki
    else
        print ("Solution not found%N")
    end
end

Find Algorithm Implementations

Search for specific algorithm types:

local
    l_rosetta: SIMPLE_ROSETTA
    l_results: ARRAYED_LIST [TUPLE [task: STRING; tier: INTEGER; class_name: STRING]]
do
    create l_rosetta.make

    -- Find all sorting algorithms
    l_results := l_rosetta.search_solutions ("sort")

    print ("Sorting algorithms:%N")
    across l_results as l_r loop
        print ("  " + l_r.task + " (Tier " + l_r.tier.out + ")%N")
    end
end

Add a New Solution

Create a new solution file following the standard format:

note
    description: "[
        Rosetta Code: Your Task Name
        https://rosettacode.org/wiki/Your_Task_Name

        Description of what this task does.
    ]"
    author: "Your Name"
    see_also: "https://github.com/simple-eiffel"
    rosetta_task: "Your_Task_Name"
    tier: "2"

class
    YOUR_TASK_NAME

create
    make

feature {NONE} -- Initialization

    make
            -- Demonstrate the solution.
        do
            print ("Your solution output%N")
        end

end

Save to the appropriate tier folder:

Import Solutions to Database

After adding new solution files, import them:

local
    l_store: SOLUTION_STORE
    l_validator: SOLUTIONS_VALIDATOR
do
    create l_store.make ("rosetta.db")
    create l_validator.make (l_store)

    l_validator.import_solutions ("solutions/")

    print ("Imported: " + l_validator.imported_count.out + "%N")
    print ("Errors: " + l_validator.error_count.out + "%N")

    l_store.close
end

Get Database Statistics

View solution counts by tier:

local
    l_rosetta: SIMPLE_ROSETTA
    l_summary: ARRAYED_LIST [TUPLE [tier: INTEGER; count: INTEGER]]
do
    create l_rosetta.make

    print ("Total solutions: " + l_rosetta.solution_count.out + "%N%N")

    l_summary := l_rosetta.tier_summary
    across l_summary as l_s loop
        print ("Tier " + l_s.tier.out + ": " + l_s.count.out + " solutions%N")
    end
end

CLI Quick Reference

# Search for solutions
rosetta search fibonacci
rosetta search "binary search"

# List by tier
rosetta list 1    # Trivial
rosetta list 2    # Easy
rosetta list 3    # Moderate
rosetta list 4    # Complex

# Generate wiki format
rosetta wiki Fibonacci_sequence
rosetta wiki "Hello_world/Text"

# Statistics
rosetta stats

# Validate all solutions compile
rosetta validate