Questions
Let’s represent 61 students sitting in a row as a simple string, 61 characters long. Students...

Let’s represent 61 students sitting in a row as a simple string, 61 characters long. Students not wearing a mask are represented by the space character. Students wearing a mask are represented by an asterisk (*). On the first day, only one student, sitting in the middle of the row is wearing a mask. Our initial string looks like this: " * " Students will decide whether to wear a mask the next day according to the following rule: If a student is sitting next to exactly one student wearing a mask (on the left or the right) then they will wear a mask to the next class. Otherwise they won’t wear a mask the next day. How does the mask-wearing behavior change over time. Generate the subsequent strings for 100 subsequent classes. Embed your output inside your code as a triple-quoted string. Here are the first few classes: " * " " * * " " * * " " * * * * " (should look like a pyramid with space in middle of third row)

In: Computer Science

########################################################### # Lab 5 - Debugging # Name: # Date: # # Objective: # The purpose...

###########################################################
# Lab 5 - Debugging
# Name:
# Date:
#
# Objective:
# The purpose of this lab assignment is to help you understand
# debugging processes in assembly language using debug tools
# provided by QtSpim
#
# Description:
# 1) Syntax, logic, and comment errors exist in:
# - main
# - print_array
# - read_array
# - allocate_array
# 2) Find and fix the syntax, logical, and comment errors
# *** Hint: Find all the "#To do" and fix bugs ***
# *** There are 23 total bugs to fix! ***
# 3) Test the code. If the code is working, submit to
# the Lab #5 dropbox on Canvas
#
# Note:
# sort_array subprogram is correct and has no bug, do not modify sort_array!
#
# Sample run:
# Enter size of the array to allocate (size > 0): 5
# Enter an integer: 4
# Enter an integer: 3
# Enter an integer: 2
# Enter an integer: 1
# Enter an integer: -5
# Array: 4 3 2 1 -5
# Array: -5 1 2 3 4
#
###########################################################
.data
array_pointer_p: .word 0 # holds address of dynamic array (address)
array_size_p: .word 0 # hold size of dynamic array (value)

newline_p: .asciiz "\n"
###########################################################
.text
main:
# set up arguments for allocate_array subprogram
la $a0, array_pointer_p # load the address of static variable array_pointer into register $a0
la $a1, array_size_p # load the address of static variable array_size into register $a1
jal allocate_array # call subprogram allocate_array
# arguments IN: address of static variable "array_pointer" & "array_size"
# arguments OUT: NONE

# set up arguments for read_array subprogram
#To do: Think about the logic and syntax and fix errors

la $a0, array_pointer_p # load the address of variable array_pointer into register $a0
la $a1, array_size_p # load the address of variable array_size into register $a1
jal read_array # call subprogram read_array
# arguments IN: true address of dynamic array and array size value
# arguments OUT: NONE

# calling subprogram print_array
#To do: Think about the logic and syntax and fix errors
la $a0, array_pointer_p # load the address of variable array_pointer into register $a0
la $a1, array_size_p # load the address of variable array_size into register $a1
jal print_array # calling subprogram print_array

# print newline character
la $a0, newline_p # prints newline character
li $v0, 4
syscall
# calling subprogram sort_array
#To do: Think about the logic and syntax and fix errors

la $a0, array_pointer_p # load the address of variable array_pointer into register $a0
la $a1, array_size_p # load the address of variable array_size into register $a1
jal sort_array # calling subprogram sort_array

# calling subprogram print_array
#To do: Think about the logic and syntax and fix error
la $a0, array_pointer_p # load the address of variable array_pointer into register $a0
la $a1, array_size_p # load the address of variable array_size into register $a1
jal print_array # calling subprogram print_array

