From 7e60a6b390dfef28e4c935b66fe722f0d1c227a8 Mon Sep 17 00:00:00 2001 From: rzmk Date: Mon, 18 Mar 2024 20:56:52 +0000 Subject: [PATCH] deploy: b35539051bbfc7b1d1421ef0c76680a60204f89b --- ladderz/all.html | 2 +- ladderz/dsa/fn.two_sum.html | 2 + ladderz/dsa/index.html | 4 +- ladderz/dsa/sidebar-items.js | 2 +- lz/dsa/enum.Dsa.html | 18 +++- lz/dsa/fn.match_dsa.html | 2 +- lz/dsa/index.html | 2 +- search-index.js | 4 +- src/ladderz/dsa.rs.html | 38 ++++++++ src/lz/dsa.rs.html | 96 +++++++++++++++++++ .../derive/trait.FromArgMatches.js | 2 +- .../clap_builder/derive/trait.Subcommand.js | 2 +- 12 files changed, 162 insertions(+), 12 deletions(-) create mode 100644 ladderz/dsa/fn.two_sum.html diff --git a/ladderz/all.html b/ladderz/all.html index 91c5ed6..4b4ae3a 100644 --- a/ladderz/all.html +++ b/ladderz/all.html @@ -1,2 +1,2 @@ List of all items in this crate -
\ No newline at end of file +
\ No newline at end of file diff --git a/ladderz/dsa/fn.two_sum.html b/ladderz/dsa/fn.two_sum.html new file mode 100644 index 0000000..55c8567 --- /dev/null +++ b/ladderz/dsa/fn.two_sum.html @@ -0,0 +1,2 @@ +two_sum in ladderz::dsa - Rust +

Function ladderz::dsa::two_sum

source ·
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32>
\ No newline at end of file diff --git a/ladderz/dsa/index.html b/ladderz/dsa/index.html index 65ffd05..ea6424c 100644 --- a/ladderz/dsa/index.html +++ b/ladderz/dsa/index.html @@ -1,5 +1,5 @@ ladderz::dsa - Rust -

Module ladderz::dsa

source ·
Expand description

Various data structures and algorithms implementations.

+

Module ladderz::dsa

source ·
Expand description

Various data structures and algorithms implementations.

Example

use ladderz::dsa::contains_duplicate;
 
@@ -7,4 +7,4 @@
 let result = contains_duplicate(nums.clone());
 println!("The vector {:?} {} contain a duplicate.", &nums, if result { "does" } else { "does not" });
The vector [2, 3, 4, 2] does contain a duplicate.
-

Functions

\ No newline at end of file +

Functions

\ No newline at end of file diff --git a/ladderz/dsa/sidebar-items.js b/ladderz/dsa/sidebar-items.js index 9a2f7e6..6ff7a6f 100644 --- a/ladderz/dsa/sidebar-items.js +++ b/ladderz/dsa/sidebar-items.js @@ -1 +1 @@ -window.SIDEBAR_ITEMS = {"fn":["contains_duplicate","is_anagram","is_anagram2"]}; \ No newline at end of file +window.SIDEBAR_ITEMS = {"fn":["contains_duplicate","is_anagram","is_anagram2","two_sum"]}; \ No newline at end of file diff --git a/lz/dsa/enum.Dsa.html b/lz/dsa/enum.Dsa.html index e8ab4a3..d7df14d 100644 --- a/lz/dsa/enum.Dsa.html +++ b/lz/dsa/enum.Dsa.html @@ -1,5 +1,5 @@ -Dsa in lz::dsa - Rust -

Enum lz::dsa::Dsa

