5 kyu

John and Ann sign up for Codewars

115 of 3,899g964

Description:

John and his wife Ann have decided to go to Codewars. On the first day Ann will do one kata and John - he wants to know how it is working - 0 kata.

Let us call a(n) - and j(n) - the number of katas done by Ann - and John - at day n. We have a(0) = 1 and in the same manner j(0) = 0.

They have chosen the following rules:

  • On day n the number of katas done by Ann should be n minus the number of katas done by John at day t, t being equal to the number of katas done by Ann herself at day n - 1

  • On day n the number of katas done by John should be n minus the number of katas done by Ann at day t, t being equal to the number of katas done by John himself at day n - 1

Whoops! I think they need to lay out a little clearer exactly what there're getting themselves into!

Could you write:

  • functions ann(n) and john(n) that return the list of the number of katas Ann/John does on the first n days;
  • functions sum_ann(n) and sum_john(n) that return the total number of katas done by Ann/John on the first n days

Examples:

john(11)  -->  [0, 0, 1, 2, 2, 3, 4, 4, 5, 6, 6]
ann(6)    -->  [1, 1, 2, 2, 3, 3]

sum_john(75)  -->  1720
sum_ann(150)  -->  6930

Note:

Keep an eye on performance.

Mathematics
Algorithms

More By Author:

Check out these other kata created by g964

Stats:

CreatedJun 9, 2016
PublishedJun 9, 2016
Warriors Trained22593
Total Skips7741
Total Code Submissions22312
Total Times Completed3899
Ruby Completions115
Python Completions771
JavaScript Completions522
CoffeeScript Completions7
TypeScript Completions110
Java Completions561
C# Completions297
Haskell Completions61
Clojure Completions33
Elixir Completions35
C++ Completions394
PHP Completions137
Crystal Completions8
F# Completions29
C Completions186
OCaml Completions25
Rust Completions292
Swift Completions73
Go Completions165
R Completions32
Shell Completions8
Kotlin Completions85
Fortran Completions8
Julia Completions18
NASM Completions6
Groovy Completions10
Scala Completions45
PowerShell Completions7
Nim Completions4
Reason Completions3
Racket Completions12
VB Completions9
Dart Completions55
Pascal Completions5
Lua Completions30
Perl Completions4
Elm Completions2
D Completions4
Erlang Completions3
Total Stars478
% of votes with a positive feedback rating85% of 616
Total "Very Satisfied" Votes459
Total "Somewhat Satisfied" Votes135
Total "Not Satisfied" Votes22
Ad
Contributors
  • g964 Avatar
  • jhoffner Avatar
  • anter69 Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • wneumann Avatar
  • Voile Avatar
  • Bubbler Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
Ad