mainEnd:
li $v0, 4
syscall # Halt
###########################################################
# Arguments IN and OUT of subprogram
# $a0 Holds array pointer (address)
# $a1 Holds array size pointer (address)
# $a2
# $a3
# $v0
# $v1
# $sp
# $sp+4
# $sp+8
# $sp+12
###########################################################
# Register Usage
# $t0 Holds array pointer (address)
# $t1 Holds array size pointer (address)
# $t2 Holds array size, temporarily
###########################################################
.data
allocate_array_prompt_p: .asciiz "Enter size of the array to allocate (size > 0): "
allocate_array_invalid_p: .asciiz "Array size you entered is incorrect (size > 0)!\n"
###########################################################
.text
allocate_array:
# save arguments so we do not lose them
#To do: Think about the logic and syntax and fix errors

move $t1, $a0 # move array pointer (address) to $t0
move $t0, $a1 # move array size pointer (address) to $t1
allocate_array_loop:
li $v0, 4 # prompt for array size
la $a0, allocate_array_prompt_p
syscall
#To do: Think about syntax and fix error
li $v0, 6 # reads integer for array size
syscall

#To do: Think about logic and fix error
bgez $v0, allocate_array_invalid_size # branch to error section as array size is
# less than or equal to zero
move $t2, $v0 # store valid array size in register $t2

#To do: Think about syntax and fix error
li $v0, 5 # dynamically allocate an array (using system call 9)
move $a0, $t2 # puts array size in register $a0

#To do: Think about logic and fix error
sll $a0, $a0, 3 # multiply array size by 4, as word in MIPS is 4 bytes
syscall

b allocate_array_end # branch unconditionally to the end of subprogram
allocate_array_invalid_size:
li $v0, 4 # prints error saying that array size is less than or equal to zero
la $a0, allocate_array_invalid_p
syscall
b allocate_array_loop # branch unconditionally back to beginning of the loop
allocate_array_end:
sw $v0, 0($t0) # store address of dynamic array in static variable (array_pointer)

#To do: Think about logic and fix error
sw $t2, 4($t1) # store size of dynamic array in static variable (array_size)

jr $ra # jump back to the main
###########################################################
# read_array subprogram
#
# Subprogram description:
# This subprogram will receive as argument IN address of integer array and then
# prompts for integer and read integer for each array element (or index). This
# subprogram does not return anything as argument OUT.
#
###########################################################
# Arguments IN and OUT of subprogram
# $a0 Holds array pointer (address)
# $a1 Holds array size (value)
# $a2
# $a3
# $v0
# $v1
# $sp
# $sp+4
# $sp+8
# $sp+12
###########################################################
# Register Usage
# $t0 Holds array pointer (address)
# $t1 Holds array index
###########################################################
.data
read_array_prompt_p: .asciiz "Enter an integer: "
###########################################################
.text
read_array:
# save arguments so we do not lose them
#To do: Think about syntax, logic, and fix errors

move $t1, $a0 # move array pointer (address) to $t0
move $t0, $a1 # move array size (value) to $t1
read_array_loop:
#To do: Think about logic and fix error

bge $t1, read_array_end # branch to read_array_end if counter is less than or equal to zero

#To do: Think about syntax and fix error
li $v0, 5 # prompt array element
la $a0, read_array_prompt_p
syscall

#To do: Think about syntax and fix error
li $v0, 4 # reads integer
syscall

#To do: Think about logic and syntax and fix errors
sw $a0, 4($t0) # memory[$t0 + 0] <-- $v0
# store a value that is in register $v0 into memory

#To do: Think about syntax and fix error
addi $t0, $t0, 6 # increment array pointer (address) to next word (each word is 4 bytes)
addi $t1, $t1, -1 # decrement array counter (index)
b read_array_loop # branch unconditionally back to beginning of the loop
read_array_end:

#To do: Think about syntax, comments and fix errors

