Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit52cc15b76cc94af6cc34110a836af290f8173f79 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-02 19:14:51 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-02 19:14:51 +0200
Files92060bbd15c69728ba3c544161546fed4b4e9461
uni-projects-52cc15b76cc94af6cc34110a836af290f8173f79.tar
uni-projects-52cc15b76cc94af6cc34110a836af290f8173f79.tar.gz
uni-projects-52cc15b76cc94af6cc34110a836af290f8173f79.zip
Parent26742347cab411558a1366dab0cde90febe4e816 (diff)
Fixed solution for ex 8 with an old solution to a similar exercise
1 files changed, 11 insertions, 1 deletions
-rw-r--r--Year 1/Programming introduction/Practice-02.10.21.cpp12
diff --git a/Year 1/Programming introduction/Practice-02.10.21.cpp b/Year 1/Programming introduction/Practice-02.10.21.cpp
index 0c524f3..960e211 100644
--- a/Year 1/Programming introduction/Practice-02.10.21.cpp
+++ b/Year 1/Programming introduction/Practice-02.10.21.cpp
@@ -148,7 +148,17 @@ void ex7() {
// (f(a, b) == f(c, d)) ⇐⇒ (a == c & b == d)
int f(int a, int b) {
- return fac(a) + fac(b);
+ // This is some old code of mine: https://gitlab.com/Syndamia/algorithms/-/blob/master/C_C++/FindSpiralNumber.cpp
+ int n, v = max(abs(a), abs(b)), g = 8 * (v * (v + 1) / 2);
+
+ if (b == v || a == v) { // Top row or right column
+ n = g - a + b - 6 * v;
+ }
+ else { // Left column or bottom row
+ n = g + a - b - 2 * v;
+ }
+
+ return n;
}
void ex8() {