source ·
pub enum Dsa {
+Dsa in lz::dsa - Rust
+    

Enum lz::dsa::Dsa

source ·
pub enum Dsa {
     ContainsDuplicate {
         n: Vec<i32>,
         raw: bool,
@@ -9,6 +9,11 @@
         b: String,
         raw: bool,
     },
+    TwoSum {
+        nums: String,
+        target: i32,
+        raw: bool,
+    },
 }

Variants§

§

ContainsDuplicate

Fields

§n: Vec<i32>

The vector of numbers to detect whether it has a duplicate.

§raw: bool

Whether or not to return the raw output.

Returns true or false based on whether the vector has a duplicate.

@@ -24,6 +29,15 @@ lz dsa contains-duplicate 1 2 3 2
Example
Input
lz dsa is-anagram marc cram
 
Output
"marc" is an anagram of "cram".
 
Raw Output (use -r or --raw)
true
+
§

TwoSum

Fields

§nums: String

The vector of numbers as a comma-delimited string.

+
§target: i32

The number that two numbers from nums must sum to.

+
§raw: bool

Whether or not to return the raw output.

+

Returns the indices of two numbers in a vector that sum to a target number.

+

There is an assumption that there must always exist at least two numbers that +sum to the target number in the given vector of numbers.

+
Example
Input
lz dsa two-sum 1,2,3 5
+
Output
[1, 2]
+
Raw Output (use -r or --raw)
[1, 2]
 

Trait Implementations§

source§

impl FromArgMatches for Dsa

source§

fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>

Instantiate Self from [ArgMatches], parsing the arguments as needed. Read more
source§

fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches ) -> Result<Self, Error>

Instantiate Self from [ArgMatches], parsing the arguments as needed. Read more
source§

