• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 19:48
CET 01:48
KST 09:48
  • 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
TL.net Map Contest #21: Winners10Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7[BSL21] RO32 Group Stage4Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win10
StarCraft 2
General
Mech is the composition that needs teleportation t StarCraft, SC2, HotS, WC3, Returning to Blizzcon! RotterdaM "Serral is the GOAT, and it's not close" TL.net Map Contest #21: Winners Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win
Tourneys
Constellation Cup - Main Event - Stellar Fest Sparkling Tuna Cup - Weekly Open Tournament $5,000+ WardiTV 2025 Championship Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle [ASL20] Ask the mapmakers — Drop your questions BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ Where's CardinalAllin/Jukado the mapmaker?
Tourneys
[ASL20] Grand Finals [BSL21] RO32 Group A - Saturday 21:00 CET [Megathread] Daily Proleagues [BSL21] RO32 Group B - Sunday 21:00 CET
Strategy
PvZ map balance Current Meta How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile Should offensive tower rushing be viable in RTS games? Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Things Aren’t Peaceful in Palestine The Games Industry And ATVI US Politics Mega-thread Russo-Ukrainian War Thread YouTube Thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
Formula 1 Discussion 2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Learning my new SC2 hotkey…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1021 users

The Big Programming Thread - Page 860

Forum Index > General Forum
Post a Reply
Prev 1 858 859 860 861 862 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.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
March 10 2017 19:52 GMT
#17181
--- Nuked ---
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-03-10 20:40:39
March 10 2017 20:16 GMT
#17182
Haha, I'm glad people enjoyed that question. It was memorable to me because I was annoyed about the time limit as well when I was doing it the first time and didn't finish.

In hindsight I think it's a good question: it has a lot of pretty straightforward coding sections like palindrome, lends itself well to breaking down into parts, has lots of areas for optimizations, and then the short time limit adds a nice intensity given I think most people could find an okay solution in 30 minutes.

This takes me 4 minutes to code, but I have the advantage of knowing the question and my previous attempt :p

mfw trying to read slmw's O(n) solution... lol

+ Show Spoiler +

bool is_palindrome(string s) {
int left = 0;
int right = s.length() - 1;
while (left < right) {
if (s[left] != s[right]) {
return false;
}
left++;
right--;
}
return true;
}

int longest_palindrome(vector<string> text) {
int max_length = 0;
for (string s: text) {
for (int i = 0; i < s.length(); i++) {
for (int j = s.length() - 1; j > i && (j - i + 1) > max_length; j--) {
if (s[i] == s[j] && is_palindrome(s.substr(i, j - i + 1))) {
max_length = max(max_length, j - i + 1);
}
}
}
}
return max_length;
}

int main() {
vector<string> text = {
"carracecar",
"aabbaa",
"aabbbabab"
};

for (string s: text) {
cout << is_palindrome(s) << endl;
}

cout << longest_palindrome(text) << endl;

return 0;
}
There is no one like you in the universe.
Fwmeh
Profile Joined April 2008
1286 Posts
March 11 2017 09:39 GMT
#17183
I'm not sure that I understand the complexity analysis of that proposed O(n) solution. I would treat a for-loop with a nested while bound by the length (and half the length is still bound by the length) of the string as O(n^2).

Best I could do, certainly more than 5 minutes. https://ideone.com/M4tVmS. O(n^2), but reasonably good constants.
A parser for things is a function from strings to lists of pairs of things and strings
meatpudding
Profile Joined March 2011
Australia520 Posts
March 11 2017 09:55 GMT
#17184
I guess it's really O(nm) where n is the word length and m is the palindrome length.
Be excellent to each other.
slmw
Profile Blog Joined October 2010
Finland233 Posts
Last Edited: 2017-03-11 12:54:34
March 11 2017 12:53 GMT
#17185
The algorithm in question is Manacher's algorithm. The idea is that we maintain the currently rightmost palindrome, which means that we can look up some of the answers from the left side of the current palindrome since it's simply a mirrored case. The while loop will fail on the first iteration any time we are inside a larger palindrome and don't update the rightmost palindrome. If we need to expand the current palindrome, we update the rightmost palindrome. That means on each iteration we either move the current rightmost palindrome further or do an O(1) copying of a value. The rightmost palindrome can move only at most N times, so the whole algorithm is O(N) per string.