###########################################################
# sort_array subprogram
#
# *** *** <<<<<<
# *** DO NOT MODIFY this subprogram !!! *** <<<<<<
# *** *** <<<<<<
#
# Subprogram description:
# This subprogram will receive as argument IN address of integer
# array and size and it iterates through array via two nested loops
# and sorts all elements of array (in-place sort). This subprogram
# does not return anything as argument OUT.
#
# Algorithm O(n^2) running time (highly inefficient, too slow):
#
# for (i = 0; i < array.length; i++) {
# for (i = 0; i < array.length; i++) {
# if (array[index] >= array[index + 1]) {
# swap(array[index], array[index + 1])
# }
# }
# }
#
###########################################################
# Arguments IN and OUT of subprogram
# $a0 Holds array pointer (address)
# $a1 Holds array size (value)
# $a2
# $a3
# $v0
# $v1
# $sp
# $sp+4
# $sp+8
# $sp+12
###########################################################
# Register Usage
# $t0 Holds array pointer (address)
# $t1 Holds array index
# $t2 Holds (unmodified / original) array pointer (address)
# $t3 Holds inner-loop counter (count-down from array size to 0)
# $t4 Holds outer-loop counter (count-down from array size to 0)
# $t5
# $t6
# $t7
# $t8 temporarily
# $t9 temporarily
###########################################################
.data
###########################################################
.text
sort_array:
# save arguments so we do not lose them
move $t0, $a0 # move array pointer (address) to $t0
move $t1, $a1 # move array size (value) to $t1
addi $t1, $t1, -1 # subtract one from array size
blez $t1, sort_array_end # if array size was originally 1 then array
# is already sorted
move $t2, $t0 # backup base address into register $t2
move $t3, $t1 # backup $t1 which is array size - 1 into $t3
move $t4, $t1 # backup $t1 which is array size - 1 into $t4
sort_array_loop1:
blez $t3, sort_array_loop1_end # if outer-looper counter <= 0 then stop outer-loop

sort_array_loop2:
blez $t4, sort_array_loop2_end # if inner-looper counter <= 0 then stop inner-loop
lw $t8, 0($t0) # $t8 <-- array[index]
lw $t9, 4($t0) # $t9 <-- array[index + 1]
ble $t8, $t9, sort_array_no_swap # if $t8 < $t9 then no need to swap in-place
sort_array_swap:
sw $t9, 0($t0) # array[index] = $t9
sw $t8, 4($t0) # array[index] = $t8
sort_array_no_swap:
addi $t0, $t0, 4 # increment base address by 4 (because integers are 4 bytes)
addi $t4, $t4, -1 # decrement inner-loop counter by 1
b sort_array_loop1 # branch unconditionally to the beginning of inner-loop
sort_array_loop2_end:
move $t0, $t2 # restore inner-loop counter to array size - 1
move $t4, $t1 # restore array address to first element of array or base address
addi $t3, $t3, -1 # decrement outer-loop counter by 1
b sort_array_loop2 # branch unconditionally to the beginning of outer-loop-loop
sort_array_loop1_end:
sort_array_end:
jr $ra # jump back to the main
###########################################################
# print_array subprogram
#
# Subprogram description:
# This subprogram will receive as argument IN address of integer
# array and size and it iterates through array and prints all
# elements of array. This subprogram does not return anything
# as argument OUT.
#
###########################################################
# Arguments IN and OUT of subprogram
# $a0 Holds array pointer (address)
# $a1 Holds array size (value)
# $a2
# $a3
# $v0
# $v1
# $sp
# $sp+4
# $sp+8
# $sp+12
###########################################################
# Register Usage
# $t0 Holds array pointer (address)
# $t1 Holds array index
###########################################################
.data
print_array_array_p: .asciiz "Array: "
print_array_space_p: .asciiz " "
###########################################################
.text
print_array:
# save arguments so we do not lose them
#To do: Think about syntax and fix errors

move $t1, $a0 # move array pointer (address) to $t0
move $t0, $a1 # move array size (value) to $t1
li $v0, 4 # prints array is:
la $a0, print_array_array_p
syscall
print_array_while:
#To do: Think about logic and fix errors

blt $t9, print_array_end # branch to print_array_end if counter is less than or equal to zero
# print value from array
#To do: Think about logic, syntax, and fix errors

