Menu
Coddy logo textTech

Final Code

Part of the Logic & Flow section of Coddy's Rust journey — lesson 19 of 66.

challenge icon

Challenge

Easy

You will receive four inputs representing a complete to-do list workflow: first, a comma-separated list of initial tasks; second, a new task to add; third, a task number to view (1-based indexing); and fourth, a task number to remove (1-based indexing). Create a complete to-do list manager that processes all these operations and displays the final state.

Requirements:

  • Read the first input containing comma-separated task descriptions (e.g., Buy groceries,Call dentist,Finish homework)
  • Split the string by commas and create a mutable vector with these initial tasks
  • Read the second input and add this new task to the vector using .push()
  • Read the third input, convert it to an integer (1-based task number to view)
  • Read the fourth input, convert it to an integer (1-based task number to remove)
  • Remove the specified task by converting the 1-based index to 0-based and using .remove()
  • Print Total tasks: X where X is the final number of tasks
  • Print Viewing task: Y where Y is the task number that was requested to view
  • Iterate through the final task list and print each task with its number (1-based)
  • For the task matching the view number (after removal adjustments), print: [X] [task description] (selected)
  • For all other tasks, print: [X] [task description]

Input:

  • First line: Comma-separated task descriptions (e.g., Buy groceries,Call dentist,Finish homework)
  • Second line: A new task to add (e.g., Study for exam)
  • Third line: An integer representing the task number to view (1-based indexing)
  • Fourth line: An integer representing the task number to remove (1-based indexing)

Output:

  • First line: Total tasks: X where X is the final number of tasks
  • Second line: Viewing task: Y where Y is the requested view number
  • Following lines: Each task with its number in the format [X] [task description]
  • The selected task (matching the view number) should have (selected) appended

Try it yourself

use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    
    // Read the initial comma-separated tasks
    let initial_tasks = lines.next().unwrap().unwrap();
    
    // Read the new task to add
    let new_task = lines.next().unwrap().unwrap();
    
    // Read the task number to view (1-based)
    let view_number: usize = lines.next().unwrap().unwrap().trim().parse().unwrap();
    
    // Read the task number to remove (1-based)
    let remove_number: usize = lines.next().unwrap().unwrap().trim().parse().unwrap();
    
    // TODO: Write your code below
    // 1. Split initial_tasks by commas and create a mutable vector
    // 2. Add the new_task to the vector
    // 3. Remove the task at remove_number (convert to 0-based index)
    // 4. Print the total tasks and viewing task information
    // 5. Iterate through the final list and print each task
    
}

All lessons in Logic & Flow