fn update_from_arg_matches( diff --git a/lz/dsa/fn.match_dsa.html b/lz/dsa/fn.match_dsa.html index dad61ae..b9009da 100644 --- a/lz/dsa/fn.match_dsa.html +++ b/lz/dsa/fn.match_dsa.html @@ -1,2 +1,2 @@ match_dsa in lz::dsa - Rust -

Function lz::dsa::match_dsa

source ·
pub fn match_dsa(function: Option<Dsa>)
\ No newline at end of file +

Function lz::dsa::match_dsa

source ·
pub fn match_dsa(function: Option<Dsa>)
\ No newline at end of file diff --git a/lz/dsa/index.html b/lz/dsa/index.html index 33e1337..5b3fba5 100644 --- a/lz/dsa/index.html +++ b/lz/dsa/index.html @@ -1,2 +1,2 @@ lz::dsa - Rust -
\ No newline at end of file +
\ No newline at end of file diff --git a/search-index.js b/search-index.js index f9ca1c5..f7fde0f 100644 --- a/search-index.js +++ b/search-index.js @@ -1,6 +1,6 @@ var searchIndex = new Map(JSON.parse('[\ -["ladderz",{"doc":"ladderz","t":"CCHHHHHHHHHHHH","n":["dsa","prealgebra","contains_duplicate","is_anagram","is_anagram2","get_factor_pairs","get_factors","get_multiples_in_range","get_prime_factorization","get_primes_in_range","is_composite","is_factor","is_multiple","is_prime"],"q":[[0,"ladderz"],[2,"ladderz::dsa"],[5,"ladderz::prealgebra"],[14,"alloc::vec"],[15,"alloc::string"],[16,"std::collections::hash::set"],[17,"std::collections::hash::map"]],"d":["Various data structures and algorithms implementations.","Various pre-algebra implementations including factor …","","","","Finds all factor pairs for a positive integer n.","Finds all factors of a positive integer n.","Finds all the multiples of a positive integer n starting …","Returns the prime factorization of a positive integer n.","Returns all prime numbers in the range [start, end].","Checks if a positive integer n is a composite number.","Checks if a positive integer x is a factor of another …","Checks if a positive integer x is a multiple of another …","Checks if a positive integer n is a prime number."],"i":[0,0,0,0,0,0,0,0,0,0,0,0,0,0],"f":[0,0,[[[2,[1]]],3],[[4,4],3],[[4,4],3],[5,[[7,[[6,[5,5]]]]]],[5,[[7,[5]]]],[[5,5,5],[[7,[5]]]],[5,[[8,[5,5]]]],[[5,5],[[7,[5]]]],[5,3],[[5,5],3],[[5,5],3],[5,3]],"c":[],"p":[[1,"i32"],[5,"Vec",14],[1,"bool"],[5,"String",15],[1,"u32"],[1,"tuple"],[5,"HashSet",16],[5,"HashMap",17]],"b":[]}],\ -["lz",{"doc":"lz","t":"FPPGNNNNNNNNNNCNNNNNNNNNNHCONNNNNNNNNNOOPGPNNNNNNNNNHNNNNNOOOOOPPPPPPPGPPNNNNNNNNNHNNNNNOOOOOOOOOOOOOOOOOOOOOOO","n":["Cli","Dsa","Prealgebra","Subjects","augment_args","augment_args_for_update","augment_subcommands","augment_subcommands_for_update","borrow","borrow","borrow_mut","borrow_mut","command","command_for_update","dsa","from","from","from_arg_matches","from_arg_matches","from_arg_matches_mut","from_arg_matches_mut","group_id","has_subcommand","into","into","main","prealgebra","subject","try_from","try_from","try_into","try_into","type_id","type_id","update_from_arg_matches","update_from_arg_matches","update_from_arg_matches_mut","update_from_arg_matches_mut","function","function","ContainsDuplicate","Dsa","IsAnagram","augment_subcommands","augment_subcommands_for_update","borrow","borrow_mut","from","from_arg_matches","from_arg_matches_mut","has_subcommand","into","match_dsa","try_from","try_into","type_id","update_from_arg_matches","update_from_arg_matches_mut","a","b","n","raw","raw","FactorPairs","Factors","IsComposite","IsFactor","IsMultiple","IsPrime","MultiplesInRange","Prealgebra","PrimeFactorization","PrimesInRange","augment_subcommands","augment_subcommands_for_update","borrow","borrow_mut","from","from_arg_matches","from_arg_matches_mut","has_subcommand","into","match_prealgebra","try_from","try_into","type_id","update_from_arg_matches","update_from_arg_matches_mut","lower_bound","lower_bound","m","m","n","n","n","n","n","n","n","n","raw","raw","raw","raw","raw","raw","raw","raw","raw","upper_bound","upper_bound"],"q":[[0,"lz"],[38,"lz::Subjects"],[40,"lz::dsa"],[58,"lz::dsa::Dsa"],[63,"lz::prealgebra"],[88,"lz::prealgebra::Prealgebra"],[111,"clap_builder::builder::command"],[112,"clap_builder::parser::matches::arg_matches"],[113,"clap_builder"],[114,"core::result"],[115,"clap_builder::util::id"],[116,"core::option"],[117,"core::any"]],"d":["","","","The subjects that can be used.","","","","","","","","","","","","Returns the argument unchanged.","Returns the argument unchanged.","","","","","","","Calls U::from(self).","Calls U::from(self).","","","","","","","","","","","","","","The function (command) to run.","","Returns true or false based on whether the vector has a …","","Returns true or false based on whether string a is an …","","","","","Returns the argument unchanged.","","","","Calls U::from(self).","","","","","","","The first string to compare against.","The second string to compare against.","The vector of numbers to detect whether it has a duplicate.","Whether or not to return the raw output.","Whether or not to return the raw output.","Finds all factor pairs for a positive integer.","Finds all factors for a positive integer.","Determines if a positive integer is composite.","Determines if a positive integer is a factor of another …","Determines if a positive integer is a multiple of another …","Determines if a positive integer is prime.","Finds all multiples of a positive integer in a given range.","","Finds the prime factorization of a positive integer.","Finds all primes in a given range.","","","","","Returns the argument unchanged.","","","","Calls U::from(self).","","","","","","","The lower bound of the range to find multiples in.","The lower bound of the range to find primes in.","The positive integer to determine if it is a multiple.","The positive integer to determine if it is a factor.","The positive integer to find factor pairs for.","The positive integer to find factors for.","The positive integer to find multiples for.","The positive integer to find the prime factorization of.","The positive integer to determine if it is composite.","The positive integer to determine if it is prime.","The positive integer to determine if it is a factor.","The positive integer to determine if it is a multiple.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","The upper bound of the range to find multiples in.","The upper bound of the range to find primes in."],"i":[0,6,6,0,3,3,6,6,3,6,3,6,3,3,0,3,6,3,6,3,6,3,6,3,6,0,0,3,3,6,3,6,3,6,3,6,3,6,15,16,13,0,13,13,13,13,13,13,13,13,13,13,0,13,13,13,13,13,17,17,18,18,17,14,14,14,14,14,14,14,0,14,14,14,14,14,14,14,14,14,14,14,0,14,14,14,14,14,19,20,21,22,23,24,19,25,26,27,21,22,23,24,19,20,25,26,27,21,22,19,20],"f":[0,0,0,0,[1,1],[1,1],[1,1],[1,1],[-1,-2,[],[]],[-1,-2,[],[]],[-1,-2,[],[]],[-1,-2,[],[]],[[],1],[[],1],0,[-1,-1,[]],[-1,-1,[]],[2,[[5,[3,4]]]],[2,[[5,[6,4]]]],[2,[[5,[3,4]]]],[2,[[5,[6,4]]]],[[],[[8,[7]]]],[9,10],[-1,-2,[],[]],[-1,-2,[],[]],[[],11],0,0,[-1,[[5,[-2]]],[],[]],[-1,[[5,[-2]]],[],[]],[-1,[[5,[-2]]],[],[]],[-1,[[5,[-2]]],[],[]],[-1,12,[]],[-1,12,[]],[[3,2],[[5,[11,4]]]],[[6,2],[[5,[11,4]]]],[[3,2],[[5,[11,4]]]],[[6,2],[[5,[11,4]]]],0,0,0,0,0,[1,1],[1,1],[-1,-2,[],[]],[-1,-2,[],[]],[-1,-1,[]],[2,[[5,[13,4]]]],[2,[[5,[13,4]]]],[9,10],[-1,-2,[],[]],[[[8,[13]]],11],[-1,[[5,[-2]]],[],[]],[-1,[[5,[-2]]],[],[]],[-1,12,[]],[[13,2],[[5,[11,4]]]],[[13,2],[[5,[11,4]]]],0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,[1,1],[1,1],[-1,-2,[],[]],[-1,-2,[],[]],[-1,-1,[]],[2,[[5,[14,4]]]],[2,[[5,[14,4]]]],[9,10],[-1,-2,[],[]],[[[8,[14]]],11],[-1,[[5,[-2]]],[],[]],[-1,[[5,[-2]]],[],[]],[-1,12,[]],[[14,2],[[5,[11,4]]]],[[14,2],[[5,[11,4]]]],0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"c":[],"p":[[5,"Command",111],[5,"ArgMatches",112],[5,"Cli",0],[8,"Error",113],[6,"Result",114],[6,"Subjects",0],[5,"Id",115],[6,"Option",116],[1,"str"],[1,"bool"],[1,"tuple"],[5,"TypeId",117],[6,"Dsa",40],[6,"Prealgebra",63],[15,"Prealgebra",38],[15,"Dsa",38],[15,"IsAnagram",58],[15,"ContainsDuplicate",58],[15,"MultiplesInRange",88],[15,"PrimesInRange",88],[15,"IsFactor",88],[15,"IsMultiple",88],[15,"FactorPairs",88],[15,"Factors",88],[15,"PrimeFactorization",88],[15,"IsComposite",88],[15,"IsPrime",88]],"b":[]}]\ +["ladderz",{"doc":"ladderz","t":"CCHHHHHHHHHHHHH","n":["dsa","prealgebra","contains_duplicate","is_anagram","is_anagram2","two_sum","get_factor_pairs","get_factors","get_multiples_in_range","get_prime_factorization","get_primes_in_range","is_composite","is_factor","is_multiple","is_prime"],"q":[[0,"ladderz"],[2,"ladderz::dsa"],[6,"ladderz::prealgebra"],[15,"alloc::vec"],[16,"alloc::string"],[17,"std::collections::hash::set"],[18,"std::collections::hash::map"]],"d":["Various data structures and algorithms implementations.","Various pre-algebra implementations including factor …","","","","","Finds all factor pairs for a positive integer n.","Finds all factors of a positive integer n.","Finds all the multiples of a positive integer n starting …","Returns the prime factorization of a positive integer n.","Returns all prime numbers in the range [start, end].","Checks if a positive integer n is a composite number.","Checks if a positive integer x is a factor of another …","Checks if a positive integer x is a multiple of another …","Checks if a positive integer n is a prime number."],"i":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"f":[0,0,[[[2,[1]]],3],[[4,4],3],[[4,4],3],[[[2,[1]],1],[[2,[1]]]],[5,[[7,[[6,[5,5]]]]]],[5,[[7,[5]]]],[[5,5,5],[[7,[5]]]],[5,[[8,[5,5]]]],[[5,5],[[7,[5]]]],[5,3],[[5,5],3],[[5,5],3],[5,3]],"c":[],"p":[[1,"i32"],[5,"Vec",15],[1,"bool"],[5,"String",16],[1,"u32"],[1,"tuple"],[5,"HashSet",17],[5,"HashMap",18]],"b":[]}],\ +["lz",{"doc":"lz","t":"FPPGNNNNNNNNNNCNNNNNNNNNNHCONNNNNNNNNNOOPGPPNNNNNNNNNHNNNNNOOOOOOOOPPPPPPPGPPNNNNNNNNNHNNNNNOOOOOOOOOOOOOOOOOOOOOOO","n":["Cli","Dsa","Prealgebra","Subjects","augment_args","augment_args_for_update","augment_subcommands","augment_subcommands_for_update","borrow","borrow","borrow_mut","borrow_mut","command","command_for_update","dsa","from","from","from_arg_matches","from_arg_matches","from_arg_matches_mut","from_arg_matches_mut","group_id","has_subcommand","into","into","main","prealgebra","subject","try_from","try_from","try_into","try_into","type_id","type_id","update_from_arg_matches","update_from_arg_matches","update_from_arg_matches_mut","update_from_arg_matches_mut","function","function","ContainsDuplicate","Dsa","IsAnagram","TwoSum","augment_subcommands","augment_subcommands_for_update","borrow","borrow_mut","from","from_arg_matches","from_arg_matches_mut","has_subcommand","into","match_dsa","try_from","try_into","type_id","update_from_arg_matches","update_from_arg_matches_mut","a","b","n","nums","raw","raw","raw","target","FactorPairs","Factors","IsComposite","IsFactor","IsMultiple","IsPrime","MultiplesInRange","Prealgebra","PrimeFactorization","PrimesInRange","augment_subcommands","augment_subcommands_for_update","borrow","borrow_mut","from","from_arg_matches","from_arg_matches_mut","has_subcommand","into","match_prealgebra","try_from","try_into","type_id","update_from_arg_matches","update_from_arg_matches_mut","lower_bound","lower_bound","m","m","n","n","n","n","n","n","n","n","raw","raw","raw","raw","raw","raw","raw","raw","raw","upper_bound","upper_bound"],"q":[[0,"lz"],[38,"lz::Subjects"],[40,"lz::dsa"],[59,"lz::dsa::Dsa"],[67,"lz::prealgebra"],[92,"lz::prealgebra::Prealgebra"],[115,"clap_builder::builder::command"],[116,"clap_builder::parser::matches::arg_matches"],[117,"clap_builder"],[118,"core::result"],[119,"clap_builder::util::id"],[120,"core::option"],[121,"core::any"]],"d":["","","","The subjects that can be used.","","","","","","","","","","","","Returns the argument unchanged.","Returns the argument unchanged.","","","","","","","Calls U::from(self).","Calls U::from(self).","","","","","","","","","","","","","","The function (command) to run.","","Returns true or false based on whether the vector has a …","","Returns true or false based on whether string a is an …","Returns the indices of two numbers in a vector that sum to …","","","","","Returns the argument unchanged.","","","","Calls U::from(self).","","","","","","","The first string to compare against.","The second string to compare against.","The vector of numbers to detect whether it has a duplicate.","The vector of numbers as a comma-delimited string.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","The number that two numbers from nums must sum to.","Finds all factor pairs for a positive integer.","Finds all factors for a positive integer.","Determines if a positive integer is composite.","Determines if a positive integer is a factor of another …","Determines if a positive integer is a multiple of another …","Determines if a positive integer is prime.","Finds all multiples of a positive integer in a given range.","","Finds the prime factorization of a positive integer.","Finds all primes in a given range.","","","","","Returns the argument unchanged.","","","","Calls U::from(self).","","","","","","","The lower bound of the range to find multiples in.","The lower bound of the range to find primes in.","The positive integer to determine if it is a multiple.","The positive integer to determine if it is a factor.","The positive integer to find factor pairs for.","The positive integer to find factors for.","The positive integer to find multiples for.","The positive integer to find the prime factorization of.","The positive integer to determine if it is composite.","The positive integer to determine if it is prime.","The positive integer to determine if it is a factor.","The positive integer to determine if it is a multiple.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","Whether or not to return the raw output.","The upper bound of the range to find multiples in.","The upper bound of the range to find primes in."],"i":[0,6,6,0,3,3,6,6,3,6,3,6,3,3,0,3,6,3,6,3,6,3,6,3,6,0,0,3,3,6,3,6,3,6,3,6,3,6,15,16,13,0,13,13,13,13,13,13,13,13,13,13,13,0,13,13,13,13,13,17,17,18,19,18,17,19,19,14,14,14,14,14,14,14,0,14,14,14,14,14,14,14,14,14,14,14,0,14,14,14,14,14,20,21,22,23,24,25,20,26,27,28,22,23,24,25,20,21,26,27,28,22,23,20,21],"f":[0,0,0,0,[1,1],[1,1],[1,1],[1,1],[-1,-2,[],[]],[-1,-2,[],[]],[-1,-2,[],[]],[-1,-2,[],[]],[[],1],[[],1],0,[-1,-1,[]],[-1,-1,[]],[2,[[5,[3,4]]]],[2,[[5,[6,4]]]],[2,[[5,[3,4]]]],[2,[[5,[6,4]]]],[[],[[8,[7]]]],[9,10],[-1,-2,[],[]],[-1,-2,[],[]],[[],11],0,0,[-1,[[5,[-2]]],[],[]],[-1,[[5,[-2]]],[],[]],[-1,[[5,[-2]]],[],[]],[-1,[[5,[-2]]],[],[]],[-1,12,[]],[-1,12,[]],[[3,2],[[5,[11,4]]]],[[6,2],[[5,[11,4]]]],[[3,2],[[5,[11,4]]]],[[6,2],[[5,[11,4]]]],0,0,0,0,0,0,[1,1],[1,1],[-1,-2,[],[]],[-1,-2,[],[]],[-1,-1,[]],[2,[[5,[13,4]]]],[2,[[5,[13,4]]]],[9,10],[-1,-2,[],[]],[[[8,[13]]],11],[-1,[[5,[-2]]],[],[]],[-1,[[5,[-2]]],[],[]],[-1,12,[]],[[13,2],[[5,[11,4]]]],[[13,2],[[5,[11,4]]]],0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,[1,1],[1,1],[-1,-2,[],[]],[-1,-2,[],[]],[-1,-1,[]],[2,[[5,[14,4]]]],[2,[[5,[14,4]]]],[9,10],[-1,-2,[],[]],[[[8,[14]]],11],[-1,[[5,[-2]]],[],[]],[-1,[[5,[-2]]],[],[]],[-1,12,[]],[[14,2],[[5,[11,4]]]],[[14,2],[[5,[11,4]]]],0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"c":[],"p":[[5,"Command",115],[5,"ArgMatches",116],[5,"Cli",0],[8,"Error",117],[6,"Result",118],[6,"Subjects",0],[5,"Id",119],[6,"Option",120],[1,"str"],[1,"bool"],[1,"tuple"],[5,"TypeId",121],[6,"Dsa",40],[6,"Prealgebra",67],[15,"Prealgebra",38],[15,"Dsa",38],[15,"IsAnagram",59],[15,"ContainsDuplicate",59],[15,"TwoSum",59],[15,"MultiplesInRange",92],[15,"PrimesInRange",92],[15,"IsFactor",92],[15,"IsMultiple",92],[15,"FactorPairs",92],[15,"Factors",92],[15,"PrimeFactorization",92],[15,"IsComposite",92],[15,"IsPrime",92]],"b":[]}]\ ]')); if (typeof exports !== 'undefined') exports.searchIndex = searchIndex; else if (window.initSearch) window.initSearch(searchIndex); diff --git a/src/ladderz/dsa.rs.html b/src/ladderz/dsa.rs.html index 6e98b67..6b08705 100644 --- a/src/ladderz/dsa.rs.html +++ b/src/ladderz/dsa.rs.html @@ -73,6 +73,25 @@ 72 73 74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93

use std::collections::{HashMap, HashSet};
 
 pub fn contains_duplicate(nums: Vec<i32>) -> bool {
@@ -129,6 +148,18 @@
     letters.into_values().all(|c: i32| c == 0)
 }
 
+pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
+    let mut seen = HashMap::new();
+    for (i, num) in nums.iter().enumerate() {
+        if seen.contains_key(num) {
+            return vec![i as i32, seen[num]];
+        }
+        let diff = target - num;
+        seen.insert(diff, i as i32);
+    }
+    vec![0, 1]
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;
@@ -146,5 +177,12 @@
         let expected = true;
         assert_eq!(result, expected);
     }