li $v0, 4
sw $a0, 0($t0) # $a0 <-- memory[$t0 + 0]
# load a value from memory to register $a0
syscall
li $v0, 4 # space character
la $a0, print_array_space_p
syscall
#To do: Think about logic and fix errors
addi $t0, $t0, 8 # increment array pointer (address) to next word (each word is 4 bytes)
addi $t1, $t1, -1 # decrement array counter (index)

#To do: Think about logic, syntax, comments and fix errors
b print_array # branch unconditionally back to beginning of the loop
print_array_end:

#To do: Think about syntax, comments, and fix errors
###########################################################

First, download the Lab05.s file as usual. This lab is fully written, including main and all other subprograms.

However, there are numerous errors scattered throughout the program, and your task is to locate each one and fix it. These range from syntax errors (errors that show up when you try to load the file into QtSpim) to logic errors (errors that either cause the program to crash at runtime, or causes the program to do the wrong thing.)

There are 23 total errors that you will need to locate and fix. Some helpful hints:

  1. It is suggested to look for the all of the syntax errors first.
  2. The subprogram sort_array has no errors in it at all. Do not fix anything in sort_array!
  3. All areas where there are errors are marked with a #To do comment.
  4. You may find it helpful to write comments where you made changes to keep track of what was changed and why.

Once you've fixed all the errors and run the program with some test input a few times, the lab can be submitted.

In: Computer Science

You have a job that you really dislike. You have just gone to interview for a...

You have a job that you really dislike. You have just gone to interview for a job that you really like, and the interview went well, but the result will not be known until a month later, and there is no way you can find out any more information about it before then. In the meantime, another employer offers you a job that is better than your current job, but it demands your acceptance in a week or the offer will be withdrawn forever. Clearly describe how do you can use decision tree analysis and utility theory to help you make the decision about the offer that is better than your current job but not as good as the job you really like. Your answer should be a set of instructions or a computational procedure that the decision-maker can follow with an example.

1. CLEARLY STATE A QUANTITATIVE PROCEDURE USING THE DECISION TREE ANALYSIS AND UTILITY THEORY.

In: Computer Science

Exercise #1:  Write MARIE assembly language code to input 3 values into variables x, y, and z,...

Exercise #1:  Write MARIE assembly language code to input 3 values into variables x, y, and z, calculate x + y -z, and outputs the result. Run your code in the simulator and submit a screen shot of your program run and the code.

//x + y -z

ORG 100
    INPUT
    STORE X
    INPUT
    STORE Y
    INPUT
    STORE Z
    LOAD X
    ADD Y
    SUBT Z
    OUTPUT
    Halt
X, Dec 0
Y, DEC 0
Z, DEC 0

Exercise #2: Write MARIE assembly language code to implement the following algorithm:

Y = 0;
X = 1;
While X < 10 do
Y = Y + X;
X = X + 1;
Endwhile;

So this code calculates the sum of integers between 1 and 9, and stores the result in Y. So after executing the code, the value stored in Y should be decimal 45 i.e. Hexacimal 2D.


ORG 100

    Load X
    Store One
    Test, Subt Ten
    Skipcond 400
    Jump Loop
    Jump Done
    Loop, Load Y
    ADD X
    STORE Y
    Load X
    Add One
    Store X
    Jump Test
    Done, Halt

X, DEC 1
Y, DEC 0
Ten, DEC 10
One, DEC 1

Output:

Input is X = 10, Y = 15, Z = 13

ITS PROGRAMMING

In: Computer Science

#include <iostream> #include <fstream> #include <vector> using namespace std; struct Point{ int x, y; bool operator==(const...

#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

struct Point{
int x, y;
bool operator==(const Point& p2) {
return this->x == p2.x and this->y == p2.y;
}
bool operator!=(const Point& p2) {
return this->x != p2.x or this->y != p2.y;
}
friend ostream &operator<<( ostream &out, const Point &P ) {
out << "(" << P.x << ", " << P.y << ")";
return out;
}

friend istream &operator>>( istream &in, Point &P ) {
char d1, d2, d3;
// input format: (1, 2)
in >> d1 >> P.x >> d2 >> P.y >> d3;
return in;
}
};