If you try every substring (N^2) in a string and check if it is a palindrome you get an O(N^3) algorithm. That is what Fwmeh's and many others' solution is doing. If you try every midpoint and expand until it is no longer a palindrome, you get an O(N^2) algorithm. This is what travis's solution was doing for odd palindromes.
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
Last Edited: 2017-03-13 14:14:27
March 13 2017 14:08 GMT
#17186
Does anyone here know any resources where I can dig up some imposition calculation algorithms for printing presses?

I've got new assignment today: rewrite old PHP library as new Ruby gem. Sounds simple enough, but then there's a couple of problems:

  • no documentation
  • no tests
  • entire library is a single class that's 4k lines long (basically no empty lines)
  • at the top of class the error reporting is being disabled (which doesn't bode well)
  • there's plenty of magic arbitrary numbers and overall code readability is on par with assembler
  • loops nested 6 deep with other control statements spread throughout
  • 2k lines of configuration
  • large arrays in global variables, which are being manipulated in different ways by different functions (reversed, reversed with reindexing, values moved around and changed etc. etc.)


After nearly 7 hours of sifting through it I simply gave up trying to understand what's going on in there and I'm looking to simply write this shit from scratch. So, if you know of any resources or ready libraries (any language) that deal with this kind of stuff, please help...

+ Show Spoiler [sample] +


function build_collect_placement_array($sect=1){
$count_pairs = count($this->grid_build_used[$sect]);
$inc = 1;
for ($x = 1; $x <= $count_pairs; $x++){ // build an array for each of the two pair numbering patterns
if ($inc > 0) {
if ($x == 1) {
$add_a = 1; // first instance
} else {
$add_a = $arr_b[$x-1] + $inc;
}
if ($add_a==$count_pairs){
$add_b = $add_a;
$inc = -2;
} else {
$add_b = $add_a + $inc;
}
if (($add_b==$count_pairs)&&($add_a!=$count_pairs)){
$inc = 0;
}
} else {
if ($inc == 0) {
$add_b = $arr_b[$x-1];
$inc = -1;
} elseif ($inc == -2) {
$add_b = $arr_b[$x-1] + $inc;
} else {
$add_b = $arr_a[$x-1] + $inc;
}
if ($inc == -2) {
$add_a = $add_b + 1;
} else {
$add_a = $add_b + $inc;
}
}
$arr_a[$x] = $add_a;
$arr_b[$x] = $add_b;
}
$place_arr_a = $arr_a;
$place_arr_b = $arr_b;

$keep_count=1;
for ($x = 1; $x <= 4; $x++){ // loop for each column
for ($y = 1; $y <= $count_pairs; $y++){ // create array for pair placement
$final_pr_arr[$y+($count_pairs*2*($x-1))] = $place_arr_a[$y];
$final_pr_arr[$y+($count_pairs*2*($x-1))+$count_pairs] = $place_arr_b[$y];
}
if (((($count_pairs % 2)==0)||($x==1)||($x==3))&&(($this->grid_cols != 2)||((($this->grid_cols == 2)&&($count_pairs % 2)==0)))){
$temp_arr = $place_arr_a;
$place_arr_a = $place_arr_b;
$place_arr_b = $temp_arr;
}
for ($y = 1; $y <= 2; $y++){ //
for ($z = 1; $z <= 2; $z++){ // build the sub-grid pattern
$inc=0;
if (($count_pairs % 2)==1){ // there is an odd number of pairs
if (($x == 1)||($x == 4)){
if (($y == 1)&&($z == 2)){
$inc=1;
}
if (($y == 2)&&($z == 1)){
$inc=1;
}
}
if (($x == 2)||($x == 3)){
if (($y == 1)&&($z == 1)){
$inc=1;
}
if (($y == 2)&&($z == 2)){
$inc=1;
}
}
if (($this->grid_cols == 2)&&($x == 2)){ // different sub-grid pattern for 4-up
if ((($y == 1)&&($z == 2))||(($y == 2)&&($z == 1))){
$inc=1;
} else {
$inc=0;
}
}
}
for ($a = 1; $a <= (ceil($count_pairs/2)-$inc); $a++){ // create array for sub-grid placement
$final_sg_arr[$keep_count] = $x*2-(2-$z);
$keep_count++;
}
}
}
}
if(is_array($final_pr_arr)) {
foreach ($final_pr_arr as $key => $final_pr_val){
$final_arr[$key]["pair"] = $final_pr_val;
$final_arr[$key]["subgrid"] = $final_sg_arr[$key];
}
ksort($final_arr);
return $final_arr;
}
return null;
}


One of my favorites:

list($rows, $columns) = array($columns, $rows);

Time is precious. Waste it wisely.
BluzMan
Profile Blog Joined April 2006
Russian Federation4235 Posts
Last Edited: 2017-03-13 15:56:57
March 13 2017 15:54 GMT
#17187
On March 13 2017 23:08 Manit0u wrote:
Does anyone here know any resources where I can dig up some imposition calculation algorithms for printing presses?

I've got new assignment today: rewrite old PHP library as new Ruby gem. Sounds simple enough, but then there's a couple of problems:

  • no documentation
  • no tests
  • entire library is a single class that's 4k lines long (basically no empty lines)
  • at the top of class the error reporting is being disabled (which doesn't bode well)
  • there's plenty of magic arbitrary numbers and overall code readability is on par with assembler
  • loops nested 6 deep with other control statements spread throughout
  • 2k lines of configuration
  • large arrays in global variables, which are being manipulated in different ways by different functions (reversed, reversed with reindexing, values moved around and changed etc. etc.)


After nearly 7 hours of sifting through it I simply gave up trying to understand what's going on in there and I'm looking to simply write this shit from scratch. So, if you know of any resources or ready libraries (any language) that deal with this kind of stuff, please help...

+ Show Spoiler [sample] +


function build_collect_placement_array($sect=1){
$count_pairs = count($this->grid_build_used[$sect];
$inc = 1;
for ($x = 1; $x <= $count_pairs; $x++){ // build an array for each of the two pair numbering patterns
if ($inc > 0) {
if ($x == 1) {
$add_a = 1; // first instance
} else {
$add_a = $arr_b[$x-1] + $inc;
}
if ($add_a==$count_pairs){
$add_b = $add_a;
$inc = -2;
} else {
$add_b = $add_a + $inc;
}
if (($add_b==$count_pairs)&&($add_a!=$count_pairs)){
$inc = 0;
}
} else {
if ($inc == 0) {
$add_b = $arr_b[$x-1];
$inc = -1;
} elseif ($inc == -2) {
$add_b = $arr_b[$x-1] + $inc;
} else {
$add_b = $arr_a[$x-1] + $inc;
}
if ($inc == -2) {
$add_a = $add_b + 1;
} else {
$add_a = $add_b + $inc;
}
}
$arr_a[$x] = $add_a;
$arr_b[$x] = $add_b;
}
$place_arr_a = $arr_a;
$place_arr_b = $arr_b;

$keep_count=1;
for ($x = 1; $x <= 4; $x++){ // loop for each column
for ($y = 1; $y <= $count_pairs; $y++){ // create array for pair placement
$final_pr_arr[$y+($count_pairs*2*($x-1))] = $place_arr_a[$y];
$final_pr_arr[$y+($count_pairs*2*($x-1))+$count_pairs] = $place_arr_b[$y];
}
if (((($count_pairs % 2)==0)||($x==1)||($x==3))&&(($this->grid_cols != 2)||((($this->grid_cols == 2)&&($count_pairs % 2)==0)))){
$temp_arr = $place_arr_a;
$place_arr_a = $place_arr_b;
$place_arr_b = $temp_arr;
}
for ($y = 1; $y <= 2; $y++){ //
for ($z = 1; $z <= 2; $z++){ // build the sub-grid pattern
$inc=0;
if (($count_pairs % 2)==1){ // there is an odd number of pairs
if (($x == 1)||($x == 4)){
if (($y == 1)&&($z == 2)){
$inc=1;
}
if (($y == 2)&&($z == 1)){
$inc=1;
}
}
if (($x == 2)||($x == 3)){
if (($y == 1)&&($z == 1)){
$inc=1;
}
if (($y == 2)&&($z == 2)){
$inc=1;
}
}
if (($this->grid_cols == 2)&&($x == 2)){ // different sub-grid pattern for 4-up
if ((($y == 1)&&($z == 2))||(($y == 2)&&($z == 1))){
$inc=1;
} else {
$inc=0;
}
}
}
for ($a = 1; $a <= (ceil($count_pairs/2)-$inc); $a++){ // create array for sub-grid placement
$final_sg_arr[$keep_count] = $x*2-(2-$z);
$keep_count++;
}
}
}
}
if(is_array($final_pr_arr)) {
foreach ($final_pr_arr as $key => $final_pr_val){
$final_arr[$key]["pair"] = $final_pr_val;
$final_arr[$key]["subgrid"] = $final_sg_arr[$key];
}
ksort($final_arr);
return $final_arr;
}
return null;
}


One of my favorites:

list($rows, $columns) = array($columns, $rows);


Looks like regular production code to me, also pretty well-formed. At least this doesn't have 20 global declarations at the start of each function like our code did.

Based on the sample you provided I would definitely try to reuse it, deep control structure nesting does not necessarily imply redundancy, it might just be that the field is actually that difficult. In that was the case, rewriting it from scratch would be a pretty stupid thing to do. Maybe start with writing tests for the parts you understand and slowly increase the coverage as your understanding grows? Could also refactor obvious subroutines into functions, etc.

Throwing working code away and rewriting from scratch is almost never a good idea.

One of my favorites:

list($rows, $columns) = array($columns, $rows);


That is a pretty creative way to do a swap one-liner Can you implement cpp-style swap with references in php? Don't remember the exact way they work.
You want 20 good men, but you need a bad pussy.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-03-13 17:27:20
March 13 2017 17:26 GMT
#17188
I am studying for my discrete math midterm. Here is a question that an old exam asks:

Prove:
If a, b, c and d are consecutive integers, 4 | abcd.

*please note that this is under the heading "formal proofs"


So my answer is:

+ Show Spoiler +

Any 4 consecutive numbers (a,b,c,d) must contain a multiple of 4. Therefore 4 can be factored from a*b*c*d. Therefore 4|abcd.


Here is what the answer key says:

+ Show Spoiler +

Without loss of generality, assume that a is an even number. From a known theorem in class, we know that consecutive integers have opposite parity, which means that b is odd, and c is even. By the definition of even parity, this means that there exist integers k_1, k_2 such that a = 2k_1 and c = 2k_2 . Therefore, a · b · c · d = (2k_1) · b · (2k_2) · d = (4k_1k_2)bd = 4 (k_1k_2bd) m∈Z = 4m ⇔ 4|abcd.


So I guess my question is, does my answer suffice for a "formal" proof?
Also this question is dumb.
Acrofales
Profile Joined August 2010
Spain18112 Posts
March 13 2017 17:50 GMT
#17189
I think your answer is fine. Whether your teacher agrees i don't know...
tofucake
Profile Blog Joined October 2009
Hyrule19151 Posts
March 13 2017 17:51 GMT
#17190
Depends on how strict the grader is. Your answer is correct, but it's not a mathematical proof.
Liquipediaasante sana squash banana
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
March 13 2017 18:05 GMT
#17191
So technically to make it a mathematical proof I would need to do what? State step one mathematically and then prove the other steps by mathematically manipulating what I start with?
Biolunar
Profile Joined February 2012
Germany224 Posts
March 13 2017 18:15 GMT
#17192
There is no such thing as a “mathematical proof”. A proof is a proof, if it is correct independent of how it was proven.
Same goes of following example: ℕ = { n ∈ ℤ | n ≥ 0 } is not more “mathematically” than ℕ = { n ∈ ℤ | n is greater or equal to zero }, although the former is more formal.
What is best? To crush the Zerg, see them driven before you, and hear the lamentations of the Protoss.
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
March 13 2017 21:35 GMT
#17193
On March 14 2017 00:54 BluzMan wrote:
Show nested quote +
On March 13 2017 23:08 Manit0u wrote:
Does anyone here know any resources where I can dig up some imposition calculation algorithms for printing presses?

I've got new assignment today: rewrite old PHP library as new Ruby gem. Sounds simple enough, but then there's a couple of problems:

  • no documentation
  • no tests
  • entire library is a single class that's 4k lines long (basically no empty lines)
  • at the top of class the error reporting is being disabled (which doesn't bode well)
  • there's plenty of magic arbitrary numbers and overall code readability is on par with assembler
  • loops nested 6 deep with other control statements spread throughout
  • 2k lines of configuration
  • large arrays in global variables, which are being manipulated in different ways by different functions (reversed, reversed with reindexing, values moved around and changed etc. etc.)


After nearly 7 hours of sifting through it I simply gave up trying to understand what's going on in there and I'm looking to simply write this shit from scratch. So, if you know of any resources or ready libraries (any language) that deal with this kind of stuff, please help...

+ Show Spoiler [sample] +


function build_collect_placement_array($sect=1){
$count_pairs = count($this->grid_build_used[$sect];
$inc = 1;
for ($x = 1; $x <= $count_pairs; $x++){ // build an array for each of the two pair numbering patterns
if ($inc > 0) {
if ($x == 1) {
$add_a = 1; // first instance
} else {
$add_a = $arr_b[$x-1] + $inc;
}
if ($add_a==$count_pairs){
$add_b = $add_a;
$inc = -2;
} else {
$add_b = $add_a + $inc;
}
if (($add_b==$count_pairs)&&($add_a!=$count_pairs)){
$inc = 0;
}
} else {
if ($inc == 0) {
$add_b = $arr_b[$x-1];
$inc = -1;
} elseif ($inc == -2) {
$add_b = $arr_b[$x-1] + $inc;
} else {
$add_b = $arr_a[$x-1] + $inc;
}
if ($inc == -2) {
$add_a = $add_b + 1;
} else {
$add_a = $add_b + $inc;
}
}
$arr_a[$x] = $add_a;
$arr_b[$x] = $add_b;
}
$place_arr_a = $arr_a;
$place_arr_b = $arr_b;

$keep_count=1;
for ($x = 1; $x <= 4; $x++){ // loop for each column
for ($y = 1; $y <= $count_pairs; $y++){ // create array for pair placement
$final_pr_arr[$y+($count_pairs*2*($x-1))] = $place_arr_a[$y];
$final_pr_arr[$y+($count_pairs*2*($x-1))+$count_pairs] = $place_arr_b[$y];
}
if (((($count_pairs % 2)==0)||($x==1)||($x==3))&&(($this->grid_cols != 2)||((($this->grid_cols == 2)&&($count_pairs % 2)==0)))){
$temp_arr = $place_arr_a;
$place_arr_a = $place_arr_b;
$place_arr_b = $temp_arr;
}
for ($y = 1; $y <= 2; $y++){ //
for ($z = 1; $z <= 2; $z++){ // build the sub-grid pattern
$inc=0;
if (($count_pairs % 2)==1){ // there is an odd number of pairs
if (($x == 1)||($x == 4)){
if (($y == 1)&&($z == 2)){
$inc=1;
}
if (($y == 2)&&($z == 1)){
$inc=1;
}
}
if (($x == 2)||($x == 3)){
if (($y == 1)&&($z == 1)){
$inc=1;
}
if (($y == 2)&&($z == 2)){
$inc=1;
}
}
if (($this->grid_cols == 2)&&($x == 2)){ // different sub-grid pattern for 4-up
if ((($y == 1)&&($z == 2))||(($y == 2)&&($z == 1))){
$inc=1;
} else {
$inc=0;
}
}
}
for ($a = 1; $a <= (ceil($count_pairs/2)-$inc); $a++){ // create array for sub-grid placement
$final_sg_arr[$keep_count] = $x*2-(2-$z);
$keep_count++;
}
}
}
}
if(is_array($final_pr_arr)) {
foreach ($final_pr_arr as $key => $final_pr_val){
$final_arr[$key]["pair"] = $final_pr_val;
$final_arr[$key]["subgrid"] = $final_sg_arr[$key];
}
ksort($final_arr);
return $final_arr;
}
return null;
}


One of my favorites:

list($rows, $columns) = array($columns, $rows);


Looks like regular production code to me, also pretty well-formed. At least this doesn't have 20 global declarations at the start of each function like our code did.

Based on the sample you provided I would definitely try to reuse it, deep control structure nesting does not necessarily imply redundancy, it might just be that the field is actually that difficult. In that was the case, rewriting it from scratch would be a pretty stupid thing to do. Maybe start with writing tests for the parts you understand and slowly increase the coverage as your understanding grows? Could also refactor obvious subroutines into functions, etc.

Throwing working code away and rewriting from scratch is almost never a good idea.

Show nested quote +
One of my favorites:

list($rows, $columns) = array($columns, $rows);


That is a pretty creative way to do a swap one-liner Can you implement cpp-style swap with references in php? Don't remember the exact way they work.


It doesn't have 20 global declarations at each function. It has 60 at the top of the file though. Swap one-liner is clever, but it comes out of the blue and is buried deep in other logic (also with functions that span several hundred lines it's easy to miss).

I have to pretty much rewrite it anyway since I have to do it in another language. I've started with various utility functions around the code, but it's hard to implement some of the larger methods since no documentation or anything and magic numbers are bad (also, pi with 5 digit precision jumped at me out of nowhere, no explanation why 5 digits or how important it is...). I've been reading some books from 1895 on imposition, also some Rockwell patents I found on Google. It's damn complicated stuff
Time is precious. Waste it wisely.
Liebig
Profile Joined August 2010
France738 Posts
March 13 2017 21:44 GMT
#17194
On March 14 2017 02:26 travis wrote:
I am studying for my discrete math midterm. Here is a question that an old exam asks:

Prove:
If a, b, c and d are consecutive integers, 4 | abcd.

*please note that this is under the heading "formal proofs"


So my answer is:

+ Show Spoiler +

Any 4 consecutive numbers (a,b,c,d) must contain a multiple of 4. Therefore 4 can be factored from a*b*c*d. Therefore 4|abcd.


Here is what the answer key says:

+ Show Spoiler +

Without loss of generality, assume that a is an even number. From a known theorem in class, we know that consecutive integers have opposite parity, which means that b is odd, and c is even. By the definition of even parity, this means that there exist integers k_1, k_2 such that a = 2k_1 and c = 2k_2 . Therefore, a · b · c · d = (2k_1) · b · (2k_2) · d = (4k_1k_2)bd = 4 (k_1k_2bd) m∈Z = 4m ⇔ 4|abcd.


So I guess my question is, does my answer suffice for a "formal" proof?
Also this question is dumb.

I think it's fine, but I would play it safe if it was in the first few questions of the exam and just answer like that

We can assume without loss of generality that b=a+1, c=a+2, d=a+3.
If a=0[4] then a*b*c*d is clearly a multiple of 4
If a=1[4] then d=0[4] and etc

Atreides
Profile Joined October 2010
United States2393 Posts
March 13 2017 21:51 GMT
#17195
On March 14 2017 02:26 travis wrote:
I am studying for my discrete math midterm. Here is a question that an old exam asks:

Prove:
If a, b, c and d are consecutive integers, 4 | abcd.

*please note that this is under the heading "formal proofs"


So my answer is:

+ Show Spoiler +

Any 4 consecutive numbers (a,b,c,d) must contain a multiple of 4. Therefore 4 can be factored from a*b*c*d. Therefore 4|abcd.


Here is what the answer key says:

+ Show Spoiler +

Without loss of generality, assume that a is an even number. From a known theorem in class, we know that consecutive integers have opposite parity, which means that b is odd, and c is even. By the definition of even parity, this means that there exist integers k_1, k_2 such that a = 2k_1 and c = 2k_2 . Therefore, a · b · c · d = (2k_1) · b · (2k_2) · d = (4k_1k_2)bd = 4 (k_1k_2bd) m∈Z = 4m ⇔ 4|abcd.


So I guess my question is, does my answer suffice for a "formal" proof?
Also this question is dumb.


Every math professor in the world here is just looking for you to say there is two even numbers bla bla bla. It's ez to formalize.

Jumping straight to divisible by four is obviously doable but slightly harder to formalize. For a question like that the entire thing is formalizing something intuitively obvious so I can't imagine any prof giving full credit for your answer.
Hanh
Profile Joined June 2016
146 Posts
Last Edited: 2017-03-14 01:26:41
March 14 2017 01:10 GMT
#17196
On March 14 2017 03:05 travis wrote:
So technically to make it a mathematical proof I would need to do what? State step one mathematically and then prove the other steps by mathematically manipulating what I start with?


You can only use theorems and axioms that were given to you during your class, so I wouldn't call your answer a formal proof.

Edit:
1. Use the canonical injection to go from N to Z/4Z.
2. By definition, you get 4 different equivalent classes of Z/4Z.
3. Z/4Z has cardinality 4. Therefore one of the classes must be 0.
4. the product is 0
5. Therefore the product is a multiple of 4.
Prillan
Profile Joined August 2011
Sweden350 Posts
March 14 2017 18:33 GMT
#17197
On March 14 2017 03:05 travis wrote:
So technically to make it a mathematical proof I would need to do what? State step one mathematically and then prove the other steps by mathematically manipulating what I start with?

You need to state why the things you do are true. Ask "why?" until you reach an already proved result.
To get you started:
Any 4 consecutive numbers (a,b,c,d) must contain a multiple of 4.

Why?
TheBB's sidekick, aligulac.com | "Reality is frequently inaccurate." - Douglas Adams
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-03-15 02:10:03
March 14 2017 22:49 GMT
#17198
To add onto everyone's answers, I believe the problem is you're not rigorous enough with your terminology. A formal proof has a certain structure because the structure makes reasoning very clear. In your answer, you've skipped those structures, but the proof is still mostly comprehensible because the domain is pretty straight-forward. But it's likely that the purpose of these exercises is to teach you these concepts in preparation for later proofs - eventually having the concepts translate to programming logic - so skipping these structures kind of misses the point of the lesson.

Now to go over your answer. Correct me if I am wrong, but "multiple" and "factor" are not words in the theorems you've been taught. They are obvious mathematical definitions and results of the theorems, and maybe part of some related, unpresented corollary due to those definitions, but they essentially aren't part of your set of premises. The goal of these exercises is to have you conceptualize how to infer the result, given the premises. Using these "unrelated" concepts and jumping from result to result is what is I meant by not being rigorous.


> Any 4 consecutive numbers (a,b,c,d) must contain a multiple of 4. (1)

Is this true? It looks like it's true, but how do I prove that? Is it so trivially true that it's unnecessary to show (1*n = n)? Is this the result of some theorem that I know (n|a-b => a === b mod n)? This result is intuitive, in that it's easy enough to convince yourself that this must be true, but how do you show that in writing?

> Therefore 4 can be factored from a*b*c*d. (2)

What did factored come from and what factored mean? Are you saying that "multiple of n" implies "factor out by n"?

> Therefore 4|abcd. (3)

Are you saying that "factor n from x" implies "n | x"?


I think you'd have to enumerate all the cases in (1) to show a proof of it.


Suppose a,b,c,d are consecutive numbers.
Any 4 consecutive numbers (a,b,c,d) must contain 1 number which is a multiple of 4.
<show that this is true>
Without loss of generality, suppose a is divisible by 4.
Therefore there exists n such that a = 4n. (2)
Therefore there exists n such that abcd = 4nbcd.
If x == nbcd, then abcd = 4x.
From definitions, a | b iff a*n = b.
Therefore 4 | abcd. (3)
There is no one like you in the universe.
netherh
Profile Blog Joined November 2011
United Kingdom333 Posts
March 15 2017 04:29 GMT
#17199
On March 15 2017 07:49 Blisse wrote:
Suppose a,b,c,d are consecutive numbers.
Any 4 consecutive numbers (a,b,c,d) must contain 1 number which is a multiple of 4.
<show that this is true>
Without loss of generality, suppose a is divisible by 4.
Therefore there exists n such that a = 4n. (2)
Therefore there exists n such that abcd = 4nbcd.
If x == nbcd, then abcd = 4x.
From definitions, a | b iff a*n = b.
Therefore 4 | abcd. (3)


Probably dumb questions:

What does the line in 4 | abcd mean?
What does "without loss of generality" mean, and why do you use it there?
tofucake
Profile Blog Joined October 2009
Hyrule19151 Posts
March 15 2017 04:35 GMT
#17200
4 | abcd means "4 divides abcd"
Liquipediaasante sana squash banana
Prev 1 858 859 860 861 862 1032 Next
Please log in or register to reply.
Live Events Refresh
OSC
23:00
OSC Elite Rising Star #17
ReBellioN vs HiGhDrA
Shameless vs Demi
LetaleX vs Mute
Percival vs TBD
CranKy Ducklings100
Liquipedia
BSL 21
20:00
ProLeague - RO32 Group B
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
ZZZero.O106
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
White-Ra 314
ProTech122
UpATreeSC 66
Ketroc 21
StarCraft: Brood War
Artosis 740
ZZZero.O 106
NaDa 25
Super Smash Bros
hungrybox1456
Other Games
Grubby2922
summit1g941
fl0m555
Maynarde133
JuggernautJason11
Organizations
Other Games
gamesdonequick1470
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• Hupsaiya 84
• RyuSc2 50
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• blackmanpl 20
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota21115
League of Legends
• imaqtpie3228
Other Games
• Scarra640
Upcoming Events
OSC
8h 12m
Wardi Open
11h 12m
Wardi Open
15h 12m
Replay Cast
22h 12m
WardiTV Korean Royale
1d 11h
Replay Cast
2 days
Kung Fu Cup
2 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
2 days
The PondCast
3 days
RSL Revival
3 days
Solar vs Zoun
MaxPax vs Bunny
[ Show More ]
Kung Fu Cup
3 days
WardiTV Korean Royale
3 days
Replay Cast
3 days
RSL Revival
4 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
4 days
CranKy Ducklings
5 days
RSL Revival
5 days
herO vs Gerald
ByuN vs SHIN
Kung Fu Cup
5 days
BSL 21
5 days
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
6 days
RSL Revival
6 days
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
6 days
WardiTV Korean Royale
6 days
BSL 21
6 days
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
Liquipedia Results

Completed

Proleague 2025-11-07
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
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 © 2025 TLnet. All Rights Reserved.