Review - Cipher

Stat 251

2025-02-06

Homework 2

  • graded with feedback

  • you can re-submit (once) to react to the feedback (submit the link in Canvas again, so that I know you are ready for another round of grading)

  • extra credit: timing of palindrome evaluation

Speed test: R vs python

Five runs of 10,000 evaluations of checking vector for palindromes:

  run replications R [in s] python [in s]
1   1        10000    0.514     0.1686378
2   2        10000    0.516     0.1630241
3   3        10000    0.513     0.1622581
4   4        10000    0.515     0.1622709
5   5        10000    0.516     0.1628715

What information do we gain from the multiple runs?

What do you expect to happen for lower number of replicates (besides faster times)?

Number of replications

Other factors: machine load

Due dates coming up

  • Readings: Data input - quiz before class on Tuesday

  • Homework #3 due on Tuesday

Topics to Know

Review: General Programming

Know how to:

  • Create a data table structure
  • Get a column, row, or value from a data table
  • Get an item from a list

Homework - Cipher

  • Goal for today: push at least one commit to your Github repo

  • Not all statements that execute are correct (Part 1: fix mistakes)

  • Part 2: write a decoder

  • Part 3: Decode the secret message!

Vector to matrices

default in R is to fill columns first

x <- 1:9
matrix(x, ncol=3)
     [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9

Vector to matrices

in python rows are filled first - need to set order to False

import numpy as np
x = np.arange(1, 10)
matrix_x = x.reshape(-1, 3, order='F')

print(matrix_x)
[[1 4 7]
 [2 5 8]
 [3 6 9]]

Extra Credit

Write an encoder for your decoder, then use it to create another secret message.

Add the R/python code for your encoder in a code chunk in index.qmd.

Add your encoded secret message as a file to your repo.

Next Time