int main()
{
vector<Point> original_points;
cout << "Enter points :\n";
Point P;
// loop continues until any error occurs
while(cin>>P)
{
// if any input error occurs, exit the loop keeping the valid points in vector
if(cin.fail()){
cin.clear(); // back in 'normal' operation mode
cin.ignore(100,'\n'); // and remove the bad input

}
original_points.push_back(P);
}

ofstream out("mydata.txt");
cout << "You entered the points:\n";
for(Point p: original_points)
{
cout << p << '\n';
out << p << '\n';
}
out.close();


ifstream in("mydata.txt");
vector<Point> processed_points;

// loop to read the data from input file
while( in >> P )
{
// if input file read error occurs, exit the loop
if(in.fail())
{
in.clear(); // back in 'normal' operation mode
in.ignore(100,'\n'); // and remove the bad input
}
processed_points.push_back(P);
}

int n = original_points.size();
for(int i=0; i<n; i++)
{
if(original_points[i] == processed_points[i])
{
cout << "Points at index " << i << " are same\n"
<< original_points[i] << " "
<< processed_points[i] << '\n';
}
if(original_points[i] != processed_points[i])
{
cout << "Points at index " << i << " are not same\n"
<< original_points[i] << " "
<< processed_points[i] << '\n';
}
}

return 0;
}
Depend on this code, if the user enters the wrong input like (8.5,8.7) change in to (8,8) then let the user enter another input again the user enter like (er,yu) ignore this input and let the user enter another input the user wants to terminate use file termination. is there anybody can help

In: Computer Science

Add a new function that takes a phrase as an argument and counts each unique word...

Add a new function that takes a phrase as an argument and counts each unique word in the phrase. The function should return a list of lists, where each sub-list is a unique [word, count] pair. Hint: A well-written list comprehension can solve this in a single line of code, but this approach is not required.

In: Computer Science

​​​​​​This is an assignment that I'm having trouble figuring out in python: Modify Node class so...

​​​​​​This is an assignment that I'm having trouble figuring out in python:

  • Modify Node class so it has a field called frequency and initialize it as one.

  • Add a search function. If a number is in the list, return its frequency.

  • Modify Insert function. Remove push, append, and insertAfter as one function called insert(self, data). If you insert a data that is already in the list, simply increase this node’s frequency. If the number is not in the list, add it to the beginning of the list.

  • Modify Delete function. When you delete a node, reduce its frequency. If frequency becomes zero, remove the node from the list.

  • Modify Print function to print out all the numbers with their frequency in the list.

The program that we are suppose to modify:

class Node:
def __init__(self,d):
self.data=d;# data in the node
self.next=None #address of next node
"""add a field called frequency here"""
class LinkedList:
def __init__(self):
self.head=None #linked list at the beginning is empty. head is None
  
def print(self):#print every node's data
temp=self.head#let temp points to head
while temp:#As long as temp is not None (the end)
"""modify print, so frequency is also printed out frequency """
print(temp.data,end="")#print data
temp=temp.next # let temp points to the next Node
print()
"""complete the folloing function """   
def insert(self,d):
temp=self.head
"""
travel the list like print, if d is in there break the loop
if yes, increase its freq
if not add it the front of the list like "push"
"""
  
  

"""
def push(self,new_d):#will add new node at the beginning
newNode=Node(new_d) #create a Node
newNode.next=self.head #Let new Node's next to be the original head
self.head=newNode #update head as the New Node
def insertAfter(self,prev_data, new_data):
temp=self.head#let temp be the head
while temp and temp.data!=prev_data:#as long temp is not None and data is not prev_data
temp=temp.next
#if you can get here. One of the condition must be false
if temp==None:#There is no prev_data because you have reached the end
print("The given previous node does not exist")
return
#if you can reach here, temp.data=prev.data
newNode=Node(new_data)#create a new node after Node temp
  
newNode.next=temp.next#make newNode's next as temp's next
temp.next=newNode# make temp's(prev) next as NewNode
def append(self,new_data):# add new_data at the end of the list
newNode=Node(new_data)#create a Node with new_data

if self.head==None:#in case the list is empty
self.head=newNode
return

last=self.head#let last be head
while last.next:#as long last next is not None, continue
last=last.next# let last as its next
#when loop terminates, last.next is None, therefore last points to the last Node
last.next=newNode
"""
def delete(self,key):#delete a Node with data "key"
temp=self.head #let temp be head
if temp is not None:#if list is not empty
if temp.data==key:#if key is at the first Node
"""reduce temp'frequency
if its frequency becomes 0, execute the next three lines"""
self.head=temp.next #let head to head's next
temp=None
return
  
