140 lines
5 KiB
Markdown
140 lines
5 KiB
Markdown
- DONE Ardour
|
|
- 怎么录制
|
|
- Ardour vs. audacity
|
|
-
|
|
- Leetcode - Happy Number
|
|
collapsed:: true
|
|
- Times:
|
|
- Time when completed: 12:36
|
|
- Time taken to complete: I forgot, very quick I suppose
|
|
- Revisions:
|
|
- Tags:
|
|
- Algorithms: #Floyd_s_cycle_finding_algorithm
|
|
- Difficulty: #difficulty_easy
|
|
- Platforms: #leetcode
|
|
- Links:
|
|
- [link to the problem](https://leetcode.com/problems/happy-number/description/)
|
|
- Problem:
|
|
- Write an algorithm to determine if a number `n` is happy.
|
|
|
|
A **happy number** is a number defined by the following process:
|
|
- Starting with any positive integer, replace the number by the sum of the squares of its digits.
|
|
- Repeat the process until the number equals 1 (where it will stay), or it **loops endlessly in a cycle** which does not include 1.
|
|
- Those numbers for which this process **ends in 1** are happy.
|
|
|
|
Return `true` _if_ `n` _is a happy number, and_ `false` _if not_.
|
|
- Examples:
|
|
- ```
|
|
Example 1:
|
|
|
|
Input: n = 19
|
|
Output: true
|
|
Explanation:
|
|
12 + 92 = 82
|
|
82 + 22 = 68
|
|
62 + 82 = 100
|
|
12 + 02 + 02 = 1
|
|
|
|
Example 2:
|
|
|
|
Input: n = 2
|
|
Output: false
|
|
|
|
```
|
|
- Constraints:
|
|
- `1 <= n <= 231 - 1`
|
|
- Thoughts:
|
|
- Intuition:
|
|
- It loops endlessly in a cycle, which means we need to use a cycle detection algorithm, which happens to be the [[Floyd's Cycle Finding Algorithm]].
|
|
- Approach:
|
|
- Use the Floyd's cycle finding algorithm, with two variables
|
|
- when fast == slow, cycle is found
|
|
- detect if fast is 1, and return values
|
|
- Solution:
|
|
- Code
|
|
- ```java
|
|
class Solution {
|
|
private int progress(int n) {
|
|
int sum = 0;
|
|
while (n > 0) {
|
|
sum += (n % 10) * (n % 10);
|
|
n /= 10;
|
|
}
|
|
return sum;
|
|
}
|
|
public boolean isHappy(int n) {
|
|
// loop detection
|
|
int slow = progress(n);
|
|
int fast = progress(slow);
|
|
|
|
while (slow != fast) {
|
|
slow = progress(slow);
|
|
fast = progress(progress(fast));
|
|
}
|
|
|
|
return (fast == 1);
|
|
}
|
|
}
|
|
```
|
|
-
|
|
- Daily reflection [[Daily reflections]]
|
|
collapsed:: true
|
|
- What I've done
|
|
- 写学交论文
|
|
- 音乐 improvising
|
|
- I met someone, she's gorgeous
|
|
- What I've thought #thoughts
|
|
- Improvisation is fun :)
|
|
- I think I fall in love with someone, I have a strong feeling when she is nearby, and dopamine burst out whenever I talk to her. I don't know if she feel the same (I think to some extent she does. I don't really know, I just follow the flow and enjoy every moment of that). ~~aaand also I erected a lot~~
|
|
- Mood
|
|
- Generally excited, but sometimes exhausted from these happy feelings, I deserve a good sleep.
|
|
-
|
|
- Todo
|
|
- DONE Edx 写一篇 blues
|
|
:LOGBOOK:
|
|
CLOCK: [2023-04-07 Fri 14:36:18]--[2023-04-07 Fri 16:50:36] => 02:14:18
|
|
:END:
|
|
- DONE 概率论作业
|
|
:LOGBOOK:
|
|
CLOCK: [2023-04-07 Fri 17:31:14]--[2023-04-07 Fri 21:19:06] => 03:47:52
|
|
:END:
|
|
- DONE 22, 23, 24, 25, 26, 27, 29
|
|
- DONE 58, 59
|
|
-
|
|
- 乐理学习 #music
|
|
- LATER 每天学 15 分钟 Open Music Theory [上次学到的地方](https://viva.pressbooks.pub/openmusictheory/chapter/aspn/)
|
|
SCHEDULED: <2023-05-16 Tue .+1d>
|
|
:LOGBOOK:
|
|
- State "DONE" from "LATER" [2023-04-07 Fri 16:50]
|
|
- State "DONE" from "LATER" [2023-04-07 Fri 16:52]
|
|
* State "DONE" from "LATER" [2023-04-10 Mon 22:49]
|
|
* State "DONE" from "LATER" [2023-04-11 Tue 23:35]
|
|
CLOCK: [2023-04-12 Wed 09:16:56]--[2023-04-12 Wed 09:44:02] => 00:27:06
|
|
* State "DONE" from "LATER" [2023-04-12 Wed 09:44]
|
|
* State "DONE" from "LATER" [2023-04-18 Tue 23:31]
|
|
* State "DONE" from "LATER" [2023-04-21 Fri 09:30]
|
|
CLOCK: [2023-04-23 Sun 15:18:42]--[2023-04-23 Sun 15:18:43] => 00:00:01
|
|
* State "DONE" from "NOW" [2023-04-23 Sun 15:18]
|
|
* State "DONE" from "LATER" [2023-04-26 Wed 22:31]
|
|
* State "DONE" from "LATER" [2023-05-08 Mon 20:47]
|
|
CLOCK: [2023-05-09 Tue 09:52:58]--[2023-05-09 Tue 10:01:36] => 00:08:38
|
|
* State "DONE" from "NOW" [2023-05-09 Tue 10:01]
|
|
CLOCK: [2023-05-09 Tue 10:11:30]--[2023-05-09 Tue 10:11:31] => 00:00:01
|
|
CLOCK: [2023-05-11 Thu 10:14:15]--[2023-05-11 Thu 11:16:14] => 01:01:59
|
|
* State "DONE" from "NOW" [2023-05-11 Thu 11:16]
|
|
* State "DONE" from "LATER" [2023-05-15 Mon 16:23]
|
|
:END:
|
|
- LATER 每天 5 分钟 Ear training [Teoria](https://www.teoria.com/en/exercises/)
|
|
SCHEDULED: <2023-05-12 Fri .+1d>
|
|
:LOGBOOK:
|
|
- State "DONE" from "LATER" [2023-04-07 Fri 23:31]
|
|
* State "DONE" from "LATER" [2023-04-11 Tue 16:41]
|
|
* State "DONE" from "LATER" [2023-04-12 Wed 15:07]
|
|
CLOCK: [2023-04-21 Fri 14:41:07]--[2023-04-21 Fri 14:41:09] => 00:00:02
|
|
* State "DONE" from "LATER" [2023-04-25 Tue 11:33]
|
|
* State "DONE" from "LATER" [2023-04-26 Wed 22:31]
|
|
* State "DONE" from "LATER" [2023-05-08 Mon 20:48]
|
|
CLOCK: [2023-05-09 Tue 10:01:48]--[2023-05-09 Tue 10:10:01] => 00:08:13
|
|
* State "DONE" from "LATER" [2023-05-09 Tue 10:10]
|
|
* State "DONE" from "LATER" [2023-05-11 Thu 20:06]
|
|
:END: |