+
+    #[test]
+    fn test_two_sum() {
+        let result: HashSet<i32> = HashSet::from_iter(two_sum(vec![2, 3, 8, 5], 8));
+        let expected: HashSet<i32> = HashSet::from_iter(vec![1, 3]);
+        assert_eq!(result, expected);
+    }
 }
 
\ No newline at end of file diff --git a/src/lz/dsa.rs.html b/src/lz/dsa.rs.html index 4b88112..94892d5 100644 --- a/src/lz/dsa.rs.html +++ b/src/lz/dsa.rs.html @@ -98,6 +98,54 @@ 97 98 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147
use clap::Subcommand;
 
 #[derive(Subcommand)]
@@ -164,6 +212,39 @@
         #[arg(short = 'r', long)]
         raw: bool,
     },
+    /// Returns the indices of two numbers in a vector that sum to a target number.
+    ///
+    /// There is an assumption that there must always exist at least two numbers that
+    /// sum to the target number in the given vector of numbers.
+    ///
+    /// ## Example
+    ///
+    /// ### Input
+    ///
+    /// ```bash
+    /// lz dsa two-sum 1,2,3 5
+    /// ```
+    ///
+    /// ### Output
+    ///
+    /// ```bash
+    /// [1, 2]
+    /// ```
+    ///
+    /// ## Raw Output (use `-r` or `--raw`)
+    ///
+    /// ```bash
+    /// [1, 2]
+    /// ```
+    TwoSum {
+        /// The vector of numbers as a comma-delimited string.
+        nums: String,
+        /// The number that two numbers from nums must sum to.
+        target: i32,
+        /// Whether or not to return the raw output.
+        #[arg(short = 'r', long)]
+        raw: bool,
+    },
 }
 
 pub fn match_dsa(function: Option<Dsa>) {
@@ -192,6 +273,21 @@
                 )
             }
         },