while temp is not None:#if list is not empty
if temp.data==key:#loop ends if key is found
break
prev=temp#prev is node before
temp=temp.next
#Loop ends either temp is None or loop ends because of "break" which means key is found
if temp==None:
return #return because key is not in the list
#when temp.data is same as key
"""reduce temp'frequency
if its frequency becomes 0, execute the next three lines"""
prev.next=temp.next
temp=None
  
  
  
  
  
list=LinkedList()
list.insert(5)
list.insert(9)
list.insert(5)
list.insert(6)
list.insert(6)
list.insert(9)

list.print()
list.delete(5)
list.print()
list.delete(5)
list.print()
list.delete(6)
list.print()
list.delete(6)
list.print()

  

In: Computer Science

Handwritten Digit Recognition using Shallow ANN The MNIST database of handwritten digits, available from this page,...

Handwritten Digit Recognition using Shallow ANN

The MNIST database of handwritten digits, available from this page, has a training set of 60,000 examples, and a test set of 10,000 examples. It is a subset of a larger set available from NIST. The digits have been size-normalized and centered in a fixed-size image of 28-by-28.

Hint: The ANN should have 28*28=784 input nodes.

Data files:

  • training_set: contains images of handwritten digits for training. Each picture is 28×28. There are 60,000 images.
  • training_label: contains the digit label for each training image in the training set.
  • testing_set: contains the images of handwritten digits for testing. There are 10,000 images.
  • testing_label: contains the digit label for each testing image in the testing set.

Data input:

The data is stored in a very simple file format designed for storing vectors and multidimensional matrices. All the integers in the files are stored in the MSB first (high endian) format used by most non-Intel processors. You can use the functions loadMNISTImages and loadMNISTLabels to read in the training/testing set and label files respectively.

Data format for ANN:

Function loadMNISTImages will return an array of 784 rows, each column contains pixel values of an image.

Use the following code to convert labels into a 10-row array, each column represents one digit:

labels = loadMNISTLabels('training_label'); % initialize figure

labels = labels';  

labels(labels==0)=10;

labels=dummyvar(labels);      

Create an ANN:

Use patternnet(hiddenLayerSize, trainFcn)to create an ANN for pattern recognition. You may need to try different hiddenLayerSize and training function to obtain good results.

Testing:

After the ANN is trained, use the testing_set/label files to verify the ANN. You must SYSTEMATICALLY test the performance of your system, i.e. use the 20% of data as testing examples and report the overall accuracy, using different number of hidden nodes and training functions. Plotting will be helpful to visualize your results.

NEED TO WRITE CODE IN MATLAB

In: Computer Science

JAVA programming - please answer all prompts as apart of 1 java assignment. Part A Create...

JAVA programming - please answer all prompts as apart of 1 java assignment.

Part A

Create a java class InventoryItem which has

  • a String description
  • a double price
  • an int howMany

Provide a copy constructor in addition to other constructors. The copy constructor should copy description and price but not howMany, which defaults to 1 instead. In all inheriting classes, also provide copy constructors which chain to this one.

Write a clone method that uses the copy constructor to create a copy. Create similar clone methods in all classes in this assignment.

Write a toString for this class that returns something like "Footo the Wonder Boot Exploder ($22.99)" (leave out howMany)

Also write an equals method for this class. InventoryItems can only be equal to other InventoryItems, and only if they have the same price and description (even if howMany is different). Note how the equals method agrees with the copy constructor about what it means for two InventoryItems to be the same.

