7 kyu

Simple Fun #190: Folding Paper

499 of 941myjinxin2015

Description:

Task

John was in math class and got bored, so he decided to fold some origami from a rectangular a × b sheet of paper (a > b). His first step is to make a square piece of paper from the initial rectangular piece of paper by folding the sheet along the bisector of the right angle and cutting off the excess part.

Folding

After moving the square piece of paper aside, John wanted to make even more squares! He took the remaining (a-b) × b strip of paper and went on with the process until he was left with a square piece of paper.

Your task is to determine how many square pieces of paper John can make.

Example:

For: a = 2, b = 1, the output should be 2.

Given a = 2 and b = 1, John can fold a 1 × 1 then another 1 × 1.

So the answer is 2.

For: a = 10, b = 7, the output should be 6.

We are given a = 10 and b = 7. The following is the order of squares John folds: 7 × 7, 3 × 3, 3 × 3, 1 × 1, 1 × 1, and 1 × 1.

Here are pictures for the example cases.

Resulting squares

Input/Output

  • [input] integer a

2 ≤ a ≤ 1000

  • [input] integer b

1 ≤ b < a ≤ 1000

  • [output] an integer

The maximum number of squares.

Puzzles

Stats:

CreatedMar 8, 2017
PublishedMar 8, 2017
Warriors Trained2019
Total Skips39
Total Code Submissions2353
Total Times Completed941
JavaScript Completions290
C# Completions111
Python Completions499
Ruby Completions67
Crystal Completions11
Haskell Completions40
C Completions10
Total Stars29
% of votes with a positive feedback rating92% of 183
Total "Very Satisfied" Votes158
Total "Somewhat Satisfied" Votes20
Total "Not Satisfied" Votes5
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • ZozoFouchtra Avatar
  • nekokat Avatar
  • Madjosz Avatar
  • rowcased Avatar
  • hobovsky Avatar
  • cliffstamp Avatar
  • user1326445 Avatar
  • dfhwze Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad