Skip to main content
added 1 character in body
Source Link
Arnaud
  • 8.6k
  • 1
  • 40
  • 60

The "prime frog" is a strange animal that jumps between integers, until it arrives on 3 or 19...


Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).

For a given integer n >= 2:

  1. Let f be the position of the frog. It is initially set to n
  2. if f = 3 or f = 19 : the frog stops jumping - halt the program and output f.
  3. if f is prime : the frog jumps to the position 2×f-1. Go back to step 2.
  4. if f is composite : let d be f's biggerbiggest prime divisor. The frog jumps to the position f-d. Go back to step 2.

Examples:

An example with n = 5:

5 > 9 > 6 > 3 stop 

The program should output 3.

Another example with n = 23:

23 > 45 > 40 > 35 > 28 > 21 > 14 > 7 > 13 > 25 > 20 > 15 > 10 > 5 > 9 > 6 > 3 stop 

Again, the program should output 3.

Test cases:

10 => 3 74 => 19 94 => 3 417 => 3 991 => 19 9983 => 19 

You can assume 1 < n < 1000000 (I have checked the program ends for these values).

The "prime frog" is a strange animal that jumps between integers, until it arrives on 3 or 19...


Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).

For a given integer n >= 2:

  1. Let f be the position of the frog. It is initially set to n
  2. if f = 3 or f = 19 : the frog stops jumping - halt the program and output f.
  3. if f is prime : the frog jumps to the position 2×f-1. Go back to step 2.
  4. if f is composite : let d be f's bigger prime divisor. The frog jumps to the position f-d. Go back to step 2.

Examples:

An example with n = 5:

5 > 9 > 6 > 3 stop 

The program should output 3.

Another example with n = 23:

23 > 45 > 40 > 35 > 28 > 21 > 14 > 7 > 13 > 25 > 20 > 15 > 10 > 5 > 9 > 6 > 3 stop 

Again, the program should output 3.

Test cases:

10 => 3 74 => 19 94 => 3 417 => 3 991 => 19 9983 => 19 

You can assume 1 < n < 1000000 (I have checked the program ends for these values).

The "prime frog" is a strange animal that jumps between integers, until it arrives on 3 or 19...


Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).

For a given integer n >= 2:

  1. Let f be the position of the frog. It is initially set to n
  2. if f = 3 or f = 19 : the frog stops jumping - halt the program and output f.
  3. if f is prime : the frog jumps to the position 2×f-1. Go back to step 2.
  4. if f is composite : let d be f's biggest prime divisor. The frog jumps to the position f-d. Go back to step 2.

Examples:

An example with n = 5:

5 > 9 > 6 > 3 stop 

The program should output 3.

Another example with n = 23:

23 > 45 > 40 > 35 > 28 > 21 > 14 > 7 > 13 > 25 > 20 > 15 > 10 > 5 > 9 > 6 > 3 stop 

Again, the program should output 3.

Test cases:

10 => 3 74 => 19 94 => 3 417 => 3 991 => 19 9983 => 19 

You can assume 1 < n < 1000000 (I have checked the program ends for these values).

Tweeted twitter.com/StackCodeGolf/status/921258226519244801
deleted 2 characters in body
Source Link
Arnaud
  • 8.6k
  • 1
  • 40
  • 60

The "prime frog" is a strange animal that jumps between integers, until it arrives on 3 or 19...


Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).

For a given integer n >= 2:

  1. Let f be the position of the frog. It is initially set to n
  2. if f = 3 or f = 19 : the frog stops jumping - halt the program and output f.
  3. if f is prime : the frogsfrog jumps to the position 2×f-1. Go back to step 2.
  4. if f is composite : let d be f's bigger prime divisor. The frogsfrog jumps to the position f-d. Go back to step 2.

Examples:

An example with n = 5:

5 > 9 > 6 > 3 stop 

The program should output 3.

Another example with n = 23:

23 > 45 > 40 > 35 > 28 > 21 > 14 > 7 > 13 > 25 > 20 > 15 > 10 > 5 > 9 > 6 > 3 stop 

Again, the program should output 3.

Test cases:

10 => 3 74 => 19 94 => 3 417 => 3 991 => 19 9983 => 19 

You can assume 1 < n < 1000000 (I have checked the program ends for these values).

The "prime frog" is a strange animal that jumps between integers, until it arrives on 3 or 19...


Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).

For a given integer n >= 2:

  1. Let f be the position of the frog. It is initially set to n
  2. if f = 3 or f = 19 : the frog stops jumping - halt the program and output f.
  3. if f is prime : the frogs jumps to the position 2×f-1. Go back to step 2.
  4. if f is composite : let d be f's bigger prime divisor. The frogs jumps to the position f-d. Go back to step 2.

Examples:

An example with n = 5:

5 > 9 > 6 > 3 stop 

The program should output 3.

Another example with n = 23:

23 > 45 > 40 > 35 > 28 > 21 > 14 > 7 > 13 > 25 > 20 > 15 > 10 > 5 > 9 > 6 > 3 stop 

Again, the program should output 3.

Test cases:

10 => 3 74 => 19 94 => 3 417 => 3 991 => 19 9983 => 19 

You can assume 1 < n < 1000000 (I have checked the program ends for these values).

The "prime frog" is a strange animal that jumps between integers, until it arrives on 3 or 19...


Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).

For a given integer n >= 2:

  1. Let f be the position of the frog. It is initially set to n
  2. if f = 3 or f = 19 : the frog stops jumping - halt the program and output f.
  3. if f is prime : the frog jumps to the position 2×f-1. Go back to step 2.
  4. if f is composite : let d be f's bigger prime divisor. The frog jumps to the position f-d. Go back to step 2.

Examples:

An example with n = 5:

5 > 9 > 6 > 3 stop 

The program should output 3.

Another example with n = 23:

23 > 45 > 40 > 35 > 28 > 21 > 14 > 7 > 13 > 25 > 20 > 15 > 10 > 5 > 9 > 6 > 3 stop 

Again, the program should output 3.

Test cases:

10 => 3 74 => 19 94 => 3 417 => 3 991 => 19 9983 => 19 

You can assume 1 < n < 1000000 (I have checked the program ends for these values).

edited body
Source Link
Arnaud
  • 8.6k
  • 1
  • 40
  • 60

The "prime frog" is a strange animal that jumps between integers, until it arrives on 3 or 19...


Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).

For a given integer n >= 2:

  1. Let be f be the position of the frog. It is initially set to n
  2. if f = 3 or f = 19 : the frog stops jumping - halt the program and output f.
  3. if f is prime : the frogs jumps to the position 2×f-1. Go back to step 2.
  4. if f is composite : let d be f's bigger prime divisor. The frogs jumps to the position f-d. Go back to step 2.

Examples:

An example with n = 5:

5 > 9 > 6 > 3 stop 

The program should output 3.

Another example with n = 23:

23 > 45 > 40 > 35 > 28 > 21 > 14 > 7 > 13 > 25 > 20 > 15 > 10 > 5 > 9 > 6 > 3 stop 

Again, the program should output 3.

Test cases:

10 => 3 74 => 19 94 => 3 417 => 3 991 => 19 9983 => 19 

You can assume 1 < n < 1000000 (I have checked the program ends for these values).

The "prime frog" is a strange animal that jumps between integers, until it arrives on 3 or 19...


Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).

For a given integer n >= 2:

  1. Let be f the position of the frog. It is initially set to n
  2. if f = 3 or f = 19 : the frog stops jumping - halt the program and output f.
  3. if f is prime : the frogs jumps to the position 2×f-1. Go back to step 2.
  4. if f is composite : let d be f's bigger prime divisor. The frogs jumps to the position f-d. Go back to step 2.

Examples:

An example with n = 5:

5 > 9 > 6 > 3 stop 

The program should output 3.

Another example with n = 23:

23 > 45 > 40 > 35 > 28 > 21 > 14 > 7 > 13 > 25 > 20 > 15 > 10 > 5 > 9 > 6 > 3 stop 

Again, the program should output 3.

Test cases:

10 => 3 74 => 19 94 => 3 417 => 3 991 => 19 9983 => 19 

You can assume 1 < n < 1000000 (I have checked the program ends for these values).

The "prime frog" is a strange animal that jumps between integers, until it arrives on 3 or 19...


Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).

For a given integer n >= 2:

  1. Let f be the position of the frog. It is initially set to n
  2. if f = 3 or f = 19 : the frog stops jumping - halt the program and output f.
  3. if f is prime : the frogs jumps to the position 2×f-1. Go back to step 2.
  4. if f is composite : let d be f's bigger prime divisor. The frogs jumps to the position f-d. Go back to step 2.

Examples:

An example with n = 5:

5 > 9 > 6 > 3 stop 

The program should output 3.

Another example with n = 23:

23 > 45 > 40 > 35 > 28 > 21 > 14 > 7 > 13 > 25 > 20 > 15 > 10 > 5 > 9 > 6 > 3 stop 

Again, the program should output 3.

Test cases:

10 => 3 74 => 19 94 => 3 417 => 3 991 => 19 9983 => 19 

You can assume 1 < n < 1000000 (I have checked the program ends for these values).

edited tags
Link
Martin Ender
  • 198.3k
  • 67
  • 455
  • 999
Loading
Source Link
Arnaud
  • 8.6k
  • 1
  • 40
  • 60
Loading