C
C#12mo ago
RANI

help with code

Need to get 100 pairs at the same time And need console to find what Is the smallest number out of the all the big number
42 Replies
SG97
SG9712mo ago
aight, what's the code so far? and what do the pairs represent a small and a big number?
RANI
RANIOP12mo ago
Pair is input from user User need to input 100 pair I need console to get those 100 pair find the biggest of every pair And what is the smallest number out of all this
SG97
SG9712mo ago
so the smallest and biggest of all the pairs?
RANI
RANIOP12mo ago
Nope output is the smallest number out of all of biggest number For example (8,9),(1,6) (7,3)(2,4) Output is 4 Cuz the biggest number is 9,6,7,4 and the smallest of them is 4
Angius
Angius12mo ago
Sure, makes sense What code do you have so far?
RANI
RANIOP12mo ago
Got the basic only
SG97
SG9712mo ago
$code
MODiX
MODiX12mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
RANI
RANIOP12mo ago
using System; class Program { static void Main() { Console.writeLine("Hello, please enter 100 pairs of number in this format (num,num)”)
} }
Angius
Angius12mo ago
Ah, so you don't even have the user input Start with that
RANI
RANIOP12mo ago
Save it as something or like
Angius
Angius12mo ago
Uh, in a variable probably, yes
RANI
RANIOP12mo ago
But like how do I spilt the pairs Or I save all 100 as the same int
Angius
Angius12mo ago
Who says the same int? Use a list And the elements of each pair could be stored in, let's say, a tuple Or another list/array Splitting? Easy, .Split() You might also want to .Trim() the parentheses And then int.Parse() the strings to actual integers
RANI
RANIOP12mo ago
Imma check teacher if I can use it we haven’t learned it yet If I do spilt how is it going to split Like by what
Angius
Angius12mo ago
By what you want .Split() does take arguments
RANI
RANIOP12mo ago
Oh like .split(-) And it’s gonna split between each -?
Angius
Angius12mo ago
Yep
MODiX
MODiX12mo ago
Angius
REPL Result: Success
"a-b".Split('-')
"a-b".Split('-')
Result: string[]
[
"a",
"b"
]
[
"a",
"b"
]
Compile: 411.928ms | Execution: 26.073ms | React with ❌ to remove this embed.
RANI
RANIOP12mo ago
It’s just .split or what is before
Angius
Angius12mo ago
See the code above
RANI
RANIOP12mo ago
So like save input as a and then a.split(-)?
Angius
Angius12mo ago
You could, yeah
RANI
RANIOP12mo ago
So imma add it and get back to u Teacher say I can’t use split I can use While string For string String If Math And the basic
Angius
Angius12mo ago
Not even a foreach loop? Still, it's doable You'll just have to parse the input manually Use the fact, that each string is just an array of characters So you can go through all the characters in order If the first one is (, discard it, continue If the next one is a numeric char, add it to some buffer Keep doing that until you encounter a comma Then keep adding the numeric chars to another buffer, until you encounter a closing parentheses or end of the string We can check if a character is numeric with simple maths We use the fact that chars are just integers in disguise
MODiX
MODiX12mo ago
Angius
REPL Result: Success
new { ZeroValue = (int)'0', NineValue = (int)'9' }
new { ZeroValue = (int)'0', NineValue = (int)'9' }
Result: <>f__AnonymousType0#1<int, int>
{
"zeroValue": 48,
"nineValue": 57
}
{
"zeroValue": 48,
"nineValue": 57
}
Compile: 287.926ms | Execution: 80.486ms | React with ❌ to remove this embed.
Angius
Angius12mo ago
We're looking for chars in this range All of them will be numeric, that is 0 to 9
RANI
RANIOP12mo ago
I think the number can be everything that can be in int Not for m0-9
Angius
Angius12mo ago
But we're stepping through the string char by char That's why I mentioned using a buffer of some sort
RANI
RANIOP12mo ago
So how am I about to split Even manually have no idea how do u split it
Angius
Angius12mo ago
==182
^ not int, skip
buffer = ""

==182
^ not int, skip
buffer = ""

==182
^ int, add to buffer
buffer = "18"

==182
^ int, add to buffer
buffer = "182"
==182
^ not int, skip
buffer = ""

==182
^ not int, skip
buffer = ""

==182
^ int, add to buffer
buffer = "18"

==182
^ int, add to buffer
buffer = "182"
For example You'd do the same but with two buffers
(12,82)
^ not numeric, skip
a = "", b = ""

(12,82)
^ numeric, add
a = "1", b = ""

(12,82)
^ numeric, add
a = "12", b = ""

(12,82)
^ comma, switch buffers
a = "12", b = ""

(12,82)
^ numeric, add
a = "12", b = "8"

(12,82)
^ numeric, add
a = "12", b = "82"

(12,82)
^ not numeric, end
a = "12", b = "82"
(12,82)
^ not numeric, skip
a = "", b = ""

(12,82)
^ numeric, add
a = "1", b = ""

(12,82)
^ numeric, add
a = "12", b = ""

(12,82)
^ comma, switch buffers
a = "12", b = ""

(12,82)
^ numeric, add
a = "12", b = "8"

(12,82)
^ numeric, add
a = "12", b = "82"

(12,82)
^ not numeric, end
a = "12", b = "82"
RANI
RANIOP12mo ago
Don’t think we learn that also
Angius
Angius12mo ago
Learn what? Loops? Strings? Variables? It's not some fancy concept, just a loop, two string variables, and a couple of ifs And a couple of bools
RANI
RANIOP12mo ago
Buffer Or am I just dumb What is buffet stand for
Angius
Angius12mo ago
Just a string variable you add to string a = "" And then you can append the numeric chars to it
MODiX
MODiX12mo ago
Angius
REPL Result: Success
string a = "";
a += '5';
a += '7';
a
string a = "";
a += '5';
a += '7';
a
Result: string
57
57
Compile: 441.765ms | Execution: 37.697ms | React with ❌ to remove this embed.
Angius
Angius12mo ago
Like so
RANI
RANIOP12mo ago
So u got string a Du did and 5 and 7 It’s add it up to 57 Just would that help up divide
Angius
Angius12mo ago
Because you will have two variables a and b Look at the example I sent Specifically at the position of the ^ Before you encounter the comma, keep adding to a
RANI
RANIOP12mo ago
This?
Angius
Angius12mo ago
MODiX
MODiX12mo ago
Angius
(12,82)
^ not numeric, skip
a = "", b = ""

(12,82)
^ numeric, add
a = "1", b = ""

(12,82)
^ numeric, add
a = "12", b = ""

(12,82)
^ comma, switch buffers
a = "12", b = ""

(12,82)
^ numeric, add
a = "12", b = "8"

(12,82)
^ numeric, add
a = "12", b = "82"

(12,82)
^ not numeric, end
a = "12", b = "82"
(12,82)
^ not numeric, skip
a = "", b = ""

(12,82)
^ numeric, add
a = "1", b = ""

(12,82)
^ numeric, add
a = "12", b = ""

(12,82)
^ comma, switch buffers
a = "12", b = ""

(12,82)
^ numeric, add
a = "12", b = "8"

(12,82)
^ numeric, add
a = "12", b = "82"

(12,82)
^ not numeric, end
a = "12", b = "82"
Quoted by
<@85903769203642368> from #help with code (click here)
React with ❌ to remove this embed.
Want results from more Discord servers?
Add your server