Task 1: Binary Flip You are given a positive integer, $n. Write a script to find the binary flip. Example 1 Input: $n = 5 Output: 2 First find the binary equivalent of the given integer, 101. Then flip the binary digits 0 -> 1 and 1 -> 0 and we get 010. So Binary 010 => Decimal 2. Example 2 Input: $n = 4 Output: 3 Decimal 4 = Binary 100 Flip 0 -> 1 and 1 -> 0, we get 011. Binary 011 = Decimal 3 Example 3 Input: $n = 6 Output: 1 Decimal 6 = Binary 110 Flip 0 -> 1 and 1 -> 0, we get 001. Binary 001 = Decimal 1 MY NOTES: very easy. That's ones complement with a bit of range-fixing! GUEST LANGUAGE: As a bonus, I also had a go at translating ch-1.pl into C (look in the C directory for the translation) Task 2: Equal Distribution You are given a list of integers greater than or equal to zero, @list. Write a script to distribute the number so that each members are same. If you succeed then print the total moves otherwise print -1. Please follow the rules (as suggested by Neils van Dijke [2022-11-21 13:00] 1) You can only move a value of '1' per move 2) You are only allowed to move a value of '1' to a direct neighbor/adjacent cell Example 1: Input: @list = (1, 0, 5) Output: 4 Move #1: 1, 1, 4 (2nd cell gets 1 from the 3rd cell) Move #2: 1, 2, 3 (2nd cell gets 1 from the 3rd cell) Move #3: 2, 1, 3 (1st cell get 1 from the 2nd cell) Move #4: 2, 2, 2 (2nd cell gets 1 from the 3rd cell) Example 2: Input: @list = (0, 2, 0) Output: -1 It is not possible to make each same. Example 3: Input: @list = (0, 3, 0) Output: 2 Move #1: 1, 2, 0 (1st cell gets 1 from the 2nd cell) Move #2: 1, 1, 1 (3rd cell gets 1 from the 2nd cell) MY NOTES: Hmm.. If I'm understanding that right, it's two passes: 1. repeatedly find two adjacent cells whose absolute difference > 1 and transfer one from the bigger cell to the smaller cell. 2. repeatedly find 2 adjacent cells where firstvalue < secondvalue and transfer one from secondvalue to firstvalue Note also that I'm pretty sure that all lists whose sum is divisible by 3 can be balanced, and no list whose sum is NOT divisible by 3 can be. GUEST LANGUAGE: As a bonus, I also had a go at translating ch-2.pl into C (look in the C directory for the translation)