Add a method view(), that prints something like "Viewing: Footo the Wonder Boot Exploder"

In a harness class with a main, create several InventoryItems, clone them, and check that equals works properly.

Part B

Create a class Book which inherits from InventoryItem and also has a String author (Book will use description to hold the book's title). toString for this class will return something like "Book: The Curse of the Flying Wombat by Constance deCoverlet ($12.95)".

For Book, override view() to print something like "Opening Book Exerpt: The Curse of the Flying Wombat"

Also override equals to require author is the same, in addition to the requirements in the superclass (chain the equals methods together).

Create a class MusicCD which inherits from InventoryItem and also has a String performer (it will use description to hold the CD's title). toString for this class will return something like "CD: Tommy Gnosis: Greatest Hits ($18.65)"

For MusicCD override view() to print something like "Now Playing Sample: Greatest Hits".

Also override equals to require performer is the same, in addition to the requirements in the superclass.

In your main, create more InventoryItem variables, but point them at a Book and a MusicCD. Use clone to make copies of each type and make sure this works. Check that equals works properly.

In: Computer Science

In shell script what is the reason this statement is not working? x=7 y=13 while [...

In shell script what is the reason this statement is not working?

x=7

y=13

while [ $x -le $y ]

do

echo $x

x=x+2

done

why on while statement it has error?

2.x=7

y=13

while [$x \< $y ]

do

echo $x

let x=x+2

done

what does it mean \< ? and give me the reason how this statement works

In: Computer Science

define aray and string?

define aray and string?

In: Computer Science

PYTHON PROGRAM! Exercise 1 - The Collatz Conjecture The Collatz conjecture was a mathematical proposal set...

PYTHON PROGRAM!

Exercise 1 - The Collatz Conjecture

The Collatz conjecture was a mathematical proposal set forward by Lothar Collatz in 1937, also known as the 3n + 1 conjecture.

The conjecture is summarized as follows:

  1. Start with any positive integer
  2. if that number is even, divide it by 2
  3. otherwise (i.e. if it's odd), multiply the number by 3 and add one (hence 3n + 1)
  4. repeat until (and if!) the resulting number is 1

For example, if you start with 12, the series would be 12, 6, 3, 10, 5, 16, 8, 4, 2, 1, and takes 9 iterations to get to 1.

The Collatz conjecture says that any starting number will eventually end up at 1. However, it is still unproven (see Mathematician Proves Huge Result on ‘Dangerous’ Problem (Links to an external site.) for some recent progress!).

Collatz visualization

Write a python program that will determine how many iterations it takes for each starting value from 1 to 100 (experiment with higher values if you want!). Write out the starting value and number of iterations to a comma delimited csv file (i.e. one set of comma separated values per line). Also plot the result (starting value vs. iterations) with a visible marker for the points (you can choose which ever style you like) and no line. Make sure to give your plot a title and label the axes appropriately.

In: Computer Science

Consider an employee using their computer to send and retrieve email at their workplace. Only Ethernet...

Consider an employee using their computer to send and retrieve email at their workplace. Only Ethernet networks are used for physical connectivity, but the mail server is located on a separate network. The employee’s network and the mail server’s network are connected by a single router which also has a connection to the Internet via the workplace’s ISP.

Explain how the employees email client sends and receives emails using the email server, indicating any protocols involved and where any encapsulation/decapsulation occurs as data travels between the client, local mail server, and remote mail servers.

In: Computer Science

As an IT professional who may face differing and competing priorities from business units, suggest one...

As an IT professional who may face differing and competing priorities from business units, suggest one (1) strategy for negotiating an achievable project scope without damaging the relationship with business units. Support your answer with the steps that you would take in order to implement your strategy.

In: Computer Science

Can you provide source code in Java that 1. accepts a two-way acceptor via file; 2....

Can you provide source code in Java that
1. accepts a two-way acceptor via file;
2. and validate if the input string is part of the language

In: Computer Science