• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 11:09
CEST 17:09
KST 00:09
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL21] Ro16 Preview Pt1: Fresh Flow6[ASL21] Ro24 Preview Pt2: News Flash10[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy21ByuL: The Forgotten Master of ZvT30
Community News
MaNa leaves Team Liquid14$5,000 WardiTV TLMC tournament - Presented by Monster Energy5GSL CK: More events planned pending crowdfunding7Weekly Cups (May 30-Apr 5): herO, Clem, SHIN win0[BSL22] RO32 Group Stage5
StarCraft 2
General
Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool MaNa leaves Team Liquid Team Liquid Map Contest #22 - Presented by Monster Energy Quebec Clan still alive ? BGE Stara Zagora 2026 cancelled
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament $5,000 WardiTV TLMC tournament - Presented by Monster Energy RSL Revival: Season 5 - Qualifiers and Main Event GSL CK: More events planned pending crowdfunding Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 521 Memorable Boss The PondCast: SC2 News & Results Mutation # 520 Moving Fees Mutation # 519 Inner Power
Brood War
General
[ASL21] Ro16 Preview Pt1: Fresh Flow Leta's ASL Ro24 Review The Korean Terminology Thread ASL21 General Discussion BGH Auto Balance -> http://bghmmr.eu/
Tourneys
Escore Tournament StarCraft Season 2 [ASL21] Ro16 Group A [Megathread] Daily Proleagues [ASL21] Ro24 Group F
Strategy
Any training maps people recommend? Fighting Spirit mining rates Muta micro map competition What's the deal with APM & what's its true value
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Battle Aces/David Kim RTS Megathread General RTS Discussion Thread Starcraft Tabletop Miniature Game
Dota 2
The Story of Wings Gaming Official 'what is Dota anymore' discussion
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread Canadian Politics Mega-thread Russo-Ukrainian War Thread European Politico-economics QA Mega-thread The China Politics Thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion Cricket [SPORT] Tokyo Olympics 2021 Thread
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
lurker extra damage testi…
StaticNine
How Streamers Inspire Gamers…
TrAiDoS
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1826 users

The Big Programming Thread - Page 845

Forum Index > General Forum
Post a Reply
Prev 1 843 844 845 846 847 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Hanh
Profile Joined June 2016
146 Posts
February 15 2017 14:16 GMT
#16881
Looks the same results to me considering the clock resolution.
Acrofales
Profile Joined August 2010
Spain18259 Posts
February 15 2017 14:27 GMT
#16882
On February 15 2017 22:16 Manit0u wrote:

require 'benchmark'

arr = Array(1..10_000_000)

def test_fun_guard(ary)
return false if ary.empty?

ary.dup.reverse
end

def test_fun_standard(ary)
if ary.empty?
false
else
ary.dup.reverse
end
end

Benchmark.bmbm(10) do |bm|
bm.report('guard') do
test_fun_guard arr
end

bm.report('standard') do
test_fun_standard arr
end
end


It's astounding how seemingly identical code (same logic basically) can impact performance:


Rehearsal ----------------------------------------------
guard 0.010000 0.020000 0.030000 ( 0.020905)
standard 0.030000 0.010000 0.040000 ( 0.042935)
------------------------------------- total: 0.070000sec
user system total real
guard 0.000000 0.000000 0.000000 ( 0.018477)
standard 0.010000 0.010000 0.020000 ( 0.018885)


I should definitely test if other interpreted languages behave in this way. If so, guard clauses all the way!



I'm not quite sure how to interpret your benchmark results, but if I am supposed to look at what it computes as "real" time in the actual test, it seems like a completely negligible difference. There's a lot of statistics missing. If that ran once, it doesn't show anything. If it was run lots of times, you'd espect a mean and a std. dev... and preferrably a t-test. Finally, I don't know enough about low-level architecture, but how accurate is the computer clock? Because it's claiming microsecond accuracy, and unless you have specialized time measuring equipment in your system, I doubt the clock is accurate to that degree, which means you'd need to cut off a whole load of those trailing digits due to insignificance.
Manit0u
Profile Blog Joined August 2004
Poland17720 Posts
Last Edited: 2017-02-15 15:02:07
February 15 2017 14:50 GMT
#16883
I didn't have enough time to write a real test. It's just copying and reversing an array with 10 million numbers in it 10 times.

The difference in cpu time, system call time and real time doesn't seem like much, but the test was the most basic thing I could think of. I'll write a proper test later on.

The thing is, that supposedly with guard clauses the interpreter doesn't have to parse so much, and it should work faster.

To test it properly I'll write a bit more elaborate functions, with guards and regular, both hitting the guard and not.

Edit:
Results with fibonacci 42 and 1

user system total real
guard 29.350000 0.000000 29.350000 ( 29.356830)
guard hit 0.000000 0.000000 0.000000 ( 0.000001)
standard 29.570000 0.000000 29.570000 ( 29.583686)
standard false 0.000000 0.000000 0.000000 ( 0.000002)


0.2s is not insignificant, even though it's still simple. Any idea how I could test it better? Should I add more of the branching logic, exceptions etc? I'm genuinely interested in this peculiarity.

Also:
https://github.com/search?utf8=✓&q=remove password&type=Commits&ref=searchresults
Time is precious. Waste it wisely.
Hanh
Profile Joined June 2016
146 Posts
February 15 2017 15:14 GMT
#16884
If the test is about copy/reverse of an array, why would the guard even matter? It's only run 10 times compared to the 10 million read/writes. Anyway, the results are the same because the AST is nearly the same.
Silvanel
Profile Blog Joined March 2003
Poland4749 Posts
Last Edited: 2017-02-15 15:23:24
February 15 2017 15:19 GMT
#16885
So i was playing with arrays in C. And i just encountered something i am not sure i understand. What is happening?

my code
+ Show Spoiler +


#include <stdio.h>

const int MAX = 15;

int main () {

int var[] = {10, 100, 200, 500};
int *ptr;
int i;

ptr = var;

for (i =0; i < MAX; i++) {


printf("Value of var [%d] = %d\n", i, *ptr);

ptr++;
}
return 0;

}



output i am getting
+ Show Spoiler +


Value of var [0] = 10
Value of var [1] = 100
Value of var [2] = 200
Value of var [3] = 500
Value of var [4] = 4
Value of var [5] = 2686780
Value of var [6] = 0
Value of var [7] = 0
Value of var [8] = 2686868
Value of var [9] = 4199021
Value of var [10] = 1
Value of var [11] = 3812752
Value of var [12] = 3807472
Value of var [13] = 2686824
Value of var [14] = 1989945361


So basically i created a loop longer than array i am iterating over. Where does the values after the array ends come from? Is C assigning them at random? I suppose lesson is - be aware C is weird.
Pathetic Greta hater.
Acrofales
Profile Joined August 2010
Spain18259 Posts
February 15 2017 15:34 GMT
#16886
On February 16 2017 00:19 Silvanel wrote:
So i was playing with arrays in C. And i just encountered something i am not sure i understand. What is happening?

my code
+ Show Spoiler +


#include <stdio.h>

const int MAX = 15;

int main () {

int var[] = {10, 100, 200, 500};
int *ptr;
int i;

ptr = var;

for (i =0; i < MAX; i++) {


printf("Value of var [%d] = %d\n", i, *ptr);

ptr++;
}
return 0;

}



output i am getting
+ Show Spoiler +


Value of var [0] = 10
Value of var [1] = 100
Value of var [2] = 200
Value of var [3] = 500
Value of var [4] = 4
Value of var [5] = 2686780
Value of var [6] = 0
Value of var [7] = 0
Value of var [8] = 2686868
Value of var [9] = 4199021
Value of var [10] = 1
Value of var [11] = 3812752
Value of var [12] = 3807472
Value of var [13] = 2686824
Value of var [14] = 1989945361


So basically i created a loop longer than array i am iterating over. Where does the values after the array ends come from? Is C assigning them at random? I suppose lesson is - be aware C is weird.

Not so much that C is weird, but that C is unsafe. C won't throw pretty "array index out of bounds" exception thingies. It'll simply see whether it can turn whatever it finds at the pointer address into the correct type. For more complex types, that is usually no, but for ints, it is almost always yes... and thus it won't segfault out, but interpret what it finds as an int and continue. Then 100 lines of code further it will try to divide by 0 and segfault, or it will just give random gibberish as output.
slmw
Profile Blog Joined October 2010
Finland233 Posts
February 15 2017 15:35 GMT
#16887
You're accessing memory locations that are outside of the array. All memory locations will always have a value. You're interpreting each memory location outside of the array as a 4 byte integer, which is why you're getting 'random' values. All this should be fairly obvious if you've studied how pointers work.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-02-15 19:42:43
February 15 2017 19:40 GMT
#16888
On February 16 2017 00:19 Silvanel wrote:
So i was playing with arrays in C. And i just encountered something i am not sure i understand. What is happening?

my code
+ Show Spoiler +


#include <stdio.h>

const int MAX = 15;

int main () {

int var[] = {10, 100, 200, 500};
int *ptr;
int i;

ptr = var;

for (i =0; i < MAX; i++) {


printf("Value of var [%d] = %d\n", i, *ptr);

ptr++;
}
return 0;

}



output i am getting
+ Show Spoiler +


Value of var [0] = 10
Value of var [1] = 100
Value of var [2] = 200
Value of var [3] = 500
Value of var [4] = 4
Value of var [5] = 2686780
Value of var [6] = 0
Value of var [7] = 0
Value of var [8] = 2686868
Value of var [9] = 4199021
Value of var [10] = 1
Value of var [11] = 3812752
Value of var [12] = 3807472
Value of var [13] = 2686824
Value of var [14] = 1989945361


So basically i created a loop longer than array i am iterating over. Where does the values after the array ends come from? Is C assigning them at random? I suppose lesson is - be aware C is weird.


As everyone has said, in C, `arrayPointer[i]` is equivalent to `*(arrayPointer + i)`.

If you declared an array with 4 elements `int array[4];` and called `array[100]` you'd actually access the value by `*(array + 100)`.

A fun result is that you should also be able to do `100[array]`.


Also potentially helpful in understanding.

http://c-faq.com/aryptr/aryptr2.html
There is no one like you in the universe.
tofucake
Profile Blog Joined October 2009
Hyrule19202 Posts
Last Edited: 2017-02-15 20:10:10
February 15 2017 20:09 GMT
#16889
derp
Liquipediaasante sana squash banana
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-02-15 20:46:25
February 15 2017 20:42 GMT
#16890
On February 15 2017 01:52 TheEmulator wrote:
My cousin is in grade 12 and he's thinking of majoring in CS when he goes to uni. He knows I've taken a few classes and have been doing self learning over the past year so he asked me some questions, one of which was "what's a good online course I can take to get a head start". I am thinking of recommending the intro to programming on Udacity as well as Harvard's CS50x since he wants more of an actual structured class. Any other options? Has anyone taken either of those, and would you recommend them?


The most stimulating thing I found with programming when I was younger was solving problems from coding competitions, which generally involved more extracting logical requirements from written problems and translating them into mostly straightforward code. I had much more of a math background pre-university which made those ideas comfortable. There are a lot of high school coding competitions and more importantly practice problems that may be more relevant, if he has any programming experience.

Computer Science is such a hot commodity now though so hopefully he's not starting from scratch by himself otherwise it'll likely be much more difficult getting into university for CS.
There is no one like you in the universe.
mantequilla
Profile Blog Joined June 2012
Turkey781 Posts
February 15 2017 22:03 GMT
#16891
On February 16 2017 04:40 Blisse wrote:
Show nested quote +
On February 16 2017 00:19 Silvanel wrote:
So i was playing with arrays in C. And i just encountered something i am not sure i understand. What is happening?

my code
+ Show Spoiler +


#include <stdio.h>

const int MAX = 15;

int main () {

int var[] = {10, 100, 200, 500};
int *ptr;
int i;

ptr = var;

for (i =0; i < MAX; i++) {


printf("Value of var [%d] = %d\n", i, *ptr);

ptr++;
}
return 0;

}



output i am getting
+ Show Spoiler +


Value of var [0] = 10
Value of var [1] = 100
Value of var [2] = 200
Value of var [3] = 500
Value of var [4] = 4
Value of var [5] = 2686780
Value of var [6] = 0
Value of var [7] = 0
Value of var [8] = 2686868
Value of var [9] = 4199021
Value of var [10] = 1
Value of var [11] = 3812752
Value of var [12] = 3807472
Value of var [13] = 2686824
Value of var [14] = 1989945361


So basically i created a loop longer than array i am iterating over. Where does the values after the array ends come from? Is C assigning them at random? I suppose lesson is - be aware C is weird.


As everyone has said, in C, `arrayPointer[i]` is equivalent to `*(arrayPointer + i)`.

If you declared an array with 4 elements `int array[4];` and called `array[100]` you'd actually access the value by `*(array + 100)`.

A fun result is that you should also be able to do `100[array]`.


Also potentially helpful in understanding.

http://c-faq.com/aryptr/aryptr2.html



when do you start accessing other programs' data on memory?
Age of Mythology forever!
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2017-02-15 23:00:52
February 15 2017 22:43 GMT
#16892
--- Nuked ---
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
February 15 2017 22:49 GMT
#16893
On February 16 2017 07:03 mantequilla wrote:
Show nested quote +
On February 16 2017 04:40 Blisse wrote:
On February 16 2017 00:19 Silvanel wrote:
So i was playing with arrays in C. And i just encountered something i am not sure i understand. What is happening?

my code
+ Show Spoiler +


#include <stdio.h>

const int MAX = 15;

int main () {

int var[] = {10, 100, 200, 500};
int *ptr;
int i;

ptr = var;

for (i =0; i < MAX; i++) {


printf("Value of var [%d] = %d\n", i, *ptr);

ptr++;
}
return 0;

}



output i am getting
+ Show Spoiler +


Value of var [0] = 10
Value of var [1] = 100
Value of var [2] = 200
Value of var [3] = 500
Value of var [4] = 4
Value of var [5] = 2686780
Value of var [6] = 0
Value of var [7] = 0
Value of var [8] = 2686868
Value of var [9] = 4199021
Value of var [10] = 1
Value of var [11] = 3812752
Value of var [12] = 3807472
Value of var [13] = 2686824
Value of var [14] = 1989945361


So basically i created a loop longer than array i am iterating over. Where does the values after the array ends come from? Is C assigning them at random? I suppose lesson is - be aware C is weird.


As everyone has said, in C, `arrayPointer[i]` is equivalent to `*(arrayPointer + i)`.

If you declared an array with 4 elements `int array[4];` and called `array[100]` you'd actually access the value by `*(array + 100)`.

A fun result is that you should also be able to do `100[array]`.


Also potentially helpful in understanding.

http://c-faq.com/aryptr/aryptr2.html



when do you start accessing other programs' data on memory?


What do you mean by "when"?

Generally there is an OS-level monitor in place that detects when you access memory your process doesn't have access to, and then generally there may be OS-level provisions to resolve that.
There is no one like you in the universe.
Acrofales
Profile Joined August 2010
Spain18259 Posts
February 15 2017 23:16 GMT
#16894
On February 16 2017 07:49 Blisse wrote:
Show nested quote +
On February 16 2017 07:03 mantequilla wrote:
On February 16 2017 04:40 Blisse wrote:
On February 16 2017 00:19 Silvanel wrote:
So i was playing with arrays in C. And i just encountered something i am not sure i understand. What is happening?

my code
+ Show Spoiler +


#include <stdio.h>

const int MAX = 15;

int main () {

int var[] = {10, 100, 200, 500};
int *ptr;
int i;

ptr = var;

for (i =0; i < MAX; i++) {


printf("Value of var [%d] = %d\n", i, *ptr);

ptr++;
}
return 0;

}



output i am getting
+ Show Spoiler +


Value of var [0] = 10
Value of var [1] = 100
Value of var [2] = 200
Value of var [3] = 500
Value of var [4] = 4
Value of var [5] = 2686780
Value of var [6] = 0
Value of var [7] = 0
Value of var [8] = 2686868
Value of var [9] = 4199021
Value of var [10] = 1
Value of var [11] = 3812752
Value of var [12] = 3807472
Value of var [13] = 2686824
Value of var [14] = 1989945361


So basically i created a loop longer than array i am iterating over. Where does the values after the array ends come from? Is C assigning them at random? I suppose lesson is - be aware C is weird.


As everyone has said, in C, `arrayPointer[i]` is equivalent to `*(arrayPointer + i)`.

If you declared an array with 4 elements `int array[4];` and called `array[100]` you'd actually access the value by `*(array + 100)`.

A fun result is that you should also be able to do `100[array]`.


Also potentially helpful in understanding.

http://c-faq.com/aryptr/aryptr2.html



when do you start accessing other programs' data on memory?


What do you mean by "when"?

Generally there is an OS-level monitor in place that detects when you access memory your process doesn't have access to, and then generally there may be OS-level provisions to resolve that.

But way back when in DOS days the OS didn't have the safeguards they do today, you could do whatever you wanted with memory... and that's why my father forbade me from ever using peeks and pokes in my BASIC programs.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-02-16 23:46:54
February 16 2017 23:27 GMT
#16895
let's help travis understand reflexive, symmetric, and transitive relations!

So let's say our domain is.. reals

reflexive means that if we pick a relation ( <, R x R), we are looking for it to be true for every n that (n, n) fits the relationship
so we are looking for an "n" in the reals where n is less than n.
so this is not reflexive because this is not always (never, in this case) true
but if we pick ( =, R x R), then we are looking for n = n, which is the case so this is reflexive ?



symmetric means that for every (n1, n2) in the relationship, then (n2, n1) also exists in the relationship?

so in the reals , a relationship of ( <, RxR) would be false, since 1 < 2 but 2 !< 1
however, a relationship of ( (n1 * n2 < 10) , RxR ) would be true, since 1 * 2 < 10, and 2 * 1 < 10 (and it holds true for every n1, n2)


transitive means that given an n1, n2, n3 in our relation: (n1, n2) and (n2, n3) in the relation means (n1, n3) is in the relation

so an example that holds false would be uh... say... (( n1 * n2 = 0), RxR), (( n2 * n3 = 0), RxR)
because 1 * 0 = 0 , 0 * 5 = 0 , but 1 * 5 = 5

but an example that holds true would be that (n1 < n2, RxR), (n2 < n3, RxR). because if 1 < 2, and 2 < 3, then 1 is less than 3


is my understanding with these all correct?
this stuff is getting kinda of tough tbh
my class is covering SO MUCH material


another question

is 0 congruent to 0 (mod n) where n is any integer ?
no, right?
the remainder is n?
edit: looks like wolfram alpha is saying that it IS congruent. I don't understand why the remainder is 0 but okay


a weird question:

is it false to say that 10 is congruent to 5 (mod 5) ?
Hanh
Profile Joined June 2016
146 Posts
Last Edited: 2017-02-17 01:04:06
February 17 2017 01:03 GMT
#16896
1. That's correct. A relation that has these properties is particularly interesting because it forms equivalent classes and is the basis for building new sets.

2. Congruence modulo N is an example of such relation. By definition, a is congruent to b if and only if there is a p in Z such as a = b + pN. You can prove it is reflexive, symetric and transitive.

- reflexive: a = a + 0xN
- symetric: a = b + pN <=> b = a - pN
- transitive: a = b + pN and b = c + qN => a = c + (p+q)N

Trivially, from the reflexive property.
0 = 0 (n)

and 10 = 5 (5) because 10 = 5 + 1x5

If it helps, remember than we use congruence mod 12 all the 'time' (pun intended).
5 am and 5 pm are congruent mod 12.

Another way to see congruence is:

a = b (n) if and only if a-b is a multiple of n (zero and negative multiples are allowed)
so 10-5 = 5 which is a multiple of 5 obviously.

From a more high level point of view, your class covers a lot of material quickly because many of the properties of continuous sets do not apply and it has to introduce what is available. After that, you will hardly ever deal with relations anymore. It will be implied by the context. Yet, it is important to know what you can and cannot do.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-02-17 01:32:50
February 17 2017 01:31 GMT
#16897
Hanh, I need help understanding these scenarios. I believe I already have the answers via proofs, but I don't understand the proofs. I've been trying to understand it but I don't.

http://aleph.math.louisville.edu/teaching/2011SP-311/notes-110209.pdf

The 3 propositions

I understand proposition 1,

but #2 and 3 makes no sense to me

like, the actual proof makes sense, but in practice, let's take

a = 100, b = 2, n = 7
100 is congruent 2 (mod 7)

this is true. and based on their proof, 7 does divide (100-2)

but

2 is congruent 100 (mod 7)

this is not true. based on their proof, 7 does divide (2-100), but I don't understand how I am using modular arithmetic incorrectly then

is it that I am actually applying it incorrectly and that the correct way to apply it is not to divide a by n and look for remainder b, but rather to always subtract b from a and then see if the result is divisible by n?


edit: (it looks like you provided the same proofs above)
Hanh
Profile Joined June 2016
146 Posts
February 17 2017 02:13 GMT
#16898
Don't divide by n if you want to test for congruence, stick to definition instead. The remainder of the integer division is for finding the smallest positive congruent number.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-02-17 03:16:37
February 17 2017 03:11 GMT
#16899
On February 17 2017 10:31 travis wrote:
Hanh, I need help understanding these scenarios. I believe I already have the answers via proofs, but I don't understand the proofs. I've been trying to understand it but I don't.

http://aleph.math.louisville.edu/teaching/2011SP-311/notes-110209.pdf

The 3 propositions

I understand proposition 1,

but #2 and 3 makes no sense to me

like, the actual proof makes sense, but in practice, let's take

a = 100, b = 2, n = 7
100 is congruent 2 (mod 7)

this is true. and based on their proof, 7 does divide (100-2)

but

2 is congruent 100 (mod 7)

this is not true. based on their proof, 7 does divide (2-100), but I don't understand how I am using modular arithmetic incorrectly then

is it that I am actually applying it incorrectly and that the correct way to apply it is not to divide a by n and look for remainder b, but rather to always subtract b from a and then see if the result is divisible by n?


edit: (it looks like you provided the same proofs above)


2 is congruent to 100 mod 7 iff 7 | 2 - 100
7 | 2 - 100
7 | -98
7 | -98 iff exists n such that 7*n = -98
n=-14, thus 7 | -98
therefore 2 is congruent to 100 mod 7


conceptually it helps the first time to think about congruency as x dividing n with remainder r, but think of how it'd work for different numbers

is -12 congruent to 100 mod 7?
via your original non-definition method you'd go
-12 / 7 = 1 remainder -5
100 / 7 = 14 remainder 2
-5 is not equal to 2, but -5 + 7 is 2, so that looks good

what's with the random steps
why do we compare to 2 here, instead of say, 16, because -12 is also congruent to 16 mod 7. is there something special about remainder 2? why do we care that it's the smallest positive congruent integer?

versus formally and to the point,

-12 congruent to 100 mod 7 iff 7 | -12 - 100
7 | -12 - 100
7 | -112
7 | -112 iff exists n such that 7*n = -112
n=-16, thus 7 | -112
therefore -12 is congruent to 100 mod 7


the classes move quickly because these definitions aren't the meat of the class, but they're foundational to working with the theorems later on. they should also be relatively straightforward, just following formulas and definitions. the later theorems are much more about developing intuition on how people arrived at the theorem.
There is no one like you in the universe.
tofucake
Profile Blog Joined October 2009
Hyrule19202 Posts
February 17 2017 03:14 GMT
#16900
your math is wrong, travis

a = 100, b = 2, n = 7

a - b is 100 - 2 = 98, which is 7*14

The way you did it also works but isn't congruent because of a negative result
Liquipediaasante sana squash banana
Prev 1 843 844 845 846 847 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 51m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
LamboSC2 290
Hui .286
Lowko281
ProTech127
StarCraft: Brood War
Sea 12986
Calm 7234
Bisu 3943
Horang2 2124
Jaedong 1600
Mini 611
EffOrt 522
BeSt 464
Stork 440
firebathero 397
[ Show more ]
Larva 242
Soulkey 167
Hyun 156
Zeus 148
Rush 135
actioN 133
Pusan 110
ggaemo 68
Dewaltoss 66
[sc1f]eonzerg 63
ToSsGirL 50
Mind 50
Killer 47
zelot 37
Barracks 29
Nal_rA 27
Rock 20
Movie 17
Terrorterran 15
Hm[arnc] 15
GoRush 15
IntoTheRainbow 11
SilentControl 11
Bale 10
Sexy 7
Dota 2
qojqva1945
syndereN279
420jenkins184
League of Legends
Reynor20
Counter-Strike
fl0m4522
olofmeister4293
Other Games
hiko953
B2W.Neo947
XBOCT340
crisheroes299
Pyrionflax173
KnowMe120
RotterdaM91
QueenE85
ArmadaUGS58
Mew2King36
Trikslyr20
Organizations
Other Games
WardiTV721
BasetradeTV497
Counter-Strike
PGL246
StarCraft: Brood War
Kim Chul Min (afreeca) 17
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• StrangeGG 67
• Shameless 2
• IndyKCrew
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• LaughNgamezSOOP
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• Noizen47
League of Legends
• Nemesis2080
• TFBlade1396
• Jankos659
Other Games
• Shiphtur27
Upcoming Events
Monday Night Weeklies
51m
OSC
8h 51m
Afreeca Starleague
18h 51m
Snow vs PianO
hero vs Rain
WardiTV Map Contest Tou…
18h 51m
GSL
20h 51m
PiGosaur Cup
1d 8h
CranKy Ducklings
1d 17h
Kung Fu Cup
1d 20h
Replay Cast
2 days
The PondCast
2 days
[ Show More ]
WardiTV Map Contest Tou…
2 days
Replay Cast
3 days
Escore
3 days
WardiTV Map Contest Tou…
3 days
Korean StarCraft League
4 days
CranKy Ducklings
4 days
WardiTV Map Contest Tou…
4 days
IPSL
5 days
WolFix vs nOmaD
dxtr13 vs Razz
BSL
5 days
Sparkling Tuna Cup
5 days
WardiTV Map Contest Tou…
5 days
Ladder Legends
5 days
BSL
6 days
IPSL
6 days
JDConan vs TBD
Aegong vs rasowy
Replay Cast
6 days
Replay Cast
6 days
Wardi Open
6 days
Afreeca Starleague
6 days
Bisu vs Ample
Jaedong vs Flash
Liquipedia Results

Completed

Escore Tournament S2: W2
RSL Revival: Season 4
NationLESS Cup

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
StarCraft2 Community Team League 2026 Spring
Nations Cup 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026

Upcoming

Escore Tournament S2: W3
Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
RSL Revival: Season 5
WardiTV TLMC #16
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.