Sit-In Lab 1 Twenty-Forty-Eight

Slides:



Advertisements
Similar presentations
The economical eigen-computation is where the sufficient spanning set is The final updated LDA component is given by Motivation Incremental Linear Discriminant.
Advertisements

How SAS implements structured programming constructs
Sorting Really Big Files Sorting Part 3. Using K Temporary Files Given  N records in file F  M records will fit into internal memory  Use K temp files,
Goal: to rotate a figure around a central point
Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 1 An overview of lecture 6 A parallel search algorithm A parallel merging algorithm.
ALGORITHM ANALYSIS AND DESIGN INTRODUCTION TO ALGORITHMS CS 413 Divide and Conquer Algortihms: Binary search, merge sort.
SOLVING SUDOKU WITH MATLAB VERIFICATION FUNCTION correctness verification of the puzzle: checks if the current element appears twice in the same line,
Possible Outcomes Carlos and Chris 6E. Buying a car.
Jigsaw Puzzles with Pieces of Unknown Orientation Andrew C. Gallagher Eastman Kodak Research Laboratories Rochester, New York.
PREVIOUS SORTING ALGORITHMS  BUBBLE SORT –Time Complexity: O(n 2 ) For each item, make (n –1) comparisons Gives: Comparisons = (n –1) + (n – 2)
Merge Sort Comparison Left Half Data Movement Right Half Sorted.
Ch. 6 Geometry Lab 6-9b Tessellations Lab 6-9b Tessellations.
Luminosity measurements at Hadron Colliders
Virtual Environments and Computer Graphics
Điều trị chống huyết khối trong tai biến mạch máu não
Electronics for Pedestrians – Passive Components –
L-Systems and Affine Transformations
Bayesian Confidence Limits and Intervals
实习总结 (Internship Summary)
Face Recognition Monday, February 1, 2016.
Theoretical Results on Neutrinos
Creating Synthetic Microdata for Higher Educational Use in Japan: Reproduction of Distribution Type based on the Descriptive Statistics Kiyomi Shirakawa.
Overview of TST-2 Experiment
Optomechanics with atoms
داده کاوی سئوالات نمونه
Wissenschaftliche Aussprache zur Dissertation
Particle acceleration during the gamma-ray flares of the Crab Nebular
Factor Based Index of Systemic Stress (FISS)
THE BERRY PHASE OF A BOGOLIUBOV QUASIPARTICLE IN AN ABRIKOSOV VORTEX*
Quantum-classical transition in optical twin beams and experimental applications to quantum metrology Ivano Ruo-Berchera Frascati.
פרויקט מסכם לתואר בוגר במדעים (B.Sc.) במתמטיקה שימושית
C3q Measurement Using Polarized e+/e- Beams at JLab
Machine learning tehniques for credit risk modeling in practice
Lower bounds against convex relaxations via statistical query complexity Based on: V. F., Will Perkins, Santosh Vempala. On the Complexity of Random Satisfiability.
Fundamentals of Algorithms MCS - 2 Lecture # 11
Entry Ticket: Algorithms and Program Construction
Merging Merge. Keep track of smallest element in each sorted half.
Sorting Algorithms.
David Kauchak cs201 Spring 2014
Sit-In Lab 1 Ob-CHESS-ion
Topic Checking prior knowledge of anaerobic respiration and fermentation Level GCSE (or any course for students aged 14-16) Outcomes Can write the symbol.
Data Structures Recursion CIS265/506: Chapter 06 - Recursion.
Insertion Sort Sorted Unsorted
Growth Functions Algorithms Lecture 8
(2,4) Trees 11/15/2018 9:25 AM Sorting Lower Bound Sorting Lower Bound.
شاخصهای عملکردی بیمارستان
Yang-Ming University, Taipei, Taiwan
MSIS 655 Advanced Business Applications Programming
مدل زنجیره ای در برنامه های سلامت
فرق بین خوب وعالی فقط اندکی تلاش بیشتر است
Lecture 24 Logistics Last lecture Today HW7 due today
Medians and Order Statistics
IT 4043 Data Structures and Algorithms
Please retrieve a copy of page A8 from the Student Handout Packet.
Suppose I want to add all the even integers from 1 to 100 (inclusive)
Searching an Array or Table
Multidimensional array
Domain range A A-1 MATRIX INVERSE.
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
Lecture 21 Logistics Last lecture Today HW7 due Wednesday
A G L O R H I M S T A Merging Merge.
A LESSON IN LOOPING What is a loop?
Topic 5: Heap data structure heap sort Priority queue
Lecture 24 Logistics Last lecture Today HW7 due today
A G L O R H I M S T A Merging Merge.
A G L O R H I M S T A Merging Merge.
Rotation, Freeform, and YOU
I can determine whether a relation is a function
Applications of Arrays
Generic Set Algorithms
Presentation transcript:

Sit-In Lab 1 Twenty-Forty-Eight

2048 Puzzle 4 by 4 matrix You can slide the tiles in 4 directions: up, down, left, right Tiles will hit each other If 2 same-number tiles hit each other, they are “merged” Tiles can only be merged once Write a piece of code to print the result of the move Input: 4 lines of 4 numbers - Initial state of the puzzle Followed by d - the direction of the move 0 (left) 1 (up) 2 (right) 3 (down) Output the outcome of the move

Sample 1 2 4 16 8 64 32 Move left

Similar numbers will be merged Sample 1 2 4 16 8 64 32 4 16 8 2 64 32 Move left Similar numbers will be merged Before After

Sample 2 2 4 16 8 64 32 Move up

Sample 2 2 4 16 8 64 32 2 16 8 4 64 32 Move up Numbers take the place of the “0” Similar numbers will be merged Before After

Sample 3 2 4 16 8 64 32 Move right

Sample 3 2 4 16 8 64 32 4 16 8 2 64 32 Move right Numbers take the place of the “0” Similar numbers will be merged Before After

Sample 4 2 4 16 8 64 32 Move down

Similar numbers will be merged Sample 4 2 4 16 8 64 32 2 4 16 8 64 32 Move down Similar numbers will be merged Before After

Algorithm #1 To move up… Use a combination of rotateRight moveLeft 2 16 8 4 64 32 4 8 32 64 16 2 Use a combination of rotateRight moveLeft 4. Move left To move up… 1. Rotate right 2. Rotate right 3. Rotate right 2 4 16 8 64 32 32 2 4 64 16 8 64 32 4 2 8 16 2 4 8 32 64 16

Algorithm #1 To move right… Use a combination of rotateRight moveLeft 4 16 8 2 64 32 4 2 64 8 32 16 Use a combination of rotateRight moveLeft 4. Rotate right To move right… 1. Rotate right 2. Rotate right 3. Move left 2 4 16 8 64 32 32 2 4 64 16 8 64 32 4 2 8 16 64 4 32 2 8 16

Algorithm #1 To move down… Use a combination of rotateRight moveLeft 2 4 16 8 64 32 4 8 32 64 16 2 Use a combination of rotateRight moveLeft 4. Rotate right To move down… 1. Rotate right 2. Move left 3. Rotate right 2 4 16 8 64 32 32 2 4 64 16 8 32 2 4 64 16 8 8 64 32 4 2 16

Main method Helper methods Read in the inputs Call helper methods and print the output Helper methods rotateRight: rotate the matrix 90 degrees right moveLeft: move numbers to the left, merging numbers if necessary

Algorithm #2 Assemble 1D array Perform moveLeft on each of the array Copy result back to array 1 2 3 4 4 3 2 1 Move left Move right 1 2 3 4 4 3 2 1 Move up Move down

Main method Helper methods Read in the inputs Call helper methods and print the output Helper methods assemble1DArray: retrieve 1D array based on direction of move, set first element to be the direction of the move moveLeft: move numbers to the left, merging numbers if necessary

How to assemble?

2 4 16 8 64 32 Sample 1 Move left [0, 0] [0, 1] [0, 2] [0, 3] … 4 16 8 64 32 Move left (first element is the direction of the move) [0, 0] [0, 1] [0, 2] [0, 3] …

Sample 2 2 4 16 8 64 32 Move up [0, 0] [1, 0] [2, 0] [3, 0] …

Sample 3 2 4 16 8 64 32 Move right [0, 3] [0, 2] [0, 1] [0, 0] …

Sample 4 2 4 16 8 64 32 Move down [3, 0] [2, 0] [1, 0] [0, 0] …

How to collapse and merge? (moveLeft)

moveLeft 2 4 Move left Collapse all numbers to left 2 4

2 4 2 4 moveLeft Compare 2 numbers if similar If not, move onto the next set of numbers 2 4

2 4 2 8 moveLeft Compare the next set of numbers If yes, merge the numbers 2 8

2 8 2 8 moveLeft Continue until no more comparisons Collapse everything to the left again, if necessary 2 8

Questions?