diff --git a/config.json b/config.json index 3175db29..6eae6a4a 100644 --- a/config.json +++ b/config.json @@ -1021,6 +1021,19 @@ "practices": [], "prerequisites": [], "difficulty": 5 + }, + { + "slug": "space-pirates", + "name": "space-pirates", + "uuid": "c9e78be6-8e53-4507-a143-ae927069d901", + "practices": [], + "prerequisites": [], + "difficulty": 5, + "topics": [ + "processes", + "references", + "concurrency" + ] } ], "foregone": [ diff --git a/exercises/practice/space-pirates/.docs/hints.md b/exercises/practice/space-pirates/.docs/hints.md new file mode 100644 index 00000000..9bc6211b --- /dev/null +++ b/exercises/practice/space-pirates/.docs/hints.md @@ -0,0 +1,92 @@ +## General + +The Basics of Process Communication + +In Erlang, every communication between processes happens through message passing. + +Think of your ships not as objects with methods, but as independent beings that can only talk to each other by sending messages. + +When a ship goes down, it doesn't call a function - it simply stops receiving messages. + +How would other ships know it's gone? You'll need to establish connections between your processes that can detect when one disappears. + +Remember: in space, no one can hear you scream - unless you've set up the right message handling! + +___ + +Monitoring Your Fleet + +To build a robust fleet communication system, you'll need to use these key Erlang concepts: + +`link/1`` - Creates a bidirectional connection between processes +`process_flag(trap_exit, true)`` - Makes a process receive notifications when linked processes die +`spawn_link/1` - Creates a new process that's automatically linked to its parent + +When setting up your command ship, make sure it can "trap exits" so it receives notifications when ships are destroyed. + +Your message pattern matching should look for `{'EXIT', Pid, Reason}` messages that indicate a ship has gone down. + +For secure communications, remember that `make_ref/0` creates a unique reference that can't be guessed - perfect for authenticating messages between ships! + +___ + +Implementation Blueprint + +Here's a detailed structure for your solution: + +```erlang + +%% Command ship state management +-record(command_state, { + ships = #{}, % Map of ship name to Pid + trap_exit = false, % Is the ship currently trapping exits? + distress_log = [], % List of received distress signals + auth_refs = sets:new() % Set of valid authentication references +}). + +%% Pirate ship state management +-record(ship_state, { + name, + messages = #{}, % Map of Ref to message content + auth_refs = sets:new() % Set of valid authentication refs +}). + +%% Handle the 'EXIT' signal in your command ship loop +command_loop(State) -> + receive + {'EXIT', Pid, {ship_destroyed, Reason}} -> + %% 1. Find the ship's name from its Pid + ShipName = maps:fold(fun(Name, P, Acc) -> + if P =:= Pid -> Name; true -> Acc end + end, undefined, State#command_state.ships), + + %% 2. Remove the ship from the registry + NewShips = maps:remove(ShipName, State#command_state.ships), + + %% 3. Log the distress + NewLog = [{ShipName, Reason, erlang:timestamp()} | State#command_state.distress_log], + + %% 4. Spawn replacement if auto-replace is enabled + FinalShips = case State#command_state.auto_replace of + true -> + NewShip = spawn_link(fun() -> ship_loop(#ship_state{name=ShipName}) end), + maps:put(ShipName, NewShip, NewShips); + false -> + NewShips + end, + + command_loop(State#command_state{ships=FinalShips, distress_log=NewLog}); + + %% Handle other messages... + end. + +``` + +For secure message authentication: + +Create references with `make_ref()` +Register them with both sender and receiver +Verify that incoming messages contain a registered reference +Remember that pirates can't be trusted - always verify before accepting a message! + +The command ship should maintain the fleet registry and be the central point for monitoring ship status. diff --git a/exercises/practice/space-pirates/.docs/instructions.md b/exercises/practice/space-pirates/.docs/instructions.md new file mode 100644 index 00000000..66fecf92 --- /dev/null +++ b/exercises/practice/space-pirates/.docs/instructions.md @@ -0,0 +1,42 @@ +# Instructions + +Your task is to implement a reliable communication system for Captain Nova's pirate fleet using Erlang's process model. + +The system needs to handle ship-to-ship communication, distress signals, authentication, and automatic ship replacement when one is destroyed. + +Core Requirements + +- Command Ship - Implement a central command ship process that acts as a supervisor for the fleet +- Pirate Ships - Create ship processes that can send and receive authenticated messages +- Distress Beacon - Enable command ships to trap exit signals when pirate ships are destroyed +- Message Authentication - Use Erlang references to create secure communications between ships +- Ship Registry - Maintain a registry of active ships in the fleet +- Auto-Replacement - When a ship is destroyed, automatically spawn a replacement + +Concepts You'll Be Using + +- Process Creation: Using spawn/1 and spawn_link/1 to create processes +- Message Passing: Sending messages between processes using the `!` operator +- Process Linking: Using link/1 to connect processes +- Exit Signal Handling: Using process_flag(trap_exit, true) to catch process termination +- References: Using make_ref/0 to create unique identifiers for messages +- Process Registration: Maintaining a registry of processes + +## Your Task + +Implement the functions in the `space_pirates.erl` module to create a robust, fault-tolerant messaging system that can: + +- Start a command ship that can monitor other ships +- Spawn pirate ships that can communicate with each other +- Enable the distress beacon to trap exit signals +- Create unique references for mission authentication +- Send authenticated messages between ships +- Handle ship destruction and automatic replacement + +Remember, in deep space, there's no room for failure. + +Ships get destroyed, communications get intercepted, and the Empire is always watching. + +Your system needs to be reliable, secure, and resilient. + +Good luck, Communication Officer. The fleet's success depends on you. diff --git a/exercises/practice/space-pirates/.docs/introduction.md b/exercises/practice/space-pirates/.docs/introduction.md new file mode 100644 index 00000000..51641d3a --- /dev/null +++ b/exercises/practice/space-pirates/.docs/introduction.md @@ -0,0 +1,10 @@ +# Introduction + +In the 30th century, interstellar travel has become commonplace, and with it, the age-old profession of piracy has expanded to the stars. Captains with fast ships and loyal crews plunder trade routes across the galaxy, always staying one step ahead of the Imperial Fleet. + +You've recently joined the crew of the notorious Captain Nova, whose fleet of pirate ships is known throughout the Perseus Arm. As the new communications officer, you've been tasked with implementing their distributed messaging system. The previous officer was spaced after a critical failure that left three ships stranded during a raid on an Imperial convoy. + +"Listen carefully," Captain Nova tells you on your first day. "Our ships operate across vast distances. A fleet is only as strong as its communication network. When a ship goes down—and they do go down—I need to know immediately. If a ship sends a distress signal, it needs to reach command with proper authentication. No Imperial interference, no message spoofing. And most importantly, when we lose a ship, I need an immediate replacement dispatched. Understood?" + +You gulp nervously. "I'll need to use **Erlang**'s concurrency model—processes, links, monitors, and references." +Captain Nova grins. "*Precisely*. Now get to work before I find another communications officer." diff --git a/exercises/practice/space-pirates/.meta/config.json b/exercises/practice/space-pirates/.meta/config.json new file mode 100644 index 00000000..2bfafaca --- /dev/null +++ b/exercises/practice/space-pirates/.meta/config.json @@ -0,0 +1,17 @@ +{ + "authors": [ + "Maartz" + ], + "files": { + "solution": [ + "src/space_pirates.erl" + ], + "test": [ + "test/space_pirates_tests.erl" + ], + "example": [ + ".meta/example.erl" + ] + }, + "blurb": "Learn Erlang's process model by building a communication system for a fleet of space pirates." +} diff --git a/exercises/practice/space-pirates/.meta/example.erl b/exercises/practice/space-pirates/.meta/example.erl new file mode 100644 index 00000000..6a0cc1b6 --- /dev/null +++ b/exercises/practice/space-pirates/.meta/example.erl @@ -0,0 +1,289 @@ +-module(example). + +-export([start_command_ship/0, spawn_pirate_ship/2, ship_exists/2, create_mission_ref/0, + send_message/3, message_received/2, get_last_message/2, enable_distress_beacon/1, + link_ships/2, destroy_ship/2, get_last_distress_signal/1, enable_auto_replacement/2, + count_ships_by_name/2, get_ship_by_name/2, send_distress_signal/4, + get_distress_signal_by_ref/2, create_auth_ref/2, send_authenticated_message/4, + authenticate_message/2]). + +%% Internal ship state record +-record(ship_state, + {name, + messages = [], + received_refs = [], + auth_refs = [], + trap_exit = false, + distress_signals = [], + ships_registry = [], + auto_replace = false, + last_distress = undefined}). + +%% Start a command ship process that can act as a supervisor +start_command_ship() -> + spawn_link(fun() -> command_ship_loop(#ship_state{name = "Command"}) end). + +%% Spawn a new pirate ship process with the given name +spawn_pirate_ship(CommandShip, Name) -> + PirateShip = spawn(fun() -> pirate_ship_loop(#ship_state{name = Name}) end), + CommandShip ! {register_ship, Name, PirateShip}, + PirateShip. + +%% Check if a ship with the given name exists in the command ship's registry +ship_exists(CommandShip, Name) -> + CommandShip ! {ship_exists, Name, self()}, + receive + {ship_exists_response, Result} -> + Result + after 1000 -> + false + end. + +%% Create a unique mission reference +create_mission_ref() -> + make_ref(). + +%% Send a message from one ship to another +send_message(FromShip, ToShip, Message) -> + ToShip ! {message, FromShip, Message}, + ok. + +%% Check if a message with the given reference was received +message_received(Ship, Ref) -> + Ship ! {check_received, Ref, self()}, + receive + {received_check, Result} -> + Result + after 1000 -> + false + end. + +%% Retrieve the last message with the given reference +get_last_message(Ship, Ref) -> + Ship ! {get_message, Ref, self()}, + receive + {message_response, Message} -> + Message + after 1000 -> + undefined + end. + +%% Enable the command ship to trap exit signals from linked ships +enable_distress_beacon(CommandShip) -> + CommandShip ! {enable_distress_beacon, self()}, + receive + {distress_beacon_enabled, true} -> + ok + after 1000 -> + {error, timeout} + end. + +%% Link two ship processes +link_ships(ShipA, ShipB) -> + ShipA ! {link_to, ShipB}, + ShipB ! {link_to, ShipA}, + timer:sleep(10), % Small delay to ensure linking + ok. + +%% Destroy a ship with a reason +destroy_ship(Ship, Reason) -> + exit(Ship, {ship_destroyed, Reason}), + ok. + +%% Get the last distress signal received by the command ship +get_last_distress_signal(CommandShip) -> + CommandShip ! {get_last_distress, self()}, + receive + {last_distress, Signal} -> + Signal + after 1000 -> + undefined + end. + +%% Enable or disable automatic replacement of destroyed ships +enable_auto_replacement(CommandShip, Enable) -> + CommandShip ! {auto_replace, Enable}, + ok. + +%% Count the number of ships with a specific name +count_ships_by_name(CommandShip, Name) -> + CommandShip ! {count_ships, Name, self()}, + receive + {ship_count, Count} -> + Count + after 1000 -> + 0 + end. + +%% Get the process ID of a ship by its name +get_ship_by_name(CommandShip, Name) -> + CommandShip ! {get_ship, Name, self()}, + receive + {ship_pid, Pid} -> + Pid + after 1000 -> + undefined + end. + +%% Send a distress signal with a reference from a ship to the command ship +send_distress_signal(Ship, CommandShip, Ref, Message) -> + CommandShip ! {distress_signal, Ship, Ref, Message}, + ok. + +%% Get a specific distress signal by its reference +get_distress_signal_by_ref(CommandShip, Ref) -> + CommandShip ! {get_distress_ref, Ref, self()}, + receive + {distress_ref_response, Signal} -> + Signal + after 1000 -> + undefined + end. + +%% Create an authentication reference for secure communication between ships +create_auth_ref(FromShip, ToShip) -> + Ref = make_ref(), + FromShip ! {register_auth_ref, Ref}, + ToShip ! {register_auth_ref, Ref}, + Ref. + +%% Send an authenticated message between ships +send_authenticated_message(FromShip, ToShip, AuthRef, Message) -> + ToShip ! {auth_message, FromShip, AuthRef, Message}, + ok. + +%% Verify if a message has a valid authentication reference +authenticate_message(Ship, AuthRef) -> + Ship ! {auth_check, AuthRef, self()}, + receive + {auth_result, Result} -> + Result + after 1000 -> + false + end. + +%% Main loop for the command ship process +command_ship_loop(State) -> + receive + {enable_distress_beacon, From} -> + process_flag(trap_exit, true), + From ! {distress_beacon_enabled, true}, + command_ship_loop(State#ship_state{trap_exit = true}); + {register_ship, Name, Pid} -> + NewRegistry = [{Name, Pid} | State#ship_state.ships_registry], + command_ship_loop(State#ship_state{ships_registry = NewRegistry}); + {ship_exists, Name, From} -> + Exists = lists:keymember(Name, 1, State#ship_state.ships_registry), + From ! {ship_exists_response, Exists}, + command_ship_loop(State); + {link_to, Ship} -> + link(Ship), + command_ship_loop(State); + {auto_replace, Enable} -> + command_ship_loop(State#ship_state{auto_replace = Enable}); + {get_last_distress, From} -> + From ! {last_distress, State#ship_state.last_distress}, + command_ship_loop(State); + {count_ships, Name, From} -> + Count = length([X || {N, _} = X <- State#ship_state.ships_registry, N =:= Name]), + From ! {ship_count, Count}, + command_ship_loop(State); + {get_ship, Name, From} -> + case lists:keyfind(Name, 1, State#ship_state.ships_registry) of + {Name, Pid} -> + From ! {ship_pid, Pid}; + false -> + From ! {ship_pid, undefined} + end, + command_ship_loop(State); + {distress_signal, Ship, Ref, Message} -> + case lists:keyfind(Ship, 2, State#ship_state.ships_registry) of + {Name, Ship} -> + DistressSignals = [{distress, Name, Message, Ref} | State#ship_state.distress_signals], + command_ship_loop(State#ship_state{distress_signals = DistressSignals, + last_distress = {distress, Name, Message, Ref}}); + false -> + command_ship_loop(State) + end; + {get_distress_ref, Ref, From} -> + Signal = lists:keyfind(Ref, 4, State#ship_state.distress_signals), + From ! {distress_ref_response, Signal}, + command_ship_loop(State); + {'EXIT', Pid, {ship_destroyed, Reason}} -> + case lists:keyfind(Pid, 2, State#ship_state.ships_registry) of + {Name, Pid} -> + NewState = + State#ship_state{last_distress = {ship_lost, Name, Reason}, + ships_registry = + lists:keydelete(Pid, 2, State#ship_state.ships_registry)}, + + % Auto-replace if enabled + FinalState = + case NewState#ship_state.auto_replace of + true -> + NewShip = spawn(fun() -> pirate_ship_loop(#ship_state{name = Name}) end), + NewRegistry = [{Name, NewShip} | NewState#ship_state.ships_registry], + link(NewShip), + NewState#ship_state{ships_registry = NewRegistry}; + false -> + NewState + end, + + command_ship_loop(FinalState); + false -> + command_ship_loop(State) + end; + {register_auth_ref, Ref} -> + AuthRefs = [Ref | State#ship_state.auth_refs], + command_ship_loop(State#ship_state{auth_refs = AuthRefs}); + {auth_check, Ref, From} -> + Result = lists:member(Ref, State#ship_state.auth_refs), + From ! {auth_result, Result}, + command_ship_loop(State); + _Other -> + command_ship_loop(State) + end. + +%% Main loop for pirate ship processes +pirate_ship_loop(State) -> + receive + {message, _FromShip, {Ref, Content}} -> + NewRefs = [Ref | State#ship_state.received_refs], + NewMessages = [{Ref, Content} | State#ship_state.messages], + pirate_ship_loop(State#ship_state{received_refs = NewRefs, messages = NewMessages}); + {check_received, Ref, From} -> + Result = lists:member(Ref, State#ship_state.received_refs), + From ! {received_check, Result}, + pirate_ship_loop(State); + {get_message, Ref, From} -> + Message = + case lists:keyfind(Ref, 1, State#ship_state.messages) of + {Ref, Content} -> + Content; + false -> + undefined + end, + From ! {message_response, Message}, + pirate_ship_loop(State); + {link_to, Ship} -> + link(Ship), + pirate_ship_loop(State); + {register_auth_ref, Ref} -> + AuthRefs = [Ref | State#ship_state.auth_refs], + pirate_ship_loop(State#ship_state{auth_refs = AuthRefs}); + {auth_message, _FromShip, AuthRef, Message} -> + % Store the auth message if we have the ref registered + case lists:member(AuthRef, State#ship_state.auth_refs) of + true -> + NewMessages = [{AuthRef, Message} | State#ship_state.messages], + pirate_ship_loop(State#ship_state{messages = NewMessages}); + false -> + pirate_ship_loop(State) + end; + {auth_check, Ref, From} -> + Result = lists:member(Ref, State#ship_state.auth_refs), + From ! {auth_result, Result}, + pirate_ship_loop(State); + _Other -> + pirate_ship_loop(State) + end. diff --git a/exercises/practice/space-pirates/rebar.config b/exercises/practice/space-pirates/rebar.config new file mode 100644 index 00000000..db5d9076 --- /dev/null +++ b/exercises/practice/space-pirates/rebar.config @@ -0,0 +1,30 @@ +%% Erlang compiler options +{erl_opts, [debug_info, warnings_as_errors]}. + +{deps, [{erl_exercism, "0.1.2"}]}. + +{dialyzer, [ + {warnings, [underspecs, no_return]}, + {get_warnings, true}, + {plt_apps, top_level_deps}, % top_level_deps | all_deps + {plt_extra_apps, []}, + {plt_location, local}, % local | "/my/file/name" + {plt_prefix, "rebar3"}, + {base_plt_apps, [stdlib, kernel, crypto]}, + {base_plt_location, global}, % global | "/my/file/name" + {base_plt_prefix, "rebar3"} +]}. + +%% eunit:test(Tests) +{eunit_tests, []}. +%% Options for eunit:test(Tests, Opts) +{eunit_opts, [verbose]}. + +%% == xref == + +{xref_warnings, true}. + +%% xref checks to run +{xref_checks, [undefined_function_calls, undefined_functions, + locals_not_used, exports_not_used, + deprecated_function_calls, deprecated_functions]}. diff --git a/exercises/practice/space-pirates/src/space_pirates.app.src b/exercises/practice/space-pirates/src/space_pirates.app.src new file mode 100644 index 00000000..ac0160e1 --- /dev/null +++ b/exercises/practice/space-pirates/src/space_pirates.app.src @@ -0,0 +1,10 @@ +{application, space_pirates, + [{description, "exercism.org - space-pirates"}, + {vsn, "0.0.1"}, + {modules, []}, + {registered, []}, + {applications, [kernel, + stdlib]}, + {env, []} + ]}. + diff --git a/exercises/practice/space-pirates/src/space_pirates.erl b/exercises/practice/space-pirates/src/space_pirates.erl new file mode 100644 index 00000000..a7033b37 --- /dev/null +++ b/exercises/practice/space-pirates/src/space_pirates.erl @@ -0,0 +1 @@ +-module(space_pirates). diff --git a/exercises/practice/space-pirates/test/space_pirates_tests.erl b/exercises/practice/space-pirates/test/space_pirates_tests.erl new file mode 100644 index 00000000..0fc456dd --- /dev/null +++ b/exercises/practice/space-pirates/test/space_pirates_tests.erl @@ -0,0 +1,112 @@ +-module(space_pirates_tests). + +-include_lib("erl_exercism/include/exercism.hrl"). +-include_lib("eunit/include/eunit.hrl"). + +command_ship_start_test_() -> + {"Command ship can be started and is a valid process", + ?_assertMatch(Pid when is_pid(Pid), space_pirates:start_command_ship())}. + +spawn_pirate_ship_test_() -> + {"A pirate ship can be spawned with a name and returns a valid process ID", + fun() -> + CommandShip = space_pirates:start_command_ship(), + PirateShip = space_pirates:spawn_pirate_ship(CommandShip, "Black Pearl"), + ?assert(is_pid(PirateShip)), + ?assertEqual(true, space_pirates:ship_exists(CommandShip, "Black Pearl")) + end}. + +create_mission_ref_test_() -> + {"Mission references are created as unique references", + fun() -> + Ref1 = space_pirates:create_mission_ref(), + Ref2 = space_pirates:create_mission_ref(), + ?assert(is_reference(Ref1)), + ?assert(is_reference(Ref2)), + ?assertNotEqual(Ref1, Ref2) + end}. + +message_sending_test_() -> + {"Ships can send and receive messages with proper authentication", + fun() -> + CommandShip = space_pirates:start_command_ship(), + ShipA = space_pirates:spawn_pirate_ship(CommandShip, "Stellar Blade"), + ShipB = space_pirates:spawn_pirate_ship(CommandShip, "Crimson Raider"), + MissionRef = space_pirates:create_mission_ref(), + Message = "Coordinates to treasure: Sector 7G", + ?assertEqual(ok, space_pirates:send_message(ShipA, ShipB, {MissionRef, Message})), + timer:sleep(50), % Small delay to ensure message delivery + ?assertEqual(true, space_pirates:message_received(ShipB, MissionRef)), + ?assertEqual(Message, space_pirates:get_last_message(ShipB, MissionRef)) + end}. + +enable_distress_beacon_test_() -> + {"Command ship can enable distress beacon to trap exit signals", + fun() -> + CommandShip = space_pirates:start_command_ship(), + ?assertEqual(ok, space_pirates:enable_distress_beacon(CommandShip)) + end}. + +ship_destruction_test_() -> + {"When a ship is destroyed, the command ship receives an exit signal", + fun() -> + CommandShip = space_pirates:start_command_ship(), + space_pirates:enable_distress_beacon(CommandShip), + PirateShip = space_pirates:spawn_pirate_ship(CommandShip, "Doomed Vessel"), + ?assertEqual(ok, space_pirates:link_ships(CommandShip, PirateShip)), + ?assertEqual(ok, space_pirates:destroy_ship(PirateShip, "Hit by asteroid")), + timer:sleep(100), % Give time for exit signal to be processed + ?assertEqual( + {ship_lost, "Doomed Vessel", "Hit by asteroid"}, + space_pirates:get_last_distress_signal(CommandShip) + ) + end}. + +ship_replacement_test_() -> + {"Command ship can automatically replace destroyed ships", + fun() -> + CommandShip = space_pirates:start_command_ship(), + space_pirates:enable_distress_beacon(CommandShip), + space_pirates:enable_auto_replacement(CommandShip, true), + OriginalShip = space_pirates:spawn_pirate_ship(CommandShip, "Replaceable"), + space_pirates:link_ships(CommandShip, OriginalShip), + ?assertEqual(1, space_pirates:count_ships_by_name(CommandShip, "Replaceable")), + space_pirates:destroy_ship(OriginalShip, "Battle damage"), + timer:sleep(200), % Give time for replacement to occur + ?assertEqual(1, space_pirates:count_ships_by_name(CommandShip, "Replaceable")), + NewShip = space_pirates:get_ship_by_name(CommandShip, "Replaceable"), + ?assertNotEqual(OriginalShip, NewShip) + end}. + +%% Test distress signal with reference +distress_signal_with_ref_test_() -> + {"Distress signals include unique references for tracking", + fun() -> + CommandShip = space_pirates:start_command_ship(), + space_pirates:enable_distress_beacon(CommandShip), + PirateShip = space_pirates:spawn_pirate_ship(CommandShip, "Imperiled"), + DistressRef = make_ref(), + ?assertEqual(ok, space_pirates:send_distress_signal(PirateShip, CommandShip, DistressRef, "Under attack")), + timer:sleep(50), % Allow time for message processing + ?assertEqual( + {distress, "Imperiled", "Under attack", DistressRef}, + space_pirates:get_distress_signal_by_ref(CommandShip, DistressRef) + ) + end}. + +message_authentication_test_() -> + {"Messages between ships must be properly authenticated with references", + fun() -> + CommandShip = space_pirates:start_command_ship(), + ShipA = space_pirates:spawn_pirate_ship(CommandShip, "Sender"), + ShipB = space_pirates:spawn_pirate_ship(CommandShip, "Receiver"), + AuthRef = space_pirates:create_auth_ref(ShipA, ShipB), + Message = "Secret plans", + ?assertEqual(ok, space_pirates:send_authenticated_message(ShipA, ShipB, AuthRef, Message)), + timer:sleep(50), + ?assertEqual(true, space_pirates:authenticate_message(ShipB, AuthRef)), + FakeRef = make_ref(), + ?assertEqual(ok, space_pirates:send_authenticated_message(ShipA, ShipB, FakeRef, "Fake message")), + timer:sleep(50), + ?assertEqual(false, space_pirates:authenticate_message(ShipB, FakeRef)) + end}.