+        Some(Dsa::TwoSum { target, nums, raw }) => {
+            let nums_vec: Vec<i32> = nums
+                .split(',')
+                .map(|num| num.trim())
+                .map(|num| num.parse::<i32>().unwrap())
+                .collect();
+
+            match raw {
+                true => println!("{:?}", two_sum(nums_vec, target)),
+                false => println!(
+                    "The pair of indices of the two numbers that sum to {target} is: {:?}.",
+                    two_sum(nums_vec, target)
+                ),
+            }
+        }
         None => {
             println!("Please provide a function to use.");
         }
diff --git a/trait.impl/clap_builder/derive/trait.FromArgMatches.js b/trait.impl/clap_builder/derive/trait.FromArgMatches.js
index f1b9f23..5fe1efb 100644
--- a/trait.impl/clap_builder/derive/trait.FromArgMatches.js
+++ b/trait.impl/clap_builder/derive/trait.FromArgMatches.js
@@ -1,3 +1,3 @@
 (function() {var implementors = {
-"lz":[["impl FromArgMatches for Dsa"],["impl FromArgMatches for Subjects"],["impl FromArgMatches for Prealgebra"],["impl FromArgMatches for Cli"]]
+"lz":[["impl FromArgMatches for Prealgebra"],["impl FromArgMatches for Subjects"],["impl FromArgMatches for Cli"],["impl FromArgMatches for Dsa"]]
 };if (window.register_implementors) {window.register_implementors(implementors);} else {window.pending_implementors = implementors;}})()
\ No newline at end of file
diff --git a/trait.impl/clap_builder/derive/trait.Subcommand.js b/trait.impl/clap_builder/derive/trait.Subcommand.js
index 236c05a..08c5e88 100644
--- a/trait.impl/clap_builder/derive/trait.Subcommand.js
+++ b/trait.impl/clap_builder/derive/trait.Subcommand.js
@@ -1,3 +1,3 @@
 (function() {var implementors = {
-"lz":[["impl Subcommand for Prealgebra"],["impl Subcommand for Dsa"],["impl Subcommand for Subjects"]]
+"lz":[["impl Subcommand for Subjects"],["impl Subcommand for Prealgebra"],["impl Subcommand for Dsa"]]
 };if (window.register_implementors) {window.register_implementors(implementors);} else {window.pending_implementors = implementors;}})()
\ No newline at end of file