Yesterday I was bored at work and decided to see if I could get back into the Google Foo Bar challenge. I once again tried all the known combinations that had gotten me in before, and surprise surprise… I got back in. This time it was the solar doomsday challenge, which I have gotten before. I intially solved this challenge in Java, and for this attempt I decided to try and solve it in Python. Both answers are pretty similar, and I’m sure there is a more eloquent solution, but it’s what I came up with. The Java version was done first, and then Python one follows the same algorithm, just with the Python syntax. Both use recursion to solve the problem. The main difference is in the data structure used to hold the final list. In Java I used a deque, which is a faster version of a linked list when used a queue. In Python I just went with a standard list and reversed the list before returning the final answer. Both work, but Python’s seems easier and uses less space than the Java version.

## Python Version

''' Created on Feb 15, 2017 @author: Tony Harrell ''' import math; def answer(area): fList = []; solarPanelCalc(area, fList); fList.reverse(); return fList; def solarPanelCalc(area, fList): pArea = 0; if area >= 1 and area <= 1000000: tmp = int(math.sqrt(area)); print tmp; if tmp <= 0: return pArea; else: pArea = int(math.pow(tmp, 2)); nArea = area - pArea; solarPanelCalc(nArea, fList); fList.append(pArea); return pArea; print answer(12);

## Java Version

import java.util.ArrayDeque; import java.util.Arrays; public class SolarChallenge { public static int[] answer(int area){ int[] finalList = {}; ArrayDeque&lt;Integer&gt; areaQueue = new ArrayDeque&lt;&gt;(); solarPanelCalc(area, areaQueue); finalList = new int[areaQueue.size()]; for(int i=areaQueue.size()-1; i&gt;=0; i--){ finalList[i] = areaQueue.pop(); } return finalList; } public static int solarPanelCalc(int area, ArrayDeque&lt;Integer&gt; aq){ int panelArea = 0; if(area &gt;= 1 &amp;&amp; area &lt;= 1000000){ int temp = (int) Math.sqrt(area); if(temp &lt;= 0){ return panelArea; }else{ panelArea = (int) Math.pow(temp, 2); int nextArea = area - panelArea; solarPanelCalc(nextArea, aq); aq.add(panelArea); } } return panelArea; } public static void main(String[] args) { // TODO Auto-generated method stub int[] ans1 = answer(12); System.out.println(Arrays.toString(ans1)); } }